[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.19, Sat Oct 1 10:35:02 2011 UTC
# Line 16  Line 16 
16  # Genomes at veronika@thefig.info or download a copy from  # Genomes at veronika@thefig.info or download a copy from
17  # http://www.theseed.org/LICENSE.TXT.  # http://www.theseed.org/LICENSE.TXT.
18  #  #
19  use FIGMODEL;  #use FIGMODEL;
20    
21  package ModelSaplingLoader;  package ModelSaplingLoader;
22      use strict;      use strict;
23      use Tracer;      use Tracer;
24      use ERDB;      use ERDB;
     use HTTP::Date;  
25      use base 'BaseSaplingLoader';      use base 'BaseSaplingLoader';
26    
27  =head1 Sapling ModelLoader Load Group Class  =head1 Sapling Model Load Group Class
28    
29  =head2 Introduction  =head2 Introduction
30    
31  The ModelLoader Load Group includes all of the major mdl tables.  The Model Load Group includes a small set of tables that describe reactions and compounds
32    and how they relate to the models in the main model database.
33    
34  =head3 new  =head3 new
35    
36      my $sl = ModelLoaderSaplingLoader->new($erdb, $options, @tables);      my $sl = ModelSaplingLoader->new($erdb, $options, @tables);
37    
38  Construct a new ModelLoaderSaplingLoader object.  Construct a new ModelSaplingLoader object.
39    
40  =over 4  =over 4
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 = qw(Compound Reaction EcNumber Model Media IsTriggeredBy
63                        IsCategorizedInto IsConsistentWith IsModeledBy Involves
64                        IsRequiredBy Complex IsSetOf IsExemplarOf);
65      # Create the BaseSaplingLoader object.      # Create the BaseSaplingLoader object.
66      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);
67        # Create the reaction tracking hash.
68        $retVal->{reactions} = {};
69      # Return it.      # Return it.
70      return $retVal;      return $retVal;
71  }  }
# Line 72  Line 76 
76    
77      $sl->Generate();      $sl->Generate();
78    
79  Generate the data for the mdl files.  Generate the data for the model files.
80    
81  =cut  =cut
82    
# Line 81  Line 85 
85      my ($self) = @_;      my ($self) = @_;
86      # Get the database object.      # Get the database object.
87      my $erdb = $self->db();      my $erdb = $self->db();
     # Get the source object.  
     my $fig = $self->source();  
88      # Is this the global section?      # Is this the global section?
     my $model = new FIGMODEL;  
89      if ($self->global()) {      if ($self->global()) {
90          #Loading the model entities and relationships          # Load the tables from the model dump files.
91          $self->LoadModels($model);          $self->LoadModelFiles();
         #Loading structural cues first  
         $self->LoadStructuralCues($model);  
         #Loading the compound entities and relationships  
         $self->LoadCompounds($model);  
         #Loading the reaction, and EC number entities and relationships  
         $self->LoadReactions($model);  
         #Loading the role set entity and relationships  
         $self->LoadRoleSets($model);  
92      } else {      } else {
93          # Get the section ID.          # Get the section ID.
94          my $genomeID = $self->section();          my $genomeID = $self->section();
# Line 103  Line 96 
96      }      }
97  }  }
98    
99  #This function loads all of the StructuralCue entities  =head3 LoadModelFiles
 sub LoadStructuralCues {  
     my ($self,$model) = @_;  
100    
101      #Getting the list of structural cue filenames      $sl->LoadModelFiles();
     my @CuesList = glob($model->{"Reaction database directory"}->[0]."cues/");  
     my %CuePriorities;  
     #TODO:NEED TO POPULATE THE PRIORITIES HASH  
     foreach my $CueFile (@CuesList) {  
         my $Object = FIGMODELObject->load($CueFile,"\t");  
         if (defined($Object) && defined($Object->{"NAME"}->[0])) {  
             my @LoadingArray = ($Object->{"NAME"}->[0],-1,0,0,"","","","");  
             if (defined($CuePriorities{$Object->{"NAME"}->[0]})) {  
                 $LoadingArray[1] = $CuePriorities{$Object->{"NAME"}->[0]};  
             }  
             if (defined($Object->{"SMALL_MOLECULE"}->[0])) {  
                 $LoadingArray[2] = $Object->{"SMALL_MOLECULE"}->[0];  
             }  
             if (defined($Object->{"CHARGE"}->[0])) {  
                 $LoadingArray[3] = $Object->{"CHARGE"}->[0];  
             }  
             if (defined($Object->{"FORMULA"}->[0])) {  
                 $LoadingArray[4] = $Object->{"FORMULA"}->[0];  
             }  
             if (defined($Object->{"ENERGY"}->[0])) {  
                 $LoadingArray[5] = $Object->{"ENERGY"}->[0];  
             }  
             if (defined($Object->{"ERROR"}->[0])) {  
                 $LoadingArray[6] = $Object->{"ERROR"}->[0];  
             }  
             if (defined($Object->{"STRUCTURAL_CUES"}->[0])) {  
                 $LoadingArray[7] = join(";",@{$Object->{"STRUCTURAL_CUES"}});  
             }  
             $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]);  
         }  
     }  
 }  
