[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.106, Wed Feb 6 23:21:02 2008 UTC revision 1.118, Sat Sep 20 14:32:34 2008 UTC
# Line 14  Line 14 
14      use BasicLocation;      use BasicLocation;
15      use CustomAttributes;      use CustomAttributes;
16      use RemoteCustomAttributes;      use RemoteCustomAttributes;
17        use CGI;
18        use WikiTools;
19        use BioWords;
20      use base qw(ERDB);      use base qw(ERDB);
21    
22  =head1 Sprout Database Manipulation Object  =head1 Sprout Database Manipulation Object
# Line 105  Line 108 
108                                                          # data file directory                                                          # data file directory
109                         xmlFileName  => "$dbd_dir/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
110                                                          # database definition file name                                                          # database definition file name
111                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::sproutUser/$FIG_Config::sproutPass",
112                                                          # user name and password                                                          # user name and password
113                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::sproutPort,
114                                                          # database connection port                                                          # database connection port
115                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::sproutSock,
116                         host         => $FIG_Config::sprout_host,                         host         => $FIG_Config::sprout_host,
117                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
118                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
# Line 150  Line 153 
153      return $retVal;      return $retVal;
154  }  }
155    
156  =head3 RealCoreGenomes  =head3 CoreGenomes
157    
158      my @genomes = $sprout->RealCoreGenomes();      my @genomes = $sprout->CoreGenomes($scope);
159    
160  Return the IDs of the original core NMPDR genomes. These are the ones  Return the IDs of NMPDR genomes in the specified scope.
161  in the major groups indicated in the C<@realCoreGroups> member of the  
162  B<FIG_Config> file.  =over 4
163    
164    =item scope
165    
166    Scope of the desired genomes. C<core> covers the original core genomes,
167    C<nmpdr> covers all genomes in NMPDR groups, and C<all> covers all
168    genomes in the system.
169    
170    =item RETURN
171    
172    Returns a list of the IDs for the genomes in the specified scope.
173    
174    =back
175    
176  =cut  =cut
177    
178  sub RealCoreGenomes {  sub CoreGenomes {
179      # Get the parameters.      # Get the parameters.
180      my ($self) = @_;      my ($self, $scope) = @_;
181      # Declare the return variable.      # Declare the return variable.
182      my @retVal = ();      my @retVal = ();
183      # Get the hash of all the genome groups.      # If we want all genomes, then this is easy.
184        if ($scope eq 'all') {
185            @retVal = $self->Genomes();
186        } else {
187            # Here we're dealing with groups. Get the hash of all the
188            # genome groups.
189      my %groups = $self->GetGroups();      my %groups = $self->GetGroups();
190      # Loop through the groups, keeping the ones that belong to real core          # Loop through the groups, keeping the ones that we want.
     # organisms.  
191      for my $group (keys %groups) {      for my $group (keys %groups) {
192          if (grep { $group =~ /$_/ } @FIG_Config::realCoreGroups) {              # Decide if we want to keep this group.
193                my $keepGroup = 0;
194                if ($scope eq 'nmpdr') {
195                    # NMPDR mode: keep all groups.
196                    $keepGroup = 1;
197                } elsif ($scope eq 'core') {
198                    # CORE mode. Only keep real core groups.
199                    if (grep { $group =~ /$_/ } @{$FIG_Config::realCoreGroups}) {
200                        $keepGroup = 1;
201                    }
202                }
203                # Add this group if we're keeping it.
204                if ($keepGroup) {
205              push @retVal, @{$groups{$group}};              push @retVal, @{$groups{$group}};
206          }          }
207      }      }
208        }
209      # Return the result.      # Return the result.
210      return @retVal;      return @retVal;
211  }  }
212    
213    =head3 SuperGroup
214    
215        my $superGroup = $sprout->SuperGroup($groupName);
216    
217    Return the name of the super-group containing the specified NMPDR genome
218    group. If no appropriate super-group can be found, an error will be
219    thrown.
220    
221    =over 4
222    
223    =item groupName
224    
225    Name of the group whose super-group is desired.
226    
227    =item RETURN
228    
229    Returns the name of the super-group containing the incoming group.
230    
231    =back
232    
233    =cut
234    
235    sub SuperGroup {
236        # Get the parameters.
237        my ($self, $groupName) = @_;
238        # Declare the return variable.
239        my $retVal;
240        # Get the group hash.
241        my %groupHash = $self->CheckGroupFile();
242        # Find the super-group genus.
243        $groupName =~ /([A-Z]\w+)/;
244        my $nameThing = $1;
245        # See if it's directly in the group hash.
246        if (exists $groupHash{$nameThing}) {
247            # Yes, then it's our result.
248            $retVal = $nameThing;
249        } else {
250            # No, so we have to search.
251            for my $superGroup (keys %groupHash) {
252                # Get this super-group's item list.
253                my $list = $groupHash{$superGroup}->{contents};
254                # Search it.
255                if (grep { $_->[0] eq $nameThing } @{$list}) {
256                    $retVal = $superGroup;
257                }
258            }
259            # Make sure we found something.
260            if (! $retVal) {
261                Confess("No super-group found for \"$groupName\".");
262            }
263        }
264        # Return the result.
265        return $retVal;
266    }
267    
268  =head3 MaxSegment  =head3 MaxSegment
269    
270      my $length = $sprout->MaxSegment();      my $length = $sprout->MaxSegment();
# Line 381  Line 468 
468      return $retVal;      return $retVal;
469  }  }
470    
471  =head3 GeneMenu  =head3 GenomeMenu
472    
473        my $html = $sprout->GenomeMenu(%options);
474    
475      my $selectHtml = $sprout->GeneMenu(\%attributes, $filterString, \@params, $selected);  Generate a genome selection control with the specified name and options.
476    This control is almost but not quite the same as the genome control in the
477    B<SearchHelper> class. Eventually, the two will be combined.
478    
479  Return an HTML select menu of genomes. Each genome will be an option in the menu,  =over 4
480  and will be displayed by name with the ID and a contig count attached. The selection  
481  value will be the genome ID. The genomes will be sorted by genus/species name.  =item options
482    
483    Optional parameters for the control (see below).
484    
485    =item RETURN
486    
487    Returns the HTML for a genome selection control on a form (sometimes called a popup menu).
488    
489    =back
490    
491    The valid options are as follows.
492    
493  =over 4  =over 4
494    
495  =item attributes  =item name
496    
497  Reference to a hash mapping attributes to values for the SELECT tag generated.  Name to give this control for use in passing it to the form. The default is C<myGenomeControl>.
498    Terrible things will happen if you have two controls with the same name on the same page.
499    
500  =item filterString  =item filter
501    
502  A filter string for use in selecting the genomes. The filter string must conform  If specified, a filter for the list of genomes to display. The filter should be in the form of a
503  to the rules for the C<< ERDB->Get >> method.  list reference. The first element of the list should be the filter string, and the remaining elements
504    the filter parameters.
505    
506  =item params  =item multiSelect
507    
508  Reference to a list of values to be substituted in for the parameter marks in  If TRUE, then the user can select multiple genomes. If FALSE, the user can only select one genome.
 the filter string.  
