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

View of /FigKernelPackages/ALITRE.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Wed Apr 20 20:17:54 2011 UTC (9 years, 1 month ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_05262011
Changes since 1.1: +1 -1 lines
Uncommented metadata call.

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
#
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License.
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#
package ALITRE;

    use strict;
    use AlignsAndTrees;
    use Tracer;
    use SeedUtils;
    use ServerThing;

=head1 Alignment and Tree Server Function Object

This file contains the functions and utilities used by the Alignment and Tree Server
(B<alitre_server.cgi>). The various methods listed in the sections below represent
function calls direct to the server. These all have a signature similar to the
following.

    my $results = $altObject->function_name($args);

where C<$altObject> is an object created by this module, 
C<$args> is a parameter structure, and C<function_name> is the server function name.
The output $results is a scalar, generally a hash reference, but sometimes a
string or a list reference.

=head2 Constructor

Use

    my $altObject = SAPserver->new();

to create a new alignment/tree server function object. The server function object
is used to invoke the L</Primary Methods> listed below. See L<ALITREserver> for
more information on how to create this object and the options available.

=cut

#   
# Actually, if you are using ALITRE.pm, you should do ALITRE->new(), not ALITREserver->new()
# That comment above is for the benefit of the pod doc stuff on how to use ALITREserver 
# that is generated from this file.
#

sub new {
    my ($class) = @_;
    # Create the server object.
    my $retVal = { };
    # Bless and return it.
    bless $retVal, $class;
    return $retVal;
}

=head1 Primary Methods

=head2 Server Utility Methods

You will not use the methods in this section very often. Currently, the only one
present (L</methods>) is used by the server framework for maintenance and control
purposes.

=head3 methods

    my $methodList =        $altObject->methods();

Return a reference to a list of the methods allowed on this object.

=cut

use constant METHODS => [qw(
                         ali_tree_pairs_to_metadata
                         ali_tree_pairs_to_prots
                         all_ali_tree_pairs
                         prot_set_to_ali_tree_pairs
                         prots_to_ali_tree_pairs
                        )];

sub methods {
    # Get the parameters.
    my ($self) = @_;
    # Return the result.
    return METHODS;
}

=head2 Client Methods

=head3 ali_tree_pairs_to_metadata

    my $altHash =       $altObject->ali_tree_pairs_to_metadata({
                            -ids => [$alt1, $alt2, ...]
                        });

Return the metadata associated with each specified alignment/tree pair.

=over 4

=item parameter

The parameter should be a reference to a hash with the following keys:

=over 8

=item -ids

Reference to a list of alignment/tree pair IDs.

=back

=item RETURN

Returns a reference to a hash mapping each incoming alignment/tree pair ID to a sub-hash
that maps metadata field names to field values.

    $altHash = { $alt1 => { $fld1a => $value1a, $fld1b => $value1b, ... },
                 $alt2 => { $fld2a => $value2a, $fld2b => $value2b, ... },
                 ... };

=back

=cut

sub ali_tree_pairs_to_metadata {
    # Get the parameters.
    my ($self, $args) = @_;
    # Get the list of IDs.
    my $ids = ServerThing::GetIdList(-ids => $args);
    # Declare the return hash.
    my $retVal = {};
    # Loop through the incoming alignment/tree IDs.
    for my $id (@$ids) {
        # Get the metadata for this alignment.
        my $metadata = AlignsAndTrees::md5_alignment_metadata($id);
        # Store it in the return hash.
        $retVal->{$id} = $metadata;
    }
    # Return the result.
    return $retVal;
}

=head3 ali_tree_pairs_to_prots

    my $altHash =       $altObject->ali_tree_pairs_to_prots({
                            -ids => [$alt1, $alt2, ...]
                        });

Return a list of the protein IDs in each specified alignment/tree pair.

=over 4

=item parameter

The parameter should be a reference to a hash with the following keys.

=over 8

=item -ids

Reference to a list of alignment/tree pair IDs.

=back

=item RETURN

Returns a reference to a hash mapping each incoming alignment/tree ID to a list of MD5 protein IDs
representing the proteins found in the alignment/tree pair.

    $altHash = { $alt1 => [$prot1a, $prot1b, ...],
                 $alt2 => [$prot2a, $prot2b, ...],
                 ... };

=back

=cut

sub ali_tree_pairs_to_prots {
    # Get the parameters.
    my ($self, $args) = @_;
    # Get the list of alignment/tree IDs.
    my $ids = ServerThing::GetIdList(-ids => $args);
    # Declare the return hash.
    my $retVal = {};
    # Loop through the list of IDs.
    for my $id (@$ids) {
        # Get the list of proteins for this alignment.
        my $prots = AlignsAndTrees::md5IDs_in_align($id);
        # Store it in the return hash.
        $retVal->{$id} = $prots;
    }
    # Return the result.
    return $retVal;
}

=head3 all_ali_tree_pairs

    my $altList =       $altObject->all_ali_tree_pairs();

Return a list of all the alignment/tree IDs. Each ID represents an alignment and an associated
tree.

=over 4

=item RETURN

Returns a reference to a list of alignment/tree IDs.

    $idList = [$alt1, $alt2, ...];

=back

=cut

sub all_ali_tree_pairs {
    # Get the parameters.
    my ($self) = @_;
    # Get the list of IDs.
    my $retVal = AlignsAndTrees::all_alignIDs();
    # Return the list.
    return $retVal;
}

=head3 prot_set_to_ali_tree_pairs

    my $altList =       $altObject({
                            -prots => [$prot1, $prot2, ...]
                        });

Return a list of the alignments containing all of the incoming proteins.

=over 4

=over 4

=item parameter

The parameter should be a reference to a hash with the following keys.

=over 8

=item -prots

Reference to a list of MD5 protein IDs.

=back

=item RETURN

Returns a reference to a list of IDs for the alignment/tree pairs containing all the
incoming proteins.

    $altList = [$alt1, $alt2, ... ];

=back

=cut

sub prot_set_to_ali_tree_pairs {
    # Get the parameters.
    my ($self, $args) = @_;
    # Get the protein ID list.
    my $prots = ServerThing::GetIdList(-prots => $args);
    # Declare the return variable.
    my $retVal = [];
    # Only proceed if we have at least one protein.
    my ($prot1, @otherProts) = @$prots;
    if ($prot1) {
        # Create a hash of the alignments found for the first protein.
        my %found = map { $_ => 1 } AlignsAndTrees::aligns_with_md5ID($prot1);
        # Loop through the remaining proteins. In each case we only keep the
        # alignments already found.
        for my $prot (@otherProts) {
            # Get the alignment/tree pairs for this protein.
            my %newAlts = map { $_ => 1 } AlignsAndTrees::aligns_with_md5ID($prot);
            # Delete the alignments in the result hash that are not found for the new 
            # protein.
            for my $alt (keys %found) {
                if (! $newAlts{$alt}) {
                    delete $found{$alt};
                }
            }
        }
        # Store the alignments found as the result list.
        $retVal = [ sort keys %found ];
    }
    # Return the result.
    return $retVal;
}


=head3 prots_to_ali_tree_pairs

    my $protHash =      $altObject({
                            -prots => [$prot1, $prot2, ...]
                        });

For each incoming protein ID, return a list of the alignment/tree pairs containing that protein.

=over 4

=item parameter

The parameter should be a reference to a hash with the following keys.

=over 8

=item -prots

Reference to a list of MD5 protein IDs.

=back

=item RETURN

Returns a reference to a hash that maps each incoming protein ID to a list of IDs for the
alignment/tree pairs containing that protein.

    $protHash = { $prot1 => [$alt1a, $alt1b, ...],
                  $prot2 => [$alt2a, $alt2b, ...],
                  ... };

=back

=cut

sub prots_to_ali_tree_pairs {
    # Get the parameters.
    my ($self, $args) = @_;
    # Get the protein ID list.
    my $prots = ServerThing::GetIdList(-prots => $args);
    # Declare the return hash.
    my $retVal = {};
    # Loop through the proteins.
    for my $prot (@$prots) {
        # Get the alignment/tree pairs for this protein.
        my $alts = AlignsAndTrees::aligns_with_md5ID($prot);
        # Store the resulting list in the return hash.
        $retVal->{$prot} = $alts;
    }
    # Return the result.
    return $retVal;
}



1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3