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

Annotation of /Sprout/ModelSaplingLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3