[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.83, Wed Sep 6 19:30:22 2006 UTC revision 1.99, Fri Apr 27 22:21:46 2007 UTC
# Line 5  Line 5 
5      @ISA = qw(Exporter ERDB);      @ISA = qw(Exporter ERDB);
6      use Data::Dumper;      use Data::Dumper;
7      use strict;      use strict;
     use Carp;  
8      use DBKernel;      use DBKernel;
9      use XML::Simple;      use XML::Simple;
10      use DBQuery;      use DBQuery;
11      use DBObject;      use ERDBObject;
12      use Tracer;      use Tracer;
13      use FIGRules;      use FIGRules;
14      use FidCheck;      use FidCheck;
15      use Stats;      use Stats;
16      use POSIX qw(strftime);      use POSIX qw(strftime);
17      use BasicLocation;      use BasicLocation;
18        use CustomAttributes;
19        use RemoteCustomAttributes;
20    
21  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
22    
# Line 131  Line 132 
132      # Add the option table and XML file name.      # Add the option table and XML file name.
133      $retVal->{_options} = $optionTable;      $retVal->{_options} = $optionTable;
134      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
135        # Set up space for the group file data.
136        $retVal->{groupHash} = undef;
137        # Connect to the attributes.
138        if ($FIG_Config::attrURL) {
139            Trace("Remote attribute server $FIG_Config::attrURL chosen.") if T(3);
140            $retVal->{_ca} = RemoteCustomAttributes->new($FIG_Config::attrURL);
141        } elsif ($FIG_Config::attrDbName) {
142            Trace("Local attribute database $FIG_Config::attrDbName chosen.") if T(3);
143            my $user = ($FIG_Config::arch eq 'win' ? 'self' : scalar(getpwent()));
144            $retVal->{_ca} = CustomAttributes->new(user => $user);
145        }
146      # Return it.      # Return it.
147      return $retVal;      return $retVal;
148  }  }
# Line 340  Line 352 
352    
353  =head3 GeneMenu  =head3 GeneMenu
354    
355  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>
356    
357  Return an HTML select menu of genomes. Each genome will be an option in the menu,  Return an HTML select menu of genomes. Each genome will be an option in the menu,
358  and will be displayed by name with the ID and a contig count attached. The selection  and will be displayed by name with the ID and a contig count attached. The selection
# Line 362  Line 374 
374  Reference to a list of values to be substituted in for the parameter marks in  Reference to a list of values to be substituted in for the parameter marks in
375  the filter string.  the filter string.
376    
377    =item selected (optional)
378    
379    ID of the genome to be initially selected.
380    
381    =item fast (optional)
382    
383    If specified and TRUE, the contig counts will be omitted to improve performance.
384    
385  =item RETURN  =item RETURN
386    
387  Returns an HTML select menu with the specified genomes as selectable options.  Returns an HTML select menu with the specified genomes as selectable options.
# Line 372  Line 392 
392    
393  sub GeneMenu {  sub GeneMenu {
394      # Get the parameters.      # Get the parameters.
395      my ($self, $attributes, $filterString, $params) = @_;      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;
396        my $slowMode = ! $fast;
397        # Default to nothing selected. This prevents an execution warning if "$selected"
398        # is undefined.
399        $selected = "" unless defined $selected;
400        Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);
401      # Start the menu.      # Start the menu.
402      my $retVal = "<select " .      my $retVal = "<select " .
403          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .
# Line 389  Line 414 
414          # Get the data for this genome.          # Get the data for this genome.
415          my ($genomeID, $genus, $species, $strain) = @{$genomeData};          my ($genomeID, $genus, $species, $strain) = @{$genomeData};
416          # Get the contig count.          # Get the contig count.
417            my $contigInfo = "";
418            if ($slowMode) {
419          my $count = $self->ContigCount($genomeID);          my $count = $self->ContigCount($genomeID);
420          my $counting = ($count == 1 ? "contig" : "contigs");          my $counting = ($count == 1 ? "contig" : "contigs");
421                $contigInfo = "[$count $counting]";
422            }
423            # Find out if we're selected.
424            my $selectOption = ($selected eq $genomeID ? " selected" : "");
425          # Build the option tag.          # Build the option tag.
426          $retVal .= "<option value=\"$genomeID\">$genus $species $strain ($genomeID) [$count $counting]</option>\n";          $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";
         Trace("Option tag built for $genomeID: $genus $species $strain.") if T(3);  
427      }      }
428      # Close the SELECT tag.      # Close the SELECT tag.
429      $retVal .= "</select>\n";      $retVal .= "</select>\n";
430      # Return the result.      # Return the result.
431      return $retVal;      return $retVal;
432  }  }
433    
434  =head3 Build  =head3 Build
435    
436  C<< $sprout->Build(); >>  C<< $sprout->Build(); >>
# Line 634  Line 665 
665      return ($contigID, $start, $dir, $len);      return ($contigID, $start, $dir, $len);
666  }  }
667    
668    
669    
670  =head3 PointLocation  =head3 PointLocation
671    
672  C<< my $found = Sprout::PointLocation($location, $point); >>  C<< my $found = Sprout::PointLocation($location, $point); >>
# Line 898  Line 931 
931      my ($self, $genomeID) = @_;      my ($self, $genomeID) = @_;
932      # Declare the return variable.      # Declare the return variable.
933      my $retVal = {};      my $retVal = {};
934      # Query the genome's features and annotations. We'll put the oldest annotations      # Query the genome's features.
935      # first so that the last assignment to go into the hash will be the correct one.      my $query = $self->Get(['HasFeature', 'Feature'], "HasFeature(from-link) = ?",
     my $query = $self->Get(['HasFeature', 'IsTargetOfAnnotation', 'Annotation'],  
                            "HasFeature(from-link) = ? ORDER BY Annotation(time)",  
936                             [$genomeID]);                             [$genomeID]);
937      # Loop through the annotations.      # Loop through the features.
938      while (my $data = $query->Fetch) {      while (my $data = $query->Fetch) {
939          # Get the feature ID and annotation text.          # Get the feature ID and assignment.
940          my ($fid, $annotation) = $data->Values(['HasFeature(to-link)',          my ($fid, $assignment) = $data->Values(['Feature(id)', 'Feature(assignment)']);
941                                                  'Annotation(annotation)']);          if ($assignment) {
         # Check to see if this is an assignment. Note that the user really  
         # doesn't matter to us, other than we use it to determine whether or  
         # not this is an assignment.  
         my ($user, $assignment) = _ParseAssignment('fig', $annotation);  
         if ($user) {  
             # Here it's an assignment. We put it in the return hash, overwriting  
             # any older assignment that might be present.  
942              $retVal->{$fid} = $assignment;              $retVal->{$fid} = $assignment;
943          }          }
944      }      }
# Line 1276  Line 1300 
1300  Return the most recently-determined functional assignment of a particular feature.  Return the most recently-determined functional assignment of a particular feature.
1301    
1302  The functional assignment is handled differently depending on the type of feature. If  The functional assignment is handled differently depending on the type of feature. If
1303  the feature is identified by a FIG ID (begins with the string C<fig|>), then a functional  the feature is identified by a FIG ID (begins with the string C<fig|>), then the functional
1304  assignment is a type of annotation. The format of an assignment is described in  assignment is taken from the B<Feature> or C<Annotation> table, depending.
 L</ParseAssignment>. Its worth noting that we cannot filter on the content of the  
 annotation itself because it's a text field; however, this is not a big problem because  
 most features only have a small number of annotations.  
