[Bio] / FigKernelPackages / model.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/model.pm

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

revision 1.16, Mon Jul 23 15:07:25 2007 UTC revision 1.17, Fri Nov 2 19:12:58 2007 UTC
# Line 63  Line 63 
63    
64  #Flip this bit to enable debugging  #Flip this bit to enable debugging
65  my $debug = int($ENV{HOPE_DEBUG});  my $debug = int($ENV{HOPE_DEBUG});
66    #$debug = 0;
67    
68  sub set_fig  sub set_fig
69  {  {
# Line 109  Line 110 
110    
111      my %data;      my %data;
112    
113      my @inputs = @{$subsystem->get_hope_input_compounds($name)};      my @inputs = $subsystem->get_hope_input_compounds($name);
114      my @outputs = @{$subsystem->get_hope_output_compounds($name)};      my @outputs = $subsystem->get_hope_output_compounds($name);
115      my @map_ids = @{$subsystem->get_hope_map_ids($name)};      my @map_ids = $subsystem->get_hope_map_ids($name);
116      my @additional_reactions = @{$subsystem->get_hope_additional_reactions($name)};      my @additional_reactions = $subsystem->get_hope_additional_reactions($name);
117      my @ignore_reactions = @{$subsystem->get_hope_ignore_reactions($name)};      my @ignore_reactions = $subsystem->get_hope_ignore_reactions($name);
118    
119      $data{inputs} = \@inputs;      $data{inputs} = \@inputs;
120      $data{outputs} = \@outputs;      $data{outputs} = \@outputs;
# Line 143  Line 144 
144    
145      if ($genome eq "All")      if ($genome eq "All")
146      {      {
147          my %all_reactions = %{$subsystem->get_hope_reactions};          my %all_reactions = $subsystem->get_hope_reactions;
148          foreach my $role (keys %all_reactions)          foreach my $role (keys %all_reactions)
149          {          {
150              map { $ss_reactions{$_} = 1 } @{$all_reactions{$role}};              map { $ss_reactions{$_} = 1 } @{$all_reactions{$role}};
# Line 151  Line 152 
152      }      }
153      else      else
154      {      {
155          my $reactions_for_genome = $subsystem->get_hope_reactions_for_genome($genome);          my %reactions_for_genome = $subsystem->get_hope_reactions_for_genome($genome);
156          map { $ss_reactions{$_} = 1 } keys %{$reactions_for_genome} if defined $reactions_for_genome;          map { $ss_reactions{$_} = 1 } keys %reactions_for_genome if defined %reactions_for_genome;
157      }      }
158    
159      map { $sc_inputs{$_} = 1 } @{$scenario_data->{inputs}};      map { $sc_inputs{$_} = 1 } @{$scenario_data->{inputs}};
# Line 409  Line 410 
410      my ($reactions, $map_ids) = @_;      my ($reactions, $map_ids) = @_;
411    
412      # determine whether the reaction is in one of the maps, and get directionality accordingly      # determine whether the reaction is in one of the maps, and get directionality accordingly
413      my (%reactions_in_maps, %reactions_not_in_maps);      my (%reactions_in_maps, %reactions_not_in_maps, %reactions_not_in_any_map);
414    
415      foreach my $rxn (keys %$reactions)      foreach my $rxn (keys %$reactions)
416      {      {
# Line 471  Line 472 
472                  }                  }
473                  if (!$found_in_other_map)                  if (!$found_in_other_map)
474                  {                  {
475                      # reaction not in map, get directionality without reference to map                      # reaction not in any map, get directionality without reference to map
476                      if($fig->reversible($rxn) eq "1")                      if($fig->reversible($rxn) eq "1")
477                      {                      {
478                          $direction = "B";                          $direction = "B";
# Line 480  Line 481 
481                      {                      {
482                          $direction = "R";                          $direction = "R";
483                      }                      }
484    
485                        $reactions_not_in_any_map{$rxn} = 1;
486                  }                  }
487              }              }
488    
# Line 587  Line 590 
590              $all_compounds_to_main{$cpd} = $additional_compounds_to_main{$cpd};              $all_compounds_to_main{$cpd} = $additional_compounds_to_main{$cpd};
591          }          }
592      }      }
593    
594        # the reactions that aren't in any map at all won't have any main compounds.
595        # mark those compounds that are in all_compounds_to_main as main.
596        foreach my $rxn (keys %reactions_not_in_any_map)
597        {
598            print STDERR "Checking reaction not in any map: $rxn\n" if $debug;
599            foreach my $cpd_array ($reactions_to_substrate_arrays{$rxn."_L"},
600                                   $reactions_to_substrate_arrays{$rxn."_R"},
601                                   $reactions_to_product_arrays{$rxn."_L"},
602                                   $reactions_to_product_arrays{$rxn."_R"})
603            {
604                if (defined $cpd_array)
605                {
606                    foreach my $cinfo (@{$cpd_array})
607                    {
608                        my $cpd = $cinfo->[0];
609                        if ($all_compounds_to_main{$cpd})
610                        {
611                            print STDERR "\t Setting $cpd to main\n";
612                            $cinfo->[2] = 1;
613                        }
614                    }
615                }
616            }
617    
618        }
619  }  }
620    
621  sub process_paths  sub process_paths
# Line 2051  Line 2080 
2080          {          {
2081              if ($compounds_borrowed_to_tokens->{$cpd}->{$token_id} > 0)              if ($compounds_borrowed_to_tokens->{$cpd}->{$token_id} > 0)
2082              {              {
2083                    # I don't know why I put in this "if" statement, so I'm going to do the same thing
2084                    # in both cases, but print a distinguishing debug statement in case I need to find
2085                    # the occurrences later
2086                  if ($all_compounds_to_main{$cpd})                  if ($all_compounds_to_main{$cpd})
2087                  {                  {
2088                      my @names = $fig->names_of_compound($cpd);                      my @names = $fig->names_of_compound($cpd);
2089                      print STDERR "\ttoken '$token_id' has borrowed $cpd $names[0]\n" unless !$debug;                      print STDERR "\ttoken '$token_id' has borrowed $cpd $names[0] (main)\n" unless !$debug;
2090                        $token_is_done_borrowing = 0;
2091                    }
2092                    else
2093                    {
2094                        my @names = $fig->names_of_compound($cpd);
2095                        print STDERR "\ttoken '$token_id' has borrowed $cpd $names[0] (not main)\n" unless !$debug;
2096                      $token_is_done_borrowing = 0;                      $token_is_done_borrowing = 0;
2097                  }                  }
2098              }              }
# Line 2705  Line 2743 
2743    
2744  sub compare_scenario  sub compare_scenario
2745  {  {
2746      my($genome,$superset,$ss_name,$scenario_name) = @_;      my($genome,$superset,$ss_name,$scenario_name,$dont_copy) = @_;
2747      my @genome_paths;      my @genome_paths;
2748      my $scenario_dir_all = $fig->model_directory('All') . "/Scenarios/$superset/$ss_name/$scenario_name";      my $scenario_dir_all = $fig->model_directory('All') . "/Scenarios/$superset/$ss_name/$scenario_name";
2749      my $subsystem = $fig->get_subsystem($ss_name);      my $subsystem = $fig->get_subsystem($ss_name);
2750      my @additional_reactions = @{$subsystem->get_hope_additional_reactions($scenario_name)};      my @additional_reactions = $subsystem->get_hope_additional_reactions($scenario_name);
2751      my %additional_reactions;      my %additional_reactions;
2752      map { $additional_reactions{$_} = 1 } @additional_reactions;      map { $additional_reactions{$_} = 1 } @additional_reactions;
2753    
# Line 2717  Line 2755 
2755    
2756      if ($genome eq "All")      if ($genome eq "All")
2757      {      {
2758          my %all_reactions = %{$subsystem->get_hope_reactions};          my %all_reactions = $subsystem->get_hope_reactions;
2759          foreach my $role (keys %all_reactions)          foreach my $role (keys %all_reactions)
2760          {          {
2761              map { $ss_reactions{$_} = 1 } @{$all_reactions{$role}};              map { $ss_reactions{$_} = 1 } @{$all_reactions{$role}};
# Line 2725  Line 2763 
2763      }      }
2764      else      else
2765      {      {
2766          my $reactions_for_genome = $subsystem->get_hope_reactions_for_genome($genome);          my %reactions_for_genome = $subsystem->get_hope_reactions_for_genome($genome);
2767          map { $ss_reactions{$_} = 1 } keys %{$reactions_for_genome} if defined $reactions_for_genome;          map { $ss_reactions{$_} = 1 } keys %reactions_for_genome if defined %reactions_for_genome;
2768      }      }
2769    
2770      # first find paths in the All directory that should be valid for the genome      # first find paths in the All directory that should be valid for the genome
2771      # based on the reactions associated with it in the subsystems      # based on the reactions associated with it in the subsystems
2772      opendir (DIR_ALL,$scenario_dir_all) or die("cannot open directory $scenario_dir_all: $!");      opendir (DIR_ALL,$scenario_dir_all) or return [];
2773      my @sub_dirs  = readdir DIR_ALL; shift @sub_dirs; shift @sub_dirs; # get rid of . and ..      my @sub_dirs  = readdir DIR_ALL; shift @sub_dirs; shift @sub_dirs; # get rid of . and ..
2774      close DIR_ALL;      close DIR_ALL;
2775    
# Line 2767  Line 2805 
2805      # are in the appropriate All subdirectory      # are in the appropriate All subdirectory
2806      my $scenario_dir_genome = $fig->model_directory($genome). "/Scenarios/$superset/$ss_name/$scenario_name";      my $scenario_dir_genome = $fig->model_directory($genome). "/Scenarios/$superset/$ss_name/$scenario_name";
2807    
2808      opendir (DIR_GENOME,$scenario_dir_genome) or die("$scenario_dir_genome");      opendir (DIR_GENOME,$scenario_dir_genome) or return \@genome_paths;
2809      @sub_dirs  = readdir DIR_GENOME; shift @sub_dirs; shift @sub_dirs; # get rid of . and ..      @sub_dirs  = readdir DIR_GENOME; shift @sub_dirs; shift @sub_dirs; # get rid of . and ..
2810      close DIR_GENOME;      close DIR_GENOME;
2811    
# Line 2792  Line 2830 
2830    
2831          if (! exists($paths_all{$reaction_string}))          if (! exists($paths_all{$reaction_string}))
2832          {          {
2833                if ($dont_copy)
2834                {
2835                    print STDERR "$scenario_dir_genome/$path not found in All\n";
2836                }
2837                else
2838                {
2839              $path_counter++;              $path_counter++;
2840              my $new_path_name = "path_".$path_counter;              my $new_path_name = "path_".$path_counter;
2841              my $temp_sdg = $scenario_dir_genome;              my $temp_sdg = $scenario_dir_genome;
# Line 2802  Line 2846 
2846              $temp_sda =~ s/\)/\\\)/g;              $temp_sda =~ s/\)/\\\)/g;
2847              `cp -R $temp_sdg/$path $temp_sda/$new_path_name`;              `cp -R $temp_sdg/$path $temp_sda/$new_path_name`;
2848              push @genome_paths, $new_path_name;              push @genome_paths, $new_path_name;
2849              print "Copied $temp_sdg/$path to $temp_sda/$new_path_name\n";                  print STDERR "Copied $temp_sdg/$path to $temp_sda/$new_path_name\n";
2850                }
2851          }          }
2852    
2853            unless ($dont_copy)
2854            {
2855          # remove genome-specific paths          # remove genome-specific paths
2856          rmtree("$scenario_dir_genome/$path");          rmtree("$scenario_dir_genome/$path");
2857      }      }
2858        }
2859    
2860        unless ($dont_copy)
2861        {
2862      # create soft links for each genome-specific path, with the same name      # create soft links for each genome-specific path, with the same name
2863      # as the path in the "All" directory      # as the path in the "All" directory
2864      foreach my $path (@genome_paths)      foreach my $path (@genome_paths)
# Line 2821  Line 2871 
2871          $temp_sda =~ s/\)/\\\)/g;          $temp_sda =~ s/\)/\\\)/g;
2872          `ln -s $temp_sda/$path $temp_sdg`;          `ln -s $temp_sda/$path $temp_sdg`;
2873      }      }
2874        }
2875    
2876      return \@genome_paths;      return \@genome_paths;
2877  }  }
# Line 3002  Line 3053 
3053    
3054  sub compare_subsystem  sub compare_subsystem
3055  {  {
3056      my ($genome,$superset,$subsystem) = @_;      my ($genome,$superset,$subsystem,$dont_copy) = @_;
3057      my %genome_scenarios;      my %genome_scenarios;
3058    
3059      my $subsystem_obj = $fig->get_subsystem($subsystem);      my $subsystem_obj = $fig->get_subsystem($subsystem);
# Line 3013  Line 3064 
3064          return;          return;
3065      }      }
3066    
   
