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

Diff of /Sprout/Sprout.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.75, Sun Jun 25 18:02:35 2006 UTC revision 1.82, Sat Sep 2 07:00:54 2006 UTC
# Line 15  Line 15 
15      use FidCheck;      use FidCheck;
16      use Stats;      use Stats;
17      use POSIX qw(strftime);      use POSIX qw(strftime);
18        use BasicLocation;
19    
20  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
21    
# Line 92  Line 92 
92  sub new {  sub new {
93      # Get the parameters.      # Get the parameters.
94      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
95        # Compute the DBD directory.
96        my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
97                                                      $FIG_Config::fig );
98      # Compute the options. We do this by starting with a table of defaults and overwriting with      # Compute the options. We do this by starting with a table of defaults and overwriting with
99      # the incoming data.      # the incoming data.
100      my $optionTable = Tracer::GetOptions({      my $optionTable = Tracer::GetOptions({
# Line 99  Line 102 
102                                                          # database type                                                          # database type
103                         dataDir      => $FIG_Config::sproutData,                         dataDir      => $FIG_Config::sproutData,
104                                                          # data file directory                                                          # data file directory
105                         xmlFileName  => "$FIG_Config::fig/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
106                                                          # database definition file name                                                          # database definition file name
107                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
108                                                          # user name and password                                                          # user name and password
109                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::dbport,
110                                                          # database connection port                                                          # database connection port
111                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::dbsock,
112                           host         => $FIG_Config::dbhost,
113                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
114                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
115                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 119  Line 123 
123      my $dbh;      my $dbh;
124      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
125          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
126                                  $password, $optionTable->{port}, undef, $optionTable->{sock});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
127      }      }
128      # Create the ERDB object.      # Create the ERDB object.
129      my $xmlFileName = "$optionTable->{xmlFileName}";      my $xmlFileName = "$optionTable->{xmlFileName}";
# Line 1656  Line 1660 
1660  sub CoupledFeatures {  sub CoupledFeatures {
1661      # Get the parameters.      # Get the parameters.
1662      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1663        Trace("Looking for features coupled to $featureID.") if T(coupling => 3);
1664      # Create a query to retrieve the functionally-coupled features.      # Create a query to retrieve the functionally-coupled features.
1665      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1666                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);
# Line 1668  Line 1673 
1673          # Get the ID and score of the coupling.          # Get the ID and score of the coupling.
1674          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1675                                                          'Coupling(score)']);                                                          'Coupling(score)']);
1676            Trace("$featureID coupled with score $score to ID $couplingID.") if T(coupling => 4);
1677          # Get the other feature that participates in the coupling.          # Get the other feature that participates in the coupling.
1678          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],
1679                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",
1680                                             [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)');                                             [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)');
1681            Trace("$couplingID target feature is $otherFeatureID.") if T(coupling => 4);
1682          # Attach the other feature's score to its ID.          # Attach the other feature's score to its ID.
1683          $retVal{$otherFeatureID} = $score;          $retVal{$otherFeatureID} = $score;
1684          $found = 1;          $found = 1;
# Line 2860  Line 2867 
2867      return @retVal;      return @retVal;
2868  }  }
2869    
2870    =head3 GenomeSubsystemData
2871    
2872    C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>
2873    
2874    Return a hash mapping genome features to their subsystem roles.
2875    
2876    =over 4
2877    
2878    =item genomeID
2879    
2880    ID of the genome whose subsystem feature map is desired.
2881    
2882    =item RETURN
2883    
2884    Returns a hash mapping each feature of the genome to a list of 2-tuples. Eacb
2885    2-tuple contains a subsystem name followed by a role ID.
2886    
2887    =back
2888    
2889    =cut
2890    
2891    sub GenomeSubsystemData {
2892        # Get the parameters.
2893        my ($self, $genomeID) = @_;
2894        # Declare the return variable.
2895        my %retVal = ();
2896        # Get a list of the genome features that participate in subsystems. For each
2897        # feature we get its spreadsheet cells and the corresponding roles.
2898        my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],
2899                                 "HasFeature(from-link) = ?", [$genomeID],
2900                                 ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);
2901        # Now we get a list of the spreadsheet cells and their associated subsystems. Subsystems
2902        # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the
2903        # list. We use it at the beginning to get all the spreadsheet cells for the genome and
2904        # again at the end to filter out participation in subsystems with a negative variant code.
2905        my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],
2906                                     "IsGenomeOf(from-link) = ? AND ParticipatesIn(variant-code) >= 0 AND ParticipatesIn(from-link) = ?",
2907                                     [$genomeID, $genomeID], ['HasSSCell(to-link)', 'HasSSCell(from-link)']);
2908        # Now "@roleData" lists the spreadsheet cell and role for each of the genome's features.
2909        # "@cellData" lists the subsystem name for each of the genome's spreadsheet cells. We
2910        # link these two lists together to create the result. First, we want a hash mapping
2911        # spreadsheet cells to subsystem names.
2912        my %subHash = map { $_->[0] => $_->[1] } @cellData;
2913        # We loop through @cellData to build the hash.
2914        for my $roleEntry (@roleData) {
2915            # Get the data for this feature and cell.
2916            my ($fid, $cellID, $role) = @{$roleEntry};
2917            # Check for a subsystem name.
2918            my $subsys = $subHash{$cellID};
2919            if ($subsys) {
2920                # Insure this feature has an entry in the return hash.
2921                if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
2922                # Merge in this new data.
2923                push @{$retVal{$fid}}, [$subsys, $role];
2924            }
2925        }
2926        # Return the result.
2927        return %retVal;
2928    }
2929    
2930  =head3 RelatedFeatures  =head3 RelatedFeatures
2931    
2932  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>  C<< my @relatedList = $sprout->RelatedFeatures($featureID, $function, $userID); >>
# Line 3333  Line 3400 
3400      return $retVal;      return $retVal;
3401  }  }
3402    
3403    =head3 Fix
3404    
3405    C<< my %fixedHash = Sprout::Fix(%groupHash); >>
3406    
3407    Prepare a genome group hash (like that returned by L</GetGroups> for processing.
3408    Groups with the same primary name will be combined. The primary name is the
3409    first capitalized word in the group name.
3410    
3411    =over 4
3412    
3413    =item groupHash
3414    
3415    Hash to be fixed up.
3416    
3417    =item RETURN
3418    
3419    Returns a fixed-up version of the hash.
3420    
3421    =back
3422    
3423    =cut
3424    
3425    sub Fix {
3426        # Get the parameters.
3427        my (%groupHash) = @_;
3428        # Create the result hash.
3429        my %retVal = ();
3430        # Copy over the genomes.
3431        for my $groupID (keys %groupHash) {
3432            # Make a safety copy of the group ID.
3433            my $realGroupID = $groupID;
3434            # Yank the primary name.
3435            if ($groupID =~ /([A-Z]\w+)/) {
3436                $realGroupID = $1;
3437            }
3438            # Append this group's genomes into the result hash.
3439            Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});
3440        }
3441        # Return the result hash.
3442        return %retVal;
3443    }
3444    
3445  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3446    
3447  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3389  Line 3498 
3498      }      }
3499      # If we have an assignment, we need to clean the function text. There may be      # If we have an assignment, we need to clean the function text. There may be
3500      # extra junk at the end added as a note from the user.      # extra junk at the end added as a note from the user.
3501      if (@retVal) {      if (defined( $retVal[1] )) {
3502          $retVal[1] =~ s/(\t\S)?\s*$//;          $retVal[1] =~ s/(\t\S)?\s*$//;
3503      }      }
3504      # Return the result list.      # Return the result list.

Legend:
Removed from v.1.75  
changed lines
  Added in v.1.82

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3