1305    
1306  Each user has an associated list of trusted users. The assignment returned will be the most  Each user has an associated list of trusted users. The assignment returned will be the most
1307  recent one by at least one of the trusted users. If no trusted user list is available, then  recent one by at least one of the trusted users. If no trusted user list is available, then
# Line 1299  Line 1320 
1320    
1321  =item userID (optional)  =item userID (optional)
1322    
1323  ID of the user whose function determination is desired. If omitted, only the latest  ID of the user whose function determination is desired. If omitted, the primary
1324  C<FIG> assignment will be returned.  functional assignment in the B<Feature> table will be returned.
1325    
1326  =item RETURN  =item RETURN
1327    
# Line 1317  Line 1338 
1338      my $retVal;      my $retVal;
1339      # Determine the ID type.      # Determine the ID type.
1340      if ($featureID =~ m/^fig\|/) {      if ($featureID =~ m/^fig\|/) {
1341          # Here we have a FIG feature ID. We must build the list of trusted          # Here we have a FIG feature ID.
1342          # users.          if (!$userID) {
1343                # Use the primary assignment.
1344                ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);
1345            } else {
1346                # We must build the list of trusted users.
1347          my %trusteeTable = ();          my %trusteeTable = ();
1348          # Check the user ID.          # Check the user ID.
1349          if (!$userID) {          if (!$userID) {
# Line 1361  Line 1386 
1386                  }                  }
1387              }              }
1388          }          }
1389            }
1390      } else {      } else {
1391          # Here we have a non-FIG feature ID. In this case the user ID does not          # Here we have a non-FIG feature ID. In this case the user ID does not
1392          # matter. We simply get the information from the External Alias Function          # matter. We simply get the information from the External Alias Function
# Line 1476  Line 1502 
1502      my %retVal = ();      my %retVal = ();
1503      # Loop through the incoming features.      # Loop through the incoming features.
1504      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1505          # Create a query to get the feature's best hit.          # Ask the server for the feature's best hit.
1506          my $query = $self->Get(['IsBidirectionalBestHitOf'],          my @bbhData = FIGRules::BBHData($featureID);
                                "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",  
                                [$featureID, $genomeID]);  
1507          # Peel off the BBHs found.          # Peel off the BBHs found.
1508          my @found = ();          my @found = ();
1509          while (my $bbh = $query->Fetch) {          for my $bbh (@bbhData) {
1510              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');              my $fid = $bbh->[0];
1511                my $bbGenome = $self->GenomeOf($fid);
1512                if ($bbGenome eq $genomeID) {
1513                    push @found, $fid;
1514                }
1515          }          }
1516          $retVal{$featureID} = \@found;          $retVal{$featureID} = \@found;
1517      }      }
# Line 1497  Line 1525 
1525    
1526  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1527    
1528  Sprout does not support real similarities, so this method just returns the bidirectional  This method just returns the bidirectional best hits for performance reasons.
 best hits.  
