Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true
}
2 changes: 1 addition & 1 deletion coralme/builder/flat_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def process_m_model(
# cobra.manipulation.delete.prune_unused_metabolites(m_model) # orphan metabolites

# met_data DataFrame
mets_data = mets_data[mets_data['type'].isin(['ADD', 'REPLACE'])]
mets_data = mets_data[mets_data['type'].isin(['ADD', 'REPLACE', 'CORRECTION'])]
mets_data.columns = ['me_id', 'name', 'formula', 'compartment', 'type']
# WARNING: Do we need to rename the index?
#mets_data.rename(index = lambda x: x.replace('_DASH_', '__'), inplace = True)
Expand Down
14 changes: 10 additions & 4 deletions coralme/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MEBuilder(object):
to update the configuration of the parent class.

"""
def __init__(self, *args, m_model_path = None, genbank_path = None, locus_tag = 'locus_tag', blast_threads = None, **kwargs):
def __init__(self, *args, m_model_path = False, genbank_path = False, locus_tag = 'locus_tag', blast_threads = None, **kwargs):
"""
keyword arguments
ME-Model-ID, str
Expand All @@ -94,6 +94,11 @@ def __init__(self, *args, m_model_path = None, genbank_path = None, locus_tag =
estimate_keffs, default True
"""

self.available_reference_models = {
'iJL1678b' : 'locus_tag', # E. coli, gram negative
'iJT964' : 'old_locus_tag', # B. subtilis, gram positive
}

if blast_threads is None:
blast_threads = os.cpu_count()-1

Expand Down Expand Up @@ -265,7 +270,7 @@ def generate_files(self, overwrite = True):
if bool(config.get('dev_reference', False)) or bool(config.get('user_reference', False)):
logging.warning("Reading reference")

self.ref = coralme.builder.organism.Organism(config.copy(), is_reference = True)
self.ref = coralme.builder.organism.Organism(config.copy(), is_reference = True, available_reference_models = self.available_reference_models)
self.ref.get_organism()

folder = self.org.blast_directory
Expand Down Expand Up @@ -1236,8 +1241,9 @@ def update_special_modifications_from_homology(self):
ref_cplx_homolog[i] for i in ref_cplxs if i in ref_cplx_homolog
]
for i in org_cplxs:
if v["stoich"]:
org_special_trna_subreactions[k]["stoich"] = v["stoich"]
# WARNING: stoichiometry of special modifications is in subreactions.txt
# if v["stoich"]:
# org_special_trna_subreactions[k]["stoich"] = v["stoich"]
if self._is_base_complex_in_list(i,defined_cplxs):
continue
defined_cplxs.append(i)
Expand Down
65 changes: 43 additions & 22 deletions coralme/builder/organism.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import anyconfig
import numpy
import collections
import pathlib

import Bio
import cobra
Expand Down Expand Up @@ -42,33 +43,47 @@ class Organism(object):
If True, process as reference organism.
"""

def __init__(self, config, is_reference):
def __init__(self, config, is_reference, available_reference_models = None):
self.available_reference_models = available_reference_models

if is_reference:
# check values
if not bool(config.get('dev_reference', False)) and not bool(config.get('user_reference', False)):
config['dev_reference'] = 'iJL1678b'
logging.warning('Using \'iJL1678b\' model as reference. See `builder.available_reference_models` for more information.')
elif 'dev_reference' in config and 'user_reference' in config:
raise ValueError('The keys \'dev_reference\' and \'user_reference\' are mutually exclusive. Please remove one from configuration.')
elif config['dev_reference'] is True:
config['dev_reference'] = 'iJL1678b'
logging.warning('Using \'iJL1678b\' model as reference. See `builder.available_reference_models` for more information.')
elif config['dev_reference']:
if not config['dev_reference'] in self.available_reference_models:
raise ValueError('The key \'dev_reference\' must be \'iJL1678b\' (E. coli, gram negative) or \'iJT964\' (B. subtilis, gram positive)')
elif config['user_reference']:
if not pathlib.Path(config['user_reference']).is_dir():
raise ValueError('The key \'user_reference\' must be a directory.')
else:
return NotImplementedError

# If Organism is reference, set some default values for future processing
if bool(config.get('dev_reference', False)) and not bool(config.get('user_reference', False)):
# If no reference set, use the default iJL1678b E. coli ME-model files as reference
self.id = 'iJL1678b'
config["locus_tag"] = "locus_tag"
elif not bool(config.get('dev_reference', False)) and bool(config.get('user_reference', False)):
if config['dev_reference']:
self.id = config['dev_reference']
config["locus_tag"] = self.available_reference_models[self.id]

elif config['user_reference']:
# If User set a reference, use manually set values
# Set ID
self.id = config['user_reference']
config = config.copy()
# TODO: check if necessary
# Update the configuration using the configuration from the User's defined reference
for input_file in [config['user_reference'] + "/organism.json", \
config['user_reference'] + "/input.json"]:
with open(input_file, 'r') as infile:
config.update(anyconfig.load(infile))
elif bool(config.get('dev_reference', False)) and bool(config.get('user_reference', False)):
# Reference configuration is contradictory. Using default reference instead.
logging.warning('The \'dev_reference\' and \'user-reference\' options are mutually exclusive. Using default iJL1678b as reference.')
self.id = 'iJL1678b'
config["locus_tag"] = "locus_tag"

else:
# In any other case, use the default reference instead
logging.warning('No reference was set. Using default iJL1678b as reference.')
self.id = 'iJL1678b'
config["locus_tag"] = "locus_tag"
return NotImplementedError
else:
# If it is not the reference, use the organism files
self.id = config['ME-Model-ID']
Expand Down Expand Up @@ -104,7 +119,7 @@ def __init__(self, config, is_reference):
@property
def directory(self):
"""Working file directory with reconstruction files"""
if self.is_reference and self.id == 'iJL1678b':
if self.is_reference and self.id in self.available_reference_models:
try:
from importlib.resources import files
except ImportError:
Expand Down Expand Up @@ -188,9 +203,12 @@ def _m_model(self):
"""
Returns the M-model.
"""
if self.id == 'iJL1678b':
# If reference organism is iJL1678b, read it from m_model.json
model = self.directory + 'm_model.json'
if self.is_reference:
if self.id in self.available_reference_models:
# If reference organism is iJL1678b, read it from m_model.json
model = self.directory + 'm_model.json'
else:
raise ValueError('Reference code is not valid. See builder.available_reference_models for available references.')
else:
# Read M-model from the configuration file path
model = self.config['m-model-path']
Expand Down Expand Up @@ -300,9 +318,12 @@ def get_organism(self):
def get_genbank_contigs(self):
""" Reads GenBank file as a list of contigs.
"""
if self.id == 'iJL1678b':
# If default reference iJL1678b, read from genome.gb
gb_it = Bio.SeqIO.parse(self.directory + "genome.gb", "gb")
if self.is_reference:
if self.id in self.available_reference_models:
# If default reference iJL1678b, read from genome.gb
gb_it = Bio.SeqIO.parse(self.directory + "genome.gb", "gb")
else:
raise ValueError('Reference code is not valid. See builder.available_reference_models for available references.')
else:
# Read from configuration file path
gb_it = Bio.SeqIO.parse(self.config['genbank-path'], "gb")
Expand Down
2 changes: 1 addition & 1 deletion coralme/builder/troubleshooting.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def brute_force_check(me_model, metabolites_to_add, growth_key_and_value,solver=
"""
if solver in ['gurobi', 'cplex']:
me_model.get_solution = me_model.optimize_windows
me_model.get_feasibility =me_model.feas_windows(solver = solver)
me_model.get_feasibility = me_model.feas_windows(solver = solver)
elif solver == "qminos":
me_model.get_solution = me_model.optimize
me_model.get_feasibility = me_model.feasibility
Expand Down
1 change: 1 addition & 0 deletions coralme/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
import coralme.core.parameters
import coralme.core.processdata
import coralme.core.reaction
import coralme.core.optimization
Loading