[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.17, Mon Jun 27 20:00:55 2005 UTC revision 1.20, Wed Aug 24 19:31:20 2005 UTC
# Line 86  Line 86 
86      # 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
87      # the incoming data.      # the incoming data.
88      my $optionTable = Tracer::GetOptions({      my $optionTable = Tracer::GetOptions({
89                         dbType       => 'mysql',         # database type                         dbType       => $FIG_Config::dbms,
90                         dataDir      => 'Data',          # data file directory                                                          # database type
91                         xmlFileName  => 'SproutDBD.xml', # database definition file name                         dataDir      => $FIG_Config::sproutData,
92                         userData     => 'root/',         # user name and password                                                          # data file directory
93                         port         => 0,               # database connection port                         xmlFileName  => "$FIG_Config::sproutData/SproutDBD.xml",
94                                                            # database definition file name
95                           userData     => "$FIG_Config::dbuser/$FIG_Config::dbpass",
96                                                            # user name and password
97                           port         => $FIG_Config::dbport,
98                                                            # database connection port
99                         maxSegmentLength => 4500,        # maximum feature segment length                         maxSegmentLength => 4500,        # maximum feature segment length
100                         maxSequenceLength => 8000,       # maximum contig sequence length                         maxSequenceLength => 8000,       # maximum contig sequence length
101                        }, $options);                        }, $options);
# Line 420  Line 425 
425      # Loop through the incoming table names.      # Loop through the incoming table names.
426      for my $tableName (@{$tableList}) {      for my $tableName (@{$tableList}) {
427          # Find the table's file.          # Find the table's file.
428          my $fileName = "$dataDir/$tableName";          my $fileName = LoadFileName($dataDir, $tableName);
429          if (! -e $fileName) {          if (! $fileName) {
430              $fileName = "$fileName.dtx";              Trace("No load file found for $tableName in $dataDir.") if T(0);
431          }          } else {
432          # Attempt to load this table.          # Attempt to load this table.
433          my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);          my $result = $erdb->LoadTable($fileName, $tableName, $truncateFlag);
434          # Accumulate the resulting statistics.          # Accumulate the resulting statistics.
435          $retVal->Accumulate($result);          $retVal->Accumulate($result);
436      }      }
437        }
438      # Return the statistics.      # Return the statistics.
439      return $retVal;      return $retVal;
440  }  }
# Line 570  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 613  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 1506  Line 1512 
1512      my ($self, $peg1, $peg2) = @_;      my ($self, $peg1, $peg2) = @_;
1513      # Declare the return variable.      # Declare the return variable.
1514      my @retVal = ();      my @retVal = ();
1515      # Our first task is to find out the nature of the coupling.      # Our first task is to find out the nature of the coupling: whether or not
1516        # it exists, its score, and whether the features are stored in the same
1517        # order as the ones coming in.
1518      my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);      my ($couplingID, $inverted, $score) = $self->GetCoupling($peg1, $peg2);
1519      # Only proceed if a coupling exists.      # Only proceed if a coupling exists.
1520      if ($couplingID) {      if ($couplingID) {
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; otherwise,          # inverted, we want to see feature 2 before feature 1 (descending); otherwise,
1523          # we want the reverse.          # we want feature 1 before feature 2 (normal).
1524          my $ordering = ($inverted ? "DESC" : "");          my $ordering = ($inverted ? "DESC" : "");
1525          # Get the coupling evidence.          # Get the coupling evidence.
1526          my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],          my @evidenceList = $self->GetAll(['IsEvidencedBy', 'PCH', 'UsesAsEvidence'],
# Line 1529  Line 1537 
1537              push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];              push @retVal, [$peg1Data->[1], $peg2Data->[1], $peg1Data->[0]];
1538          }          }
1539      }      }
     # TODO: code  