509    
510  =item selected (optional)  =item size
511    
512  ID of the genome to be initially selected.  Number of rows to display in the control. The default is C<10>
513    
514  =item fast (optional)  =item id
515    
516  If specified and TRUE, the contig counts will be omitted to improve performance.  ID to give this control. The default is the value of the C<name> option. Nothing will work correctly
517    unless this ID is unique.
518    
519  =item RETURN  =item selected
520    
521  Returns an HTML select menu with the specified genomes as selectable options.  A comma-delimited list of selected genomes, or a reference to a list of selected genomes. The
522    default is none.
523    
524    =item class
525    
526    If specified, a style class to assign to the genome control.
527    
528  =back  =back
529    
530  =cut  =cut
531    
532  sub GeneMenu {  sub GenomeMenu {
533      # Get the parameters.      # Get the parameters.
534      my ($self, $attributes, $filterString, $params, $selected, $fast) = @_;      my ($self, %options) = @_;
535      my $slowMode = ! $fast;      # Get the control's name and ID.
536      # Default to nothing selected. This prevents an execution warning if "$selected"      my $menuName = $options{name} || $options{id} || 'myGenomeControl';
537      # is undefined.      my $menuID = $options{id} || $menuName;
538      $selected = "" unless defined $selected;      Trace("Genome menu name = $menuName with ID $menuID.") if T(3);
539      Trace("Gene Menu called with slow mode \"$slowMode\" and selection \"$selected\".") if T(3);      # Compute the IDs for the status display.
540      # Start the menu.      my $divID = "${menuID}_status";
541      my $retVal = "<select " .      my $urlID = "${menuID}_url";
542          join(" ", map { "$_=\"$attributes->{$_}\"" } keys %{$attributes}) .      # Compute the code to show selected genomes in the status area.
543          ">\n";      my $showSelect = "showSelected('$menuID', '$divID', '$urlID', 1000)";
544      # Get the genomes.      # Check for single-select or multi-select.
545      my @genomes = $self->GetAll(['Genome'], $filterString, $params, ['Genome(id)',      my $multiSelect = $options{multiSelect} || 0;
546                                                                       'Genome(genus)',      # Get the style data.
547                                                                       'Genome(species)',      my $class = $options{class} || '';
548                                                                       'Genome(unique-characterization)']);      # Get the list of pre-selected items.
549      # Sort them by name.      my $selections = $options{selected} || [];
550      my @sorted = sort { lc("$a->[1] $a->[2]") cmp lc("$b->[1] $b->[2]") } @genomes;      if (ref $selections ne 'ARRAY') {
551      # Loop through the genomes, creating the option tags.          $selections = [ split /\s*,\s*/, $selections ];
552      for my $genomeData (@sorted) {      }
553          # Get the data for this genome.      my %selected = map { $_ => 1 } @{$selections};
554          my ($genomeID, $genus, $species, $strain) = @{$genomeData};      # Extract the filter information. The default is no filtering. It can be passed as a tab-delimited
555          # Get the contig count.      # string or a list reference.
556          my $contigInfo = "";      my $filterParms = $options{filter} || "";
557          if ($slowMode) {      if (! ref $filterParms) {
558              my $count = $self->ContigCount($genomeID);          $filterParms = [split /\t|\\t/, $filterParms];
559              my $counting = ($count == 1 ? "contig" : "contigs");      }
560              $contigInfo = "[$count $counting]";      my $filterString = shift @{$filterParms};
561          }      # Get a list of all the genomes in group order. In fact, we only need them ordered
562          # Find out if we're selected.      # by name (genus,species,strain), but putting primary-group in front enables us to
563          my $selectOption = ($selected eq $genomeID ? " selected" : "");      # take advantage of an existing index.
564          # Build the option tag.      my @genomeList = $self->GetAll(['Genome'], "$filterString ORDER BY Genome(primary-group), Genome(genus), Genome(species), Genome(unique-characterization)",
565          $retVal .= "<option value=\"$genomeID\"$selectOption>$genus $species $strain ($genomeID)$contigInfo</option>\n";                                     $filterParms,
566                                       [qw(Genome(primary-group) Genome(id) Genome(genus) Genome(species) Genome(unique-characterization) Genome(taxonomy) Genome(contigs))]);
567        # Create a hash to organize the genomes by group. Each group will contain a list of
568        # 2-tuples, the first element being the genome ID and the second being the genome
569        # name.
570        my %gHash = ();
571        for my $genome (@genomeList) {
572            # Get the genome data.
573            my ($group, $genomeID, $genus, $species, $strain, $taxonomy, $contigs) = @{$genome};
574            # Compute its name. This is the genus, species, strain (if any), and the contig count.
575            my $name = "$genus $species ";
576            $name .= "$strain " if $strain;
577            my $contigCount = ($contigs == 1 ? "" : ", $contigs contigs");
578            # Now we get the domain. The domain tells us the display style of the organism.
579            my ($domain) = split /\s*;\s*/, $taxonomy, 2;
580            # Now compute the display group. This is normally the primary group, but if the
581            # organism is supporting, we blank it out.
582            my $displayGroup = ($group eq $FIG_Config::otherGroup ? "" : $group);
583            # Push the genome into the group's list. Note that we use the real group
584            # name for the hash key here, not the display group name.
585            push @{$gHash{$group}}, [$genomeID, $name, $contigCount, $domain];
586        }
587        # We are almost ready to unroll the menu out of the group hash. The final step is to separate
588        # the supporting genomes by domain. First, we extract the NMPDR groups and sort them. They
589        # are sorted by the first capitalized word. Groups with "other" are sorted after groups
590        # that aren't "other". At some point, we will want to make this less complicated.
591        my %sortGroups = map { $_ =~ /(other)?(.*)([A-Z].+)/; "$3$1$2" => $_ }
592                             grep { $_ ne $FIG_Config::otherGroup } keys %gHash;
593        my @groups = map { $sortGroups{$_} } sort keys %sortGroups;
594        # Remember the number of NMPDR groups.
595        my $nmpdrGroupCount = scalar @groups;
596        # Loop through the supporting genomes, classifying them by domain. We'll also keep a list
597        # of the domains found.
598        my @otherGenomes = @{$gHash{$FIG_Config::otherGroup}};
599        my @domains = ();
600        for my $genomeData (@otherGenomes) {
601            my ($genomeID, $name, $contigCount, $domain) = @{$genomeData};
602            if (exists $gHash{$domain}) {
603                push @{$gHash{$domain}}, $genomeData;
604            } else {
605                $gHash{$domain} = [$genomeData];
606                push @domains, $domain;
607            }
608        }
609        # Add the domain groups at the end of the main group list. The main group list will now
610        # contain all the categories we need to display the genomes.
611        push @groups, sort @domains;
612        # Delete the supporting group.
613        delete $gHash{$FIG_Config::otherGroup};
614        # Now it gets complicated. We need a way to mark all the NMPDR genomes. We take advantage
615        # of the fact they come first in the list. We'll accumulate a count of the NMPDR genomes
616        # and use that to make the selections.
617        my $nmpdrCount = 0;
618        # Create the type counters.
619        my $groupCount = 1;
620        # Get the number of rows to display.
621        my $rows = $options{size} || 10;
622        # If we're multi-row, create an onChange event.
623        my $onChangeTag = ( $rows > 1 ? " onChange=\"$showSelect;\" onFocus=\"$showSelect;\"" : "" );
624        # Set up the multiple-select flag.
625        my $multipleTag = ($multiSelect ? " multiple" : "" );
626        # Set up the style class.
627        my $classTag = ($class ? " class=\"$class\"" : "" );
628        # Create the SELECT tag and stuff it into the output array.
629        my @lines = ("<SELECT name=\"$menuName\" id=\"$menuID\" $onChangeTag$multipleTag$classTag size=\"$rows\">");
630        # Loop through the groups.
631        for my $group (@groups) {
632            # Get the genomes in the group.
633            for my $genome (@{$gHash{$group}}) {
634                # If this is an NMPDR organism, we add an extra style and count it.
635                my $nmpdrStyle = "";
636                if ($nmpdrGroupCount > 0) {
637                    $nmpdrCount++;
638                    $nmpdrStyle = " Core";
639                }
640                # Get the organism ID, name, contig count, and domain.
641                my ($genomeID, $name, $contigCount, $domain) = @{$genome};
642                # See if we're pre-selected.
643                my $selectTag = ($selected{$genomeID} ? " SELECTED" : "");
644                # Compute the display name.
645                my $nameString = "$name ($genomeID$contigCount)";
646                # Generate the option tag.
647                my $optionTag = "<OPTION class=\"$domain$nmpdrStyle\" title=\"$group\" value=\"$genomeID\"$selectTag>$nameString</OPTION>";
648                push @lines, "    $optionTag";
649            }
650            # Record this group in the nmpdrGroup count. When that gets to 0, we've finished the NMPDR
651            # groups.
652            $nmpdrGroupCount--;
653      }      }
654      # Close the SELECT tag.      # Close the SELECT tag.
655      $retVal .= "</select>\n";      push @lines, "</SELECT>";
656        if ($rows > 1) {
657            # We're in a non-compact mode, so we need to add some selection helpers. First is
658            # the search box. This allows the user to type text and change which genomes are
659            # displayed. For multiple-select mode, we include a button that selects the displayed
660            # genes. For single-select mode, we use a plain label instead.
661            my $searchThingName = "${menuID}_SearchThing";
662            my $searchThingLabel = ($multiSelect ? "<INPUT type=\"button\" name=\"MacroSearch\" class=\"button\" value=\"Select genomes containing\" onClick=\"selectShowing('$menuID', '$searchThingName'); $showSelect;\" />"
663                                                 : "Show genomes containing");
664            push @lines, "<br />$searchThingLabel&nbsp;" .
665                         "<INPUT type=\"text\" id=\"$searchThingName\" name=\"$searchThingName\" size=\"30\" onKeyup=\"showTyped('$menuID', '$searchThingName');\" />" .
666                         Hint("GenomeControl", "Type here to filter the genomes displayed.") . "<br />";
667            # For multi-select mode, we also have buttons to set and clear selections.
668            if ($multiSelect) {
669                push @lines, "<INPUT type=\"button\" name=\"ClearAll\" class=\"bigButton\"  value=\"Clear All\" onClick=\"clearAll('$menuID'); $showSelect\" />";
670                push @lines, "<INPUT type=\"button\" name=\"SelectAll\" class=\"bigButton\" value=\"Select All\" onClick=\"selectAll('$menuID'); $showSelect\" />";
671                push @lines, "<INPUT type=\"button\" name=\"NMPDROnly\" class=\"bigButton\"  value=\"Select NMPDR\" onClick=\"selectSome('$menuID', $nmpdrCount, true); $showSelect;\" />";
672            }
673            # Add a hidden field we can use to generate organism page hyperlinks.
674            push @lines, "<INPUT type=\"hidden\" id=\"$urlID\" value=\"$FIG_Config::cgi_url/wiki/rest.cgi/NmpdrPlugin/SeedViewer?page=Organism;organism=\" />";
675            # Add the status display. This tells the user what's selected no matter where the list is scrolled.
676            push @lines, "<DIV id=\"$divID\" class=\"Panel\"></DIV>";
677        }
678        # Assemble all the lines into a string.
679        my $retVal = join("\n", @lines, "");
680      # Return the result.      # Return the result.
681      return $retVal;      return $retVal;
682  }  }
683    
684    
685    =head3 Stem
686    
687        my $stem = $sprout->Stem($word);
688    
689    Return the stem of the specified word, or C<undef> if the word is not
690    stemmable. Note that even if the word is stemmable, the stem may be
691    the same as the original word.
692    
693    =over 4
694    
695    =item word
696    
697    Word to convert into a stem.
698    
699    =item RETURN
700    
701    Returns a stem of the word (which may be the word itself), or C<undef> if
702    the word is not stemmable.
703    
704    =back
705    
706    =cut
707    
708    sub Stem {
709        # Get the parameters.
710        my ($self, $word) = @_;
711        # Get the stemmer object.
712        my $stemmer = $self->{stemmer};
713        if (! defined $stemmer) {
714            # We don't have one pre-built, so we build and save it now.
715            $stemmer = BioWords->new(exceptions => "$FIG_Config::sproutData/Exceptions.txt",
716                                     stops => "$FIG_Config::sproutData/StopWords.txt",
717                                     cache => 1);
718            $self->{stemmer} = $stemmer;
719        }
720        # Try to stem the word.
721        my $retVal = $stemmer->Process($word);
722        # Return the result.
723        return $retVal;
724    }
725    
726    
727  =head3 Build  =head3 Build
728    
729      $sprout->Build();      $sprout->Build();
# Line 599  Line 861 
861  =item RETURN  =item RETURN
862    
863  Returns a list of the feature's contig segments. The locations are returned as a list in a list  Returns a list of the feature's contig segments. The locations are returned as a list in a list
864  context and as a comma-delimited string in a scalar context.  context and as a comma-delimited string in a scalar context. An empty list means the feature
865    wasn't found.
866    
867  =back  =back
868    
# Line 608  Line 871 
871  sub FeatureLocation {  sub FeatureLocation {
872      # Get the parameters.      # Get the parameters.
873      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
874        # Declare the return variable.
875        my @retVal = ();
876      # Get the feature record.      # Get the feature record.
877      my $object = $self->GetEntity('Feature', $featureID);      my $object = $self->GetEntity('Feature', $featureID);
878      Confess("Feature $featureID not found.") if ! defined($object);      # Only proceed if we found it.
879        if (defined $object) {
880      # Get the location string.      # Get the location string.
881      my $locString = $object->PrimaryValue('Feature(location-string)');      my $locString = $object->PrimaryValue('Feature(location-string)');
882      # Create the return list.      # Create the return list.
883      my @retVal = split /\s*,\s*/, $locString;          @retVal = split /\s*,\s*/, $locString;
884        }
885      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
886      return (wantarray ? @retVal : join(',', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
887  }  }
# Line 1346  Line 1613 
1613  the specified user and FIG are considered trusted. If the user ID is omitted, only FIG  the specified user and FIG are considered trusted. If the user ID is omitted, only FIG
1614  is trusted.  is trusted.
1615    
1616  If the feature is B<not> identified by a FIG ID, then the functional assignment  If the feature is B<not> identified by a FIG ID, then we search the aliases for it.
1617  information is taken from the B<ExternalAliasFunc> table. If the table does  If no matching alias is found, we return an undefined value.
 not contain an entry for the feature, an undefined value is returned.  
1618    
1619  =over 4  =over 4
1620    
# Line 1374  Line 1640 
1640      my ($self, $featureID, $userID) = @_;      my ($self, $featureID, $userID) = @_;
1641      # Declare the return value.      # Declare the return value.
1642      my $retVal;      my $retVal;
1643      # Determine the ID type.      # Find a FIG ID for this feature.
1644      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1645        # Only proceed if we have an ID.
1646        if ($fid) {
1647          # Here we have a FIG feature ID.          # Here we have a FIG feature ID.
1648          if (!$userID) {          if (!$userID) {
1649              # Use the primary assignment.              # Use the primary assignment.
1650              ($retVal) = $self->GetEntityValues('Feature', $featureID, ['Feature(assignment)']);              ($retVal) = $self->GetEntityValues('Feature', $fid, ['Feature(assignment)']);
1651          } else {          } else {
1652              # We must build the list of trusted users.              # We must build the list of trusted users.
1653              my %trusteeTable = ();              my %trusteeTable = ();
# Line 1405  Line 1673 
1673              # Build a query for all of the feature's annotations, sorted by date.              # Build a query for all of the feature's annotations, sorted by date.
1674              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],              my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1675                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                     "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1676                                     [$featureID]);                                     [$fid]);
1677              my $timeSelected = 0;              my $timeSelected = 0;
1678              # Loop until we run out of annotations.              # Loop until we run out of annotations.
1679              while (my $annotation = $query->Fetch()) {              while (my $annotation = $query->Fetch()) {
# Line 1425  Line 1693 
1693                  }                  }
1694              }              }
1695          }          }
     } else {  
         # Here we have a non-FIG feature ID. In this case the user ID does not  
         # matter. We simply get the information from the External Alias Function  
         # table.  
         ($retVal) = $self->GetEntityValues('ExternalAliasFunc', $featureID, ['ExternalAliasFunc(func)']);  
1696      }      }
1697      # Return the assignment found.      # Return the assignment found.
1698      return $retVal;      return $retVal;
# Line 1448  Line 1711 
1711  annotation itself because it's a text field; however, this is not a big problem because  annotation itself because it's a text field; however, this is not a big problem because
1712  most features only have a small number of annotations.  most features only have a small number of annotations.
1713    
 If the feature is B<not> identified by a FIG ID, then the functional assignment  
 information is taken from the B<ExternalAliasFunc> table. If the table does  
 not contain an entry for the feature, an empty list is returned.  
   
