_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q255200 | add_lexicographic_constraints | validation | def add_lexicographic_constraints(model,
objectives,
objective_direction='max'):
"""
Successively optimize separate targets in a specific order.
For each objective, optimize the model and set the optimal value as a
constraint. Proceed ... | python | {
"resource": ""
} |
q255201 | shared_np_array | validation | def shared_np_array(shape, data=None, integer=False):
"""Create a new numpy array that resides in shared memory.
Parameters
----------
shape : tuple of ints
The shape of the new array.
data : numpy.array
Data to copy to the new array. Has to have the same shape.
integer : boolea... | python | {
"resource": ""
} |
q255202 | step | validation | def step(sampler, x, delta, fraction=None, tries=0):
"""Sample a new feasible point from the point `x` in direction `delta`."""
prob = sampler.problem
valid = ((np.abs(delta) > sampler.feasibility_tol) &
np.logical_not(prob.variable_fixed))
# permissible alphas for staying in variable bou... | python | {
"resource": ""
} |
q255203 | HRSampler.__build_problem | validation | def __build_problem(self):
"""Build the matrix representation of the sampling problem."""
# Set up the mathematical problem
prob = constraint_matrices(self.model, zero_tol=self.feasibility_tol)
# check if there any non-zero equality constraints
equalities = prob.equalities
... | python | {
"resource": ""
} |
q255204 | HRSampler.generate_fva_warmup | validation | def generate_fva_warmup(self):
"""Generate the warmup points for the sampler.
Generates warmup points by setting each flux as the sole objective
and minimizing/maximizing it. Also caches the projection of the
warmup points into the nullspace for non-homogeneous problems (only
if... | python | {
"resource": ""
} |
q255205 | HRSampler._reproject | validation | def _reproject(self, p):
"""Reproject a point into the feasibility region.
This function is guaranteed to return a new feasible point. However,
no guarantees in terms of proximity to the original point can be made.
Parameters
----------
p : numpy.array
The c... | python | {
"resource": ""
} |
q255206 | HRSampler._random_point | validation | def _random_point(self):
"""Find an approximately random point in the flux cone."""
idx = np.random.randint(self.n_warmup,
size=min(2, np.ceil(np.sqrt(self.n_warmup))))
return self.warmup[idx, :].mean(axis=0) | python | {
"resource": ""
} |
q255207 | HRSampler._is_redundant | validation | def _is_redundant(self, matrix, cutoff=None):
"""Identify rdeundant rows in a matrix that can be removed."""
cutoff = 1.0 - self.feasibility_tol
# Avoid zero variances
extra_col = matrix[:, 0] + 1
# Avoid zero rows being correlated with constant rows
extra_col[matrix.s... | python | {
"resource": ""
} |
q255208 | HRSampler._bounds_dist | validation | def _bounds_dist(self, p):
"""Get the lower and upper bound distances. Negative is bad."""
prob = self.problem
lb_dist = (p - prob.variable_bounds[0, ]).min()
ub_dist = (prob.variable_bounds[1, ] - p).min()
if prob.bounds.shape[0] > 0:
const = prob.inequalities.dot(... | python | {
"resource": ""
} |
q255209 | HRSampler.batch | validation | def batch(self, batch_size, batch_num, fluxes=True):
"""Create a batch generator.
This is useful to generate n batches of m samples each.
Parameters
----------
batch_size : int
The number of samples contained in each batch (m).
batch_num : int
Th... | python | {
"resource": ""
} |
q255210 | HRSampler.validate | validation | def validate(self, samples):
"""Validate a set of samples for equality and inequality feasibility.
Can be used to check whether the generated samples and warmup points
are feasible.
Parameters
----------
samples : numpy.matrix
Must be of dimension (n_samples... | python | {
"resource": ""
} |
q255211 | prune_unused_metabolites | validation | def prune_unused_metabolites(cobra_model):
"""Remove metabolites that are not involved in any reactions and
returns pruned model
Parameters
----------
cobra_model: class:`~cobra.core.Model.Model` object
the model to remove unused metabolites from
Returns
-------
output_model: c... | python | {
"resource": ""
} |
q255212 | prune_unused_reactions | validation | def prune_unused_reactions(cobra_model):
"""Remove reactions with no assigned metabolites, returns pruned model
Parameters
----------
cobra_model: class:`~cobra.core.Model.Model` object
the model to remove unused reactions from
Returns
-------
output_model: class:`~cobra.core.Model... | python | {
"resource": ""
} |
q255213 | undelete_model_genes | validation | def undelete_model_genes(cobra_model):
"""Undoes the effects of a call to delete_model_genes in place.
cobra_model: A cobra.Model which will be modified in place
"""
if cobra_model._trimmed_genes is not None:
for x in cobra_model._trimmed_genes:
x.functional = True
if cobra_... | python | {
"resource": ""
} |
q255214 | find_gene_knockout_reactions | validation | def find_gene_knockout_reactions(cobra_model, gene_list,
compiled_gene_reaction_rules=None):
"""identify reactions which will be disabled when the genes are knocked out
cobra_model: :class:`~cobra.core.Model.Model`
gene_list: iterable of :class:`~cobra.core.Gene.Gene`
... | python | {
"resource": ""
} |
q255215 | remove_genes | validation | def remove_genes(cobra_model, gene_list, remove_reactions=True):
"""remove genes entirely from the model
This will also simplify all gene_reaction_rules with this
gene inactivated."""
gene_set = {cobra_model.genes.get_by_id(str(i)) for i in gene_list}
gene_id_set = {i.id for i in gene_set}
remo... | python | {
"resource": ""
} |
q255216 | gapfill | validation | def gapfill(model, universal=None, lower_bound=0.05,
penalties=None, demand_reactions=True, exchange_reactions=False,
iterations=1):
"""Perform gapfilling on a model.
See documentation for the class GapFiller.
Parameters
----------
model : cobra.Model
The model to p... | python | {
"resource": ""
} |
q255217 | GapFiller.extend_model | validation | def extend_model(self, exchange_reactions=False, demand_reactions=True):
"""Extend gapfilling model.
Add reactions from universal model and optionally exchange and
demand reactions for all metabolites in the model to perform
gapfilling on.
Parameters
----------
... | python | {
"resource": ""
} |
q255218 | GapFiller.update_costs | validation | def update_costs(self):
"""Update the coefficients for the indicator variables in the objective.
Done incrementally so that second time the function is called,
active indicators in the current solutions gets higher cost than the
unused indicators.
"""
for var in self.ind... | python | {
"resource": ""
} |
q255219 | GapFiller.add_switches_and_objective | validation | def add_switches_and_objective(self):
""" Update gapfilling model with switches and the indicator objective.
"""
constraints = list()
big_m = max(max(abs(b) for b in r.bounds)
for r in self.model.reactions)
prob = self.model.problem
for rxn in self.mod... | python | {
"resource": ""
} |
q255220 | GapFiller.fill | validation | def fill(self, iterations=1):
"""Perform the gapfilling by iteratively solving the model, updating
the costs and recording the used reactions.
Parameters
----------
iterations : int
The number of rounds of gapfilling to perform. For every
iteration, the ... | python | {
"resource": ""
} |
q255221 | find_external_compartment | validation | def find_external_compartment(model):
"""Find the external compartment in the model.
Uses a simple heuristic where the external compartment should be the one
with the most exchange reactions.
Arguments
---------
model : cobra.Model
A cobra model.
Returns
-------
str
... | python | {
"resource": ""
} |
q255222 | is_boundary_type | validation | def is_boundary_type(reaction, boundary_type, external_compartment):
"""Check whether a reaction is an exchange reaction.
Arguments
---------
reaction : cobra.Reaction
The reaction to check.
boundary_type : str
What boundary type to check for. Must be one of
"exchange", "dem... | python | {
"resource": ""
} |
q255223 | find_boundary_types | validation | def find_boundary_types(model, boundary_type, external_compartment=None):
"""Find specific boundary reactions.
Arguments
---------
model : cobra.Model
A cobra model.
boundary_type : str
What boundary type to check for. Must be one of
"exchange", "demand", or "sink".
exte... | python | {
"resource": ""
} |
q255224 | normalize_cutoff | validation | def normalize_cutoff(model, zero_cutoff=None):
"""Return a valid zero cutoff value."""
if zero_cutoff is None:
return model.tolerance
else:
if zero_cutoff < model.tolerance:
raise ValueError(
"The chosen zero cutoff cannot be less than the model's "
... | python | {
"resource": ""
} |
q255225 | _sample_chain | validation | def _sample_chain(args):
"""Sample a single chain for OptGPSampler.
center and n_samples are updated locally and forgotten afterwards.
"""
n, idx = args # has to be this way to work in Python 2.7
center = sampler.center
np.random.seed((sampler._seed + idx) % np.iinfo(np.int32).max)
... | python | {
"resource": ""
} |
q255226 | ast2str | validation | def ast2str(expr, level=0, names=None):
"""convert compiled ast to gene_reaction_rule str
Parameters
----------
expr : str
string for a gene reaction rule, e.g "a and b"
level : int
internal use only
names : dict
Dict where each element id a gene identifier and the value... | python | {
"resource": ""
} |
q255227 | eval_gpr | validation | def eval_gpr(expr, knockouts):
"""evaluate compiled ast of gene_reaction_rule with knockouts
Parameters
----------
expr : Expression
The ast of the gene reaction rule
knockouts : DictList, set
Set of genes that are knocked out
Returns
-------
bool
True if the ge... | python | {
"resource": ""
} |
q255228 | parse_gpr | validation | def parse_gpr(str_expr):
"""parse gpr into AST
Parameters
----------
str_expr : string
string with the gene reaction rule to parse
Returns
-------
tuple
elements ast_tree and gene_ids as a set
"""
str_expr = str_expr.strip()
if len(str_expr) == 0:
return... | python | {
"resource": ""
} |
q255229 | Gene.knock_out | validation | def knock_out(self):
"""Knockout gene by marking it as non-functional and setting all
associated reactions bounds to zero.
The change is reverted upon exit if executed within the model as
context.
"""
self.functional = False
for reaction in self.reactions:
... | python | {
"resource": ""
} |
q255230 | Gene.remove_from_model | validation | def remove_from_model(self, model=None,
make_dependent_reactions_nonfunctional=True):
"""Removes the association
Parameters
----------
model : cobra model
The model to remove the gene from
make_dependent_reactions_nonfunctional : bool
... | python | {
"resource": ""
} |
q255231 | add_moma | validation | def add_moma(model, solution=None, linear=True):
r"""Add constraints and objective representing for MOMA.
This adds variables and constraints for the minimization of metabolic
adjustment (MOMA) to the model.
Parameters
----------
model : cobra.Model
The model to add MOMA constraints an... | python | {
"resource": ""
} |
q255232 | _fix_type | validation | def _fix_type(value):
"""convert possible types to str, float, and bool"""
# Because numpy floats can not be pickled to json
if isinstance(value, string_types):
return str(value)
if isinstance(value, float_):
return float(value)
if isinstance(value, bool_):
return bool(value)... | python | {
"resource": ""
} |
q255233 | _update_optional | validation | def _update_optional(cobra_object, new_dict, optional_attribute_dict,
ordered_keys):
"""update new_dict with optional attributes from cobra_object"""
for key in ordered_keys:
default = optional_attribute_dict[key]
value = getattr(cobra_object, key)
if value is None o... | python | {
"resource": ""
} |
q255234 | model_to_dict | validation | def model_to_dict(model, sort=False):
"""Convert model to a dict.
Parameters
----------
model : cobra.Model
The model to reformulate as a dict.
sort : bool, optional
Whether to sort the metabolites, reactions, and genes or maintain the
order defined in the model.
Return... | python | {
"resource": ""
} |
q255235 | model_from_dict | validation | def model_from_dict(obj):
"""Build a model from a dict.
Models stored in json are first formulated as a dict that can be read to
cobra model using this function.
Parameters
----------
obj : dict
A dictionary with elements, 'genes', 'compartments', 'id',
'metabolites', 'notes' a... | python | {
"resource": ""
} |
q255236 | _get_id_compartment | validation | def _get_id_compartment(id):
"""extract the compartment from the id string"""
bracket_search = _bracket_re.findall(id)
if len(bracket_search) == 1:
return bracket_search[0][1]
underscore_search = _underscore_re.findall(id)
if len(underscore_search) == 1:
return underscore_search[0][1... | python | {
"resource": ""
} |
q255237 | _cell | validation | def _cell(x):
"""translate an array x into a MATLAB cell array"""
x_no_none = [i if i is not None else "" for i in x]
return array(x_no_none, dtype=np_object) | python | {
"resource": ""
} |
q255238 | load_matlab_model | validation | def load_matlab_model(infile_path, variable_name=None, inf=inf):
"""Load a cobra model stored as a .mat file
Parameters
----------
infile_path: str
path to the file to to read
variable_name: str, optional
The variable name of the model in the .mat file. If this is not
specif... | python | {
"resource": ""
} |
q255239 | save_matlab_model | validation | def save_matlab_model(model, file_name, varname=None):
"""Save the cobra model as a .mat file.
This .mat file can be used directly in the MATLAB version of COBRA.
Parameters
----------
model : cobra.core.Model.Model object
The model to save
file_name : str or file-like object
T... | python | {
"resource": ""
} |
q255240 | create_mat_dict | validation | def create_mat_dict(model):
"""create a dict mapping model attributes to arrays"""
rxns = model.reactions
mets = model.metabolites
mat = OrderedDict()
mat["mets"] = _cell([met_id for met_id in create_mat_metabolite_id(model)])
mat["metNames"] = _cell(mets.list_attr("name"))
mat["metFormulas"... | python | {
"resource": ""
} |
q255241 | model_to_pymatbridge | validation | def model_to_pymatbridge(model, variable_name="model", matlab=None):
"""send the model to a MATLAB workspace through pymatbridge
This model can then be manipulated through the COBRA toolbox
Parameters
----------
variable_name : str
The variable name to which the model will be assigned in t... | python | {
"resource": ""
} |
q255242 | get_context | validation | def get_context(obj):
"""Search for a context manager"""
try:
return obj._contexts[-1]
except (AttributeError, IndexError):
pass
try:
return obj._model._contexts[-1]
except (AttributeError, IndexError):
pass
return None | python | {
"resource": ""
} |
q255243 | resettable | validation | def resettable(f):
"""A decorator to simplify the context management of simple object
attributes. Gets the value of the attribute prior to setting it, and stores
a function to set the value to the old value in the HistoryManager.
"""
def wrapper(self, new_value):
context = get_context(self)... | python | {
"resource": ""
} |
q255244 | get_solution | validation | def get_solution(model, reactions=None, metabolites=None, raise_error=False):
"""
Generate a solution representation of the current solver state.
Parameters
---------
model : cobra.Model
The model whose reactions to retrieve values for.
reactions : list, optional
An iterable of ... | python | {
"resource": ""
} |
q255245 | Model.get_metabolite_compartments | validation | def get_metabolite_compartments(self):
"""Return all metabolites' compartments."""
warn('use Model.compartments instead', DeprecationWarning)
return {met.compartment for met in self.metabolites
if met.compartment is not None} | python | {
"resource": ""
} |
q255246 | Model.medium | validation | def medium(self, medium):
"""Get or set the constraints on the model exchanges.
`model.medium` returns a dictionary of the bounds for each of the
boundary reactions, in the form of `{rxn_id: bound}`, where `bound`
specifies the absolute value of the bound in direction of metabolite
... | python | {
"resource": ""
} |
q255247 | Model.add_metabolites | validation | def add_metabolites(self, metabolite_list):
"""Will add a list of metabolites to the model object and add new
constraints accordingly.
The change is reverted upon exit when using the model as a context.
Parameters
----------
metabolite_list : A list of `cobra.core.Metab... | python | {
"resource": ""
} |
q255248 | Model.remove_metabolites | validation | def remove_metabolites(self, metabolite_list, destructive=False):
"""Remove a list of metabolites from the the object.
The change is reverted upon exit when using the model as a context.
Parameters
----------
metabolite_list : list
A list with `cobra.Metabolite` obj... | python | {
"resource": ""
} |
q255249 | Model.add_boundary | validation | def add_boundary(self, metabolite, type="exchange", reaction_id=None,
lb=None, ub=None, sbo_term=None):
"""
Add a boundary reaction for a given metabolite.
There are three different types of pre-defined boundary reactions:
exchange, demand, and sink reactions.
... | python | {
"resource": ""
} |
q255250 | Model.add_reactions | validation | def add_reactions(self, reaction_list):
"""Add reactions to the model.
Reactions with identifiers identical to a reaction already in the
model are ignored.
The change is reverted upon exit when using the model as a context.
Parameters
----------
reaction_list :... | python | {
"resource": ""
} |
q255251 | Model.remove_reactions | validation | def remove_reactions(self, reactions, remove_orphans=False):
"""Remove reactions from the model.
The change is reverted upon exit when using the model as a context.
Parameters
----------
reactions : list
A list with reactions (`cobra.Reaction`), or their id's, to re... | python | {
"resource": ""
} |
q255252 | Model.add_groups | validation | def add_groups(self, group_list):
"""Add groups to the model.
Groups with identifiers identical to a group already in the model are
ignored.
If any group contains members that are not in the model, these members
are added to the model as well. Only metabolites, reactions, and g... | python | {
"resource": ""
} |
q255253 | Model.remove_groups | validation | def remove_groups(self, group_list):
"""Remove groups from the model.
Members of each group are not removed
from the model (i.e. metabolites, reactions, and genes in the group
stay in the model after any groups containing them are removed).
Parameters
----------
... | python | {
"resource": ""
} |
q255254 | Model._populate_solver | validation | def _populate_solver(self, reaction_list, metabolite_list=None):
"""Populate attached solver with constraints and variables that
model the provided reactions.
"""
constraint_terms = AutoVivification()
to_add = []
if metabolite_list is not None:
for met in meta... | python | {
"resource": ""
} |
q255255 | Model.slim_optimize | validation | def slim_optimize(self, error_value=float('nan'), message=None):
"""Optimize model without creating a solution object.
Creating a full solution object implies fetching shadow prices and
flux values for all reactions and metabolites from the solver
object. This necessarily takes some tim... | python | {
"resource": ""
} |
q255256 | Model.optimize | validation | def optimize(self, objective_sense=None, raise_error=False):
"""
Optimize the model using flux balance analysis.
Parameters
----------
objective_sense : {None, 'maximize' 'minimize'}, optional
Whether fluxes should be maximized or minimized. In case of None,
... | python | {
"resource": ""
} |
q255257 | Model.repair | validation | def repair(self, rebuild_index=True, rebuild_relationships=True):
"""Update all indexes and pointers in a model
Parameters
----------
rebuild_index : bool
rebuild the indices kept in reactions, metabolites and genes
rebuild_relationships : bool
reset all... | python | {
"resource": ""
} |
q255258 | Model.merge | validation | def merge(self, right, prefix_existing=None, inplace=True,
objective='left'):
"""Merge two models to create a model with the reactions from both
models.
Custom constraints and variables from right models are also copied
to left model, however note that, constraints and var... | python | {
"resource": ""
} |
q255259 | _escape_str_id | validation | def _escape_str_id(id_str):
"""make a single string id SBML compliant"""
for c in ("'", '"'):
if id_str.startswith(c) and id_str.endswith(c) \
and id_str.count(c) == 2:
id_str = id_str.strip(c)
for char, escaped_char in _renames:
id_str = id_str.replace(char, esca... | python | {
"resource": ""
} |
q255260 | escape_ID | validation | def escape_ID(cobra_model):
"""makes all ids SBML compliant"""
for x in chain([cobra_model],
cobra_model.metabolites,
cobra_model.reactions,
cobra_model.genes):
x.id = _escape_str_id(x.id)
cobra_model.repair()
gene_renamer = _GeneEscaper()... | python | {
"resource": ""
} |
q255261 | rename_genes | validation | def rename_genes(cobra_model, rename_dict):
"""renames genes in a model from the rename_dict"""
recompute_reactions = set() # need to recomptue related genes
remove_genes = []
for old_name, new_name in iteritems(rename_dict):
# undefined if there a value matches a different key
# becaus... | python | {
"resource": ""
} |
q255262 | to_json | validation | def to_json(model, sort=False, **kwargs):
"""
Return the model as a JSON document.
``kwargs`` are passed on to ``json.dumps``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
sort : bool, optional
Whether to sort the metabolites, reactions, and genes... | python | {
"resource": ""
} |
q255263 | save_json_model | validation | def save_json_model(model, filename, sort=False, pretty=False, **kwargs):
"""
Write the cobra model to a file in JSON format.
``kwargs`` are passed on to ``json.dump``.
Parameters
----------
model : cobra.Model
The cobra model to represent.
filename : str or file-like
File ... | python | {
"resource": ""
} |
q255264 | load_json_model | validation | def load_json_model(filename):
"""
Load a cobra model from a file in JSON format.
Parameters
----------
filename : str or file-like
File path or descriptor that contains the JSON document describing the
cobra model.
Returns
-------
cobra.Model
The cobra model as... | python | {
"resource": ""
} |
q255265 | add_linear_obj | validation | def add_linear_obj(model):
"""Add a linear version of a minimal medium to the model solver.
Changes the optimization objective to finding the growth medium requiring
the smallest total import flux::
minimize sum |r_i| for r_i in import_reactions
Arguments
---------
model : cobra.Model... | python | {
"resource": ""
} |
q255266 | add_mip_obj | validation | def add_mip_obj(model):
"""Add a mixed-integer version of a minimal medium to the model.
Changes the optimization objective to finding the medium with the least
components::
minimize size(R) where R part of import_reactions
Arguments
---------
model : cobra.model
The model to ... | python | {
"resource": ""
} |
q255267 | _as_medium | validation | def _as_medium(exchanges, tolerance=1e-6, exports=False):
"""Convert a solution to medium.
Arguments
---------
exchanges : list of cobra.reaction
The exchange reactions to consider.
tolerance : positive double
The absolute tolerance for fluxes. Fluxes with an absolute value
... | python | {
"resource": ""
} |
q255268 | minimal_medium | validation | def minimal_medium(model, min_objective_value=0.1, exports=False,
minimize_components=False, open_exchanges=False):
"""
Find the minimal growth medium for the model.
Finds the minimal growth medium for the model which allows for
model as well as individual growth. Here, a minimal med... | python | {
"resource": ""
} |
q255269 | _init_worker | validation | def _init_worker(model, loopless, sense):
"""Initialize a global model object for multiprocessing."""
global _model
global _loopless
_model = model
_model.solver.objective.direction = sense
_loopless = loopless | python | {
"resource": ""
} |
q255270 | flux_variability_analysis | validation | def flux_variability_analysis(model, reaction_list=None, loopless=False,
fraction_of_optimum=1.0, pfba_factor=None,
processes=None):
"""
Determine the minimum and maximum possible flux value for each reaction.
Parameters
----------
model :... | python | {
"resource": ""
} |
q255271 | find_blocked_reactions | validation | def find_blocked_reactions(model,
reaction_list=None,
zero_cutoff=None,
open_exchanges=False,
processes=None):
"""
Find reactions that cannot carry any flux.
The question whether or not a reaction is... | python | {
"resource": ""
} |
q255272 | find_essential_genes | validation | def find_essential_genes(model, threshold=None, processes=None):
"""
Return a set of essential genes.
A gene is considered essential if restricting the flux of all reactions
that depend on it to zero causes the objective, e.g., the growth rate,
to also be zero, below the threshold, or infeasible.
... | python | {
"resource": ""
} |
q255273 | find_essential_reactions | validation | def find_essential_reactions(model, threshold=None, processes=None):
"""Return a set of essential reactions.
A reaction is considered essential if restricting its flux to zero
causes the objective, e.g., the growth rate, to also be zero, below the
threshold, or infeasible.
Parameters
--------... | python | {
"resource": ""
} |
q255274 | add_SBO | validation | def add_SBO(model):
"""adds SBO terms for demands and exchanges
This works for models which follow the standard convention for
constructing and naming these reactions.
The reaction should only contain the single metabolite being exchanged,
and the id should be EX_metid or DM_metid
"""
for ... | python | {
"resource": ""
} |
q255275 | Formula.weight | validation | def weight(self):
"""Calculate the mol mass of the compound
Returns
-------
float
the mol mass
"""
try:
return sum([count * elements_and_molecular_weights[element]
for element, count in self.elements.items()])
excep... | python | {
"resource": ""
} |
q255276 | build_hugo_md | validation | def build_hugo_md(filename, tag, bump):
"""
Build the markdown release notes for Hugo.
Inserts the required TOML header with specific values and adds a break
for long release notes.
Parameters
----------
filename : str, path
The release notes file.
tag : str
The tag, fo... | python | {
"resource": ""
} |
q255277 | find_bump | validation | def find_bump(target, tag):
"""Identify the kind of release by comparing to existing ones."""
tmp = tag.split(".")
existing = [intify(basename(f)) for f in glob(join(target, "[0-9]*.md"))]
latest = max(existing)
if int(tmp[0]) > latest[0]:
return "major"
elif int(tmp[1]) > latest[1]:
... | python | {
"resource": ""
} |
q255278 | main | validation | def main(argv):
"""
Identify the release type and create a new target file with TOML header.
Requires three arguments.
"""
source, target, tag = argv
if "a" in tag:
bump = "alpha"
if "b" in tag:
bump = "beta"
else:
bump = find_bump(target, tag)
filename = "{... | python | {
"resource": ""
} |
q255279 | _multi_deletion | validation | def _multi_deletion(model, entity, element_lists, method="fba",
solution=None, processes=None, **kwargs):
"""
Provide a common interface for single or multiple knockouts.
Parameters
----------
model : cobra.Model
The metabolic model to perform deletions in.
entity : ... | python | {
"resource": ""
} |
q255280 | single_reaction_deletion | validation | def single_reaction_deletion(model, reaction_list=None, method="fba",
solution=None, processes=None, **kwargs):
"""
Knock out each reaction from a given list.
Parameters
----------
model : cobra.Model
The metabolic model to perform deletions in.
reaction_lis... | python | {
"resource": ""
} |
q255281 | single_gene_deletion | validation | def single_gene_deletion(model, gene_list=None, method="fba", solution=None,
processes=None, **kwargs):
"""
Knock out each gene from a given list.
Parameters
----------
model : cobra.Model
The metabolic model to perform deletions in.
gene_list : iterable
... | python | {
"resource": ""
} |
q255282 | double_reaction_deletion | validation | def double_reaction_deletion(model, reaction_list1=None, reaction_list2=None,
method="fba", solution=None, processes=None,
**kwargs):
"""
Knock out each reaction pair from the combinations of two given lists.
We say 'pair' here but the order order d... | python | {
"resource": ""
} |
q255283 | double_gene_deletion | validation | def double_gene_deletion(model, gene_list1=None, gene_list2=None, method="fba",
solution=None, processes=None, **kwargs):
"""
Knock out each gene pair from the combination of two given lists.
We say 'pair' here but the order order does not matter.
Parameters
----------
... | python | {
"resource": ""
} |
q255284 | Reaction.reverse_id | validation | def reverse_id(self):
"""Generate the id of reverse_variable from the reaction's id."""
return '_'.join((self.id, 'reverse',
hashlib.md5(
self.id.encode('utf-8')).hexdigest()[0:5])) | python | {
"resource": ""
} |
q255285 | Reaction.flux | validation | def flux(self):
"""
The flux value in the most recent solution.
Flux is the primal value of the corresponding variable in the model.
Warnings
--------
* Accessing reaction fluxes through a `Solution` object is the safer,
preferred, and only guaranteed to be co... | python | {
"resource": ""
} |
q255286 | Reaction.gene_name_reaction_rule | validation | def gene_name_reaction_rule(self):
"""Display gene_reaction_rule with names intead.
Do NOT use this string for computation. It is intended to give a
representation of the rule using more familiar gene names instead of
the often cryptic ids.
"""
names = {i.id: i.name for... | python | {
"resource": ""
} |
q255287 | Reaction.functional | validation | def functional(self):
"""All required enzymes for reaction are functional.
Returns
-------
bool
True if the gene-protein-reaction (GPR) rule is fulfilled for
this reaction, or if reaction is not associated to a model,
otherwise False.
"""
... | python | {
"resource": ""
} |
q255288 | Reaction._update_awareness | validation | def _update_awareness(self):
"""Make sure all metabolites and genes that are associated with
this reaction are aware of it.
"""
for x in self._metabolites:
x._reaction.add(self)
for x in self._genes:
x._reaction.add(self) | python | {
"resource": ""
} |
q255289 | Reaction.copy | validation | def copy(self):
"""Copy a reaction
The referenced metabolites and genes are also copied.
"""
# no references to model when copying
model = self._model
self._model = None
for i in self._metabolites:
i._model = None
for i in self._genes:
... | python | {
"resource": ""
} |
q255290 | Reaction.get_coefficient | validation | def get_coefficient(self, metabolite_id):
"""
Return the stoichiometric coefficient of a metabolite.
Parameters
----------
metabolite_id : str or cobra.Metabolite
"""
if isinstance(metabolite_id, Metabolite):
return self._metabolites[metabolite_id]
... | python | {
"resource": ""
} |
q255291 | Reaction.add_metabolites | validation | def add_metabolites(self, metabolites_to_add, combine=True,
reversibly=True):
"""Add metabolites and stoichiometric coefficients to the reaction.
If the final coefficient for a metabolite is 0 then it is removed
from the reaction.
The change is reverted upon exit... | python | {
"resource": ""
} |
q255292 | Reaction.subtract_metabolites | validation | def subtract_metabolites(self, metabolites, combine=True, reversibly=True):
"""Subtract metabolites from a reaction.
That means add the metabolites with -1*coefficient. If the final
coefficient for a metabolite is 0 then the metabolite is removed from
the reaction.
Notes
... | python | {
"resource": ""
} |
q255293 | Reaction.build_reaction_string | validation | def build_reaction_string(self, use_metabolite_names=False):
"""Generate a human readable reaction string"""
def format(number):
return "" if number == 1 else str(number).rstrip(".") + " "
id_type = 'id'
if use_metabolite_names:
id_type = 'name'
reactant... | python | {
"resource": ""
} |
q255294 | Reaction.check_mass_balance | validation | def check_mass_balance(self):
"""Compute mass and charge balance for the reaction
returns a dict of {element: amount} for unbalanced elements.
"charge" is treated as an element in this dict
This should be empty for balanced reactions.
"""
reaction_element_dict = defaultd... | python | {
"resource": ""
} |
q255295 | Reaction.compartments | validation | def compartments(self):
"""lists compartments the metabolites are in"""
if self._compartments is None:
self._compartments = {met.compartment for met in self._metabolites
if met.compartment is not None}
return self._compartments | python | {
"resource": ""
} |
q255296 | Reaction._associate_gene | validation | def _associate_gene(self, cobra_gene):
"""Associates a cobra.Gene object with a cobra.Reaction.
Parameters
----------
cobra_gene : cobra.core.Gene.Gene
"""
self._genes.add(cobra_gene)
cobra_gene._reaction.add(self)
cobra_gene._model = self._model | python | {
"resource": ""
} |
q255297 | Reaction._dissociate_gene | validation | def _dissociate_gene(self, cobra_gene):
"""Dissociates a cobra.Gene object with a cobra.Reaction.
Parameters
----------
cobra_gene : cobra.core.Gene.Gene
"""
self._genes.discard(cobra_gene)
cobra_gene._reaction.discard(self) | python | {
"resource": ""
} |
q255298 | Reaction.build_reaction_from_string | validation | def build_reaction_from_string(self, reaction_str, verbose=True,
fwd_arrow=None, rev_arrow=None,
reversible_arrow=None, term_split="+"):
"""Builds reaction from reaction equation reaction_str using parser
Takes a string and using the... | python | {
"resource": ""
} |
q255299 | _clip | validation | def _clip(sid, prefix):
"""Clips a prefix from the beginning of a string if it exists."""
return sid[len(prefix):] if sid.startswith(prefix) else sid | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.