1529    
1530  =over 4  =over 4
1531    
# Line 1518  Line 1545 
1545      # Get the parameters.      # Get the parameters.
1546      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1547      # Ask for the best hits.      # Ask for the best hits.
1548      my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],      my @lists = FIGRules::BBHData($featureID);
                               "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",  
                               [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],  
                               $count);  
1549      # Create the return value.      # Create the return value.
1550      my %retVal = ();      my %retVal = ();
1551      for my $tuple (@lists) {      for my $tuple (@lists) {
# Line 1531  Line 1555 
1555      return %retVal;      return %retVal;
1556  }  }
1557    
   
   
1558  =head3 IsComplete  =head3 IsComplete
1559    
1560  C<< my $flag = $sprout->IsComplete($genomeID); >>  C<< my $flag = $sprout->IsComplete($genomeID); >>
# Line 2521  Line 2543 
2543    
2544  Return a list of the properties with the specified characteristics.  Return a list of the properties with the specified characteristics.
2545    
2546  Properties are arbitrary key-value pairs associated with a feature. (At some point they  Properties are the Sprout analog of the FIG attributes. The call is
2547  will also be associated with genomes.) A property value is represented by a 4-tuple of  passed directly to the CustomAttributes or RemoteCustomAttributes object
2548  the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter  contained in this object.
2549    
2550  =over 4  This method returns a series of tuples that match the specified criteria. Each tuple
2551    will contain an object ID, a key, and one or more values. The parameters to this
2552    method therefore correspond structurally to the values expected in each tuple. In
2553    addition, you can ask for a generic search by suffixing a percent sign (C<%>) to any
2554    of the parameters. So, for example,
2555    
2556  =item fid      my @attributeList = $sprout->GetProperties('fig|100226.1.peg.1004', 'structure%', 1, 2);
2557    
2558  ID of the feature possessing the property.  would return something like
2559    
2560  =item key      ['fig}100226.1.peg.1004', 'structure', 1, 2]
2561        ['fig}100226.1.peg.1004', 'structure1', 1, 2]
2562        ['fig}100226.1.peg.1004', 'structure2', 1, 2]
2563        ['fig}100226.1.peg.1004', 'structureA', 1, 2]
2564    
2565  Name or key of the property.  Use of C<undef> in any position acts as a wild card (all values). You can also specify
2566    a list reference in the ID column. Thus,
2567    
2568  =item value      my @attributeList = $sprout->GetProperties(['100226.1', 'fig|100226.1.%'], 'PUBMED');
2569    
2570  Value of the property.  would get the PUBMED attribute data for Streptomyces coelicolor A3(2) and all its
2571    features.
2572    
2573  =item url  In addition to values in multiple sections, a single attribute key can have multiple
2574    values, so even
2575    
2576  URL of the document that indicated the property should have this particular value, or an      my @attributeList = $sprout->GetProperties($peg, 'virulent');
 empty string if no such document exists.  
2577    
2578  =back  which has no wildcard in the key or the object ID, may return multiple tuples.
2579    
2580  The parameters act as a filter for the desired data. Any non-null parameter will  =over 4
 automatically match all the tuples returned. So, specifying just the I<$fid> will  
 return all the properties of the specified feature; similarly, specifying the I<$key>  
 and I<$value> parameters will return all the features having the specified property  
 value.  
2581    
2582  A single property key can have many values, representing different ideas about the  =item objectID
 feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is  
 virulent, and another may declare that it is not virulent. A query about the virulence of  
 C<fig|83333.1.peg.10> would be coded as  
