id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2,400 | opencobra/memote | memote/support/thermodynamics.py | get_smallest_compound_id | def get_smallest_compound_id(compounds_identifiers):
"""
Return the smallest KEGG compound identifier from a list.
KEGG identifiers may map to compounds, drugs or glycans prefixed
respectively with "C", "D", and "G" followed by at least 5 digits. We
choose the lowest KEGG identifier with the assump... | python | def get_smallest_compound_id(compounds_identifiers):
return min((c for c in compounds_identifiers if c.startswith("C")),
key=lambda c: int(c[1:])) | [
"def",
"get_smallest_compound_id",
"(",
"compounds_identifiers",
")",
":",
"return",
"min",
"(",
"(",
"c",
"for",
"c",
"in",
"compounds_identifiers",
"if",
"c",
".",
"startswith",
"(",
"\"C\"",
")",
")",
",",
"key",
"=",
"lambda",
"c",
":",
"int",
"(",
"... | Return the smallest KEGG compound identifier from a list.
KEGG identifiers may map to compounds, drugs or glycans prefixed
respectively with "C", "D", and "G" followed by at least 5 digits. We
choose the lowest KEGG identifier with the assumption that several
identifiers are due to chirality and that t... | [
"Return",
"the",
"smallest",
"KEGG",
"compound",
"identifier",
"from",
"a",
"list",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/thermodynamics.py#L37-L64 |
2,401 | opencobra/memote | memote/support/thermodynamics.py | map_metabolite2kegg | def map_metabolite2kegg(metabolite):
"""
Return a KEGG compound identifier for the metabolite if it exists.
First see if there is an unambiguous mapping to a single KEGG compound ID
provided with the model. If not, check if there is any KEGG compound ID in
a list of mappings. KEGG IDs may map to co... | python | def map_metabolite2kegg(metabolite):
logger.debug("Looking for KEGG compound identifier for %s.", metabolite.id)
kegg_annotation = metabolite.annotation.get("kegg.compound")
if kegg_annotation is None:
# TODO (Moritz Beber): Currently name matching is very slow and
# inaccurate. We disable ... | [
"def",
"map_metabolite2kegg",
"(",
"metabolite",
")",
":",
"logger",
".",
"debug",
"(",
"\"Looking for KEGG compound identifier for %s.\"",
",",
"metabolite",
".",
"id",
")",
"kegg_annotation",
"=",
"metabolite",
".",
"annotation",
".",
"get",
"(",
"\"kegg.compound\""... | Return a KEGG compound identifier for the metabolite if it exists.
First see if there is an unambiguous mapping to a single KEGG compound ID
provided with the model. If not, check if there is any KEGG compound ID in
a list of mappings. KEGG IDs may map to compounds, drugs and glycans. KEGG
compound IDs... | [
"Return",
"a",
"KEGG",
"compound",
"identifier",
"for",
"the",
"metabolite",
"if",
"it",
"exists",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/thermodynamics.py#L67-L126 |
2,402 | opencobra/memote | memote/support/thermodynamics.py | translate_reaction | def translate_reaction(reaction, metabolite_mapping):
"""
Return a mapping from KEGG compound identifiers to coefficients.
Parameters
----------
reaction : cobra.Reaction
The reaction whose metabolites are to be translated.
metabolite_mapping : dict
An existing mapping from cobr... | python | def translate_reaction(reaction, metabolite_mapping):
# Transport reactions where the same metabolite occurs in different
# compartments should have been filtered out but just to be sure, we add
# coefficients in the mapping.
stoichiometry = defaultdict(float)
for met, coef in iteritems(reaction.met... | [
"def",
"translate_reaction",
"(",
"reaction",
",",
"metabolite_mapping",
")",
":",
"# Transport reactions where the same metabolite occurs in different",
"# compartments should have been filtered out but just to be sure, we add",
"# coefficients in the mapping.",
"stoichiometry",
"=",
"def... | Return a mapping from KEGG compound identifiers to coefficients.
Parameters
----------
reaction : cobra.Reaction
The reaction whose metabolites are to be translated.
metabolite_mapping : dict
An existing mapping from cobra.Metabolite to KEGG compound identifier
that may already ... | [
"Return",
"a",
"mapping",
"from",
"KEGG",
"compound",
"identifiers",
"to",
"coefficients",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/thermodynamics.py#L129-L158 |
2,403 | opencobra/memote | memote/support/thermodynamics.py | find_thermodynamic_reversibility_index | def find_thermodynamic_reversibility_index(reactions):
u"""
Return the reversibility index of the given reactions.
To determine the reversibility index, we calculate
the reversibility index ln_gamma (see [1]_ section 3.5) of each reaction
using the eQuilibrator API [2]_.
Parameters
-------... | python | def find_thermodynamic_reversibility_index(reactions):
u"""
Return the reversibility index of the given reactions.
To determine the reversibility index, we calculate
the reversibility index ln_gamma (see [1]_ section 3.5) of each reaction
using the eQuilibrator API [2]_.
Parameters
-------... | [
"def",
"find_thermodynamic_reversibility_index",
"(",
"reactions",
")",
":",
"incomplete_mapping",
"=",
"[",
"]",
"problematic_calculation",
"=",
"[",
"]",
"reversibility_indexes",
"=",
"[",
"]",
"unbalanced",
"=",
"[",
"]",
"metabolite_mapping",
"=",
"{",
"}",
"f... | u"""
Return the reversibility index of the given reactions.
To determine the reversibility index, we calculate
the reversibility index ln_gamma (see [1]_ section 3.5) of each reaction
using the eQuilibrator API [2]_.
Parameters
----------
reactions: list of cobra.Reaction
A... | [
"u",
"Return",
"the",
"reversibility",
"index",
"of",
"the",
"given",
"reactions",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/thermodynamics.py#L161-L234 |
2,404 | opencobra/memote | memote/support/consistency.py | check_stoichiometric_consistency | def check_stoichiometric_consistency(model):
"""
Verify the consistency of the model's stoichiometry.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Notes
-----
See [1]_ section 3.1 for a complete description of the algorithm.
.. [1] Gev... | python | def check_stoichiometric_consistency(model):
problem = model.problem
# The transpose of the stoichiometric matrix N.T in the paper.
stoich_trans = problem.Model()
internal_rxns = con_helpers.get_internals(model)
metabolites = set(met for rxn in internal_rxns for met in rxn.metabolites)
LOGGER.in... | [
"def",
"check_stoichiometric_consistency",
"(",
"model",
")",
":",
"problem",
"=",
"model",
".",
"problem",
"# The transpose of the stoichiometric matrix N.T in the paper.",
"stoich_trans",
"=",
"problem",
".",
"Model",
"(",
")",
"internal_rxns",
"=",
"con_helpers",
".",
... | Verify the consistency of the model's stoichiometry.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Notes
-----
See [1]_ section 3.1 for a complete description of the algorithm.
.. [1] Gevorgyan, A., M. G Poolman, and D. A Fell.
"Dete... | [
"Verify",
"the",
"consistency",
"of",
"the",
"model",
"s",
"stoichiometry",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L63-L110 |
2,405 | opencobra/memote | memote/support/consistency.py | find_unconserved_metabolites | def find_unconserved_metabolites(model):
"""
Detect unconserved metabolites.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Notes
-----
See [1]_ section 3.2 for a complete description of the algorithm.
.. [1] Gevorgyan, A., M. G Poolman... | python | def find_unconserved_metabolites(model):
problem = model.problem
stoich_trans = problem.Model()
internal_rxns = con_helpers.get_internals(model)
metabolites = set(met for rxn in internal_rxns for met in rxn.metabolites)
# The binary variables k[i] in the paper.
k_vars = list()
for met in met... | [
"def",
"find_unconserved_metabolites",
"(",
"model",
")",
":",
"problem",
"=",
"model",
".",
"problem",
"stoich_trans",
"=",
"problem",
".",
"Model",
"(",
")",
"internal_rxns",
"=",
"con_helpers",
".",
"get_internals",
"(",
"model",
")",
"metabolites",
"=",
"s... | Detect unconserved metabolites.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Notes
-----
See [1]_ section 3.2 for a complete description of the algorithm.
.. [1] Gevorgyan, A., M. G Poolman, and D. A Fell.
"Detection of Stoichiomet... | [
"Detect",
"unconserved",
"metabolites",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L113-L165 |
2,406 | opencobra/memote | memote/support/consistency.py | find_inconsistent_min_stoichiometry | def find_inconsistent_min_stoichiometry(model, atol=1e-13):
"""
Detect inconsistent minimal net stoichiometries.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
atol : float, optional
Values below the absolute tolerance are treated as zero. Exp... | python | def find_inconsistent_min_stoichiometry(model, atol=1e-13):
if check_stoichiometric_consistency(model):
return set()
Model, Constraint, Variable, Objective = con_helpers.get_interface(model)
unconserved_mets = find_unconserved_metabolites(model)
LOGGER.info("model has %d unconserved metabolites"... | [
"def",
"find_inconsistent_min_stoichiometry",
"(",
"model",
",",
"atol",
"=",
"1e-13",
")",
":",
"if",
"check_stoichiometric_consistency",
"(",
"model",
")",
":",
"return",
"set",
"(",
")",
"Model",
",",
"Constraint",
",",
"Variable",
",",
"Objective",
"=",
"c... | Detect inconsistent minimal net stoichiometries.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
atol : float, optional
Values below the absolute tolerance are treated as zero. Expected to be
very small but larger than zero.
Notes
----... | [
"Detect",
"inconsistent",
"minimal",
"net",
"stoichiometries",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L170-L246 |
2,407 | opencobra/memote | memote/support/consistency.py | detect_energy_generating_cycles | def detect_energy_generating_cycles(model, metabolite_id):
u"""
Detect erroneous energy-generating cycles for a a single metabolite.
The function will first build a dissipation reaction corresponding to the
input metabolite. This reaction is then set as the objective for
optimization, after closing... | python | def detect_energy_generating_cycles(model, metabolite_id):
u"""
Detect erroneous energy-generating cycles for a a single metabolite.
The function will first build a dissipation reaction corresponding to the
input metabolite. This reaction is then set as the objective for
optimization, after closing... | [
"def",
"detect_energy_generating_cycles",
"(",
"model",
",",
"metabolite_id",
")",
":",
"main_comp",
"=",
"helpers",
".",
"find_compartment_id_in_model",
"(",
"model",
",",
"'c'",
")",
"met",
"=",
"helpers",
".",
"find_met_in_model",
"(",
"model",
",",
"metabolite... | u"""
Detect erroneous energy-generating cycles for a a single metabolite.
The function will first build a dissipation reaction corresponding to the
input metabolite. This reaction is then set as the objective for
optimization, after closing all exchanges. If the reaction was able to
carry flux, an ... | [
"u",
"Detect",
"erroneous",
"energy",
"-",
"generating",
"cycles",
"for",
"a",
"a",
"single",
"metabolite",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L277-L369 |
2,408 | opencobra/memote | memote/support/consistency.py | find_orphans | def find_orphans(model):
"""
Return metabolites that are only consumed in reactions.
Metabolites that are involved in an exchange reaction are never
considered to be orphaned.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
"""
exchange =... | python | def find_orphans(model):
exchange = frozenset(model.exchanges)
return [
met for met in model.metabolites
if (len(met.reactions) > 0) and all(
(not rxn.reversibility) and (rxn not in exchange) and
(rxn.metabolites[met] < 0) for rxn in met.reactions
)
] | [
"def",
"find_orphans",
"(",
"model",
")",
":",
"exchange",
"=",
"frozenset",
"(",
"model",
".",
"exchanges",
")",
"return",
"[",
"met",
"for",
"met",
"in",
"model",
".",
"metabolites",
"if",
"(",
"len",
"(",
"met",
".",
"reactions",
")",
">",
"0",
")... | Return metabolites that are only consumed in reactions.
Metabolites that are involved in an exchange reaction are never
considered to be orphaned.
Parameters
----------
model : cobra.Model
The metabolic model under investigation. | [
"Return",
"metabolites",
"that",
"are",
"only",
"consumed",
"in",
"reactions",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L434-L454 |
2,409 | opencobra/memote | memote/support/consistency.py | find_metabolites_not_produced_with_open_bounds | def find_metabolites_not_produced_with_open_bounds(model):
"""
Return metabolites that cannot be produced with open exchange reactions.
A perfect model should be able to produce each and every metabolite when
all medium components are available.
Parameters
----------
model : cobra.Model
... | python | def find_metabolites_not_produced_with_open_bounds(model):
mets_not_produced = list()
helpers.open_exchanges(model)
for met in model.metabolites:
with model:
exch = model.add_boundary(
met, type="irrex", reaction_id="IRREX", lb=0, ub=1000)
solution = helpers.r... | [
"def",
"find_metabolites_not_produced_with_open_bounds",
"(",
"model",
")",
":",
"mets_not_produced",
"=",
"list",
"(",
")",
"helpers",
".",
"open_exchanges",
"(",
"model",
")",
"for",
"met",
"in",
"model",
".",
"metabolites",
":",
"with",
"model",
":",
"exch",
... | Return metabolites that cannot be produced with open exchange reactions.
A perfect model should be able to produce each and every metabolite when
all medium components are available.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Returns
-------... | [
"Return",
"metabolites",
"that",
"cannot",
"be",
"produced",
"with",
"open",
"exchange",
"reactions",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L493-L520 |
2,410 | opencobra/memote | memote/support/consistency.py | find_metabolites_not_consumed_with_open_bounds | def find_metabolites_not_consumed_with_open_bounds(model):
"""
Return metabolites that cannot be consumed with open boundary reactions.
When all metabolites can be secreted, it should be possible for each and
every metabolite to be consumed in some form.
Parameters
----------
model : cobra... | python | def find_metabolites_not_consumed_with_open_bounds(model):
mets_not_consumed = list()
helpers.open_exchanges(model)
for met in model.metabolites:
with model:
exch = model.add_boundary(
met, type="irrex", reaction_id="IRREX", lb=-1000, ub=0)
solution = helpers.... | [
"def",
"find_metabolites_not_consumed_with_open_bounds",
"(",
"model",
")",
":",
"mets_not_consumed",
"=",
"list",
"(",
")",
"helpers",
".",
"open_exchanges",
"(",
"model",
")",
"for",
"met",
"in",
"model",
".",
"metabolites",
":",
"with",
"model",
":",
"exch",
... | Return metabolites that cannot be consumed with open boundary reactions.
When all metabolites can be secreted, it should be possible for each and
every metabolite to be consumed in some form.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Returns
... | [
"Return",
"metabolites",
"that",
"cannot",
"be",
"consumed",
"with",
"open",
"boundary",
"reactions",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L523-L550 |
2,411 | opencobra/memote | memote/support/consistency.py | find_reactions_with_unbounded_flux_default_condition | def find_reactions_with_unbounded_flux_default_condition(model):
"""
Return list of reactions whose flux is unbounded in the default condition.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Returns
-------
tuple
list
A li... | python | def find_reactions_with_unbounded_flux_default_condition(model):
try:
fva_result = flux_variability_analysis(model, fraction_of_optimum=1.0)
except Infeasible as err:
LOGGER.error("Failed to find reactions with unbounded flux "
"because '{}'. This may be a bug.".format(err))... | [
"def",
"find_reactions_with_unbounded_flux_default_condition",
"(",
"model",
")",
":",
"try",
":",
"fva_result",
"=",
"flux_variability_analysis",
"(",
"model",
",",
"fraction_of_optimum",
"=",
"1.0",
")",
"except",
"Infeasible",
"as",
"err",
":",
"LOGGER",
".",
"er... | Return list of reactions whose flux is unbounded in the default condition.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Returns
-------
tuple
list
A list of reactions that in default modeling conditions are able to
c... | [
"Return",
"list",
"of",
"reactions",
"whose",
"flux",
"is",
"unbounded",
"in",
"the",
"default",
"condition",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency.py#L553-L612 |
2,412 | opencobra/memote | memote/experimental/tabular.py | read_tabular | def read_tabular(filename, dtype_conversion=None):
"""
Read a tabular data file which can be CSV, TSV, XLS or XLSX.
Parameters
----------
filename : str or pathlib.Path
The full file path. May be a compressed file.
dtype_conversion : dict
Column names as keys and corresponding t... | python | def read_tabular(filename, dtype_conversion=None):
if dtype_conversion is None:
dtype_conversion = {}
name, ext = filename.split(".", 1)
ext = ext.lower()
# Completely empty columns are interpreted as float by default.
dtype_conversion["comment"] = str
if "csv" in ext:
df = pd.re... | [
"def",
"read_tabular",
"(",
"filename",
",",
"dtype_conversion",
"=",
"None",
")",
":",
"if",
"dtype_conversion",
"is",
"None",
":",
"dtype_conversion",
"=",
"{",
"}",
"name",
",",
"ext",
"=",
"filename",
".",
"split",
"(",
"\".\"",
",",
"1",
")",
"ext",... | Read a tabular data file which can be CSV, TSV, XLS or XLSX.
Parameters
----------
filename : str or pathlib.Path
The full file path. May be a compressed file.
dtype_conversion : dict
Column names as keys and corresponding type for loading the data.
Please take a look at the `pa... | [
"Read",
"a",
"tabular",
"data",
"file",
"which",
"can",
"be",
"CSV",
"TSV",
"XLS",
"or",
"XLSX",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/tabular.py#L25-L60 |
2,413 | opencobra/memote | memote/suite/cli/reports.py | snapshot | def snapshot(model, filename, pytest_args, exclusive, skip, solver,
experimental, custom_tests, custom_config):
"""
Take a snapshot of a model's state and generate a report.
MODEL: Path to model file. Can also be supplied via the environment variable
MEMOTE_MODEL or configured in 'setup.cf... | python | def snapshot(model, filename, pytest_args, exclusive, skip, solver,
experimental, custom_tests, custom_config):
model_obj, sbml_ver, notifications = api.validate_model(
model)
if model_obj is None:
LOGGER.critical(
"The model could not be loaded due to the following SBML... | [
"def",
"snapshot",
"(",
"model",
",",
"filename",
",",
"pytest_args",
",",
"exclusive",
",",
"skip",
",",
"solver",
",",
"experimental",
",",
"custom_tests",
",",
"custom_config",
")",
":",
"model_obj",
",",
"sbml_ver",
",",
"notifications",
"=",
"api",
".",... | Take a snapshot of a model's state and generate a report.
MODEL: Path to model file. Can also be supplied via the environment variable
MEMOTE_MODEL or configured in 'setup.cfg' or 'memote.ini'. | [
"Take",
"a",
"snapshot",
"of",
"a",
"model",
"s",
"state",
"and",
"generate",
"a",
"report",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/reports.py#L89-L119 |
2,414 | opencobra/memote | memote/suite/cli/reports.py | history | def history(location, model, filename, deployment, custom_config):
"""Generate a report over a model's git commit history."""
callbacks.git_installed()
LOGGER.info("Initialising history report generation.")
if location is None:
raise click.BadParameter("No 'location' given or configured.")
t... | python | def history(location, model, filename, deployment, custom_config):
callbacks.git_installed()
LOGGER.info("Initialising history report generation.")
if location is None:
raise click.BadParameter("No 'location' given or configured.")
try:
repo = git.Repo()
except git.InvalidGitReposito... | [
"def",
"history",
"(",
"location",
",",
"model",
",",
"filename",
",",
"deployment",
",",
"custom_config",
")",
":",
"callbacks",
".",
"git_installed",
"(",
")",
"LOGGER",
".",
"info",
"(",
"\"Initialising history report generation.\"",
")",
"if",
"location",
"i... | Generate a report over a model's git commit history. | [
"Generate",
"a",
"report",
"over",
"a",
"model",
"s",
"git",
"commit",
"history",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/reports.py#L144-L175 |
2,415 | opencobra/memote | memote/suite/cli/reports.py | diff | def diff(models, filename, pytest_args, exclusive, skip, solver,
experimental, custom_tests, custom_config):
"""
Take a snapshot of all the supplied models and generate a diff report.
MODELS: List of paths to two or more model files.
"""
if not any(a.startswith("--tb") for a in pytest_args... | python | def diff(models, filename, pytest_args, exclusive, skip, solver,
experimental, custom_tests, custom_config):
if not any(a.startswith("--tb") for a in pytest_args):
pytest_args = ["--tb", "no"] + pytest_args
# Add further directories to search for tests.
pytest_args.extend(custom_tests)
... | [
"def",
"diff",
"(",
"models",
",",
"filename",
",",
"pytest_args",
",",
"exclusive",
",",
"skip",
",",
"solver",
",",
"experimental",
",",
"custom_tests",
",",
"custom_config",
")",
":",
"if",
"not",
"any",
"(",
"a",
".",
"startswith",
"(",
"\"--tb\"",
"... | Take a snapshot of all the supplied models and generate a diff report.
MODELS: List of paths to two or more model files. | [
"Take",
"a",
"snapshot",
"of",
"all",
"the",
"supplied",
"models",
"and",
"generate",
"a",
"diff",
"report",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/reports.py#L226-L287 |
2,416 | opencobra/memote | memote/suite/results/history_manager.py | HistoryManager.build_branch_structure | def build_branch_structure(self, model, skip):
"""Inspect and record the repo's branches and their history."""
self._history = dict()
self._history["commits"] = commits = dict()
self._history["branches"] = branches = dict()
for branch in self._repo.refs:
LOGGER.debug(... | python | def build_branch_structure(self, model, skip):
self._history = dict()
self._history["commits"] = commits = dict()
self._history["branches"] = branches = dict()
for branch in self._repo.refs:
LOGGER.debug(branch.name)
if branch.name in skip:
continu... | [
"def",
"build_branch_structure",
"(",
"self",
",",
"model",
",",
"skip",
")",
":",
"self",
".",
"_history",
"=",
"dict",
"(",
")",
"self",
".",
"_history",
"[",
"\"commits\"",
"]",
"=",
"commits",
"=",
"dict",
"(",
")",
"self",
".",
"_history",
"[",
... | Inspect and record the repo's branches and their history. | [
"Inspect",
"and",
"record",
"the",
"repo",
"s",
"branches",
"and",
"their",
"history",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/history_manager.py#L65-L90 |
2,417 | opencobra/memote | memote/suite/results/history_manager.py | HistoryManager.load_history | def load_history(self, model, skip={"gh-pages"}):
"""
Load the entire results history into memory.
Could be a bad idea in a far future.
"""
if self._history is None:
self.build_branch_structure(model, skip)
self._results = dict()
all_commits = list(s... | python | def load_history(self, model, skip={"gh-pages"}):
if self._history is None:
self.build_branch_structure(model, skip)
self._results = dict()
all_commits = list(self._history["commits"])
for commit in all_commits:
try:
self._results[commit] = self.ma... | [
"def",
"load_history",
"(",
"self",
",",
"model",
",",
"skip",
"=",
"{",
"\"gh-pages\"",
"}",
")",
":",
"if",
"self",
".",
"_history",
"is",
"None",
":",
"self",
".",
"build_branch_structure",
"(",
"model",
",",
"skip",
")",
"self",
".",
"_results",
"=... | Load the entire results history into memory.
Could be a bad idea in a far future. | [
"Load",
"the",
"entire",
"results",
"history",
"into",
"memory",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/history_manager.py#L100-L116 |
2,418 | opencobra/memote | memote/suite/results/history_manager.py | HistoryManager.get_result | def get_result(self, commit, default=MemoteResult()):
"""Return an individual result from the history if it exists."""
assert self._results is not None, \
"Please call the method `load_history` first."
return self._results.get(commit, default) | python | def get_result(self, commit, default=MemoteResult()):
assert self._results is not None, \
"Please call the method `load_history` first."
return self._results.get(commit, default) | [
"def",
"get_result",
"(",
"self",
",",
"commit",
",",
"default",
"=",
"MemoteResult",
"(",
")",
")",
":",
"assert",
"self",
".",
"_results",
"is",
"not",
"None",
",",
"\"Please call the method `load_history` first.\"",
"return",
"self",
".",
"_results",
".",
"... | Return an individual result from the history if it exists. | [
"Return",
"an",
"individual",
"result",
"from",
"the",
"history",
"if",
"it",
"exists",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/history_manager.py#L118-L122 |
2,419 | opencobra/memote | memote/support/matrix.py | absolute_extreme_coefficient_ratio | def absolute_extreme_coefficient_ratio(model):
"""
Return the maximum and minimum absolute, non-zero coefficients.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
"""
s_matrix, _, _ = con_helpers.stoichiometry_matrix(
model.metabolites, mo... | python | def absolute_extreme_coefficient_ratio(model):
s_matrix, _, _ = con_helpers.stoichiometry_matrix(
model.metabolites, model.reactions
)
abs_matrix = np.abs(s_matrix)
return abs_matrix.max(), abs_matrix[abs_matrix > 0].min() | [
"def",
"absolute_extreme_coefficient_ratio",
"(",
"model",
")",
":",
"s_matrix",
",",
"_",
",",
"_",
"=",
"con_helpers",
".",
"stoichiometry_matrix",
"(",
"model",
".",
"metabolites",
",",
"model",
".",
"reactions",
")",
"abs_matrix",
"=",
"np",
".",
"abs",
... | Return the maximum and minimum absolute, non-zero coefficients.
Parameters
----------
model : cobra.Model
The metabolic model under investigation. | [
"Return",
"the",
"maximum",
"and",
"minimum",
"absolute",
"non",
"-",
"zero",
"coefficients",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/matrix.py#L29-L43 |
2,420 | opencobra/memote | memote/support/matrix.py | number_independent_conservation_relations | def number_independent_conservation_relations(model):
"""
Return the number of conserved metabolite pools.
This number is given by the left null space of the stoichiometric matrix.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
"""
s_matrix,... | python | def number_independent_conservation_relations(model):
s_matrix, _, _ = con_helpers.stoichiometry_matrix(
model.metabolites, model.reactions
)
ln_matrix = con_helpers.nullspace(s_matrix.T)
return ln_matrix.shape[1] | [
"def",
"number_independent_conservation_relations",
"(",
"model",
")",
":",
"s_matrix",
",",
"_",
",",
"_",
"=",
"con_helpers",
".",
"stoichiometry_matrix",
"(",
"model",
".",
"metabolites",
",",
"model",
".",
"reactions",
")",
"ln_matrix",
"=",
"con_helpers",
"... | Return the number of conserved metabolite pools.
This number is given by the left null space of the stoichiometric matrix.
Parameters
----------
model : cobra.Model
The metabolic model under investigation. | [
"Return",
"the",
"number",
"of",
"conserved",
"metabolite",
"pools",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/matrix.py#L46-L62 |
2,421 | opencobra/memote | memote/support/matrix.py | matrix_rank | def matrix_rank(model):
"""
Return the rank of the model's stoichiometric matrix.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
"""
s_matrix, _, _ = con_helpers.stoichiometry_matrix(
model.metabolites, model.reactions
)
return co... | python | def matrix_rank(model):
s_matrix, _, _ = con_helpers.stoichiometry_matrix(
model.metabolites, model.reactions
)
return con_helpers.rank(s_matrix) | [
"def",
"matrix_rank",
"(",
"model",
")",
":",
"s_matrix",
",",
"_",
",",
"_",
"=",
"con_helpers",
".",
"stoichiometry_matrix",
"(",
"model",
".",
"metabolites",
",",
"model",
".",
"reactions",
")",
"return",
"con_helpers",
".",
"rank",
"(",
"s_matrix",
")"... | Return the rank of the model's stoichiometric matrix.
Parameters
----------
model : cobra.Model
The metabolic model under investigation. | [
"Return",
"the",
"rank",
"of",
"the",
"model",
"s",
"stoichiometric",
"matrix",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/matrix.py#L65-L78 |
2,422 | opencobra/memote | memote/support/matrix.py | degrees_of_freedom | def degrees_of_freedom(model):
"""
Return the degrees of freedom, i.e., number of "free variables".
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Notes
-----
This specifically refers to the dimensionality of the (right) null space
of the... | python | def degrees_of_freedom(model):
s_matrix, _, _ = con_helpers.stoichiometry_matrix(
model.metabolites, model.reactions
)
return s_matrix.shape[1] - matrix_rank(model) | [
"def",
"degrees_of_freedom",
"(",
"model",
")",
":",
"s_matrix",
",",
"_",
",",
"_",
"=",
"con_helpers",
".",
"stoichiometry_matrix",
"(",
"model",
".",
"metabolites",
",",
"model",
".",
"reactions",
")",
"return",
"s_matrix",
".",
"shape",
"[",
"1",
"]",
... | Return the degrees of freedom, i.e., number of "free variables".
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Notes
-----
This specifically refers to the dimensionality of the (right) null space
of the stoichiometric matrix, as dim(Null(S)) cor... | [
"Return",
"the",
"degrees",
"of",
"freedom",
"i",
".",
"e",
".",
"number",
"of",
"free",
"variables",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/matrix.py#L81-L109 |
2,423 | opencobra/memote | memote/experimental/config.py | ExperimentConfiguration.load | def load(self, model):
"""
Load all information from an experimental configuration file.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
"""
self.load_medium(model)
self.load_essentiality(model)
self... | python | def load(self, model):
self.load_medium(model)
self.load_essentiality(model)
self.load_growth(model)
# self.load_experiment(config.config.get("growth"), model)
return self | [
"def",
"load",
"(",
"self",
",",
"model",
")",
":",
"self",
".",
"load_medium",
"(",
"model",
")",
"self",
".",
"load_essentiality",
"(",
"model",
")",
"self",
".",
"load_growth",
"(",
"model",
")",
"# self.load_experiment(config.config.get(\"growth\"), model)",
... | Load all information from an experimental configuration file.
Parameters
----------
model : cobra.Model
The metabolic model under investigation. | [
"Load",
"all",
"information",
"from",
"an",
"experimental",
"configuration",
"file",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/config.py#L67-L81 |
2,424 | opencobra/memote | memote/experimental/config.py | ExperimentConfiguration.validate | def validate(self):
"""Validate the configuration file."""
validator = Draft4Validator(self.SCHEMA)
if not validator.is_valid(self.config):
for err in validator.iter_errors(self.config):
LOGGER.error(str(err.message))
validator.validate(self.config) | python | def validate(self):
validator = Draft4Validator(self.SCHEMA)
if not validator.is_valid(self.config):
for err in validator.iter_errors(self.config):
LOGGER.error(str(err.message))
validator.validate(self.config) | [
"def",
"validate",
"(",
"self",
")",
":",
"validator",
"=",
"Draft4Validator",
"(",
"self",
".",
"SCHEMA",
")",
"if",
"not",
"validator",
".",
"is_valid",
"(",
"self",
".",
"config",
")",
":",
"for",
"err",
"in",
"validator",
".",
"iter_errors",
"(",
"... | Validate the configuration file. | [
"Validate",
"the",
"configuration",
"file",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/config.py#L83-L89 |
2,425 | opencobra/memote | memote/experimental/config.py | ExperimentConfiguration.load_medium | def load_medium(self, model):
"""Load and validate all media."""
media = self.config.get("medium")
if media is None:
return
definitions = media.get("definitions")
if definitions is None or len(definitions) == 0:
return
path = self.get_path(media, j... | python | def load_medium(self, model):
media = self.config.get("medium")
if media is None:
return
definitions = media.get("definitions")
if definitions is None or len(definitions) == 0:
return
path = self.get_path(media, join("data", "experimental", "media"))
... | [
"def",
"load_medium",
"(",
"self",
",",
"model",
")",
":",
"media",
"=",
"self",
".",
"config",
".",
"get",
"(",
"\"medium\"",
")",
"if",
"media",
"is",
"None",
":",
"return",
"definitions",
"=",
"media",
".",
"get",
"(",
"\"definitions\"",
")",
"if",
... | Load and validate all media. | [
"Load",
"and",
"validate",
"all",
"media",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/config.py#L91-L111 |
2,426 | opencobra/memote | memote/experimental/config.py | ExperimentConfiguration.get_path | def get_path(self, obj, default):
"""Return a relative or absolute path to experimental data."""
path = obj.get("path")
if path is None:
path = join(self._base, default)
if not isabs(path):
path = join(self._base, path)
return path | python | def get_path(self, obj, default):
path = obj.get("path")
if path is None:
path = join(self._base, default)
if not isabs(path):
path = join(self._base, path)
return path | [
"def",
"get_path",
"(",
"self",
",",
"obj",
",",
"default",
")",
":",
"path",
"=",
"obj",
".",
"get",
"(",
"\"path\"",
")",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"join",
"(",
"self",
".",
"_base",
",",
"default",
")",
"if",
"not",
"isabs"... | Return a relative or absolute path to experimental data. | [
"Return",
"a",
"relative",
"or",
"absolute",
"path",
"to",
"experimental",
"data",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/config.py#L171-L178 |
2,427 | opencobra/memote | memote/support/annotation.py | find_components_without_annotation | def find_components_without_annotation(model, components):
"""
Find model components with empty annotation attributes.
Parameters
----------
model : cobra.Model
A cobrapy metabolic model.
components : {"metabolites", "reactions", "genes"}
A string denoting `cobra.Model` componen... | python | def find_components_without_annotation(model, components):
return [elem for elem in getattr(model, components) if
elem.annotation is None or len(elem.annotation) == 0] | [
"def",
"find_components_without_annotation",
"(",
"model",
",",
"components",
")",
":",
"return",
"[",
"elem",
"for",
"elem",
"in",
"getattr",
"(",
"model",
",",
"components",
")",
"if",
"elem",
".",
"annotation",
"is",
"None",
"or",
"len",
"(",
"elem",
".... | Find model components with empty annotation attributes.
Parameters
----------
model : cobra.Model
A cobrapy metabolic model.
components : {"metabolites", "reactions", "genes"}
A string denoting `cobra.Model` components.
Returns
-------
list
The components without an... | [
"Find",
"model",
"components",
"with",
"empty",
"annotation",
"attributes",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/annotation.py#L125-L143 |
2,428 | opencobra/memote | memote/support/annotation.py | generate_component_annotation_miriam_match | def generate_component_annotation_miriam_match(elements, component, db):
"""
Tabulate which MIRIAM databases the element's annotation match.
If the relevant MIRIAM identifier is not in an element's annotation it is
ignored.
Parameters
----------
elements : list
Elements of a model,... | python | def generate_component_annotation_miriam_match(elements, component, db):
def is_faulty(annotation, key, pattern):
# Ignore missing annotation for this database.
if key not in annotation:
return False
test = annotation[key]
if isinstance(test, native_str):
retu... | [
"def",
"generate_component_annotation_miriam_match",
"(",
"elements",
",",
"component",
",",
"db",
")",
":",
"def",
"is_faulty",
"(",
"annotation",
",",
"key",
",",
"pattern",
")",
":",
"# Ignore missing annotation for this database.",
"if",
"key",
"not",
"in",
"ann... | Tabulate which MIRIAM databases the element's annotation match.
If the relevant MIRIAM identifier is not in an element's annotation it is
ignored.
Parameters
----------
elements : list
Elements of a model, either metabolites or reactions.
component : {"metabolites", "reactions"}
... | [
"Tabulate",
"which",
"MIRIAM",
"databases",
"the",
"element",
"s",
"annotation",
"match",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/annotation.py#L167-L206 |
2,429 | opencobra/memote | memote/support/annotation.py | generate_component_id_namespace_overview | def generate_component_id_namespace_overview(model, components):
"""
Tabulate which MIRIAM databases the component's identifier matches.
Parameters
----------
model : cobra.Model
A cobrapy metabolic model.
components : {"metabolites", "reactions", "genes"}
A string denoting `cob... | python | def generate_component_id_namespace_overview(model, components):
patterns = {
"metabolites": METABOLITE_ANNOTATIONS,
"reactions": REACTION_ANNOTATIONS,
"genes": GENE_PRODUCT_ANNOTATIONS
}[components]
databases = list(patterns)
data = list()
index = list()
for elem in geta... | [
"def",
"generate_component_id_namespace_overview",
"(",
"model",
",",
"components",
")",
":",
"patterns",
"=",
"{",
"\"metabolites\"",
":",
"METABOLITE_ANNOTATIONS",
",",
"\"reactions\"",
":",
"REACTION_ANNOTATIONS",
",",
"\"genes\"",
":",
"GENE_PRODUCT_ANNOTATIONS",
"}",... | Tabulate which MIRIAM databases the component's identifier matches.
Parameters
----------
model : cobra.Model
A cobrapy metabolic model.
components : {"metabolites", "reactions", "genes"}
A string denoting `cobra.Model` components.
Returns
-------
pandas.DataFrame
T... | [
"Tabulate",
"which",
"MIRIAM",
"databases",
"the",
"component",
"s",
"identifier",
"matches",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/annotation.py#L209-L257 |
2,430 | opencobra/memote | memote/support/essentiality.py | confusion_matrix | def confusion_matrix(predicted_essential, expected_essential,
predicted_nonessential, expected_nonessential):
"""
Compute a representation of the confusion matrix.
Parameters
----------
predicted_essential : set
expected_essential : set
predicted_nonessential : set
... | python | def confusion_matrix(predicted_essential, expected_essential,
predicted_nonessential, expected_nonessential):
true_positive = predicted_essential & expected_essential
tp = len(true_positive)
true_negative = predicted_nonessential & expected_nonessential
tn = len(true_negative)
f... | [
"def",
"confusion_matrix",
"(",
"predicted_essential",
",",
"expected_essential",
",",
"predicted_nonessential",
",",
"expected_nonessential",
")",
":",
"true_positive",
"=",
"predicted_essential",
"&",
"expected_essential",
"tp",
"=",
"len",
"(",
"true_positive",
")",
... | Compute a representation of the confusion matrix.
Parameters
----------
predicted_essential : set
expected_essential : set
predicted_nonessential : set
expected_nonessential : set
Returns
-------
dict
Confusion matrix as different keys of a dictionary. The abbreviated
... | [
"Compute",
"a",
"representation",
"of",
"the",
"confusion",
"matrix",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/essentiality.py#L29-L100 |
2,431 | opencobra/memote | memote/suite/api.py | validate_model | def validate_model(path):
"""
Validate a model structurally and optionally store results as JSON.
Parameters
----------
path :
Path to model file.
Returns
-------
tuple
cobra.Model
The metabolic model under investigation.
tuple
A tuple re... | python | def validate_model(path):
notifications = {"warnings": [], "errors": []}
model, sbml_ver = val.load_cobra_model(path, notifications)
return model, sbml_ver, notifications | [
"def",
"validate_model",
"(",
"path",
")",
":",
"notifications",
"=",
"{",
"\"warnings\"",
":",
"[",
"]",
",",
"\"errors\"",
":",
"[",
"]",
"}",
"model",
",",
"sbml_ver",
"=",
"val",
".",
"load_cobra_model",
"(",
"path",
",",
"notifications",
")",
"retur... | Validate a model structurally and optionally store results as JSON.
Parameters
----------
path :
Path to model file.
Returns
-------
tuple
cobra.Model
The metabolic model under investigation.
tuple
A tuple reporting on the SBML level, version, an... | [
"Validate",
"a",
"model",
"structurally",
"and",
"optionally",
"store",
"results",
"as",
"JSON",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/api.py#L41-L64 |
2,432 | opencobra/memote | memote/suite/api.py | snapshot_report | def snapshot_report(result, config=None, html=True):
"""
Generate a snapshot report from a result set and configuration.
Parameters
----------
result : memote.MemoteResult
Nested dictionary structure as returned from the test suite.
config : dict, optional
The final test report ... | python | def snapshot_report(result, config=None, html=True):
if config is None:
config = ReportConfiguration.load()
report = SnapshotReport(result=result, configuration=config)
if html:
return report.render_html()
else:
return report.render_json() | [
"def",
"snapshot_report",
"(",
"result",
",",
"config",
"=",
"None",
",",
"html",
"=",
"True",
")",
":",
"if",
"config",
"is",
"None",
":",
"config",
"=",
"ReportConfiguration",
".",
"load",
"(",
")",
"report",
"=",
"SnapshotReport",
"(",
"result",
"=",
... | Generate a snapshot report from a result set and configuration.
Parameters
----------
result : memote.MemoteResult
Nested dictionary structure as returned from the test suite.
config : dict, optional
The final test report configuration (default None).
html : bool, optional
W... | [
"Generate",
"a",
"snapshot",
"report",
"from",
"a",
"result",
"set",
"and",
"configuration",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/api.py#L112-L132 |
2,433 | opencobra/memote | memote/suite/api.py | history_report | def history_report(history, config=None, html=True):
"""
Test a model and save a history report.
Parameters
----------
history : memote.HistoryManager
The manager grants access to previous results.
config : dict, optional
The final test report configuration.
html : bool, opt... | python | def history_report(history, config=None, html=True):
if config is None:
config = ReportConfiguration.load()
report = HistoryReport(history=history, configuration=config)
if html:
return report.render_html()
else:
return report.render_json() | [
"def",
"history_report",
"(",
"history",
",",
"config",
"=",
"None",
",",
"html",
"=",
"True",
")",
":",
"if",
"config",
"is",
"None",
":",
"config",
"=",
"ReportConfiguration",
".",
"load",
"(",
")",
"report",
"=",
"HistoryReport",
"(",
"history",
"=",
... | Test a model and save a history report.
Parameters
----------
history : memote.HistoryManager
The manager grants access to previous results.
config : dict, optional
The final test report configuration.
html : bool, optional
Whether to render the report as full HTML or JSON (... | [
"Test",
"a",
"model",
"and",
"save",
"a",
"history",
"report",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/api.py#L135-L155 |
2,434 | opencobra/memote | memote/suite/api.py | diff_report | def diff_report(diff_results, config=None, html=True):
"""
Generate a diff report from a result set and configuration.
Parameters
----------
diff_results : iterable of memote.MemoteResult
Nested dictionary structure as returned from the test suite.
config : dict, optional
The fi... | python | def diff_report(diff_results, config=None, html=True):
if config is None:
config = ReportConfiguration.load()
report = DiffReport(diff_results=diff_results, configuration=config)
if html:
return report.render_html()
else:
return report.render_json() | [
"def",
"diff_report",
"(",
"diff_results",
",",
"config",
"=",
"None",
",",
"html",
"=",
"True",
")",
":",
"if",
"config",
"is",
"None",
":",
"config",
"=",
"ReportConfiguration",
".",
"load",
"(",
")",
"report",
"=",
"DiffReport",
"(",
"diff_results",
"... | Generate a diff report from a result set and configuration.
Parameters
----------
diff_results : iterable of memote.MemoteResult
Nested dictionary structure as returned from the test suite.
config : dict, optional
The final test report configuration (default None).
html : bool, opti... | [
"Generate",
"a",
"diff",
"report",
"from",
"a",
"result",
"set",
"and",
"configuration",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/api.py#L158-L178 |
2,435 | opencobra/memote | memote/suite/api.py | validation_report | def validation_report(path, notifications, filename):
"""
Generate a validation report from a notification object.
Parameters
----------
path : string
Path to model file.
notifications : dict
A simple dictionary structure containing a list of errors and warnings.
"""
en... | python | def validation_report(path, notifications, filename):
env = Environment(
loader=PackageLoader('memote.suite', 'templates'),
autoescape=select_autoescape(['html', 'xml'])
)
template = env.get_template('validation_template.html')
model = os.path.basename(path)
with open(filename, "w") ... | [
"def",
"validation_report",
"(",
"path",
",",
"notifications",
",",
"filename",
")",
":",
"env",
"=",
"Environment",
"(",
"loader",
"=",
"PackageLoader",
"(",
"'memote.suite'",
",",
"'templates'",
")",
",",
"autoescape",
"=",
"select_autoescape",
"(",
"[",
"'h... | Generate a validation report from a notification object.
Parameters
----------
path : string
Path to model file.
notifications : dict
A simple dictionary structure containing a list of errors and warnings. | [
"Generate",
"a",
"validation",
"report",
"from",
"a",
"notification",
"object",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/api.py#L181-L200 |
2,436 | opencobra/memote | memote/suite/reporting/config.py | ReportConfiguration.load | def load(cls, filename=None):
"""Load a test report configuration."""
if filename is None:
LOGGER.debug("Loading default configuration.")
with open_text(templates, "test_config.yml",
encoding="utf-8") as file_handle:
content = yaml.load(... | python | def load(cls, filename=None):
if filename is None:
LOGGER.debug("Loading default configuration.")
with open_text(templates, "test_config.yml",
encoding="utf-8") as file_handle:
content = yaml.load(file_handle)
else:
LOGGER.de... | [
"def",
"load",
"(",
"cls",
",",
"filename",
"=",
"None",
")",
":",
"if",
"filename",
"is",
"None",
":",
"LOGGER",
".",
"debug",
"(",
"\"Loading default configuration.\"",
")",
"with",
"open_text",
"(",
"templates",
",",
"\"test_config.yml\"",
",",
"encoding",
... | Load a test report configuration. | [
"Load",
"a",
"test",
"report",
"configuration",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/reporting/config.py#L52-L70 |
2,437 | opencobra/memote | memote/support/gpr_helpers.py | find_top_level_complex | def find_top_level_complex(gpr):
"""
Find unique elements of both branches of the top level logical AND.
Parameters
----------
gpr : str
The gene-protein-reaction association as a string.
Returns
-------
int
The size of the symmetric difference between the set of elemen... | python | def find_top_level_complex(gpr):
logger.debug("%r", gpr)
conform = logical_and.sub("and", gpr)
conform = logical_or.sub("or", conform)
conform = escape_chars.sub("_", conform)
expression = ast.parse(conform)
walker = GPRVisitor()
walker.visit(expression)
return len(walker.left ^ walker.r... | [
"def",
"find_top_level_complex",
"(",
"gpr",
")",
":",
"logger",
".",
"debug",
"(",
"\"%r\"",
",",
"gpr",
")",
"conform",
"=",
"logical_and",
".",
"sub",
"(",
"\"and\"",
",",
"gpr",
")",
"conform",
"=",
"logical_or",
".",
"sub",
"(",
"\"or\"",
",",
"co... | Find unique elements of both branches of the top level logical AND.
Parameters
----------
gpr : str
The gene-protein-reaction association as a string.
Returns
-------
int
The size of the symmetric difference between the set of elements to
the left of the top level logic... | [
"Find",
"unique",
"elements",
"of",
"both",
"branches",
"of",
"the",
"top",
"level",
"logical",
"AND",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/gpr_helpers.py#L107-L130 |
2,438 | opencobra/memote | memote/support/gpr_helpers.py | GPRVisitor.visit_BoolOp | def visit_BoolOp(self, node):
"""Set up recording of elements with this hook."""
if self._is_top and isinstance(node.op, ast.And):
self._is_top = False
self._current = self.left
self.visit(node.values[0])
self._current = self.right
for successo... | python | def visit_BoolOp(self, node):
if self._is_top and isinstance(node.op, ast.And):
self._is_top = False
self._current = self.left
self.visit(node.values[0])
self._current = self.right
for successor in node.values[1:]:
self.visit(successor)... | [
"def",
"visit_BoolOp",
"(",
"self",
",",
"node",
")",
":",
"if",
"self",
".",
"_is_top",
"and",
"isinstance",
"(",
"node",
".",
"op",
",",
"ast",
".",
"And",
")",
":",
"self",
".",
"_is_top",
"=",
"False",
"self",
".",
"_current",
"=",
"self",
".",... | Set up recording of elements with this hook. | [
"Set",
"up",
"recording",
"of",
"elements",
"with",
"this",
"hook",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/gpr_helpers.py#L90-L100 |
2,439 | opencobra/memote | memote/support/basic.py | find_nonzero_constrained_reactions | def find_nonzero_constrained_reactions(model):
"""Return list of reactions with non-zero, non-maximal bounds."""
lower_bound, upper_bound = helpers.find_bounds(model)
return [rxn for rxn in model.reactions if
0 > rxn.lower_bound > lower_bound or
0 < rxn.upper_bound < upper_bound] | python | def find_nonzero_constrained_reactions(model):
lower_bound, upper_bound = helpers.find_bounds(model)
return [rxn for rxn in model.reactions if
0 > rxn.lower_bound > lower_bound or
0 < rxn.upper_bound < upper_bound] | [
"def",
"find_nonzero_constrained_reactions",
"(",
"model",
")",
":",
"lower_bound",
",",
"upper_bound",
"=",
"helpers",
".",
"find_bounds",
"(",
"model",
")",
"return",
"[",
"rxn",
"for",
"rxn",
"in",
"model",
".",
"reactions",
"if",
"0",
">",
"rxn",
".",
... | Return list of reactions with non-zero, non-maximal bounds. | [
"Return",
"list",
"of",
"reactions",
"with",
"non",
"-",
"zero",
"non",
"-",
"maximal",
"bounds",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L53-L58 |
2,440 | opencobra/memote | memote/support/basic.py | find_zero_constrained_reactions | def find_zero_constrained_reactions(model):
"""Return list of reactions that are constrained to zero flux."""
return [rxn for rxn in model.reactions if
rxn.lower_bound == 0 and
rxn.upper_bound == 0] | python | def find_zero_constrained_reactions(model):
return [rxn for rxn in model.reactions if
rxn.lower_bound == 0 and
rxn.upper_bound == 0] | [
"def",
"find_zero_constrained_reactions",
"(",
"model",
")",
":",
"return",
"[",
"rxn",
"for",
"rxn",
"in",
"model",
".",
"reactions",
"if",
"rxn",
".",
"lower_bound",
"==",
"0",
"and",
"rxn",
".",
"upper_bound",
"==",
"0",
"]"
] | Return list of reactions that are constrained to zero flux. | [
"Return",
"list",
"of",
"reactions",
"that",
"are",
"constrained",
"to",
"zero",
"flux",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L61-L65 |
2,441 | opencobra/memote | memote/support/basic.py | find_unconstrained_reactions | def find_unconstrained_reactions(model):
"""Return list of reactions that are not constrained at all."""
lower_bound, upper_bound = helpers.find_bounds(model)
return [rxn for rxn in model.reactions if
rxn.lower_bound <= lower_bound and
rxn.upper_bound >= upper_bound] | python | def find_unconstrained_reactions(model):
lower_bound, upper_bound = helpers.find_bounds(model)
return [rxn for rxn in model.reactions if
rxn.lower_bound <= lower_bound and
rxn.upper_bound >= upper_bound] | [
"def",
"find_unconstrained_reactions",
"(",
"model",
")",
":",
"lower_bound",
",",
"upper_bound",
"=",
"helpers",
".",
"find_bounds",
"(",
"model",
")",
"return",
"[",
"rxn",
"for",
"rxn",
"in",
"model",
".",
"reactions",
"if",
"rxn",
".",
"lower_bound",
"<=... | Return list of reactions that are not constrained at all. | [
"Return",
"list",
"of",
"reactions",
"that",
"are",
"not",
"constrained",
"at",
"all",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L73-L78 |
2,442 | opencobra/memote | memote/support/basic.py | find_ngam | def find_ngam(model):
u"""
Return all potential non growth-associated maintenance reactions.
From the list of all reactions that convert ATP to ADP select the reactions
that match a defined reaction string and whose metabolites are situated
within the main model compartment. The main model compartm... | python | def find_ngam(model):
u"""
Return all potential non growth-associated maintenance reactions.
From the list of all reactions that convert ATP to ADP select the reactions
that match a defined reaction string and whose metabolites are situated
within the main model compartment. The main model compartm... | [
"def",
"find_ngam",
"(",
"model",
")",
":",
"atp_adp_conv_rxns",
"=",
"helpers",
".",
"find_converting_reactions",
"(",
"model",
",",
"(",
"\"MNXM3\"",
",",
"\"MNXM7\"",
")",
")",
"id_of_main_compartment",
"=",
"helpers",
".",
"find_compartment_id_in_model",
"(",
... | u"""
Return all potential non growth-associated maintenance reactions.
From the list of all reactions that convert ATP to ADP select the reactions
that match a defined reaction string and whose metabolites are situated
within the main model compartment. The main model compartment is the
cytosol, an... | [
"u",
"Return",
"all",
"potential",
"non",
"growth",
"-",
"associated",
"maintenance",
"reactions",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L81-L148 |
2,443 | opencobra/memote | memote/support/basic.py | calculate_metabolic_coverage | def calculate_metabolic_coverage(model):
u"""
Return the ratio of reactions and genes included in the model.
Determine whether the amount of reactions and genes in model not equal to
zero, then return the ratio.
Parameters
----------
model : cobra.Model
The metabolic model under in... | python | def calculate_metabolic_coverage(model):
u"""
Return the ratio of reactions and genes included in the model.
Determine whether the amount of reactions and genes in model not equal to
zero, then return the ratio.
Parameters
----------
model : cobra.Model
The metabolic model under in... | [
"def",
"calculate_metabolic_coverage",
"(",
"model",
")",
":",
"if",
"len",
"(",
"model",
".",
"reactions",
")",
"==",
"0",
"or",
"len",
"(",
"model",
".",
"genes",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"\"The model contains no reactions or genes.\"... | u"""
Return the ratio of reactions and genes included in the model.
Determine whether the amount of reactions and genes in model not equal to
zero, then return the ratio.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Returns
-------
flo... | [
"u",
"Return",
"the",
"ratio",
"of",
"reactions",
"and",
"genes",
"included",
"in",
"the",
"model",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L151-L192 |
2,444 | opencobra/memote | memote/support/basic.py | find_protein_complexes | def find_protein_complexes(model):
"""
Find reactions that are catalyzed by at least a heterodimer.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Returns
-------
list
Reactions whose gene-protein-reaction association contains at leas... | python | def find_protein_complexes(model):
complexes = []
for rxn in model.reactions:
if not rxn.gene_reaction_rule:
continue
size = find_top_level_complex(rxn.gene_reaction_rule)
if size >= 2:
complexes.append(rxn)
return complexes | [
"def",
"find_protein_complexes",
"(",
"model",
")",
":",
"complexes",
"=",
"[",
"]",
"for",
"rxn",
"in",
"model",
".",
"reactions",
":",
"if",
"not",
"rxn",
".",
"gene_reaction_rule",
":",
"continue",
"size",
"=",
"find_top_level_complex",
"(",
"rxn",
".",
... | Find reactions that are catalyzed by at least a heterodimer.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
Returns
-------
list
Reactions whose gene-protein-reaction association contains at least one
logical AND combining different g... | [
"Find",
"reactions",
"that",
"are",
"catalyzed",
"by",
"at",
"least",
"a",
"heterodimer",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L195-L218 |
2,445 | opencobra/memote | memote/support/basic.py | is_constrained_reaction | def is_constrained_reaction(model, rxn):
"""Return whether a reaction has fixed constraints."""
lower_bound, upper_bound = helpers.find_bounds(model)
if rxn.reversibility:
return rxn.lower_bound > lower_bound or rxn.upper_bound < upper_bound
else:
return rxn.lower_bound > 0 or rxn.upper_... | python | def is_constrained_reaction(model, rxn):
lower_bound, upper_bound = helpers.find_bounds(model)
if rxn.reversibility:
return rxn.lower_bound > lower_bound or rxn.upper_bound < upper_bound
else:
return rxn.lower_bound > 0 or rxn.upper_bound < upper_bound | [
"def",
"is_constrained_reaction",
"(",
"model",
",",
"rxn",
")",
":",
"lower_bound",
",",
"upper_bound",
"=",
"helpers",
".",
"find_bounds",
"(",
"model",
")",
"if",
"rxn",
".",
"reversibility",
":",
"return",
"rxn",
".",
"lower_bound",
">",
"lower_bound",
"... | Return whether a reaction has fixed constraints. | [
"Return",
"whether",
"a",
"reaction",
"has",
"fixed",
"constraints",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L236-L242 |
2,446 | opencobra/memote | memote/support/basic.py | find_unique_metabolites | def find_unique_metabolites(model):
"""Return set of metabolite IDs without duplicates from compartments."""
unique = set()
for met in model.metabolites:
is_missing = True
for comp in model.compartments:
if met.id.endswith("_{}".format(comp)):
unique.add(met.id[:-... | python | def find_unique_metabolites(model):
unique = set()
for met in model.metabolites:
is_missing = True
for comp in model.compartments:
if met.id.endswith("_{}".format(comp)):
unique.add(met.id[:-(len(comp) + 1)])
is_missing = False
break
... | [
"def",
"find_unique_metabolites",
"(",
"model",
")",
":",
"unique",
"=",
"set",
"(",
")",
"for",
"met",
"in",
"model",
".",
"metabolites",
":",
"is_missing",
"=",
"True",
"for",
"comp",
"in",
"model",
".",
"compartments",
":",
"if",
"met",
".",
"id",
"... | Return set of metabolite IDs without duplicates from compartments. | [
"Return",
"set",
"of",
"metabolite",
"IDs",
"without",
"duplicates",
"from",
"compartments",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L253-L265 |
2,447 | opencobra/memote | memote/support/basic.py | find_duplicate_metabolites_in_compartments | def find_duplicate_metabolites_in_compartments(model):
"""
Return list of metabolites with duplicates in the same compartment.
This function identifies duplicate metabolites in each compartment by
determining if any two metabolites have identical InChI-key annotations.
For instance, this function w... | python | def find_duplicate_metabolites_in_compartments(model):
unique_identifiers = ["inchikey", "inchi"]
duplicates = []
for met_1, met_2 in combinations(model.metabolites, 2):
if met_1.compartment == met_2.compartment:
for key in unique_identifiers:
if key in met_1.annotation a... | [
"def",
"find_duplicate_metabolites_in_compartments",
"(",
"model",
")",
":",
"unique_identifiers",
"=",
"[",
"\"inchikey\"",
",",
"\"inchi\"",
"]",
"duplicates",
"=",
"[",
"]",
"for",
"met_1",
",",
"met_2",
"in",
"combinations",
"(",
"model",
".",
"metabolites",
... | Return list of metabolites with duplicates in the same compartment.
This function identifies duplicate metabolites in each compartment by
determining if any two metabolites have identical InChI-key annotations.
For instance, this function would find compounds with IDs ATP1 and ATP2 in
the cytosolic com... | [
"Return",
"list",
"of",
"metabolites",
"with",
"duplicates",
"in",
"the",
"same",
"compartment",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L269-L298 |
2,448 | opencobra/memote | memote/support/basic.py | find_reactions_with_partially_identical_annotations | def find_reactions_with_partially_identical_annotations(model):
"""
Return duplicate reactions based on identical annotation.
Identify duplicate reactions globally by checking if any two metabolic
reactions have the same entries in their annotation attributes. This can be
useful to identify one 'ty... | python | def find_reactions_with_partially_identical_annotations(model):
duplicates = {}
rxn_db_identifiers = ["metanetx.reaction", "kegg.reaction", "brenda",
"rhea", "biocyc", "bigg.reaction"]
# Build a list that associates a reaction with a set of its annotations.
ann_rxns = []
fo... | [
"def",
"find_reactions_with_partially_identical_annotations",
"(",
"model",
")",
":",
"duplicates",
"=",
"{",
"}",
"rxn_db_identifiers",
"=",
"[",
"\"metanetx.reaction\"",
",",
"\"kegg.reaction\"",
",",
"\"brenda\"",
",",
"\"rhea\"",
",",
"\"biocyc\"",
",",
"\"bigg.reac... | Return duplicate reactions based on identical annotation.
Identify duplicate reactions globally by checking if any two metabolic
reactions have the same entries in their annotation attributes. This can be
useful to identify one 'type' of reactions that occurs in several
compartments, to curate merged m... | [
"Return",
"duplicate",
"reactions",
"based",
"on",
"identical",
"annotation",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L301-L356 |
2,449 | opencobra/memote | memote/support/basic.py | map_metabolites_to_structures | def map_metabolites_to_structures(metabolites, compartments):
"""
Map metabolites from the identifier namespace to structural space.
Metabolites who lack structural annotation (InChI or InChIKey) are ignored.
Parameters
----------
metabolites : iterable
The cobra.Metabolites to map.
... | python | def map_metabolites_to_structures(metabolites, compartments):
# TODO (Moritz Beber): Consider SMILES?
unique_identifiers = ["inchikey", "inchi"]
met2mol = {}
molecules = {c: [] for c in compartments}
for met in metabolites:
ann = []
for key in unique_identifiers:
mol = me... | [
"def",
"map_metabolites_to_structures",
"(",
"metabolites",
",",
"compartments",
")",
":",
"# TODO (Moritz Beber): Consider SMILES?",
"unique_identifiers",
"=",
"[",
"\"inchikey\"",
",",
"\"inchi\"",
"]",
"met2mol",
"=",
"{",
"}",
"molecules",
"=",
"{",
"c",
":",
"[... | Map metabolites from the identifier namespace to structural space.
Metabolites who lack structural annotation (InChI or InChIKey) are ignored.
Parameters
----------
metabolites : iterable
The cobra.Metabolites to map.
compartments : iterable
The different compartments to consider. ... | [
"Map",
"metabolites",
"from",
"the",
"identifier",
"namespace",
"to",
"structural",
"space",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L359-L407 |
2,450 | opencobra/memote | memote/support/basic.py | find_duplicate_reactions | def find_duplicate_reactions(model):
"""
Return a list with pairs of reactions that are functionally identical.
Identify duplicate reactions globally by checking if any
two reactions have the same metabolites, same directionality and are in
the same compartment.
This can be useful to curate me... | python | def find_duplicate_reactions(model):
met2mol = map_metabolites_to_structures(model.metabolites,
model.compartments)
# Build a list associating reactions with their stoichiometry in molecular
# structure space.
structural = []
for rxn in model.reactions:
... | [
"def",
"find_duplicate_reactions",
"(",
"model",
")",
":",
"met2mol",
"=",
"map_metabolites_to_structures",
"(",
"model",
".",
"metabolites",
",",
"model",
".",
"compartments",
")",
"# Build a list associating reactions with their stoichiometry in molecular",
"# structure space... | Return a list with pairs of reactions that are functionally identical.
Identify duplicate reactions globally by checking if any
two reactions have the same metabolites, same directionality and are in
the same compartment.
This can be useful to curate merged models or to clean-up bulk model
modific... | [
"Return",
"a",
"list",
"with",
"pairs",
"of",
"reactions",
"that",
"are",
"functionally",
"identical",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L410-L479 |
2,451 | opencobra/memote | memote/support/basic.py | find_reactions_with_identical_genes | def find_reactions_with_identical_genes(model):
"""
Return reactions that have identical genes.
Identify duplicate reactions globally by checking if any
two reactions have the same genes.
This can be useful to curate merged models or to clean-up bulk model
modifications, but also to identify pr... | python | def find_reactions_with_identical_genes(model):
duplicates = dict()
for rxn_a, rxn_b in combinations(model.reactions, 2):
if not (rxn_a.genes and rxn_b.genes):
continue
if rxn_a.genes == rxn_b.genes:
# This works because the `genes` are frozen sets.
identifier... | [
"def",
"find_reactions_with_identical_genes",
"(",
"model",
")",
":",
"duplicates",
"=",
"dict",
"(",
")",
"for",
"rxn_a",
",",
"rxn_b",
"in",
"combinations",
"(",
"model",
".",
"reactions",
",",
"2",
")",
":",
"if",
"not",
"(",
"rxn_a",
".",
"genes",
"a... | Return reactions that have identical genes.
Identify duplicate reactions globally by checking if any
two reactions have the same genes.
This can be useful to curate merged models or to clean-up bulk model
modifications, but also to identify promiscuous enzymes.
The heuristic compares reactions in a... | [
"Return",
"reactions",
"that",
"have",
"identical",
"genes",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L482-L526 |
2,452 | opencobra/memote | memote/support/basic.py | find_external_metabolites | def find_external_metabolites(model):
"""Return all metabolites in the external compartment."""
ex_comp = find_external_compartment(model)
return [met for met in model.metabolites if met.compartment == ex_comp] | python | def find_external_metabolites(model):
ex_comp = find_external_compartment(model)
return [met for met in model.metabolites if met.compartment == ex_comp] | [
"def",
"find_external_metabolites",
"(",
"model",
")",
":",
"ex_comp",
"=",
"find_external_compartment",
"(",
"model",
")",
"return",
"[",
"met",
"for",
"met",
"in",
"model",
".",
"metabolites",
"if",
"met",
".",
"compartment",
"==",
"ex_comp",
"]"
] | Return all metabolites in the external compartment. | [
"Return",
"all",
"metabolites",
"in",
"the",
"external",
"compartment",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/basic.py#L541-L544 |
2,453 | opencobra/memote | memote/suite/results/result_manager.py | ResultManager.store | def store(self, result, filename, pretty=True):
"""
Write a result to the given file.
Parameters
----------
result : memote.MemoteResult
The dictionary structure of results.
filename : str or pathlib.Path
Store results directly to the given filena... | python | def store(self, result, filename, pretty=True):
LOGGER.info("Storing result in '%s'.", filename)
if filename.endswith(".gz"):
with gzip.open(filename, "wb") as file_handle:
file_handle.write(
jsonify(result, pretty=pretty).encode("utf-8")
)... | [
"def",
"store",
"(",
"self",
",",
"result",
",",
"filename",
",",
"pretty",
"=",
"True",
")",
":",
"LOGGER",
".",
"info",
"(",
"\"Storing result in '%s'.\"",
",",
"filename",
")",
"if",
"filename",
".",
"endswith",
"(",
"\".gz\"",
")",
":",
"with",
"gzip... | Write a result to the given file.
Parameters
----------
result : memote.MemoteResult
The dictionary structure of results.
filename : str or pathlib.Path
Store results directly to the given filename.
pretty : bool, optional
Whether (default) or... | [
"Write",
"a",
"result",
"to",
"the",
"given",
"file",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/result_manager.py#L42-L64 |
2,454 | opencobra/memote | memote/suite/results/result_manager.py | ResultManager.load | def load(self, filename):
"""Load a result from the given JSON file."""
LOGGER.info("Loading result from '%s'.", filename)
if filename.endswith(".gz"):
with gzip.open(filename, "rb") as file_handle:
result = MemoteResult(
json.loads(file_handle.rea... | python | def load(self, filename):
LOGGER.info("Loading result from '%s'.", filename)
if filename.endswith(".gz"):
with gzip.open(filename, "rb") as file_handle:
result = MemoteResult(
json.loads(file_handle.read().decode("utf-8"))
)
else:
... | [
"def",
"load",
"(",
"self",
",",
"filename",
")",
":",
"LOGGER",
".",
"info",
"(",
"\"Loading result from '%s'.\"",
",",
"filename",
")",
"if",
"filename",
".",
"endswith",
"(",
"\".gz\"",
")",
":",
"with",
"gzip",
".",
"open",
"(",
"filename",
",",
"\"r... | Load a result from the given JSON file. | [
"Load",
"a",
"result",
"from",
"the",
"given",
"JSON",
"file",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/result_manager.py#L66-L80 |
2,455 | opencobra/memote | memote/support/validation.py | load_cobra_model | def load_cobra_model(path, notifications):
"""Load a COBRA model with meta information from an SBML document."""
doc = libsbml.readSBML(path)
fbc = doc.getPlugin("fbc")
sbml_ver = doc.getLevel(), doc.getVersion(), fbc if fbc is None else \
fbc.getVersion()
with catch_warnings(record=True) as... | python | def load_cobra_model(path, notifications):
doc = libsbml.readSBML(path)
fbc = doc.getPlugin("fbc")
sbml_ver = doc.getLevel(), doc.getVersion(), fbc if fbc is None else \
fbc.getVersion()
with catch_warnings(record=True) as warnings:
simplefilter("always")
try:
model =... | [
"def",
"load_cobra_model",
"(",
"path",
",",
"notifications",
")",
":",
"doc",
"=",
"libsbml",
".",
"readSBML",
"(",
"path",
")",
"fbc",
"=",
"doc",
".",
"getPlugin",
"(",
"\"fbc\"",
")",
"sbml_ver",
"=",
"doc",
".",
"getLevel",
"(",
")",
",",
"doc",
... | Load a COBRA model with meta information from an SBML document. | [
"Load",
"a",
"COBRA",
"model",
"with",
"meta",
"information",
"from",
"an",
"SBML",
"document",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/validation.py#L30-L49 |
2,456 | opencobra/memote | memote/support/validation.py | format_failure | def format_failure(failure):
"""Format how an error or warning should be displayed."""
return "Line {}, Column {} - #{}: {} - Category: {}, Severity: {}".format(
failure.getLine(),
failure.getColumn(),
failure.getErrorId(),
failure.getMessage(),
failure.getCategoryAsStrin... | python | def format_failure(failure):
return "Line {}, Column {} - #{}: {} - Category: {}, Severity: {}".format(
failure.getLine(),
failure.getColumn(),
failure.getErrorId(),
failure.getMessage(),
failure.getCategoryAsString(),
failure.getSeverity()
) | [
"def",
"format_failure",
"(",
"failure",
")",
":",
"return",
"\"Line {}, Column {} - #{}: {} - Category: {}, Severity: {}\"",
".",
"format",
"(",
"failure",
".",
"getLine",
"(",
")",
",",
"failure",
".",
"getColumn",
"(",
")",
",",
"failure",
".",
"getErrorId",
"(... | Format how an error or warning should be displayed. | [
"Format",
"how",
"an",
"error",
"or",
"warning",
"should",
"be",
"displayed",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/validation.py#L52-L61 |
2,457 | opencobra/memote | memote/support/validation.py | run_sbml_validation | def run_sbml_validation(document, notifications):
"""Report errors and warnings found in an SBML document."""
validator = libsbml.SBMLValidator()
validator.validate(document)
for i in range(document.getNumErrors()):
notifications['errors'].append(format_failure(document.getError(i)))
for i i... | python | def run_sbml_validation(document, notifications):
validator = libsbml.SBMLValidator()
validator.validate(document)
for i in range(document.getNumErrors()):
notifications['errors'].append(format_failure(document.getError(i)))
for i in range(validator.getNumFailures()):
failure = validator... | [
"def",
"run_sbml_validation",
"(",
"document",
",",
"notifications",
")",
":",
"validator",
"=",
"libsbml",
".",
"SBMLValidator",
"(",
")",
"validator",
".",
"validate",
"(",
"document",
")",
"for",
"i",
"in",
"range",
"(",
"document",
".",
"getNumErrors",
"... | Report errors and warnings found in an SBML document. | [
"Report",
"errors",
"and",
"warnings",
"found",
"in",
"an",
"SBML",
"document",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/validation.py#L64-L75 |
2,458 | opencobra/memote | memote/suite/results/sql_result_manager.py | SQLResultManager.load | def load(self, commit=None):
"""Load a result from the database."""
git_info = self.record_git_info(commit)
LOGGER.info("Loading result from '%s'.", git_info.hexsha)
result = MemoteResult(
self.session.query(Result.memote_result).
filter_by(hexsha=git_info.hexsha)... | python | def load(self, commit=None):
git_info = self.record_git_info(commit)
LOGGER.info("Loading result from '%s'.", git_info.hexsha)
result = MemoteResult(
self.session.query(Result.memote_result).
filter_by(hexsha=git_info.hexsha).
one().memote_result)
# Ad... | [
"def",
"load",
"(",
"self",
",",
"commit",
"=",
"None",
")",
":",
"git_info",
"=",
"self",
".",
"record_git_info",
"(",
"commit",
")",
"LOGGER",
".",
"info",
"(",
"\"Loading result from '%s'.\"",
",",
"git_info",
".",
"hexsha",
")",
"result",
"=",
"MemoteR... | Load a result from the database. | [
"Load",
"a",
"result",
"from",
"the",
"database",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/sql_result_manager.py#L89-L100 |
2,459 | opencobra/memote | memote/suite/reporting/history.py | HistoryReport.collect_history | def collect_history(self):
"""Build the structure of results in terms of a commit history."""
def format_data(data):
"""Format result data according to the user-defined type."""
# TODO Remove this failsafe once proper error handling is in place.
if type == "percent" o... | python | def collect_history(self):
def format_data(data):
"""Format result data according to the user-defined type."""
# TODO Remove this failsafe once proper error handling is in place.
if type == "percent" or data is None:
# Return an empty list here to reduce the o... | [
"def",
"collect_history",
"(",
"self",
")",
":",
"def",
"format_data",
"(",
"data",
")",
":",
"\"\"\"Format result data according to the user-defined type.\"\"\"",
"# TODO Remove this failsafe once proper error handling is in place.",
"if",
"type",
"==",
"\"percent\"",
"or",
"d... | Build the structure of results in terms of a commit history. | [
"Build",
"the",
"structure",
"of",
"results",
"in",
"terms",
"of",
"a",
"commit",
"history",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/reporting/history.py#L61-L126 |
2,460 | opencobra/memote | memote/suite/reporting/diff.py | DiffReport.format_and_score_diff_data | def format_and_score_diff_data(self, diff_results):
"""Reformat the api results to work with the front-end."""
base = dict()
meta = base.setdefault('meta', dict())
tests = base.setdefault('tests', dict())
score = base.setdefault('score', dict())
for model_filename, result... | python | def format_and_score_diff_data(self, diff_results):
base = dict()
meta = base.setdefault('meta', dict())
tests = base.setdefault('tests', dict())
score = base.setdefault('score', dict())
for model_filename, result in iteritems(diff_results):
if meta == dict():
... | [
"def",
"format_and_score_diff_data",
"(",
"self",
",",
"diff_results",
")",
":",
"base",
"=",
"dict",
"(",
")",
"meta",
"=",
"base",
".",
"setdefault",
"(",
"'meta'",
",",
"dict",
"(",
")",
")",
"tests",
"=",
"base",
".",
"setdefault",
"(",
"'tests'",
... | Reformat the api results to work with the front-end. | [
"Reformat",
"the",
"api",
"results",
"to",
"work",
"with",
"the",
"front",
"-",
"end",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/reporting/diff.py#L48-L97 |
2,461 | opencobra/memote | scripts/annotate_mnx_shortlists.py | generate_shortlist | def generate_shortlist(mnx_db, shortlist):
"""
Create a condensed cross-references format from data in long form.
Both data frames must contain a column 'MNX_ID' and the dump is assumed
to also have a column 'XREF'.
Parameters
----------
mnx_db : pandas.DataFrame
The entire MetaNet... | python | def generate_shortlist(mnx_db, shortlist):
# Reduce the whole database to targets of interest.
xref = mnx_db.loc[mnx_db["MNX_ID"].isin(shortlist["MNX_ID"]), :]
# Drop deprecated MetaNetX identifiers. Disabled for now.
# xref = xref.loc[~xref["XREF"].str.startswith("deprecated", na=False), :]
# Drop ... | [
"def",
"generate_shortlist",
"(",
"mnx_db",
",",
"shortlist",
")",
":",
"# Reduce the whole database to targets of interest.",
"xref",
"=",
"mnx_db",
".",
"loc",
"[",
"mnx_db",
"[",
"\"MNX_ID\"",
"]",
".",
"isin",
"(",
"shortlist",
"[",
"\"MNX_ID\"",
"]",
")",
"... | Create a condensed cross-references format from data in long form.
Both data frames must contain a column 'MNX_ID' and the dump is assumed
to also have a column 'XREF'.
Parameters
----------
mnx_db : pandas.DataFrame
The entire MetaNetX dump as a data frame.
shortlist : pandas.DataFram... | [
"Create",
"a",
"condensed",
"cross",
"-",
"references",
"format",
"from",
"data",
"in",
"long",
"form",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/scripts/annotate_mnx_shortlists.py#L50-L96 |
2,462 | opencobra/memote | scripts/annotate_mnx_shortlists.py | generate | def generate(mnx_dump):
"""
Annotate a shortlist of metabolites with cross-references using MetaNetX.
MNX_DUMP : The chemicals dump from MetaNetX usually called 'chem_xref.tsv'.
Will be downloaded if it doesn't exist.
"""
LOGGER.info("Read shortlist.")
targets = pd.read_table(join(dirn... | python | def generate(mnx_dump):
LOGGER.info("Read shortlist.")
targets = pd.read_table(join(dirname(__file__), "shortlist.tsv"))
if not exists(mnx_dump):
# Download the MetaNetX chemicals dump if it doesn't exists.
# Download done as per https://stackoverflow.com/a/16696317.
LOGGER.info("Met... | [
"def",
"generate",
"(",
"mnx_dump",
")",
":",
"LOGGER",
".",
"info",
"(",
"\"Read shortlist.\"",
")",
"targets",
"=",
"pd",
".",
"read_table",
"(",
"join",
"(",
"dirname",
"(",
"__file__",
")",
",",
"\"shortlist.tsv\"",
")",
")",
"if",
"not",
"exists",
"... | Annotate a shortlist of metabolites with cross-references using MetaNetX.
MNX_DUMP : The chemicals dump from MetaNetX usually called 'chem_xref.tsv'.
Will be downloaded if it doesn't exist. | [
"Annotate",
"a",
"shortlist",
"of",
"metabolites",
"with",
"cross",
"-",
"references",
"using",
"MetaNetX",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/scripts/annotate_mnx_shortlists.py#L105-L133 |
2,463 | opencobra/memote | memote/experimental/essentiality.py | EssentialityExperiment.evaluate | def evaluate(self, model):
"""Use the defined parameters to predict single gene essentiality."""
with model:
if self.medium is not None:
self.medium.apply(model)
if self.objective is not None:
model.objective = self.objective
model.add_... | python | def evaluate(self, model):
with model:
if self.medium is not None:
self.medium.apply(model)
if self.objective is not None:
model.objective = self.objective
model.add_cons_vars(self.constraints)
max_val = model.slim_optimize()
... | [
"def",
"evaluate",
"(",
"self",
",",
"model",
")",
":",
"with",
"model",
":",
"if",
"self",
".",
"medium",
"is",
"not",
"None",
":",
"self",
".",
"medium",
".",
"apply",
"(",
"model",
")",
"if",
"self",
".",
"objective",
"is",
"not",
"None",
":",
... | Use the defined parameters to predict single gene essentiality. | [
"Use",
"the",
"defined",
"parameters",
"to",
"predict",
"single",
"gene",
"essentiality",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/essentiality.py#L78-L93 |
2,464 | opencobra/memote | memote/utils.py | register_with | def register_with(registry):
"""
Register a passed in object.
Intended to be used as a decorator on model building functions with a
``dict`` as a registry.
Examples
--------
.. code-block:: python
REGISTRY = dict()
@register_with(REGISTRY)
def build_empty(base):
... | python | def register_with(registry):
def decorator(func):
registry[func.__name__] = func
return func
return decorator | [
"def",
"register_with",
"(",
"registry",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"registry",
"[",
"func",
".",
"__name__",
"]",
"=",
"func",
"return",
"func",
"return",
"decorator"
] | Register a passed in object.
Intended to be used as a decorator on model building functions with a
``dict`` as a registry.
Examples
--------
.. code-block:: python
REGISTRY = dict()
@register_with(REGISTRY)
def build_empty(base):
return base | [
"Register",
"a",
"passed",
"in",
"object",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/utils.py#L48-L68 |
2,465 | opencobra/memote | memote/utils.py | annotate | def annotate(title, format_type, message=None, data=None, metric=1.0):
"""
Annotate a test case with info that should be displayed in the reports.
Parameters
----------
title : str
A human-readable descriptive title of the test case.
format_type : str
A string that determines ho... | python | def annotate(title, format_type, message=None, data=None, metric=1.0):
if format_type not in TYPES:
raise ValueError(
"Invalid type. Expected one of: {}.".format(", ".join(TYPES)))
def decorator(func):
func.annotation = dict(
title=title,
summary=extended_sum... | [
"def",
"annotate",
"(",
"title",
",",
"format_type",
",",
"message",
"=",
"None",
",",
"data",
"=",
"None",
",",
"metric",
"=",
"1.0",
")",
":",
"if",
"format_type",
"not",
"in",
"TYPES",
":",
"raise",
"ValueError",
"(",
"\"Invalid type. Expected one of: {}.... | Annotate a test case with info that should be displayed in the reports.
Parameters
----------
title : str
A human-readable descriptive title of the test case.
format_type : str
A string that determines how the result data is formatted in the
report. It is expected not to be None... | [
"Annotate",
"a",
"test",
"case",
"with",
"info",
"that",
"should",
"be",
"displayed",
"in",
"the",
"reports",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/utils.py#L71-L130 |
2,466 | opencobra/memote | memote/utils.py | truncate | def truncate(sequence):
"""
Create a potentially shortened text display of a list.
Parameters
----------
sequence : list
An indexable sequence of elements.
Returns
-------
str
The list as a formatted string.
"""
if len(sequence) > LIST_SLICE:
return ", ... | python | def truncate(sequence):
if len(sequence) > LIST_SLICE:
return ", ".join(sequence[:LIST_SLICE] + ["..."])
else:
return ", ".join(sequence) | [
"def",
"truncate",
"(",
"sequence",
")",
":",
"if",
"len",
"(",
"sequence",
")",
">",
"LIST_SLICE",
":",
"return",
"\", \"",
".",
"join",
"(",
"sequence",
"[",
":",
"LIST_SLICE",
"]",
"+",
"[",
"\"...\"",
"]",
")",
"else",
":",
"return",
"\", \"",
".... | Create a potentially shortened text display of a list.
Parameters
----------
sequence : list
An indexable sequence of elements.
Returns
-------
str
The list as a formatted string. | [
"Create",
"a",
"potentially",
"shortened",
"text",
"display",
"of",
"a",
"list",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/utils.py#L152-L170 |
2,467 | opencobra/memote | memote/utils.py | log_json_incompatible_types | def log_json_incompatible_types(obj):
"""
Log types that are not JSON compatible.
Explore a nested dictionary structure and log types that are not JSON
compatible.
Parameters
----------
obj : dict
A potentially nested dictionary.
"""
keys_to_explore = list(obj)
while l... | python | def log_json_incompatible_types(obj):
keys_to_explore = list(obj)
while len(keys_to_explore) > 0:
key = keys_to_explore.pop()
if not isinstance(key, str):
LOGGER.info(type(key))
value = obj[key]
if isinstance(value, dict):
LOGGER.info("%s:", key)
... | [
"def",
"log_json_incompatible_types",
"(",
"obj",
")",
":",
"keys_to_explore",
"=",
"list",
"(",
"obj",
")",
"while",
"len",
"(",
"keys_to_explore",
")",
">",
"0",
":",
"key",
"=",
"keys_to_explore",
".",
"pop",
"(",
")",
"if",
"not",
"isinstance",
"(",
... | Log types that are not JSON compatible.
Explore a nested dictionary structure and log types that are not JSON
compatible.
Parameters
----------
obj : dict
A potentially nested dictionary. | [
"Log",
"types",
"that",
"are",
"not",
"JSON",
"compatible",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/utils.py#L173-L198 |
2,468 | opencobra/memote | memote/utils.py | flatten | def flatten(list_of_lists):
"""Flatten a list of lists but maintain strings and ints as entries."""
flat_list = []
for sublist in list_of_lists:
if isinstance(sublist, string_types) or isinstance(sublist, int):
flat_list.append(sublist)
elif sublist is None:
continue
... | python | def flatten(list_of_lists):
flat_list = []
for sublist in list_of_lists:
if isinstance(sublist, string_types) or isinstance(sublist, int):
flat_list.append(sublist)
elif sublist is None:
continue
elif not isinstance(sublist, string_types) and len(sublist) == 1:
... | [
"def",
"flatten",
"(",
"list_of_lists",
")",
":",
"flat_list",
"=",
"[",
"]",
"for",
"sublist",
"in",
"list_of_lists",
":",
"if",
"isinstance",
"(",
"sublist",
",",
"string_types",
")",
"or",
"isinstance",
"(",
"sublist",
",",
"int",
")",
":",
"flat_list",... | Flatten a list of lists but maintain strings and ints as entries. | [
"Flatten",
"a",
"list",
"of",
"lists",
"but",
"maintain",
"strings",
"and",
"ints",
"as",
"entries",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/utils.py#L254-L266 |
2,469 | opencobra/memote | memote/utils.py | stdout_notifications | def stdout_notifications(notifications):
"""
Print each entry of errors and warnings to stdout.
Parameters
----------
notifications: dict
A simple dictionary structure containing a list of errors and warnings.
"""
for error in notifications["errors"]:
LOGGER.error(error)
... | python | def stdout_notifications(notifications):
for error in notifications["errors"]:
LOGGER.error(error)
for warn in notifications["warnings"]:
LOGGER.warning(warn) | [
"def",
"stdout_notifications",
"(",
"notifications",
")",
":",
"for",
"error",
"in",
"notifications",
"[",
"\"errors\"",
"]",
":",
"LOGGER",
".",
"error",
"(",
"error",
")",
"for",
"warn",
"in",
"notifications",
"[",
"\"warnings\"",
"]",
":",
"LOGGER",
".",
... | Print each entry of errors and warnings to stdout.
Parameters
----------
notifications: dict
A simple dictionary structure containing a list of errors and warnings. | [
"Print",
"each",
"entry",
"of",
"errors",
"and",
"warnings",
"to",
"stdout",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/utils.py#L289-L302 |
2,470 | opencobra/memote | memote/experimental/experimental_base.py | ExperimentalBase.validate | def validate(self, model, checks=[]):
"""Use a defined schema to validate the given table."""
records = self.data.to_dict("records")
self.evaluate_report(
validate(records, headers=list(records[0]),
preset='table', schema=self.schema,
order_f... | python | def validate(self, model, checks=[]):
records = self.data.to_dict("records")
self.evaluate_report(
validate(records, headers=list(records[0]),
preset='table', schema=self.schema,
order_fields=True, custom_checks=checks)) | [
"def",
"validate",
"(",
"self",
",",
"model",
",",
"checks",
"=",
"[",
"]",
")",
":",
"records",
"=",
"self",
".",
"data",
".",
"to_dict",
"(",
"\"records\"",
")",
"self",
".",
"evaluate_report",
"(",
"validate",
"(",
"records",
",",
"headers",
"=",
... | Use a defined schema to validate the given table. | [
"Use",
"a",
"defined",
"schema",
"to",
"validate",
"the",
"given",
"table",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/experimental_base.py#L90-L96 |
2,471 | opencobra/memote | memote/experimental/experimental_base.py | ExperimentalBase.evaluate_report | def evaluate_report(report):
"""Iterate over validation errors."""
if report["valid"]:
return
for warn in report["warnings"]:
LOGGER.warning(warn)
# We only ever test one table at a time.
for err in report["tables"][0]["errors"]:
LOGGER.error(e... | python | def evaluate_report(report):
if report["valid"]:
return
for warn in report["warnings"]:
LOGGER.warning(warn)
# We only ever test one table at a time.
for err in report["tables"][0]["errors"]:
LOGGER.error(err["message"])
raise ValueError("Inval... | [
"def",
"evaluate_report",
"(",
"report",
")",
":",
"if",
"report",
"[",
"\"valid\"",
"]",
":",
"return",
"for",
"warn",
"in",
"report",
"[",
"\"warnings\"",
"]",
":",
"LOGGER",
".",
"warning",
"(",
"warn",
")",
"# We only ever test one table at a time.",
"for"... | Iterate over validation errors. | [
"Iterate",
"over",
"validation",
"errors",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/experimental_base.py#L99-L108 |
2,472 | opencobra/memote | memote/support/consistency_helpers.py | add_reaction_constraints | def add_reaction_constraints(model, reactions, Constraint):
"""
Add the stoichiometric coefficients as constraints.
Parameters
----------
model : optlang.Model
The transposed stoichiometric matrix representation.
reactions : iterable
Container of `cobra.Reaction` instances.
... | python | def add_reaction_constraints(model, reactions, Constraint):
constraints = []
for rxn in reactions:
expression = add(
[c * model.variables[m.id] for m, c in rxn.metabolites.items()])
constraints.append(Constraint(expression, lb=0, ub=0, name=rxn.id))
model.add(constraints) | [
"def",
"add_reaction_constraints",
"(",
"model",
",",
"reactions",
",",
"Constraint",
")",
":",
"constraints",
"=",
"[",
"]",
"for",
"rxn",
"in",
"reactions",
":",
"expression",
"=",
"add",
"(",
"[",
"c",
"*",
"model",
".",
"variables",
"[",
"m",
".",
... | Add the stoichiometric coefficients as constraints.
Parameters
----------
model : optlang.Model
The transposed stoichiometric matrix representation.
reactions : iterable
Container of `cobra.Reaction` instances.
Constraint : optlang.Constraint
The constraint class for the spe... | [
"Add",
"the",
"stoichiometric",
"coefficients",
"as",
"constraints",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L43-L62 |
2,473 | opencobra/memote | memote/support/consistency_helpers.py | stoichiometry_matrix | def stoichiometry_matrix(metabolites, reactions):
"""
Return the stoichiometry matrix representation of a set of reactions.
The reactions and metabolites order is respected. All metabolites are
expected to be contained and complete in terms of the reactions.
Parameters
----------
reactions... | python | def stoichiometry_matrix(metabolites, reactions):
matrix = np.zeros((len(metabolites), len(reactions)))
met_index = dict((met, i) for i, met in enumerate(metabolites))
rxn_index = dict()
for i, rxn in enumerate(reactions):
rxn_index[rxn] = i
for met, coef in iteritems(rxn.metabolites):
... | [
"def",
"stoichiometry_matrix",
"(",
"metabolites",
",",
"reactions",
")",
":",
"matrix",
"=",
"np",
".",
"zeros",
"(",
"(",
"len",
"(",
"metabolites",
")",
",",
"len",
"(",
"reactions",
")",
")",
")",
"met_index",
"=",
"dict",
"(",
"(",
"met",
",",
"... | Return the stoichiometry matrix representation of a set of reactions.
The reactions and metabolites order is respected. All metabolites are
expected to be contained and complete in terms of the reactions.
Parameters
----------
reactions : iterable
A somehow ordered list of unique reactions... | [
"Return",
"the",
"stoichiometry",
"matrix",
"representation",
"of",
"a",
"set",
"of",
"reactions",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L65-L97 |
2,474 | opencobra/memote | memote/support/consistency_helpers.py | rank | def rank(matrix, atol=1e-13, rtol=0):
"""
Estimate the rank, i.e., the dimension of the column space, of a matrix.
The algorithm used by this function is based on the singular value
decomposition of `stoichiometry_matrix`.
Parameters
----------
matrix : ndarray
The matrix should be... | python | def rank(matrix, atol=1e-13, rtol=0):
matrix = np.atleast_2d(matrix)
sigma = svd(matrix, compute_uv=False)
tol = max(atol, rtol * sigma[0])
return int((sigma >= tol).sum()) | [
"def",
"rank",
"(",
"matrix",
",",
"atol",
"=",
"1e-13",
",",
"rtol",
"=",
"0",
")",
":",
"matrix",
"=",
"np",
".",
"atleast_2d",
"(",
"matrix",
")",
"sigma",
"=",
"svd",
"(",
"matrix",
",",
"compute_uv",
"=",
"False",
")",
"tol",
"=",
"max",
"("... | Estimate the rank, i.e., the dimension of the column space, of a matrix.
The algorithm used by this function is based on the singular value
decomposition of `stoichiometry_matrix`.
Parameters
----------
matrix : ndarray
The matrix should be at most 2-D. A 1-D array with length k
w... | [
"Estimate",
"the",
"rank",
"i",
".",
"e",
".",
"the",
"dimension",
"of",
"the",
"column",
"space",
"of",
"a",
"matrix",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L100-L144 |
2,475 | opencobra/memote | memote/support/consistency_helpers.py | get_interface | def get_interface(model):
"""
Return the interface specific classes.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
"""
return (
model.solver.interface.Model,
model.solver.interface.Constraint,
model.solver.interface.Varia... | python | def get_interface(model):
return (
model.solver.interface.Model,
model.solver.interface.Constraint,
model.solver.interface.Variable,
model.solver.interface.Objective
) | [
"def",
"get_interface",
"(",
"model",
")",
":",
"return",
"(",
"model",
".",
"solver",
".",
"interface",
".",
"Model",
",",
"model",
".",
"solver",
".",
"interface",
".",
"Constraint",
",",
"model",
".",
"solver",
".",
"interface",
".",
"Variable",
",",
... | Return the interface specific classes.
Parameters
----------
model : cobra.Model
The metabolic model under investigation. | [
"Return",
"the",
"interface",
"specific",
"classes",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L197-L212 |
2,476 | opencobra/memote | memote/support/consistency_helpers.py | get_internals | def get_internals(model):
"""
Return non-boundary reactions and their metabolites.
Boundary reactions are unbalanced by their nature. They are excluded here
and only the metabolites of the others are considered.
Parameters
----------
model : cobra.Model
The metabolic model under in... | python | def get_internals(model):
biomass = set(find_biomass_reaction(model))
if len(biomass) == 0:
LOGGER.warning("No biomass reaction detected. Consistency test results "
"are unreliable if one exists.")
return set(model.reactions) - (set(model.boundary) | biomass) | [
"def",
"get_internals",
"(",
"model",
")",
":",
"biomass",
"=",
"set",
"(",
"find_biomass_reaction",
"(",
"model",
")",
")",
"if",
"len",
"(",
"biomass",
")",
"==",
"0",
":",
"LOGGER",
".",
"warning",
"(",
"\"No biomass reaction detected. Consistency test result... | Return non-boundary reactions and their metabolites.
Boundary reactions are unbalanced by their nature. They are excluded here
and only the metabolites of the others are considered.
Parameters
----------
model : cobra.Model
The metabolic model under investigation. | [
"Return",
"non",
"-",
"boundary",
"reactions",
"and",
"their",
"metabolites",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L216-L233 |
2,477 | opencobra/memote | memote/support/consistency_helpers.py | add_cut | def add_cut(problem, indicators, bound, Constraint):
"""
Add an integer cut to the problem.
Ensure that the same solution involving these indicator variables cannot be
found by enforcing their sum to be less than before.
Parameters
----------
problem : optlang.Model
Specific optlan... | python | def add_cut(problem, indicators, bound, Constraint):
cut = Constraint(sympy.Add(*indicators), ub=bound)
problem.add(cut)
return cut | [
"def",
"add_cut",
"(",
"problem",
",",
"indicators",
",",
"bound",
",",
"Constraint",
")",
":",
"cut",
"=",
"Constraint",
"(",
"sympy",
".",
"Add",
"(",
"*",
"indicators",
")",
",",
"ub",
"=",
"bound",
")",
"problem",
".",
"add",
"(",
"cut",
")",
"... | Add an integer cut to the problem.
Ensure that the same solution involving these indicator variables cannot be
found by enforcing their sum to be less than before.
Parameters
----------
problem : optlang.Model
Specific optlang interface Model instance.
indicators : iterable
Bin... | [
"Add",
"an",
"integer",
"cut",
"to",
"the",
"problem",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L298-L327 |
2,478 | opencobra/memote | memote/support/consistency_helpers.py | is_mass_balanced | def is_mass_balanced(reaction):
"""Confirm that a reaction is mass balanced."""
balance = defaultdict(int)
for metabolite, coefficient in iteritems(reaction.metabolites):
if metabolite.elements is None or len(metabolite.elements) == 0:
return False
for element, amount in iteritem... | python | def is_mass_balanced(reaction):
balance = defaultdict(int)
for metabolite, coefficient in iteritems(reaction.metabolites):
if metabolite.elements is None or len(metabolite.elements) == 0:
return False
for element, amount in iteritems(metabolite.elements):
balance[element]... | [
"def",
"is_mass_balanced",
"(",
"reaction",
")",
":",
"balance",
"=",
"defaultdict",
"(",
"int",
")",
"for",
"metabolite",
",",
"coefficient",
"in",
"iteritems",
"(",
"reaction",
".",
"metabolites",
")",
":",
"if",
"metabolite",
".",
"elements",
"is",
"None"... | Confirm that a reaction is mass balanced. | [
"Confirm",
"that",
"a",
"reaction",
"is",
"mass",
"balanced",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L330-L338 |
2,479 | opencobra/memote | memote/support/consistency_helpers.py | is_charge_balanced | def is_charge_balanced(reaction):
"""Confirm that a reaction is charge balanced."""
charge = 0
for metabolite, coefficient in iteritems(reaction.metabolites):
if metabolite.charge is None:
return False
charge += coefficient * metabolite.charge
return charge == 0 | python | def is_charge_balanced(reaction):
charge = 0
for metabolite, coefficient in iteritems(reaction.metabolites):
if metabolite.charge is None:
return False
charge += coefficient * metabolite.charge
return charge == 0 | [
"def",
"is_charge_balanced",
"(",
"reaction",
")",
":",
"charge",
"=",
"0",
"for",
"metabolite",
",",
"coefficient",
"in",
"iteritems",
"(",
"reaction",
".",
"metabolites",
")",
":",
"if",
"metabolite",
".",
"charge",
"is",
"None",
":",
"return",
"False",
... | Confirm that a reaction is charge balanced. | [
"Confirm",
"that",
"a",
"reaction",
"is",
"charge",
"balanced",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/consistency_helpers.py#L341-L348 |
2,480 | opencobra/memote | memote/experimental/checks.py | check_partial | def check_partial(func, *args, **kwargs):
"""Create a partial to be used by goodtables."""
new_func = partial(func, *args, **kwargs)
new_func.check = func.check
return new_func | python | def check_partial(func, *args, **kwargs):
new_func = partial(func, *args, **kwargs)
new_func.check = func.check
return new_func | [
"def",
"check_partial",
"(",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"new_func",
"=",
"partial",
"(",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"new_func",
".",
"check",
"=",
"func",
".",
"check",
"return",
"new_f... | Create a partial to be used by goodtables. | [
"Create",
"a",
"partial",
"to",
"be",
"used",
"by",
"goodtables",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/checks.py#L27-L31 |
2,481 | opencobra/memote | memote/experimental/checks.py | gene_id_check | def gene_id_check(genes, errors, columns, row_number):
"""
Validate gene identifiers against a known set.
Parameters
----------
genes : set
The known set of gene identifiers.
errors :
Passed by goodtables.
columns :
Passed by goodtables.
row_number :
Pass... | python | def gene_id_check(genes, errors, columns, row_number):
message = ("Gene '{value}' in column {col} and row {row} does not "
"appear in the metabolic model.")
for column in columns:
if "gene" in column['header'] and column['value'] not in genes:
message = message.format(
... | [
"def",
"gene_id_check",
"(",
"genes",
",",
"errors",
",",
"columns",
",",
"row_number",
")",
":",
"message",
"=",
"(",
"\"Gene '{value}' in column {col} and row {row} does not \"",
"\"appear in the metabolic model.\"",
")",
"for",
"column",
"in",
"columns",
":",
"if",
... | Validate gene identifiers against a known set.
Parameters
----------
genes : set
The known set of gene identifiers.
errors :
Passed by goodtables.
columns :
Passed by goodtables.
row_number :
Passed by goodtables. | [
"Validate",
"gene",
"identifiers",
"against",
"a",
"known",
"set",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/checks.py#L35-L64 |
2,482 | opencobra/memote | memote/experimental/checks.py | reaction_id_check | def reaction_id_check(reactions, errors, columns, row_number):
"""
Validate reactions identifiers against a known set.
Parameters
----------
reactions : set
The known set of reaction identifiers.
errors :
Passed by goodtables.
columns :
Passed by goodtables.
row_... | python | def reaction_id_check(reactions, errors, columns, row_number):
message = ("Reaction '{value}' in column {col} and row {row} does not "
"appear in the metabolic model.")
for column in columns:
if "reaction" in column['header'] and column['value'] not in reactions:
message = mes... | [
"def",
"reaction_id_check",
"(",
"reactions",
",",
"errors",
",",
"columns",
",",
"row_number",
")",
":",
"message",
"=",
"(",
"\"Reaction '{value}' in column {col} and row {row} does not \"",
"\"appear in the metabolic model.\"",
")",
"for",
"column",
"in",
"columns",
":... | Validate reactions identifiers against a known set.
Parameters
----------
reactions : set
The known set of reaction identifiers.
errors :
Passed by goodtables.
columns :
Passed by goodtables.
row_number :
Passed by goodtables. | [
"Validate",
"reactions",
"identifiers",
"against",
"a",
"known",
"set",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/checks.py#L68-L97 |
2,483 | opencobra/memote | memote/experimental/checks.py | metabolite_id_check | def metabolite_id_check(metabolites, errors, columns, row_number):
"""
Validate metabolite identifiers against a known set.
Parameters
----------
metabolites : set
The known set of metabolite identifiers.
errors :
Passed by goodtables.
columns :
Passed by goodtables.... | python | def metabolite_id_check(metabolites, errors, columns, row_number):
message = ("Metabolite '{value}' in column {col} and row {row} does not "
"appear in the metabolic model.")
for column in columns:
if "metabolite" in column['header'] and \
column['value'] not in metabolite... | [
"def",
"metabolite_id_check",
"(",
"metabolites",
",",
"errors",
",",
"columns",
",",
"row_number",
")",
":",
"message",
"=",
"(",
"\"Metabolite '{value}' in column {col} and row {row} does not \"",
"\"appear in the metabolic model.\"",
")",
"for",
"column",
"in",
"columns"... | Validate metabolite identifiers against a known set.
Parameters
----------
metabolites : set
The known set of metabolite identifiers.
errors :
Passed by goodtables.
columns :
Passed by goodtables.
row_number :
Passed by goodtables. | [
"Validate",
"metabolite",
"identifiers",
"against",
"a",
"known",
"set",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/experimental/checks.py#L101-L131 |
2,484 | opencobra/memote | memote/suite/cli/runner.py | run | def run(model, collect, filename, location, ignore_git, pytest_args, exclusive,
skip, solver, experimental, custom_tests, deployment,
skip_unchanged):
"""
Run the test suite on a single model and collect results.
MODEL: Path to model file. Can also be supplied via the environment variable
... | python | def run(model, collect, filename, location, ignore_git, pytest_args, exclusive,
skip, solver, experimental, custom_tests, deployment,
skip_unchanged):
def is_verbose(arg):
return (arg.startswith("--verbosity") or
arg.startswith("-v") or arg.startswith("--verbose") or
... | [
"def",
"run",
"(",
"model",
",",
"collect",
",",
"filename",
",",
"location",
",",
"ignore_git",
",",
"pytest_args",
",",
"exclusive",
",",
"skip",
",",
"solver",
",",
"experimental",
",",
"custom_tests",
",",
"deployment",
",",
"skip_unchanged",
")",
":",
... | Run the test suite on a single model and collect results.
MODEL: Path to model file. Can also be supplied via the environment variable
MEMOTE_MODEL or configured in 'setup.cfg' or 'memote.ini'. | [
"Run",
"the",
"test",
"suite",
"on",
"a",
"single",
"model",
"and",
"collect",
"results",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/runner.py#L133-L222 |
2,485 | opencobra/memote | memote/suite/cli/runner.py | new | def new(directory, replay):
"""
Create a suitable model repository structure from a template.
By using a cookiecutter template, memote will ask you a couple of questions
and set up a new directory structure that will make your life easier. The
new directory will be placed in the current directory o... | python | def new(directory, replay):
callbacks.git_installed()
if directory is None:
directory = os.getcwd()
cookiecutter("gh:opencobra/cookiecutter-memote", output_dir=directory,
replay=replay) | [
"def",
"new",
"(",
"directory",
",",
"replay",
")",
":",
"callbacks",
".",
"git_installed",
"(",
")",
"if",
"directory",
"is",
"None",
":",
"directory",
"=",
"os",
".",
"getcwd",
"(",
")",
"cookiecutter",
"(",
"\"gh:opencobra/cookiecutter-memote\"",
",",
"ou... | Create a suitable model repository structure from a template.
By using a cookiecutter template, memote will ask you a couple of questions
and set up a new directory structure that will make your life easier. The
new directory will be placed in the current directory or respect the given
--directory opti... | [
"Create",
"a",
"suitable",
"model",
"repository",
"structure",
"from",
"a",
"template",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/runner.py#L236-L250 |
2,486 | opencobra/memote | memote/suite/cli/runner.py | online | def online(note, github_repository, github_username):
"""Upload the repository to GitHub and enable testing on Travis CI."""
callbacks.git_installed()
try:
repo = git.Repo()
except git.InvalidGitRepositoryError:
LOGGER.critical(
"'memote online' requires a git repository in o... | python | def online(note, github_repository, github_username):
callbacks.git_installed()
try:
repo = git.Repo()
except git.InvalidGitRepositoryError:
LOGGER.critical(
"'memote online' requires a git repository in order to follow "
"the current branch's commit history.")
... | [
"def",
"online",
"(",
"note",
",",
"github_repository",
",",
"github_username",
")",
":",
"callbacks",
".",
"git_installed",
"(",
")",
"try",
":",
"repo",
"=",
"git",
".",
"Repo",
"(",
")",
"except",
"git",
".",
"InvalidGitRepositoryError",
":",
"LOGGER",
... | Upload the repository to GitHub and enable testing on Travis CI. | [
"Upload",
"the",
"repository",
"to",
"GitHub",
"and",
"enable",
"testing",
"on",
"Travis",
"CI",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/runner.py#L737-L780 |
2,487 | opencobra/memote | scripts/update_mock_repo.py | update_mock_repo | def update_mock_repo():
"""
Clone and gzip the memote-mock-repo used for CLI and integration tests.
The repo is hosted at
'https://github.com/ChristianLieven/memote-mock-repo.git' and maintained
separately from
"""
target_file = os.path.abspath(
join("tests", "data", "memote-mock-r... | python | def update_mock_repo():
target_file = os.path.abspath(
join("tests", "data", "memote-mock-repo.tar.gz")
)
temp_dir = mkdtemp(prefix='tmp_mock')
previous_wd = os.getcwd()
try:
LOGGER.info("Cloning repository.")
os.chdir(temp_dir)
check_output(
['git', 'clon... | [
"def",
"update_mock_repo",
"(",
")",
":",
"target_file",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"join",
"(",
"\"tests\"",
",",
"\"data\"",
",",
"\"memote-mock-repo.tar.gz\"",
")",
")",
"temp_dir",
"=",
"mkdtemp",
"(",
"prefix",
"=",
"'tmp_mock'",
")",
... | Clone and gzip the memote-mock-repo used for CLI and integration tests.
The repo is hosted at
'https://github.com/ChristianLieven/memote-mock-repo.git' and maintained
separately from | [
"Clone",
"and",
"gzip",
"the",
"memote",
"-",
"mock",
"-",
"repo",
"used",
"for",
"CLI",
"and",
"integration",
"tests",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/scripts/update_mock_repo.py#L39-L86 |
2,488 | opencobra/memote | memote/support/biomass.py | sum_biomass_weight | def sum_biomass_weight(reaction):
"""
Compute the sum of all reaction compounds.
This function expects all metabolites of the biomass reaction to have
formula information assigned.
Parameters
----------
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under... | python | def sum_biomass_weight(reaction):
return sum(-coef * met.formula_weight
for (met, coef) in iteritems(reaction.metabolites)) / 1000.0 | [
"def",
"sum_biomass_weight",
"(",
"reaction",
")",
":",
"return",
"sum",
"(",
"-",
"coef",
"*",
"met",
".",
"formula_weight",
"for",
"(",
"met",
",",
"coef",
")",
"in",
"iteritems",
"(",
"reaction",
".",
"metabolites",
")",
")",
"/",
"1000.0"
] | Compute the sum of all reaction compounds.
This function expects all metabolites of the biomass reaction to have
formula information assigned.
Parameters
----------
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under investigation.
Returns
-------
f... | [
"Compute",
"the",
"sum",
"of",
"all",
"reaction",
"compounds",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L69-L88 |
2,489 | opencobra/memote | memote/support/biomass.py | find_biomass_precursors | def find_biomass_precursors(model, reaction):
"""
Return a list of all biomass precursors excluding ATP and H2O.
Parameters
----------
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under investigation.
model : cobra.Model
The metabolic model under inv... | python | def find_biomass_precursors(model, reaction):
id_of_main_compartment = helpers.find_compartment_id_in_model(model, 'c')
gam_reactants = set()
try:
gam_reactants.update([
helpers.find_met_in_model(
model, "MNXM3", id_of_main_compartment)[0]])
except RuntimeError:
... | [
"def",
"find_biomass_precursors",
"(",
"model",
",",
"reaction",
")",
":",
"id_of_main_compartment",
"=",
"helpers",
".",
"find_compartment_id_in_model",
"(",
"model",
",",
"'c'",
")",
"gam_reactants",
"=",
"set",
"(",
")",
"try",
":",
"gam_reactants",
".",
"upd... | Return a list of all biomass precursors excluding ATP and H2O.
Parameters
----------
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under investigation.
model : cobra.Model
The metabolic model under investigation.
Returns
-------
list
Meta... | [
"Return",
"a",
"list",
"of",
"all",
"biomass",
"precursors",
"excluding",
"ATP",
"and",
"H2O",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L91-L126 |
2,490 | opencobra/memote | memote/support/biomass.py | find_blocked_biomass_precursors | def find_blocked_biomass_precursors(reaction, model):
"""
Return a list of all biomass precursors that cannot be produced.
Parameters
----------
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under investigation.
model : cobra.Model
The metabolic model... | python | def find_blocked_biomass_precursors(reaction, model):
LOGGER.debug("Finding blocked biomass precursors")
precursors = find_biomass_precursors(model, reaction)
blocked_precursors = list()
_, ub = helpers.find_bounds(model)
for precursor in precursors:
with model:
dm_rxn = model.ad... | [
"def",
"find_blocked_biomass_precursors",
"(",
"reaction",
",",
"model",
")",
":",
"LOGGER",
".",
"debug",
"(",
"\"Finding blocked biomass precursors\"",
")",
"precursors",
"=",
"find_biomass_precursors",
"(",
"model",
",",
"reaction",
")",
"blocked_precursors",
"=",
... | Return a list of all biomass precursors that cannot be produced.
Parameters
----------
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under investigation.
model : cobra.Model
The metabolic model under investigation.
Returns
-------
list
Me... | [
"Return",
"a",
"list",
"of",
"all",
"biomass",
"precursors",
"that",
"cannot",
"be",
"produced",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L129-L163 |
2,491 | opencobra/memote | memote/support/biomass.py | gam_in_biomass | def gam_in_biomass(model, reaction):
"""
Return boolean if biomass reaction includes growth-associated maintenance.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under ... | python | def gam_in_biomass(model, reaction):
id_of_main_compartment = helpers.find_compartment_id_in_model(model, 'c')
try:
left = {
helpers.find_met_in_model(
model, "MNXM3", id_of_main_compartment)[0],
helpers.find_met_in_model(
model, "MNXM2", id_of_ma... | [
"def",
"gam_in_biomass",
"(",
"model",
",",
"reaction",
")",
":",
"id_of_main_compartment",
"=",
"helpers",
".",
"find_compartment_id_in_model",
"(",
"model",
",",
"'c'",
")",
"try",
":",
"left",
"=",
"{",
"helpers",
".",
"find_met_in_model",
"(",
"model",
","... | Return boolean if biomass reaction includes growth-associated maintenance.
Parameters
----------
model : cobra.Model
The metabolic model under investigation.
reaction : cobra.core.reaction.Reaction
The biomass reaction of the model under investigation.
Returns
-------
boole... | [
"Return",
"boolean",
"if",
"biomass",
"reaction",
"includes",
"growth",
"-",
"associated",
"maintenance",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L166-L206 |
2,492 | opencobra/memote | memote/support/biomass.py | find_direct_metabolites | def find_direct_metabolites(model, reaction, tolerance=1E-06):
"""
Return list of possible direct biomass precursor metabolites.
The term direct metabolites describes metabolites that are involved only
in either transport and/or boundary reactions, AND the biomass reaction(s),
but not in any purely... | python | def find_direct_metabolites(model, reaction, tolerance=1E-06):
biomass_rxns = set(helpers.find_biomass_reaction(model))
tra_bou_bio_rxns = helpers.find_interchange_biomass_reactions(
model, biomass_rxns)
try:
precursors = find_biomass_precursors(model, reaction)
main_comp = helpers.f... | [
"def",
"find_direct_metabolites",
"(",
"model",
",",
"reaction",
",",
"tolerance",
"=",
"1E-06",
")",
":",
"biomass_rxns",
"=",
"set",
"(",
"helpers",
".",
"find_biomass_reaction",
"(",
"model",
")",
")",
"tra_bou_bio_rxns",
"=",
"helpers",
".",
"find_interchang... | Return list of possible direct biomass precursor metabolites.
The term direct metabolites describes metabolites that are involved only
in either transport and/or boundary reactions, AND the biomass reaction(s),
but not in any purely metabolic reactions.
Parameters
----------
model : cobra.Mode... | [
"Return",
"list",
"of",
"possible",
"direct",
"biomass",
"precursor",
"metabolites",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L209-L272 |
2,493 | opencobra/memote | memote/support/biomass.py | detect_false_positive_direct_metabolites | def detect_false_positive_direct_metabolites(
candidates, biomass_reactions, cytosol, extra, reaction_fluxes,
metabolite_fluxes):
"""
Weed out false positive direct metabolites.
False positives exists in the extracellular
compartment with flux from the cytosolic compartment and are part... | python | def detect_false_positive_direct_metabolites(
candidates, biomass_reactions, cytosol, extra, reaction_fluxes,
metabolite_fluxes):
for met in candidates:
is_internal = met.compartment != extra
for rxn in met.reactions:
if rxn in biomass_reactions:
continue
... | [
"def",
"detect_false_positive_direct_metabolites",
"(",
"candidates",
",",
"biomass_reactions",
",",
"cytosol",
",",
"extra",
",",
"reaction_fluxes",
",",
"metabolite_fluxes",
")",
":",
"for",
"met",
"in",
"candidates",
":",
"is_internal",
"=",
"met",
".",
"compartm... | Weed out false positive direct metabolites.
False positives exists in the extracellular
compartment with flux from the cytosolic compartment and are part of the
biomass reaction(s). It sums fluxes positively or negatively depending
on if direct metabolites in the extracellular compartment are defined a... | [
"Weed",
"out",
"false",
"positive",
"direct",
"metabolites",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L275-L334 |
2,494 | opencobra/memote | memote/support/biomass.py | bundle_biomass_components | def bundle_biomass_components(model, reaction):
"""
Return bundle biomass component reactions if it is not one lumped reaction.
There are two basic ways of specifying the biomass composition. The most
common is a single lumped reaction containing all biomass precursors.
Alternatively, the biomass e... | python | def bundle_biomass_components(model, reaction):
if len(reaction.metabolites) >= 16:
return [reaction]
id_of_main_compartment = helpers.find_compartment_id_in_model(model,
'c')
gam_mets = ["MNXM3", "MNXM2", "MNXM7", "MNXM1", 'MNXM9']
... | [
"def",
"bundle_biomass_components",
"(",
"model",
",",
"reaction",
")",
":",
"if",
"len",
"(",
"reaction",
".",
"metabolites",
")",
">=",
"16",
":",
"return",
"[",
"reaction",
"]",
"id_of_main_compartment",
"=",
"helpers",
".",
"find_compartment_id_in_model",
"(... | Return bundle biomass component reactions if it is not one lumped reaction.
There are two basic ways of specifying the biomass composition. The most
common is a single lumped reaction containing all biomass precursors.
Alternatively, the biomass equation can be split into several reactions
each focusin... | [
"Return",
"bundle",
"biomass",
"component",
"reactions",
"if",
"it",
"is",
"not",
"one",
"lumped",
"reaction",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L337-L408 |
2,495 | opencobra/memote | memote/support/biomass.py | essential_precursors_not_in_biomass | def essential_precursors_not_in_biomass(model, reaction):
u"""
Return a list of essential precursors missing from the biomass reaction.
There are universal components of life that make up the biomass of all
known organisms. These include all proteinogenic amino acids, deoxy- and
ribonucleotides, wa... | python | def essential_precursors_not_in_biomass(model, reaction):
u"""
Return a list of essential precursors missing from the biomass reaction.
There are universal components of life that make up the biomass of all
known organisms. These include all proteinogenic amino acids, deoxy- and
ribonucleotides, wa... | [
"def",
"essential_precursors_not_in_biomass",
"(",
"model",
",",
"reaction",
")",
":",
"main_comp",
"=",
"helpers",
".",
"find_compartment_id_in_model",
"(",
"model",
",",
"'c'",
")",
"biomass_eq",
"=",
"bundle_biomass_components",
"(",
"model",
",",
"reaction",
")"... | u"""
Return a list of essential precursors missing from the biomass reaction.
There are universal components of life that make up the biomass of all
known organisms. These include all proteinogenic amino acids, deoxy- and
ribonucleotides, water and a range of metabolic cofactors.
Parameters
--... | [
"u",
"Return",
"a",
"list",
"of",
"essential",
"precursors",
"missing",
"from",
"the",
"biomass",
"reaction",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/support/biomass.py#L411-L477 |
2,496 | opencobra/memote | memote/suite/cli/callbacks.py | validate_experimental | def validate_experimental(context, param, value):
"""Load and validate an experimental data configuration."""
if value is None:
return
config = ExperimentConfiguration(value)
config.validate()
return config | python | def validate_experimental(context, param, value):
if value is None:
return
config = ExperimentConfiguration(value)
config.validate()
return config | [
"def",
"validate_experimental",
"(",
"context",
",",
"param",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"config",
"=",
"ExperimentConfiguration",
"(",
"value",
")",
"config",
".",
"validate",
"(",
")",
"return",
"config"
] | Load and validate an experimental data configuration. | [
"Load",
"and",
"validate",
"an",
"experimental",
"data",
"configuration",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/callbacks.py#L44-L50 |
2,497 | opencobra/memote | memote/suite/cli/callbacks.py | probe_git | def probe_git():
"""Return a git repository instance if it exists."""
try:
repo = git.Repo()
except git.InvalidGitRepositoryError:
LOGGER.warning(
"We highly recommend keeping your model in a git repository."
" It allows you to track changes and to easily collaborate ... | python | def probe_git():
try:
repo = git.Repo()
except git.InvalidGitRepositoryError:
LOGGER.warning(
"We highly recommend keeping your model in a git repository."
" It allows you to track changes and to easily collaborate with"
" others via online platforms such as h... | [
"def",
"probe_git",
"(",
")",
":",
"try",
":",
"repo",
"=",
"git",
".",
"Repo",
"(",
")",
"except",
"git",
".",
"InvalidGitRepositoryError",
":",
"LOGGER",
".",
"warning",
"(",
"\"We highly recommend keeping your model in a git repository.\"",
"\" It allows you to tra... | Return a git repository instance if it exists. | [
"Return",
"a",
"git",
"repository",
"instance",
"if",
"it",
"exists",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/callbacks.py#L79-L94 |
2,498 | opencobra/memote | memote/suite/cli/callbacks.py | git_installed | def git_installed():
"""Interrupt execution of memote if `git` has not been installed."""
LOGGER.info("Checking `git` installation.")
try:
check_output(['git', '--version'])
except CalledProcessError as e:
LOGGER.critical(
"The execution of memote was interrupted since no ins... | python | def git_installed():
LOGGER.info("Checking `git` installation.")
try:
check_output(['git', '--version'])
except CalledProcessError as e:
LOGGER.critical(
"The execution of memote was interrupted since no installation of "
"`git` could be detected. Please install git t... | [
"def",
"git_installed",
"(",
")",
":",
"LOGGER",
".",
"info",
"(",
"\"Checking `git` installation.\"",
")",
"try",
":",
"check_output",
"(",
"[",
"'git'",
",",
"'--version'",
"]",
")",
"except",
"CalledProcessError",
"as",
"e",
":",
"LOGGER",
".",
"critical",
... | Interrupt execution of memote if `git` has not been installed. | [
"Interrupt",
"execution",
"of",
"memote",
"if",
"git",
"has",
"not",
"been",
"installed",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/cli/callbacks.py#L103-L115 |
2,499 | opencobra/memote | memote/suite/results/repo_result_manager.py | RepoResultManager.record_git_info | def record_git_info(self, commit=None):
"""
Record git meta information.
Parameters
----------
commit : str, optional
Unique hexsha of the desired commit.
Returns
-------
GitInfo
Git commit meta information.
"""
i... | python | def record_git_info(self, commit=None):
if commit is None:
commit = self._repo.head.commit
else:
commit = self._repo.commit(commit)
return GitInfo(
hexsha=commit.hexsha,
author=commit.author.name,
email=commit.author.email,
... | [
"def",
"record_git_info",
"(",
"self",
",",
"commit",
"=",
"None",
")",
":",
"if",
"commit",
"is",
"None",
":",
"commit",
"=",
"self",
".",
"_repo",
".",
"head",
".",
"commit",
"else",
":",
"commit",
"=",
"self",
".",
"_repo",
".",
"commit",
"(",
"... | Record git meta information.
Parameters
----------
commit : str, optional
Unique hexsha of the desired commit.
Returns
-------
GitInfo
Git commit meta information. | [
"Record",
"git",
"meta",
"information",
"."
] | 276630fcd4449fb7b914186edfd38c239e7052df | https://github.com/opencobra/memote/blob/276630fcd4449fb7b914186edfd38c239e7052df/memote/suite/results/repo_result_manager.py#L61-L85 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.