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

Annotation of /Sprout/ReactionNeighborHunt.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     # -*- perl -*-
4 :     #
5 :     # Copyright (c) 2003-2011 University of Chicago and Fellowship
6 :     # for Interpretations of Genomes. All Rights Reserved.
7 :     #
8 :     # This file is part of the SEED Toolkit.
9 :     #
10 :     # The SEED Toolkit is free software. You can redistribute
11 :     # it and/or modify it under the terms of the SEED Toolkit
12 :     # Public License.
13 :     #
14 :     # You should have received a copy of the SEED Toolkit Public License
15 :     # along with this program; if not write to the University of Chicago
16 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
17 :     # Genomes at veronika@thefig.info or download a copy from
18 :     # http://www.theseed.org/LICENSE.TXT.
19 :     #
20 :    
21 :     =head1 ReactionNeighborHunt
22 :    
23 :     This script is used to test several of the chemistry-related methods.
24 :     Starting from a set of reactions specified as positional parameters,
25 :     it will list each reaction's neighbors, their roles, and their formulae,
26 :     then proceed recursively until a limit is reached.
27 :    
28 :     The currently-supported command-line options are as follows.
29 :    
30 :     =over 4
31 :    
32 :     =item count
33 :    
34 :     Number of iterations of neighbors to run through before stopping. The default
35 :     is C<5>.
36 :    
37 :     =item user
38 :    
39 :     Name suffix to be used for log files. If omitted, the PID is used.
40 :    
41 :     =item trace
42 :    
43 :     Numeric trace level. A higher trace level causes more messages to appear. The
44 :     default trace level is 2. Tracing will be directly to the standard output
45 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
46 :     where I<User> is the value of the B<user> option above.
47 :    
48 :     =item sql
49 :    
50 :     If specified, turns on tracing of SQL activity.
51 :    
52 :     =item background
53 :    
54 :     Save the standard and error output to files. The files will be created
55 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
56 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
57 :     B<user> option above.
58 :    
59 :     =item h
60 :    
61 :     Display this command's parameters and options.
62 :    
63 :     =item dbname
64 :    
65 :     Name of the Sapling database to use. This option is generally only useful for debugging.
66 :    
67 :     =item dbhost
68 :    
69 :     SQL host for the Sapling database to use. This option is generally only useful for debugging.
70 :    
71 :     =item dbport
72 :    
73 :     Database port to use for the Sapling database. This option is generally only useful for debugging.
74 :    
75 :     =back
76 :    
77 :     =cut
78 :    
79 :     use strict;
80 :     use Tracer;
81 :     use Stats;
82 :     use Sapling;
83 :     use SAPserver;
84 :    
85 :     # Parse the command line.
86 :     my ($options, @parameters) = StandardSetup([qw(ERDB Sapling)],
87 :     {dbname => [$FIG_Config::saplingDB, "name of the Sapling database to use"],
88 :     dbhost => ["", "host containing the Sapling database"],
89 :     dbport => ["", "port for connecting to the Sapling database"],
90 :     count => [5, "number of neighbor iterations to run"],
91 :     trace => ["2-", "trace level"],
92 :     },
93 :     "<rxn1> <rxn2> ...", @ARGV);
94 :    
95 :     # Connect to the Sapling.
96 :     my $sap = Sapling->new(dbName => $options->{dbname}, dbhost => $options->{dbhost},
97 :     port => $options->{dbport});
98 :     # Get a Sapling server for it. Note we're localhost, so this is not using the real
99 :     # servers. It is, after all, essentially a test script.
100 :     my $sapObject = SAPserver->new(sapDB => $sap, url => 'localhost');
101 :     # Get the iteration count.
102 :     my $count = $options->{count};
103 :     # Get the starting reactions.
104 :     my @queue = @parameters;
105 :     # This hash will hold reactions we've already found, so that we don't loop back.
106 :     my %found;
107 :     # Loop through the iterations. At the beginning of each iteration, the reactions
108 :     # we want to process are in @queue. If @queue is ever empty, we stop.
109 :     while (@queue && $count-- > 0) {
110 :     # We'll build the new queue in here.
111 :     my @newQueue;
112 :     # Get the reaction strings and roles.
113 :     my $rxnStringHash = $sapObject->reaction_strings(-ids => \@queue, -roles => 1);
114 :     # Get the reaction neighbors for the next iteration.
115 :     my $neighborHash = $sapObject->reaction_neighbors(-ids => \@queue);
116 :     # Loop through the old queue.
117 :     for my $rxn (@queue) {
118 :     # Get the reaction string and the roles.
119 :     my ($string, @roles) = @{$rxnStringHash->{$rxn}};
120 :     print "*** $rxn: $string\n";
121 :     # Get the neighbors of this reaction.
122 :     my @neighbors = sort keys %{$neighborHash->{$rxn}};
123 :     print " " . scalar(@neighbors) . " neighbors: " .
124 :     join(", ", @neighbors) . "\n";
125 :     # Display the roles.
126 :     for my $role (@roles) {
127 :     print " role: $role\n";
128 :     }
129 :     # Get the list of new neighbors.
130 :     my @newRxns = grep { ! $found{$_} } @neighbors;
131 :     # Mark them so we don't process them again.
132 :     for my $newRxn (@newRxns) {
133 :     $found{$newRxn} = 1;
134 :     }
135 :     # Push them on the queue for next time.
136 :     push @newQueue, @newRxns;
137 :     }
138 :     # Replace the old queue with the new one.
139 :     @queue = @newQueue;
140 :     }
141 :     Trace("All done.") if T(2);
142 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3