2583    
2584      my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');  ID of object whose attributes are desired. If the attributes are desired for multiple
2585    objects, this parameter can be specified as a list reference. If the attributes are
2586    desired for all objects, specify C<undef> or an empty string. Finally, you can specify
2587    attributes for a range of object IDs by putting a percent sign (C<%>) at the end.
2588    
2589  Here the I<$value> and I<$url> fields are left blank, indicating that those fields are  =item key
 not to be filtered. The tuples returned would be  
2590    
2591      ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')  Attribute key name. A value of C<undef> or an empty string will match all
2592      ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')  attribute keys. If the values are desired for multiple keys, this parameter can be
2593    specified as a list reference. Finally, you can specify attributes for a range of
2594    keys by putting a percent sign (C<%>) at the end.
2595    
2596    =item values
2597    
2598    List of the desired attribute values, section by section. If C<undef>
2599    or an empty string is specified, all values in that section will match. A
2600    generic match can be requested by placing a percent sign (C<%>) at the end.
2601    In that case, all values that match up to and not including the percent sign
2602    will match. You may also specify a regular expression enclosed
2603    in slashes. All values that match the regular expression will be returned. For
2604    performance reasons, only values have this extra capability.
2605    
2606    =item RETURN
2607    
2608    Returns a list of tuples. The first element in the tuple is an object ID, the
2609    second is an attribute key, and the remaining elements are the sections of
2610    the attribute value. All of the tuples will match the criteria set forth in
2611    the parameter list.
2612    
2613    =back
2614    
2615  =cut  =cut
2616  #: Return Type @@;  
2617  sub GetProperties {  sub GetProperties {
2618      # Get the parameters.      # Get the parameters.
2619      my ($self, @parms) = @_;      my ($self, @parms) = @_;
2620      # Declare the return variable.      # Declare the return variable.
2621      my @retVal = ();      my @retVal = $self->{_ca}->GetAttributes(@parms);
     # Now we need to create a WHERE clause that will get us the data we want. First,  
     # we create a list of the columns containing the data for each parameter.  
     my @colNames = ('HasProperty(from-link)', 'Property(property-name)',  
                     'Property(property-value)', 'HasProperty(evidence)');  
     # Now we build the WHERE clause and the list of parameter values.  
     my @where = ();  
     my @values = ();  
     for (my $i = 0; $i <= $#colNames; $i++) {  
         my $parm = $parms[$i];  
         if (defined $parm && ($parm ne '')) {  
             push @where, "$colNames[$i] = ?";  
             push @values, $parm;  
         }  
     }  
     # Format the WHERE clause.  
     my $filter = (@values > 0 ? (join " AND ", @where) : undef);  
     # Ask for all the propertie values with the desired characteristics.  
     my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);  
     while (my $valueObject = $query->Fetch()) {  
         my @tuple = $valueObject->Values(\@colNames);  
         push @retVal, \@tuple;  
     }  
2622      # Return the result.      # Return the result.
2623      return @retVal;      return @retVal;
2624  }  }
# Line 2606  Line 2631 
2631  that specify special characteristics of the feature. For example, a property could indicate  that specify special characteristics of the feature. For example, a property could indicate
2632  that a feature is essential to the survival of the organism or that it has benign influence  that a feature is essential to the survival of the organism or that it has benign influence
2633  on the activities of a pathogen. Each property is returned as a triple of the form  on the activities of a pathogen. Each property is returned as a triple of the form
2634  C<($key,$value,$url)>, where C<$key> is the property name, C<$value> is its value (commonly  C<($key,@values)>, where C<$key> is the property name and  C<@values> are its values.
 a 1 or a 0, but possibly a string or a floating-point value), and C<$url> is a string describing  
 the web address or citation in which the property's value for the feature was identified.  
2635    
2636  =over 4  =over 4
2637    
# Line 2618  Line 2641 
2641    
2642  =item RETURN  =item RETURN
2643    
2644  Returns a list of triples, each triple containing the property name, its value, and a URL or  Returns a list of tuples, each tuple containing the property name and its values.
 citation.  
