[Bio] / FigKernelScripts / find_model_information_v2.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/find_model_information_v2.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : mkubal 1.1 ## _*_ Perl _*_
2 :    
3 :    
4 :     use FIGV;
5 :     use Scenario;
6 :     use strict;
7 :    
8 :     my ($genome_id, $type, $orgdir) = @ARGV;
9 :    
10 :     my $debug = 0;
11 :    
12 :     unless (scalar( @ARGV) >= 2)
13 :     {
14 :     print STDERR "\nusage: find_model_information <genome_id> <inputs|outputs|biomass>\n";
15 :     exit(-1);
16 :     }
17 :     chomp $genome_id;
18 :    
19 :     #check for proper input on variable $type
20 :     unless($type eq 'inputs' || $type eq 'outputs' || $type eq 'biomass')
21 :     {
22 :     print STDERR "\nSecond parameter required in format: 'outputs','inputs' or 'biomass'\n";
23 :     exit(-1);
24 :     }
25 :     my $fig;
26 :     if($orgdir)
27 :     {
28 :     $fig = new FIGV($orgdir);
29 :     }
30 :     else
31 :     {
32 :     $fig = new FIGV;
33 :     }
34 :    
35 :     Scenario::set_fig($fig,$genome_id);
36 :     my @scenarios = @{Scenario->get_genome_scenarios($genome_id,0)};
37 :    
38 :     my %compound_id_to_name;
39 :     open(IN,"$FIG_Config::global/Models/compound_id_to_name.txt") or die("Failed to open compound_id_to_name.txt");
40 :     while($_ = <IN>){
41 :     chomp($_);
42 :     my($id,$name) = split("\t",$_);
43 :     $compound_id_to_name{$id} = $name;
44 :     }
45 :     close(IN);
46 :    
47 :     my %inputs;
48 :     my %outputs;
49 :    
50 :     open(SM,"$FIG_Config::global/Models/standard_medium_lib.txt")
51 :     or die("Failed to open $FIG_Config::global/Models/standard_medium_lib.txt ");
52 :     while(<SM>)
53 :     {
54 :     chomp;
55 :     $inputs{$_} = 1;
56 :     }
57 :     close(SM);
58 :    
59 :    
60 :     foreach my $scenario (@scenarios)
61 :     {
62 :     #map {$inputs{$_} = 1} @{$scenario->get_substrates_all()};
63 :     map {$outputs{$_} = 1} @{$scenario->get_products_all()};
64 :     #Uncomment this line of code if you want to see what scenario a cpd is being referenced from
65 :     # Make sure you comment the previous line out if you do this
66 :     #map {$outputs{$_} = $scenario->get_id()} @{$scenario->get_products_all()};
67 :     }
68 :    
69 :     my $libbase = "$FIG_Config::global/Models/";
70 :     my $filebase = $fig->model_directory($genome_id)."/Analysis/";
71 :    
72 :    
73 :    
74 :    
75 :     if($type eq 'inputs')
76 :     {
77 :    
78 :     open(MODEL_INPUTS,">".$filebase."inputs.txt");
79 :     foreach my $input (keys %inputs){print MODEL_INPUTS "$input\n";}
80 :     close(MODEL_INPUTS);
81 :     =pod
82 :     my $results = generate_resource($type,$libbase."standard_medium_lib.txt",\%inputs);
83 :     #Lets run a additional check to see if any biomass cpds are taken up directly
84 :     # Note - This check removed because we are going for generalized models
85 :     # not all inputs like this type are appropriate for most organisms.
86 :     #open(BIO,$filebase."biomass.txt");
87 :     while(<BIO>)
88 :     {
89 :     chomp;
90 :     my @items = split "\t" , $_;
91 :     chomp @items;
92 :     if($inputs{$items[0]})
93 :     {
94 :     delete $results->{$items[0]};
95 :     }
96 :     }
97 :     close(BIO);
98 :     print_resource($type,$results,\%inputs) if($debug);
99 :     output_resource($type,$results,$genome_id);
100 :     =cut
101 :     }
102 :    
103 :     if($type eq 'outputs')
104 :     {
105 :     my $results = generate_resource($type,$libbase."transports_out.txt",\%outputs);
106 :     print_resource($type,$results,\%outputs) if($debug);
107 :     output_resource($type,$results,$genome_id);
108 :     }
109 :     if($type eq 'biomass')
110 :     {
111 :     my $results = generate_resource($type,$libbase."ec_biomass.txt",\%outputs);
112 :     #filter results for trouble compounds
113 :     open(TRB,$libbase."trouble_cpds.txt");
114 :     while(<TRB>)
115 :     {
116 :     chomp;
117 :     if(/\#/) {next;}
118 :     my @temp = split "\t" , $_;
119 :     chomp @temp;
120 :     my ($cpd_1,$cpd_2,$reason) = @temp;
121 :     if($results->{$cpd_1} && $results->{$cpd_2})
122 :     {
123 :     delete $results->{$cpd_2};
124 :     print STDERR "Removing $cpd_2 from possible biomass due to $reason\n" if($debug);
125 :     }
126 :     }
127 :     close(TRB);
128 :     print_resource($type,$results,\%outputs) if($debug);
129 :     output_resource($type,$results,$genome_id);
130 :     }
131 :    
132 :     sub generate_resource
133 :     {
134 :     my ($type,$resource_lib,$resource_hash) = @_;
135 :     my %likely_compounds;
136 :    
137 :     open(RES_LIB, $resource_lib);
138 :     while(<RES_LIB>)
139 :     {
140 :     chomp;
141 :     my @temp = split "\t" , $_;
142 :     if(defined $resource_hash->{$temp[0]} && $temp[0] ne "")
143 :     {
144 :     $likely_compounds{$temp[0]} = $resource_hash->{$temp[0]};
145 :     # A print statment for debugging. If you enable this above, uncomment this line
146 :     #print "$temp[0] was found generated from $resource_hash->{$temp[0]}\n";
147 :     delete $resource_hash->{$temp[0]};
148 :     }
149 :     }
150 :     close(RES_LIB);
151 :     return \%likely_compounds;
152 :     }
153 :    
154 :     sub print_resource
155 :     {
156 :     my ($type,$results_hash,$resource_hash) = @_;
157 :     print STDERR "\nLeft over $type :\n";
158 :     print STDERR map { $_." $resource_hash->{$_}\n" } sort keys %{$resource_hash};
159 :     print STDERR "\nLikely $type based on previous $type lib :\n";
160 :     print STDERR map { $_." $results_hash->{$_}\n" } sort keys %{$results_hash};
161 :     }
162 :    
163 :     sub output_resource
164 :     {
165 :     my ($type,$results_hash,$genome_id) = @_;
166 :     my $location = $fig->model_directory($genome_id)."/Analysis/";
167 :     #Make the Analysis directory if it doesn't exist
168 :     mkdir($location);
169 :     open(OUTPUT,">",$location.$type.".txt") or
170 :     die("Failed to create file ".$location.$type.".txt");
171 :     print OUTPUT map { $_."\t$compound_id_to_name{$_}\n" } sort keys %{$results_hash};
172 :     close(OUTPUT);
173 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3