[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.90, Fri Sep 29 15:10:05 2006 UTC
# Line 131  Line 131 
131      # Add the option table and XML file name.      # Add the option table and XML file name.
132      $retVal->{_options} = $optionTable;      $retVal->{_options} = $optionTable;
133      $retVal->{_xmlName} = $xmlFileName;      $retVal->{_xmlName} = $xmlFileName;
134        # Set up space for the group file data.
135        $retVal->{groupHash} = undef;
136      # Return it.      # Return it.
137      return $retVal;      return $retVal;
138  }  }
# Line 340  Line 342 
342    
343  =head3 GeneMenu  =head3 GeneMenu
344    
345  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>  C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>
346    
347  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,
348  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 364 
364  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
365  the filter string.  the filter string.
366    
367    =item selected (optional)
368    
369    ID of the genome to be initially selected.
370    
371    =item fast (optional)
372    
373    If specified and TRUE, the contig counts will be omitted to improve performance.
374    
375  =item RETURN  =item RETURN
376    
377  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 382 
382    
383  sub GeneMenu {  sub GeneMenu {
384      # Get the parameters.      # Get the parameters.
385      my ($self, $attributes, $filterString, $params) = @_;      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;
386        my $slowMode = ! $fast;
387        # Default to nothing selected. This prevents an execution warning if "$selected"
388        # is undefined.
389        $selected = "" unless defined $selected;
390        Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);
391      # Start the menu.      # Start the menu.
392      my $retVal = "<select " .      my $retVal = "<select " .
393          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .
# Line 389  Line 404 
404          # Get the data for this genome.          # Get the data for this genome.
405          my ($genomeID, $genus, $species, $strain) = @{$genomeData};          my ($genomeID, $genus, $species, $strain) = @{$genomeData};
406          # Get the contig count.          # Get the contig count.
407            my $contigInfo = "";
408            if ($slowMode) {
409          my $count = $self->ContigCount($genomeID);          my $count = $self->ContigCount($genomeID);
410          my $counting = ($count == 1 ? "contig" : "contigs");          my $counting = ($count == 1 ? "contig" : "contigs");
411                $contigInfo = "[$count $counting]";
412            }
413            # Find out if we're selected.
414            my $selectOption = ($selected eq $genomeID ? " selected" : "");
415          # Build the option tag.          # Build the option tag.
416          $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);  
417      }      }
418      # Close the SELECT tag.      # Close the SELECT tag.
419      $retVal .= "</select>\n";      $retVal .= "</select>\n";
420      # Return the result.      # Return the result.
421      return $retVal;      return $retVal;
422  }  }
423    
424  =head3 Build  =head3 Build
425    
426  C<< $sprout->Build(); >>  C<< $sprout->Build(); >>
# Line 634  Line 655 
655      return ($contigID, $start, $dir, $len);      return ($contigID, $start, $dir, $len);
656  }  }
657    
658    
659    
660  =head3 PointLocation  =head3 PointLocation
661    
662  C<< my $found = Sprout::PointLocation($location, $point); >>  C<< my $found = Sprout::PointLocation($location, $point); >>
# Line 1476  Line 1499 
1499      my %retVal = ();      my %retVal = ();
1500      # Loop through the incoming features.      # Loop through the incoming features.
1501      for my $featureID (@{$featureList}) {      for my $featureID (@{$featureList}) {
1502          # Create a query to get the feature's best hit.          # Ask the server for the feature's best hit.
1503          my $query = $self->Get(['IsBidirectionalBestHitOf'],          my @bbhData = FIGRules::BBHData($featureID);
                                "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",  
                                [$featureID, $genomeID]);  
1504          # Peel off the BBHs found.          # Peel off the BBHs found.
1505          my @found = ();          my @found = ();
1506          while (my $bbh = $query->Fetch) {          for my $bbh (@bbhData) {
1507              push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');              push @found, $bbh->[0];
1508          }          }
1509          $retVal{$featureID} = \@found;          $retVal{$featureID} = \@found;
1510      }      }
# Line 1497  Line 1518 
1518    
1519  Return a list of the similarities to the specified feature.  Return a list of the similarities to the specified feature.
1520    
1521  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.  
1522    
1523  =over 4  =over 4
1524    
# Line 1518  Line 1538 
1538      # Get the parameters.      # Get the parameters.
1539      my ($self, $featureID, $count) = @_;      my ($self, $featureID, $count) = @_;
1540      # Ask for the best hits.      # Ask for the best hits.
1541      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);  
1542      # Create the return value.      # Create the return value.
1543      my %retVal = ();      my %retVal = ();
1544      for my $tuple (@lists) {      for my $tuple (@lists) {
# Line 1531  Line 1548 
1548      return %retVal;      return %retVal;
1549  }  }
1550    
   
   
1551  =head3 IsComplete  =head3 IsComplete
1552    
1553  C<< my $flag = $sprout->IsComplete($genomeID); >>  C<< my $flag = $sprout->IsComplete($genomeID); >>
# Line 2664  Line 2679 
2679      return $retVal;      return $retVal;
2680  }  }
2681    
2682    =head3 PropertyID
2683    
2684    C<< my $id = $sprout->PropertyID($propName, $propValue); >>
2685    
2686    Return the ID of the specified property name and value pair, if the
2687    pair exists.
2688    
2689    =over 4
2690    
2691    =item propName
2692    
2693    Name of the desired property.
2694    
2695    =item propValue
2696    
2697    Value expected for the desired property.
2698    
2699    =item RETURN
2700    
2701    Returns the ID of the name/value pair, or C<undef> if the pair does not exist.
2702    
2703    =back
2704    
2705    =cut
2706    
2707    sub PropertyID {
2708        # Get the parameters.
2709        my ($self, $propName, $propValue) = @_;
2710        # Try to find the ID.
2711        my ($retVal) = $self->GetFlat(['Property'],
2712                                      "Property(property-name) = ? AND Property(property-value) = ?",
2713                                      [$propName, $propValue], 'Property(id)');
2714        # Return the result.
2715        return $retVal;
2716    }
2717    
2718  =head3 MergedAnnotations  =head3 MergedAnnotations
2719    
2720  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>  C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>
# Line 2861  Line 2912 
2912      # Get the parameters.      # Get the parameters.
2913      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
2914      # Get the list of names.      # Get the list of names.
2915      my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",
2916                                  [$featureID], 'HasSSCell(from-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
2917      # Return the result.      # Return the result, sorted.
2918      return @retVal;      return sort @retVal;
2919  }  }
2920    
2921  =head3 GenomeSubsystemData  =head3 GenomeSubsystemData
# Line 2962  Line 3013 
3013      # Get the parameters.      # Get the parameters.
3014      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
3015      # 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.
3016      my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
                                      "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],  
                                      'IsBidirectionalBestHitOf(to-link)');  
