32 |
my $filebase = $fig->model_directory($genome_id)."/Analysis/"; |
my $filebase = $fig->model_directory($genome_id)."/Analysis/"; |
33 |
|
|
34 |
my %scenarios_used; |
my %scenarios_used; |
35 |
|
my %scenarios_id; |
36 |
my %all_substrates; |
my %all_substrates; |
37 |
foreach (@scenarios) |
foreach (@scenarios) |
38 |
{ |
{ |
39 |
map {$all_substrates{$_} = 1} @{$_->get_substrates_all()}; |
map {$all_substrates{$_} = 1} @{$_->get_substrates_all()}; |
40 |
$scenarios_used{$_->get_scenario_name()} = 0; |
$scenarios_used{$_->get_scenario_name()} = 0; |
41 |
|
$scenarios_id{$_->get_id()} = 0; |
42 |
} |
} |
43 |
|
|
44 |
my %input_cpds; |
my %input_cpds; |
53 |
} |
} |
54 |
close(INPUTS); |
close(INPUTS); |
55 |
|
|
56 |
|
#ATP Snythase HACK, lets add ATP as a input |
57 |
|
$input_cpds{"C00002"} = 1; |
58 |
|
|
59 |
my %cofactor_cpds; |
my %cofactor_cpds; |
60 |
open(INPUTCO,$filebase."cofactors.txt") |
open(INPUTCO,$filebase."secondary_compounds.txt") |
61 |
or die("Failed to open ".$filebase."cofactors.txt. Run find_model_cofactors $genome_id\n"); |
or die("Failed to open ".$filebase."secondary_compounds.txt. Run find_model_cofactors $genome_id\n"); |
62 |
while(<INPUTCO>) |
while(<INPUTCO>) |
63 |
{ |
{ |
64 |
chomp; |
chomp; |
79 |
$biomass_cpds{$temp[0]} = 1; |
$biomass_cpds{$temp[0]} = 1; |
80 |
} |
} |
81 |
close(BIOMASS); |
close(BIOMASS); |
82 |
|
|
83 |
|
my %compound_id_to_name; |
84 |
|
open(IN,"$FIG_Config::global/Models/compound_id_to_name.txt") or die("Failed to open compound_id_to_name.txt"); |
85 |
|
while($_ = <IN>){ |
86 |
|
chomp($_); |
87 |
|
my($id,$name) = split("\t",$_); |
88 |
|
$compound_id_to_name{$id} = $name; |
89 |
|
} |
90 |
|
close(IN); |
91 |
|
|
92 |
print STDERR "\tStage 1 - Complete\n" if($debug); |
print STDERR "\tStage 1 - Complete\n" if($debug); |
93 |
|
|
94 |
print STDERR "\tStage 2 - Run Analysis Tools (fueled by caffine)\n" if($debug); |
print STDERR "\tStage 2 - Run Analysis Tools (fueled by caffine)\n" if($debug); |
95 |
#Total list of what compounds we reach. |
#Total list of what compounds we reach. |
96 |
my @list_generated = keys %input_cpds; |
my @list_generated = keys %input_cpds; |
97 |
|
push @list_generated , keys %cofactor_cpds; |
98 |
my %possible_problems; |
my %possible_problems; |
99 |
my %good_compounds; |
my %good_compounds; |
100 |
|
|
108 |
$current_inputs{$_} = 1; |
$current_inputs{$_} = 1; |
109 |
} |
} |
110 |
my %current_cofactors; |
my %current_cofactors; |
|
my %previous_inputs; |
|
111 |
foreach (keys %cofactor_cpds) |
foreach (keys %cofactor_cpds) |
112 |
{ |
{ |
113 |
$current_cofactors{$_} = 1; |
$current_cofactors{$_} = 1; |
115 |
|
|
116 |
while(scalar(keys %current_inputs)) |
while(scalar(keys %current_inputs)) |
117 |
{ |
{ |
118 |
my ($temp_in,$temp_co) = generate_new_inputs(\%current_inputs,\%current_cofactors); |
my ($temp_in,$temp_co,$break) = generate_new_inputs(\%current_inputs,\%current_cofactors); |
|
#Check to make sure we have a different compound |
|
|
my $break = 1; |
|
|
foreach my $key (keys %$temp_in) |
|
|
{ |
|
|
if(!defined $current_inputs{$key} && !defined $previous_inputs{$key}) |
|
|
{ |
|
|
$break = 0; |
|
|
} |
|
|
} |
|
|
if($break) { last;} #break the while loop, we are looping |
|
|
|
|
|
undef %previous_inputs; |
|
|
map {$previous_inputs{$_} = 1;} sort keys %current_inputs; |
|
119 |
|
|
120 |
#undef %current_inputs; |
map {$current_inputs{$_} = 1;} keys %$temp_in; |
121 |
map {$current_inputs{$_} = 1;} sort keys %$temp_in; |
map {$current_cofactors{$_} = 1;} keys %$temp_co; |
|
|
|
|
#undef %current_cofactors; |
|
|
map {$current_cofactors{$_} = 1;} sort keys %$temp_co; |
|
122 |
|
|
123 |
push @list_generated, keys %$temp_in; |
push @list_generated, keys %$temp_in; |
124 |
push @list_generated, keys %$temp_co; |
push @list_generated, keys %$temp_co; |
125 |
|
|
126 |
|
print STDERR "Rechecking with inputs\n" if($debug); |
127 |
|
if($break) |
128 |
|
{ |
129 |
|
last; |
130 |
} |
} |
131 |
|
} |
132 |
|
print STDERR "Finished checking scenarios\n" if($debug); |
133 |
foreach my $found (@list_generated) |
foreach my $found (@list_generated) |
134 |
{ |
{ |
135 |
if(defined $biomass_cpds{$found}) |
if(defined $biomass_cpds{$found}) |
188 |
{ |
{ |
189 |
if($biomass_cpds{$_} != 2) |
if($biomass_cpds{$_} != 2) |
190 |
{ |
{ |
191 |
print RESULTS "Biomass $_ failed to be generated using inputs.txt\n"; |
print RESULTS "Biomass $_ $compound_id_to_name{$_} failed to be generated using inputs.txt\n"; |
192 |
} |
} |
193 |
else |
else |
194 |
{ |
{ |
195 |
print OUT "$_\n"; |
print OUT "$_\t$compound_id_to_name{$_}\n"; |
196 |
} |
} |
197 |
} |
} |
198 |
close(RESULTS); |
close(RESULTS); |
219 |
close(SCEN_RESULTS); |
close(SCEN_RESULTS); |
220 |
close(OUT); |
close(OUT); |
221 |
|
|
222 |
open(RESULTS_INPUT,">".$filebase."info_inputs.txt"); |
#open(RESULTS_INPUT,">".$filebase."info_inputs.txt"); |
223 |
foreach (sort keys %possible_problems) |
#foreach (sort keys %possible_problems) |
224 |
{ |
#{ |
225 |
if($possible_problems{$_} == 1 && !defined $good_compounds{$_}) |
# if($possible_problems{$_} == 1 && !defined $good_compounds{$_}) |
226 |
{ |
# { |
227 |
print RESULTS_INPUT "Input $_ may be a false-positive. Perhaps a Scenario should generate this.\n"; |
# print RESULTS_INPUT "Input $_ may be a false-positive. Perhaps a Scenario should generate this.\n"; |
228 |
} |
# } |
229 |
} |
#} |
230 |
close(RESULTS_INPUT); |
#close(RESULTS_INPUT); |
231 |
|
|
232 |
print STDERR "\tStage 2 - Complete! Results in info_inputs.txt, info_biomass.txt and info_scenarios.txt\n" if($debug); |
print STDERR "\tStage 2 - Complete! Results in info_inputs.txt, info_biomass.txt and info_scenarios.txt\n" if($debug); |
233 |
|
|
236 |
my ($inputs,$cofactors) = @_; |
my ($inputs,$cofactors) = @_; |
237 |
my %new_inputs; |
my %new_inputs; |
238 |
my %new_cofactors; |
my %new_cofactors; |
239 |
|
my $break = 1; |
240 |
foreach my $scenario (@scenarios) |
foreach my $scenario (@scenarios) |
241 |
{ |
{ |
242 |
|
if($scenarios_id{$scenario->get_id()} == 1) |
243 |
|
{ |
244 |
|
next; |
245 |
|
} |
246 |
my $count = 0; |
my $count = 0; |
247 |
foreach my $substrate (@{$scenario->get_substrates_all()}) |
foreach my $substrate (@{$scenario->get_substrates_all()}) |
248 |
{ |
{ |
263 |
else |
else |
264 |
{ |
{ |
265 |
print STDERR "Scenario ".$scenario->get_scenario_name()." ran.\n" if($debug); |
print STDERR "Scenario ".$scenario->get_scenario_name()." ran.\n" if($debug); |
266 |
|
$break = 0; |
267 |
### here we want to mark what inputs we used |
$scenarios_id{$scenario->get_id()} = 1; |
|
foreach (@{$scenario->get_substrates()}) |
|
|
{ |
|
|
$inputs->{$_} = 2; |
|
|
} |
|
|
|
|
268 |
$scenarios_used{$scenario->get_scenario_name()} = 1; |
$scenarios_used{$scenario->get_scenario_name()} = 1; |
269 |
foreach my $product (@{$scenario->get_products()}) |
foreach my $product (@{$scenario->get_products()}) |
270 |
{ |
{ |
276 |
} |
} |
277 |
} |
} |
278 |
} |
} |
279 |
#Add any inputs that aren't used to the return again |
return (\%new_inputs,\%new_cofactors,$break); |
|
foreach (keys %$inputs) |
|
|
{ |
|
|
if($inputs->{$_} !=2) |
|
|
{ |
|
|
$new_inputs{$_} = 1; |
|
|
} |
|
|
} |
|
|
|
|
|
return (\%new_inputs,\%new_cofactors); |
|
280 |
} |
} |