2645    
2646  =back  =back
2647    
# Line 2629  Line 2651 
2651      # Get the parameters.      # Get the parameters.
2652      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2653      # Get the properties.      # Get the properties.
2654      my @retVal = $self->GetAll(['HasProperty', 'Property'], "HasProperty(from-link) = ?", [$featureID],      my @attributes = $self->{_ca}->GetAttributes($featureID);
2655                              ['Property(property-name)', 'Property(property-value)',      # Strip the feature ID off each tuple.
2656                               'HasProperty(evidence)']);      my @retVal = ();
2657        for my $attributeRow (@attributes) {
2658            shift @{$attributeRow};
2659            push @retVal, $attributeRow;
2660        }
2661      # Return the resulting list.      # Return the resulting list.
2662      return @retVal;      return @retVal;
2663  }  }
# Line 2664  Line 2690 
2690      return $retVal;      return $retVal;
2691  }  }
2692    
2693    =head3 PropertyID
2694    
2695    C<< my $id = $sprout->PropertyID($propName, $propValue); >>
2696    
2697    Return the ID of the specified property name and value pair, if the
2698    pair exists. Only a small subset of the FIG attributes are stored as
2699    Sprout properties, mostly for use in search optimization.
2700    
2701    =over 4
2702    
2703    =item propName
2704    
2705    Name of the desired property.
2706    
2707    =item propValue
2708    
2709    Value expected for the desired property.
2710    
2711    =item RETURN
2712    
2713    Returns the ID of the name/value pair, or C<undef> if the pair does not exist.
2714    
2715    =back
2716    
2717    =cut
2718    
2719    sub PropertyID {
2720        # Get the parameters.
2721        my ($self, $propName, $propValue) = @_;
2722        # Try to find the ID.
2723        my ($retVal) = $self->GetFlat(['Property'],
2724                                      "Property(property-name) = ? AND Property(property-value) = ?",
2725                                      [$propName, $propValue], 'Property(id)');
2726        # Return the result.
2727        return $retVal;
2728    }
2729    
2730  =head3 MergedAnnotations  =head3 MergedAnnotations
2731    
2732  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>
# Line 2861  Line 2924 
2924      # Get the parameters.      # Get the parameters.
2925      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2926      # Get the list of names.      # Get the list of names.
2927      my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",
2928                                  [$featureID], 'HasSSCell(from-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
2929      # Return the result.      # Return the result, sorted.
2930      return @retVal;      return sort @retVal;
2931  }  }
2932    
2933  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
# Line 2962  Line 3025 
3025      # Get the parameters.      # Get the parameters.
3026      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
3027      # Get a list of the features that are BBHs of the incoming feature.      # Get a list of the features that are BBHs of the incoming feature.
3028      my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
                                      "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],  
                                      'IsBidirectionalBestHitOf(to-link)');  
