Skip to content

Commit e5f0403

Browse files
committed
Robustness increased
1 parent 1cce1b9 commit e5f0403

File tree

7 files changed

+646
-533
lines changed

7 files changed

+646
-533
lines changed

BOFdat/dna.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _convert_to_coefficient(model, ratio_genome, CELL_WEIGHT, DNA_RATIO):
6969
DNA_coefficients = dict(zip(metabolites,coefficients))
7070
return DNA_coefficients
7171

72-
def generate_coefficients(path_to_fasta, path_to_model, CELL_WEIGHT=280, DNA_WEIGHT_FRACTION=0.031):
72+
def generate_coefficients(path_to_fasta, path_to_model , DNA_WEIGHT_FRACTION=0.031):
7373
"""
7474
Generates a dictionary of metabolite:coefficients for the 4 DNA bases from the organism's
7575
DNA fasta file and the weight percentage of DNA in the cell.
@@ -78,12 +78,11 @@ def generate_coefficients(path_to_fasta, path_to_model, CELL_WEIGHT=280, DNA_WEI
7878
7979
:param path_to_model: a path to the model, format supported are json and xml
8080
81-
:param CELL_WEIGHT: experimentally measured cell weight in femtograms, float
82-
8381
:param DNA_RATIO: the ratio of DNA in the entire cell
8482
8583
:return: a dictionary of metabolites and coefficients
8684
"""
85+
CELL_WEIGHT = 280
8786
if DNA_WEIGHT_FRACTION > 1.:
8887
raise Exception('WEIGHT FRACTION should be a number between 0 and 1')
8988
#Operations

BOFdat/lipid.py

Lines changed: 196 additions & 137 deletions
Large diffs are not rendered by default.

BOFdat/maintenance.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@
99
2- Estimate GAM and NGAM from theorical values
1010
1111
"""
12+
def _import_model(path_to_model):
13+
import cobra
14+
extension = path_to_model.split('.')[-1]
15+
if extension == 'json':
16+
return cobra.io.load_json_model(path_to_model)
17+
elif extension == 'xml':
18+
return cobra.io.read_sbml_model(path_to_model)
19+
else:
20+
raise Exception('Model format not compatible, provide xml or json')
21+
22+
def _import_data(path_to_data):
23+
import pandas as pd
24+
import warnings
25+
26+
data = pd.read_csv(path_to_data)
27+
'''
28+
#1- This file should have a header
29+
for i in data.columns:
30+
try:
31+
float(i)
32+
raise ValueError('Provide file header')
33+
except:
34+
pass
35+
'''
36+
return data
1237

1338
def experimental_maintenance(path_to_data, path_to_model,show_GAM=False):
1439
"""
@@ -29,26 +54,13 @@ def experimental_maintenance(path_to_data, path_to_model,show_GAM=False):
2954

3055
#From experimental data growth rate on a given carbon source
3156
#Obtain best fit from model to experimental data
32-
def import_model(path_to_model):
33-
import cobra
34-
extension = path_to_model.split('.')[-1]
35-
if extension == 'json':
36-
return cobra.io.load_json_model(path_to_model)
37-
elif extension == 'xml':
38-
return cobra.io.read_sbml_model(path_to_model)
39-
40-
def import_data(path_to_data):
41-
import pandas as pd
42-
return pd.read_csv(path_to_data)
43-
4457
def get_carbon_sources(data):
4558
return [c for c in data.Source]
4659

4760
def attribute_colors(data,carbon_sources):
4861
# Attribute colors to carbon sources for ploting
4962
# Set a color palette
5063
import seaborn as sb
51-
5264
color_palette = sb.color_palette('deep',len(carbon_sources))
5365
data['color'] = ''
5466
for i in len(carbon_sources):
@@ -190,7 +202,7 @@ def show_gam(raw_GAM):
190202
import seaborn as sns
191203
import numpy as np
192204
import matplotlib.pyplot as plt
193-
205+
sns.set_style('whitegrid')
194206
x = raw_GAM['Growth_rate']
195207
y = raw_GAM['ATP']
196208
#Fit with np.polyfit
@@ -205,7 +217,8 @@ def show_gam(raw_GAM):
205217
print('R2=', correlation ** 2)
206218
plt.scatter(raw_GAM['Growth_rate'], raw_GAM['ATP'])
207219
# plt.scatter(filtered_data['GR'],filtered_data['ATP'], color=filtered_data['color'], marker=filtered_data['marker'].tolist())
208-
220+
plt.ylabel('ATP')
221+
plt.xlabel('Growth rate')
209222
plt.xlim([0, 1.1])
210223
plt.ylim([0, 110])
211224
plt.show()
@@ -283,9 +296,9 @@ def show_gam(raw_GAM):
283296
return {'GAM': m, 'NGAM': b}
284297

285298
#1- Import model
286-
model = import_model(path_to_model)
299+
model = _import_model(path_to_model)
287300
#2- Import experimental data
288-
data = import_data(path_to_data)
301+
data = _import_data(path_to_data)
289302
#3- Calculate GAM
290303
raw_GAM = calculate_gam(model, data,show_GAM)
291304
#4-

0 commit comments

Comments
 (0)