[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.18, Tue Jun 28 21:34:15 2005 UTC revision 1.22, Fri Sep 9 21:10:46 2005 UTC
# Line 576  Line 576 
576  =item RETURN  =item RETURN
577    
578  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
579  context and as a space-delimited string in a scalar context.  context and as a comma-delimited string in a scalar context.
580    
581  =back  =back
582    
# Line 619  Line 619 
619          push @retVal, "${contigID}_$beg$dir$len";          push @retVal, "${contigID}_$beg$dir$len";
620      }      }
621      # Return the list in the format indicated by the context.      # Return the list in the format indicated by the context.
622      return (wantarray ? @retVal : join(' ', @retVal));      return (wantarray ? @retVal : join(',', @retVal));
623  }  }
624    
625  =head3 ParseLocation  =head3 ParseLocation
# Line 1521  Line 1521 
1521          # Determine the ordering to place on the evidence items. If we're          # Determine the ordering to place on the evidence items. If we're
1522          # inverted, we want to see feature 2 before feature 1 (descending); otherwise,          # inverted, we want to see feature 2 before feature 1 (descending); otherwise,
1523          # we want feature 1 before feature 2 (normal).          # we want feature 1 before feature 2 (normal).
1524            Trace("Coupling evidence for ($peg1, $peg2) with inversion flag $inverted.") if T(Coupling => 4);
1525          my $ordering = ($inverted ? "DESC" : "");          my $ordering = ($inverted ? "DESC" : "");
1526          # Get the coupling evidence.          # Get the coupling evidence.
1527          my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],          my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],
# Line 1534  Line 1535 
1535          while (@evidenceList > 0) {          while (@evidenceList > 0) {
1536              my $peg1Data = shift @evidenceList;              my $peg1Data = shift @evidenceList;
1537              my $peg2Data = shift @evidenceList;              my $peg2Data = shift @evidenceList;
1538                Trace("Peg 1 is " . $peg1Data->[1] . " and Peg 2 is " . $peg2Data->[1] . ".") if T(Coupling => 4);
1539              push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];              push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];
1540          }          }
1541            Trace("Last index in evidence result is is $#retVal.") if T(Coupling => 4);
1542      }      }
1543      # Return the result.      # Return the result.
1544      return @retVal;      return @retVal;
# Line 2226  Line 2229 
2229      return @retVal;      return @retVal;
2230  }  }
2231    
2232    =head3 GetProperties
2233    
2234    C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>
2235    
2236    Return a list of the properties with the specified characteristics.
2237    
2238    Properties are arbitrary key-value pairs associated with a feature. (At some point they
2239    will also be associated with genomes.) A property value is represented by a 4-tuple of
2240    the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter
2241    
2242    =over 4
2243    
2244    =item fid
2245    
2246    ID of the feature possessing the property.
2247    
2248    =item key
2249    
2250    Name or key of the property.
2251    
2252    =item value
2253    
2254    Value of the property.
2255    
2256    =item url
2257    
2258    URL of the document that indicated the property should have this particular value, or an
2259    empty string if no such document exists.
2260    
2261    =back
2262    
2263    The parameters act as a filter for the desired data. Any non-null parameter will
2264    automatically match all the tuples returned. So, specifying just the I<$fid> will
2265    return all the properties of the specified feature; similarly, specifying the I<$key>
2266    and I<$value> parameters will return all the features having the specified property
2267    value.
2268    
2269    A single property key can have many values, representing different ideas about the
2270    feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is
2271    virulent, and another may declare that it is not virulent. A query about the virulence of
2272    C<fig|83333.1.peg.10> would be coded as
2273    
2274        my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');
2275    
2276    Here the I<$value> and I<$url> fields are left blank, indicating that those fields are
2277    not to be filtered. The tuples returned would be
2278    
2279        ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')
2280        ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')
2281    
2282    =cut
2283    #: Return Type @@;
2284    sub GetProperties {
2285        # Get the parameters.
2286        my ($self, @parms) = @_;
2287        # Declare the return variable.
2288        my @retVal = ();
2289        # Now we need to create a WHERE clause that will get us the data we want. First,
2290        # we create a list of the columns containing the data for each parameter.
2291        my @colNames = ('HasProperty(from-link)', 'Property(property-name)',
2292                        'Property(property-value)', 'HasProperty(evidence)');
2293        # Now we build the WHERE clause and the list of parameter values.
2294        my @where = ();
2295        my @values = ();
2296        for (my $i = 0; $i <= $#colNames; $i++) {
2297            my $parm = $parms[$i];
2298            if (defined $parm && ($parm ne '')) {
2299                push @where, "$colNames[$i] = ?";
2300                push @values, $parm;
2301            }
2302        }
2303        # Format the WHERE clause.
2304        my $filter = (@values > 0 ? (join " AND ", @where) : undef);
2305        # Ask for all the propertie values with the desired characteristics.
2306        my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);
2307        while (my $valueObject = $query->Fetch()) {
2308            my @tuple = $valueObject->Values(\@colNames);
2309            push @retVal, \@tuple;
2310        }
2311        # Return the result.
2312        return @retVal;
2313    }
2314    
2315  =head3 FeatureProperties  =head3 FeatureProperties
2316    
2317  C<< my @properties = $sprout->FeatureProperties($featureID); >>  C<< my @properties = $sprout->FeatureProperties($featureID); >>
# Line 2420  Line 2506 
2506  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>
2507    
2508  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped  Return a hash describing all the subsystems in which a feature participates. Each subsystem is mapped
2509  to the role the feature performs.  to the roles the feature performs.
2510    
2511  =over 4  =over 4
2512    
# Line 2430  Line 2516 
2516    
2517  =item RETURN  =item RETURN
2518    
2519  Returns a hash mapping all the feature's subsystems to the feature's role.  Returns a hash mapping all the feature's subsystems to a list of the feature's roles.
2520    
2521  =back  =back
2522    
2523  =cut  =cut
2524  #: Return Type %;  #: Return Type %@;
2525  sub SubsystemsOf {  sub SubsystemsOf {
2526      # Get the parameters.      # Get the parameters.
2527      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
# Line 2447  Line 2533 
2533      my %retVal = ();      my %retVal = ();
2534      # Loop through the results, adding them to the hash.      # Loop through the results, adding them to the hash.
2535      for my $record (@subsystems) {      for my $record (@subsystems) {
2536          $retVal{$record->[0]} = $record->[1];          my ($subsys, $role) = @{$record};
2537            if (exists $retVal{$subsys}) {
2538                push @{$retVal{$subsys}}, $role;
2539            } else {
2540                $retVal{$subsys} = [$role];
2541            }
2542      }      }
2543      # Return the hash.      # Return the hash.
2544      return %retVal;      return %retVal;
# Line 3108  Line 3199 
3199      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3200  }  }
3201    
3202    
3203    
3204  1;  1;

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.22

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3