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

View of /Sprout/ReactionNeighborHunt.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (as text) (annotate)
Wed Sep 21 21:05:15 2011 UTC (8 years 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 ReactionNeighborHunt

This script is used to test several of the chemistry-related methods.
Starting from a set of reactions specified as positional parameters,
it will list each reaction's neighbors, their roles, and their formulae,
then proceed recursively until a limit is reached.

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

=over 4

=item count

Number of iterations of neighbors to run through before stopping. The default
is C<5>.

=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.



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

# 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"],
     count =>  [5, "number of neighbor iterations to run"],
     trace =>  ["2-", "trace level"],
    "<rxn1> <rxn2> ...", @ARGV);

# Connect to the Sapling.
my $sap = Sapling->new(dbName => $options->{dbname}, dbhost => $options->{dbhost},
    port => $options->{dbport});
# Get a Sapling server for it. Note we're localhost, so this is not using the real
# servers. It is, after all, essentially a test script.
my $sapObject = SAPserver->new(sapDB => $sap, url => 'localhost');
# Get the iteration count.
my $count = $options->{count};
# Get the starting reactions.
my @queue = @parameters;
# This hash will hold reactions we've already found, so that we don't loop back.
my %found;
# Loop through the iterations. At the beginning of each iteration, the reactions
# we want to process are in @queue. If @queue is ever empty, we stop.
while (@queue && $count-- > 0) {
    # We'll build the new queue in here.
    my @newQueue;
    # Get the reaction strings and roles.
    my $rxnStringHash = $sapObject->reaction_strings(-ids => \@queue, -roles => 1);
    # Get the reaction neighbors for the next iteration.
    my $neighborHash = $sapObject->reaction_neighbors(-ids => \@queue);
    # Loop through the old queue.
    for my $rxn (@queue) {
        # Get the reaction string and the roles.
        my ($string, @roles) = @{$rxnStringHash->{$rxn}};
        print "*** $rxn: $string\n";
        # Get the neighbors of this reaction.
        my @neighbors = sort keys %{$neighborHash->{$rxn}};
        print "    " . scalar(@neighbors) . " neighbors: " .
            join(", ", @neighbors) . "\n";
        # Display the roles.
        for my $role (@roles) {
            print "    role: $role\n";
        # Get the list of new neighbors.
        my @newRxns = grep { ! $found{$_} } @neighbors;
        # Mark them so we don't process them again.
        for my $newRxn (@newRxns) {
            $found{$newRxn} = 1;
        # Push them on the queue for next time.
        push @newQueue, @newRxns;
    # Replace the old queue with the new one.
    @queue = @newQueue;
Trace("All done.") if T(2);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3