[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.76, Sun Jun 25 18:03:29 2006 UTC revision 1.91, Sat Oct 14 18:12:48 2006 UTC
# Line 92  Line 92 
92  sub new {  sub new {
93      # Get the parameters.      # Get the parameters.
94      my ($class, $dbName, $options) = @_;      my ($class, $dbName, $options) = @_;
95        # Compute the DBD directory.
96        my $dbd_dir = (defined($FIG_Config::dbd_dir) ? $FIG_Config::dbd_dir :
97                                                      $FIG_Config::fig );
98      # Compute the options. We do this by starting with a table of defaults and overwriting with      # Compute the options. We do this by starting with a table of defaults and overwriting with
99      # the incoming data.      # the incoming data.
100      my $optionTable = Tracer::GetOptions({      my $optionTable = Tracer::GetOptions({
# Line 99  Line 102 
102                                                          # database type                                                          # database type
103                         dataDir      => $FIG_Config::sproutData,                         dataDir      => $FIG_Config::sproutData,
104                                                          # data file directory                                                          # data file directory
105                         xmlFileName  => "$FIG_Config::fig/SproutDBD.xml",                         xmlFileName  => "$dbd_dir/SproutDBD.xml",
106                                                          # database definition file name                                                          # database definition file name
107                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",                         userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
108                                                          # user name and password                                                          # user name and password
109                         port         => $FIG_Config::dbport,                         port         => $FIG_Config::dbport,
110                                                          # database connection port                                                          # database connection port
111                         sock         => $FIG_Config::dbsock,                         sock         => $FIG_Config::dbsock,
112                           host         => $FIG_Config::dbhost,
113                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
114                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
115                         noDBOpen     => 0,               # 1 to suppress the database open                         noDBOpen     => 0,               # 1 to suppress the database open
# Line 119  Line 123 
123      my $dbh;      my $dbh;
124      if (! $optionTable->{noDBOpen}) {      if (! $optionTable->{noDBOpen}) {
125          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,          $dbh = DBKernel->new($optionTable->{dbType}, $dbName, $userName,
126                                  $password, $optionTable->{port}, undef, $optionTable->{sock});                                  $password, $optionTable->{port}, $optionTable->{host}, $optionTable->{sock});
127      }      }
128      # Create the ERDB object.      # Create the ERDB object.
129      my $xmlFileName = "$optionTable->{xmlFileName}";      my $xmlFileName = "$optionTable->{xmlFileName}";
# Line 127  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 336  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 358  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 368  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 385  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 630  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 1472  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 1493  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 1514  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 1527  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 1656  Line 1675 
1675  sub CoupledFeatures {  sub CoupledFeatures {
1676      # Get the parameters.      # Get the parameters.
1677      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
1678        Trace("Looking for features coupled to $featureID.") if T(coupling => 3);
1679      # Create a query to retrieve the functionally-coupled features.      # Create a query to retrieve the functionally-coupled features.
1680      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],      my $query = $self->Get(['ParticipatesInCoupling', 'Coupling'],
1681                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);                             "ParticipatesInCoupling(from-link) = ?", [$featureID]);
# Line 1668  Line 1688 
1688          # Get the ID and score of the coupling.          # Get the ID and score of the coupling.
1689          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',          my ($couplingID, $score) = $clustering->Values(['Coupling(id)',
1690                                                          'Coupling(score)']);                                                          'Coupling(score)']);
1691            Trace("$featureID coupled with score $score to ID $couplingID.") if T(coupling => 4);
1692          # Get the other feature that participates in the coupling.          # Get the other feature that participates in the coupling.
1693          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],          my ($otherFeatureID) = $self->GetFlat(['ParticipatesInCoupling'],
1694                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",                                             "ParticipatesInCoupling(to-link) = ? AND ParticipatesInCoupling(from-link) <> ?",
1695                                             [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)');                                             [$couplingID, $featureID], 'ParticipatesInCoupling(from-link)');
1696            Trace("$couplingID target feature is $otherFeatureID.") if T(coupling => 4);
1697          # Attach the other feature's score to its ID.          # Attach the other feature's score to its ID.
1698          $retVal{$otherFeatureID} = $score;          $retVal{$otherFeatureID} = $score;
1699          $found = 1;          $found = 1;
# Line 2657  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 2854  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, sorted.
2918        return sort @retVal;
2919    }
2920    
2921    =head3 GenomeSubsystemData
2922    
2923    C<< my %featureData = $sprout->GenomeSubsystemData($genomeID); >>
2924    
2925    Return a hash mapping genome features to their subsystem roles.
2926    
2927    =over 4
2928    
2929    =item genomeID
2930    
2931    ID of the genome whose subsystem feature map is desired.
2932    
2933    =item RETURN
2934    
2935    Returns a hash mapping each feature of the genome to a list of 2-tuples. Eacb
2936    2-tuple contains a subsystem name followed by a role ID.
2937    
2938    =back
2939    
2940    =cut
2941    
2942    sub GenomeSubsystemData {
2943        # Get the parameters.
2944        my ($self, $genomeID) = @_;
2945        # Declare the return variable.
2946        my %retVal = ();
2947        # Get a list of the genome features that participate in subsystems. For each
2948        # feature we get its spreadsheet cells and the corresponding roles.
2949        my @roleData = $self->GetAll(['HasFeature', 'ContainsFeature', 'IsRoleOf'],
2950                                 "HasFeature(from-link) = ?", [$genomeID],
2951                                 ['HasFeature(to-link)', 'IsRoleOf(to-link)', 'IsRoleOf(from-link)']);
2952        # Now we get a list of the spreadsheet cells and their associated subsystems. Subsystems
2953        # with an unknown variant code (-1) are skipped. Note the genome ID is at both ends of the
2954        # list. We use it at the beginning to get all the spreadsheet cells for the genome and
2955        # again at the end to filter out participation in subsystems with a negative variant code.
2956        my @cellData = $self->GetAll(['IsGenomeOf', 'HasSSCell', 'ParticipatesIn'],
2957                                     "IsGenomeOf(from-link) = ? AND ParticipatesIn(variant-code) >= 0 AND ParticipatesIn(from-link) = ?",
2958                                     [$genomeID, $genomeID], ['HasSSCell(to-link)', 'HasSSCell(from-link)']);
2959        # Now "@roleData" lists the spreadsheet cell and role for each of the genome's features.
2960        # "@cellData" lists the subsystem name for each of the genome's spreadsheet cells. We
2961        # link these two lists together to create the result. First, we want a hash mapping
2962        # spreadsheet cells to subsystem names.
2963        my %subHash = map { $_->[0] => $_->[1] } @cellData;
2964        # We loop through @cellData to build the hash.
2965        for my $roleEntry (@roleData) {
2966            # Get the data for this feature and cell.
2967            my ($fid, $cellID, $role) = @{$roleEntry};
2968            # Check for a subsystem name.
2969            my $subsys = $subHash{$cellID};
2970            if ($subsys) {
2971                # Insure this feature has an entry in the return hash.
2972                if (! exists $retVal{$fid}) { $retVal{$fid} = []; }
2973                # Merge in this new data.
2974                push @{$retVal{$fid}}, [$subsys, $role];
2975            }
2976        }
2977      # Return the result.      # Return the result.
2978      return @retVal;      return %retVal;
2979  }  }
2980    
2981  =head3 RelatedFeatures  =head3 RelatedFeatures
# Line 2895  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 3098  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 3176  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 3197  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 3205  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 3333  Line 3495 
3495      return $retVal;      return $retVal;
3496  }  }
3497    
3498  =head2 Internal Utility Methods  =head3 Fix
3499    
3500  =head3 ParseAssignment  C<< my %fixedHash = Sprout::Fix(%groupHash); >>
3501    
3502  Parse annotation text to determine whether or not it is a functional assignment. If it is,  Prepare a genome group hash (like that returned by L</GetGroups> for processing.
3503  the user, function text, and assigning user will be returned as a 3-element list. If it  Groups with the same primary name will be combined. The primary name is the
3504  isn't, an empty list will be returned.  first capitalized word in the group name.
3505    
3506  A functional assignment is always of the form  =over 4
3507    
3508      C<set >I<YYYY>C< function to\n>I<ZZZZZ>  =item groupHash
3509    
3510  where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,  Hash to be fixed up.
 the user and the assigning user (from MadeAnnotation) will be the same, but that is  
 not always the case.  
3511    
3512  In addition, the functional role may contain extra data that is stripped, such as  =item RETURN
 terminating spaces or a comment separated from the rest of the text by a tab.  
3513    
3514  This is a static method.  Returns a fixed-up version of the hash.
3515    
3516  =over 4  =back
3517    
3518  =item user  =cut
3519    
3520  Name of the assigning user.  sub Fix {
3521        # Get the parameters.
3522        my (%groupHash) = @_;
3523        # Create the result hash.
3524        my %retVal = ();
3525        # Copy over the genomes.
3526        for my $groupID (keys %groupHash) {
3527            # Make a safety copy of the group ID.
3528            my $realGroupID = $groupID;
3529            # Yank the primary name.
3530            if ($groupID =~ /([A-Z]\w+)/) {
3531                $realGroupID = $1;
3532            }
3533            # Append this group's genomes into the result hash.
3534            Tracer::AddToListMap(\%retVal, $realGroupID, @{$groupHash{$groupID}});
3535        }
3536        # Return the result hash.
3537        return %retVal;
3538    }
3539    
3540  =item text  =head3 GroupPageName
3541    
3542  Text of the annotation.  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  =item RETURN
3553    
3554  Returns an empty list if the annotation is not a functional assignment; otherwise, returns  Returns the relative page name (e.g. C<../content/campy.php>). If the group file is not in
3555  a two-element list containing the user name and the function text.  memory it will be read in.
3556    
3557  =back  =back
3558    
3559  =cut  =cut
3560    
3561  sub _ParseAssignment {  sub GroupPageName {
3562      # Get the parameters.      # Get the parameters.
3563      my ($user, $text) = @_;      my ($self, $group) = @_;
3564      # Declare the return value.      # Declare the return variable.
3565      my @retVal = ();      my $retVal;
3566      # Check to see if this is a functional assignment.      # Check for the group file data.
3567      my ($type, $function) = split(/\n/, $text);      if (! defined $self->{groupHash}) {
3568      if ($type =~ m/^set function to$/i) {          # Read the group file.
3569          # Here we have an assignment without a user, so we use the incoming user ID.          my %groupData = Sprout::ReadGroupFile($self->{_options}->{dataDir} . "/groups.tbl");
3570          @retVal = ($user, $function);          # Store it in our object.
3571      } elsif ($type =~ m/^set (\S+) function to$/i) {          $self->{groupHash} = \%groupData;
         # Here we have an assignment with a user that is passed back to the caller.  
         @retVal = ($1, $function);  
3572      }      }
3573      # If we have an assignment, we need to clean the function text. There may be      # Compute the real group name.
3574      # extra junk at the end added as a note from the user.      my $realGroup = $group;
3575      if (@retVal) {      if ($group =~ /([A-Z]\w+)/) {
3576          $retVal[1] =~ s/(\t\S)?\s*$//;          $realGroup = $1;
3577      }      }
3578      # Return the result list.      # Return the page name.
3579      return @retVal;      $retVal = "../content/" . $self->{groupHash}->{$realGroup}->[1];
3580        # Return the result.
3581        return $retVal;
3582  }  }
3583    
3584  =head3 FriendlyTimestamp  =head3 ReadGroupFile
3585    
3586  Convert a time number to a user-friendly time stamp for display.  C<< my %groupData = Sprout::ReadGroupFile($groupFileName); >>
3587    
3588  This is a static method.  Read in the data from the specified group file. The group file contains information
3589    about each of the NMPDR groups.
3590    
3591  =over 4  =over 4
3592    
3593  =item timeValue  =item name
3594    
3595  Numeric time value.  Name of the group.
3596    
3597    =item page
3598    
3599    Name of the group's page on the web site (e.g. C<campy.php> for
3600    Campylobacter)
3601    
3602    =item genus
3603    
3604    Genus of the group
3605    
3606    =item species
3607    
3608    Species of the group, or an empty string if the group is for an entire
3609    genus. If the group contains more than one species, the species names
3610    should be separated by commas.
3611    
3612    =back
3613    
3614    The parameters to this method are as follows
3615    
3616    =over 4
3617    
3618    =item groupFile
3619    
3620    Name of the file containing the group data.
3621    
3622  =item RETURN  =item RETURN
3623    
3624  Returns a string containing the same time in user-readable format.  Returns a hash keyed on group name. The value of each hash
3625    
3626  =back  =back
3627    
3628  =cut  =cut
3629    
3630  sub FriendlyTimestamp {  sub ReadGroupFile {
3631      my ($timeValue) = @_;      # Get the parameters.
3632      my $retVal = localtime($timeValue);      my ($groupFileName) = @_;
3633      return $retVal;      # Declare the return variable.
3634        my %retVal;
3635        # Read the group file.
3636        my @groupLines = Tracer::GetFile($groupFileName);
3637        for my $groupLine (@groupLines) {
3638            my ($name, $page, $genus, $species) = split(/\t/, $groupLine);
3639            $retVal{$name} = [$page, $genus, $species];
3640        }
3641        # Return the result.
3642        return %retVal;
3643  }  }
3644    
3645  =head3 AddProperty  =head3 AddProperty
# Line 3479  Line 3699 
3699      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3700  }  }
3701    
3702    =head2 Virtual Methods
3703    
3704    =head3 CleanKeywords
3705    
3706    C<< my $cleanedString = $sprout->CleanKeywords($searchExpression); >>
3707    
3708    Clean up a search expression or keyword list. This involves converting the periods
3709    in EC numbers to underscores, converting non-leading minus signs to underscores,
3710    a vertical bar or colon to an apostrophe, and forcing lower case for all alphabetic
3711    characters. In addition, any extra spaces are removed.
3712    
3713    =over 4
3714    
3715    =item searchExpression
3716    
3717    Search expression or keyword list to clean. Note that a search expression may
3718    contain boolean operators which need to be preserved. This includes leading
3719    minus signs.
3720    
3721    =item RETURN
3722    
3723    Cleaned expression or keyword list.
3724    
3725    =back
3726    
3727    =cut
3728    
3729    sub CleanKeywords {
3730        # Get the parameters.
3731        my ($self, $searchExpression) = @_;
3732        # Perform the standard cleanup.
3733        my $retVal = $self->ERDB::CleanKeywords($searchExpression);
3734        # Fix the periods in EC and TC numbers.
3735        $retVal =~ s/(\d+|\-)\.(\d+|-)\.(\d+|-)\.(\d+|-)/$1_$2_$3_$4/g;
3736        # Fix non-trailing periods.
3737        $retVal =~ s/\.(\w)/_$1/g;
3738        # Fix non-leading minus signs.
3739        $retVal =~ s/(\w)[\-]/$1_/g;
3740        # Fix the vertical bars and colons
3741        $retVal =~ s/(\w)[|:](\w)/$1'$2/g;
3742        # Return the result.
3743        return $retVal;
3744    }
3745    
3746    =head2 Internal Utility Methods
3747    
3748    =head3 ParseAssignment
3749    
3750    Parse annotation text to determine whether or not it is a functional assignment. If it is,
3751    the user, function text, and assigning user will be returned as a 3-element list. If it
3752    isn't, an empty list will be returned.
3753    
3754    A functional assignment is always of the form
3755    
3756        C<set >I<YYYY>C< function to\n>I<ZZZZZ>
3757    
3758    where I<YYYY> is the B<user>, and I<ZZZZ> is the actual functional role. In most cases,
3759    the user and the assigning user (from MadeAnnotation) will be the same, but that is
3760    not always the case.
3761    
3762    In addition, the functional role may contain extra data that is stripped, such as
3763    terminating spaces or a comment separated from the rest of the text by a tab.
3764    
3765    This is a static method.
3766    
3767    =over 4
3768    
3769    =item user
3770    
3771    Name of the assigning user.
3772    
3773    =item text
3774    
3775    Text of the annotation.
3776    
3777    =item RETURN
3778    
3779    Returns an empty list if the annotation is not a functional assignment; otherwise, returns
3780    a two-element list containing the user name and the function text.
3781    
3782    =back
3783    
3784    =cut
3785    
3786    sub _ParseAssignment {
3787        # Get the parameters.
3788        my ($user, $text) = @_;
3789        # Declare the return value.
3790        my @retVal = ();
3791        # Check to see if this is a functional assignment.
3792        my ($type, $function) = split(/\n/, $text);
3793        if ($type =~ m/^set function to$/i) {
3794            # Here we have an assignment without a user, so we use the incoming user ID.
3795            @retVal = ($user, $function);
3796        } elsif ($type =~ m/^set (\S+) function to$/i) {
3797            # Here we have an assignment with a user that is passed back to the caller.
3798            @retVal = ($1, $function);
3799        }
3800        # If we have an assignment, we need to clean the function text. There may be
3801        # extra junk at the end added as a note from the user.
3802        if (defined( $retVal[1] )) {
3803            $retVal[1] =~ s/(\t\S)?\s*$//;
3804        }
3805        # Return the result list.
3806        return @retVal;
3807    }
3808    
3809    =head3 FriendlyTimestamp
3810    
3811    Convert a time number to a user-friendly time stamp for display.
3812    
3813    This is a static method.
3814    
3815    =over 4
3816    
3817    =item timeValue
3818    
3819    Numeric time value.
3820    
3821    =item RETURN
3822    
3823    Returns a string containing the same time in user-readable format.
3824    
3825    =back
3826    
3827    =cut
3828    
3829    sub FriendlyTimestamp {
3830        my ($timeValue) = @_;
3831        my $retVal = localtime($timeValue);
3832        return $retVal;
3833    }
3834    
3835    
3836  1;  1;

Legend:
Removed from v.1.76  
changed lines
  Added in v.1.91

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3