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

Annotation of /FigKernelPackages/ALITRE.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (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 : parrello 1.4 use strict;
20 :     use AlignsAndTrees;
21 :     use Tracer;
22 :     use SeedUtils;
23 :     use ServerThing;
24 : parrello 1.1
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 : parrello 1.3 my $altObject = ALITREserver->new();
44 : parrello 1.1
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 : parrello 1.4 #
52 : parrello 1.1 # Actually, if you are using ALITRE.pm, you should do ALITRE->new(), not ALITREserver->new()
53 : parrello 1.4 # That comment above is for the benefit of the pod doc stuff on how to use ALITREserver
54 : parrello 1.1 # that is generated from this file.
55 :     #
56 :    
57 :     sub new {
58 : parrello 1.4 my ( $class, $sap ) = @_;
59 :    
60 :     # Create the sapling object.
61 :     if ( !defined $sap ) {
62 :     $sap = ERDB::GetDatabase('Sapling');
63 :     }
64 :    
65 :     # Create the server object.
66 :     my $retVal = { db => $sap };
67 :    
68 :     # Bless and return it.
69 :     bless $retVal, $class;
70 :     return $retVal;
71 : parrello 1.1 }
72 :    
73 :     =head1 Primary Methods
74 :    
75 :     =head2 Server Utility Methods
76 :    
77 :     You will not use the methods in this section very often. Currently, the only one
78 :     present (L</methods>) is used by the server framework for maintenance and control
79 :     purposes.
80 :    
81 :     =head3 methods
82 :    
83 :     my $methodList = $altObject->methods();
84 :    
85 :     Return a reference to a list of the methods allowed on this object.
86 :    
87 :     =cut
88 :    
89 : parrello 1.4 use constant METHODS => [
90 :     qw(
91 : fangfang 1.6 alignment_metadata_by_md5
92 :     alignments_metadata_by_md5
93 : parrello 1.4 alignment_tree_metadata
94 :     aligns_with_md5ID
95 :     all_alignIDs
96 :     all_treeIDs
97 :     expand_duplicate_tips
98 :     fid_align_and_tree_to_md5_version
99 :     fid_align_to_md5_align
100 :     fid_tree_to_md5_tree
101 :     get_projections
102 :     map_fid_to_md5
103 :     map_md5_to_fid
104 :     md5IDs_in_align
105 :     md5IDs_in_tree
106 :     md5_align_and_tree_by_ID
107 :     md5_align_and_tree_to_fid_version
108 :     md5_align_to_fid_align
109 :     md5_alignment_by_ID
110 : fangfang 1.5 md5_alignment_metadata
111 : parrello 1.4 md5_tree_by_ID
112 :     md5_tree_to_fid_tree
113 :     trees_with_md5ID
114 :     )
115 :     ];
116 : parrello 1.1
117 :     sub methods {
118 : parrello 1.4
119 :     # Get the parameters.
120 :     my ($self) = @_;
121 :    
122 :     # Return the result.
123 :     return METHODS;
124 : parrello 1.1 }
125 :    
126 :     =head2 Client Methods
127 :    
128 : parrello 1.3 =head3 alignment_tree_metadata
129 :    
130 :     my $alignHash = $altObject->alignment_tree_metadata({
131 :     -ids => [$alt1, $alt2, ...]
132 :     });
133 :    
134 :     Return the construction metadata for the alignment and tree in each specified
135 :     alignment/tree pair. The construction metadata describes how the alignment
136 :     and tree were built from the raw data.
137 :    
138 :     =over 4
139 :    
140 :     =item parameters
141 :    
142 :     The parameter should be a reference to a hash with the following keys:
143 :    
144 :     =over 8
145 :    
146 :     =item -ids
147 :    
148 :     Reference to a list of alignment/tree IDs.
149 :    
150 :     =back
151 :    
152 :     =item RETURN
153 :    
154 :     Returns a reference to a hash mapping each incoming alignment ID to a 6-tuple
155 :     of metadata information, including (0) the name of the method used to build
156 :     the alignment, (1) the parameters passed to the alignment method, (2) the
157 :     properties of the alignment process, (3) the name of the method used to build
158 :     the tree, (4) the parameters passed to the tree method, and (5) the properties
159 :     of the tree-building process.
160 :    
161 :     $alignHash => { $alt1 => [$almethod1, $alparms1, $alprops1,
162 :     $trmethod1, $trparms1, $trprops1],
163 :     $alt2 => [$almethod2, $alparms2, $alprops2,
164 :     $trmethod2, $trparms2, $trprops2],
165 :     ... };
166 :    
167 :     =back
168 :    
169 :     =cut
170 :    
171 :     sub alignment_tree_metadata {
172 : parrello 1.4
173 :     # Get the parameters.
174 :     my ( $self, $args ) = @_;
175 :    
176 :     # Get the Sapling database.
177 :     my $sap = $self->{db};
178 :    
179 :     # Create the return hash.
180 :     my $retVal = {};
181 :    
182 :     # Get the alignment IDs.
183 :     my $ids = ServerThing::GetIdList( -ids => $args );
184 :    
185 :     # Loop through the IDs, extracting the metadata.
186 :     for my $id (@$ids) {
187 :     $retVal->{$id} = AlignsAndTrees::alignment_tree_metadata( $sap, $id );
188 :     }
189 :    
190 :     # Return the result hash.
191 :     return $retVal;
192 : parrello 1.3 }
193 :    
194 :     =head3 aligns_with_md5ID
195 :    
196 :     my $protHash = $altObject->aligns_with_md5ID({
197 :     -ids => [$prot1, $prot2, ...]
198 :     });
199 :    
200 :     Return a list of the alignment/tree pairs containing each of the specified proteins.
201 :    
202 :     =over 4
203 :    
204 :     =item parameters
205 :    
206 :     The parameter should be a reference to a hash with the following keys:
207 :    
208 :     =over 8
209 :    
210 :     =item -ids
211 :    
212 :     Reference to a list of MD5 protein IDs.
213 :    
214 :     =back
215 :    
216 :     =item RETURN
217 :    
218 :     Returns a reference to a hash mapping each incoming protein ID to a list of the
219 :     IDs for the alignments containing that protein.
220 :    
221 :     $protHash = { $prot1 => [$alt1a, $alt1b, ...],
222 :     $prot2 => [$alt2a, $alt2b, ...],
223 :     ... };
224 :    
225 :     =back
226 :    
227 :     =cut
228 :    
229 :     sub aligns_with_md5ID {
230 : parrello 1.4
231 :     # Get the parameters.
232 :     my ( $self, $args ) = @_;
233 :    
234 :     # Get the Sapling database.
235 :     my $sap = $self->{db};
236 :    
237 :     # Create the return hash.
238 :     my $retVal = {};
239 :    
240 :     # Get the list of incoming IDs.
241 :     my $ids = ServerThing::GetIdList( -ids => $args );
242 :    
243 :     # Loop through the protein IDs, finding the alignments.
244 :     for my $id (@$ids) {
245 :     $retVal->{$id} = AlignsAndTrees::aligns_with_md5ID( $sap, $id );
246 :     }
247 :    
248 :     # Return the result hash.
249 :     return $retVal;
250 : parrello 1.3 }
251 :    
252 :     =head3 all_alignIDs
253 :    
254 :     my $idList = $altObject->all_alignIDs();
255 :    
256 :     Return a list of all the alignment IDs in the database.
257 :    
258 :     =over 4
259 :    
260 :     =item RETURN
261 :    
262 :     Returns a reference to a list of alignment IDs for all the alignments in the database.
263 :    
264 :     $idList = [$alt1, $alt2, ...];
265 :    
266 :     =back
267 :    
268 :     =cut
269 :    
270 :     sub all_alignIDs {
271 : parrello 1.4
272 :     # Get the parameters.
273 :     my ($self) = @_;
274 :    
275 :     # Get the sapling database.
276 :     my $sap = $self->{db};
277 :    
278 :     # Get the list of IDs.
279 :     my $retVal = AlignsAndTrees::all_alignIDs($sap);
280 :    
281 :     # Return it to the caller.
282 :     return $retVal;
283 : parrello 1.3 }
284 : parrello 1.1
285 : parrello 1.3 =head3 all_treeIDs
286 :    
287 :     my $idList = $altObject->all_treeIDs();
288 :    
289 :     Return a list of all the tree IDs in the database.
290 :    
291 :     =over 4
292 :    
293 :     =item RETURN
294 :    
295 :     Returns a reference to a list of IDs for all the trees in the database. (Note:
296 :     as currently construed, this is the same as a list of all the alignment IDs, since
297 :     each alignment has exactly one associated tree and it has the same ID.)
298 :    
299 :     $idList = [$alt1, $alt2, ...];
300 :    
301 :     =back
302 :    
303 :     =cut
304 :    
305 :     sub all_treeIDs {
306 : parrello 1.4 return all_alignIDs(@_);
307 : parrello 1.3 }
308 :    
309 :     =head3 expand_duplicate_tips
310 :    
311 :     my $newTree = $altObject->expand_duplicate_tips({
312 :     -tree => $actualTree,
313 :     -map => { $oldName1 => [$newName1a, $newName1b, ...],
314 :     $oldName2 => [$newName2a, $newName2b, ...],
315 :     ... }
316 : parrello 1.1 });
317 :    
318 : parrello 1.3 Rename and possibly expand the tips of the specified tree data structure using the
319 :     specified mapping.
320 :    
321 :     =over 4
322 :    
323 :     =item parameter
324 :    
325 :     The parameter should be a reference to a hash with the following keys.
326 :    
327 :     =over 8
328 :    
329 :     =item -tree
330 :    
331 :     Reference to a list that encodes a newick phylogenetic tree.
332 :    
333 :     =item -map
334 :    
335 :     Reference to a hash that maps node names to new node names. Each new node name is
336 :     a reference to a list of names. If the list is a singleton, the mapping is a simple
337 :     renaming. If the list contains muliple entries, the node will be expanded into duplicates.
338 :    
339 :     =back
340 :    
341 :     =item RETURN
342 :    
343 :     Returns a new version of the tree with the specified renamings performed.
344 :    
345 :     =back
346 :    
347 :     =cut
348 :    
349 :     sub expand_duplicate_tips {
350 : parrello 1.4
351 :     # Get the parameters.
352 :     my ( $self, $args ) = @_;
353 :    
354 :     # Get the incoming tree.
355 :     my $tree = $args->{-tree};
356 :     if ( !$tree ) {
357 :     Confess("Missing -tree parameter to expand_duplicate_tips.");
358 :     } elsif ( ref $tree ne 'ARRAY' ) {
359 :     Confess("Invalid -tree parameter for expand_duplicate_tips.");
360 :     }
361 :    
362 :     # Get the incoming name map.
363 :     my $map = $args->{-map};
364 :     if ( !$map ) {
365 :     Confess("Missing -map parameter to expand_duplicate_tips.");
366 :     } elsif ( ref $map ne 'HASH' ) {
367 :     Confess("Invalid -map parameter to expand_duplicate_tips.");
368 :     }
369 :    
370 :     # Perform the expansion. Note that the expansion is actually done in place,
371 :     # and the method simply returns the incoming argument.
372 :     my $retVal = AlignsAndTrees::expand_duplicate_tips( $tree, $map );
373 :    
374 :     # Return the modified tree.
375 :     return $retVal;
376 : parrello 1.3 }
377 :    
378 :     =head3 fid_align_and_tree_to_md5_version
379 :    
380 :     my $md5Tuple = $altObject->fid_align_and_tree_to_md5_version({
381 :     -align => $fid_align,
382 :     -tree => $fid_tree,
383 :     -meta => $fid_meta,
384 :     -relaxed => 1
385 :     });
386 :    
387 :     Convert a PEG-based alignment/tree pair to an MD5-based alignment/tree pair. Each
388 :     PEG identifier in the alignment and tree will be converted to the corresponding MD5
389 :     protein identifier. This may cause some nodes in the tree and items in the alignment
390 :     to be collapsed into a single instance, since multiple PEGs can produce the same
391 :     protein.
392 :    
393 :     =over 4
394 :    
395 :     =item parameter
396 :    
397 :     The parameter should be a reference to a hash with the following keys:
398 :    
399 :     =over 8
400 :    
401 :     =item -align
402 :    
403 :     The PEG-based alignment to convert.
404 :    
405 :     =item -tree
406 :    
407 :     The corresponding phylogenetic tree.
408 :    
409 :     =item -meta
410 :    
411 :     Reference to a hash mapping each feature ID in the alignment and tree to a
412 :     description of which part of the resulting protein was used.
413 :    
414 :     =item -relaxed (optional)
415 :    
416 :     If TRUE, then incoming feature IDs that are not found in the database will be
417 :     left untranslated in the output. Otherwise, such IDs will cause an error. The
418 :     default is FALSE.
419 :    
420 :     =back
421 :    
422 :     =item RETURN
423 :    
424 :     Returns a reference to a 3-tuple containing (0) the MD5 version of the incoming
425 :     alignment, (1) the MD5 version of the incoming tree, and (2) a reference to a
426 :     hash describing which portion of each protein was used in the alignment.
427 :    
428 :     $md5Tuple = [$md5_align, $md5_tree, $md5_metadata];
429 :    
430 :     =back
431 :    
432 :     =cut
433 :    
434 :     sub fid_align_and_tree_to_md5_version {
435 : parrello 1.4
436 :     # Get the parameters.
437 :     my ( $self, $args ) = @_;
438 :    
439 :     # Get the Sapling database.
440 :     my $sap = $self->{db};
441 :    
442 :     # Get the parameters.
443 :     my $align = $args->{-align}
444 :     || Confess("No alignment specified in fid_align_and_tree_to_fid_version.");
445 :     my $tree = $args->{-tree}
446 :     || Confess("No tree specified in fid_align_and_tree_to_fid_version.");
447 :     my $meta = $args->{-meta}
448 :     || Confess("No metadata specified in fid_align_and_tree_to_fid_version.");
449 :     my $relaxed = $args->{-relaxed} || 0;
450 :    
451 :     # Convert the alignment and tree.
452 :     my ( $newAlign, $newTree, $newMeta ) =
453 :     AlignsAndTrees::fid_align_and_tree_to_md5_version( $sap, $align, $tree,
454 :     $meta, $relaxed );
455 :    
456 :     # Return the results.
457 :     return [ $newAlign, $newTree, $newMeta ];
458 : parrello 1.3
459 :     }
460 :    
461 :     =head3 fid_align_to_md5_align
462 :    
463 :     my $md5align = $altObject->fid_align_to_md5_align({
464 :     -align => $fid_align,
465 :     -map => $fid_to_md5_map
466 :     });
467 :    
468 :     Use a map produced by L</map_fid_to_md5> to convert a PEG-based tree to an MD5-based tree.
469 :    
470 :     =over 4
471 :    
472 :     =item parameter
473 :    
474 :     The parameter should be a reference to a hash with the following keys:
475 :    
476 :     =over 8
477 :    
478 :     =item -align
479 :    
480 :     The PEG-based alignment to be converted.
481 :    
482 :     =item -map
483 :    
484 :     A hash tha maps each feature ID in the alignment to the corresponding MD5 protein
485 :     ID.
486 :    
487 :     =back
488 :    
489 :     =item RETURN
490 :    
491 :     Returns a new version of the alignment with the feature IDs replaced by MD5 protein
492 :     IDs using the data in the map.
493 :    
494 :     =back
495 :    
496 :     =cut
497 :    
498 :     sub fid_align_to_md5_align {
499 : parrello 1.4
500 :     # Get the parameters.
501 :     my ( $self, $args ) = @_;
502 :    
503 :     # Get the incoming alignment and map.
504 :     my $align = $args->{-align}
505 :     || Confess("No alignment specified in fid_align_to_md5_align.");
506 :     my $map = $args->{-map}
507 :     || Confess("No map specified in fid_align_to_md5_align,");
508 :    
509 :     # Perform the conversion.
510 :     my $retVal = AlignsAndTrees::fid_align_to_md5_align( $align, $map );
511 :    
512 :     # Return the result.
513 :     return $retVal;
514 : parrello 1.3 }
515 :    
516 :     =head3 fid_tree_to_md5_tree
517 :    
518 :     my $md5tree = $altObject->fid_tree_to_md5_tree({
519 :     -tree => $fid_tree,
520 :     -map => $fid_to_md5_map
521 :     });
522 :    
523 :     Use a map produced by L</map_fid_to_md5> to convert a PEG-based tree to an MD5-based tree.
524 :    
525 :     =over 4
526 :    
527 :     =item parameter
528 :    
529 :     The parameter should be a reference to a hash with the following keys:
530 :    
531 :     =over 8
532 :    
533 :     =item -tree
534 :    
535 :     The PEG-based tree to be converted.
536 :    
537 :     =item -map
538 :    
539 :     A hash tha maps each feature ID in the tree to the corresponding MD5 protein
540 :     ID.
541 :    
542 :     =back
543 :    
544 :     =item RETURN
545 :    
546 :     Returns a new version of the tree with the feature IDs replaced by MD5 protein
547 :     IDs using the data in the map.
548 :    
549 :     =back
550 :    
551 :     =cut
552 :    
553 :     sub fid_tree_to_md5_tree {
554 : parrello 1.4
555 :     # Get the parameters.
556 :     my ( $self, $args ) = @_;
557 :    
558 :     # Get the incoming tree and map.
559 :     my $tree = $args->{-tree}
560 :     || Confess("No tree specified in fid_tree_to_md5_tree.");
561 :     my $map = $args->{-map}
562 :     || Confess("No map specified in fid_tree_to_md5_tree,");
563 :    
564 :     # Perform the conversion.
565 :     my $retVal = AlignsAndTrees::fid_tree_to_md5_tree( $tree, $map );
566 :    
567 :     # Return the result.
568 :     return $retVal;
569 :     }
570 :    
571 :     =head3 get_projections
572 :    
573 :     my $protHash = $altObject->get_projections({
574 :     -ids => [$prot1, $prot2, ...],
575 :     -minScore => 0,
576 :     -details => 1
577 :     });
578 :    
579 :     Get all the proteins that are clear bidirectional best hits (projections) of the
580 :     specified proteins. The call can specify whether or not to include the details of
581 :     the projection (score, context, percent identity) and also whether to only include
582 :     projections with a certain minimum score.
583 :    
584 :     =over 4
585 :    
586 :     =item parameter
587 :    
588 :     The parameter should be a reference to a hash with the following keys.
589 :    
590 :     =over 8
591 :    
592 :     =item -ids
593 :    
594 :     Reference to a list of MD5 protein IDs.
595 :    
596 :     =item -minScore (optional)
597 :    
598 :     Minimum score for projections to be included. Only projections with the specified
599 :     score or greater will be included in the output. The score ranges from 0 to 1. The
600 :     default is C<0>, which includes everything.
601 :    
602 :     =item -details (optional)
603 :    
604 :     If TRUE, then for each projected protein, the gene-context count, percent identity,
605 :     and score will be included in the output. The default is FALSE (only the protein IDs
606 :     are returned).
607 :    
608 :     =back
609 :    
610 :     =item RETURN
611 :    
612 :     Returns a reference to a hash mapping each incoming protein ID to a list of the
613 :     proteins that are clear bidirectional best hits. If C<-details> is FALSE, each
614 :     protein will be represented by its MD5 protein ID. If C<-details> is TRUE, each
615 :     protein will be represented by a 4-tuple consisting of (0) the MD5 protein ID,
616 :     (1) the number of homologous genes in the immediate context of the two proteins
617 :     (up to a maximum of 10), (2) the percent match between the two protein sequences,
618 :     and (3) the score of the projections (0 to 1).
619 :    
620 :     =over 8
621 :    
622 :     =item -details FALSE
623 :    
624 :     $protHash = { $prot1 => [$prot1a, $prot1b, ...],
625 :     $prot2 => [$prot2a, $prot2b, ...],
626 :     ... };
627 :    
628 :     =item -details TRUE
629 :    
630 :     $protHash = { $prot1 => [[$prot1a, $context1a, $match1a, $score1a],
631 :     [$prot1b, $context1b, $match1b, $score1b],
632 :     ... ],
633 :     $prot2 => [[$prot2a, $context2a, $match2a, $score2a],
634 :     [$prot2b, $context2b, $match2b, $score2b],
635 :     ... ],
636 :     ... };
637 :    
638 :     =back
639 :    
640 :     =back
641 :    
642 :     =cut
643 :    
644 :     sub get_projections {
645 : parrello 1.3 # Get the parameters.
646 :     my ($self, $args) = @_;
647 : parrello 1.4 # Get the sapling database.
648 :     my $sap = $self->{db};
649 :     # Get the list of protein IDs.
650 :     my $ids = ServerThing::GetIdList(-ids => $args);
651 :     # Compute the minimum score.
652 :     my $minScore = $args->{-minScore} || 0;
653 :     # Compute the detail level.
654 :     my $details = ($args->{-details} ? 1 : 0);
655 :     # Create the return variable.
656 :     my $retVal = {};
657 :     # Loop through the proteins.
658 :     for my $id (@$ids) {
659 :     # Compute the filter parameters.
660 :     my $parms = [$id, $minScore];
661 :     # We'll put our query results in here. The query itself depends on the
662 :     # details mode.
663 :     my @projections;
664 :     # The query has to be tried twice: once from each direction.
665 :     for my $rel (qw(ProjectsOnto IsProjectedOnto)) {
666 :     if ($details) {
667 :     # Here we have a detailed projection request.
668 :     push @projections, $sap->GetAll($rel,
669 :     "$rel(from-link) = ? AND $rel(score) >= ?",
670 :     $parms, "to-link gene-context percent-identity score");
671 :     } else {
672 :     # Here we want only the projected protein ID.
673 :     push @projections, $sap->GetFlat($rel,
674 :     "$rel(from-link) = ? AND $rel(score) >= ?", $parms, "to-link");
675 :     }
676 :     }
677 :     # Store the results found in the return hash.
678 :     $retVal->{$id} = \@projections;
679 :     }
680 :     # Return the hash of results.
681 : parrello 1.3 return $retVal;
682 :     }
683 :    
684 :     =head3 map_fid_to_md5
685 :    
686 :     my $md5Tuple = $altObject->map_fid_to_md5({
687 :     -meta => $fid_metadata,
688 :     -relaxed => 0
689 :     });
690 :    
691 :     Analyze the metadata for a PEG-basedalignment/tree pair and compute the metadata for
692 :     the corresponding MD5-based data structions along with a mapping from the PEG IDs
693 :     to MD5 IDs.
694 :    
695 :     =over 4
696 :    
697 :     =item parameter
698 :    
699 :     Reference to a hash with the following keys:
700 :    
701 :     =over 8
702 :    
703 :     =item -meta
704 :    
705 :     Reference to a hash mapping each FIG feature ID in an alignment/tree pair to
706 :     information describing which part of each feature's protein was used.
707 :    
708 :     =item -relaxed (optional)
709 :    
710 :     If TRUE, then incoming feature IDs that are not found in the database will be
711 :     left untranslated in the output. Otherwise, such IDs will cause an error. The
712 :     default is FALSE.
713 :    
714 :     =back
715 :    
716 :     =item RETURN
717 :    
718 :     Returns a reference to a 2-tuple containing (0) the MD5-based metadata hash
719 :     creating from the incoming hash and (1) a hash mapping each incoming feature ID
720 :     to the corresponding MD5 protein ID.
721 :    
722 :     $md5Tuple => [$md5_metadata, { $fida => $md5a, $fidb => $md5b, ... }];
723 :    
724 :     =back
725 :    
726 :     =cut
727 :    
728 :     sub map_fid_to_md5 {
729 : parrello 1.4
730 :     # Get the parameters.
731 :     my ( $self, $args ) = @_;
732 :    
733 :     # Get the Sapling database.
734 :     my $sap = $self->{db};
735 :    
736 :     # Get the metadata structure.
737 :     my $meta = $args->{-meta}
738 :     || Confess("No metadata structure passed to map_fid_to_md5.");
739 :    
740 :     # Compute the relax flag.
741 :     my $relaxed = $args->{-relaxed} || 0;
742 :    
743 :     # Perform the conversion.
744 :     my ( $newMeta, $map ) =
745 :     AlignsAndTrees::map_fid_to_md5( $sap, $meta, $relaxed );
746 :    
747 :     # Return the result.
748 :     return [ $newMeta, $map ];
749 : parrello 1.3 }
750 :    
751 :     =head3 map_md5_to_fid
752 :    
753 :     my $fidTuple = $altObject->map_md5_to_fid({
754 :     -meta => $md5_metadata,
755 :     -relaxed => 0
756 :     });
757 :    
758 :     Analyze the metadata for an MD5 alignment/tree pair and compute the metadata for
759 :     the corresponding PEG-based data structions along with a mapping from the MD5 IDs
760 :     to the PEG IDs.
761 :    
762 :     =over 4
763 :    
764 :     =item parameter
765 :    
766 :     Reference to a hash with the following keys:
767 :    
768 :     =over 8
769 :    
770 :     =item -meta
771 :    
772 :     Reference to a hash mapping each MD5 protein ID in an alignment/tree pair to
773 :     information describing which part of each protein was used.
774 :    
775 :     =item -relaxed (optional)
776 :    
777 :     If TRUE, then incoming MD5 IDs that are not found in the database will be
778 :     left untranslated in the output. Otherwise, such IDs will cause an error. The
779 :     default is FALSE.
780 :    
781 :     =back
782 :    
783 :     =item RETURN
784 :    
785 :     Returns a reference to a 2-tuple containing (0) the PEG-based metadata hash
786 :     created from the incoming hash and (1) a hash mapping each incoming MD5 protein
787 :     ID to a list of corresponding FIG feature IDs.
788 :    
789 :     $fidTuple => [$fid_metadata, { $md5a => [$fida1, $fida2, ...],
790 :     $md5b => [$fidb1, $fidb2, ...],
791 :     ... }];
792 :    
793 :     =back
794 :    
795 :     =cut
796 :    
797 :     sub map_md5_to_fid {
798 : parrello 1.4
799 :     # Get the parameters.
800 :     my ( $self, $args ) = @_;
801 :    
802 :     # Get the Sapling database.
803 :     my $sap = $self->{db};
804 :    
805 :     # Get the metadata structure.
806 :     my $meta = $args->{-meta}
807 :     || Confess("No metadata structure passed to map_md5_to_fid.");
808 :    
809 :     # Compute the relax flag.
810 :     my $relaxed = $args->{-relaxed} || 0;
811 :    
812 :     # Perform the conversion.
813 :     my ( $newMeta, $map ) =
814 :     AlignsAndTrees::map_md5_to_fid( $sap, $meta, $relaxed );
815 :    
816 :     # Return the result.
817 :     return [ $newMeta, $map ];
818 : parrello 1.3 }
819 :    
820 :     =head3 md5IDs_in_align
821 :    
822 :     my $altHash = $altObject->md5IDs_in_align({
823 :     -ids => [$alt1, $alt2, ...]
824 :     });
825 :    
826 :     For each incoming alignment ID, return a list of the MD5 protein IDs for the proteins
827 :     found in the alignment.
828 : parrello 1.1
829 :     =over 4
830 :    
831 :     =item parameter
832 :    
833 :     The parameter should be a reference to a hash with the following keys:
834 :    
835 :     =over 8
836 :    
837 :     =item -ids
838 :    
839 : parrello 1.3 Reference to a list of alignment IDs.
840 : parrello 1.1
841 :     =back
842 :    
843 :     =item RETURN
844 :    
845 : parrello 1.3 Returns a reference to a hash mapping each incoming alignment ID to a list of
846 :     the proteins found in the alignment. Each protein is represented by an MD5 protein
847 :     ID.
848 : parrello 1.1
849 : parrello 1.3 $altHash = { $alta => [$md5a1, $md5a2, ... ],
850 :     $altb => [$md5b1, $md5b2, ... ],
851 : parrello 1.1 ... };
852 :    
853 :     =back
854 :    
855 :     =cut
856 :    
857 : parrello 1.3 sub md5IDs_in_align {
858 : parrello 1.4
859 :     # Get the parameters.
860 :     my ( $self, $args ) = @_;
861 :    
862 :     # Get the list of alignment IDs.
863 :     my $ids = ServerThing::GetIdList( -ids => $args );
864 :    
865 :     # Get the sapling database.
866 :     my $sap = $self->{db};
867 :    
868 :     # Declare the return hash.
869 :     my $retVal = {};
870 :    
871 :     # Loop through the incoming IDs.
872 :     for my $id (@$ids) {
873 :    
874 :     # Get the MD5s for this alignment.
875 :     my $md5List = AlignsAndTrees::md5IDs_in_align( $sap, $id );
876 :    
877 :     # Store them in the return hash.
878 :     $retVal->{$id} = $md5List;
879 :     }
880 :    
881 :     # Return the result hash.
882 :     return $retVal;
883 : parrello 1.1 }
884 :    
885 : parrello 1.3 =head3 md5IDs_in_tree
886 :    
887 :     my $altHash = $altObject->md5IDs_in_tree({
888 :     -ids => [$alt1, $alt2, ...]
889 :     });
890 : parrello 1.1
891 : parrello 1.3 For each incoming tree ID, return a list of the MD5 protein IDs for the proteins
892 :     found in the tree.
893 : parrello 1.1
894 :     =over 4
895 :    
896 :     =item parameter
897 :    
898 : parrello 1.3 The parameter should be a reference to a hash with the following keys:
899 : parrello 1.1
900 :     =over 8
901 :    
902 :     =item -ids
903 :    
904 : parrello 1.3 Reference to a list of tree IDs.
905 : parrello 1.1
906 :     =back
907 :    
908 :     =item RETURN
909 :    
910 : parrello 1.3 Returns a reference to a hash mapping each incoming tree ID to a list of
911 :     the proteins found in the tree. Each protein is represented by an MD5 protein
912 :     ID.
913 : parrello 1.1
914 : parrello 1.3 $altHash = { $alta => [$md5a1, $md5a2, ... ],
915 :     $altb => [$md5b1, $md5b2, ... ],
916 : parrello 1.1 ... };
917 :    
918 :     =back
919 :    
920 :     =cut
921 :    
922 : parrello 1.3 sub md5IDs_in_tree {
923 : parrello 1.4
924 :     # Get the parameters.
925 :     my ( $self, $args ) = @_;
926 :    
927 :     # Get the list of tree IDs.
928 :     my $ids = ServerThing::GetIdList( -ids => $args );
929 :    
930 :     # Get the sapling database.
931 :     my $sap = $self->{db};
932 :    
933 :     # Declare the return hash.
934 :     my $retVal = {};
935 :    
936 :     # Loop through the incoming IDs.
937 :     for my $id (@$ids) {
938 :    
939 :     # Get the MD5s for this tree.
940 :     my $md5List = AlignsAndTrees::md5IDs_in_tree( $sap, $id );
941 :    
942 :     # Store them in the return hash.
943 :     $retVal->{$id} = $md5List;
944 :     }
945 :    
946 :     # Return the result hash.
947 :     return $retVal;
948 : parrello 1.1 }
949 :    
950 : parrello 1.3 =head3 md5_align_and_tree_by_ID
951 : parrello 1.1
952 : parrello 1.3 my $tupleHash = $altObject->md5_align_and_tree_by_ID({
953 :     -ids => [$alt1, $alt2, ...]
954 :     });
955 :    
956 :     Return the alignment and tree for each specified ID. The return hash will contain
957 :     a 3-tuple for each tree ID consisting of the alignment, the tree, and the metadata
958 :     describing the proteins involved.
959 : parrello 1.1
960 :     =over 4
961 :    
962 : parrello 1.3 =item parameter
963 :    
964 :     The parameter should be a reference to a hash with the following keys:
965 :    
966 :     =over 8
967 :    
968 :     =item -ids
969 :    
970 :     Reference to a list of alignment/tree pair IDs.
971 :    
972 :     =back
973 :    
974 : parrello 1.1 =item RETURN
975 :    
976 : parrello 1.3 Returns a reference to a hash mapping each incoming ID to a 3-tuple containing (0) the
977 :     identified MD5 protein alignment, (1) the associated phylogenetic tree, and (2) a
978 :     hash describing what portion of each protein was used in the alignment.
979 :    
980 :     $tupleHash = { $alt1 => [$md5_align1, $md5_tree1, $md5_metadata1],
981 :     $alt2 => [$md5_align2, $md5_tree2, $md5_metadata2],
982 :     ... };
983 : parrello 1.1
984 :     =back
985 :    
986 :     =cut
987 :    
988 : parrello 1.3 sub md5_align_and_tree_by_ID {
989 : parrello 1.4
990 :     # Get the parameters.
991 :     my ( $self, $args ) = @_;
992 :    
993 :     # Get the Sapling database.
994 :     my $sap = $self->{db};
995 :    
996 :     # Declare the return hash.
997 :     my $retVal = {};
998 :    
999 :     # Get the list of incoming IDs.
1000 :     my $ids = ServerThing::GetIdList( -ids => $args );
1001 :    
1002 :     # Loop through the list.
1003 :     for my $id (@$ids) {
1004 :    
1005 :     # Get the alignment and the metadata.
1006 :     my ( $align, $meta ) = AlignsAndTrees::md5_alignment_by_ID( $sap, $id );
1007 :    
1008 :     # Get the tree as well.
1009 :     my $tree = AlignsAndTrees::md5_tree_by_ID( $sap, $id );
1010 :    
1011 :     # Return all three items.
1012 :     $retVal->{$id} = [ $align, $tree, $meta ];
1013 :     }
1014 :    
1015 :     # Return the result hash.
1016 :     return $retVal;
1017 : parrello 1.1 }
1018 :    
1019 : parrello 1.3 =head3 md5_align_and_tree_to_fid_version
1020 :    
1021 :     my $fidTuple = $altObject->md5_align_and_tree_to_fid_version({
1022 :     -align => $md5_align,
1023 :     -tree => $md5_tree,
1024 :     -meta => $md5_metadata,
1025 :     -relaxed => 1
1026 :     });
1027 :    
1028 :     Convert an MD5 alignment/tree pair to a PEG-based alignment-tree pair. Each protein in
1029 :     the alignment or tree will be translated to a corresponding FIG feature ID. In some
1030 :     cases, this may cause a single protein to be replicated to include all the features
1031 :     that produce that protein.
1032 :    
1033 :     =over 4
1034 :    
1035 :     =item parameter
1036 :    
1037 :     The parameter should be a reference to a hash with the following keys.
1038 :    
1039 :     =over 8
1040 :    
1041 :     =item -align
1042 :    
1043 :     Reference to the MD5 alignment to be converted.
1044 :    
1045 :     =item -tree
1046 :    
1047 :     Reference to the corresponding phylogenetic tree.
1048 :    
1049 :     =item -meta
1050 :    
1051 :     Reference to a hash mapping each MD5 protein ID in the alignment and tree to a
1052 :     description of what section of the protein was used.
1053 :    
1054 :     =item -relaxed (optional)
1055 :    
1056 :     If TRUE, then incoming feature IDs that are not found in the database will be
1057 :     left untranslated in the output. Otherwise, such IDs will cause an error. The
1058 :     default is FALSE.
1059 :    
1060 :     =back
1061 :    
1062 :     =item RETURN
1063 :    
1064 :     Returns a reference to a 3-tuple containing (0) a PEG-based version of the
1065 :     incoming alignment, (1) a PEG-based version of the incoming tree, and (2) a
1066 :     reference to a hash mapping each feature ID in the new alignment and tree to
1067 :     a description of what section of the feature's protein was used.
1068 :    
1069 :     $fidTuple = [$fid_align, $fid_tree, $fid_metadata];
1070 :    
1071 :     =back
1072 :    
1073 :     =cut
1074 :    
1075 :     sub md5_align_and_tree_to_fid_version {
1076 : parrello 1.4
1077 :     # Get the parameters.
1078 :     my ( $self, $args ) = @_;
1079 :    
1080 :     # Get the sapling database.
1081 :     my $sap = $self->{db};
1082 :    
1083 :     # Get the parameters.
1084 :     my $align = $args->{-align}
1085 :     || Confess("No alignment specified in md5_align_and_tree_to_fid_version.");
1086 :     my $tree = $args->{-tree}
1087 :     || Confess("No tree specified in md5_align_and_tree_to_fid_version.");
1088 :     my $meta = $args->{-meta}
1089 :     || Confess("No metadata specified in md5_align_and_tree_to_fid_version.");
1090 :     my $relaxed = $args->{-relaxed} || 0;
1091 :    
1092 :     # Convert the alignment and tree.
1093 :     my ( $newAlign, $newTree, $newMeta ) =
1094 :     AlignsAndTrees::md5_align_and_tree_to_fid_version( $sap, $align, $tree,
1095 :     $meta, $relaxed );
1096 :    
1097 :     # Return the results.
1098 :     return [ $newAlign, $newTree, $newMeta ];
1099 : parrello 1.3 }
1100 : parrello 1.1
1101 : parrello 1.3 =head md5_align_to_fid_align
1102 : parrello 1.1
1103 : parrello 1.3 my $fidAlign = $altObject->md5_align_to_fid_align({
1104 :     -align => $md5_align,
1105 :     -map => $md5_to_fid_map
1106 :     });
1107 :    
1108 :     Use a map produced by L</map_fid_to_md5> to convert an MD5-based alignment to a PEG-based
1109 :     alignment. Since a single protein may be generated by multiple features, this could
1110 :     result in alignment entries being replicated in the result.
1111 : parrello 1.1
1112 :     =over 4
1113 :    
1114 : parrello 1.3 =item parameter
1115 :    
1116 :     The parameter should be a reference to a hash containing the following keys.
1117 :    
1118 :     =over 8
1119 :    
1120 :     =item -align
1121 :    
1122 :     The MD5-based alignment to be converted.
1123 :    
1124 :     =item -map
1125 :    
1126 :     Reference to a hash mapping each MD5 protein ID to a list of the corresponding FIG
1127 :     feature IDs.
1128 :    
1129 :     =back
1130 :    
1131 :     =item RETURN
1132 :    
1133 :     Returns a new version of the alignment with the MD5 protein IDs replaced by FIG
1134 :     feature IDs.
1135 :    
1136 :     =back
1137 :    
1138 :     =cut
1139 :    
1140 :     sub md5_align_to_fid_align {
1141 : parrello 1.4
1142 :     # Get the parameters.
1143 :     my ( $self, $args ) = @_;
1144 :    
1145 :     # Get the alignment and the map.
1146 :     my $align = $args->{-align}
1147 :     || Confess("No alignment specified in md5_align_to_fid_align.");
1148 :     my $map = $args->{-map}
1149 :     || Confess("No map specified in md5_align_to_fid_align.");
1150 :    
1151 :     # Perform the conversion.
1152 :     my $retVal = AlignsAndTrees::md5_align_to_fid_align( $align, $map );
1153 :    
1154 :     # Return the result.
1155 :     return $retVal;
1156 : parrello 1.3 }
1157 :    
1158 :     =head3 md5_alignment_by_ID
1159 :    
1160 :     my $altHash = $altObject->md5_alignment_by_ID({
1161 :     -ids => [$alt1, $alt2, ...]
1162 :     });
1163 :    
1164 :     Return the alignments with the specified IDs. The return hash will contain a
1165 :     2-tuple for each alignment ID consisting of the alignment itself followed by
1166 :     the metadata describing the proteins in the alignment.
1167 :    
1168 : parrello 1.1 =over 4
1169 :    
1170 :     =item parameter
1171 :    
1172 : parrello 1.3 The parameter should be a reference to a hash with the following keys:
1173 : parrello 1.1
1174 :     =over 8
1175 :    
1176 : parrello 1.3 =item -ids
1177 : parrello 1.1
1178 : parrello 1.3 Reference to a list of alignment IDs.
1179 : parrello 1.1
1180 :     =back
1181 :    
1182 :     =item RETURN
1183 :    
1184 : parrello 1.3 Returns a reference to a hash mapping each incoming ID to an MD5 alignment.
1185 : parrello 1.1
1186 : parrello 1.3 $altHash = { $alt1 => $md5_align1, $alt2 => $md5_align2, ... };
1187 : parrello 1.1
1188 :     =back
1189 :    
1190 :     =cut
1191 :    
1192 : parrello 1.3 sub md5_alignment_by_ID {
1193 : parrello 1.4
1194 :     # Get the parameters.
1195 :     my ( $self, $args ) = @_;
1196 :    
1197 :     # Get the Sapling database.
1198 :     my $sap = $self->{db};
1199 :    
1200 :     # Get the list of incoming IDs.
1201 :     my $ids = ServerThing::GetIdList( -ids => $args );
1202 :    
1203 :     # Declare the return hash.
1204 :     my $retVal = {};
1205 :    
1206 :     # Loop through the incoming IDs.
1207 :     for my $id (@$ids) {
1208 :    
1209 :     # Get the tree and metadata for this ID.
1210 :     $retVal->{$id} = [ AlignsAndTrees::md5_alignment_by_ID( $sap, $id ) ];
1211 :     }
1212 :    
1213 :     # Return the result hash.
1214 :     return $retVal;
1215 : parrello 1.3
1216 : parrello 1.1 }
1217 :    
1218 : fangfang 1.5
1219 :     =head3 md5_alignment_metadata
1220 :    
1221 :     my $alignHash = $altObject->md5_alignment_metadata({
1222 :     -ids => [$alignID1, alignID2, ...]
1223 :     });
1224 :    
1225 :     Return the sequence metadata for the alignment.
1226 :    
1227 :     =over 4
1228 :    
1229 :     =item parameters
1230 :    
1231 :     The parameter should be a reference to a hash with the following keys:
1232 :    
1233 :     =over 8
1234 :    
1235 :     =item -ids
1236 :    
1237 :     Reference to a list of alignment/tree IDs.
1238 :    
1239 :     =back
1240 :    
1241 :     =item RETURN
1242 :    
1243 :     Returns a reference to a hash mapping each incoming alignment ID to a 5-tuple
1244 :     of metadata information.
1245 :    
1246 :     $metadataHash => { $alignID1 => [ $md5, $peg_length, $trim_beg, $trim_end, $location_string ],
1247 :     $alignID2 => [ $md5, $peg_length, $trim_beg, $trim_end, $location_string ],
1248 :     ... };
1249 :    
1250 :     =back
1251 :    
1252 :     =cut
1253 :    
1254 :     sub md5_alignment_metadata {
1255 : fangfang 1.6 my ($self, $args) = @_;
1256 : fangfang 1.5 my $sap = $self->{db};
1257 :     my $ids = ServerThing::GetIdList( -ids => $args );
1258 :     my $retVal = {};
1259 :    
1260 :     for my $id (@$ids) {
1261 :     $retVal->{$id} = AlignsAndTrees::md5_alignment_metadata( $sap, $id );
1262 :     }
1263 :    
1264 :     return $retVal;
1265 :     }
1266 :    
1267 :    
1268 : fangfang 1.6 =head3 alignment_metadata_by_md5
1269 :    
1270 :     my $alignHash = $altObject->alignment_metadata_by_md5({
1271 :     -ids => [$alignID, md5ID1, md5ID2, ...]
1272 :     });
1273 :    
1274 :     Return the sequence metadata for the alignment.
1275 :    
1276 :     =over 4
1277 :    
1278 :     =item parameters
1279 :    
1280 :     The parameter should be a reference to a hash with the following keys:
1281 :    
1282 :     =over 8
1283 :    
1284 :     =item -ids
1285 :    
1286 :     Reference to a list of alignment whose first element is an align ID followed by MD5 IDs.
1287 :    
1288 :     =back
1289 :    
1290 :     =item RETURN
1291 :    
1292 :     Returns a reference to a hash mapping each alignmen row ID to a 5-tuple
1293 :     of metadata information.
1294 :    
1295 :     $metadataHash => { $seqID1 => [ $md5, $peg_length, $trim_beg, $trim_end, $location_string ],
1296 :     $seqID2 => [ $md5, $peg_length, $trim_beg, $trim_end, $location_string ],
1297 :     ... };
1298 :    
1299 :     =back
1300 :    
1301 :     =cut
1302 :    
1303 :     sub alignment_metadata_by_md5 {
1304 :     my ($self, $args) = @_;
1305 :     my $sap = $self->{db};
1306 :     my $ids = ServerThing::GetIdList( -ids => $args );
1307 :    
1308 :     my ($alignID, @md5IDs) = @$ids;
1309 :    
1310 :     my $metadata = AlignsAndTrees::alignment_metadata_by_md5( $sap, $alignID, @md5IDs );
1311 :    
1312 :     return $metadata;
1313 :     }
1314 :    
1315 :    
1316 :     =head3 alignments_metadata_by_md5
1317 :    
1318 :     my $metadataHash = $altObject->alignments_metadata_by_md5({
1319 :     -ids => [md5ID1, md5ID2, ...]
1320 :     });
1321 :    
1322 :     Return the sequence metadata for the alignment.
1323 :    
1324 :     =over 4
1325 :    
1326 :     =item parameters
1327 :    
1328 :     The parameter should be a reference to a hash with the following keys:
1329 :    
1330 :     =over 8
1331 :    
1332 :     =item -ids
1333 :    
1334 :     Reference to a list of MD5 IDs.
1335 :    
1336 :     =back
1337 :    
1338 :     =item RETURN
1339 :    
1340 :     Returns a reference to a list of a 7-tuple of metadata information.
1341 :    
1342 :     $metadataList => [ [ $alignID1, $seqID1, $md5, $peg_length, $trim_beg, $trim_end, $location_string ],
1343 :     [ $alignID2, $seqID2, $md5, $peg_length, $trim_beg, $trim_end, $location_string ],
1344 :     ... ] ];
1345 :    
1346 :     =back
1347 :    
1348 :     =cut
1349 :    
1350 :     sub alignments_metadata_by_md5 {
1351 :     my ($self, $args) = @_;
1352 :     my $sap = $self->{db};
1353 :     my $ids = ServerThing::GetIdList( -ids => $args );
1354 :    
1355 :     my @md5IDs = @$ids;
1356 :    
1357 :     my $metadata = AlignsAndTrees::alignments_metadata_by_md5( $sap, @md5IDs );
1358 :    
1359 :     return $metadata;
1360 :     }
1361 : fangfang 1.5
1362 :    
1363 : parrello 1.3 =head3 md5_tree_by_ID
1364 :    
1365 :     my $tupleHash = $altObject->md5_tree_by_ID({
1366 :     -ids => [$alt1, $alt2, ...]
1367 :     });
1368 :    
1369 :     Return the trees with the specified IDs. The return hash will contain a 2-tuple
1370 :     for each tree ID consisting of the tree itself followed by the metadata describing
1371 :     the proteins in the tree.
1372 :    
1373 :     =over 4
1374 :    
1375 :     =item parameter
1376 :    
1377 :     The parameter should be a reference to a hash with the following keys:
1378 :    
1379 :     =over 8
1380 :    
1381 :     =item -ids
1382 : parrello 1.1
1383 : parrello 1.3 Reference to a list of tree IDs.
1384 : parrello 1.1
1385 : parrello 1.3 =back
1386 :    
1387 :     =item RETURN
1388 :    
1389 :     Returns a reference to a hash that maps each incoming tree ID to a 2-tuple consisting of
1390 :     (0) a data structure containing the identified phylogenetic tree represented as a
1391 :     newick-format list, and (1) a hash containing the metadata for the leaves of the tree.
1392 :    
1393 :     $tupleHash = { $tree1 => [$md5_tree1, $md5_metadata1],
1394 :     $tree2 => [$md5_tree2, $md5_metadata2],
1395 :     ... };
1396 :    
1397 :     =back
1398 :    
1399 :     =cut
1400 :    
1401 :     sub md5_tree_by_ID {
1402 : parrello 1.4
1403 :     # Get the parameters.
1404 :     my ( $self, $args ) = @_;
1405 :    
1406 :     # Get the sapling database.
1407 :     my $sap = $self->{db};
1408 :    
1409 :     # Get the incoming IDs.
1410 :     my $ids = ServerThing::GetIdList( -ids => $args );
1411 :    
1412 :     # Declare the return hash.
1413 :     my $retVal = {};
1414 :    
1415 :     # Loop through the incoming IDs.
1416 :     for my $id (@$ids) {
1417 :    
1418 :     # Get the tree and metadata for this ID.
1419 :     $retVal->{$id} = [ AlignsAndTrees::md5_tree_by_ID( $sap, $id ) ];
1420 :     }
1421 :    
1422 :     # Return the result hash.
1423 :     return $retVal;
1424 : parrello 1.3 }
1425 :    
1426 :     =head md5_tree_to_fid_tree
1427 : parrello 1.1
1428 : parrello 1.3 my $fidtree = $altObject->md5_tree_to_fid_tree({
1429 :     -tree => $md5_tree,
1430 :     -map => $md5_to_fid_map
1431 :     });
1432 :    
1433 :     Use a map produced by L</map_fid_to_md5> to convert an MD5-based tree to a PEG-based
1434 :     tree. Since a single protein may be generated by multiple features, this could
1435 :     result in tree nodes being replicated in the result.
1436 : parrello 1.1
1437 :     =over 4
1438 :    
1439 :     =item parameter
1440 :    
1441 : parrello 1.3 The parameter should be a reference to a hash containing the following keys.
1442 :    
1443 :     =over 8
1444 :    
1445 :     =item -tree
1446 :    
1447 :     The MD5-based tree to be converted.
1448 :    
1449 :     =item -map
1450 :    
1451 :     Reference to a hash mapping each MD5 protein ID to a list of the corresponding FIG
1452 :     feature IDs.
1453 :    
1454 :     =back
1455 :    
1456 :     =item RETURN
1457 :    
1458 :     Returns a new version of the tree with the MD5 protein IDs replaced by FIG
1459 :     feature IDs.
1460 :    
1461 :     =back
1462 :    
1463 :     =cut
1464 :    
1465 :     sub md5_tree_to_fid_tree {
1466 : parrello 1.4
1467 :     # Get the parameters.
1468 :     my ( $self, $args ) = @_;
1469 :    
1470 :     # Get the tree and the map.
1471 :     my $tree = $args->{-tree}
1472 :     || Confess("No tree specified in md5_tree_to_fid_tree.");
1473 :     my $map = $args->{-map}
1474 :     || Confess("No map specified in md5_tree_to_fid_tree.");
1475 :    
1476 :     # Perform the conversion.
1477 :     my $retVal = AlignsAndTrees::md5_tree_to_fid_tree( $tree, $map );
1478 :    
1479 :     # Return the result.
1480 :     return $retVal;
1481 : parrello 1.3 }
1482 :    
1483 :     =head3 trees_with_md5ID
1484 :    
1485 :     my $protHash = $altObject->trees_with_md5ID({
1486 :     -ids => [$prot1, $prot2, ...]
1487 :     });
1488 :    
1489 :     Return a list of the alignment/tree pairs containing each of the specified proteins.
1490 :    
1491 :     =over 4
1492 :    
1493 :     =item parameters
1494 :    
1495 :     The parameter should be a reference to a hash with the following keys:
1496 : parrello 1.1
1497 :     =over 8
1498 :    
1499 : parrello 1.3 =item -ids
1500 : parrello 1.1
1501 :     Reference to a list of MD5 protein IDs.
1502 :    
1503 :     =back
1504 :    
1505 :     =item RETURN
1506 :    
1507 : parrello 1.3 Returns a reference to a hash mapping each incoming protein ID to a list of the
1508 :     IDs for the trees containing that protein.
1509 : parrello 1.1
1510 :     $protHash = { $prot1 => [$alt1a, $alt1b, ...],
1511 :     $prot2 => [$alt2a, $alt2b, ...],
1512 :     ... };
1513 :    
1514 :     =back
1515 :    
1516 :     =cut
1517 :    
1518 : parrello 1.3 sub trees_with_md5ID {
1519 : parrello 1.4
1520 :     # Get the parameters.
1521 :     my ( $self, $args ) = @_;
1522 :    
1523 :     # Get the Sapling database.
1524 :     my $sap = $self->{db};
1525 :    
1526 :     # Create the return hash.
1527 :     my $retVal = {};
1528 :    
1529 :     # Get the list of incoming IDs.
1530 :     my $ids = ServerThing::GetIdList( -ids => $args );
1531 :    
1532 :     # Loop through the protein IDs, finding the trees.
1533 :     for my $id (@$ids) {
1534 :     $retVal->{$id} = AlignsAndTrees::trees_with_md5ID( $sap, $id );
1535 :     }
1536 :    
1537 :     # Return the result hash.
1538 :     return $retVal;
1539 : parrello 1.1 }
1540 :    
1541 : parrello 1.4 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3