1714  =over 4  =over 4
1715    
1716  =item featureID  =item featureID
# Line 1472  Line 1731 
1731      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1732      # Declare the return value.      # Declare the return value.
1733      my @retVal = ();      my @retVal = ();
1734      # Determine the ID type.      # Convert to a FIG ID.
1735      if ($featureID =~ m/^fig\|/) {      my ($fid) = $self->FeaturesByAlias($featureID);
1736        # Only proceed if we found one.
1737        if ($fid) {
1738          # Here we have a FIG feature ID. We must build the list of trusted          # Here we have a FIG feature ID. We must build the list of trusted
1739          # users.          # users.
1740          my %trusteeTable = ();          my %trusteeTable = ();
1741          # Build a query for all of the feature's annotations, sorted by date.          # Build a query for all of the feature's annotations, sorted by date.
1742          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],          my $query = $self->Get(['IsTargetOfAnnotation', 'Annotation', 'MadeAnnotation'],
1743                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",                                 "IsTargetOfAnnotation(from-link) = ? ORDER BY Annotation(time) DESC",
1744                                 [$featureID]);                                 [$fid]);
1745          my $timeSelected = 0;          my $timeSelected = 0;
1746          # Loop until we run out of annotations.          # Loop until we run out of annotations.
1747          while (my $annotation = $query->Fetch()) {          while (my $annotation = $query->Fetch()) {
# Line 1495  Line 1756 
1756                  push @retVal, [$actualUser, $function];                  push @retVal, [$actualUser, $function];
1757              }              }
1758          }          }
     } else {  
         # Here we have a non-FIG feature ID. In this case the user ID does not  
         # matter. We simply get the information from the External Alias Function  
         # table.  
         my @assignments = $self->GetEntityValues('ExternalAliasFunc', $featureID,  
                                                  ['ExternalAliasFunc(func)']);  
         push @retVal, map { ['master', $_] } @assignments;  
1759      }      }
1760      # Return the assignments found.      # Return the assignments found.
1761      return @retVal;      return @retVal;
# Line 1689  Line 1943 
1943      if ($featureID =~ /^fig\|(\d+\.\d+)/) {      if ($featureID =~ /^fig\|(\d+\.\d+)/) {
1944          $retVal = $1;          $retVal = $1;
1945      } else {      } else {
1946          Confess("Invalid feature ID $featureID.");          # Find the feature by alias.
1947            my ($realFeatureID) = $self->FeaturesByAlias($featureID);
1948            if ($realFeatureID && $realFeatureID =~ /^fig\|(\d+\.\d+)/) {
1949                $retVal = $1;
1950            }
1951      }      }
1952      # Return the value found.      # Return the value found.
1953      return $retVal;      return $retVal;
# Line 2529  Line 2787 
2787      return @retVal;      return @retVal;
2788  }  }
2789    
 =head3 GetProperties  
   
     my @list = $sprout->GetProperties($fid, $key, $value, $url);  
   
 Return a list of the properties with the specified characteristics.  
   
 Properties are the Sprout analog of the FIG attributes. The call is  
 passed directly to the CustomAttributes or RemoteCustomAttributes object  
 contained in this object.  
   
 This method returns a series of tuples that match the specified criteria. Each tuple  
 will contain an object ID, a key, and one or more values. The parameters to this  
 method therefore correspond structurally to the values expected in each tuple. In  
 addition, you can ask for a generic search by suffixing a percent sign (C<%>) to any  
 of the parameters. So, for example,  
   
     my @attributeList = $sprout->GetProperties('fig|100226.1.peg.1004', 'structure%', 1, 2);  
   
 would return something like  
   
     ['fig}100226.1.peg.1004', 'structure', 1, 2]  
     ['fig}100226.1.peg.1004', 'structure1', 1, 2]  
     ['fig}100226.1.peg.1004', 'structure2', 1, 2]  
     ['fig}100226.1.peg.1004', 'structureA', 1, 2]  
   
 Use of C<undef> in any position acts as a wild card (all values). You can also specify  
 a list reference in the ID column. Thus,  
   
     my @attributeList = $sprout->GetProperties(['100226.1', 'fig|100226.1.%'], 'PUBMED');  
   
 would get the PUBMED attribute data for Streptomyces coelicolor A3(2) and all its  
 features.  
   
 In addition to values in multiple sections, a single attribute key can have multiple  
 values, so even  
   
     my @attributeList = $sprout->GetProperties($peg, 'virulent');  
   
 which has no wildcard in the key or the object ID, may return multiple tuples.  
   
 =over 4  
   
 =item objectID  
   
 ID of object whose attributes are desired. If the attributes are desired for multiple  
 objects, this parameter can be specified as a list reference. If the attributes are  
 desired for all objects, specify C<undef> or an empty string. Finally, you can specify  
 attributes for a range of object IDs by putting a percent sign (C<%>) at the end.  
   
 =item key  
   
 Attribute key name. A value of C<undef> or an empty string will match all  
 attribute keys. If the values are desired for multiple keys, this parameter can be  
 specified as a list reference. Finally, you can specify attributes for a range of  
 keys by putting a percent sign (C<%>) at the end.  
   
 =item values  
   
 List of the desired attribute values, section by section. If C<undef>  
 or an empty string is specified, all values in that section will match. A  
 generic match can be requested by placing a percent sign (C<%>) at the end.  
 In that case, all values that match up to and not including the percent sign  
 will match. You may also specify a regular expression enclosed  
 in slashes. All values that match the regular expression will be returned. For  
 performance reasons, only values have this extra capability.  
   
 =item RETURN  
   
 Returns a list of tuples. The first element in the tuple is an object ID, the  
 second is an attribute key, and the remaining elements are the sections of  
 the attribute value. All of the tuples will match the criteria set forth in  
 the parameter list.  
   
 =back  
   
 =cut  
   
 sub GetProperties {  
     # Get the parameters.  
     my ($self, @parms) = @_;  
     # Declare the return variable.  
     my @retVal = $self->{_ca}->GetAttributes(@parms);  
     # Return the result.  
     return @retVal;  
 }  
   
