[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.19, Sun Aug 14 23:32:08 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 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 2896  Line 2986 
2986      return %retVal;      return %retVal;
2987  }  }
2988    
2989    =head3 MyGenomes
2990    
2991    C<< my @genomes = Sprout::MyGenomes($dataDir); >>
2992    
2993    Return a list of the genomes to be included in the Sprout.
2994    
2995    This method is provided for use during the Sprout load. It presumes the Genome load file has
2996    already been created. (It will be in the Sprout data directory and called either C<Genome>
2997    or C<Genome.dtx>.) Essentially, it reads in the Genome load file and strips out the genome
2998    IDs.
2999    
3000    =over 4
3001    
3002    =item dataDir
3003    
3004    Directory containing the Sprout load files.
3005    
3006    =back
3007    
3008    =cut
3009    #: Return Type @;
3010    sub MyGenomes {
3011        # Get the parameters.
3012        my ($dataDir) = @_;
3013        # Compute the genome file name.
3014        my $genomeFileName = LoadFileName($dataDir, "Genome");
3015        # Extract the genome IDs from the files.
3016        my @retVal = map { $_ =~ /^(\S+)/; $1 } Tracer::GetFile($genomeFileName);
3017        # Return the result.
3018        return @retVal;
3019    }
3020    
3021    =head3 LoadFileName
3022    
3023    C<< my $fileName = Sprout::LoadFileName($dataDir, $tableName); >>
3024    
3025    Return the name of the load file for the specified table in the specified data
3026    directory.
3027    
3028    =over 4
3029    
3030    =item dataDir
3031    
3032    Directory containing the Sprout load files.
3033    
3034    =item tableName
3035    
3036    Name of the table whose load file is desired.
3037    
3038    =item RETURN
3039    
3040    Returns the name of the file containing the load data for the specified table, or
3041    C<undef> if no load file is present.
3042    
3043    =back
3044    
3045    =cut
3046    #: Return Type $;
3047    sub LoadFileName {
3048        # Get the parameters.
3049        my ($dataDir, $tableName) = @_;
3050        # Declare the return variable.
3051        my $retVal;
3052        # Check for the various file names.
3053        if (-e "$dataDir/$tableName") {
3054            $retVal = "$dataDir/$tableName";
3055        } elsif (-e "$dataDir/$tableName.dtx") {
3056            $retVal = "$dataDir/$tableName.dtx";
3057        }
3058        # Return the result.
3059        return $retVal;
3060    }
3061    
3062  =head2 Internal Utility Methods  =head2 Internal Utility Methods
3063    
3064  =head3 ParseAssignment  =head3 ParseAssignment
# Line 3028  Line 3191 
3191      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });      $self->Insert('HasProperty', { 'from-link' => $featureID, 'to-link' => $propID, evidence => $url });
3192  }  }
3193    
3194    
3195    
3196  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3