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

Annotation of /Sprout/ModelSaplingLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (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 : parrello 1.13 #use FIGMODEL;
20 : parrello 1.1
21 :     package ModelSaplingLoader;
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use HTTP::Date;
26 :     use base 'BaseSaplingLoader';
27 :    
28 :     =head1 Sapling ModelLoader Load Group Class
29 :    
30 :     =head2 Introduction
31 :    
32 :     The ModelLoader Load Group includes all of the major mdl tables.
33 :    
34 :     =head3 new
35 :    
36 :     my $sl = ModelLoaderSaplingLoader->new($erdb, $options, @tables);
37 :    
38 :     Construct a new ModelLoaderSaplingLoader object.
39 :    
40 :     =over 4
41 :    
42 :     =item erdb
43 :    
44 : parrello 1.4 L<Sapling> object for the database being loaded.
45 : parrello 1.1
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 :     my ($class, $erdb, $options) = @_;
61 :     # Create the table list.
62 : parrello 1.10 my @tables = sort qw(StructuralCue IsFoundIn Compound HasAliasOf AliasType
63 :     HasReactionAliasOf Reaction Involves IsTriggeredBy
64 :     RoleSet IsCombinationOf IsCategorizedInto EcNumber
65 :     IsConsistentWith IsStimulatedBy FeatureSet IsSetOf
66 :     IsRequiredBy Model IsModeledBy ModelUser); # Encompasses);
67 : parrello 1.1 # Create the BaseSaplingLoader object.
68 :     my $retVal = BaseSaplingLoader::new($class, $erdb, $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 mdl files.
80 :    
81 :     =cut
82 :    
83 :     sub Generate {
84 :     # Get the parameters.
85 :     my ($self) = @_;
86 :     # Get the database object.
87 :     my $erdb = $self->db();
88 :     # Get the source object.
89 :     my $fig = $self->source();
90 :     # Is this the global section?
91 : parrello 1.13 #my $model = new FIGMODEL;
92 : parrello 1.1 if ($self->global()) {
93 :     #Loading the compound entities and relationships
94 : parrello 1.13 # $self->LoadCompounds($model);
95 : parrello 1.1 #Loading the reaction, and EC number entities and relationships
96 : parrello 1.13 # $self->LoadReactions($model);
97 : parrello 1.1 } else {
98 :     # Get the section ID.
99 :     my $genomeID = $self->section();
100 :     #NO GENOME SPECIFIC MODEL STUFF
101 :     }
102 :     }
103 :    
104 :     sub LoadCompounds {
105 :     my ($self,$model) = @_;
106 :    
107 :     #First getting the compound table which has a list of all compounds in the database as well as alot of compound information
108 : parrello 1.8 my $CompoundTable = $model->database()->GetDBTable("COMPOUNDS");
109 : parrello 1.1
110 :     #Adding the universal AliasType that will always exist
111 :     $self->PutE(AliasType => "NAME", source => "NONE");
112 :     $self->PutE(AliasType => "SEARCHNAME", source => "NONE");
113 :     $self->PutE(AliasType => "KEGG", source => "http://www.kegg.com/");
114 :     $self->PutE(AliasType => "ARGONNE", source => "OBSOLETE IDs");
115 :    
116 :     #Cycling through the compound list and adding each individual compound entity
117 :     for (my $i=0; $i < $CompoundTable->size(); $i++) {
118 :     my $Row = $CompoundTable->get_row($i);
119 :     if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/cpd\d\d\d\d\d/) {
120 :     my $Object = FIGMODELObject->load($model->{"compound directory"}->[0].$Row->{"DATABASE"}->[0],"\t");
121 :     my @LoadingArray = ($Row->{"DATABASE"}->[0],$Row->{"DATABASE"}->[0],0,"",0,"",0,10000000,10000000,"");
122 : parrello 1.3 $self->Track(compoundRow => $LoadingArray[0], 1000);
123 : parrello 1.1 if (defined($Row->{"NAME"}->[0])) {
124 :     $LoadingArray[1] = $Row->{"NAME"}->[0];
125 :     }
126 :     if (defined($Object->{"MASS"}->[0])) {
127 :     $LoadingArray[2] = $Object->{"MASS"}->[0];
128 :     }
129 :     if (defined($Object->{"FORMULA"}->[0])) {
130 :     $LoadingArray[3] = $Object->{"FORMULA"}->[0];
131 :     }
132 :     if (defined($Object->{"CHARGE"}->[0])) {
133 :     $LoadingArray[4] = $Object->{"CHARGE"}->[0];
134 :     }
135 :     if (defined($Object->{"CHARGE"}->[0]) && defined($Object->{"FORMULA"}->[0])) {
136 :     $LoadingArray[5] = FIGMODEL::ConvertToNeutralFormula($Object->{"FORMULA"}->[0],$Object->{"CHARGE"}->[0]);
137 :     }
138 :     if (-e $model->{"Argonne molfile directory"}->[0].$Row->{"DATABASE"}->[0].".mol" || -e $model->{"Argonne molfile directory"}->[0]."pH7/".$Row->{"DATABASE"}->[0].".mol") {
139 :     $LoadingArray[6] = 1;
140 :     }
141 :     if (defined($Object->{"DELTAG"}->[0])) {
142 :     $LoadingArray[7] = $Object->{"DELTAG"}->[0];
143 :     }
144 :     if (defined($Object->{"DELTAGERR"}->[0])) {
145 :     $LoadingArray[8] = $Object->{"DELTAGERR"}->[0];
146 :     }
147 :     if (defined($Row->{"STRINGCODE"}->[0])) {
148 :     $LoadingArray[9] = $Row->{"STRINGCODE"}->[0];
149 :     }
150 :     $self->PutE(Compound => $LoadingArray[0], label => $LoadingArray[1], mass => $LoadingArray[2], chargedFormula => $LoadingArray[3], charge => $LoadingArray[4],neutralFormula => $LoadingArray[5], hasMolfile => $LoadingArray[6], deltaG => $LoadingArray[7], deltaGerr => $LoadingArray[8], stringcode => $LoadingArray[9]);
151 :     #Adding the relationship between compound and structural cue
152 :     if (defined($Object->{"STRUCTURAL_CUES"})) {
153 :     foreach my $Cue (@{$Object->{"STRUCTURAL_CUES"}}) {
154 :     my @TempArray = split(/:/,$Cue);
155 :     if (@TempArray == 2) {
156 :     $self->PutR(IsFoundIn => $TempArray[0],$LoadingArray[0],count => $TempArray[1]);
157 :     }
158 :     }
159 :     }
160 :     #Adding the relationship between compound and alias type
161 :     if (defined($Object->{"NAME"})) {
162 :     foreach my $Name (@{$Object->{"NAME"}}) {
163 :     $self->PutR(HasAliasOf => $LoadingArray[0],"NAME",alias => $Name);
164 :     my @SearchNames = FIGMODEL::ConvertToSearchNames($Name);
165 :     foreach my $SearchName (@SearchNames) {
166 :     $self->PutR(HasAliasOf => $LoadingArray[0],"SEARCHNAME",alias => $SearchName);
167 :     }
168 :     }
169 :     }
170 :     if (defined($Object->{"DBLINKS"})) {
171 :     foreach my $Link (@{$Object->{"DBLINKS"}}) {
172 :     my @TempArray = split(/:/,$Link);
173 :     if (@TempArray >= 2) {
174 :     if ($TempArray[0] ne "KEGG" && $TempArray[0] ne "ARGONNE") {
175 :     $self->PutE(AliasType => $TempArray[0], source => "PUBLISHED MODEL");
176 :     }
177 :     if ($TempArray[0] eq "ARGONNE") {
178 :     splice(@TempArray,1,1);
179 :     }
180 :     for (my $j=1; $j < @TempArray; $j++) {
181 :     $self->PutR(HasAliasOf => $LoadingArray[0],$TempArray[0],alias => $TempArray[$j]);
182 :     }
183 :     }
184 :     }
185 :     }
186 :     }
187 :     }
188 :     }
189 :    
190 :     sub LoadReactions {
191 :     my ($self,$model) = @_;
192 :     #First getting the reaction table which has a list of all reactions in the database as well as alot of reaction information
193 : parrello 1.8 my $ReactionTable = $model->database()->GetDBTable("REACTIONS");
194 : parrello 1.1
195 :     #Cycling through the compound list and adding each individual compound entity
196 :     my $Count = 0;
197 :     for (my $i=0; $i < $ReactionTable->size(); $i++) {
198 :     my $Row = $ReactionTable->get_row($i);
199 :     if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/rxn\d\d\d\d\d/) {
200 :     my $Object = FIGMODELObject->load($model->{"reaction directory"}->[0].$Row->{"DATABASE"}->[0],"\t");
201 :     my @LoadingArray = ($Row->{"DATABASE"}->[0],"","","","","",10000000,10000000,10000000,"R");
202 : parrello 1.3 $self->Track(reactionRow => $LoadingArray[0], 1000);
203 : parrello 1.1 if (defined($Object->{"DEFINITION"}->[0])) {
204 :     $LoadingArray[1] = $Object->{"DEFINITION"}->[0];
205 :     }
206 :     if (defined($Object->{"EQUATION"}->[0])) {
207 :     my ($Direction,$Equation,$ReverseEquation,$FullEquation,$EquationCompartment,$Error) = $model->ConvertEquationToCode($Object->{"EQUATION"}->[0],{"Test" => "Test"});
208 :     $LoadingArray[2] = $Equation;
209 :     }
210 :     if (defined($Object->{"OPERATOR"}->[0])) {
211 :     $LoadingArray[3] = $Object->{"OPERATOR"}->[0];
212 :     }
213 :     if (defined($Object->{"PATHWAY"}->[0])) {
214 :     $LoadingArray[4] = join(";",@{$Object->{"PATHWAY"}});
215 :     }
216 :     if (defined($Row->{"KEGG MAPS"}->[0])) {
217 :     $LoadingArray[5] = join(";",@{$Row->{"KEGG MAPS"}});
218 :     }
219 :     if (defined($Object->{"DELTAG"}->[0])) {
220 :     $LoadingArray[6] = $Object->{"DELTAG"}->[0];
221 :     }
222 :     if (defined($Object->{"MMDELTAG"}->[0])) {
223 :     $LoadingArray[7] = $Object->{"MMDELTAG"}->[0];
224 :     }
225 :     if (defined($Object->{"DELTAGERR"}->[0])) {
226 :     $LoadingArray[8] = $Object->{"DELTAGERR"}->[0];
227 :     }
228 :     if (defined($Object->{"THERMODYNAMIC REVERSIBILITY"}->[0])) {
229 :     my $code = $Object->{"THERMODYNAMIC REVERSIBILITY"}->[0];
230 :     if ($code eq '<=>') {
231 :     $LoadingArray[9] = "R";
232 :     } elsif ($code eq '<=') {
233 :     $LoadingArray[9] = "B";
234 :     } elsif ($code eq '=>') {
235 :     $LoadingArray[9] = "F";
236 :     }
237 :     }
238 :     $self->PutE(Reaction => $LoadingArray[0], definition => $LoadingArray[1], code => $LoadingArray[2], operator => $LoadingArray[3], pathway => $LoadingArray[4],keggMap => $LoadingArray[5], deltaG => $LoadingArray[6], MMdeltaG => $LoadingArray[7], deltaGerr => $LoadingArray[8], predictedReversibility => $LoadingArray[9]);
239 :     #Adding relationship between compounds and reactions
240 :     my ($Reactants,$Products) = $model->GetReactionSubstrateData($LoadingArray[0]);
241 : parrello 1.3 if (! defined $Reactants) {
242 :     $self->Add(missingReactants => 1);
243 :     } else {
244 :     for (my $j=0; $j < @{$Reactants}; $j++) {
245 :     $self->PutR(Involves => $LoadingArray[0],$Reactants->[$j]->{"DATABASE"}->[0],product => 0,stoichiometry => $Reactants->[$j]->{"COEFFICIENT"}->[0],main => 1,compartment => $Reactants->[$j]->{"COMPARTMENT"}->[0],discriminator => $Count);
246 :     #TODO:Properly identify main reactants in reactions
247 :     $Count++;
248 :     }
249 :     }
250 :     if (! defined $Products) {
251 :     $self->Add(missingProducts => 1);
252 :     } else {
253 :     for (my $j=0; $j < @{$Products}; $j++) {
254 :     $self->PutR(Involves => $LoadingArray[0],$Products->[$j]->{"DATABASE"}->[0],product => 1,stoichiometry => $Products->[$j]->{"COEFFICIENT"}->[0],main => 1,compartment => $Products->[$j]->{"COMPARTMENT"}->[0],discriminator => $Count);
255 :     #TODO:Properly identify main reactants in reactions
256 :     $Count++;
257 :     }
258 : parrello 1.1 }
259 :     #Adding relationship between EC number and reactions
260 :     if (defined($Object->{"ENZYME"})) {
261 :     foreach my $Enzyme (@{$Object->{"ENZYME"}}) {
262 : parrello 1.6 if ($Enzyme =~ /,/) {
263 :     #TODO:Invalid enzyme
264 :     } else {
265 :     $Enzyme =~ s/\s//g;
266 :     $self->PutE(EcNumber => $Enzyme, obsolete => 0, replacedby => "NONE");
267 :     $self->PutR(IsCategorizedInto => $LoadingArray[0],$Enzyme,source => "KEGG");
268 :     }
269 : parrello 1.1 }
270 :     }
271 :     #Adding the relationship between reaction and alias type
272 :     if (defined($Object->{"NAME"})) {
273 :     foreach my $Name (@{$Object->{"NAME"}}) {
274 :     $self->PutR(HasReactionAliasOf => $LoadingArray[0],"NAME",alias => $Name);
275 :     }
276 :     }
277 :     if (defined($Object->{"DBLINKS"})) {
278 :     foreach my $Link (@{$Object->{"DBLINKS"}}) {
279 :     my @TempArray = split(/:/,$Link);
280 :     if (@TempArray >= 2) {
281 :     if ($TempArray[0] ne "KEGG" && $TempArray[0] ne "ARGONNE") {
282 :     $self->PutE(AliasType => $TempArray[0], source => "PUBLISHED MODEL");
283 :     }
284 :     if ($TempArray[0] eq "ARGONNE") {
285 :     splice(@TempArray,1,1);
286 :     }
287 :     for (my $j=1; $j < @TempArray; $j++) {
288 :     $self->PutR(HasReactionAliasOf => $LoadingArray[0],$TempArray[0],alias => $TempArray[$j]);
289 :     }
290 :     }
291 :     }
292 :     }
293 :     }
294 :     }
295 :     }
296 :    
297 :    
298 : parrello 1.10 sub FixDate {
299 :     my ($date) = @_;
300 :     my $retVal = ($date eq 'NA' ? 0 : $date);
301 :     return $retVal;
302 :     }
303 :    
304 : parrello 1.1 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3