2790  =head3 FeatureProperties  =head3 FeatureProperties
2791    
2792      my @properties = $sprout->FeatureProperties($featureID);      my @properties = $sprout->FeatureProperties($featureID);
# Line 2915  Line 3087 
3087  sub SubsystemList {  sub SubsystemList {
3088      # Get the parameters.      # Get the parameters.
3089      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
3090      # Get the list of names.      # Get the list of names. We do a join to the Subsystem table because we have missing subsystems in
3091      my @retVal = $self->GetFlat(['HasRoleInSubsystem'], "HasRoleInSubsystem(from-link) = ?",      # the Sprout database!
3092        my @retVal = $self->GetFlat(['HasRoleInSubsystem', 'Subsystem'], "HasRoleInSubsystem(from-link) = ?",
3093                                  [$featureID], 'HasRoleInSubsystem(to-link)');                                  [$featureID], 'HasRoleInSubsystem(to-link)');
3094      # Return the result, sorted.      # Return the result, sorted.
3095      return sort @retVal;      return sort @retVal;
# Line 2949  Line 3122 
3122      # Declare the return variable.      # Declare the return variable.
3123      my %retVal = ();      my %retVal = ();
3124      # Get a list of the genome features that participate in subsystems. For each      # Get a list of the genome features that participate in subsystems. For each
3125      # feature we get its spreadsheet cells and the corresponding roles.      # feature we get its subsystem ID and the corresponding roles.
3126      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],      my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf', 'HasSSCell'],
3127                               "HasFeature(from-link) = ?", [$genomeID],                               "HasFeature(from-link) = ?", [$genomeID],
3128                               ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);                                   ['HasFeature(to-link)', 'IsRoleOf(from-link)',  'HasSSCell(from-link)']);
3129      # Now we get a list of the spreadsheet cells and their associated subsystems. Subsystems      # Now we get a list of valid subsystems. These are the subsystems connected to the genome with
3130      # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the      # a non-negative variant code.
3131      # list. We use it at the beginning to get all the spreadsheet cells for the genome and      my %subs = map { $_ => 1 } $self->GetFlat(['ParticipatesIn'],
3132      # again at the end to filter out participation in subsystems with a negative variant code.                                                  "ParticipatesIn(from-link) = ? AND ParticipatesIn(variant-code) >= 0",
3133      my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],                                                  [$genomeID], 'ParticipatesIn(to-link)');
3134                                   "IsGenomeOf(from-link) = ? AND ParticipatesIn(variant-code) >= 0 AND ParticipatesIn(from-link) = ?",      # We loop through @roleData to build the hash.
                                  [$genomeID, $genomeID], ['HasSSCell(to-link)', 'HasSSCell(from-link)']);  
     # Now "@roleData" lists the spreadsheet cell and role for each of the genome's features.  
     # "@cellData" lists the subsystem name for each of the genome's spreadsheet cells. We  
     # link these two lists together to create the result. First, we want a hash mapping  
     # spreadsheet cells to subsystem names.  
     my %subHash = map { $_->[0] => $_->[1] } @cellData;  
     # We loop through @cellData to build the hash.  
