Skip to content

Commit

Permalink
New variable in comets model building, to choose whether to add rando…
Browse files Browse the repository at this point in the history
…mtag to name
  • Loading branch information
djbajic committed Jun 30, 2021
1 parent 97fef98 commit 9c820e0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cometspy/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def set_specific_metabolite_diffusion(self, met : str,
self.__diffusion_flag = True

def set_specific_metabolite(self, met : str, amount : float,
static : bool =False):
static : bool = False):
"""
sets the initial (or constant) value for a metabolite across space
Expand Down
30 changes: 20 additions & 10 deletions cometspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ class model:
iJO1366
"""
def __init__(self, model : cobra.Model = None):
def __init__(self, model : cobra.Model = None, randomtag : bool = False):
self.initial_pop = [[0, 0, 0.0]]
self.id = '_' + hex(id(self))

if randomtag:
self.id = '_' + hex(id(self))
else:
self.id = ""

self.reactions = pd.DataFrame(columns=['REACTION_NAMES', 'ID',
'LB', 'UB', 'EXCH',
'EXCH_IND', 'V_MAX',
Expand Down Expand Up @@ -104,12 +109,12 @@ def __init__(self, model : cobra.Model = None):

if model is not None:
if isinstance(model, cobra.Model):
self.load_cobra_model(model)
self.load_cobra_model(model, randomtag)
else: # assume it is a path
if model[-3:] == "cmd":
self.read_comets_model(model)
self.read_comets_model(model, randomtag)
else:
self.read_cobra_model(model)
self.read_cobra_model(model, randomtag)

def get_reaction_names(self) -> list:
""" returns a list of reaction names"""
Expand Down Expand Up @@ -451,7 +456,7 @@ def read_cobra_model(self, path : str):
curr_m = cobra.io.read_sbml_model(path)
self.load_cobra_model(curr_m)

def load_cobra_model(self, curr_m : cobra.Model):
def load_cobra_model(self, curr_m : cobra.Model, randomtag : bool = False):
""" creates the COMETS model from the supplied cobra model
This is usually used internally when creating a COMETS model.
Expand All @@ -471,8 +476,11 @@ def load_cobra_model(self, curr_m : cobra.Model):
>>> model = c.model()
>>> model.load_cobra_model(ecoli)
"""
self.id = curr_m.id + self.id
"""
self.id = curr_m.id
if randomtag:
self.id = self.id + '_' + hex(id(self))

# reactions and their features
reaction_list = curr_m.reactions
self.reactions['REACTION_NAMES'] = [str(x).split(':')[0] for
Expand Down Expand Up @@ -588,9 +596,11 @@ def read_comets_model(self, path : str):
>>> model = c.model()
>>> model.read_comets_model(path_to_model)
"""
"""
self.id = os.path.splitext(os.path.basename(path))[0] + self.id

if randomtag:
self.id = self.id + '_' + hex(id(self))

# in this way, its robust to empty lines:
m_f_lines = [s for s in _read_file(path).splitlines() if s]
m_filedata_string = os.linesep.join(m_f_lines)
Expand Down
Binary file added dist/cometspy-0.4.11.tar.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
setup(
name='cometspy',
packages=['cometspy'],
version='0.4.11',
version='0.4.12',
license='GPL',
description='The Python interface to COMETS',
author='The COMETSPy Core Team',
author_email='djordje.bajic@yale.edu',
url='https://github.com/segrelab/cometspy',
download_url='https://github.com/segrelab/cometspy/archive/v0.4.11.tar.gz', # New releases here!!
download_url='https://github.com/segrelab/cometspy/archive/v0.4.12.tar.gz', # New releases here!!
keywords=['metabolism', 'dynamic', 'flux', 'balance', 'analysis', 'spatial', 'evolution'],
install_requires=[
# I get to this in a second
Expand Down

0 comments on commit 9c820e0

Please sign in to comment.