3017      # 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
3018      # functional assignment.      # functional assignment.
3019      my @retVal = ();      my @retVal = ();
# Line 3165  Line 3214 
3214      my ($self, $featureID, $cutoff) = @_;      my ($self, $featureID, $cutoff) = @_;
3215      # Create the return hash.      # Create the return hash.
3216      my %retVal = ();      my %retVal = ();
3217      # Create a query to get the desired BBHs.      # Query for the desired BBHs.
3218      my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
                                 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',  
                                 [$cutoff, $featureID],  
                                 ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);  
3219      # Form the results into the return hash.      # Form the results into the return hash.
3220      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3221          $retVal{$pair->[0]} = $pair->[1];          $retVal{$pair->[0]} = $pair->[1];
# Line 3243  Line 3289 
3289      return $retVal;      return $retVal;
3290  }  }
3291    
3292    =head3 IsAllGenomes
3293    
3294    C<< my $flag = $sprout->IsAllGenomes(\@list, \@checkList); >>
3295    
3296    Return TRUE if all genomes in the second list are represented in the first list at
3297    least one. Otherwise, return FALSE. If the second list is omitted, the first list is
3298    compared to a list of all the genomes.
3299    
3300    =over 4
3301    
3302    =item list
3303    
3304    Reference to the list to be compared to the second list.
3305    
3306    =item checkList (optional)
3307    
3308    Reference to the comparison target list. Every genome ID in this list must occur at
3309    least once in the first list. If this parameter is omitted, a list of all the genomes
3310    is used.
3311    
3312    =item RETURN
3313    
3314    Returns TRUE if every item in the second list appears at least once in the
3315    first list, else FALSE.
3316    
3317    =back
3318    
3319    =cut
3320    
3321    sub IsAllGenomes {
3322        # Get the parameters.
3323        my ($self, $list, $checkList) = @_;
3324        # Supply the checklist if it was omitted.
3325        $checkList = [$self->Genomes()] if ! defined($checkList);
3326        # Create a hash of the original list.
3327        my %testList = map { $_ => 1 } @{$list};
3328        # Declare the return variable. We assume that the representation
3329        # is complete and stop at the first failure.
3330        my $retVal = 1;
3331        my $n = scalar @{$checkList};
3332        for (my $i = 0; $retVal && $i < $n; $i++) {
3333            if (! $testList{$checkList->[$i]}) {
3334                $retVal = 0;
3335            }
3336        }
3337        # Return the result.
3338        return $retVal;
3339    }
3340    
3341  =head3 GetGroups  =head3 GetGroups
3342    
3343  C<< my %groups = $sprout->GetGroups(\@groupList); >>  C<< my %groups = $sprout->GetGroups(\@groupList); >>
# Line 3264  Line 3359 
3359          # Here we have a group list. Loop through them individually,          # Here we have a group list. Loop through them individually,
3360          # getting a list of the relevant genomes.          # getting a list of the relevant genomes.
3361          for my $group (@{$groupList}) {          for my $group (@{$groupList}) {
3362              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",              my @genomeIDs = $self->GetFlat(['Genome'], "Genome(primary-group) = ?",
3363                  [$group], "Genome(id)");                  [$group], "Genome(id)");
3364              $retVal{$group} = \@genomeIDs;              $retVal{$group} = \@genomeIDs;
3365          }          }
# Line 3272  Line 3367 
3367          # 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
3368          # of the genome records, putting each one found into the appropriate          # of the genome records, putting each one found into the appropriate
3369          # 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
3370          # in groups are included in the return set.          # in real NMPDR groups are included in the return set.
3371          my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],          my @genomes = $self->GetAll(['Genome'], "Genome(primary-group) <> ?",
3372                                      ['Genome(id)', 'Genome(group-name)']);                                      [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
3373          # Loop through the genomes found.          # Loop through the genomes found.
3374          for my $genome (@genomes) {          for my $genome (@genomes) {
3375              # Pop this genome's ID off the current list.              # Pop this genome's ID off the current list.
# Line 3442  Line 3537 
3537      return %retVal;      return %retVal;
3538  }  }
3539    
3540    =head3 GroupPageName
3541    
3542    C<< my $name = $sprout->GroupPageName($group); >>
3543    
3544    Return the name of the page for the specified NMPDR group.
3545    
3546    =over 4
3547    
3548    =item group
3549    
3550    Name of the relevant group.
3551    
3552    =item RETURN
3553    
3554    Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
3555    memory it will be read in.
3556    
3557    =back
3558    
3559    =cut
3560    
3561    sub GroupPageName {
3562        # Get the parameters.
3563        my ($self, $group) = @_;
3564        # Declare the return variable.
3565        my $retVal;
3566        # Check for the group file data.
3567        if (! defined $self->{groupHash}) {
3568            # Read the group file.
3569            my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");
3570            # Store it in our object.
3571            $self->{groupHash} = \%groupData;
3572        }
3573        # Compute the real group name.
3574        my $realGroup = $group;
3575        if ($group =~ /([A-Z]\w+)/) {
3576            $realGroup = $1;
3577        }
3578        # Return the page name.
3579        $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];
3580        # Return the result.
3581        return $retVal;
3582    }
3583    
3584  =head3 ReadGroupFile  =head3 ReadGroupFile
3585    
3586  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>
# Line 3503  Line 3642 
3642      return %retVal;      return %retVal;
3643  }  }
3644    
3645    =head3 AddProperty
3646    
3647    C<< my  = $sprout->AddProperty($featureID, $key, $value, $url); >>
3648    
3649    Add a new attribute value (Property) to a feature. In the SEED system, attributes can
3650    be added to almost any object. In Sprout, they can only be added to features. In
3651    Sprout, attributes are implemented using I<properties>. A property represents a key/value
3652    pair. If the particular key/value pair coming in is not already in the database, a new
3653    B<Property> record is created to hold it.
3654    
3655    =over 4
3656    
3657    =item peg
3658    
3659    ID of the feature to which the attribute is to be replied.
3660    
3661    =item key
3662    
3663    Name of the attribute (key).
3664    
3665    =item value
3666    
3667    Value of the attribute.
3668    
3669    =item url
3670    
3671    URL or text citation from which the property was obtained.
3672    
3673    =back
3674    
3675    =cut
3676    #: Return Type ;
3677    sub AddProperty {
3678        # Get the parameters.
3679        my ($self, $featureID, $key, $value, $url) = @_;
3680        # Declare the variable to hold the desired property ID.
3681        my $propID;
3682        # Attempt to find a property record for this key/value pair.
3683        my @properties = $self->GetFlat(['Property'],
3684                                       "Property(property-name) = ? AND Property(property-value) = ?",
3685                                       [$key, $value], 'Property(id)');
3686        if (@properties) {
3687            # Here the property is already in the database. We save its ID.
3688            $propID = $properties[0];
3689            # Here the property value does not exist. We need to generate an ID. It will be set
3690            # to a number one greater than the maximum value in the database. This call to
3691            # GetAll will stop after one record.
3692            my @maxProperty = $self->GetAll(['Property'], "ORDER BY Property(id) DESC", [], ['Property(id)'],
3693                                            1);
3694            $propID = $maxProperty[0]->[0] + 1;
3695            # Insert the new property value.
3696            $self->Insert('Property', { 'property-name' => $key, 'property-value' => $value, id => $propID });
3697        }
3698        # Now we connect the incoming feature to the property.
3699        $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3700    }
3701    
3702  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3703    
3704  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3592  Line 3788 
3788      return $retVal;      return $retVal;
3789  }  }
3790    
 =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 });  
 }  
   
3791    
3792  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3