102    
103  sub LoadCompounds {  Load the data from the six model dump files.
     my ($self,$model) = @_;  
104    
105      #First getting the compound table which has a list of all compounds in the database as well as alot of compound information  =cut
     my $CompoundTable = $model->GetDBTable("COMPOUNDS");  
106    
107      #Adding the universal AliasType that will always exist  # hash of ubiquitous compounds.
108      $self->PutE(AliasType => "NAME", source => "NONE");  use constant UBIQUITOUS => {
109      $self->PutE(AliasType => "SEARCHNAME", source => "NONE");      cpd00001 => 'OH-',
110      $self->PutE(AliasType => "KEGG", source => "http://www.kegg.com/");      cpd00002 => 'ATP',
111      $self->PutE(AliasType => "ARGONNE", source => "OBSOLETE IDs");      cpd00003 => 'Nicotinamideadeninedinucleotide',
112        cpd00004 => 'Nicotinamideadeninedinucleotide-reduced',
113        cpd00005 => 'Nicotinamideadeninedinucleotidephosphate-reduced',
114        cpd00006 => 'Nicotinamideadeninedinucleotidephosphate',
115        cpd00007 => 'Oxygen',
116        cpd00008 => 'ADP',
117        cpd00009 => 'Orthophosphoric acid',
118        cpd00010 => 'CoenzymeA',
119        cpd00011 => 'Carbon dioxide',
120        cpd00012 => 'PPi',
121        cpd00018 => 'AMP',
122        cpd00020 => 'Pyruvic Acid',
123        cpd00022 => 'Acetyl-CoA',
124        cpd00025 => 'Hydrogen peroxide',
125        cpd00067 => 'H+',
126        cpd00971 => 'Sodium',
127        cpd15352 => '2-Demethylmenaquinone',
128        cpd15353 => '2-Demethylmenaquinol',
129        cpd15499 => 'Menaquinol',
130        cpd15500 => 'Menaquinone',
131        cpd15560 => 'Ubiquinone-8',
132        cpd15561 => 'Ubiquinol-8',
133    };
134    
135      #Cycling through the compound list and adding each individual compound entity  sub LoadModelFiles {
136      for (my $i=0; $i < $CompoundTable->size(); $i++) {      # Get the parameters.
137          my $Row = $CompoundTable->get_row($i);      my ($self) = @_;
138          if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/cpd\d\d\d\d\d/) {      # Get the sapling database.
139              my $Object = FIGMODELObject->load($model->{"compound directory"}->[0].$Row->{"DATABASE"}->[0],"\t");      my $erdb = $self->db();
140              my @LoadingArray = ($Row->{"DATABASE"}->[0],$Row->{"DATABASE"}->[0],0,"",0,"",0,10000000,10000000,"");      # Get the model dump file directory.
141              if (defined($Row->{"NAME"}->[0])) {      my $dir = $erdb->LoadDirectory() . "/models";
142                  $LoadingArray[1] = $Row->{"NAME"}->[0];      # First we read the compounds.
143              }      my $ih = $self->CheckFile("$dir/CompoundName.txt", qw(CompoundID Name));
144              if (defined($Object->{"MASS"}->[0])) {      while (! eof $ih) {
145                  $LoadingArray[2] = $Object->{"MASS"}->[0];          # Get the next compound.
146              }          my ($id, $label) = $self->ReadLine($ih);
147              if (defined($Object->{"FORMULA"}->[0])) {          # Create a compound record for it.
148                  $LoadingArray[3] = $Object->{"FORMULA"}->[0];          $self->PutE(Compound => $id, label => $label, ubiquitous => (UBIQUITOUS->{$id} ? 1 : 0));
149              }      }
150              if (defined($Object->{"CHARGE"}->[0])) {      # Next, the compound-reactions relationship. We create the reactions here, too.
151                  $LoadingArray[4] = $Object->{"CHARGE"}->[0];      $ih = $self->CheckFile("$dir/CompoundReaction.txt", qw(CompoundID ReactionID
152              }                             Stoichiometry Cofactor));
153              if (defined($Object->{"CHARGE"}->[0]) && defined($Object->{"FORMULA"}->[0])) {      while (! eof $ih) {
154                  $LoadingArray[5] = FIGMODEL::ConvertToNeutralFormula($Object->{"FORMULA"}->[0],$Object->{"CHARGE"}->[0]);          # Get the next link.
155              }          my ($compound, $reaction, $stoich, $cofactor) = $self->ReadLine($ih);
156              if (-e $model->{"Argonne molfile directory"}->[0].$Row->{"DATABASE"}->[0].".mol" || -e $model->{"Argonne molfile directory"}->[0]."pH7/".$Row->{"DATABASE"}->[0].".mol") {          # Insure the reaction exists.
157                  $LoadingArray[6] = 1;          $self->CreateReaction($reaction);
158              }          # Check for product or substrate.
159              if (defined($Object->{"DELTAG"}->[0])) {          my $product;
160                  $LoadingArray[7] = $Object->{"DELTAG"}->[0];          if ($stoich < 0) {
161              }              $product = 0;
162              if (defined($Object->{"DELTAGERR"}->[0])) {              $stoich = -$stoich;
163                  $LoadingArray[8] = $Object->{"DELTAGERR"}->[0];          } else {
164              }              $product = 1;
             if (defined($Row->{"STRINGCODE"}->[0])) {  
                 $LoadingArray[9] = $Row->{"STRINGCODE"}->[0];  
             }  
             $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]);  
             #Adding the relationship between compound and structural cue  
             if (defined($Object->{"STRUCTURAL_CUES"})) {  
                 foreach my $Cue (@{$Object->{"STRUCTURAL_CUES"}}) {  
                     my @TempArray = split(/:/,$Cue);  
                     if (@TempArray == 2) {  
                         $self->PutR(IsFoundIn => $TempArray[0],$LoadingArray[0],count => $TempArray[1]);  
                     }  
                 }  
             }  
             #Adding the relationship between compound and alias type  
             if (defined($Object->{"NAME"})) {  
                 foreach my $Name (@{$Object->{"NAME"}}) {  
                     $self->PutR(HasAliasOf => $LoadingArray[0],"NAME",alias => $Name);  
                     my @SearchNames = FIGMODEL::ConvertToSearchNames($Name);  
                     foreach my $SearchName (@SearchNames) {  
                         $self->PutR(HasAliasOf => $LoadingArray[0],"SEARCHNAME",alias => $SearchName);  
                     }  
                 }  
             }  
             if (defined($Object->{"DBLINKS"})) {  
                 foreach my $Link (@{$Object->{"DBLINKS"}}) {  
                     my @TempArray = split(/:/,$Link);  
                     if (@TempArray >= 2) {  
                         if ($TempArray[0] ne "KEGG" && $TempArray[0] ne "ARGONNE") {  
                             $self->PutE(AliasType => $TempArray[0], source => "PUBLISHED MODEL");  
                         }  
                         if ($TempArray[0] eq "ARGONNE") {  
                             splice(@TempArray,1,1);  
                         }  
                         for (my $j=1; $j < @TempArray; $j++) {  
                             $self->PutR(HasAliasOf => $LoadingArray[0],$TempArray[0],alias => $TempArray[$j]);  
                         }  
                     }  
                 }  
             }  
         }  
     }  
