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

Annotation of /Sprout/ERDBTypeProteinData.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 ERDBTypeProteinData;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use base qw(ERDBType);
26 :    
27 :     =head1 ERDB Protein FASTA Data Type Definition
28 :    
29 :     =head2 Introduction
30 :    
31 :     This object represents the data type for a list of protein FASTA sequences. Each
32 :     sequence consists of a triple of data items: an ID, a comment, and the actual sequence.
33 :     An individual data value contains a list of these triples. In the database, the
34 :     entire structure is encoded as an escaped string. The individual pieces of a triple
35 :     are tab-separated, and the triples themselves are separated by new-lines.
36 :    
37 :     =head3 new
38 :    
39 :     my $et = ERDBTypeProteinData->new();
40 :    
41 :     Construct a new ERDBTypeProteinData descriptor.
42 :    
43 :     =cut
44 :    
45 :     sub new {
46 :     # Get the parameters.
47 :     my ($class) = @_;
48 :     # Create the ERDBTypeProteinData object.
49 :     my $retVal = { };
50 :     # Bless and return it.
51 :     bless $retVal, $class;
52 :     return $retVal;
53 :     }
54 :    
55 :     =head2 Virtual Methods
56 :    
57 :     =head3 averageLength
58 :    
59 :     my $value = $et->averageLength();
60 :    
61 :     Return the average length of a data item of this field type when it is stored in the
62 :     database. This value is used to compute the expected size of a database table.
63 :    
64 :     =cut
65 :    
66 :     sub averageLength {
67 :     return 100000;
68 :     }
69 :    
70 :     =head3 prettySortValue
71 :    
72 :     my $value = $et->prettySortValue();
73 :    
74 :     Number indicating where fields of this type should go in relation to other
75 :     fields. The value should be somewhere between C<1> and C<5>. A value outside
76 :     that range will make terrible things happen.
77 :    
78 :     =cut
79 :    
80 :     sub prettySortValue() {
81 :     return 5;
82 :     }
83 :    
84 :     =head3 validate
85 :    
86 :     my $okFlag = $et->validate($value);
87 :    
88 :     Return an error message if the specified value is invalid for this field type.
89 :    
90 :     The parameters are as follows.
91 :    
92 :     =over 4
93 :    
94 :     =item value
95 :    
96 :     Value of this type, for validation.
97 :    
98 :     =item RETURN
99 :    
100 :     Returns an empty string if the specified field is valid, and an error message
101 :     otherwise.
102 :    
103 :     =back
104 :    
105 :     =cut
106 :    
107 :     sub validate {
108 :     # Get the parameters.
109 :     my ($self, $value) = @_;
110 :     # Assume it's valid until we prove otherwise.
111 :     my $retVal = "";
112 :     # Verify that we're an array.
113 :     if (ref $value ne 'ARRAY') {
114 :     $retVal = "Protein data set is not a list reference.";
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 :     # Convert the list to a string.
149 :     my $retVal = Tracer::Escape(join("\n", map { join("\t", @$_) } @$value));
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 :     =back
173 :    
174 :     =cut
175 :    
176 :     sub decode {
177 :     # Get the parameters.
178 :     my ($self, $string) = @_;
179 :     # Unescape and split the string.
180 :     my $retVal = [map { [split /\t/, $_] } split /\n/, Tracer::UnEscape($string)];
181 :     # Return the result.
182 :     return $retVal;
183 :     }
184 :    
185 :     =head3 sqlType
186 :    
187 :     my $typeString = $et->sqlType();
188 :    
189 :     Return the SQL data type for this field type.
190 :    
191 :     =cut
192 :    
193 :     sub sqlType {
194 :     return "LONGTEXT";
195 :     }
196 :    
197 :     =head3 indexMod
198 :    
199 :     my $length = $et->indexMod();
200 :    
201 :     Return the index modifier for this field type. The index modifier is the number of
202 :     characters to be indexed. If it is undefined, the field cannot be indexed. If it
203 :     is an empty string, the entire field is indexed. The default is an empty string.
204 :    
205 :     =cut
206 :    
207 :     sub indexMod {
208 :     return undef;
209 :     }
210 :    
211 :     =head3 sortType
212 :    
213 :     my $letter = $et->sortType();
214 :    
215 :     Return the sorting type for this field type. The sorting type is C<n> for integers,
216 :     C<g> for floating-point numbers, and the empty string for character fields.
217 :     The default is the empty string.
218 :    
219 :     =cut
220 :    
221 :     sub sortType {
222 :     return "";
223 :     }
224 :    
225 :     =head3 documentation
226 :    
227 :     my $docText = $et->documentation();
228 :    
229 :     Return the documentation text for this field type. This should be in TWiki markup
230 :     format, though HTML will also work.
231 :    
232 :     =cut
233 :    
234 :     sub documentation() {
235 :     return 'Protein FASTA list, encoded';
236 :     }
237 :    
238 :     =head3 name
239 :    
240 :     my $name = $et->name();
241 :    
242 :     Return the name of this type, as it will appear in the XML database definition.
243 :    
244 :     =cut
245 :    
246 :     sub name() {
247 :     return "proteinData";
248 :     }
249 :    
250 :     =head3 default
251 :    
252 :     my $defaultValue = $et->default();
253 :    
254 :     Return the default value to be used for fields of this type if no default value
255 :     is specified in the database definition or in an L<ERDBLoadGroup/Put> call
256 :     during a loader operation. The default is undefined, which means an error will
257 :     be thrown during the load.
258 :    
259 :     =cut
260 :    
261 :     sub default {
262 :     return '';
263 :     }
264 :    
265 :     =head3 html
266 :    
267 :     my $html = $et->html($value);
268 :    
269 :     Return the HTML for displaying the content of a field of this type in an output
270 :     table. The default is the raw value, html-escaped.
271 :    
272 :     =cut
273 :    
274 :     sub html {
275 :     # Get the parameters.
276 :     my ($self, $value) = @_;
277 :     # We'll build a list in here and then output it later.
278 :     my @retVal;
279 :     # Loop through the triples in the list.
280 :     for my $triple (@$value) {
281 :     # Split the triple.
282 :     my ($id, $comment, $sequence) = @$triple;
283 :     # Adjust the sequence if it's too long.
284 :     if (length $sequence > 60) {
285 :     $sequence = substr($sequence, 0, 60) . "...";
286 :     }
287 :     # Form the ID and sequence into a string.
288 :     push @retVal, "$id: $sequence";
289 :     }
290 :     # Return the result.
291 :     return CGI::ul(map { CGI::li($_) } @retVal);
292 :     }
293 :    
294 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3