[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.16, Tue Mar 1 22:26:34 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 135  Line 131 
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) {
# Line 165  Line 163 
163          $self->PutR(Involves => $reaction, $compound, product => $product,          $self->PutR(Involves => $reaction, $compound, product => $product,
164                      stoichiometry => $stoich, cofactor => $cofactor);                      stoichiometry => $stoich, cofactor => $cofactor);
165      }      }
166      # Now we connect the reactions to roles.      # 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        # 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 201  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.16  
changed lines
  Added in v.1.20

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3