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

Diff of /Sprout/ModelSaplingLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Wed Mar 4 00:08:30 2009 UTC revision 1.11, Fri Jun 18 20:05:33 2010 UTC
# Line 41  Line 41 
41    
42  =item erdb  =item erdb
43    
44  [[SaplingPm]] object for the database being loaded.  L<Sapling> object for the database being loaded.
45    
46  =item options  =item options
47    
# Line 59  Line 59 
59      # Get the parameters.      # Get the parameters.
60      my ($class, $erdb, $options) = @_;      my ($class, $erdb, $options) = @_;
61      # Create the table list.      # 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);      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      # Create the BaseSaplingLoader object.      # Create the BaseSaplingLoader object.
68      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);
69      # Return it.      # Return it.
# Line 145  Line 149 
149      my ($self,$model) = @_;      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      #First getting the compound table which has a list of all compounds in the database as well as alot of compound information
152      my $CompoundTable = $model->GetDBTable("COMPOUNDS");      my $CompoundTable = $model->database()->GetDBTable("COMPOUNDS");
153    
154      #Adding the universal AliasType that will always exist      #Adding the universal AliasType that will always exist
155      $self->PutE(AliasType => "NAME", source => "NONE");      $self->PutE(AliasType => "NAME", source => "NONE");
# Line 159  Line 163 
163          if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/cpd\d\d\d\d\d/) {          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");              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,"");              my @LoadingArray = ($Row->{"DATABASE"}->[0],$Row->{"DATABASE"}->[0],0,"",0,"",0,10000000,10000000,"");
166                $self->Track(compoundRow => $LoadingArray[0], 1000);
167              if (defined($Row->{"NAME"}->[0])) {              if (defined($Row->{"NAME"}->[0])) {
168                  $LoadingArray[1] = $Row->{"NAME"}->[0];                  $LoadingArray[1] = $Row->{"NAME"}->[0];
169              }              }
# Line 229  Line 234 
234  sub LoadReactions {  sub LoadReactions {
235      my ($self,$model) = @_;      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      #First getting the reaction table which has a list of all reactions in the database as well as alot of reaction information
237      my $ReactionTable = $model->GetDBTable("REACTIONS");      my $ReactionTable = $model->database()->GetDBTable("REACTIONS");
238    
239      #Cycling through the compound list and adding each individual compound entity      #Cycling through the compound list and adding each individual compound entity
240      my $Count = 0;      my $Count = 0;
# Line 238  Line 243 
243          if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/rxn\d\d\d\d\d/) {          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");              my $Object = FIGMODELObject->load($model->{"reaction directory"}->[0].$Row->{"DATABASE"}->[0],"\t");
245              my @LoadingArray = ($Row->{"DATABASE"}->[0],"","","","","",10000000,10000000,10000000,"R");              my @LoadingArray = ($Row->{"DATABASE"}->[0],"","","","","",10000000,10000000,10000000,"R");
246                $self->Track(reactionRow => $LoadingArray[0], 1000);
247              if (defined($Object->{"DEFINITION"}->[0])) {              if (defined($Object->{"DEFINITION"}->[0])) {
248                  $LoadingArray[1] = $Object->{"DEFINITION"}->[0];                  $LoadingArray[1] = $Object->{"DEFINITION"}->[0];
249              }              }
# Line 276  Line 282 
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]);              $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              #Adding relationship between compounds and reactions
284              my ($Reactants,$Products) = $model->GetReactionSubstrateData($LoadingArray[0]);              my ($Reactants,$Products) = $model->GetReactionSubstrateData($LoadingArray[0]);
285                if (! defined $Reactants) {
286                    $self->Add(missingReactants => 1);
287                } else {
288              for (my $j=0; $j < @{$Reactants}; $j++) {              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);                  $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                  #TODO:Properly identify main reactants in reactions
291                  $Count++;                  $Count++;
292              }              }
293                }
294                if (! defined $Products) {
295                    $self->Add(missingProducts => 1);
296                } else {
297              for (my $j=0; $j < @{$Products}; $j++) {              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);                  $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                  #TODO:Properly identify main reactants in reactions
300                  $Count++;                  $Count++;
301              }              }
302                }
303              #Adding relationship between EC number and reactions              #Adding relationship between EC number and reactions
304              if (defined($Object->{"ENZYME"})) {              if (defined($Object->{"ENZYME"})) {
305                  foreach my $Enzyme (@{$Object->{"ENZYME"}}) {                  foreach my $Enzyme (@{$Object->{"ENZYME"}}) {
306                     $self->PutE(EcNumber => $Enzyme, obselete => 0, replacedby => "NONE");                     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");                     $self->PutR(IsCategorizedInto => $LoadingArray[0],$Enzyme,source => "KEGG");
312                  }                  }
313              }              }
314                }
315              #Adding the relationship between reaction and alias type              #Adding the relationship between reaction and alias type
316              if (defined($Object->{"NAME"})) {              if (defined($Object->{"NAME"})) {
317                  foreach my $Name (@{$Object->{"NAME"}}) {                  foreach my $Name (@{$Object->{"NAME"}}) {
# Line 322  Line 341 
341  sub LoadRoleSets {  sub LoadRoleSets {
342      my ($self,$model) = @_;      my ($self,$model) = @_;
343      my $sapling =$self->db();      my $sapling =$self->db();
344      my $RoleMappings = $model->GetDBTable("CURATED ROLE MAPPINGS");      my $RoleMappings = $model->database()->GetDBTable("CURATED ROLE MAPPINGS");
345      my $NewSet;      my $NewSet;
346      my $SetHash;      my $SetHash;
347      my $LastComplex = -1;      my $LastComplex = -1;
# Line 376  Line 395 
395          $self->PutE(RoleSet => $Digested, source => "NONE");          $self->PutE(RoleSet => $Digested, source => "NONE");
396          my @ReactionList = keys(%{$SetHash->{$RoleSet}->{"REACTIONS"}});          my @ReactionList = keys(%{$SetHash->{$RoleSet}->{"REACTIONS"}});
397          foreach my $Reaction (@ReactionList) {          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"}}));              $self->PutR(IsTriggeredBy => $Reaction,$Digested, source => "NONE",master => ($SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0] ? 1 : 0),subsystem => join(";",@{$SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}));
399          }          }
400          my @RoleList = keys(%{$SetHash->{$RoleSet}->{"ROLES"}});          my @RoleList = keys(%{$SetHash->{$RoleSet}->{"ROLES"}});
401          foreach my $Role (@RoleList) {          foreach my $Role (@RoleList) {
# Line 388  Line 407 
407  sub LoadModels {  sub LoadModels {
408      my ($self,$model) = @_;      my ($self,$model) = @_;
409      my $sapling = $self->db();      my $sapling = $self->db();
410      my $ModelList = $model->GetDBTable("MODEL LIST");      ## TRS: Get hash of valid genome IDs.
411      my $ModelStats = $model->GetDBTable("MODEL STATS");      my $genomeHash = $sapling->GenomeHash();
412      for (my $i=0; $i < $ModelStats->size(); $i++) {      my $ModelList = $model->database()->GetDBTable("MODELS");
413          my $Row = $ModelStats->get_row($i);      my $ModelStats = $model->database()->GetDBTable("MODEL STATS");
414        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          if (defined($Row) && defined($Row->{"Model ID"}->[0])) {          if (defined($Row) && defined($Row->{"Model ID"}->[0])) {
418              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);              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                if (defined($Row->{"Genome ID"}->[0]) && $genomeHash->{$Row->{"Genome ID"}->[0]}) {
420              if (defined($Row->{"Organism name"}->[0])) {              if (defined($Row->{"Organism name"}->[0])) {
421                  $LoadingArray[1] = $Row->{"Organism name"}->[0];                  $LoadingArray[1] = $Row->{"Organism name"}->[0];
422              }              }
# Line 449  Line 472 
472                  $LoadingArray[18] = $Row->{"Gap filling minimal objective"}->[0];                  $LoadingArray[18] = $Row->{"Gap filling minimal objective"}->[0];
473              }              }
474              if (defined($Row->{"Build date"}->[0])) {              if (defined($Row->{"Build date"}->[0])) {
475                  $LoadingArray[19] = $Row->{"Build date"}->[0];                      $LoadingArray[19] = FixDate($Row->{"Build date"}->[0]);
476              }              }
477              if (defined($Row->{"Gap fill date"}->[0])) {              if (defined($Row->{"Gap fill date"}->[0])) {
478                  $LoadingArray[20] = $Row->{"Gap fill date"}->[0];                      $LoadingArray[20] = FixDate($Row->{"Gap fill date"}->[0]);
479              }              }
480              if (defined($Row->{"Version"}->[0])) {              if (defined($Row->{"Version"}->[0])) {
481                  $LoadingArray[21] = $Row->{"Version"}->[0];                  $LoadingArray[21] = $Row->{"Version"}->[0];
# Line 460  Line 483 
483              if (defined($Row->{"Gap fill version"}->[0])) {              if (defined($Row->{"Gap fill version"}->[0])) {
484                  $LoadingArray[22] = $Row->{"Gap fill version"}->[0];                  $LoadingArray[22] = $Row->{"Gap fill version"}->[0];
485              }              }
486                    $LoadingArray[26] = $ListRow->{"owner"}->[0];
487                    $LoadingArray[27] = $ListRow->{"date"}->[0];
488                    $LoadingArray[28] = $ListRow->{"status"}->[0];
489                    $LoadingArray[29] = $ListRow->{"message"}->[0];
490              if ($Row->{"Model ID"}->[0] =~ m/Core\d+\.\d+V\d+\.\d+/) {              if ($Row->{"Model ID"}->[0] =~ m/Core\d+\.\d+V\d+\.\d+/) {
491                  $LoadingArray[25] = 1;                  $LoadingArray[25] = 1;
492              } elsif (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID"))) {              } elsif (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID"))) {
# Line 470  Line 497 
497                      $LoadingArray[24] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"JOB ID"}->[0];                      $LoadingArray[24] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"JOB ID"}->[0];
498                  }                  }
499              }              }
500              for my $j (3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,21,22,24,25) {                  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                  $LoadingArray[$j] = 0 if ($LoadingArray[$j] =~ /[a-z]/i);                  $LoadingArray[$j] = 0 if ($LoadingArray[$j] =~ /[a-z]/i);
502              }              }
503              $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]);                  $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              #Adding the relationship between model and genome              #Adding the relationship between model and genome
512              if (defined($Row->{"Genome ID"}->[0])) {              if (defined($Row->{"Genome ID"}->[0])) {
513                  $self->PutR(IsModeledBy => $Row->{"Genome ID"}->[0],$LoadingArray[0]);                  $self->PutR(IsModeledBy => $Row->{"Genome ID"}->[0],$LoadingArray[0]);
# Line 481  Line 515 
515              #If the model is not obsolete, we add the relationships between model and reaction and featureset              #If the model is not obsolete, we add the relationships between model and reaction and featureset
516              if ($LoadingArray[25] == 0) {              if ($LoadingArray[25] == 0) {
517                  #Loading the model from file                  #Loading the model from file
518                  my $ModelTable = $model->GetDBModel($LoadingArray[0]);                      my $ModelTable = $model->database()->GetDBModel($LoadingArray[0]);
519                        if (! defined $ModelTable) {
520                            $self->Add(missingModelTable => 1);
521                        } else {
522                  for (my $j=0; $j < $ModelTable->size(); $j++) {                  for (my $j=0; $j < $ModelTable->size(); $j++) {
523                      my $RxnRow = $ModelTable->get_row($j);                      my $RxnRow = $ModelTable->get_row($j);
524                      if (defined($RxnRow) && defined($RxnRow->{"LOAD"}->[0])) {                      if (defined($RxnRow) && defined($RxnRow->{"LOAD"}->[0])) {
# Line 520  Line 557 
557                                      #Adding the relationship between the reaction and roleset                                      #Adding the relationship between the reaction and roleset
558                                      $self->PutR(IsStimulatedBy => $RxnRow->{"LOAD"}->[0],$DigestedKey);                                      $self->PutR(IsStimulatedBy => $RxnRow->{"LOAD"}->[0],$DigestedKey);
559                                      #Adding the relationship between the model and featureset                                      #Adding the relationship between the model and featureset
560                                      $self->PutR(Encompasses => $LoadingArray[0],$DigestedKey);                                              #$self->PutR(Encompasses => $LoadingArray[0],$DigestedKey);
561                                      #Adding the relationship between FeatureSet and feature                                      #Adding the relationship between FeatureSet and feature
562                                      my @PegArray = split(/\+/,$FeatureSet);                                      my @PegArray = split(/\+/,$FeatureSet);
563                                      foreach my $Feature (@PegArray) {                                      foreach my $Feature (@PegArray) {
# Line 535  Line 572 
572                          $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]);                          $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                      }                      }
574                  }                  }
575                        }
576                  #Clearing the model data from memmory                  #Clearing the model data from memmory
577                  undef $ModelTable;                  undef $ModelTable;
578                  $model->ClearDBModel($LoadingArray[0],"DELETE");                      $model->database()->ClearDBModel($LoadingArray[0],"DELETE");
579                    }
580              }              }
581          }          }
582      }      }
583  }  }
584    
585    sub FixDate {
586        my ($date) = @_;
587        my $retVal = ($date eq 'NA' ? 0 : $date);
588        return $retVal;
589    }
590    
591  1;  1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.11

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3