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

Annotation of /Sprout/ReactionSproutLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3