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

Diff of /Sprout/ScenarioSaplingLoader.pm

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

revision 1.3, Thu May 28 18:08:56 2009 UTC revision 1.4, Thu Jun 4 18:22:18 2009 UTC
# Line 23  Line 23 
23      use Tracer;      use Tracer;
24      use ERDB;      use ERDB;
25      require Image::Magick;      require Image::Magick;
26        use FIGMODEL;
27      use Rectangle;      use Rectangle;
28      use GD;      use GD;
29      use base 'BaseSaplingLoader';      use base 'BaseSaplingLoader';
# Line 65  Line 66 
66                           HasParticipant Shows Displays Diagram DiagramContent Overlaps);                           HasParticipant Shows Displays Diagram DiagramContent Overlaps);
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        # Create and attach a FIGMODEL object.
70        $retVal->{figModel} = FIGMODEL->new();
71      # Return it.      # Return it.
72      return $retVal;      return $retVal;
73  }  }
# Line 116  Line 119 
119      my ($self, $fig) = @_;      my ($self, $fig) = @_;
120      # Get the Sapling object.      # Get the Sapling object.
121      my $erdb = $self->db();      my $erdb = $self->db();
122        # Get the FIGMODEL object. This is used to map KEGG reaction IDs (used in
123        # scenarios) to our reaction IDs.
124        my $figmodel = $self->{figModel};
125      # We run through the subsystems and roles, generating the scenarios.      # We run through the subsystems and roles, generating the scenarios.
126      # We'll need some hashes to prevent duplicates.      # We'll need some hashes to prevent duplicates.
127      my %roles = ();      my %roles = ();
# Line 152  Line 158 
158                  $self->PutE(Scenario => $scenarioName);                  $self->PutE(Scenario => $scenarioName);
159                  # Attach the input compounds.                  # Attach the input compounds.
160                  for my $input ($sub->get_hope_input_compounds($scenarioName)) {                  for my $input ($sub->get_hope_input_compounds($scenarioName)) {
161                      $self->PutR(IsTerminusFor => $input, $scenarioName,                      # Resolve the compound ID.
162                        my $inputID = $figmodel->id_of_compound($input);
163                        # Write the relationship record.
164                        $self->PutR(IsTerminusFor => $inputID, $scenarioName,
165                                  group_number => 0);                                  group_number => 0);
166                  }                  }
167                  # Now we need to set up the output compounds. They come in two                  # Now we need to set up the output compounds. They come in two
# Line 162  Line 171 
171                  for my $outputGroup ($sub->get_hope_output_compounds($scenarioName)) {                  for my $outputGroup ($sub->get_hope_output_compounds($scenarioName)) {
172                      # Attach the compounds.                      # Attach the compounds.
173                      for my $compound (@$outputGroup) {                      for my $compound (@$outputGroup) {
174                          $self->PutR(IsTerminusFor => $compound, $scenarioName,                          # Resolve the compound ID.
175                            my $compoundID = $figmodel->id_of_compound($compound);
176                            # Write the relationship record.
177                            $self->PutR(IsTerminusFor => $compoundID, $scenarioName,
178                                      group_number => $outputGroupID);                                      group_number => $outputGroupID);
179                      }                      }
180                      # # Increment the group number.                      # # Increment the group number.
# Line 172  Line 184 
184                  # are not in the subsystem but are part of the scenario.                  # are not in the subsystem but are part of the scenario.
185                  my @addReactions = $sub->get_hope_additional_reactions($scenarioName);                  my @addReactions = $sub->get_hope_additional_reactions($scenarioName);
186                  for my $reaction (@addReactions) {                  for my $reaction (@addReactions) {
187                      $self->PutR(HasParticipant => $scenarioName, $reaction, type => 1);                      # Resolve the reaction ID.
188                        my $reactionID = $figmodel->id_of_reaction($reaction);
189                        # Write the relationship record.
190                        $self->PutR(HasParticipant => $scenarioName, $reactionID,
191                                    type => 1);
192                  }                  }
193                  # Next is the list of reactions not in the scenario. We get the list                  # Next is the list of reactions not in the scenario. We get the list
194                  # of these, and then we use it to modify the full reaction list. If                  # of these, and then we use it to modify the full reaction list. If
# Line 180  Line 196 
196                  # not-list, the type is 0.                  # not-list, the type is 0.
197                  my %notReactions = map { $_ => 2 } $sub->get_hope_ignore_reactions($scenarioName);                  my %notReactions = map { $_ => 2 } $sub->get_hope_ignore_reactions($scenarioName);
198                  for my $reaction (@reactions) {                  for my $reaction (@reactions) {
199                      $self->PutR(HasParticipant => $scenarioName, $reaction,                      # Resolve the reaction ID.
200                        my $reactionID = $figmodel->id_of_reaction($reaction);
201                        # Write the relationship record.
202                        $self->PutR(HasParticipant => $scenarioName, $reactionID,
203                                  type => ($notReactions{$reaction} || 0));                                  type => ($notReactions{$reaction} || 0));
204                  }                  }
205                  # Link the maps.                  # Link the maps.
# Line 237  Line 256 
256          $self->PutE(Diagram => $map, name => $name);          $self->PutE(Diagram => $map, name => $name);
257          $self->PutE(DiagramContent => $map, content => $diagram);          $self->PutE(DiagramContent => $map, content => $diagram);
258          # Now we connect it to the compounds.          # Now we connect it to the compounds.
259          $self->Connect($map, $mapTitle . "_cpd.coord", 'Shows');          $self->Connect($map, $mapTitle . "_cpd.coord", 'Shows', 'id_of_compound');
260          # Finally, the reactions.          # Finally, the reactions.
261          $self->Connect($map, $mapTitle . "_rn.coord", 'Displays');          $self->Connect($map, $mapTitle . "_rn.coord", 'Displays', 'id_of_reaction');
262      }      }
263  }  }
264    
265  =head3 Connect  =head3 Connect
266    
267      $sl->Connect($mapID, $fileName, $relName);      $sl->Connect($mapID, $fileName, $relName, $method);
268    
269  Create the relationship records connecting the specified map to the  Create the relationship records connecting the specified map to the
270  objects in the specified file. The file is tab-delimited, with the first  objects in the specified file. The file is tab-delimited, with the first
# Line 267  Line 286 
286    
287  Name of the relationship to be filled from the data.  Name of the relationship to be filled from the data.
288    
289    =item method
290    
291    Name of the method to be used to convert IDs.
292    
293    =item
294    
295  =back  =back
296    
297  =cut  =cut
298    
299  sub Connect {  sub Connect {
300      # Get the parameters.      # Get the parameters.
301      my ($self, $mapID, $fileName, $relName) = @_;      my ($self, $mapID, $fileName, $relName, $method) = @_;
302        # Get the FIGMODEL object. This is used to map KEGG reaction and compound IDs
303        # (used in disagrams) to our IDs.
304        my $figmodel = $self->{figModel};
305      # Check the file.      # Check the file.
306      if (! -s $fileName) {      if (! -s $fileName) {
307          Trace("File \"$fileName\" not found for map $mapID.") if T(1);          Trace("File \"$fileName\" not found for map $mapID.") if T(1);
# Line 285  Line 313 
313          while (! eof $ih) {          while (! eof $ih) {
314              # Get the ID and the coordinates.              # Get the ID and the coordinates.
315              my ($id, @coords) = Tracer::GetLine($ih);              my ($id, @coords) = Tracer::GetLine($ih);
316                # Resolve the ID.
317                my $realID = eval("\$figmodel->$method(\$id)");
318              # Connect the ID to the diagram.              # Connect the ID to the diagram.
319              $self->PutR($relName => $mapID, $id, location => Rectangle->new(@coords));              $self->PutR($relName => $mapID, $realID, location => Rectangle->new(@coords));
320          }          }
321      }      }
322  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3