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

View of /Sprout/FixComplexes.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Wed Sep 21 21:05:15 2011 UTC (7 years, 10 months ago) by parrello
Branch: MAIN
CVS Tags: rast_rel_2014_0912, rast_rel_2014_0729, mgrast_release_3_1_2, rast_rel_2011_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_10262011, HEAD
Changes to support complexes.

#!/usr/bin/perl -w

# -*- perl -*-
#
# Copyright (c) 2003-2011 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
#
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License.
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#

=head1 FixComplexes

This script looks for reaction-to-role relationships in the Sapling load files
that involve reactions not in complexes. When these are found, singleton
complexes are created to forge the relationship.

The single positional parameter is the name of the reaction-to-role
file. This is a standard tab-delimited file. The first line is a heading
line and is ignored. Each remaining line contains a reaction ID in the
first column and an associated role in the second.

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 dbname

Name of the Sapling database to use. This option is generally only useful for debugging.

=item dbhost

SQL host for the Sapling database to use. This option is generally only useful for debugging.

=item dbport

Database port to use for the Sapling database. This option is generally only useful for debugging.

=back

=cut

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

# Parse the command line.
my ($options, @parameters) = StandardSetup([qw(ERDB Sapling)],
    {dbname => [$FIG_Config::saplingDB, "name of the Sapling database to use"],
     dbhost => ["", "host containing the Sapling database"],
     dbport => ["", "port for connecting to the Sapling database"],
    },
    "<rrfile>", @ARGV);

# Create the statistics object.
my $stats = Stats->new();
eval {
    # This will be our input file handle.
    my $ih;
    # Get the input file name.
    my $inFile = $parameters[0];
    if (! $inFile) {
        Confess("No input file specified.");
    } else {
        # Connect to the Sapling.
        my $sap = Sapling->new(dbName => $options->{dbname}, dbhost => $options->{dbhost},
            port => $options->{dbport});
        # Open the input file.
        my $ih = Open(undef, "<$inFile");
        # Discard the header.
        Tracer::GetLine($ih);
        # Loop through the input lines.
        while (! eof $ih) {
            my ($rxn, $role) = Tracer::GetLine($ih);
            $stats->Add(linesIn => 1);
            # See if this reaction is in a complex.
            my @complexes = $sap->GetFlat("IsElementOf", "IsElementOf(from-link) = ?",
                [$rxn], "IsElementOf(to-link)");
            if (! @complexes) {
                # It's not in a complex, so we need to create one.
                $sap->InsertObject("Complex", id => $rxn);
                $stats->Add(newComplexes => 1);
                $sap->InsertObject("IsSetOf", from_link => $rxn, to_link => $rxn);
                # Remember that the reaction is in this complex.
                push @complexes, $rxn;
            }
            # If the reaction is in a singleton complex, attach the role to the
            # complex.
            if (scalar(@complexes) == 1 && $complexes[0] eq $rxn) {
                $sap->InsertObject("IsTriggeredBy", from_link => $rxn,
                    to_link => $role);
                $stats->Add(roleComplexLinks => 1);
            }
        }
    }
};
if ($@) {
    Trace("ERROR: $@") if T(0);
}
Trace("Statistics for run:\n" . $stats->Show());

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3