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

Annotation of /Sprout/ModelSaplingLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (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 :     use FIGMODEL;
20 :    
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.6 my @tables = sort qw(StructuralCue IsFoundIn Compound HasAliasOf AliasType HasReactionAliasOf Reaction Involves IsTriggeredBy RoleSet IsCombinationOf IsCategorizedInto EcNumber IsConsistentWith IsStimulatedBy FeatureSet IsSetOf IsRequiredBy Model IsModeledBy); # Encompasses);
63 : parrello 1.1 # Create the BaseSaplingLoader object.
64 :     my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);
65 :     # 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 mdl files.
76 :    
77 :     =cut
78 :    
79 :     sub Generate {
80 :     # Get the parameters.
81 :     my ($self) = @_;
82 :     # Get the database object.
83 :     my $erdb = $self->db();
84 :     # Get the source object.
85 :     my $fig = $self->source();
86 :     # Is this the global section?
87 :     my $model = new FIGMODEL;
88 :     if ($self->global()) {
89 :     #Loading the model entities and relationships
90 :     $self->LoadModels($model);
91 :     #Loading structural cues first
92 :     $self->LoadStructuralCues($model);
93 :     #Loading the compound entities and relationships
94 :     $self->LoadCompounds($model);
95 :     #Loading the reaction, and EC number entities and relationships
96 :     $self->LoadReactions($model);
97 :     #Loading the role set entity and relationships
98 :     $self->LoadRoleSets($model);
99 :     } else {
100 :     # Get the section ID.
101 :     my $genomeID = $self->section();
102 :     #NO GENOME SPECIFIC MODEL STUFF
103 :     }
104 :     }
105 :    
106 :     #This function loads all of the StructuralCue entities
107 :     sub LoadStructuralCues {
108 :     my ($self,$model) = @_;
109 :    
110 :     #Getting the list of structural cue filenames
111 :     my @CuesList = glob($model->{"Reaction database directory"}->[0]."cues/");
112 :     my %CuePriorities;
113 :     #TODO:NEED TO POPULATE THE PRIORITIES HASH
114 :     foreach my $CueFile (@CuesList) {
115 :     my $Object = FIGMODELObject->load($CueFile,"\t");
116 :     if (defined($Object) && defined($Object->{"NAME"}->[0])) {
117 :     my @LoadingArray = ($Object->{"NAME"}->[0],-1,0,0,"","","","");
118 :     if (defined($CuePriorities{$Object->{"NAME"}->[0]})) {
119 :     $LoadingArray[1] = $CuePriorities{$Object->{"NAME"}->[0]};
120 :     }
121 :     if (defined($Object->{"SMALL_MOLECULE"}->[0])) {
122 :     $LoadingArray[2] = $Object->{"SMALL_MOLECULE"}->[0];
123 :     }
124 :     if (defined($Object->{"CHARGE"}->[0])) {
125 :     $LoadingArray[3] = $Object->{"CHARGE"}->[0];
126 :     }
127 :     if (defined($Object->{"FORMULA"}->[0])) {
128 :     $LoadingArray[4] = $Object->{"FORMULA"}->[0];
129 :     }
130 :     if (defined($Object->{"ENERGY"}->[0])) {
131 :     $LoadingArray[5] = $Object->{"ENERGY"}->[0];
132 :     }
133 :     if (defined($Object->{"ERROR"}->[0])) {
134 :     $LoadingArray[6] = $Object->{"ERROR"}->[0];
135 :     }
136 :     if (defined($Object->{"STRUCTURAL_CUES"}->[0])) {
137 :     $LoadingArray[7] = join(";",@{$Object->{"STRUCTURAL_CUES"}});
138 :     }
139 :     $self->PutE(StructuralCue => $LoadingArray[0], priority => $LoadingArray[1], smallMolecule => $LoadingArray[2], charge => $LoadingArray[3], formula => $LoadingArray[4],deltaG => $LoadingArray[5], deltaGerr => $LoadingArray[6], subgroups => $LoadingArray[7]);
140 :     }
141 :     }
142 :     }
143 :    
144 :     sub LoadCompounds {
145 :     my ($self,$model) = @_;
146 :    
147 :     #First getting the compound table which has a list of all compounds in the database as well as alot of compound information
148 : parrello 1.8 my $CompoundTable = $model->database()->GetDBTable("COMPOUNDS");
149 : parrello 1.1
150 :     #Adding the universal AliasType that will always exist
151 :     $self->PutE(AliasType => "NAME", source => "NONE");
152 :     $self->PutE(AliasType => "SEARCHNAME", source => "NONE");
153 :     $self->PutE(AliasType => "KEGG", source => "http://www.kegg.com/");
154 :     $self->PutE(AliasType => "ARGONNE", source => "OBSOLETE IDs");
155 :    
156 :     #Cycling through the compound list and adding each individual compound entity
157 :     for (my $i=0; $i < $CompoundTable->size(); $i++) {
158 :     my $Row = $CompoundTable->get_row($i);
159 :     if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/cpd\d\d\d\d\d/) {
160 :     my $Object = FIGMODELObject->load($model->{"compound directory"}->[0].$Row->{"DATABASE"}->[0],"\t");
161 :     my @LoadingArray = ($Row->{"DATABASE"}->[0],$Row->{"DATABASE"}->[0],0,"",0,"",0,10000000,10000000,"");
162 : parrello 1.3 $self->Track(compoundRow => $LoadingArray[0], 1000);
163 : parrello 1.1 if (defined($Row->{"NAME"}->[0])) {
164 :     $LoadingArray[1] = $Row->{"NAME"}->[0];
165 :     }
166 :     if (defined($Object->{"MASS"}->[0])) {
167 :     $LoadingArray[2] = $Object->{"MASS"}->[0];
168 :     }
169 :     if (defined($Object->{"FORMULA"}->[0])) {
170 :     $LoadingArray[3] = $Object->{"FORMULA"}->[0];
171 :     }
172 :     if (defined($Object->{"CHARGE"}->[0])) {
173 :     $LoadingArray[4] = $Object->{"CHARGE"}->[0];
174 :     }
175 :     if (defined($Object->{"CHARGE"}->[0]) && defined($Object->{"FORMULA"}->[0])) {
176 :     $LoadingArray[5] = FIGMODEL::ConvertToNeutralFormula($Object->{"FORMULA"}->[0],$Object->{"CHARGE"}->[0]);
177 :     }
178 :     if (-e $model->{"Argonne molfile directory"}->[0].$Row->{"DATABASE"}->[0].".mol" || -e $model->{"Argonne molfile directory"}->[0]."pH7/".$Row->{"DATABASE"}->[0].".mol") {
179 :     $LoadingArray[6] = 1;
180 :     }
181 :     if (defined($Object->{"DELTAG"}->[0])) {
182 :     $LoadingArray[7] = $Object->{"DELTAG"}->[0];
183 :     }
184 :     if (defined($Object->{"DELTAGERR"}->[0])) {
185 :     $LoadingArray[8] = $Object->{"DELTAGERR"}->[0];
186 :     }
187 :     if (defined($Row->{"STRINGCODE"}->[0])) {
188 :     $LoadingArray[9] = $Row->{"STRINGCODE"}->[0];
189 :     }
190 :     $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]);
191 :     #Adding the relationship between compound and structural cue
192 :     if (defined($Object->{"STRUCTURAL_CUES"})) {
193 :     foreach my $Cue (@{$Object->{"STRUCTURAL_CUES"}}) {
194 :     my @TempArray = split(/:/,$Cue);
195 :     if (@TempArray == 2) {
196 :     $self->PutR(IsFoundIn => $TempArray[0],$LoadingArray[0],count => $TempArray[1]);
197 :     }
198 :     }
199 :     }
200 :     #Adding the relationship between compound and alias type
201 :     if (defined($Object->{"NAME"})) {
202 :     foreach my $Name (@{$Object->{"NAME"}}) {
203 :     $self->PutR(HasAliasOf => $LoadingArray[0],"NAME",alias => $Name);
204 :     my @SearchNames = FIGMODEL::ConvertToSearchNames($Name);
205 :     foreach my $SearchName (@SearchNames) {
206 :     $self->PutR(HasAliasOf => $LoadingArray[0],"SEARCHNAME",alias => $SearchName);
207 :     }
208 :     }
209 :     }
210 :     if (defined($Object->{"DBLINKS"})) {
211 :     foreach my $Link (@{$Object->{"DBLINKS"}}) {
212 :     my @TempArray = split(/:/,$Link);
213 :     if (@TempArray >= 2) {
214 :     if ($TempArray[0] ne "KEGG" && $TempArray[0] ne "ARGONNE") {
215 :     $self->PutE(AliasType => $TempArray[0], source => "PUBLISHED MODEL");
216 :     }
217 :     if ($TempArray[0] eq "ARGONNE") {
218 :     splice(@TempArray,1,1);
219 :     }
220 :     for (my $j=1; $j < @TempArray; $j++) {
221 :     $self->PutR(HasAliasOf => $LoadingArray[0],$TempArray[0],alias => $TempArray[$j]);
222 :     }
223 :     }
224 :     }
225 :     }
226 :     }
227 :     }
228 :     }
229 :    
230 :     sub LoadReactions {
231 :     my ($self,$model) = @_;
232 :     #First getting the reaction table which has a list of all reactions in the database as well as alot of reaction information
233 : parrello 1.8 my $ReactionTable = $model->database()->GetDBTable("REACTIONS");
234 : parrello 1.1
235 :     #Cycling through the compound list and adding each individual compound entity
236 :     my $Count = 0;
237 :     for (my $i=0; $i < $ReactionTable->size(); $i++) {
238 :     my $Row = $ReactionTable->get_row($i);
239 :     if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/rxn\d\d\d\d\d/) {
240 :     my $Object = FIGMODELObject->load($model->{"reaction directory"}->[0].$Row->{"DATABASE"}->[0],"\t");
241 :     my @LoadingArray = ($Row->{"DATABASE"}->[0],"","","","","",10000000,10000000,10000000,"R");
242 : parrello 1.3 $self->Track(reactionRow => $LoadingArray[0], 1000);
243 : parrello 1.1 if (defined($Object->{"DEFINITION"}->[0])) {
244 :     $LoadingArray[1] = $Object->{"DEFINITION"}->[0];
245 :     }
246 :     if (defined($Object->{"EQUATION"}->[0])) {
247 :     my ($Direction,$Equation,$ReverseEquation,$FullEquation,$EquationCompartment,$Error) = $model->ConvertEquationToCode($Object->{"EQUATION"}->[0],{"Test" => "Test"});
248 :     $LoadingArray[2] = $Equation;
249 :     }
250 :     if (defined($Object->{"OPERATOR"}->[0])) {
251 :     $LoadingArray[3] = $Object->{"OPERATOR"}->[0];
252 :     }
253 :     if (defined($Object->{"PATHWAY"}->[0])) {
254 :     $LoadingArray[4] = join(";",@{$Object->{"PATHWAY"}});
255 :     }
256 :     if (defined($Row->{"KEGG MAPS"}->[0])) {
257 :     $LoadingArray[5] = join(";",@{$Row->{"KEGG MAPS"}});
258 :     }
259 :     if (defined($Object->{"DELTAG"}->[0])) {
260 :     $LoadingArray[6] = $Object->{"DELTAG"}->[0];
261 :     }
262 :     if (defined($Object->{"MMDELTAG"}->[0])) {
263 :     $LoadingArray[7] = $Object->{"MMDELTAG"}->[0];
264 :     }
265 :     if (defined($Object->{"DELTAGERR"}->[0])) {
266 :     $LoadingArray[8] = $Object->{"DELTAGERR"}->[0];
267 :     }
268 :     if (defined($Object->{"THERMODYNAMIC REVERSIBILITY"}->[0])) {
269 :     my $code = $Object->{"THERMODYNAMIC REVERSIBILITY"}->[0];
270 :     if ($code eq '<=>') {
271 :     $LoadingArray[9] = "R";
272 :     } elsif ($code eq '<=') {
273 :     $LoadingArray[9] = "B";
274 :     } elsif ($code eq '=>') {
275 :     $LoadingArray[9] = "F";
276 :     }
277 :     }
278 :     $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]);
279 :     #Adding relationship between compounds and reactions
280 :     my ($Reactants,$Products) = $model->GetReactionSubstrateData($LoadingArray[0]);
281 : parrello 1.3 if (! defined $Reactants) {
282 :     $self->Add(missingReactants => 1);
283 :     } else {
284 :     for (my $j=0; $j < @{$Reactants}; $j++) {
285 :     $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);
286 :     #TODO:Properly identify main reactants in reactions
287 :     $Count++;
288 :     }
289 :     }
290 :     if (! defined $Products) {
291 :     $self->Add(missingProducts => 1);
292 :     } else {
293 :     for (my $j=0; $j < @{$Products}; $j++) {
294 :     $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);
295 :     #TODO:Properly identify main reactants in reactions
296 :     $Count++;
297 :     }
298 : parrello 1.1 }
299 :     #Adding relationship between EC number and reactions
300 :     if (defined($Object->{"ENZYME"})) {
301 :     foreach my $Enzyme (@{$Object->{"ENZYME"}}) {
302 : parrello 1.6 if ($Enzyme =~ /,/) {
303 :     #TODO:Invalid enzyme
304 :     } else {
305 :     $Enzyme =~ s/\s//g;
306 :     $self->PutE(EcNumber => $Enzyme, obsolete => 0, replacedby => "NONE");
307 :     $self->PutR(IsCategorizedInto => $LoadingArray[0],$Enzyme,source => "KEGG");
308 :     }
309 : parrello 1.1 }
310 :     }
311 :     #Adding the relationship between reaction and alias type
312 :     if (defined($Object->{"NAME"})) {
313 :     foreach my $Name (@{$Object->{"NAME"}}) {
314 :     $self->PutR(HasReactionAliasOf => $LoadingArray[0],"NAME",alias => $Name);
315 :     }
316 :     }
317 :     if (defined($Object->{"DBLINKS"})) {
318 :     foreach my $Link (@{$Object->{"DBLINKS"}}) {
319 :     my @TempArray = split(/:/,$Link);
320 :     if (@TempArray >= 2) {
321 :     if ($TempArray[0] ne "KEGG" && $TempArray[0] ne "ARGONNE") {
322 :     $self->PutE(AliasType => $TempArray[0], source => "PUBLISHED MODEL");
323 :     }
324 :     if ($TempArray[0] eq "ARGONNE") {
325 :     splice(@TempArray,1,1);
326 :     }
327 :     for (my $j=1; $j < @TempArray; $j++) {
328 :     $self->PutR(HasReactionAliasOf => $LoadingArray[0],$TempArray[0],alias => $TempArray[$j]);
329 :     }
330 :     }
331 :     }
332 :     }
333 :     }
334 :     }
335 :     }
336 :    
337 :     sub LoadRoleSets {
338 :     my ($self,$model) = @_;
339 :     my $sapling =$self->db();
340 : parrello 1.8 my $RoleMappings = $model->database()->GetDBTable("CURATED ROLE MAPPINGS");
341 : parrello 1.1 my $NewSet;
342 :     my $SetHash;
343 :     my $LastComplex = -1;
344 :     my $LastReaction = "";
345 :     my $LastRole = "";
346 :     for (my $i=0; $i < $RoleMappings->size(); $i++) {
347 :     my $Row = $RoleMappings->get_row($i);
348 :     if (defined($Row) && defined($Row->{"REACTION"}->[0]) && defined($Row->{"ROLE"}->[0]) && defined($Row->{"COMPLEX"}->[0]) && defined($Row->{"MASTER"}->[0])) {
349 :     if ($Row->{"REACTION"}->[0] ne $LastReaction || $LastComplex ne $Row->{"COMPLEX"}->[0]) {
350 :     if (defined($NewSet->{"ROLES"}) && defined($NewSet->{"REACTIONS"})) {
351 :     my @RoleList = sort(keys(%{$NewSet->{"ROLES"}}));
352 :     my @ReactionList = keys(%{$NewSet->{"REACTIONS"}});
353 :     foreach my $Reaction (@ReactionList) {
354 :     $SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0] = $NewSet->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0];
355 :     if (defined($NewSet->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"})) {
356 :     foreach my $Subsystem (@{$NewSet->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}) {
357 :     if (defined($SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"})) {
358 :     foreach my $OtherSubsystem (@{$SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}) {
359 :     if ($Subsystem eq $OtherSubsystem) {
360 :     $Subsystem = "";
361 :     last;
362 :     }
363 :     }
364 :     }
365 :     if ($Subsystem ne "") {
366 :     push(@{$SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}},$Subsystem);
367 :     }
368 :     }
369 :     }
370 :     }
371 :     foreach my $Role (@RoleList) {
372 :     $SetHash->{join("+",@RoleList)}->{"ROLES"}->{$Role} = 1;
373 :     }
374 :     }
375 :     $NewSet = {};
376 :     }
377 :     $NewSet->{"ROLES"}->{$Row->{"ROLE"}->[0]} = 1;
378 :     $NewSet->{"REACTIONS"}->{$Row->{"REACTION"}->[0]}->{"MASTER"}->[0] = $Row->{"MASTER"}->[0];
379 :     if (defined($Row->{"SUBSYSTEM"}->[0])) {
380 :     push(@{$NewSet->{"REACTIONS"}->{$Row->{"REACTION"}->[0]}->{"SUBSYSTEMS"}},$Row->{"SUBSYSTEM"}->[0]);
381 :     }
382 :     $LastRole = $Row->{"ROLE"}->[0];
383 :     $LastReaction = $Row->{"REACTION"}->[0];
384 :     $LastComplex = $Row->{"COMPLEX"}->[0];
385 :     }
386 :     }
387 :    
388 :     my @RoleSets = keys(%{$SetHash});
389 :     foreach my $RoleSet (@RoleSets) {
390 :     my $Digested = $sapling->DigestKey($RoleSet);
391 :     $self->PutE(RoleSet => $Digested, source => "NONE");
392 :     my @ReactionList = keys(%{$SetHash->{$RoleSet}->{"REACTIONS"}});
393 :     foreach my $Reaction (@ReactionList) {
394 :     $self->PutR(IsTriggeredBy => $Reaction,$Digested, source => "NONE",master => $SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0],subsystem => join(";",@{$SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}));
395 :     }
396 :     my @RoleList = keys(%{$SetHash->{$RoleSet}->{"ROLES"}});
397 :     foreach my $Role (@RoleList) {
398 :     $self->PutR(IsCombinationOf => $Digested,$Role, local => 0);
399 :     }
400 :     }
401 :     }
402 :    
403 :     sub LoadModels {
404 :     my ($self,$model) = @_;
405 :     my $sapling = $self->db();
406 : parrello 1.2 ## TRS: Get hash of valid genome IDs.
407 :     my $genomeHash = $sapling->GenomeHash();
408 : parrello 1.8 my $ModelList = $model->database()->GetDBTable("MODEL LIST");
409 :     my $ModelStats = $model->database()->GetDBTable("MODEL STATS");
410 : parrello 1.1 for (my $i=0; $i < $ModelStats->size(); $i++) {
411 :     my $Row = $ModelStats->get_row($i);
412 :     if (defined($Row) && defined($Row->{"Model ID"}->[0])) {
413 :     my @LoadingArray = ($Row->{"Model ID"}->[0],"","",0,0,0,"",0,0,0,0,0,0,0,0,0,0,0,0,"","",0,0,"",0,0);
414 : parrello 1.2 if (defined($Row->{"Genome ID"}->[0]) && $genomeHash->{$Row->{"Genome ID"}->[0]}) {
415 :     if (defined($Row->{"Organism name"}->[0])) {
416 :     $LoadingArray[1] = $Row->{"Organism name"}->[0];
417 :     }
418 :     if (defined($Row->{"Source"}->[0])) {
419 :     $LoadingArray[2] = $Row->{"Source"}->[0];
420 :     }
421 :     if (defined($Row->{"Total genes"}->[0])) {
422 :     $LoadingArray[3] = $Row->{"Total genes"}->[0];
423 :     }
424 :     if (defined($Row->{"Gram positive genes"}->[0])) {
425 :     $LoadingArray[4] = $Row->{"Gram positive genes"}->[0];
426 :     }
427 :     if (defined($Row->{"Gram negative genes"}->[0])) {
428 :     $LoadingArray[5] = $Row->{"Gram negative genes"}->[0];
429 :     }
430 :     if (defined($Row->{"Class"}->[0])) {
431 :     $LoadingArray[6] = $Row->{"Class"}->[0];
432 :     }
433 :     if (defined($Row->{"Genes with functions"}->[0])) {
434 :     $LoadingArray[7] = $Row->{"Genes with functions"}->[0];
435 :     }
436 :     if (defined($Row->{"Genes with reactions"}->[0])) {
437 :     $LoadingArray[8] = $Row->{"Genes with reactions"}->[0];
438 :     }
439 :     if (defined($Row->{"Subsystem genes"}->[0])) {
440 :     $LoadingArray[9] = $Row->{"Subsystem genes"}->[0];
441 :     }
442 :     if (defined($Row->{"Subsystem genes with reactions"}->[0])) {
443 :     $LoadingArray[10] = $Row->{"Subsystem genes with reactions"}->[0];
444 :     }
445 :     if (defined($Row->{"Nonsubsystem genes"}->[0])) {
446 :     $LoadingArray[11] = $Row->{"Nonsubsystem genes"}->[0];
447 :     }
448 :     if (defined($Row->{"Nonsubsystem genes with reactions"}->[0])) {
449 :     $LoadingArray[12] = $Row->{"Nonsubsystem genes with reactions"}->[0];
450 :     }
451 :     if (defined($Row->{"Number of reactions"}->[0])) {
452 :     $LoadingArray[13] = $Row->{"Number of reactions"}->[0];
453 :     }
454 :     if (defined($Row->{"Transport reaction"}->[0])) {
455 :     $LoadingArray[14] = $Row->{"Transport reaction"}->[0];
456 :     }
457 :     if (defined($Row->{"Gap filling reactions"}->[0])) {
458 :     $LoadingArray[15] = $Row->{"Gap filling reactions"}->[0];
459 :     }
460 :     if (defined($Row->{"Gap filling time"}->[0])) {
461 :     $LoadingArray[16] = $Row->{"Gap filling time"}->[0];
462 :     }
463 :     if (defined($Row->{"Gap filling objective"}->[0])) {
464 :     $LoadingArray[17] = $Row->{"Gap filling objective"}->[0];
465 :     }
466 :     if (defined($Row->{"Gap filling minimal objective"}->[0])) {
467 :     $LoadingArray[18] = $Row->{"Gap filling minimal objective"}->[0];
468 :     }
469 :     if (defined($Row->{"Build date"}->[0])) {
470 :     $LoadingArray[19] = $Row->{"Build date"}->[0];
471 :     }
472 :     if (defined($Row->{"Gap fill date"}->[0])) {
473 :     $LoadingArray[20] = $Row->{"Gap fill date"}->[0];
474 :     }
475 :     if (defined($Row->{"Version"}->[0])) {
476 :     $LoadingArray[21] = $Row->{"Version"}->[0];
477 :     }
478 :     if (defined($Row->{"Gap fill version"}->[0])) {
479 :     $LoadingArray[22] = $Row->{"Gap fill version"}->[0];
480 :     }
481 :     if ($Row->{"Model ID"}->[0] =~ m/Core\d+\.\d+V\d+\.\d+/) {
482 :     $LoadingArray[25] = 1;
483 :     } elsif (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID"))) {
484 :     if (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"DIRECTORY"}->[0])) {
485 :     $LoadingArray[23] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"DIRECTORY"}->[0];
486 :     }
487 :     if (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"JOB ID"}->[0]) && $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"JOB ID"}->[0] ne "NONE") {
488 :     $LoadingArray[24] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"JOB ID"}->[0];
489 :     }
490 :     }
491 :     for my $j (3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,21,22,24,25) {
492 :     $LoadingArray[$j] = 0 if ($LoadingArray[$j] =~ /[a-z]/i);
493 : parrello 1.1 }
494 : parrello 1.2 $self->PutE(Model => $LoadingArray[0], organismName => $LoadingArray[1], source => $LoadingArray[2], totalGenes => $LoadingArray[3], gramPositiveGenes => $LoadingArray[4],gramNegativeGenes => $LoadingArray[5], class => $LoadingArray[6], genesWithFunction => $LoadingArray[7], genesWithReactions => $LoadingArray[8], subsystemGenes => $LoadingArray[9], subsystemGenesWithReactions => $LoadingArray[10], nonsubsystemGenes => $LoadingArray[11], nonsubsystemGenesWithReactions => $LoadingArray[12], numberOfReactions => $LoadingArray[13], numberOfTransporters => $LoadingArray[14], gapFillingReactions => $LoadingArray[15], gapFillingTime => $LoadingArray[16], gapFillingObjective => $LoadingArray[17], gapFillingMinimalObjective => $LoadingArray[18], buildDate => $LoadingArray[19], gapFillDate => $LoadingArray[20], version => $LoadingArray[21], gapFillVersion => $LoadingArray[22], directory => $LoadingArray[23], jobid => $LoadingArray[24], obsolete => $LoadingArray[25]);
495 :     #Adding the relationship between model and genome
496 :     if (defined($Row->{"Genome ID"}->[0])) {
497 :     $self->PutR(IsModeledBy => $Row->{"Genome ID"}->[0],$LoadingArray[0]);
498 : parrello 1.1 }
499 : parrello 1.2 #If the model is not obsolete, we add the relationships between model and reaction and featureset
500 :     if ($LoadingArray[25] == 0) {
501 :     #Loading the model from file
502 : parrello 1.8 my $ModelTable = $model->database()->GetDBModel($LoadingArray[0]);
503 : parrello 1.7 if (! defined $ModelTable) {
504 :     $self->Add(missingModelTable => 1);
505 :     } else {
506 :     for (my $j=0; $j < $ModelTable->size(); $j++) {
507 :     my $RxnRow = $ModelTable->get_row($j);
508 :     if (defined($RxnRow) && defined($RxnRow->{"LOAD"}->[0])) {
509 :     my @SubLoadingArray = ("R","c","NONE",10,"V","NONE","UNKNOWN");
510 :     if (defined($RxnRow->{"DIRECTIONALITY"}->[0])) {
511 :     my $code = $RxnRow->{"DIRECTIONALITY"}->[0];
512 :     if ($code eq '<=>') {
513 :     $SubLoadingArray[0] = 'R';
514 :     } elsif ($code eq '<=') {
515 :     $SubLoadingArray[0] = 'B';
516 :     } elsif ($code eq '=>') {
517 :     $SubLoadingArray[0] = 'F';
518 :     }
519 :     }
520 :     if (defined($RxnRow->{"COMPARTMENT"}->[0])) {
521 :     $SubLoadingArray[1] = $RxnRow->{"COMPARTMENT"}->[0];
522 :     }
523 :     if (defined($RxnRow->{"SUBSYSTEM"})) {
524 :     $SubLoadingArray[2] = join(";",@{$RxnRow->{"SUBSYSTEM"}});
525 :     }
526 :     if (defined($RxnRow->{"CONFIDENCE"}->[0])) {
527 :     $SubLoadingArray[3] = $RxnRow->{"CONFIDENCE"}->[0];
528 :     if ($SubLoadingArray[3] eq 'NONE') {
529 :     $SubLoadingArray[3] = 10;
530 :     }
531 : parrello 1.2 }
532 : parrello 1.7 if (defined($RxnRow->{"NOTES"})) {
533 :     $SubLoadingArray[5] = join(";",@{$RxnRow->{"NOTES"}});
534 : parrello 1.2 }
535 : parrello 1.7 if (defined($RxnRow->{"ASSOCIATED PEG"})) {
536 :     #Adding the role set entities
537 :     foreach my $FeatureSet (@{$RxnRow->{"ASSOCIATED PEG"}}) {
538 :     if ($FeatureSet =~ m/peg\.\d+/) {
539 :     my $DigestedKey = $sapling->DigestKey($FeatureSet);
540 :     $self->PutE(FeatureSet => $DigestedKey, source => "NONE");
541 :     #Adding the relationship between the reaction and roleset
542 :     $self->PutR(IsStimulatedBy => $RxnRow->{"LOAD"}->[0],$DigestedKey);
543 :     #Adding the relationship between the model and featureset
544 :     #$self->PutR(Encompasses => $LoadingArray[0],$DigestedKey);
545 :     #Adding the relationship between FeatureSet and feature
546 :     my @PegArray = split(/\+/,$FeatureSet);
547 :     foreach my $Feature (@PegArray) {
548 :     if ($Feature =~ m/(peg\.\d+)/) {
549 :     $self->PutR(IsSetOf => $DigestedKey,"fig|".$Row->{"Genome ID"}->[0].".".$1);
550 :     }
551 : parrello 1.2 }
552 : parrello 1.1 }
553 :     }
554 : parrello 1.7 $SubLoadingArray[6] = join(";",@{$RxnRow->{"ASSOCIATED PEG"}});
555 : parrello 1.1 }
556 : parrello 1.7 $self->PutR(IsRequiredBy => $RxnRow->{"LOAD"}->[0],$LoadingArray[0], direction => $SubLoadingArray[0], compartment => $SubLoadingArray[1], confidence => $SubLoadingArray[3], class => $SubLoadingArray[4], notes => $SubLoadingArray[5], dependency => $SubLoadingArray[6]);
557 : parrello 1.1 }
558 :     }
559 :     }
560 : parrello 1.2 #Clearing the model data from memmory
561 :     undef $ModelTable;
562 :     $model->ClearDBModel($LoadingArray[0],"DELETE");
563 : parrello 1.1 }
564 :     }
565 :     }
566 :     }
567 :     }
568 :    
569 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3