Skip to content

Commit

Permalink
Robustness increased
Browse files Browse the repository at this point in the history
  • Loading branch information
jclachance committed Dec 14, 2017
1 parent 1cce1b9 commit e5f0403
Show file tree
Hide file tree
Showing 7 changed files with 646 additions and 533 deletions.
5 changes: 2 additions & 3 deletions BOFdat/dna.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _convert_to_coefficient(model, ratio_genome, CELL_WEIGHT, DNA_RATIO):
DNA_coefficients = dict(zip(metabolites,coefficients))
return DNA_coefficients

def generate_coefficients(path_to_fasta, path_to_model, CELL_WEIGHT=280, DNA_WEIGHT_FRACTION=0.031):
def generate_coefficients(path_to_fasta, path_to_model , DNA_WEIGHT_FRACTION=0.031):
"""
Generates a dictionary of metabolite:coefficients for the 4 DNA bases from the organism's
DNA fasta file and the weight percentage of DNA in the cell.
Expand All @@ -78,12 +78,11 @@ def generate_coefficients(path_to_fasta, path_to_model, CELL_WEIGHT=280, DNA_WEI
:param path_to_model: a path to the model, format supported are json and xml
:param CELL_WEIGHT: experimentally measured cell weight in femtograms, float
:param DNA_RATIO: the ratio of DNA in the entire cell
:return: a dictionary of metabolites and coefficients
"""
CELL_WEIGHT = 280
if DNA_WEIGHT_FRACTION > 1.:
raise Exception('WEIGHT FRACTION should be a number between 0 and 1')
#Operations
Expand Down
333 changes: 196 additions & 137 deletions BOFdat/lipid.py

Large diffs are not rendered by default.

47 changes: 30 additions & 17 deletions BOFdat/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@
2- Estimate GAM and NGAM from theorical values
"""
def _import_model(path_to_model):
import cobra
extension = path_to_model.split('.')[-1]
if extension == 'json':
return cobra.io.load_json_model(path_to_model)
elif extension == 'xml':
return cobra.io.read_sbml_model(path_to_model)
else:
raise Exception('Model format not compatible, provide xml or json')

def _import_data(path_to_data):
import pandas as pd
import warnings

data = pd.read_csv(path_to_data)
'''
#1- This file should have a header
for i in data.columns:
try:
float(i)
raise ValueError('Provide file header')
except:
pass
'''
return data

def experimental_maintenance(path_to_data, path_to_model,show_GAM=False):
"""
Expand All @@ -29,26 +54,13 @@ def experimental_maintenance(path_to_data, path_to_model,show_GAM=False):

#From experimental data growth rate on a given carbon source
#Obtain best fit from model to experimental data
def import_model(path_to_model):
import cobra
extension = path_to_model.split('.')[-1]
if extension == 'json':
return cobra.io.load_json_model(path_to_model)
elif extension == 'xml':
return cobra.io.read_sbml_model(path_to_model)

def import_data(path_to_data):
import pandas as pd
return pd.read_csv(path_to_data)

def get_carbon_sources(data):
return [c for c in data.Source]

def attribute_colors(data,carbon_sources):
# Attribute colors to carbon sources for ploting
# Set a color palette
import seaborn as sb

color_palette = sb.color_palette('deep',len(carbon_sources))
data['color'] = ''
for i in len(carbon_sources):
Expand Down Expand Up @@ -190,7 +202,7 @@ def show_gam(raw_GAM):
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

sns.set_style('whitegrid')
x = raw_GAM['Growth_rate']
y = raw_GAM['ATP']
#Fit with np.polyfit
Expand All @@ -205,7 +217,8 @@ def show_gam(raw_GAM):
print('R2=', correlation ** 2)
plt.scatter(raw_GAM['Growth_rate'], raw_GAM['ATP'])
# plt.scatter(filtered_data['GR'],filtered_data['ATP'], color=filtered_data['color'], marker=filtered_data['marker'].tolist())

plt.ylabel('ATP')
plt.xlabel('Growth rate')
plt.xlim([0, 1.1])
plt.ylim([0, 110])
plt.show()
Expand Down Expand Up @@ -283,9 +296,9 @@ def show_gam(raw_GAM):
return {'GAM': m, 'NGAM': b}

#1- Import model
model = import_model(path_to_model)
model = _import_model(path_to_model)
#2- Import experimental data
data = import_data(path_to_data)
data = _import_data(path_to_data)
#3- Calculate GAM
raw_GAM = calculate_gam(model, data,show_GAM)
#4-
Expand Down
Loading

0 comments on commit e5f0403

Please sign in to comment.