3067      my @ss_scenarios = $subsystem_obj->get_hope_scenario_names;      my @ss_scenarios = $subsystem_obj->get_hope_scenario_names;
3068    
3069      foreach my $name (@ss_scenarios)      foreach my $name (@ss_scenarios)
3070      {      {
3071          $genome_scenarios{$name} = compare_scenario($genome,$superset,$subsystem,$name);          $genome_scenarios{$name} = compare_scenario($genome,$superset,$subsystem,$name,$dont_copy);
3072      }      }
3073    
3074      return \%genome_scenarios;      return \%genome_scenarios;
# Line 3071  Line 3121 
3121    
3122  sub compare_superset  sub compare_superset
3123  {  {
3124      my($genome, $superset_name) = @_;      my($genome, $superset_name, $dont_copy) = @_;
3125    
3126      my @subsystems = @{$superset_to_ss{$superset_name}};      my @subsystems = @{$superset_to_ss{$superset_name}};
3127      my %genome_subsystems;      my %genome_subsystems;
# Line 3079  Line 3129 
3129      foreach my $ss_name (@subsystems)      foreach my $ss_name (@subsystems)
3130      {      {
3131          print STDERR "Comparing Scenarios for $genome in subsystem $ss_name\n";          print STDERR "Comparing Scenarios for $genome in subsystem $ss_name\n";
3132          $genome_subsystems{$ss_name} = compare_subsystem($genome,$superset_name,$ss_name);          $genome_subsystems{$ss_name} = compare_subsystem($genome,$superset_name,$ss_name,$dont_copy);
3133      }      }
3134    
3135      return \%genome_subsystems;      return \%genome_subsystems;
# Line 3111  Line 3161 
3161    
3162  sub compare_supersets  sub compare_supersets
3163  {  {
3164      my($genome) = @_;      my($genome, $dont_copy) = @_;
3165      my %genome_supersets;      my %genome_supersets;
3166    
3167      foreach my $superset (keys %superset_to_ss)      foreach my $superset (keys %superset_to_ss)
3168      {      {
3169          $genome_supersets{$superset} = compare_superset($genome,$superset);          $genome_supersets{$superset} = compare_superset($genome,$superset,$dont_copy);
3170      }      }
3171    
3172      return \%genome_supersets;      return \%genome_supersets;
# Line 3738  Line 3788 
3788      {      {
3789          my $subsystem = $fig->get_subsystem($subsystem_name);          my $subsystem = $fig->get_subsystem($subsystem_name);
3790          next if(!defined $subsystem);          next if(!defined $subsystem);
3791          my $reactions_for_ss = $subsystem->get_hope_reactions_for_genome($genome_id);          my %reactions_for_ss = $subsystem->get_hope_reactions_for_genome($genome_id);
3792          next if(!defined $reactions_for_ss);          next if(!defined %reactions_for_ss);
3793          foreach my $reaction (keys %$reactions_for_ss)          foreach my $reaction (keys %reactions_for_ss)
3794          {          {
3795              if(defined $reaction_to_pegs{$reaction})              if(defined $reaction_to_pegs{$reaction})
3796              {              {
3797                  push @{$reaction_to_pegs{$reaction}} , @{$reactions_for_ss->{$reaction}};                  push @{$reaction_to_pegs{$reaction}} , @{$reactions_for_ss{$reaction}};
3798              }              }
3799              else              else
3800              {              {
3801                  $reaction_to_pegs{$reaction} = $reactions_for_ss->{$reaction};                  $reaction_to_pegs{$reaction} = $reactions_for_ss{$reaction};
3802              }              }
3803          }          }
3804      }      }

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3