[Bio] / Sprout / ERDBTypeRectangle.pm Repository:
ViewVC logotype

Annotation of /Sprout/ERDBTypeRectangle.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     package ERDBTypeRectangle;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use CGI;
26 :     use base qw(ERDBType);
27 :    
28 :     =head1 ERDB Rectangle Descriptor Type Definition
29 :    
30 :     =head2 Introduction
31 :    
32 :     This object represents the data type for rectangular regions. The region is
33 :     described in terms of its top, left, bottom, and right coordinates. The
34 :     rectangle is represented in the database as a string of four numbers with
35 :     intervening commas, and is represented in the application by a [[RectanglePm]]
36 :     object.
37 :    
38 :     =head3 new
39 :    
40 :     my $et = ERDBTypeRectangle->new();
41 :    
42 :     Construct a new ERDBTypeRectangle descriptor.
43 :    
44 :     =cut
45 :    
46 :     sub new {
47 :     # Get the parameters.
48 :     my ($class) = @_;
49 :     # Create the ERDBTypeRectangle object.
50 :     my $retVal = { };
51 :     # Bless and return it.
52 :     bless $retVal, $class;
53 :     return $retVal;
54 :     }
55 :    
56 :     =head2 Virtual Methods
57 :    
58 :     =head3 averageLength
59 :    
60 :     my $value = $et->averageLength();
61 :    
62 :     Return the average length of a data item of this field type when it is stored in the
63 :     database. This value is used to compute the expected size of a database table.
64 :    
65 :     =cut
66 :    
67 :     sub averageLength {
68 :     return 15;
69 :     }
70 :    
71 :     =head3 prettySortValue
72 :    
73 :     my $value = $et->prettySortValue();
74 :    
75 :     Number indicating where fields of this type should go in relation to other
76 :     fields. The value should be somewhere between C<1> and C<5>. A value outside
77 :     that range will make terrible things happen.
78 :    
79 :     =cut
80 :    
81 :     sub prettySortValue() {
82 :     return 2;
83 :     }
84 :    
85 :     =head3 validate
86 :    
87 :     my $okFlag = $et->validate($value);
88 :    
89 :     Return an error message if the specified value is invalid for this field type.
90 :    
91 :     The parameters are as follows.
92 :    
93 :     =over 4
94 :    
95 :     =item value
96 :    
97 :     Value of this type, for validation.
98 :    
99 :     =item RETURN
100 :    
101 :     Returns an empty string if the specified field is valid, and an error message
102 :     otherwise.
103 :    
104 :     =back
105 :    
106 :     =cut
107 :    
108 :     sub validate {
109 :     # Get the parameters.
110 :     my ($self, $value) = @_;
111 :     # Assume it's valid until we prove otherwise.
112 :     my $retVal = "";
113 :     if (! defined $value || ref $value ne 'Rectangle') {
114 :     $retVal = "Value is not a rectangle object.";
115 :     }
116 :     # Return the determination.
117 :     return $retVal;
118 :     }
119 :    
120 :     =head3 encode
121 :    
122 :     my $string = $et->encode($value, $mode);
123 :    
124 :     Encode a value of this field type for storage in the database (or in a database load
125 :     file.)
126 :    
127 :     The parameters are as follows.
128 :    
129 :     =over 4
130 :    
131 :     =item value
132 :    
133 :     Value of this type, for encoding.
134 :    
135 :     =item mode
136 :    
137 :     TRUE if the value is being encoding for placement in a load file, FALSE if it
138 :     is being encoded for use as an SQL statement parameter. In most cases, the
139 :     encoding is the same for both modes.
140 :    
141 :     =back
142 :    
143 :     =cut
144 :    
145 :     sub encode {
146 :     # Get the parameters.
147 :     my ($self, $value, $mode) = @_;
148 :     # Declare the return variable.
149 :     my $retVal = join(",", $value->All());
150 :     # Return the result.
151 :     return $retVal;
152 :     }
153 :    
154 :     =head3 decode
155 :    
156 :     my $value = $et->decode($string);
157 :    
158 :     Decode a string from the database into a value of this field type.
159 :    
160 :     The parameters are as follows.
161 :    
162 :     =over 4
163 :    
164 :     =item string
165 :    
166 :     String from the database to be decoded.
167 :    
168 :     =item RETURN
169 :    
170 :     Returns a value of the desired type.
171 :    
172 :     =cut
173 :    
174 :     sub decode {
175 :     # Get the parameters.
176 :     my ($self, $string) = @_;
177 :     # Declare the return variable.
178 :     my $retVal = Rectangle->new(split /,/, $string);
179 :     ##TODO: decode the value.
180 :     # Return the result.
181 :     return $retVal;
182 :     }
183 :    
184 :     =head3 sqlType
185 :    
186 :     my $typeString = $et->sqlType();
187 :    
188 :     Return the SQL data type for this field type.
189 :    
190 :     =cut
191 :    
192 :     sub sqlType {
193 :     return "VARCHAR(50)";
194 :     }
195 :    
196 :     =head3 indexMod
197 :    
198 :     my $length = $et->indexMod();
199 :    
200 :     Return the index modifier for this field type. The index modifier is the number of
201 :     characters to be indexed. If it is undefined, the field cannot be indexed. If it
202 :     is an empty string, the entire field is indexed. The default is an empty string.
203 :    
204 :     =cut
205 :    
206 :     sub indexMod {
207 :     return '';
208 :     }
209 :    
210 :     =head3 sortType
211 :    
212 :     my $letter = $et->sortType();
213 :    
214 :     Return the sorting type for this field type. The sorting type is C<n> for integers,
215 :     C<g> for floating-point numbers, and the empty string for character fields.
216 :     The default is the empty string.
217 :    
218 :     =cut
219 :    
220 :     sub sortType {
221 :     return "";
222 :     }
223 :    
224 :     =head3 documentation
225 :    
226 :     my $docText = $et->documentation();
227 :    
228 :     Return the documentation text for this field type. This should be in TWiki markup
229 :     format, though HTML will also work.
230 :    
231 :     =cut
232 :    
233 :     sub documentation() {
234 :     return 'coordinates of a rectangle';
235 :     }
236 :    
237 :     =head3 name
238 :    
239 :     my $name = $et->name();
240 :    
241 :     Return the name of this type, as it will appear in the XML database definition.
242 :    
243 :     =cut
244 :    
245 :     sub name() {
246 :     return "rectangle";
247 :     }
248 :    
249 :     =head3 default
250 :    
251 :     my $defaultValue = $et->default();
252 :    
253 :     Return the default value to be used for fields of this type if no default value
254 :     is specified in the database definition or in an [[ERDBLoadGroup#Put]] call
255 :     during a loader operation. The default is undefined, which means an error will
256 :     be thrown during the load.
257 :    
258 :     =cut
259 :    
260 :     sub default {
261 :     return '0,0,0,0';
262 :     }
263 :    
264 :     =head3 align
265 :    
266 :     my $alignment = $et->align();
267 :    
268 :     Return the display alignment for fields of this type: either C<left>, C<right>, or
269 :     C<center>. The default is C<left>.
270 :    
271 :     =cut
272 :    
273 :     sub align {
274 :     return 'left';
275 :     }
276 :    
277 :     =head3 html
278 :    
279 :     my $html = $et->html($value);
280 :    
281 :     Return the HTML for displaying the content of a field of this type in an output
282 :     table. The default is the raw value, html-escaped.
283 :    
284 :     =cut
285 :    
286 :     sub html {
287 :     my ($self, $value) = @_;
288 :     # Convert it into a comma-separated list with enclosing angle brackets.
289 :     my $retVal = "&lt;" . join(", ", $value->All()) . "&gt;";
290 :     # Return the result.
291 :     return $retVal;
292 :     }
293 :    
294 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3