[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.1, Tue May 15 21:14:31 2007 UTC revision 1.2, Thu May 17 16:46:24 2007 UTC
# Line 238  Line 238 
238      }      }
239    
240      print STDERR "Inputs :\n" if $debug;      print STDERR "Inputs :\n" if $debug;
241      print STDERR map { $_."\n" } keys %all_inputs;      print STDERR map { $_."\n" } keys %all_inputs if $debug;
242      print STDERR "Outputs:\n" if $debug;      print STDERR "Outputs:\n" if $debug;
243      print STDERR map { $_."\n" } keys %all_outputs;      print STDERR map { $_."\n" } keys %all_outputs if $debug;
244    
245      #filter the input/outputs lists, removing the intersection unless something      #filter the input/outputs lists, removing the intersection unless something
246      # is a known cycle      # is a known cycle
# Line 266  Line 266 
266  {  {
267      my ($substrates_to_reactions, $products_to_reactions,      my ($substrates_to_reactions, $products_to_reactions,
268          $reactions_to_substrates, $reactions_to_products) = @_;          $reactions_to_substrates, $reactions_to_products) = @_;
269      print STDERR "building SS reactions\n";      print STDERR "building SS reactions\n" if $debug;
270      # use subsystem reactions      # use subsystem reactions
271      foreach my $drxn (map { ($_."_L", $_."_R") } keys %all_reactions)      foreach my $drxn (map { ($_."_L", $_."_R") } keys %all_reactions)
272      {      {
# Line 2680  Line 2680 
2680  {  {
2681      my ($genome,$ssa,$scenario,$find_first) = @_;      my ($genome,$ssa,$scenario,$find_first) = @_;
2682    
2683      print STDERR "\nIn internal_scenario with '$genome', '$ssa', '$scenario', '$find_first'\n";      print STDERR "\nIn internal_scenario with '$genome', '$ssa', '$scenario', '$find_first'\n" if $debug;
2684    
2685      load_scenario($genome,$ssa,$scenario);      load_scenario($genome,$ssa,$scenario);
2686    
# Line 2691  Line 2691 
2691  {  {
2692      my($genome,$superset,$subsystem,$scenario,$find_first) = @_;      my($genome,$superset,$subsystem,$scenario,$find_first) = @_;
2693      my $scenario_dir = "$FIG_Config::var/Models/$genome/$superset/$subsystem/$scenario";      my $scenario_dir = "$FIG_Config::var/Models/$genome/$superset/$subsystem/$scenario";
2694      `rm -rf $scenario_dir`;  
2695        system("rm", "-rf", $scenario_dir);
2696    
2697      mkdir "$FIG_Config::var/Models/$genome/";      mkdir "$FIG_Config::var/Models/$genome/";
2698      mkdir "$FIG_Config::var/Models/$genome/$superset";      mkdir "$FIG_Config::var/Models/$genome/$superset";
2699      mkdir "$FIG_Config::var/Models/$genome/$superset/$subsystem";      mkdir "$FIG_Config::var/Models/$genome/$superset/$subsystem";
# Line 2702  Line 2704 
2704      write_scenario(internal_scenario($genome,$subsystem,$scenario,$find_first),$scenario_dir);      write_scenario(internal_scenario($genome,$subsystem,$scenario,$find_first),$scenario_dir);
2705  }  }
2706    
2707    sub compare_scenario
2708    {
2709        my($genome,$superset,$ss_name,$scenario_name) = @_;
2710        my @genome_paths;
2711        my $scenario_dir_all = "$FIG_Config::temp/All/$superset/$ss_name/$scenario_name";
2712        my $subsystem = $fig->get_subsystem($ss_name);
2713        my @additional_reactions = @{$subsystem->get_hope_additional_reactions($scenario_name)};
2714        my %additional_reactions;
2715        map { $additional_reactions{$_} = 1 } @additional_reactions;
2716        my @roles = $subsystem->get_roles;
2717        my %hope_reactions = %{$subsystem->get_hope_reactions};
2718    
2719        my $valid_genome = 0;
2720        #determine if this genome has this subsystem
2721        my @genome_array = $subsystem->get_genomes();
2722        foreach my $organ (@genome_array)
2723        {
2724            if($organ eq $genome || $genome eq "All" )
2725            {
2726                $valid_genome = 1;
2727                last;
2728            }
2729        }
2730    
2731        my %ss_reactions;
2732    
2733        foreach my $role (@roles)
2734        {
2735            if ($valid_genome && defined $hope_reactions{$role} &&
2736                ($genome eq "All" || $subsystem->get_pegs_from_cell($genome,$role) > 0))
2737            {
2738                map { $ss_reactions{$_} = 1 } @{$hope_reactions{$role}};
2739            }
2740        }
2741    
2742        # first find paths in the All directory that should be valid for the genome
2743        # based on the reactions associated with it in the subsystems
2744        opendir (DIR_ALL,$scenario_dir_all) or die("$scenario_dir_all");
2745        my @sub_dirs  = readdir DIR_ALL; shift @sub_dirs; shift @sub_dirs; # get rid of . and ..
2746        close DIR_ALL;
2747    
2748        my %paths_all;
2749    
2750        for my $path (@sub_dirs)
2751        {
2752            my $match = 1;
2753            open (PATH, "$scenario_dir_all/$path/path_info");
2754            my @reactions = <PATH>;
2755            close PATH;
2756    
2757            my $reaction_string = "";
2758    
2759            foreach my $reaction (sort @reactions)
2760            {
2761                if ($reaction =~ /(R\d\d\d\d\d)/)
2762                {
2763                    $reaction_string .= $reaction;
2764    
2765                    if (! exists($ss_reactions{$1}) && ! exists($additional_reactions{$1}))
2766                    {
2767                        $match = 0;
2768                    }
2769                }
2770            }
2771    
2772            $paths_all{$reaction_string} = $match;
2773            push @genome_paths, $path if $match;
2774        }
2775    
2776        # now check all paths found for this particular organism, and make sure they
2777        # are in the appropriate All subdirectory
2778        my $scenario_dir_genome = "$FIG_Config::temp/$genome/$superset/$ss_name/$scenario_name";
2779    
2780        opendir (DIR_GENOME,$scenario_dir_genome) or die("$scenario_dir_genome");
2781        @sub_dirs  = readdir DIR_GENOME; shift @sub_dirs; shift @sub_dirs; # get rid of . and ..
2782        close DIR_GENOME;
2783    
2784        my $path_counter = scalar keys %paths_all;
2785    
2786        for my $path (@sub_dirs)
2787        {
2788            my $match = 1;
2789            open (PATH, "$scenario_dir_genome/$path/path_info");
2790            my @reactions = <PATH>;
2791            close PATH;
2792    
2793            my $reaction_string = "";
2794    
2795            foreach my $reaction (sort @reactions)
2796            {
2797                if ($reaction =~ /(R\d\d\d\d\d)/)
2798                {
2799                    $reaction_string .= $reaction;
2800                }
2801            }
2802    
2803            if (! exists($paths_all{$reaction_string}))
2804            {
2805                $path_counter++;
2806                my $new_path_name = "path_".$path_counter;
2807                my $temp_sdg = $scenario_dir_genome;
2808                $temp_sdg =~ s/\(/\\\(/g;
2809                $temp_sdg =~ s/\)/\\\)/g;
2810                my $temp_sda = $scenario_dir_all;
2811                $temp_sda =~ s/\(/\\\(/g;
2812                $temp_sda =~ s/\)/\\\)/g;
2813                `cp -R $temp_sdg/$path $temp_sda/$new_path_name`;
2814                push @genome_paths, $new_path_name;
2815                print "Copied $temp_sdg/$path to $temp_sda/$new_path_name\n";
2816            }
2817        }
2818    
2819    
2820        return \@genome_paths;
2821    }
2822    
2823  sub write_scenario  sub write_scenario
2824  {  {
2825      my($scenario_data,$scenario_dir) = @_;      my($scenario_data,$scenario_dir) = @_;
# Line 2860  Line 2978 
2978      my $subsystem_obj = $fig->get_subsystem($subsystem);      my $subsystem_obj = $fig->get_subsystem($subsystem);
2979      my @ss_scenarios = $subsystem_obj->get_hope_scenario_names;      my @ss_scenarios = $subsystem_obj->get_hope_scenario_names;
2980    
2981      `rm -rf $FIG_Config::var/Models/$genome/$superset/$subsystem`;      system("rm", "-rf",  "$FIG_Config::var/Models/$genome/$superset/$subsystem");
2982      mkdir "$FIG_Config::var/Models/$genome/";      mkdir "$FIG_Config::var/Models/$genome/";
2983      mkdir "$FIG_Config::var/Models/$genome/$superset";      mkdir "$FIG_Config::var/Models/$genome/$superset";
2984      mkdir "$FIG_Config::var/Models/$genome/$superset/$subsystem";      mkdir "$FIG_Config::var/Models/$genome/$superset/$subsystem";
# Line 2871  Line 2989 
2989      }      }
2990  }  }
2991    
2992    sub compare_subsystem
2993    {
2994        my ($genome,$superset,$subsystem) = @_;
2995        my %genome_scenarios;
2996    
2997        my $subsystem_obj = $fig->get_subsystem($subsystem);
2998        my @ss_scenarios = $subsystem_obj->get_hope_scenario_names;
2999    
3000        foreach my $name (@ss_scenarios)
3001        {
3002            $genome_scenarios{$name} = compare_scenario($genome,$superset,$subsystem,$name);
3003        }
3004    
3005        return \%genome_scenarios;
3006    }
3007    
3008  sub load_superset  sub load_superset
3009  {  {
3010      my($genome, $superset_name) = @_;      my($genome, $superset_name) = @_;
# Line 2915  Line 3049 
3049      }      }
3050  }  }
3051    
3052    sub compare_superset
3053    {
3054        my($genome, $superset_name) = @_;
3055    
3056        my @subsystems = @{$superset_to_ss{$superset_name}};
3057        my %genome_subsystems;
3058    
3059        foreach my $ss_name (@subsystems)
3060        {
3061            print STDERR "Comparing Scenarios for $genome in subsystem $ss_name\n";
3062            $genome_subsystems{$ss_name} = compare_subsystem($genome,$superset_name,$ss_name);
3063        }
3064    
3065        return \%genome_subsystems;
3066    }
3067    
3068    
3069  sub load_supersets  sub load_supersets
3070  {  {
# Line 2939  Line 3089 
3089    
3090  }  }
3091    
3092    sub compare_supersets
3093    {
3094        my($genome) = @_;
3095        my %genome_supersets;
3096    
3097        foreach my $superset (keys %superset_to_ss)
3098        {
3099            $genome_supersets{$superset} = compare_superset($genome,$superset);
3100        }
3101    
3102        return \%genome_supersets;
3103    }
3104    
3105  sub run_genome_report  sub run_genome_report
3106  {  {
3107      my ($genome) = @_;      my ($genome) = @_;
# Line 2988  Line 3151 
3151      my ($paths,$input_path,$output_path,$one_path) = @_;      my ($paths,$input_path,$output_path,$one_path) = @_;
3152    
3153    
3154      print STDERR $paths."\n";      print STDERR $paths."\n" if $debug;
3155      clear_arrays();      clear_arrays();
3156    
3157      #This gets us an array of arrays, each subarray holds      #This gets us an array of arrays, each subarray holds
# Line 3042  Line 3205 
3205      map { $all_compounds_to_main{$_} = 1 } keys %all_outputs;      map { $all_compounds_to_main{$_} = 1 } keys %all_outputs;
3206    
3207      print STDERR "Inputs: " if $debug;      print STDERR "Inputs: " if $debug;
3208      print STDERR map { $_."\n" } keys %all_inputs;      print STDERR map { $_."\n" } keys %all_inputs if $debug;
3209      print STDERR "Outputs: " if $debug;      print STDERR "Outputs: " if $debug;
3210      print STDERR map { $_."\n" } keys %all_outputs;      print STDERR map { $_."\n" } keys %all_outputs if $debug;
3211    
3212      #run process paths      #run process paths
3213      return execute_paths(\@assembly_scenarios,$one_path,\@input_arr,\@output_arr);      return execute_paths(\@assembly_scenarios,$one_path,\@input_arr,\@output_arr);
# Line 3171  Line 3334 
3334      #setup the filesystem to store the scenario/paths      #setup the filesystem to store the scenario/paths
3335      my $superset = $ss_to_superset{$ssa};      my $superset = $ss_to_superset{$ssa};
3336      my $base_dir = "$FIG_Config::var/Models/$genome/$superset/$ssa/$sc_name/";      my $base_dir = "$FIG_Config::var/Models/$genome/$superset/$ssa/$sc_name/";
3337      `rm -rf $base_dir`;      system("rm", "-rf", $base_dir);
3338      mkdir "$FIG_Config::var/Models/$genome";      mkdir "$FIG_Config::var/Models/$genome";
3339      mkdir "$FIG_Config::var/Models/$genome/$superset";      mkdir "$FIG_Config::var/Models/$genome/$superset";
3340      mkdir "$FIG_Config::var/Models/$genome/$superset/$ssa/";      mkdir "$FIG_Config::var/Models/$genome/$superset/$ssa/";

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3