[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.82, Sat Sep 2 07:00:54 2006 UTC revision 1.85, Tue Sep 19 00:14:04 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 2962  Line 2977 
2977      # Get the parameters.      # Get the parameters.
2978      my ($self, $featureID, $function, $userID) = @_;      my ($self, $featureID, $function, $userID) = @_;
2979      # 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.
2980      my @bbhFeatures = $self->GetFlat(['IsBidirectionalBestHitOf'],      my @bbhFeatures = map { $_->[0] } FIGRules::BBHData($featureID);
                                      "IsBidirectionalBestHitOf(from-link) = ?", [$featureID],  
                                      'IsBidirectionalBestHitOf(to-link)');  
2981      # 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
2982      # functional assignment.      # functional assignment.
2983      my @retVal = ();      my @retVal = ();
# Line 3165  Line 3178 
3178      my ($self, $featureID, $cutoff) = @_;      my ($self, $featureID, $cutoff) = @_;
3179      # Create the return hash.      # Create the return hash.
3180      my %retVal = ();      my %retVal = ();
3181      # Create a query to get the desired BBHs.      # Query for the desired BBHs.
3182      my @bbhList = $self->GetAll(['IsBidirectionalBestHitOf'],      my @bbhList = FIGRules::BBHData($featureID, $cutoff);
                                 'IsBidirectionalBestHitOf(sc) <= ? AND IsBidirectionalBestHitOf(from-link) = ?',  
                                 [$cutoff, $featureID],  
                                 ['IsBidirectionalBestHitOf(to-link)', 'IsBidirectionalBestHitOf(sc)']);  
3183      # Form the results into the return hash.      # Form the results into the return hash.
3184      for my $pair (@bbhList) {      for my $pair (@bbhList) {
3185          $retVal{$pair->[0]} = $pair->[1];          $retVal{$pair->[0]} = $pair->[1];
# Line 3442  Line 3452 
3452      return %retVal;      return %retVal;
3453  }  }
3454    
3455    =head3 GroupPageName
3456    
3457    C<< my $name = $sprout->GroupPageName($group); >>
3458    
3459    Return the name of the page for the specified NMPDR group.
3460    
3461    =over 4
3462    
3463    =item group
3464    
3465    Name of the relevant group.
3466    
3467    =item RETURN
3468    
3469    Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
3470    memory it will be read in.
3471    
3472    =back
3473    
3474    =cut
3475    
3476    sub GroupPageName {
3477        # Get the parameters.
3478        my ($self, $group) = @_;
3479        # Declare the return variable.
3480        my $retVal;
3481        # Check for the group file data.
3482        if (! defined $self->{groupHash}) {
3483            # Read the group file.
3484            my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");
3485            # Store it in our object.
3486            $self->{groupHash} = \%groupData;
3487        }
3488        # Compute the real group name.
3489        my $realGroup = $group;
3490        if ($group =~ /([A-Z]\w+)/) {
3491            $realGroup = $1;
3492        }
3493        # Return the page name.
3494        $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];
3495        # Return the result.
3496        return $retVal;
3497    }
3498    
3499    =head3 ReadGroupFile
3500    
3501    C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>
3502    
3503    Read in the data from the specified group file. The group file contains information
3504    about each of the NMPDR groups.
3505    
3506    =over 4
3507    
3508    =item name
3509    
3510    Name of the group.
3511    
3512    =item page
3513    
3514    Name of the group's page on the web site (e.g. C<campy.php> for
3515    Campylobacter)
3516    
3517    =item genus
3518    
3519    Genus of the group
3520    
3521    =item species
3522    
3523    Species of the group, or an empty string if the group is for an entire
3524    genus. If the group contains more than one species, the species names
3525    should be separated by commas.
3526    
3527    =back
3528    
3529    The parameters to this method are as follows
3530    
3531    =over 4
3532    
3533    =item groupFile
3534    
3535    Name of the file containing the group data.
3536    
3537    =item RETURN
3538    
3539    Returns a hash keyed on group name. The value of each hash
3540    
3541    =back
3542    
3543    =cut
3544    
3545    sub ReadGroupFile {
3546        # Get the parameters.
3547        my ($groupFileName) = @_;
3548        # Declare the return variable.
3549        my %retVal;
3550        # Read the group file.
3551        my @groupLines = Tracer::GetFile($groupFileName);
3552        for my $groupLine (@groupLines) {
3553            my ($name, $page, $genus, $species) = split(/\t/, $groupLine);
3554            $retVal{$name} = [$page, $genus, $species];
3555        }
3556        # Return the result.
3557        return %retVal;
3558    }
3559    
3560  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3561    
3562  =head3 ParseAssignment  =head3 ParseAssignment

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3