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

Annotation of /Sprout/ERDBTypeRectangle.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3