Skip to content

Commit

Permalink
commscores edits
Browse files Browse the repository at this point in the history
  • Loading branch information
freiburgermsu committed Dec 7, 2023
1 parent b055bda commit 249af79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions modelseedpy/community/commhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ def correct_nonMSID(nonMSobject, output, model_index):
name, compartment = output
index = 0 if compartment == "e" else model_index
nonMSobject.compartment = compartment + str(index)
comp = re.search(r"(_\w\d+$)", nonMSobject.id)
if comp is None: return nonMSobject.id.replace(rf"[{compartment}]", f"_{nonMSobject.compartment}")
comp = re.search(r"(_[a-z]\d+$)", nonMSobject.id)
if comp is None and rf"[{compartment}]" in nonMSobject.id: return nonMSobject.id.replace(rf"[{compartment}]", f"_{nonMSobject.compartment}")
elif comp is None: return nonMSobject.id + f"_{nonMSobject.compartment}"
return "_".join([nonMSobject.id.replace(comp.group(), ""), nonMSobject.compartment])


def build_from_species_models(org_models, model_id=None, name=None, abundances=None,
standardize=False, copy_models=True, printing=False):
standardize=False, MSmodel = True, copy_models=True, printing=False):
"""Merges the input list of single species metabolic models into a community metabolic model
Parameters
Expand Down Expand Up @@ -65,6 +66,7 @@ def build_from_species_models(org_models, model_id=None, name=None, abundances=N
model_util = MSModelUtil(org_model, copy=copy_models)
model_reaction_ids = [rxn.id for rxn in model_util.model.reactions]
model_index += 1
# if MSmodel:
# Rename metabolites
for met in model_util.model.metabolites:
# Renaming compartments
Expand Down Expand Up @@ -112,8 +114,7 @@ def build_from_species_models(org_models, model_id=None, name=None, abundances=N
output = MSModelUtil.parse_id(rxn)
if output is None:
if printing: print(f"The {rxn.id} ({output}; {hasattr(rxn, 'compartment')}) is unpredictable.")
try:
rxn.id = correct_nonMSID(rxn, (rxn.id, "c"), model_index)
try: rxn.id = correct_nonMSID(rxn, (rxn.id, "c"), model_index)
except ValueError: pass
elif len(output) == 2: rxn.id = correct_nonMSID(rxn, output, model_index)
elif len(output) == 3:
Expand All @@ -128,6 +129,9 @@ def build_from_species_models(org_models, model_id=None, name=None, abundances=N
if string_diff and not all(FBAHelper.isnumber(x) for x in string_diff):
print(f"The ID {initialID} is changed with {string_diff} to create the final ID {finalID}")
new_reactions.add(rxn)
# else:
# # TODO develop a method for compartmentalizing models without editing all reaction IDs or assuming their syntax
# pass
# adds only unique reactions and metabolites to the community model
newmodel = Model(model_id or "+".join([model.id for model in models]),
name or "+".join([model.name for model in models]))
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion modelseedpy/community/mscommunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, model=None, member_models: list = None, ids=None, abundances=
if "cpd11416" not in msid_cobraid_hash: raise KeyError("Could not find biomass compound for the model.")
other_biomass_cpds = []
for self.biomass_cpd in msid_cobraid_hash["cpd11416"]:
if self.biomass_cpd.compartment == "c0":
if "c" in self.biomass_cpd.compartment:
for rxn in self.util.model.reactions:
if self.biomass_cpd not in rxn.metabolites: continue
print(self.biomass_cpd, rxn, end=";\t")
Expand Down
4 changes: 2 additions & 2 deletions modelseedpy/core/msminimalmedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _var_to_ID(var):


def _compatibilize(org_models, printing=False):
from commscores import GEMCompatibility
from commscores import GEMCompatibility
return GEMCompatibility.standardize(org_models, conflicts_file_name="standardization_corrections.json", printing=printing)


Expand All @@ -61,7 +61,7 @@ def minimizeFlux_withGrowth(model_util, min_growth, obj):
model_util.add_objective(obj, "min")
# print(model_util.model.objective)
# print([(cons.lb, cons.expression) for cons in model_util.model.constraints if "min" in cons.name])
sol = model_util.model.optimize()
sol = model_util.model.optimize()
# print(sol.objective_value)
sol_dict = bioFlux_check(model_util.model, sol, min_growth=min_growth)
return sol, sol_dict
Expand Down

0 comments on commit 249af79

Please sign in to comment.