165  }  }
166            # Connect the reaction to the compound.
167            $self->PutR(Involves => $reaction, $compound, product => $product,
168                        stoichiometry => $stoich, cofactor => $cofactor);
169        }
170        # Now we connect the reactions to roles.
171        $ih = $self->CheckFile("$dir/ReactionRole.txt", qw(ReactionID Role));
172        while (! eof $ih) {
173            # Get the next reaction/role pair. We don't need to create roles here because
174            # they are built in the Feature module.
175            my ($reaction, $role) = $self->ReadLine($ih);
176            # Insure the reaction exists.
177            $self->CreateReaction($reaction);
178            # Connect the reaction to the role.
179            $self->PutR(IsTriggeredBy => $reaction, $role);
180        }
181        # Now we create the models.
182        $ih = $self->CheckFile("$dir/ModelGenome.txt", qw(ModelID Name GenomeID));
183        while (! eof $ih) {
184            # Get the next model.
185            my ($model, $name, $genome) = $self->ReadLine($ih);
186            # Create the model.
187            $self->PutE(Model => $model);
188            # Connect it to the genome. Again, the genomes are created elsewhere.
189            $self->PutR(IsModeledBy => $genome, $model);
190        }
191        # Next we connect the reactions to models.
192        $ih = $self->CheckFile("$dir/ModelReaction.txt", qw(ModelID ReactionID));
193        while (! eof $ih) {
194            # Get the next line.
195            my ($model, $reaction) = $self->ReadLine($ih);
196            # Only proceed if a reaction is present.
197            if ($reaction) {
198                # Insure the reaction exists.
199                $self->CreateReaction($reaction);
200                # Connect the reaction to the model.
201                $self->PutR(IsRequiredBy => $reaction, $model);
202            }
203        }
204        # Finally, the exemplars are stored in the coupling directory.
205        my $couplingDir = $erdb->LoadDirectory() . '/FamilyData';
206        $self->LoadFromFile(IsExemplarOf => "$couplingDir/IsExemplarOf.dtx",
207                            qw(from_link to_link));
208    }
209    
210    =head3 CheckFile
211    
212        my $ih = $sl->CheckFile($fileName, @fieldNames);
213    
214    Read the header record of the specified file and verify that the field names match
215    the names in the input list. If they do not, an error will be thrown; if they do, an
216    open file handle will be returned, positioned on the first data record.
217    
218  sub LoadReactions {  =over 4
     my ($self,$model) = @_;  
     #First getting the reaction table which has a list of all reactions in the database as well as alot of reaction information  
     my $ReactionTable = $model->GetDBTable("REACTIONS");  
219    
220      #Cycling through the compound list and adding each individual compound entity  =item fileName
     my $Count = 0;  
     for (my $i=0; $i < $ReactionTable->size(); $i++) {  
         my $Row = $ReactionTable->get_row($i);  
         if (defined($Row) && defined($Row->{"DATABASE"}->[0]) && $Row->{"DATABASE"}->[0] =~ m/rxn\d\d\d\d\d/) {  
             my $Object = FIGMODELObject->load($model->{"reaction directory"}->[0].$Row->{"DATABASE"}->[0],"\t");  
             my @LoadingArray = ($Row->{"DATABASE"}->[0],"","","","","",10000000,10000000,10000000,"R");  
             if (defined($Object->{"DEFINITION"}->[0])) {  
                 $LoadingArray[1] = $Object->{"DEFINITION"}->[0];  
             }  
             if (defined($Object->{"EQUATION"}->[0])) {  
                 my ($Direction,$Equation,$ReverseEquation,$FullEquation,$EquationCompartment,$Error) = $model->ConvertEquationToCode($Object->{"EQUATION"}->[0],{"Test" => "Test"});  
                 $LoadingArray[2] = $Equation;  
             }  
             if (defined($Object->{"OPERATOR"}->[0])) {  
                 $LoadingArray[3] = $Object->{"OPERATOR"}->[0];  
             }  
             if (defined($Object->{"PATHWAY"}->[0])) {  
                 $LoadingArray[4] = join(";",@{$Object->{"PATHWAY"}});  
             }  
             if (defined($Row->{"KEGG MAPS"}->[0])) {  
                 $LoadingArray[5] = join(";",@{$Row->{"KEGG MAPS"}});  
             }  
             if (defined($Object->{"DELTAG"}->[0])) {  
                 $LoadingArray[6] = $Object->{"DELTAG"}->[0];  
             }  
             if (defined($Object->{"MMDELTAG"}->[0])) {  
                 $LoadingArray[7] = $Object->{"MMDELTAG"}->[0];  
             }  
             if (defined($Object->{"DELTAGERR"}->[0])) {  
                 $LoadingArray[8] = $Object->{"DELTAGERR"}->[0];  
             }  
             if (defined($Object->{"THERMODYNAMIC REVERSIBILITY"}->[0])) {  
                 my $code = $Object->{"THERMODYNAMIC REVERSIBILITY"}->[0];  
                 if ($code eq '<=>') {  
                     $LoadingArray[9] = "R";  
                 } elsif ($code eq '<=') {  
                     $LoadingArray[9] = "B";  
                 } elsif ($code eq '=>') {  
                     $LoadingArray[9] = "F";  
                 }  
             }  
             $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]);  
             #Adding relationship between compounds and reactions  
             my ($Reactants,$Products) = $model->GetReactionSubstrateData($LoadingArray[0]);  
             for (my $j=0; $j < @{$Reactants}; $j++) {  
                 $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);  
                 #TODO:Properly identify main reactants in reactions  
                 $Count++;  
             }  
             for (my $j=0; $j < @{$Products}; $j++) {  
                 $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);  
                 #TODO:Properly identify main reactants in reactions  
                 $Count++;  
             }  
             #Adding relationship between EC number and reactions  
             if (defined($Object->{"ENZYME"})) {  
                 foreach my $Enzyme (@{$Object->{"ENZYME"}}) {  
                    $self->PutE(EcNumber => $Enzyme, obselete => 0, replacedby => "NONE");  
                    $self->PutR(IsCategorizedInto => $LoadingArray[0],$Enzyme,source => "KEGG");  
                 }  
             }  
             #Adding the relationship between reaction and alias type  
             if (defined($Object->{"NAME"})) {  
                 foreach my $Name (@{$Object->{"NAME"}}) {  
                     $self->PutR(HasReactionAliasOf => $LoadingArray[0],"NAME",alias => $Name);  
                 }  
             }  
             if (defined($Object->{"DBLINKS"})) {  
                 foreach my $Link (@{$Object->{"DBLINKS"}}) {  
                     my @TempArray = split(/:/,$Link);  
                     if (@TempArray >= 2) {  
                         if ($TempArray[0] ne "KEGG" && $TempArray[0] ne "ARGONNE") {  
                             $self->PutE(AliasType => $TempArray[0], source => "PUBLISHED MODEL");  
                         }  
                         if ($TempArray[0] eq "ARGONNE") {  
                             splice(@TempArray,1,1);  
                         }  
                         for (my $j=1; $j < @TempArray; $j++) {  
                             $self->PutR(HasReactionAliasOf => $LoadingArray[0],$TempArray[0],alias => $TempArray[$j]);  
                         }  
                     }  
                 }  
             }  
         }  
     }  
 }  