1540      # Return the result.      # Return the result.
1541      return @retVal;      return @retVal;
1542  }  }
# Line 2219  Line 2226 
2226      return @retVal;      return @retVal;
2227  }  }
2228    
2229    =head3 GetProperties
2230    
2231    C<< my @list = $sprout->GetProperties($fid, $key, $value, $url); >>
2232    
2233    Return a list of the properties with the specified characteristics.
2234    
2235    Properties are arbitrary key-value pairs associated with a feature. (At some point they
2236    will also be associated with genomes.) A property value is represented by a 4-tuple of
2237    the form B<($fid, $key, $value, $url)>. These exactly correspond to the parameter
2238    
2239    =over 4
2240    
2241    =item fid
2242    
2243    ID of the feature possessing the property.
2244    
2245    =item key
2246    
2247    Name or key of the property.
2248    
2249    =item value
2250    
2251    Value of the property.
2252    
2253    =item url
2254    
2255    URL of the document that indicated the property should have this particular value, or an
2256    empty string if no such document exists.
2257    
2258    =back
2259    
2260    The parameters act as a filter for the desired data. Any non-null parameter will
2261    automatically match all the tuples returned. So, specifying just the I<$fid> will
2262    return all the properties of the specified feature; similarly, specifying the I<$key>
2263    and I<$value> parameters will return all the features having the specified property
2264    value.
2265    
2266    A single property key can have many values, representing different ideas about the
2267    feature in question. For example, one paper may declare that a feature C<fig|83333.1.peg.10> is
2268    virulent, and another may declare that it is not virulent. A query about the virulence of
2269    C<fig|83333.1.peg.10> would be coded as
2270    
2271        my @list = $sprout->GetProperties('fig|83333.1.peg.10', 'virulence', '', '');
2272    
2273    Here the I<$value> and I<$url> fields are left blank, indicating that those fields are
2274    not to be filtered. The tuples returned would be
2275    
2276        ('fig|83333.1.peg.10', 'virulence', 'yes', 'http://www.somewhere.edu/first.paper.pdf')
2277        ('fig|83333.1.peg.10', 'virulence', 'no', 'http://www.somewhere.edu/second.paper.pdf')
2278    
2279    =cut
2280    #: Return Type @@;
2281    sub GetProperties {
2282        # Get the parameters.
2283        my ($self, @parms) = @_;
2284        # Declare the return variable.
2285        my @retVal = ();
2286        # Now we need to create a WHERE clause that will get us the data we want. First,
2287        # we create a list of the columns containing the data for each parameter.
2288        my @colNames = ('HasProperty(from-link)', 'Property(property-name)',
2289                        'Property(property-value)', 'HasProperty(evidence)');
2290        # Now we build the WHERE clause and the list of parameter values.
2291        my @where = ();
2292        my @values = ();
2293        for (my $i = 0; $i <= $#colNames; $i++) {
2294            my $parm = $parms[$i];
2295            if (defined $parm && ($parm ne '')) {
2296                push @where, "$colNames[$i] = ?";
2297                push @values, $parm;
2298            }
2299        }
2300        # Format the WHERE clause.
2301        my $filter = (@values > 0 ? (join " AND ", @where) : undef);
2302        # Ask for all the propertie values with the desired characteristics.
2303        my $query = $self->Get(['HasProperty', 'Property'], $filter, \@values);
2304        while (my $valueObject = $query->Fetch()) {
2305            my @tuple = $valueObject->Values(\@colNames);
2306            push @retVal, \@tuple;
2307        }
2308        # Return the result.
2309        return @retVal;
2310    }
2311    
2312  =head3 FeatureProperties  =head3 FeatureProperties
2313    
2314  C<< my @properties = $sprout->FeatureProperties($featureID); >>  C<< my @properties = $sprout->FeatureProperties($featureID); >>
# Line 2413  Line 2503 
2503  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>  C<< my %subsystems = $sprout->SubsystemsOf($featureID); >>
2504    
2505  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
2506  to the role the feature performs.  to the roles the feature performs.
2507    
2508  =over 4  =over 4
2509    
# Line 2423  Line 2513 
2513    
2514  =item RETURN  =item RETURN
2515    
2516  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.
2517    
2518  =back  =back
2519    
2520  =cut  =cut
2521  #: Return Type %;  #: Return Type %@;
2522  sub SubsystemsOf {  sub SubsystemsOf {
2523      # Get the parameters.      # Get the parameters.
2524      my ($self, $featureID) = @_;      my ($self, $featureID) = @_;
# Line 2440  Line 2530 
2530      my %retVal = ();      my %retVal = ();
2531      # Loop through the results, adding them to the hash.      # Loop through the results, adding them to the hash.
2532      for my $record (@subsystems) {      for my $record (@subsystems) {
2533          $retVal{$record->[0]} = $record->[1];          my ($subsys, $role) = @{$record};
2534            if (exists $retVal{$subsys}) {
2535                push @{$retVal{$subsys}}, $role;
2536            } else {
2537                $retVal{$subsys} = [$role];
2538            }
2539      }      }
2540      # Return the hash.      # Return the hash.
2541      return %retVal;      return %retVal;
# Line 2896  Line 2991 
2991      return %retVal;      return %retVal;
2992  }  }
2993    
2994    =head3 MyGenomes
2995    
2996    C<< my @genomes = Sprout::MyGenomes($dataDir); >>
2997    
2998    Return a list of the genomes to be included in the Sprout.
2999    
3000    This method is provided for use during the Sprout load. It presumes the Genome load file has
3001    already been created. (It will be in the Sprout data directory and called either C<Genome>
3002    or C<Genome.dtx>.) Essentially, it reads in the Genome load file and strips out the genome
3003    IDs.
3004    
3005    =over 4
3006    
3007    =item dataDir
3008    
3009    Directory containing the Sprout load files.
3010    
3011    =back
3012    
3013    =cut
3014    #: Return Type @;
3015    sub MyGenomes {
3016        # Get the parameters.
3017        my ($dataDir) = @_;
3018        # Compute the genome file name.
3019        my $genomeFileName = LoadFileName($dataDir, "Genome");
3020        # Extract the genome IDs from the files.
3021        my @retVal = map { $_ =~ /^(\S+)/; $1 } Tracer::GetFile($genomeFileName);
3022        # Return the result.
3023        return @retVal;
3024    }
3025    
3026    =head3 LoadFileName
3027    
3028    C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>
3029    
3030    Return the name of the load file for the specified table in the specified data
3031    directory.
3032    
3033    =over 4
3034    
3035    =item dataDir
3036    
3037    Directory containing the Sprout load files.
3038    
3039    =item tableName
3040    
3041    Name of the table whose load file is desired.
3042    
3043    =item RETURN
3044    
3045    Returns the name of the file containing the load data for the specified table, or
3046    C<undef> if no load file is present.
3047    
3048    =back
3049    
3050    =cut
3051    #: Return Type $;
3052    sub LoadFileName {
3053        # Get the parameters.
3054        my ($dataDir, $tableName) = @_;
3055        # Declare the return variable.
3056        my $retVal;
3057        # Check for the various file names.
3058        if (-e "$dataDir/$tableName") {
3059            $retVal = "$dataDir/$tableName";
3060        } elsif (-e "$dataDir/$tableName.dtx") {
3061            $retVal = "$dataDir/$tableName.dtx";
3062        }
3063        # Return the result.
3064        return $retVal;
3065    }
3066    
3067  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3068    
3069  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3028  Line 3196 
3196      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3197  }  }
3198    
3199    
3200    
3201  1;  1;

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.20

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3