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_compatible_targets(self):
modulation_target = ReactionModulationTarget("a", 1, 0)
ki_target = ReactionKnockinTarget("a", None)
ensemble_1 = EnsembleTarget("a", [modulation_target, ki_target])
ensemble_2 = EnsembleTarget("a", [ki_target, modulation_target])
assert ensemble_1.targets == ensemble_2.targets
modulation_target = ReactionModulationTarget("b", 1, 0)
swap_target = ReactionCofactorSwapTarget("b", [("nad_c", "nadh_c"), ("nadp_c", "nadph_c")])
ensemble_1 = EnsembleTarget("b", [modulation_target, swap_target])
ensemble_2 = EnsembleTarget("b", [swap_target, modulation_target])
assert ensemble_1.targets == ensemble_2.targets
ki_target = ReactionKnockinTarget("c", None)
def test_invalid_reaction_modulation_target(self, model):
reaction_id = "PGI_XY"
ref_val = 4.86
value = 4
down_reg_target = ReactionModulationTarget(reaction_id, value, ref_val)
with pytest.raises(KeyError):
down_reg_target.apply(model)
reaction_id = "RPI_Z"
ref_val = -2.28150
value = -2.0
down_reg_target = ReactionModulationTarget(reaction_id, value, ref_val)
with pytest.raises(KeyError):
down_reg_target.apply(model)
ensemble_1 = EnsembleTarget("a", [modulation_target, ki_target])
ensemble_2 = EnsembleTarget("a", [ki_target, modulation_target])
assert ensemble_1.targets == ensemble_2.targets
modulation_target = ReactionModulationTarget("b", 1, 0)
swap_target = ReactionCofactorSwapTarget("b", [("nad_c", "nadh_c"), ("nadp_c", "nadph_c")])
ensemble_1 = EnsembleTarget("b", [modulation_target, swap_target])
ensemble_2 = EnsembleTarget("b", [swap_target, modulation_target])
assert ensemble_1.targets == ensemble_2.targets
ki_target = ReactionKnockinTarget("c", None)
modulation_target = ReactionModulationTarget("c", 1, 0)
swap_target = ReactionCofactorSwapTarget("c", [("nad_c", "nadh_c"), ("nadp_c", "nadph_c")])
ensemble = EnsembleTarget("c", [modulation_target, swap_target, ki_target])
assert ensemble.targets[0] == ki_target
assert ensemble.targets[1] == swap_target
assert ensemble.targets[2] == modulation_target
def test_invalid_reaction_modulation_target(self, model):
reaction_id = "PGI_XY"
ref_val = 4.86
value = 4
down_reg_target = ReactionModulationTarget(reaction_id, value, ref_val)
with pytest.raises(KeyError):
down_reg_target.apply(model)
reaction_id = "RPI_Z"
ref_val = -2.28150
value = -2.0
down_reg_target = ReactionModulationTarget(reaction_id, value, ref_val)
with pytest.raises(KeyError):
down_reg_target.apply(model)
with model:
down_reg_target.apply(model)
assert model.reactions.PGI.upper_bound == 3.4
assert model.reactions.PGI.lower_bound == -1000
assert abs(model.slim_optimize() - 0.8706) < 0.0001
assert model.reactions.PGI.upper_bound == 1000
assert model.reactions.PGI.lower_bound == -1000
reaction_id = "RPI"
ref_val = -2.28150
value = -1.5
fold_change = -0.342537
down_reg_target = ReactionModulationTarget(reaction_id, value, ref_val)
assert round(abs(down_reg_target.fold_change - fold_change), 5) == 0
with model:
down_reg_target.apply(model)
assert model.reactions.RPI.lower_bound == -1.5
assert model.reactions.RPI.upper_bound == 1000
assert abs(model.slim_optimize() - 0.8691) < 0.0001
assert model.reactions.RPI.lower_bound == -1000
assert model.reactions.RPI.upper_bound == 1000
if abs(ref_upper) > abs(row.lower_bound):
continue
targets.append(ReactionModulationTarget(
rid,
value=row.lower_bound,
reference_value=ref_upper,
fold_change=row.normalized_gaps
))
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
def __init__(self, id, value, reference_value, **kwargs):
super(ReactionModulationTarget, self).__init__(
id, value, reference_value, **kwargs
)
reference_value=ref_upper
))
# Generate all suddenly essential targets where we know the
# reference interval lies around zero.
for row in relevant_targets[
relevant_targets["suddenly_essential"]
].itertuples():
rid = row.Index
if row.lower_bound > 0:
targets.append(ReactionModulationTarget(
rid,
value=row.lower_bound,
reference_value=reference_fva.at[rid, "upper_bound"]
))
else:
targets.append(ReactionModulationTarget(
rid,
value=row.upper_bound,
reference_value=reference_fva.at[rid, "lower_bound"]
))
# Generate all other flux modulation targets.
for row in relevant_targets[
(~relevant_targets["KO"]) & (
~relevant_targets["flux_reversal"]) & (
~relevant_targets["suddenly_essential"])
].itertuples():
rid = row.Index
ref_lower = reference_fva.at[rid, 'lower_bound']
ref_upper = reference_fva.at[rid, 'upper_bound']
if row.normalized_gaps > 0:
# For now we ignore reactions that have a positive
# normalized gap, indicating that their flux is important
for row in relevant_targets[
(~relevant_targets["KO"]) & (
~relevant_targets["flux_reversal"]) & (
~relevant_targets["suddenly_essential"])
].itertuples():
rid = row.Index
ref_lower = reference_fva.at[rid, 'lower_bound']
ref_upper = reference_fva.at[rid, 'upper_bound']
if row.normalized_gaps > 0:
# For now we ignore reactions that have a positive
# normalized gap, indicating that their flux is important
# for production, but where the reference flux is higher
# than the production flux.
if abs(ref_upper) > abs(row.lower_bound):
continue
targets.append(ReactionModulationTarget(
rid,
value=row.lower_bound,
reference_value=ref_upper,
fold_change=row.normalized_gaps
))
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,