-
Notifications
You must be signed in to change notification settings - Fork 0
/
RefrFBA_E1.py
executable file
·69 lines (60 loc) · 2.15 KB
/
RefrFBA_E1.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 4 12:24:06 2020
@author: Silvia Talavera Marcos
"""
from reframed import load_cbmodel
import os
from reframed import FBA, Environment
from carveme.reconstruction.utils import load_media_db
import statistics as stats
import pandas as pd
wd = "/home/urihs/Desktop/TFM_private/08_reframed/sin_gapfill/"
models = {}
for medium in os.listdir(wd):
models[medium] = {}
for node in os.listdir(wd+medium):
if "Node" in node:
models[medium][node] = {}
else:
continue
for sbml in os.listdir(wd+medium+"/"+node):
if ".xml" in sbml:
models[medium][node][sbml]=wd+medium+"/"+node+"/"+sbml
media_db = load_media_db("/home/urihs/Desktop/TFM_private/08_reframed/test_media.txt", compound_col="compound")
results = [] # lista de listas que finalmente dará un dataframe/csv con todos los datos
for medium in models.keys():
medio = "M9["+medium+"]"
# medio = "LB"
init_env = Environment.from_compounds(media_db[medio])
print("\nMedio: "+medio+"\nNodos de: "+medium+"\n==============")
media = 0
listofkeys = list(models[medium].keys())
listofkeys.sort()
for node in listofkeys:
media_prev = 0+media
print("Nodo: "+node+"\n===============")
total=[]
n=0# para hacer la media de solution.fobj
for f in models[medium][node]:
model = load_cbmodel(models[medium][node][f],flavor="fbc2")
init_env.apply(model)
solution = FBA(model, objective="Growth", get_values=False)
print(solution)
if solution.fobj!=0:
n+=1
total.append(solution.fobj)
results.append([medium,node,f,solution.fobj])
try:
media = sum(total)/n
print("media del nodo: ", media)
print("desviacion típica: ", stats.stdev(total),"\n")
except:
pass
try:
print("RATIO : ",media_prev/media)
except:
pass
all_data=pd.DataFrame(results,columns=["Medio","Nodo","Modelo","Crecimiento"])
all_data.to_csv("report_reframed.csv",index=False)