--- Sprout.pm 2006/08/10 07:34:37 1.80
+++ Sprout.pm 2006/09/27 16:55:38 1.89
@@ -131,6 +131,8 @@
# Add the option table and XML file name.
$retVal->{_options} = $optionTable;
$retVal->{_xmlName} = $xmlFileName;
+ # Set up space for the group file data.
+ $retVal->{groupHash} = undef;
# Return it.
return $retVal;
}
@@ -340,7 +342,7 @@
=head3 GeneMenu
-C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params); >>
+C<< my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected); >>
Return an HTML select menu of genomes. Each genome will be an option in the menu,
and will be displayed by name with the ID and a contig count attached. The selection
@@ -362,6 +364,14 @@
Reference to a list of values to be substituted in for the parameter marks in
the filter string.
+=item selected (optional)
+
+ID of the genome to be initially selected.
+
+=item fast (optional)
+
+If specified and TRUE, the contig counts will be omitted to improve performance.
+
=item RETURN
Returns an HTML select menu with the specified genomes as selectable options.
@@ -372,7 +382,12 @@
sub GeneMenu {
# Get the parameters.
- my ($self, $attributes, $filterString, $params) = @_;
+ my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;
+ my $slowMode = ! $fast;
+ # Default to nothing selected. This prevents an execution warning if "$selected"
+ # is undefined.
+ $selected = "" unless defined $selected;
+ Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);
# Start the menu.
my $retVal = "\n";
# Return the result.
return $retVal;
}
+
=head3 Build
C<< $sprout->Build(); >>
@@ -634,6 +655,8 @@
return ($contigID, $start, $dir, $len);
}
+
+
=head3 PointLocation
C<< my $found = Sprout::PointLocation($location, $point); >>
@@ -1476,14 +1499,12 @@
my %retVal = ();
# Loop through the incoming features.
for my $featureID (@{$featureList}) {
- # Create a query to get the feature's best hit.
- my $query = $self->Get(['IsBidirectionalBestHitOf'],
- "IsBidirectionalBestHitOf(from-link) = ? AND IsBidirectionalBestHitOf(genome) = ?",
- [$featureID, $genomeID]);
+ # Ask the server for the feature's best hit.
+ my @bbhData = FIGRules::BBHData($featureID);
# Peel off the BBHs found.
my @found = ();
- while (my $bbh = $query->Fetch) {
- push @found, $bbh->Value('IsBidirectionalBestHitOf(to-link)');
+ for my $bbh (@bbhData) {
+ push @found, $bbh->[0];
}
$retVal{$featureID} = \@found;
}
@@ -1497,8 +1518,7 @@
Return a list of the similarities to the specified feature.
-Sprout does not support real similarities, so this method just returns the bidirectional
-best hits.
+This method just returns the bidirectional best hits for performance reasons.
=over 4
@@ -1518,10 +1538,7 @@
# Get the parameters.
my ($self, $featureID, $count) = @_;
# Ask for the best hits.
- my @lists = $self->GetAll(['IsBidirectionalBestHitOf'],
- "IsBidirectionalBestHitOf(from-link) = ? ORDER BY IsBidirectionalBestHitOf(score) DESC",
- [$featureID], ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(score)'],
- $count);
+ my @lists = FIGRules::BBHData($featureID);
# Create the return value.
my %retVal = ();
for my $tuple (@lists) {
@@ -1531,8 +1548,6 @@
return %retVal;
}
-
-
=head3 IsComplete
C<< my $flag = $sprout->IsComplete($genomeID); >>
@@ -2664,6 +2679,42 @@
return $retVal;
}
+=head3 PropertyID
+
+C<< my $id = $sprout->PropertyID($propName, $propValue); >>
+
+Return the ID of the specified property name and value pair, if the
+pair exists.
+
+=over 4
+
+=item propName
+
+Name of the desired property.
+
+=item propValue
+
+Value expected for the desired property.
+
+=item RETURN
+
+Returns the ID of the name/value pair, or C if the pair does not exist.
+
+=back
+
+=cut
+
+sub PropertyID {
+ # Get the parameters.
+ my ($self, $propName, $propValue) = @_;
+ # Try to find the ID.
+ my ($retVal) = $self->GetFlat(['Property'],
+ "Property(property-name) = ? AND Property(property-value) = ?",
+ [$propName, $propValue], 'Property(id)');
+ # Return the result.
+ return $retVal;
+}
+
=head3 MergedAnnotations
C<< my @annotationList = $sprout->MergedAnnotations(\@list); >>
@@ -2861,10 +2912,10 @@
# Get the parameters.
my ($self, $featureID) = @_;
# Get the list of names.
- my @retVal = $self->GetFlat(['ContainsFeature', 'HasSSCell'], "ContainsFeature(to-link) = ?",
- [$featureID], 'HasSSCell(from-link)');
- # Return the result.
- return @retVal;
+ my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",
+ [$featureID], 'HasRoleInSubsystem(to-link)');
+ # Return the result, sorted.
+ return sort @retVal;
}
=head3 GenomeSubsystemData
@@ -2962,9 +3013,7 @@
# Get the parameters.
my ($self, $featureID, $function, $userID) = @_;
# Get a list of the features that are BBHs of the incoming feature.
- my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],
- "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],
- 'IsBidirectionalBestHitOf(to-link)');
+ my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
# Now we loop through the features, pulling out the ones that have the correct
# functional assignment.
my @retVal = ();
@@ -3165,11 +3214,8 @@
my ($self, $featureID, $cutoff) = @_;
# Create the return hash.
my %retVal = ();
- # Create a query to get the desired BBHs.
- my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],
- 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',
- [$cutoff, $featureID],
- ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);
+ # Query for the desired BBHs.
+ my @bbhList = FIGRules::BBHData($featureID, $cutoff);
# Form the results into the return hash.
for my $pair (@bbhList) {
$retVal{$pair->[0]} = $pair->[1];
@@ -3264,7 +3310,7 @@
# Here we have a group list. Loop through them individually,
# getting a list of the relevant genomes.
for my $group (@{$groupList}) {
- my @genomeIDs = $self->GetFlat(['Genome'], "Genome(group-name) = ?",
+ my @genomeIDs = $self->GetFlat(['Genome'], "Genome(primary-group) = ?",
[$group], "Genome(id)");
$retVal{$group} = \@genomeIDs;
}
@@ -3272,9 +3318,9 @@
# Here we need all of the groups. In this case, we run through all
# of the genome records, putting each one found into the appropriate
# group. Note that we use a filter clause to insure that only genomes
- # in groups are included in the return set.
- my @genomes = $self->GetAll(['Genome'], "Genome(group-name) > ' '", [],
- ['Genome(id)', 'Genome(group-name)']);
+ # in real NMPDR groups are included in the return set.
+ my @genomes = $self->GetAll(['Genome'], "Genome(primary-group) <> ?",
+ [$FIG_Config::otherGroup], ['Genome(id)', 'Genome(primary-group)']);
# Loop through the genomes found.
for my $genome (@genomes) {
# Pop this genome's ID off the current list.
@@ -3400,6 +3446,153 @@
return $retVal;
}
+=head3 Fix
+
+C<< my %fixedHash = Sprout::Fix(%groupHash); >>
+
+Prepare a genome group hash (like that returned by L for processing.
+Groups with the same primary name will be combined. The primary name is the
+first capitalized word in the group name.
+
+=over 4
+
+=item groupHash
+
+Hash to be fixed up.
+
+=item RETURN
+
+Returns a fixed-up version of the hash.
+
+=back
+
+=cut
+
+sub Fix {
+ # Get the parameters.
+ my (%groupHash) = @_;
+ # Create the result hash.
+ my %retVal = ();
+ # Copy over the genomes.
+ for my $groupID (keys %groupHash) {
+ # Make a safety copy of the group ID.
+ my $realGroupID = $groupID;
+ # Yank the primary name.
+ if ($groupID =~ /([A-Z]\w+)/) {
+ $realGroupID = $1;
+ }
+ # Append this group's genomes into the result hash.
+ Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});
+ }
+ # Return the result hash.
+ return %retVal;
+}
+
+=head3 GroupPageName
+
+C<< my $name = $sprout->GroupPageName($group); >>
+
+Return the name of the page for the specified NMPDR group.
+
+=over 4
+
+=item group
+
+Name of the relevant group.
+
+=item RETURN
+
+Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
+memory it will be read in.
+
+=back
+
+=cut
+
+sub GroupPageName {
+ # Get the parameters.
+ my ($self, $group) = @_;
+ # Declare the return variable.
+ my $retVal;
+ # Check for the group file data.
+ if (! defined $self->{groupHash}) {
+ # Read the group file.
+ my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");
+ # Store it in our object.
+ $self->{groupHash} = \%groupData;
+ }
+ # Compute the real group name.
+ my $realGroup = $group;
+ if ($group =~ /([A-Z]\w+)/) {
+ $realGroup = $1;
+ }
+ # Return the page name.
+ $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];
+ # Return the result.
+ return $retVal;
+}
+
+=head3 ReadGroupFile
+
+C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>
+
+Read in the data from the specified group file. The group file contains information
+about each of the NMPDR groups.
+
+=over 4
+
+=item name
+
+Name of the group.
+
+=item page
+
+Name of the group's page on the web site (e.g. C for
+Campylobacter)
+
+=item genus
+
+Genus of the group
+
+=item species
+
+Species of the group, or an empty string if the group is for an entire
+genus. If the group contains more than one species, the species names
+should be separated by commas.
+
+=back
+
+The parameters to this method are as follows
+
+=over 4
+
+=item groupFile
+
+Name of the file containing the group data.
+
+=item RETURN
+
+Returns a hash keyed on group name. The value of each hash
+
+=back
+
+=cut
+
+sub ReadGroupFile {
+ # Get the parameters.
+ my ($groupFileName) = @_;
+ # Declare the return variable.
+ my %retVal;
+ # Read the group file.
+ my @groupLines = Tracer::GetFile($groupFileName);
+ for my $groupLine (@groupLines) {
+ my ($name, $page, $genus, $species) = split(/\t/, $groupLine);
+ $retVal{$name} = [$page, $genus, $species];
+ }
+ # Return the result.
+ return %retVal;
+}
+
=head2 Internal Utility Methods
=head3 ParseAssignment
@@ -3456,7 +3649,7 @@
}
# If we have an assignment, we need to clean the function text. There may be
# extra junk at the end added as a note from the user.
- if (@retVal > 1) {
+ if (defined( $retVal[1] )) {
$retVal[1] =~ s/(\t\S)?\s*$//;
}
# Return the result list.