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

Annotation of /Sprout/ModelSaplingLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (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 :     my @tables = sort qw(StructuralCue IsFoundIn Compound HasAliasOf AliasType HasReactionAliasOf Reaction Involves IsTriggeredBy RoleSet IsCombinationOf IsCategorizedInto EcNumber IsConsistentWith IsStimulatedBy FeatureSet IsSetOf IsRequiredBy Model Encompasses IsModeledBy);
63 :     # 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 :     my $CompoundTable = $model->GetDBTable("COMPOUNDS");
149 :    
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 :     my $ReactionTable = $model->GetDBTable("REACTIONS");
234 :    
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.5 $self->PutE(EcNumber => $Enzyme, obsolete => 0, replacedby => "NONE");
303 : parrello 1.1 $self->PutR(IsCategorizedInto => $LoadingArray[0],$Enzyme,source => "KEGG");
304 :     }
305 :     }
306 :     #Adding the relationship between reaction and alias type
307 :     if (defined($Object->{"NAME"})) {
308 :     foreach my $Name (@{$Object->{"NAME"}}) {
309 :     $self->PutR(HasReactionAliasOf => $LoadingArray[0],"NAME",alias => $Name);
310 :     }
311 :     }
312 :     if (defined($Object->{"DBLINKS"})) {
313 :     foreach my $Link (@{$Object->{"DBLINKS"}}) {
314 :     my @TempArray = split(/:/,$Link);
315 :     if (@TempArray >= 2) {
316 :     if ($TempArray[0] ne "KEGG" && $TempArray[0] ne "ARGONNE") {
317 :     $self->PutE(AliasType => $TempArray[0], source => "PUBLISHED MODEL");
318 :     }
319 :     if ($TempArray[0] eq "ARGONNE") {
320 :     splice(@TempArray,1,1);
321 :     }
322 :     for (my $j=1; $j < @TempArray; $j++) {
323 :     $self->PutR(HasReactionAliasOf => $LoadingArray[0],$TempArray[0],alias => $TempArray[$j]);
324 :     }
325 :     }
326 :     }
327 :     }
328 :     }
329 :     }
330 :     }
331 :    
332 :     sub LoadRoleSets {
333 :     my ($self,$model) = @_;
334 :     my $sapling =$self->db();
335 :     my $RoleMappings = $model->GetDBTable("CURATED ROLE MAPPINGS");
336 :     my $NewSet;
337 :     my $SetHash;
338 :     my $LastComplex = -1;
339 :     my $LastReaction = "";
340 :     my $LastRole = "";
341 :     for (my $i=0; $i < $RoleMappings->size(); $i++) {
342 :     my $Row = $RoleMappings->get_row($i);
343 :     if (defined($Row) && defined($Row->{"REACTION"}->[0]) && defined($Row->{"ROLE"}->[0]) && defined($Row->{"COMPLEX"}->[0]) && defined($Row->{"MASTER"}->[0])) {
344 :     if ($Row->{"REACTION"}->[0] ne $LastReaction || $LastComplex ne $Row->{"COMPLEX"}->[0]) {
345 :     if (defined($NewSet->{"ROLES"}) && defined($NewSet->{"REACTIONS"})) {
346 :     my @RoleList = sort(keys(%{$NewSet->{"ROLES"}}));
347 :     my @ReactionList = keys(%{$NewSet->{"REACTIONS"}});
348 :     foreach my $Reaction (@ReactionList) {
349 :     $SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0] = $NewSet->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0];
350 :     if (defined($NewSet->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"})) {
351 :     foreach my $Subsystem (@{$NewSet->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}) {
352 :     if (defined($SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"})) {
353 :     foreach my $OtherSubsystem (@{$SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}) {
354 :     if ($Subsystem eq $OtherSubsystem) {
355 :     $Subsystem = "";
356 :     last;
357 :     }
358 :     }
359 :     }
360 :     if ($Subsystem ne "") {
361 :     push(@{$SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}},$Subsystem);
362 :     }
363 :     }
364 :     }
365 :     }
366 :     foreach my $Role (@RoleList) {
367 :     $SetHash->{join("+",@RoleList)}->{"ROLES"}->{$Role} = 1;
368 :     }
369 :     }
370 :     $NewSet = {};
371 :     }
372 :     $NewSet->{"ROLES"}->{$Row->{"ROLE"}->[0]} = 1;
373 :     $NewSet->{"REACTIONS"}->{$Row->{"REACTION"}->[0]}->{"MASTER"}->[0] = $Row->{"MASTER"}->[0];
374 :     if (defined($Row->{"SUBSYSTEM"}->[0])) {
375 :     push(@{$NewSet->{"REACTIONS"}->{$Row->{"REACTION"}->[0]}->{"SUBSYSTEMS"}},$Row->{"SUBSYSTEM"}->[0]);
376 :     }
377 :     $LastRole = $Row->{"ROLE"}->[0];
378 :     $LastReaction = $Row->{"REACTION"}->[0];
379 :     $LastComplex = $Row->{"COMPLEX"}->[0];
380 :     }
381 :     }
382 :    
383 :     my @RoleSets = keys(%{$SetHash});
384 :     foreach my $RoleSet (@RoleSets) {
385 :     my $Digested = $sapling->DigestKey($RoleSet);
386 :     $self->PutE(RoleSet => $Digested, source => "NONE");
387 :     my @ReactionList = keys(%{$SetHash->{$RoleSet}->{"REACTIONS"}});
388 :     foreach my $Reaction (@ReactionList) {
389 :     $self->PutR(IsTriggeredBy => $Reaction,$Digested, source => "NONE",master => $SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0],subsystem => join(";",@{$SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}));
390 :     }
391 :     my @RoleList = keys(%{$SetHash->{$RoleSet}->{"ROLES"}});
392 :     foreach my $Role (@RoleList) {
393 :     $self->PutR(IsCombinationOf => $Digested,$Role, local => 0);
394 :     }
395 :     }
396 :     }
397 :    
398 :     sub LoadModels {
399 :     my ($self,$model) = @_;
400 :     my $sapling = $self->db();
401 : parrello 1.2 ## TRS: Get hash of valid genome IDs.
402 :     my $genomeHash = $sapling->GenomeHash();
403 : parrello 1.1 my $ModelList = $model->GetDBTable("MODEL LIST");
404 :     my $ModelStats = $model->GetDBTable("MODEL STATS");
405 :     for (my $i=0; $i < $ModelStats->size(); $i++) {
406 :     my $Row = $ModelStats->get_row($i);
407 :     if (defined($Row) && defined($Row->{"Model ID"}->[0])) {
408 :     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);
409 : parrello 1.2 if (defined($Row->{"Genome ID"}->[0]) && $genomeHash->{$Row->{"Genome ID"}->[0]}) {
410 :     if (defined($Row->{"Organism name"}->[0])) {
411 :     $LoadingArray[1] = $Row->{"Organism name"}->[0];
412 :     }
413 :     if (defined($Row->{"Source"}->[0])) {
414 :     $LoadingArray[2] = $Row->{"Source"}->[0];
415 :     }
416 :     if (defined($Row->{"Total genes"}->[0])) {
417 :     $LoadingArray[3] = $Row->{"Total genes"}->[0];
418 :     }
419 :     if (defined($Row->{"Gram positive genes"}->[0])) {
420 :     $LoadingArray[4] = $Row->{"Gram positive genes"}->[0];
421 :     }
422 :     if (defined($Row->{"Gram negative genes"}->[0])) {
423 :     $LoadingArray[5] = $Row->{"Gram negative genes"}->[0];
424 :     }
425 :     if (defined($Row->{"Class"}->[0])) {
426 :     $LoadingArray[6] = $Row->{"Class"}->[0];
427 :     }
428 :     if (defined($Row->{"Genes with functions"}->[0])) {
429 :     $LoadingArray[7] = $Row->{"Genes with functions"}->[0];
430 :     }
431 :     if (defined($Row->{"Genes with reactions"}->[0])) {
432 :     $LoadingArray[8] = $Row->{"Genes with reactions"}->[0];
433 :     }
434 :     if (defined($Row->{"Subsystem genes"}->[0])) {
435 :     $LoadingArray[9] = $Row->{"Subsystem genes"}->[0];
436 :     }
437 :     if (defined($Row->{"Subsystem genes with reactions"}->[0])) {
438 :     $LoadingArray[10] = $Row->{"Subsystem genes with reactions"}->[0];
439 :     }
440 :     if (defined($Row->{"Nonsubsystem genes"}->[0])) {
441 :     $LoadingArray[11] = $Row->{"Nonsubsystem genes"}->[0];
442 :     }
443 :     if (defined($Row->{"Nonsubsystem genes with reactions"}->[0])) {
444 :     $LoadingArray[12] = $Row->{"Nonsubsystem genes with reactions"}->[0];
445 :     }
446 :     if (defined($Row->{"Number of reactions"}->[0])) {
447 :     $LoadingArray[13] = $Row->{"Number of reactions"}->[0];
448 :     }
449 :     if (defined($Row->{"Transport reaction"}->[0])) {
450 :     $LoadingArray[14] = $Row->{"Transport reaction"}->[0];
451 :     }
452 :     if (defined($Row->{"Gap filling reactions"}->[0])) {
453 :     $LoadingArray[15] = $Row->{"Gap filling reactions"}->[0];
454 :     }
455 :     if (defined($Row->{"Gap filling time"}->[0])) {
456 :     $LoadingArray[16] = $Row->{"Gap filling time"}->[0];
457 :     }
458 :     if (defined($Row->{"Gap filling objective"}->[0])) {
459 :     $LoadingArray[17] = $Row->{"Gap filling objective"}->[0];
460 :     }
461 :     if (defined($Row->{"Gap filling minimal objective"}->[0])) {
462 :     $LoadingArray[18] = $Row->{"Gap filling minimal objective"}->[0];
463 :     }
464 :     if (defined($Row->{"Build date"}->[0])) {
465 :     $LoadingArray[19] = $Row->{"Build date"}->[0];
466 :     }
467 :     if (defined($Row->{"Gap fill date"}->[0])) {
468 :     $LoadingArray[20] = $Row->{"Gap fill date"}->[0];
469 :     }
470 :     if (defined($Row->{"Version"}->[0])) {
471 :     $LoadingArray[21] = $Row->{"Version"}->[0];
472 :     }
473 :     if (defined($Row->{"Gap fill version"}->[0])) {
474 :     $LoadingArray[22] = $Row->{"Gap fill version"}->[0];
475 :     }
476 :     if ($Row->{"Model ID"}->[0] =~ m/Core\d+\.\d+V\d+\.\d+/) {
477 :     $LoadingArray[25] = 1;
478 :     } elsif (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID"))) {
479 :     if (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"DIRECTORY"}->[0])) {
480 :     $LoadingArray[23] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"DIRECTORY"}->[0];
481 :     }
482 :     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") {
483 :     $LoadingArray[24] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"JOB ID"}->[0];
484 :     }
485 :     }
486 :     for my $j (3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,21,22,24,25) {
487 :     $LoadingArray[$j] = 0 if ($LoadingArray[$j] =~ /[a-z]/i);
488 : parrello 1.1 }
489 : 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]);
490 :     #Adding the relationship between model and genome
491 :     if (defined($Row->{"Genome ID"}->[0])) {
492 :     $self->PutR(IsModeledBy => $Row->{"Genome ID"}->[0],$LoadingArray[0]);
493 : parrello 1.1 }
494 : parrello 1.2 #If the model is not obsolete, we add the relationships between model and reaction and featureset
495 :     if ($LoadingArray[25] == 0) {
496 :     #Loading the model from file
497 :     my $ModelTable = $model->GetDBModel($LoadingArray[0]);
498 :     for (my $j=0; $j < $ModelTable->size(); $j++) {
499 :     my $RxnRow = $ModelTable->get_row($j);
500 :     if (defined($RxnRow) && defined($RxnRow->{"LOAD"}->[0])) {
501 :     my @SubLoadingArray = ("R","c","NONE",10,"V","NONE","UNKNOWN");
502 :     if (defined($RxnRow->{"DIRECTIONALITY"}->[0])) {
503 :     my $code = $RxnRow->{"DIRECTIONALITY"}->[0];
504 :     if ($code eq '<=>') {
505 :     $SubLoadingArray[0] = 'R';
506 :     } elsif ($code eq '<=') {
507 :     $SubLoadingArray[0] = 'B';
508 :     } elsif ($code eq '=>') {
509 :     $SubLoadingArray[0] = 'F';
510 :     }
511 :     }
512 :     if (defined($RxnRow->{"COMPARTMENT"}->[0])) {
513 :     $SubLoadingArray[1] = $RxnRow->{"COMPARTMENT"}->[0];
514 :     }
515 :     if (defined($RxnRow->{"SUBSYSTEM"})) {
516 :     $SubLoadingArray[2] = join(";",@{$RxnRow->{"SUBSYSTEM"}});
517 :     }
518 :     if (defined($RxnRow->{"CONFIDENCE"}->[0])) {
519 :     $SubLoadingArray[3] = $RxnRow->{"CONFIDENCE"}->[0];
520 :     if ($SubLoadingArray[3] eq 'NONE') {
521 :     $SubLoadingArray[3] = 10;
522 :     }
523 : parrello 1.1 }
524 : parrello 1.2 if (defined($RxnRow->{"NOTES"})) {
525 :     $SubLoadingArray[5] = join(";",@{$RxnRow->{"NOTES"}});
526 : parrello 1.1 }
527 : parrello 1.2 if (defined($RxnRow->{"ASSOCIATED PEG"})) {
528 :     #Adding the role set entities
529 :     foreach my $FeatureSet (@{$RxnRow->{"ASSOCIATED PEG"}}) {
530 :     if ($FeatureSet =~ m/peg\.\d+/) {
531 :     my $DigestedKey = $sapling->DigestKey($FeatureSet);
532 :     $self->PutE(FeatureSet => $DigestedKey, source => "NONE");
533 :     #Adding the relationship between the reaction and roleset
534 :     $self->PutR(IsStimulatedBy => $RxnRow->{"LOAD"}->[0],$DigestedKey);
535 :     #Adding the relationship between the model and featureset
536 :     $self->PutR(Encompasses => $LoadingArray[0],$DigestedKey);
537 :     #Adding the relationship between FeatureSet and feature
538 :     my @PegArray = split(/\+/,$FeatureSet);
539 :     foreach my $Feature (@PegArray) {
540 :     if ($Feature =~ m/(peg\.\d+)/) {
541 :     $self->PutR(IsSetOf => $DigestedKey,"fig|".$Row->{"Genome ID"}->[0].".".$1);
542 :     }
543 : parrello 1.1 }
544 :     }
545 :     }
546 : parrello 1.2 $SubLoadingArray[6] = join(";",@{$RxnRow->{"ASSOCIATED PEG"}});
547 : parrello 1.1 }
548 : parrello 1.2 $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]);
549 : parrello 1.1 }
550 :     }
551 : parrello 1.2 #Clearing the model data from memmory
552 :     undef $ModelTable;
553 :     $model->ClearDBModel($LoadingArray[0],"DELETE");
554 : parrello 1.1 }
555 :     }
556 :     }
557 :     }
558 :     }
559 :    
560 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3