[Bio] / Sprout / SaplingAssignments.pl Repository:
ViewVC logotype

View of /Sprout/SaplingAssignments.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (as text) (annotate)
Mon Mar 4 19:04:31 2013 UTC (6 years, 7 months ago) by parrello
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
Support for PSEED load and updates.

#!/usr/bin/perl -w

=head1 Sapling Functional Assignment Script

This script reads a file of feature IDs and functional assignments and
applies them to the Sapling database. Unlike the normal function loader,
no annotation changes are made.

The input file must be in tab-delimited format, with the feature IDs in
the first field and the functional assignments in the second.

There is a single positional parameter: the name of the input file.

The currently-supported command-line options are as follows.

=over 4

=item user

Name suffix to be used for log files. If omitted, the PID is used.

=item trace

Numeric trace level. A higher trace level causes more messages to appear. The
default trace level is 2. Tracing will be directly to the standard output
as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
where I<User> is the value of the B<user> option above.

=item sql

If specified, turns on tracing of SQL activity.

=item background

Save the standard and error output to files. The files will be created
in the FIG temporary directory and will be named C<err>I<User>C<.log> and
C<out>I<User>C<.log>, respectively, where I<User> is the value of the
B<user> option above.

=item h

Display this command's parameters and options.

=item host

Alternate database host, if the database is located somewhere other than the
default. This is necessary on some Sapling machines to insure we get a writable
copy of the database.

=item port

Alternate database access port. This is used for debugging.

=item dbname

Alternate database name. This is used for debugging.



use strict;
use Tracer;
use Sapling;
use Stats;

use SaplingFunctionLoader;

# Get the command-line options and parameters.
my ($options, @parameters) = StandardSetup([qw(SaplingFuctionLoader) ],
                                           { host => ["", "alternate database host machine"],
                                             port => ["", "alternate database access port"],
                                             dbname => ["", "alternate datbase name"] },
# Create the statistics object.
my $stats = Stats->new();
# Insure we catch errors.
eval {
    Trace("Connecting to database.") if T(2);
    # Get the Sapling database.
    my $sap = Sapling->new(dbhost => $options->{host}, port => $options->{port},
                           dbName => $options->{dbname});
    # Create the function loader.
    my $loader = SaplingFunctionLoader->new($sap);
    # Attach our statistics object.
    $loader->{stats} = $stats;
    # Compute the input file. If no file name is specified, we use "-", which translates to
    # STDIN.
    my $inFileName = $parameters[0] || "-";
    if ($inFileName eq "-") {
        Trace("Assignments will be taken from standard input.") if T(2);
    } else {
        Trace("Assignments will be taken from $inFileName.") if T(2);
    my $ih = Open(undef, "<$inFileName");
    # Insure the input counter only refers to our input file.
    local $.;
    # Loop through the assignments.
    while (! eof $ih) {
        # Get the next assignment.
        my ($fid, $function) = Tracer::GetLine($ih);
        my $count = $stats->Add(inputLines => 1);
        # Check to see if the feature already has this function.
        my ($oldFunction) = $sap->GetFlat('Feature', 'Feature(id) = ?', [$fid],
        if (! defined $oldFunction) {
            # Here the feature does not exist.
            $stats->Add(missingFeature => 1);
        } elsif ($oldFunction eq $function) {
            # Here the feature already has this functino.
            $stats->Add(skippedFeature => 1);
        } else {
            # Here we need to make the update. Disconnect the feature
            # from its current roles.
            $sap->Disconnect('IsFunctionalIn', Feature => $fid);
            # Connect it to its new roles.
            $loader->ConnectFunctionRoles($fid, $function);
            # Update the feature with the new functional role.
            $sap->UpdateEntity('Feature', $fid, function => $function);
            $stats->Add(updatedFeature => 1);
        # Track our progress.
        Trace("$count assignments processed.") if ($count % 5000 == 0) && T(3);
    Trace("Processing complete.") if T(2);
if ($@) {
    Trace("Script failed with error: $@") if T(0);
} else {
    Trace("Script complete.") if T(2);
Trace("Statistics for this run: " . $stats->Show()) if T(2);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3