3029      # Now we loop through the features, pulling out the ones that have the correct      # Now we loop through the features, pulling out the ones that have the correct
3030      # functional assignment.      # functional assignment.
3031      my @retVal = ();      my @retVal = ();
# Line 3100  Line 3161 
3161      # Loop through the input triples.      # Loop through the input triples.
3162      my $n = length $sequence;      my $n = length $sequence;
3163      for (my $i = 0; $i < $n; $i += 3) {      for (my $i = 0; $i < $n; $i += 3) {
3164          # Get the current triple from the sequence.          # Get the current triple from the sequence. Note we convert to
3165          my $triple = substr($sequence, $i, 3);          # upper case to insure a match.
3166            my $triple = uc substr($sequence, $i, 3);
3167          # Translate it using the table.          # Translate it using the table.
3168          my $protein = "X";          my $protein = "X";
3169          if (exists $table->{$triple}) { $protein = $table->{$triple}; }          if (exists $table->{$triple}) { $protein = $table->{$triple}; }
# Line 3134  Line 3196 
3196      return @retVal;      return @retVal;
3197  }  }
3198    
3199    =head3 BBHMatrix
3200    
3201    C<< my %bbhMap = $sprout->BBHMatrix($genomeID, $cutoff, @targets); >>
3202    
3203    Find all the bidirectional best hits for the features of a genome in a
3204    specified list of target genomes. The return value will be a hash mapping
3205    features in the original genome to their bidirectional best hits in the
3206    target genomes.
3207    
3208    =over 4
3209    
3210    =item genomeID
3211    
3212    ID of the genome whose features are to be examined for bidirectional best hits.
3213    
3214    =item cutoff
3215    
3216    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3217    
3218    =item targets
3219    
3220    List of target genomes. Only pairs originating in the original
3221    genome and landing in one of the target genomes will be returned.
3222    
3223    =item RETURN
3224    
3225    Returns a hash mapping each feature in the original genome to a hash mapping its
3226    BBH pegs in the target genomes to their scores.
3227    
3228    =back
3229    
3230    =cut
3231    
3232    sub BBHMatrix {
3233        # Get the parameters.
3234        my ($self, $genomeID, $cutoff, @targets) = @_;
3235        # Declare the return variable.
3236        my %retVal = ();
3237        # Ask for the BBHs.
3238        my @bbhList = FIGRules::BatchBBHs("fig|$genomeID.%", $cutoff, @targets);
3239        # We now have a set of 4-tuples that we need to convert into a hash of hashes.
3240        for my $bbhData (@bbhList) {
3241            my ($peg1, $peg2, $score) = @{$bbhData};
3242            if (! exists $retVal{$peg1}) {
3243                $retVal{$peg1} = { $peg2 => $score };
3244            } else {
3245                $retVal{$peg1}->{$peg2} = $score;
3246            }
3247        }
3248        # Return the result.
3249        return %retVal;
3250    }
3251    
3252    
3253    =head3 SimMatrix
3254    
3255    C<< my %simMap = $sprout->SimMatrix($genomeID, $cutoff, @targets); >>
3256    
3257    Find all the similarities for the features of a genome in a
3258    specified list of target genomes. The return value will be a hash mapping
3259    features in the original genome to their similarites in the
3260    target genomes.
3261    
3262    =over 4
3263    
3264    =item genomeID
3265    
3266    ID of the genome whose features are to be examined for similarities.
3267    
3268    =item cutoff
3269    
3270    A cutoff value. Only hits with a score lower than the cutoff will be returned.
3271    
3272    =item targets
3273    
3274    List of target genomes. Only pairs originating in the original
3275    genome and landing in one of the target genomes will be returned.
3276    
3277    =item RETURN
3278    
3279    Returns a hash mapping each feature in the original genome to a hash mapping its
3280    similar pegs in the target genomes to their scores.
3281    
3282    =back
3283    
3284    =cut
3285    
3286    sub SimMatrix {
3287        # Get the parameters.
3288        my ($self, $genomeID, $cutoff, @targets) = @_;
3289        # Declare the return variable.
3290        my %retVal = ();
3291        # Get the list of features in the source organism.
3292        my @fids = $self->FeaturesOf($genomeID);
3293        # Ask for the sims. We only want similarities to fig features.
3294        my $simList = FIGRules::GetNetworkSims($self, \@fids, {}, 1000, $cutoff, "fig");
3295        if (! defined $simList) {
3296            Confess("Unable to retrieve similarities from server.");
3297        } else {
3298            Trace("Processing sims.") if T(3);
3299            # We now have a set of sims that we need to convert into a hash of hashes. First, we
3300            # Create a hash for the target genomes.
3301            my %targetHash = map { $_ => 1 } @targets;
3302            for my $simData (@{$simList}) {
3303                # Get the PEGs and the score.
3304                my ($peg1, $peg2, $score) = ($simData->id1, $simData->id2, $simData->psc);
3305                # Insure the second ID is in the target list.
3306                my ($genome2) = FIGRules::ParseFeatureID($peg2);
3307                if (exists $targetHash{$genome2}) {
3308                    # Here it is. Now we need to add it to the return hash. How we do that depends
3309                    # on whether or not $peg1 is new to us.
3310                    if (! exists $retVal{$peg1}) {
3311                        $retVal{$peg1} = { $peg2 => $score };
3312                    } else {
3313                        $retVal{$peg1}->{$peg2} = $score;
3314                    }
3315                }
3316            }
3317        }
3318        # Return the result.
3319        return %retVal;
3320    }
3321    
3322    
3323  =head3 LowBBHs  =head3 LowBBHs
3324    
3325  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>  C<< my %bbhMap = $sprout->LowBBHs($featureID, $cutoff); >>
# Line 3165  Line 3351 
3351      my ($self, $featureID, $cutoff) = @_;      my ($self, $featureID, $cutoff) = @_;
3352      # Create the return hash.      # Create the return hash.
3353      my %retVal = ();      my %retVal = ();
3354      # Create a query to get the desired BBHs.      # Query for the desired BBHs.
3355      my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
                                 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',  
                                 [$cutoff, $featureID],  
                                 ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);  