221    
222  sub LoadRoleSets {  Name for the input file. The file is in standard tab-delimited format. The first record
223      my ($self,$model) = @_;  contains the field names and the remaining records contain the data.
     my $sapling =$self->db();  
     my $RoleMappings = $model->GetDBTable("CURATED ROLE MAPPINGS");  
     my $NewSet;  
     my $SetHash;  
     my $LastComplex = -1;  
     my $LastReaction = "";  
     my $LastRole = "";  
     for (my $i=0; $i < $RoleMappings->size(); $i++) {  
         my $Row = $RoleMappings->get_row($i);  
         if (defined($Row) && defined($Row->{"REACTION"}->[0]) && defined($Row->{"ROLE"}->[0]) && defined($Row->{"COMPLEX"}->[0]) && defined($Row->{"MASTER"}->[0])) {  
             if ($Row->{"REACTION"}->[0] ne $LastReaction || $LastComplex ne $Row->{"COMPLEX"}->[0]) {  
                 if (defined($NewSet->{"ROLES"}) && defined($NewSet->{"REACTIONS"})) {  
                     my @RoleList = sort(keys(%{$NewSet->{"ROLES"}}));  
                     my @ReactionList = keys(%{$NewSet->{"REACTIONS"}});  
                     foreach my $Reaction (@ReactionList) {  
                         $SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0] = $NewSet->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0];  
                         if (defined($NewSet->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"})) {  
                             foreach my $Subsystem (@{$NewSet->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}) {  
                                 if (defined($SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"})) {  
                                     foreach my $OtherSubsystem (@{$SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}) {  
                                         if ($Subsystem eq $OtherSubsystem) {  
                                             $Subsystem = "";  
                                             last;  
                                         }  
                                     }  
                                 }  
                                 if ($Subsystem ne "") {  
                                     push(@{$SetHash->{join("+",@RoleList)}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}},$Subsystem);  
                                 }  
                             }  
                         }  
                     }  
                     foreach my $Role (@RoleList) {  
                         $SetHash->{join("+",@RoleList)}->{"ROLES"}->{$Role} = 1;  
                     }  
                 }  
                 $NewSet = {};  
             }  
             $NewSet->{"ROLES"}->{$Row->{"ROLE"}->[0]} = 1;  
             $NewSet->{"REACTIONS"}->{$Row->{"REACTION"}->[0]}->{"MASTER"}->[0] = $Row->{"MASTER"}->[0];  
             if (defined($Row->{"SUBSYSTEM"}->[0])) {  
                 push(@{$NewSet->{"REACTIONS"}->{$Row->{"REACTION"}->[0]}->{"SUBSYSTEMS"}},$Row->{"SUBSYSTEM"}->[0]);  
             }  
             $LastRole = $Row->{"ROLE"}->[0];  
             $LastReaction = $Row->{"REACTION"}->[0];  
             $LastComplex = $Row->{"COMPLEX"}->[0];  
         }  
     }  
