[Bio] / FigKernelPackages / ALITRE.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/ALITRE.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :     package ALITRE;
18 :    
19 :     use strict;
20 :     use AlignsAndTrees;
21 :     use Tracer;
22 :     use SeedUtils;
23 :     use ServerThing;
24 :    
25 :     =head1 Alignment and Tree Server Function Object
26 :    
27 :     This file contains the functions and utilities used by the Alignment and Tree Server
28 :     (B<alitre_server.cgi>). The various methods listed in the sections below represent
29 :     function calls direct to the server. These all have a signature similar to the
30 :     following.
31 :    
32 :     my $results = $altObject->function_name($args);
33 :    
34 :     where C<$altObject> is an object created by this module,
35 :     C<$args> is a parameter structure, and C<function_name> is the server function name.
36 :     The output $results is a scalar, generally a hash reference, but sometimes a
37 :     string or a list reference.
38 :    
39 :     =head2 Constructor
40 :    
41 :     Use
42 :    
43 :     my $altObject = SAPserver->new();
44 :    
45 :     to create a new alignment/tree server function object. The server function object
46 :     is used to invoke the L</Primary Methods> listed below. See L<ALITREserver> for
47 :     more information on how to create this object and the options available.
48 :    
49 :     =cut
50 :    
51 :     #
52 :     # Actually, if you are using ALITRE.pm, you should do ALITRE->new(), not ALITREserver->new()
53 :     # That comment above is for the benefit of the pod doc stuff on how to use ALITREserver
54 :     # that is generated from this file.
55 :     #
56 :    
57 :     sub new {
58 :     my ($class) = @_;
59 :     # Create the server object.
60 :     my $retVal = { };
61 :     # Bless and return it.
62 :     bless $retVal, $class;
63 :     return $retVal;
64 :     }
65 :    
66 :     =head1 Primary Methods
67 :    
68 :     =head2 Server Utility Methods
69 :    
70 :     You will not use the methods in this section very often. Currently, the only one
71 :     present (L</methods>) is used by the server framework for maintenance and control
72 :     purposes.
73 :    
74 :     =head3 methods
75 :    
76 :     my $methodList = $altObject->methods();
77 :    
78 :     Return a reference to a list of the methods allowed on this object.
79 :    
80 :     =cut
81 :    
82 :     use constant METHODS => [qw(
83 :     ali_tree_pairs_to_metadata
84 :     ali_tree_pairs_to_prots
85 :     all_ali_tree_pairs
86 :     prot_set_to_ali_tree_pairs
87 :     prots_to_ali_tree_pairs
88 :     )];
89 :    
90 :     sub methods {
91 :     # Get the parameters.
92 :     my ($self) = @_;
93 :     # Return the result.
94 :     return METHODS;
95 :     }
96 :    
97 :     =head2 Client Methods
98 :    
99 :     =head3 ali_tree_pairs_to_metadata
100 :    
101 :     my $altHash = $altObject->ali_tree_pairs_to_metadata({
102 :     -ids => [$alt1, $alt2, ...]
103 :     });
104 :    
105 :     Return the metadata associated with each specified alignment/tree pair.
106 :    
107 :     =over 4
108 :    
109 :     =item parameter
110 :    
111 :     The parameter should be a reference to a hash with the following keys:
112 :    
113 :     =over 8
114 :    
115 :     =item -ids
116 :    
117 :     Reference to a list of alignment/tree pair IDs.
118 :    
119 :     =back
120 :    
121 :     =item RETURN
122 :    
123 :     Returns a reference to a hash mapping each incoming alignment/tree pair ID to a sub-hash
124 :     that maps metadata field names to field values.
125 :    
126 :     $altHash = { $alt1 => { $fld1a => $value1a, $fld1b => $value1b, ... },
127 :     $alt2 => { $fld2a => $value2a, $fld2b => $value2b, ... },
128 :     ... };
129 :    
130 :     =back
131 :    
132 :     =cut
133 :    
134 :     sub ali_tree_pairs_to_metadata {
135 :     # Get the parameters.
136 :     my ($self, $args) = @_;
137 :     # Get the list of IDs.
138 :     my $ids = ServerThing::GetIdList(-ids => $args);
139 :     # Declare the return hash.
140 :     my $retVal = {};
141 :     # Loop through the incoming alignment/tree IDs.
142 :     for my $id (@$ids) {
143 :     # Get the metadata for this alignment.
144 : parrello 1.2 my $metadata = AlignsAndTrees::md5_alignment_metadata($id);
145 : parrello 1.1 # Store it in the return hash.
146 :     $retVal->{$id} = $metadata;
147 :     }
148 :     # Return the result.
149 :     return $retVal;
150 :     }
151 :    
152 :     =head3 ali_tree_pairs_to_prots
153 :    
154 :     my $altHash = $altObject->ali_tree_pairs_to_prots({
155 :     -ids => [$alt1, $alt2, ...]
156 :     });
157 :    
158 :     Return a list of the protein IDs in each specified alignment/tree pair.
159 :    
160 :     =over 4
161 :    
162 :     =item parameter
163 :    
164 :     The parameter should be a reference to a hash with the following keys.
165 :    
166 :     =over 8
167 :    
168 :     =item -ids
169 :    
170 :     Reference to a list of alignment/tree pair IDs.
171 :    
172 :     =back
173 :    
174 :     =item RETURN
175 :    
176 :     Returns a reference to a hash mapping each incoming alignment/tree ID to a list of MD5 protein IDs
177 :     representing the proteins found in the alignment/tree pair.
178 :    
179 :     $altHash = { $alt1 => [$prot1a, $prot1b, ...],
180 :     $alt2 => [$prot2a, $prot2b, ...],
181 :     ... };
182 :    
183 :     =back
184 :    
185 :     =cut
186 :    
187 :     sub ali_tree_pairs_to_prots {
188 :     # Get the parameters.
189 :     my ($self, $args) = @_;
190 :     # Get the list of alignment/tree IDs.
191 :     my $ids = ServerThing::GetIdList(-ids => $args);
192 :     # Declare the return hash.
193 :     my $retVal = {};
194 :     # Loop through the list of IDs.
195 :     for my $id (@$ids) {
196 :     # Get the list of proteins for this alignment.
197 :     my $prots = AlignsAndTrees::md5IDs_in_align($id);
198 :     # Store it in the return hash.
199 :     $retVal->{$id} = $prots;
200 :     }
201 :     # Return the result.
202 :     return $retVal;
203 :     }
204 :    
205 :     =head3 all_ali_tree_pairs
206 :    
207 :     my $altList = $altObject->all_ali_tree_pairs();
208 :    
209 :     Return a list of all the alignment/tree IDs. Each ID represents an alignment and an associated
210 :     tree.
211 :    
212 :     =over 4
213 :    
214 :     =item RETURN
215 :    
216 :     Returns a reference to a list of alignment/tree IDs.
217 :    
218 :     $idList = [$alt1, $alt2, ...];
219 :    
220 :     =back
221 :    
222 :     =cut
223 :    
224 :     sub all_ali_tree_pairs {
225 :     # Get the parameters.
226 :     my ($self) = @_;
227 :     # Get the list of IDs.
228 :     my $retVal = AlignsAndTrees::all_alignIDs();
229 :     # Return the list.
230 :     return $retVal;
231 :     }
232 :    
233 :     =head3 prot_set_to_ali_tree_pairs
234 :    
235 :     my $altList = $altObject({
236 :     -prots => [$prot1, $prot2, ...]
237 :     });
238 :    
239 :     Return a list of the alignments containing all of the incoming proteins.
240 :    
241 :     =over 4
242 :    
243 :     =over 4
244 :    
245 :     =item parameter
246 :    
247 :     The parameter should be a reference to a hash with the following keys.
248 :    
249 :     =over 8
250 :    
251 :     =item -prots
252 :    
253 :     Reference to a list of MD5 protein IDs.
254 :    
255 :     =back
256 :    
257 :     =item RETURN
258 :    
259 :     Returns a reference to a list of IDs for the alignment/tree pairs containing all the
260 :     incoming proteins.
261 :    
262 :     $altList = [$alt1, $alt2, ... ];
263 :    
264 :     =back
265 :    
266 :     =cut
267 :    
268 :     sub prot_set_to_ali_tree_pairs {
269 :     # Get the parameters.
270 :     my ($self, $args) = @_;
271 :     # Get the protein ID list.
272 :     my $prots = ServerThing::GetIdList(-prots => $args);
273 :     # Declare the return variable.
274 :     my $retVal = [];
275 :     # Only proceed if we have at least one protein.
276 :     my ($prot1, @otherProts) = @$prots;
277 :     if ($prot1) {
278 :     # Create a hash of the alignments found for the first protein.
279 :     my %found = map { $_ => 1 } AlignsAndTrees::aligns_with_md5ID($prot1);
280 :     # Loop through the remaining proteins. In each case we only keep the
281 :     # alignments already found.
282 :     for my $prot (@otherProts) {
283 :     # Get the alignment/tree pairs for this protein.
284 :     my %newAlts = map { $_ => 1 } AlignsAndTrees::aligns_with_md5ID($prot);
285 :     # Delete the alignments in the result hash that are not found for the new
286 :     # protein.
287 :     for my $alt (keys %found) {
288 :     if (! $newAlts{$alt}) {
289 :     delete $found{$alt};
290 :     }
291 :     }
292 :     }
293 :     # Store the alignments found as the result list.
294 :     $retVal = [ sort keys %found ];
295 :     }
296 :     # Return the result.
297 :     return $retVal;
298 :     }
299 :    
300 :    
301 :     =head3 prots_to_ali_tree_pairs
302 :    
303 :     my $protHash = $altObject({
304 :     -prots => [$prot1, $prot2, ...]
305 :     });
306 :    
307 :     For each incoming protein ID, return a list of the alignment/tree pairs containing that protein.
308 :    
309 :     =over 4
310 :    
311 :     =item parameter
312 :    
313 :     The parameter should be a reference to a hash with the following keys.
314 :    
315 :     =over 8
316 :    
317 :     =item -prots
318 :    
319 :     Reference to a list of MD5 protein IDs.
320 :    
321 :     =back
322 :    
323 :     =item RETURN
324 :    
325 :     Returns a reference to a hash that maps each incoming protein ID to a list of IDs for the
326 :     alignment/tree pairs containing that protein.
327 :    
328 :     $protHash = { $prot1 => [$alt1a, $alt1b, ...],
329 :     $prot2 => [$alt2a, $alt2b, ...],
330 :     ... };
331 :    
332 :     =back
333 :    
334 :     =cut
335 :    
336 :     sub prots_to_ali_tree_pairs {
337 :     # Get the parameters.
338 :     my ($self, $args) = @_;
339 :     # Get the protein ID list.
340 :     my $prots = ServerThing::GetIdList(-prots => $args);
341 :     # Declare the return hash.
342 :     my $retVal = {};
343 :     # Loop through the proteins.
344 :     for my $prot (@$prots) {
345 :     # Get the alignment/tree pairs for this protein.
346 :     my $alts = AlignsAndTrees::aligns_with_md5ID($prot);
347 :     # Store the resulting list in the return hash.
348 :     $retVal->{$prot} = $alts;
349 :     }
350 :     # Return the result.
351 :     return $retVal;
352 :     }
353 :    
354 :    
355 :    
356 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3