[Bio] / Sprout / ReactionSproutLoader.pm Repository:
ViewVC logotype

Annotation of /Sprout/ReactionSproutLoader.pm

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 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     package ReactionSproutLoader;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use base 'BaseSproutLoader';
26 :    
27 :     =head1 Sprout Reaction Load Group Class
28 :    
29 :     =head2 Introduction
30 :    
31 :     The Reaction Load Group includes all of the major reaction and compound tables.
32 :    
33 :     =head3 new
34 :    
35 :     my $sl = ReactionSproutLoader->new($erdb, $source, $options, @tables);
36 :    
37 :     Construct a new ReactionSproutLoader object.
38 :    
39 :     =over 4
40 :    
41 :     =item erdb
42 :    
43 :     [[SproutPm]] object for the database being loaded.
44 :    
45 :     =item source
46 :    
47 :     [[FigPm]] object used to access the source data. If this parameter is undefined,
48 :     it will be created the first time the L</source> method is called.
49 :    
50 :     =item options
51 :    
52 :     Reference to a hash of command-line options.
53 :    
54 :     =item tables
55 :    
56 :     List of tables in this load group.
57 :    
58 :     =back
59 :    
60 :     =cut
61 :    
62 :     sub new {
63 :     # Get the parameters.
64 :     my ($class, $erdb, $source, $options) = @_;
65 :     # Create the table list.
66 :     my @tables = sort qw(Reaction ReactionURL Compound CompoundName CompoundCAS IsIdentifiedByCAS HasCompoundName IsAComponentOf Scenario Catalyzes HasScenario IsInputFor IsOutputOf ExcludesReaction IncludesReaction IsOnDiagram IncludesReaction);
67 :     # Create the BaseSproutLoader object.
68 :     my $retVal = BaseSproutLoader::new($class, $erdb, $source, $options, @tables);
69 :     # Return it.
70 :     return $retVal;
71 :     }
72 :    
73 :     =head2 Public Methods
74 :    
75 :     =head3 Generate
76 :    
77 :     $sl->Generate();
78 :    
79 :     Generate the data for the reaction and compound files.
80 :    
81 :     =cut
82 :    
83 :     sub Generate {
84 :     # Get the parameters.
85 :     my ($self) = @_;
86 :     # Get the sprout object.
87 :     my $sprout = $self->db();
88 :     # Get the FIG object.
89 :     my $fig = $self->source();
90 :     # Is this the global section?
91 :     if ($self->global()) {
92 :     Trace("Generating reaction data.") if T(2);
93 :     # We need some hashes to prevent duplicates.
94 :     my %compoundNames = ();
95 :     my %compoundCASes = ();
96 :     # First we create the compounds.
97 :     my %compounds = map { $_ => 1 } $fig->all_compounds();
98 :     for my $cid (keys %compounds) {
99 :     # Check for names.
100 :     my @names = $fig->names_of_compound($cid);
101 :     # Each name will be given a priority number, starting with 1.
102 :     my $prio = 1;
103 :     for my $name (@names) {
104 :     if (! exists $compoundNames{$name}) {
105 :     $self->PutE(CompoundName => $name);
106 :     $compoundNames{$name} = 1;
107 :     }
108 :     $$self->PutRl(HasCompoundName => $cid, $name, priority => $prio++);
109 :     }
110 :     # Create the main compound record. Note that the first name
111 :     # becomes the label.
112 :     my $label = (@names > 0 ? $names[0] : $cid);
113 :     $self->PutE(Compound => $cid, label => $label);
114 :     # Check for a CAS ID.
115 :     my $cas = $fig->cas($cid);
116 :     if ($cas) {
117 :     $self->PutR(IsIdentifiedByCAS => $cid, $cas);
118 :     $self->PutE(CompoundCAR => $cas);
119 :     }
120 :     }
121 :     # All the compounds are set up, so we need to loop through the reactions next. First,
122 :     # we initialize the discriminator index. This is a single integer used to insure
123 :     # duplicate elements in a reaction are not accidentally collapsed.
124 :     my $discrim = 0;
125 :     my %reactions = map { $_ => 1 } $fig->all_reactions();
126 :     for my $reactionID (keys %reactions) {
127 :     # Create the reaction record.
128 :     $self->Put(Reaction => $reactionID, rev => $fig->reversible($reactionID));
129 :     # Compute the reaction's URL.
130 :     my $url = HTML::reaction_link($reactionID);
131 :     # Put it in the ReactionURL table.
132 :     $self->Put(ReactionURL => $reactionID, url => $url);
133 :     # Now we need all of the reaction's compounds. We get these in two phases,
134 :     # substrates first and then products.
135 :     for my $product (0, 1) {
136 :     # Get the compounds of the current type for the current reaction. FIG will
137 :     # give us 3-tuples: [ID, stoichiometry, main-flag]. At this time we do not
138 :     # have location data in SEED, so it defaults to the empty string.
139 :     my @compounds = $fig->reaction2comp($reactionID, $product);
140 :     for my $compData (@compounds) {
141 :     # Extract the compound data from the current tuple.
142 :     my ($cid, $stoich, $main) = @{$compData};
143 :     # Link the compound to the reaction.
144 :     $self->PutR(IsAComponentOf => $cid, $reactionID,
145 :     discriminator => $discrim++, loc => "",
146 :     main => $main, product => $product,
147 :     stoichiometry => $stoich);
148 :     }
149 :     }
150 :     }
151 :     # Now we run through the subsystems and roles, generating the scenarios
152 :     # and connecting the reactions. We'll need some hashes to prevent
153 :     # duplicates and a counter for compound group keys.
154 :     my %roles = ();
155 :     my %scenarios = ();
156 :     my @subsystems = $fig->all_subsystems();
157 :     for my $subName (@subsystems) {
158 :     my $sub = $fig->get_subsystem($subName);
159 :     Trace("Processing $subName reactions.") if T(3);
160 :     # Get the subsystem's reactions.
161 :     my %reactions = $sub->get_hope_reactions();
162 :     # Loop through the roles, connecting them to the reactions.
163 :     for my $role (keys %reactions) {
164 :     # Only process this role if it is new.
165 :     if (! $roles{$role}) {
166 :     $roles{$role} = 1;
167 :     my @reactions = @{$reactions{$role}};
168 :     for my $reaction (@reactions) {
169 :     $self->PutR(Catalyzes => $role, $reaction);
170 :     }
171 :     }
172 :     }
173 :     Trace("Processing $subName scenarios.") if T(3);
174 :     # Get the subsystem's scenarios.
175 :     my @scenarioNames = $sub->get_hope_scenario_names();
176 :     # Loop through the scenarios, creating scenario data.
177 :     for my $scenarioName (@scenarioNames) {
178 :     # Link this scenario to this subsystem.
179 :     $self->PutR(HasScenario => $subName, $scenarioName);
180 :     # If this scenario is new, we need to create it.
181 :     if (! $scenarios{$scenarioName}) {
182 :     Trace("Creating scenario $scenarioName.") if T(3);
183 :     $scenarios{$scenarioName} = 1;
184 :     # Create the scenario itself.
185 :     $self->PutE(Scenario => $scenarioName);
186 :     # Attach the input compounds.
187 :     for my $input ($sub->get_hope_input_compounds($scenarioName)) {
188 :     $self->PutR(IsInputFor => $input, $scenarioName);
189 :     }
190 :     # Now we need to set up the output compounds. They come in two
191 :     # groups, which we mark 0 and 1.
192 :     my $outputGroup = 0;
193 :     # Set up the output compounds.
194 :     for my $outputGroup ($sub->get_hope_output_compounds($scenarioName)) {
195 :     # Attach the compounds.
196 :     for my $compound (@$outputGroup) {
197 :     $self->PutR(IsOutputOf => $scenarioName, $compound,
198 :     auxiliary => $outputGroup);
199 :     }
200 :     }
201 :     # Create the reaction lists.
202 :     my @addReactions = $sub->get_hope_additional_reactions($scenarioName);
203 :     for my $reaction (@addReactions) {
204 :     $self->PutR(IncludesReaction => $scenarioName, $reaction);
205 :     }
206 :     my @notReactions = $sub->get_hope_ignore_reactions($scenarioName);
207 :     for my $reaction (@notReactions) {
208 :     $self->PutR(ExcludesReaction => $scenarioName, $reaction);
209 :     }
210 :     # Link the maps.
211 :     my @maps = $sub->get_hope_map_ids($scenarioName);
212 :     for my $map (@maps) {
213 :     $self->PutR(IsOnDiagram => $scenarioName, "map$map");
214 :     }
215 :     }
216 :     }
217 :     }
218 :     }
219 :     }
220 :    
221 :    
222 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3