[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.14, Sat Feb 26 19:05:32 2011 UTC revision 1.20, Thu Oct 6 19:05:55 2011 UTC
# Line 33  Line 33 
33    
34  =head3 new  =head3 new
35    
36      my $sl = ModelSaplingLoader->new($erdb, $options, @tables);      my $sl = ModelSaplingLoader->new($erdb, $options);
37    
38  Construct a new ModelSaplingLoader object.  Construct a new ModelSaplingLoader object.
39    
# Line 47  Line 47 
47    
48  Reference to a hash of command-line options.  Reference to a hash of command-line options.
49    
 =item tables  
   
 List of tables in this load group.  
   
50  =back  =back
51    
52  =cut  =cut
# Line 61  Line 57 
57      # Create the table list.      # Create the table list.
58      my @tables = qw(Compound Reaction EcNumber Model Media IsTriggeredBy      my @tables = qw(Compound Reaction EcNumber Model Media IsTriggeredBy
59                      IsCategorizedInto IsConsistentWith IsModeledBy Involves                      IsCategorizedInto IsConsistentWith IsModeledBy Involves
60                      IsRequiredBy);                      IsRequiredBy Complex IsSetOf IsExemplarOf);
61      # Create the BaseSaplingLoader object.      # Create the BaseSaplingLoader object.
62      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);
63      # Create the reaction tracking hash.      # Create the reaction tracking hash.
# Line 104  Line 100 
100    
101  =cut  =cut
102    
103    # hash of ubiquitous compounds.
104    use constant UBIQUITOUS => {
105        cpd00001 => 'OH-',
106        cpd00002 => 'ATP',
107        cpd00003 => 'Nicotinamideadeninedinucleotide',
108        cpd00004 => 'Nicotinamideadeninedinucleotide-reduced',
109        cpd00005 => 'Nicotinamideadeninedinucleotidephosphate-reduced',
110        cpd00006 => 'Nicotinamideadeninedinucleotidephosphate',
111        cpd00007 => 'Oxygen',
112        cpd00008 => 'ADP',
113        cpd00009 => 'Orthophosphoric acid',
114        cpd00010 => 'CoenzymeA',
115        cpd00011 => 'Carbon dioxide',
116        cpd00012 => 'PPi',
117        cpd00018 => 'AMP',
118        cpd00020 => 'Pyruvic Acid',
119        cpd00022 => 'Acetyl-CoA',
120        cpd00025 => 'Hydrogen peroxide',
121        cpd00067 => 'H+',
122        cpd00971 => 'Sodium',
123        cpd15352 => '2-Demethylmenaquinone',
124        cpd15353 => '2-Demethylmenaquinol',
125        cpd15499 => 'Menaquinol',
126        cpd15500 => 'Menaquinone',
127        cpd15560 => 'Ubiquinone-8',
128        cpd15561 => 'Ubiquinol-8',
129    };
130    
131  sub LoadModelFiles {  sub LoadModelFiles {
132      # Get the parameters.      # Get the parameters.
133      my ($self) = @_;      my ($self) = @_;
134        # Get the sapling database.
135        my $erdb = $self->db();
136      # Get the model dump file directory.      # Get the model dump file directory.
137      my $dir = $self->db()->LoadDirectory() . "/models";      my $dir = $erdb->LoadDirectory() . "/models";
138      # First we read the compounds.      # First we read the compounds.
139      my $ih = $self->CheckFile("$dir/CompoundName.txt", qw(CompoundID Name));      my $ih = $self->CheckFile("$dir/CompoundName.txt", qw(CompoundID Name));
140      while (! eof $ih) {      while (! eof $ih) {
141          # Get the next compound.          # Get the next compound.
142          my ($id, $label) = $self->ReadLine($ih);          my ($id, $label) = $self->ReadLine($ih);
143          # Create a compound record for it.          # Create a compound record for it.
144          $self->PutE(Compound => $id, label => $label);          $self->PutE(Compound => $id, label => $label, ubiquitous => (UBIQUITOUS->{$id} ? 1 : 0));
145      }      }
146      # Next, the compound-reactions relationship. We create the reactions here, too.      # Next, the compound-reactions relationship. We create the reactions here, too.
147      $ih = $self->CheckFile("$dir/CompoundReaction.txt", qw(CompoundID ReactionID      $ih = $self->CheckFile("$dir/CompoundReaction.txt", qw(CompoundID ReactionID
148                             Stoichiometry));                             Stoichiometry Cofactor));
149      while (! eof $ih) {      while (! eof $ih) {
150          # Get the next link.          # Get the next link.
151          my ($compound, $reaction, $stoich) = $self->ReadLine($ih);          my ($compound, $reaction, $stoich, $cofactor) = $self->ReadLine($ih);
152          # Insure the reaction exists.          # Insure the reaction exists.
153          $self->CreateReaction($reaction);          $self->CreateReaction($reaction);
154          # Check for product or substrate.          # Check for product or substrate.
# Line 135  Line 161 
161          }          }
162          # Connect the reaction to the compound.          # Connect the reaction to the compound.
163          $self->PutR(Involves => $reaction, $compound, product => $product,          $self->PutR(Involves => $reaction, $compound, product => $product,
164                      stoichiometry => $stoich);                      stoichiometry => $stoich, cofactor => $cofactor);
165        }
166        # Before we go on, we need to get a map of the modelSEED role IDs to
167        # the SEED role IDs. This is found in the Role.txt file, along with the
168        # exemplar data.
169        my %roleHash;
170        $ih = $self->CheckFile("$dir/Role.txt", qw(RoleID Name ExemplarID));
171        while (! eof $ih) {
172            # Get the next role's record.
173            my ($roleID, $role, $exemplarList) = $self->ReadLine($ih);
174            # Map the role ID to the role name (which is the SEED's ID).
175            $roleHash{$roleID} = $role;
176            # If there is are exemplars, store them.
177            if ($exemplarList && $exemplarList ne 'NONE') {
178                for my $exemplar (split /\s*,\s*/, $exemplarList) {
179                    $self->PutR(IsExemplarOf => $exemplar, $role);
180                }
181            }
182      }      }
183      # Now we connect the reactions to roles.      # The next step is to create the complexes. We load into memory a
184        # hash mapping the complexes to their reactions. This is later
185        # used to insure we have reaction-to-role coverage.
186        my %cpxHash;
187        $ih = $self->CheckFile("$dir/ReactionComplex.txt", qw(ReactionID ComplexID));
188        while (! eof $ih) {
189            # Get the next reaction/complex pair.
190            my ($rxn, $cpx) = $self->ReadLine($ih);
191            # Is this a new complex?
192            if (! exists $cpxHash{$cpx}) {
193                # Yes. Create a record for it.
194                $self->PutE(Complex => $cpx);
195                $cpxHash{$cpx} = [];
196            }
197            # Insure the reaction exists.
198            $self->CreateReaction($rxn);
199            # Connect the complex to the reaction.
200            $self->PutR(IsSetOf => $cpx, $rxn);
201            push @{$cpxHash{$cpx}}, $rxn;
202        }
203        # Here we connect the complexes to the roles. Along the way, we
204        # create a hash listing of all of a reaction's roles. That hash
205        # will be used to check for missing reaction/role links later on.
206        my %rxnHash;
207        $ih = $self->CheckFile("$dir/ComplexRole.txt", qw(RoleID ComplexID));
208        while (! eof $ih) {
209            # Get the next role/complex pair.
210            my ($roleID, $cpx) = $self->ReadLine($ih);
211            # Connect the role to the complex.
212            $self->PutR(IsTriggeredBy => $cpx, $roleHash{$roleID}, optional => 0);
213            # Denote that this role is connected to the complex's reactions.
214            for my $rxn (@{$cpxHash{$cpx}}) {
215                push @{$rxnHash{$rxn}}, $roleID;
216            }
217        }
218        # We don't need the complex hash any more. Instead, we're going to
219        # use it to track single-reaction complexes we create.
220        %cpxHash = ();
221        # Now we fill in the missing reaction-to-role connections.
222      $ih = $self->CheckFile("$dir/ReactionRole.txt", qw(ReactionID Role));      $ih = $self->CheckFile("$dir/ReactionRole.txt", qw(ReactionID Role));
223      while (! eof $ih) {      while (! eof $ih) {
224          # Get the next reaction/role pair. We don't need to create roles here because          # Get the next reaction/role pair.
         # they are built in the Feature module.  
225          my ($reaction, $role) = $self->ReadLine($ih);          my ($reaction, $role) = $self->ReadLine($ih);
226          # Insure the reaction exists.          # Insure the reaction exists.
227          $self->CreateReaction($reaction);          $self->CreateReaction($reaction);
228          # Connect the reaction to the role.          # Is this reaction already connected to this role?
229            my $roleList = $rxnHash{$reaction};
230            if (! $roleList || ! (grep { $roleHash{$_} eq $role } @{$rxnHash{$reaction}})) {
231                # No, so we have to do it the hard way.
232                if (! exists $cpxHash{$reaction}) {
233                    # Here the reaction has not had a complex created, so we
234                    # must create one.
235                    $self->Add(pseudoComplex => 1);
236                    $self->PutE(Complex => $reaction);
237                    $self->PutR(IsSetOf => $reaction, $reaction);
238                }
239                # Connect the reaction's complex to this role.
240          $self->PutR(IsTriggeredBy => $reaction, $role);          $self->PutR(IsTriggeredBy => $reaction, $role);
241                $self->Add(missingTrigger => 1);
242            }
243      }      }
244      # Now we create the models.      # Now we create the models.
245      $ih = $self->CheckFile("$dir/ModelGenome.txt", qw(ModelID GenomeID));      $ih = $self->CheckFile("$dir/ModelGenome.txt", qw(ModelID Name GenomeID));
246      while (! eof $ih) {      while (! eof $ih) {
247          # Get the next model.          # Get the next model.
248          my ($model, $genome) = $self->ReadLine($ih);          my ($model, $name, $genome) = $self->ReadLine($ih);
249          # Create the model.          # Create the model.
250          $self->PutE(Model => $model);          $self->PutE(Model => $model);
251          # Connect it to the genome. Again, the genomes are created elsewhere.          # Connect it to the genome. Again, the genomes are created elsewhere.
# Line 173  Line 266 
266      }      }
267  }  }
268    
269  =head3 StartFile  =head3 CheckFile
270    
271      my $ih = $sl->CheckFile($fileName, @fieldNames);      my $ih = $sl->CheckFile($fileName, @fieldNames);
272    

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.20

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3