3356      # Form the results into the return hash.      # Form the results into the return hash.
3357      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3358          $retVal{$pair->[0]} = $pair->[1];          my $fid = $pair->[0];
3359            if ($self->Exists('Feature', $fid)) {
3360                $retVal{$fid} = $pair->[1];
3361            }
3362      }      }
3363      # Return the result.      # Return the result.
3364      return %retVal;      return %retVal;
# Line 3190  Line 3376 
3376  Similarities can be either raw or expanded. The raw similarities are basic  Similarities can be either raw or expanded. The raw similarities are basic
3377  hits between features with similar DNA. Expanding a raw similarity drags in any  hits between features with similar DNA. Expanding a raw similarity drags in any
3378  features considered substantially identical. So, for example, if features B<A1>,  features considered substantially identical. So, for example, if features B<A1>,
3379  B<A2>, and B<A3> are all substatially identical to B<A>, then a raw similarity  B<A2>, and B<A3> are all substantially identical to B<A>, then a raw similarity
3380  B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.  B<[C,A]> would be expanded to B<[C,A] [C,A1] [C,A2] [C,A3]>.
3381    
3382  =over 4  =over 4
# Line 3243  Line 3429 
3429      return $retVal;      return $retVal;
3430  }  }
3431    
3432    =head3 IsAllGenomes
3433    
3434    C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>
3435    
3436    Return TRUE if all genomes in the second list are represented in the first list at
3437    least one. Otherwise, return FALSE. If the second list is omitted, the first list is
3438    compared to a list of all the genomes.
3439    
3440    =over 4
3441    
3442    =item list
3443    
3444    Reference to the list to be compared to the second list.
3445    
3446    =item checkList (optional)
3447    
3448    Reference to the comparison target list. Every genome ID in this list must occur at
3449    least once in the first list. If this parameter is omitted, a list of all the genomes
3450    is used.
3451    
3452    =item RETURN
3453    
3454    Returns TRUE if every item in the second list appears at least once in the
3455    first list, else FALSE.
3456    
3457    =back
3458    
3459    =cut
3460    
3461    sub IsAllGenomes {
3462        # Get the parameters.
3463        my ($self, $list, $checkList) = @_;
3464        # Supply the checklist if it was omitted.
3465        $checkList = [$self->Genomes()] if ! defined($checkList);
3466        # Create a hash of the original list.
3467        my %testList = map { $_ => 1 } @{$list};
3468        # Declare the return variable. We assume that the representation
3469        # is complete and stop at the first failure.
3470        my $retVal = 1;
3471        my $n = scalar @{$checkList};
3472        for (my $i = 0; $retVal && $i < $n; $i++) {
3473            if (! $testList{$checkList->[$i]}) {
3474                $retVal = 0;
3475            }
3476        }
3477        # Return the result.
3478        return $retVal;
3479    }
3480    
3481  =head3 GetGroups  =head3 GetGroups
3482    
3483  C<< my %groups = $sprout->GetGroups(\@groupList); >>  C<< my %groups = $sprout->GetGroups(\@groupList); >>
# Line 3264  Line 3499 
3499          # Here we have a group list. Loop through them individually,          # Here we have a group list. Loop through them individually,
3500          # getting a list of the relevant genomes.          # getting a list of the relevant genomes.
3501          for my $group (@{$groupList}) {          for my $group (@{$groupList}) {
3502              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(primary-group) = ?",
3503                  [$group], "Genome(id)");                  [$group], "Genome(id)");
3504              $retVal{$group} = \@genomeIDs;              $retVal{$group} = \@genomeIDs;
3505          }          }
# Line 3272  Line 3507 
3507          # Here we need all of the groups. In this case, we run through all          # Here we need all of the groups. In this case, we run through all
3508          # of the genome records, putting each one found into the appropriate          # of the genome records, putting each one found into the appropriate
3509          # group. Note that we use a filter clause to insure that only genomes          # group. Note that we use a filter clause to insure that only genomes
3510          # in groups are included in the return set.          # in real NMPDR groups are included in the return set.
3511          my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],          my @genomes = $self->GetAll(['Genome'], "Genome(primary-group) <> ?",
3512                                      ['Genome(id)', 'Genome(group-name)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3513          # Loop through the genomes found.          # Loop through the genomes found.
3514          for my $genome (@genomes) {          for my $genome (@genomes) {
3515              # Pop this genome's ID off the current list.              # Pop this genome's ID off the current list.
# Line 3392  Line 3627 
3627      # Get the parameters.      # Get the parameters.
3628      my ($self, $genomeID, $testFlag) = @_;      my ($self, $genomeID, $testFlag) = @_;
3629      # Perform the delete for the genome's features.      # Perform the delete for the genome's features.
3630      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", $testFlag);      my $retVal = $self->Delete('Feature', "fig|$genomeID.%", testMode => $testFlag);
3631      # Perform the delete for the primary genome data.      # Perform the delete for the primary genome data.
3632      my $stats = $self->Delete('Genome', $genomeID, $testFlag);      my $stats = $self->Delete('Genome', $genomeID, testMode => $testFlag);
3633      $retVal->Accumulate($stats);      $retVal->Accumulate($stats);
3634      # Return the result.      # Return the result.
3635      return $retVal;      return $retVal;
# Line 3442  Line 3677 
3677      return %retVal;      return %retVal;
3678  }  }
3679    
3680    =head3 GroupPageName
3681    
3682    C<< my $name = $sprout->GroupPageName($group); >>
3683    
3684    Return the name of the page for the specified NMPDR group.
3685    
3686    =over 4
3687    
3688    =item group
3689    
3690    Name of the relevant group.
3691    
3692    =item RETURN
3693    
3694    Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
3695    memory it will be read in.
3696    
3697    =back
3698    
3699    =cut
3700    
3701    sub GroupPageName {
3702        # Get the parameters.
3703        my ($self, $group) = @_;
3704        # Declare the return variable.
3705        my $retVal;
3706        # Check for the group file data.
3707        if (! defined $self->{groupHash}) {
3708            # Read the group file.
3709            my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");
3710            # Store it in our object.
3711            $self->{groupHash} = \%groupData;
3712        }
3713        # Compute the real group name.
3714        my $realGroup = $group;
3715        if ($group =~ /([A-Z]\w+)/) {
3716            $realGroup = $1;
3717        }
3718        # Return the page name.
3719        $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];
3720        # Return the result.
3721        return $retVal;
3722    }
3723    
3724  =head3 ReadGroupFile  =head3 ReadGroupFile
3725    
3726  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>
# Line 3503  Line 3782 
3782      return %retVal;      return %retVal;
3783  }  }
3784    
3785    =head3 AddProperty
3786    
3787    C<< my  = $sprout->AddProperty($featureID, $key, @values); >>
3788    
3789    Add a new attribute value (Property) to a feature.
3790    
3791    =over 4
3792    
3793    =item peg
3794    
3795    ID of the feature to which the attribute is to be added.
3796    
3797    =item key
3798    
3799    Name of the attribute (key).
3800    
3801    =item values
3802    
3803    Values of the attribute.
3804    
3805    =back
3806    
3807    =cut
3808    #: Return Type ;
3809    sub AddProperty {
3810        # Get the parameters.
3811        my ($self, $featureID, $key, @values) = @_;
3812        # Add the property using the attached attributes object.
3813        $self->{_ca}->AddAttribute($featureID, $key, @values);
3814    }
3815    
3816    =head2 Virtual Methods
3817    
3818    =head3 CleanKeywords
3819    
3820    C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>
3821    
3822    Clean up a search expression or keyword list. This involves converting the periods
3823    in EC numbers to underscores, converting non-leading minus signs to underscores,
3824    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
3825    characters. In addition, any extra spaces are removed.
3826    
3827    =over 4
3828    
3829    =item searchExpression
3830    
3831    Search expression or keyword list to clean. Note that a search expression may
3832    contain boolean operators which need to be preserved. This includes leading
3833    minus signs.
3834    
3835    =item RETURN
3836    
3837    Cleaned expression or keyword list.
3838    
3839    =back
3840    
3841    =cut
3842    
3843    sub CleanKeywords {
3844        # Get the parameters.
3845        my ($self, $searchExpression) = @_;
3846        # Perform the standard cleanup.
3847        my $retVal = $self->ERDB::CleanKeywords($searchExpression);
3848        # Fix the periods in EC and TC numbers.
3849        $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3850        # Fix non-trailing periods.
3851        $retVal =~ s/\.(\w)/_$1/g;
3852        # Fix non-leading minus signs.
3853        $retVal =~ s/(\w)[\-]/$1_/g;
3854        # Fix the vertical bars and colons
3855        $retVal =~ s/(\w)[|:](\w)/$1'$2/g;
3856        # Return the result.
3857        return $retVal;
3858    }
3859    
3860  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3861    
3862  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3592  Line 3946 
3946      return $retVal;      return $retVal;
3947  }  }
3948    
 =head3 AddProperty  
   
 C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>  
   
 Add a new attribute value (Property) to a feature. In the SEED system, attributes can  
 be added to almost any object. In Sprout, they can only be added to features. In  
 Sprout, attributes are implemented using I<properties>. A property represents a key/value  
 pair. If the particular key/value pair coming in is not already in the database, a new  
 B<Property> record is created to hold it.  
   
 =over 4  
   
 =item peg  
   
 ID of the feature to which the attribute is to be replied.  
   
 =item key  
   
 Name of the attribute (key).  
   
 =item value  
   
 Value of the attribute.  
   
 =item url  
   
 URL or text citation from which the property was obtained.  
   
 =back  
   
 =cut  
 #: Return Type ;  
 sub AddProperty {  
     # Get the parameters.  
     my ($self, $featureID, $key, $value, $url) = @_;  
     # Declare the variable to hold the desired property ID.  
     my $propID;  
     # Attempt to find a property record for this key/value pair.  
     my @properties = $self->GetFlat(['Property'],  
                                    "Property(property-name) = ? AND Property(property-value) = ?",  
                                    [$key, $value], 'Property(id)');  
     if (@properties) {  
         # Here the property is already in the database. We save its ID.  
         $propID = $properties[0];  
         # Here the property value does not exist. We need to generate an ID. It will be set  
         # to a number one greater than the maximum value in the database. This call to  
         # GetAll will stop after one record.  
         my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],  
                                         1);  
         $propID = $maxProperty[0]->[0] + 1;  
         # Insert the new property value.  
         $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });  
     }  
     # Now we connect the incoming feature to the property.  
     $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });  
 }  
   
3949    
3950  1;  1;

Legend:
Removed from v.1.83  
changed lines
  Added in v.1.99

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3