224    
225      my @RoleSets = keys(%{$SetHash});  =item fieldNames
     foreach my $RoleSet (@RoleSets) {  
         my $Digested = $sapling->DigestKey($RoleSet);  
         $self->PutE(RoleSet => $Digested, source => "NONE");  
         my @ReactionList = keys(%{$SetHash->{$RoleSet}->{"REACTIONS"}});  
         foreach my $Reaction (@ReactionList) {  
             $self->PutR(IsTriggeredBy => $Reaction,$Digested, source => "NONE",master => $SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"MASTER"}->[0],subsystem => join(";",@{$SetHash->{$RoleSet}->{"REACTIONS"}->{$Reaction}->{"SUBSYSTEMS"}}));  
         }  
         my @RoleList = keys(%{$SetHash->{$RoleSet}->{"ROLES"}});  
         foreach my $Role (@RoleList) {  
             $self->PutR(IsCombinationOf => $Digested,$Role, local => 0);  
         }  
     }  
 }  
226    
227  sub LoadModels {  List of the field names expected, in order.
228      my ($self,$model) = @_;  
229      my $sapling = $self->db();  =item RETURN
230      my $ModelList = $model->GetDBTable("MODEL LIST");  
231      my $ModelStats = $model->GetDBTable("MODEL STATS");  Returns the open file handle if successful. If there is a mismatch, throws an error.
232      for (my $i=0; $i < $ModelStats->size(); $i++) {  
233          my $Row = $ModelStats->get_row($i);  =back
234          if (defined($Row) && defined($Row->{"Model ID"}->[0])) {  
235              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);  =cut
236              if (defined($Row->{"Organism name"}->[0])) {  
237                  $LoadingArray[1] = $Row->{"Organism name"}->[0];  sub CheckFile {
238              }      # Get the parameters.
239              if (defined($Row->{"Source"}->[0])) {      my ($self, $fileName, @fieldNames) = @_;
240                  $LoadingArray[2] = $Row->{"Source"}->[0];      # Open the file.
241              }      my $retVal = Open(undef, "<$fileName");
242              if (defined($Row->{"Total genes"}->[0])) {      $self->Add(files => 1);
243                  $LoadingArray[3] = $Row->{"Total genes"}->[0];      # Read in the file header.
244              }      my @actualFields = Tracer::GetLine($retVal);
245              if (defined($Row->{"Gram positive genes"}->[0])) {      # This will be set to TRUE if there's a mismatch.
246                  $LoadingArray[4] = $Row->{"Gram positive genes"}->[0];      my $error = 0;
247              }      for (my $i = 0; $i <= $#fieldNames; $i++) {
248              if (defined($Row->{"Gram negative genes"}->[0])) {          if ($fieldNames[$i] ne $actualFields[$i]) {
249                  $LoadingArray[5] = $Row->{"Gram negative genes"}->[0];              Trace("Field match error: expected $fieldNames[$i], found $actualFields[$i].") if T(0);
250              }              $error = 1;
251              if (defined($Row->{"Class"}->[0])) {          }
252                  $LoadingArray[6] = $Row->{"Class"}->[0];      }
253              }      # Was there an error?
254              if (defined($Row->{"Genes with functions"}->[0])) {      if ($error) {
255                  $LoadingArray[7] = $Row->{"Genes with functions"}->[0];          # Yes, so abort.
256              }          Confess("Invalid field name header in $fileName.");
257              if (defined($Row->{"Genes with reactions"}->[0])) {      } else {
258                  $LoadingArray[8] = $Row->{"Genes with reactions"}->[0];          # No, so trace the open.
259              }          Trace("Processing $fileName.") if T(ERDBLoadGroup => 2);
             if (defined($Row->{"Subsystem genes"}->[0])) {  
                 $LoadingArray[9] = $Row->{"Subsystem genes"}->[0];  
             }  
             if (defined($Row->{"Subsystem genes with reactions"}->[0])) {  
                 $LoadingArray[10] = $Row->{"Subsystem genes with reactions"}->[0];  
             }  
             if (defined($Row->{"Nonsubsystem genes"}->[0])) {  
                 $LoadingArray[11] = $Row->{"Nonsubsystem genes"}->[0];  
             }  
             if (defined($Row->{"Nonsubsystem genes with reactions"}->[0])) {  
                 $LoadingArray[12] = $Row->{"Nonsubsystem genes with reactions"}->[0];  
             }  
             if (defined($Row->{"Number of reactions"}->[0])) {  
                 $LoadingArray[13] = $Row->{"Number of reactions"}->[0];  
             }  
             if (defined($Row->{"Transport reaction"}->[0])) {  
                 $LoadingArray[14] = $Row->{"Transport reaction"}->[0];  
             }  
             if (defined($Row->{"Gap filling reactions"}->[0])) {  
                 $LoadingArray[15] = $Row->{"Gap filling reactions"}->[0];  
             }  
             if (defined($Row->{"Gap filling time"}->[0])) {  
                 $LoadingArray[16] = $Row->{"Gap filling time"}->[0];  
             }  
             if (defined($Row->{"Gap filling objective"}->[0])) {  
                 $LoadingArray[17] = $Row->{"Gap filling objective"}->[0];  
             }  
             if (defined($Row->{"Gap filling minimal objective"}->[0])) {  
                 $LoadingArray[18] = $Row->{"Gap filling minimal objective"}->[0];  
             }  
             if (defined($Row->{"Build date"}->[0])) {  
                 $LoadingArray[19] = $Row->{"Build date"}->[0];  
             }  
             if (defined($Row->{"Gap fill date"}->[0])) {  
                 $LoadingArray[20] = $Row->{"Gap fill date"}->[0];  
             }  
             if (defined($Row->{"Version"}->[0])) {  
                 $LoadingArray[21] = $Row->{"Version"}->[0];  
             }  
             if (defined($Row->{"Gap fill version"}->[0])) {  
                 $LoadingArray[22] = $Row->{"Gap fill version"}->[0];  
             }  
             if ($Row->{"Model ID"}->[0] =~ m/Core\d+\.\d+V\d+\.\d+/) {  
                 $LoadingArray[25] = 1;  
             } elsif (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID"))) {  
                 if (defined($ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"DIRECTORY"}->[0])) {  
                     $LoadingArray[23] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"DIRECTORY"}->[0];  
                 }  
                 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") {  
                     $LoadingArray[24] = $ModelList->get_row_by_key($Row->{"Model ID"}->[0],"MODEL ID")->{"JOB ID"}->[0];  
                 }  
             }  
             for my $j (3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,21,22,24,25) {  
                 $LoadingArray[$j] = 0 if ($LoadingArray[$j] =~ /[a-z]/i);  
             }  
             $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]);  
             #Adding the relationship between model and genome  
             if (defined($Row->{"Genome ID"}->[0])) {  
                 $self->PutR(IsModeledBy => $Row->{"Genome ID"}->[0],$LoadingArray[0]);  
             }  
             #If the model is not obsolete, we add the relationships between model and reaction and featureset  
             if ($LoadingArray[25] == 0) {  
                 #Loading the model from file  
                 my $ModelTable = $model->GetDBModel($LoadingArray[0]);  
                 for (my $j=0; $j < $ModelTable->size(); $j++) {  
                     my $RxnRow = $ModelTable->get_row($j);  
                     if (defined($RxnRow) && defined($RxnRow->{"LOAD"}->[0])) {  
                         my @SubLoadingArray = ("R","c","NONE",10,"V","NONE","UNKNOWN");  
                         if (defined($RxnRow->{"DIRECTIONALITY"}->[0])) {  
                             my $code = $RxnRow->{"DIRECTIONALITY"}->[0];  
                             if ($code eq '<=>') {  
                                 $SubLoadingArray[0] = 'R';  
                             } elsif ($code eq '<=') {  
                                 $SubLoadingArray[0] = 'B';  
                             } elsif ($code eq '=>') {  
                                 $SubLoadingArray[0] = 'F';  
                             }  
                         }  
                         if (defined($RxnRow->{"COMPARTMENT"}->[0])) {  
                             $SubLoadingArray[1] = $RxnRow->{"COMPARTMENT"}->[0];  
                         }  
                         if (defined($RxnRow->{"SUBSYSTEM"})) {  
                             $SubLoadingArray[2] = join(";",@{$RxnRow->{"SUBSYSTEM"}});  
                         }  
                         if (defined($RxnRow->{"CONFIDENCE"}->[0])) {  
                             $SubLoadingArray[3] = $RxnRow->{"CONFIDENCE"}->[0];  
                             if ($SubLoadingArray[3] eq 'NONE') {  
                                 $SubLoadingArray[3] = 10;  
                             }  
                         }  
                         if (defined($RxnRow->{"NOTES"})) {  
                             $SubLoadingArray[5] = join(";",@{$RxnRow->{"NOTES"}});  
                         }  
                         if (defined($RxnRow->{"ASSOCIATED PEG"})) {  
                             #Adding the role set entities  
                             foreach my $FeatureSet (@{$RxnRow->{"ASSOCIATED PEG"}}) {  
                                 if ($FeatureSet =~ m/peg\.\d+/) {  
                                     my $DigestedKey = $sapling->DigestKey($FeatureSet);  
                                     $self->PutE(FeatureSet => $DigestedKey, source => "NONE");  
                                     #Adding the relationship between the reaction and roleset  
                                     $self->PutR(IsStimulatedBy => $RxnRow->{"LOAD"}->[0],$DigestedKey);  
                                     #Adding the relationship between the model and featureset  
                                     $self->PutR(Encompasses => $LoadingArray[0],$DigestedKey);  
                                     #Adding the relationship between FeatureSet and feature  
                                     my @PegArray = split(/\+/,$FeatureSet);  
                                     foreach my $Feature (@PegArray) {  
                                         if ($Feature =~ m/(peg\.\d+)/) {  
                                             $self->PutR(IsSetOf => $DigestedKey,"fig|".$Row->{"Genome ID"}->[0].".".$1);  
                                         }  
                                     }  
                                 }  
                             }  
                             $SubLoadingArray[6] = join(";",@{$RxnRow->{"ASSOCIATED PEG"}});  
                         }  
                         $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]);  
                     }  
