Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_design_to_gnomic(self, cad_reaction):
from gnomic import Genotype
t1 = ReactionKnockoutTarget('PGI')
t2 = ReactionKnockoutTarget('GAPD')
t3 = ReactionKnockinTarget("CAD", cad_reaction)
strain_design1 = StrainDesign([t1, t2, t3])
sd_gnomic = strain_design1.to_gnomic()
assert isinstance(sd_gnomic, Genotype)
assert len(sd_gnomic.added_features) == 1
assert len(sd_gnomic.removed_features) == 2
def test_add_strain_design(self, cad_reaction):
t1 = ReactionKnockoutTarget('PGI')
t2 = ReactionKnockoutTarget('GAPD')
t3 = ReactionKnockinTarget("CAD", cad_reaction)
strain_design1 = StrainDesign([t1, t2, t3])
t4 = ReactionModulationTarget("PGI", 5, 1)
strain_design2 = StrainDesign([t4])
with pytest.raises(IncompatibleTargets):
strain_design1.__add__(strain_design2)
with pytest.raises(IncompatibleTargets):
strain_design2.__add__(strain_design1)
with pytest.raises(IncompatibleTargets):
strain_design1.__iadd__(strain_design2)
with pytest.raises(IncompatibleTargets):
strain_design2.__iadd__(strain_design1)
t5 = ReactionModulationTarget("RPI", 2, 0)
strain_design3 = StrainDesign([t5])
strain_design4 = strain_design3 + strain_design1
assert t1 in strain_design4
def __add__(self, other):
df = DataFrame([design.targets for design in self._designs], columns=["targets"])
df['method'] = self.__method_name__
i = len(df)
for j, design in enumerate(other):
df.loc[i + j] = [design, [self.__method_name__]]
df = df.groupby(["design"]).aggregate(self._aggreate_functions_)
return StrainDesignMethodEnsemble([StrainDesign(targets) for targets in df.targets], df.method.tolist())
def __add__(self, other):
if not isinstance(other, StrainDesign):
raise AssertionError("Only instances of StrainDesign can be added together")
targets = {}
for target in self.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
for target in other.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
targets = [next(iter(t)) if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]
return StrainDesign(targets)
def process_strain_designs(self, strain_designs, model=None, pathway=None, aerobic=None, **kwargs):
model = model.copy()
assert isinstance(pathway, StrainDesign)
assert isinstance(pathway, PathwayResult)
final_strain_designs = []
fitness = []
yields = []
biomass = []
target_flux = []
pyield = product_yield(pathway.product, model.carbon_source)
bpcy = biomass_product_coupled_min_yield(model.biomass, pathway.product, model.carbon_source)
for strain_design in strain_designs:
assert isinstance(strain_design, StrainDesign)
_fitness, _yield, _target_flux, _biomass = self.evaluate_design(model, strain_design,
pathway, aerobic, bpcy, pyield)
fitness.append(_fitness)
yields.append(_yield)
final_strain_designs.append(strain_design)
biomass.append(_biomass)
raise AssertionError("Only instances of StrainDesign can be added together")
targets = {}
for target in self.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
for target in other.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
targets = [next(iter(t)) if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]
return StrainDesign(targets)
def _generate_designs(swaps, swap_pair):
designs = []
for swap_design, _ in swaps:
designs.append(StrainDesign([ReactionCofactorSwapTarget(swap, swap_pair) for swap in swap_design]))
return designs
))
else:
# For now we ignore reactions that have a negative
# normalized gap, indicating that their flux needs to
# decrease in production, but where the production
# interval is larger than the reference interval.
if abs(row.upper_bound) > abs(ref_lower):
continue
targets.append(ReactionModulationTarget(
rid,
value=row.upper_bound,
reference_value=ref_lower,
fold_change=row.normalized_gaps
))
designs.append(StrainDesign(targets))
return designs
from cameo.core.strain_design import StrainDesignMethodResult, StrainDesign, StrainDesignMethod
from cameo.core.target import ReactionKnockinTarget
from cameo.data import metanetx
from cameo.strain_design.pathway_prediction import util
from cameo.util import TimeMachine
from cameo.visualization.plotting import plotter
__all__ = ['PathwayPredictor']
logger = logging.getLogger(__name__)
add = Add._from_args
mul = Mul._from_args
class PathwayResult(Pathway, Result, StrainDesign):
def __init__(self, reactions, exchanges, adapters, product, *args, **kwargs):
self._meta_information = MetaInformation()
self.reactions = reactions
self.exchanges = exchanges
self.adapters = adapters
self.product = product
self.targets = self._build_targets()
def _replace_adapted_metabolites(self, reaction):
"""
Replace adapted metabolites by model metabolites
Parameters
----------
reaction: cameo.core.reaction.Reaction