-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosa_create_table.py
120 lines (108 loc) · 6.11 KB
/
cosa_create_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""Creates csv tables from the random specificity sampling."""
# IMPORTS #
# External
from typing import Tuple
# Internal
from helper import get_files, json_zip_load
# PUBLIC FUNCTIONS #
def create_cosa_tables(data_path: str, output_path: str, concentration_scenarios: Tuple[str]) -> None:
"""Create tables from the random specificity sampling.
Args:
data_path (str): The folder where the single result calculation results are stored as zipped JSON files.
output_path (str): Path to the directory where the csv shall be stored.
concentration_scenarios (Tuple[str]): The names of the tested concentration scenarios.
"""
filepaths = get_files(data_path)
filepaths = [data_path+"/"+x for x in filepaths]
for concentration_scenario in concentration_scenarios:
optmdf_results = {}
optsubmdf_results = {}
for filepath in filepaths:
concentration_part = f"_{concentration_scenario}_"
if concentration_part not in filepath:
continue
nadx_scenario = filepath.split(concentration_part)[1].split(".")[0]
jsondata = json_zip_load(filepath.replace(".zip", ""))
for rounded_used_growth in jsondata.keys():
if "OPTSUBMDF_" in filepath:
if rounded_used_growth not in optsubmdf_results:
optsubmdf_results[rounded_used_growth] = {}
optsubmdf_results[rounded_used_growth][nadx_scenario] = str(
-round(jsondata[rounded_used_growth]["objective_value"], 3)
).replace(".", ",")
elif "OPTMDF_" in filepath:
if rounded_used_growth not in optmdf_results:
optmdf_results[rounded_used_growth] = {}
optmdf_results[rounded_used_growth][nadx_scenario] = str(
-round(jsondata[rounded_used_growth]["objective_value"], 3)
).replace(".", ",")
print(">Generate OPTMDF table")
csv_string = "µ [1/h]" + "\t" + "\t".join([str(growth_rate) for growth_rate in optmdf_results[list(optmdf_results.keys())[0]].keys()]) + "\n"
for growth_rate in optmdf_results.keys():
print_output = f"{growth_rate}"
for in_vivo_key in optmdf_results[growth_rate].keys():
print_output += f"\t{optmdf_results[growth_rate][in_vivo_key]}"
print_output += "\n"
csv_string += print_output
with open(f"{output_path}/optmdf_table_{concentration_scenario}.csv", "w", encoding="utf-8") as f:
f.write(csv_string)
print(">Generating SubMDF table")
print(optsubmdf_results)
print(concentration_scenario)
csv_string = "µ [1/h]" + "\t" + "\t".join([str(growth_rate) for growth_rate in optsubmdf_results[list(optsubmdf_results.keys())[0]].keys()]) + "\n"
for growth_rate in optsubmdf_results.keys():
print_output = f"{growth_rate}"
for in_vivo_key in optsubmdf_results[growth_rate].keys():
print_output += f"\t{optsubmdf_results[growth_rate][in_vivo_key]}"
print_output += "\n"
csv_string += print_output
with open(f"{output_path}/optsubmdf_table_{concentration_scenario}.csv", "w", encoding="utf-8") as f:
f.write(csv_string)
def create_cosa_dG0_sampling_tables(data_path: str, output_path: str) -> None:
filepaths = get_files(data_path)
filepaths = [data_path+"/"+x for x in filepaths]
for concentration_scenario in ("STANDARDCONC",): # "VIVOCONC"):
optmdf_results = {}
optsubmdf_results = {}
for filepath in filepaths:
concentration_part = f"_{concentration_scenario}_"
if concentration_part not in filepath:
continue
nadx_scenario = filepath.split(concentration_part)[1].split(".")[0]
jsondata = json_zip_load(filepath.replace(".zip", ""))
for rounded_used_growth in jsondata.keys():
if "OPTSUBMDF_" in filepath:
if rounded_used_growth not in optsubmdf_results:
optsubmdf_results[rounded_used_growth] = {}
optsubmdf_results[rounded_used_growth][nadx_scenario] = str(
-round(jsondata[rounded_used_growth]["objective_value"], 3)
).replace(".", ",")
elif "OPTMDF_" in filepath:
if rounded_used_growth not in optmdf_results:
optmdf_results[rounded_used_growth] = {}
optmdf_results[rounded_used_growth][nadx_scenario] = str(
-round(jsondata[rounded_used_growth]["objective_value"], 3)
).replace(".", ",")
print(">Generate OPTMDF table")
print("A", list(optmdf_results.keys()))
csv_string = "µ [1/h]" + "\t" + "\t".join([str(growth_rate) for growth_rate in optmdf_results[list(optmdf_results.keys())[0]].keys()]) + "\n"
for growth_rate in optmdf_results.keys():
print_output = f"{growth_rate}"
for in_vivo_key in optmdf_results[growth_rate].keys():
print_output += f"\t{optmdf_results[growth_rate][in_vivo_key]}"
print_output += "\n"
csv_string += print_output
with open(f"{output_path}/optmdf_table_{concentration_scenario}.csv", "w", encoding="utf-8") as f:
f.write(csv_string)
print(">Generating SubMDF table")
print(optsubmdf_results)
print(concentration_scenario)
csv_string = "µ [1/h]" + "\t" + "\t".join([str(growth_rate) for growth_rate in optsubmdf_results[list(optsubmdf_results.keys())[0]].keys()]) + "\n"
for growth_rate in optsubmdf_results.keys():
print_output = f"{growth_rate}"
for in_vivo_key in optsubmdf_results[growth_rate].keys():
print_output += f"\t{optsubmdf_results[growth_rate][in_vivo_key]}"
print_output += "\n"
csv_string += print_output
with open(f"{output_path}/optsubmdf_table_{concentration_scenario}.csv", "w", encoding="utf-8") as f:
f.write(csv_string)