260                  }                  }
261                  #Clearing the model data from memmory      # Return the file handle.
262                  undef $ModelTable;      return $retVal;
                 $model->ClearDBModel($LoadingArray[0],"DELETE");  
263              }              }
264    
265    =head3 ReadLine
266    
267        my @fields = $sl->ReadLine($ih);
268    
269    Read a line of data from an input file.
270    
271    =over 4
272    
273    =item ih
274    
275    Open file handle for the input file.
276    
277    =item RETURN
278    
279    Returns a list of the field values for the next record in the file.
280    
281    =back
282    
283    =cut
284    
285    sub ReadLine {
286        # Get the parameters.
287        my ($self, $ih) = @_;
288        # Read the line.
289        my @retVal = Tracer::GetLine($ih);
290        # Count this record.
291        $self->Track(records => $retVal[0], 1000);
292        # Return the data.
293        return @retVal;
294          }          }
295    
296    
297    =head3 CheckReaction
298    
299        $sl->CheckReaction($reaction);
300    
301    Insure we have created a rectord for the specified reaction.
302    
303    =over 4
304    
305    =item reaction
306    
307    ID of the reaction in question.
308    
309    =back
310    
311    =cut
312    
313    sub CreateReaction {
314        # Get the parameters.
315        my ($self, $reaction) = @_;
316        # Get the reaction hash.
317        my $reactionH = $self->{reactions};
318        # See if this reaction is new.
319        if (! $reactionH->{$reaction}) {
320            # It is, so create it.
321            $self->PutE(Reaction => $reaction);
322            # Insure we don't create it again.
323            $reactionH->{$reaction} = 1;
324      }      }
325  }  }
326    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3