3135      for my $roleEntry (@roleData) {      for my $roleEntry (@roleData) {
3136          # Get the data for this feature and cell.          # Get the data for this feature and cell.
3137          my ($fid, $cellID, $role) = @{$roleEntry};          my ($fid, $role, $subsys) = @{$roleEntry};
3138          # Check for a subsystem name.          Trace("Subsystem for $fid is $subsys.") if T(4);
3139          my $subsys = $subHash{$cellID};          # Check the subsystem;
3140          if ($subsys) {          if ($subs{$subsys}) {
3141                Trace("Subsystem found.") if T(4);
3142              # Insure this feature has an entry in the return hash.              # Insure this feature has an entry in the return hash.
3143              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }              if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
3144              # Merge in this new data.              # Merge in this new data.
# Line 3649  Line 3816 
3816      my ($self, %groupHash) = @_;      my ($self, %groupHash) = @_;
3817      # Create the result hash.      # Create the result hash.
3818      my %retVal = ();      my %retVal = ();
     # Get the super-group table.  
     my %superTable = $self->CheckGroupFile();  
3819      # Copy over the genomes.      # Copy over the genomes.
3820      for my $groupID (keys %groupHash) {      for my $groupID (keys %groupHash) {
3821          # Get the super-group name.          # Get the super-group name.
3822          my $realGroupID;          my $realGroupID = $self->SuperGroup($groupID);
3823          if ($groupID =~ /([A-Z]\w+)/) {          # Append this group's genomes into the result hash
3824              if (! defined($superTable{$1})) {          # using the super-group name.
                 Confess("Super-group name not found for group $groupID.");  
             } else {  
                 $realGroupID = $1;  
             }  
         } else {  
             Confess("Invalid group name $groupID.");  
         }  
         # Append this group's genomes into the result hash.  
3825          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};          push @{$retVal{$realGroupID}}, @{$groupHash{$groupID}};
3826      }      }
3827      # Return the result hash.      # Return the result hash.
# Line 3695  Line 3852 
3852  sub GroupPageName {  sub GroupPageName {
3853      # Get the parameters.      # Get the parameters.
3854      my ($self, $group) = @_;      my ($self, $group) = @_;
     # Declare the return variable.  
     my $retVal;  
3855      # Check for the group file data.      # Check for the group file data.
3856      my %superTable = $self->CheckGroupFile();      my %superTable = $self->CheckGroupFile();
3857      # Compute the real group name.      # Compute the real group name.
3858      if ($group =~ /([A-Z]\w+)/) {      my $realGroup = $self->SuperGroup($group);
3859          my $realGroup = $1;      # Get the associated page name.
3860          if (! defined($superTable{$1})) {      my $retVal = "../content/$superTable{$realGroup}->{page}";
             Confess("No super-group found for \"$group\".");  
         } else {  
             $retVal = "../content/$superTable{$1}->{page}";  
         }  
     } else {  
         Confess("\"group\" is not a valid group name.");  
     }  
3861      # Return the result.      # Return the result.
3862      return $retVal;      return $retVal;
3863  }  }
# Line 3831  Line 3979 
3979      # Get the parameters.      # Get the parameters.
3980      my ($self, $searchExpression) = @_;      my ($self, $searchExpression) = @_;
3981      # Perform the standard cleanup.      # Perform the standard cleanup.
3982      my $retVal = $self->ERDB::CleanKeywords($searchExpression);      my $words = $self->ERDB::CleanKeywords($searchExpression);
3983      # Fix the periods in EC and TC numbers.      # Fix the periods in EC and TC numbers.
3984      $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;      $words =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3985      # Fix non-trailing periods.      # Fix non-trailing periods.
3986      $retVal =~ s/\.(\w)/_$1/g;      $words =~ s/\.(\w)/_$1/g;
3987      # Fix non-leading minus signs.      # Fix non-leading minus signs.
3988      $retVal =~ s/(\w)[\-]/$1_/g;      $words =~ s/(\w)[\-]/$1_/g;
3989      # Fix the vertical bars and colons      # Fix the vertical bars and colons
3990      $retVal =~ s/(\w)[|:](\w)/$1'$2/g;      $words =~ s/(\w)[|:](\w)/$1'$2/g;
3991        # Now split up the list so that each keyword is in its own string. We keep the delimiters
3992        # because they may contain boolean expression data.
3993        my @words = split /([^A-Za-z'0-9_]+)/, $words;
3994        # We'll convert the stemmable words into stems and re-assemble the result.
3995        my $retVal = "";
3996        for my $word (@words) {
3997            my $stem = $self->Stem($word);
3998            if (defined $stem) {
3999                $retVal .= $stem;
4000            } else {
4001                $retVal .= $word;
4002            }
4003        }
4004        Trace("Cleaned keyword list for \"$searchExpression\" is \"$retVal\".") if T(3);
4005      # Return the result.      # Return the result.
4006      return $retVal;      return $retVal;
4007  }  }
# Line 3969  Line 4131 
4131  }  }
4132    
4133    
4134    =head3 Hint
4135    
4136        my $htmlText = SearchHelper::Hint($wikiPage, $hintText);
4137    
4138    Return the HTML for a small question mark that displays the specified hint text when it is clicked.
4139    This HTML can be put in forms to provide a useful hinting mechanism.
4140    
4141    =over 4
4142    
4143    =item wikiPage
4144    
4145    Name of the wiki page to be popped up when the hint mark is clicked.
4146    
4147    =item hintText
4148    
4149    Text to display for the hint. It is raw html, but may not contain any double quotes.
4150    
4151    =item RETURN
4152    
4153    Returns the html for the hint facility. The resulting html shows a small button-like thing that
4154    uses the standard FIG popup technology.
4155    
4156    =back
4157    
4158    =cut
4159    
4160    sub Hint {
4161        # Get the parameters.
4162        my ($wikiPage, $hintText) = @_;
4163        # Escape the single quotes in the hint text.
4164        my $quotedText = $hintText;
4165        $quotedText =~ s/'/\\'/g;
4166        # Convert the wiki page name to a URL.
4167        my $wikiURL = join("", map { ucfirst $_ } split /\s+/, $wikiPage);
4168        $wikiURL = "$FIG_Config::cgi_url/wiki/view.cgi/FIG/$wikiURL";
4169        # Compute the mouseover script.
4170        my $mouseOver = "doTooltip(this, '$quotedText')";
4171        # Create the html.
4172        my $retVal = "&nbsp;<a href=\"$wikiURL\"><img src=\"$FIG_Config::cgi_url/Html/button-h.png\" class=\"helpicon\" onmouseover=\"$mouseOver\"/></a>";
4173        # Return it.
4174        return $retVal;
4175    }
4176    
4177  1;  1;

Legend:
Removed from v.1.106  
changed lines
  Added in v.1.118

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3