def test_incompatible_targets(self): ko_target = ReactionKnockoutTarget("a") ki_target = ReactionKnockinTarget("a", None) with pytest.raises(IncompatibleTargets): EnsembleTarget("a", [ko_target, ki_target]) with pytest.raises(IncompatibleTargets): EnsembleTarget("a", [ki_target, ko_target]) ko_target = ReactionKnockoutTarget("b") swap_target = ReactionCofactorSwapTarget("b", [("nad_c", "nadh_c"), ("nadp_c", "nadph_c")]) with pytest.raises(IncompatibleTargets): EnsembleTarget("b", [ko_target, swap_target]) with pytest.raises(IncompatibleTargets): EnsembleTarget("b", [swap_target, ko_target]) modulation_target = ReactionModulationTarget("c", 0, 0) ki_target = ReactionKnockinTarget("c", None) with pytest.raises(IncompatibleTargets): EnsembleTarget("c", [modulation_target, ki_target]) with pytest.raises(IncompatibleTargets): EnsembleTarget("c", [ki_target, modulation_target])
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) 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_gnomic_integration_ReactionKnockinTarget(self, model): reaction = Reaction(id="atpzase", name="Cosmic ATP generator") atp_z = Metabolite(id="atp_z", name="Cosmic ATP", compartment="c") reaction.add_metabolites({model.metabolites.atp_c: 1, atp_z: -1}) knockin_target = ReactionKnockinTarget("atpzase", reaction) knockin_target_gnomic = knockin_target.to_gnomic() assert genotype_to_string(Genotype([knockin_target_gnomic])) == "+reaction.atpzase" reaction.add_metabolites({model.metabolites.atp_c: 1, atp_z: -1}) knockin_target = ReactionKnockinTarget("atpzase", reaction, accession_id='atpzase', accession_db='unicorn') knockin_target_gnomic = knockin_target.to_gnomic() assert genotype_to_string(Genotype([knockin_target_gnomic])) == "+reaction.atpzase#unicorn:atpzase"
def _build_targets(self): targets = DictList() for reaction in self.reactions: reaction = self._replace_adapted_metabolites(reaction) targets.append(ReactionKnockinTarget(reaction.id, reaction)) for reaction in self.exchanges: reaction = self._replace_adapted_metabolites(reaction) targets.append(ReactionKnockinTarget(reaction.id, reaction)) product = self._replace_adapted_metabolites(self.product) product.lower_bound = 0 targets.append(ReactionKnockinTarget(product.id, product)) return targets
def test_add_strain_design(self): t1 = ReactionKnockoutTarget('PGI') t2 = ReactionKnockoutTarget('GAPD') t3 = ReactionKnockinTarget("CAD", self.cad_reaction) strain_design1 = StrainDesign([t1, t2, t3]) t4 = ReactionModulationTarget("PGI", 5, 1) strain_design2 = StrainDesign([t4]) self.assertRaises(IncompatibleTargets, strain_design1.__add__, strain_design2) self.assertRaises(IncompatibleTargets, strain_design2.__add__, strain_design1) self.assertRaises(IncompatibleTargets, strain_design1.__iadd__, strain_design2) self.assertRaises(IncompatibleTargets, strain_design2.__iadd__, strain_design1) t5 = ReactionModulationTarget("RPI", 2, 0) strain_design3 = StrainDesign([t5]) strain_design4 = strain_design3 + strain_design1 self.assertIn(t1, strain_design4) self.assertIn(t2, strain_design4) self.assertIn(t3, strain_design4) self.assertNotIn(t4, strain_design4) self.assertIn(t5, strain_design4) strain_design3 += strain_design1 self.assertIn(t1, strain_design3) self.assertIn(t2, strain_design3) self.assertIn(t3, strain_design3) self.assertNotIn(t4, strain_design3) self.assertIn(t5, strain_design3)
def __init__(self, reactions, exchanges, adapters, product, *args, **kwargs): self._meta_information = MetaInformation() self.reactions = reactions self.targets = [ ReactionKnockinTarget(reaction.id, reaction) for reaction in reactions ] self.exchanges = exchanges self.adapters = adapters self.product = product
def _build_targets(self): targets = DictList() for reaction in self.reactions: reaction = self._replace_adapted_metabolites(reaction) if reaction.id in metanetx.mnx2all: target = ReactionKnockinTarget(reaction.id, reaction, accession_id=reaction.id, accession_db='metanetx') else: target = ReactionKnockinTarget(reaction.id, reaction) targets.append(target) for reaction in self.exchanges: reaction = self._replace_adapted_metabolites(reaction) targets.append(ReactionKnockinTarget(reaction.id, reaction)) product = self._replace_adapted_metabolites(self.product) product.lower_bound = 0 targets.append(ReactionKnockinTarget(product.id, product)) return targets
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_reaction_knock_in_target(self, model): reaction = Reaction(id="atpzase", name="Cosmic ATP generator") atp_z = Metabolite(id="atp_z", name="Cosmic ATP", compartment="c") reaction.add_metabolites({model.metabolites.atp_c: 1, atp_z: -1}) knockin_target = ReactionKnockinTarget("atpzase", reaction) with model: knockin_target.apply(model) assert atp_z in model.metabolites assert reaction in model.reactions assert atp_z not in model.metabolites assert reaction not in model.reactions
def test_design_to_gnomic(self): from gnomic import Genotype t1 = ReactionKnockoutTarget('PGI') t2 = ReactionKnockoutTarget('GAPD') t3 = ReactionKnockinTarget("CAD", self.cad_reaction) strain_design1 = StrainDesign([t1, t2, t3]) sd_gnomic = strain_design1.to_gnomic() self.assertIsInstance(sd_gnomic, Genotype) self.assertEqual(len(sd_gnomic.added_features), 1) self.assertEqual(len(sd_gnomic.removed_features), 2)
def test_create_strain_design(self, cad_reaction): t1 = ReactionKnockoutTarget('PGI') t2 = ReactionKnockoutTarget('GAPD') t3 = ReactionKnockinTarget("CAD", cad_reaction) strain_design = StrainDesign([t1, t2, t3]) assert len(strain_design) == 3 strain_design2 = StrainDesign([t1, t2, t3]) strain_design3 = StrainDesign([t2, t1, t3]) assert strain_design == strain_design2 assert strain_design == strain_design3 assert strain_design3 == strain_design2 assert t1 in strain_design assert t2 in strain_design assert t3 in strain_design
def test_create_strain_design(self): t1 = ReactionKnockoutTarget('PGI') t2 = ReactionKnockoutTarget('GAPD') t3 = ReactionKnockinTarget("CAD", self.cad_reaction) strain_design = StrainDesign([t1, t2, t3]) self.assertEqual(len(strain_design), 3) strain_design2 = StrainDesign([t1, t2, t3]) strain_design3 = StrainDesign([t2, t1, t3]) self.assertEqual(strain_design, strain_design2) self.assertEqual(strain_design, strain_design3) self.assertEqual(strain_design3, strain_design2) self.assertIn(t1, strain_design) self.assertIn(t2, strain_design) self.assertIn(t3, strain_design)
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 assert t2 in strain_design4 assert t3 in strain_design4 assert t4 not in strain_design4 assert t5 in strain_design4 strain_design3 += strain_design1 assert t1 in strain_design3 assert t2 in strain_design3 assert t3 in strain_design3 assert t4 not in strain_design3 assert t5 in strain_design3
def test_gnomic_integration(self, model): from gnomic.models import Accession, Feature, Mutation, FeatureTree abstract_target = Target("test") abstract_target_gnomic = abstract_target.to_gnomic() assert isinstance(abstract_target_gnomic, Accession) assert abstract_target_gnomic.identifier == abstract_target.id flux_modulation_target = FluxModulationTarget("test", 1, 0) flux_modulation_target_gnomic = flux_modulation_target.to_gnomic() flux_mod_new = flux_modulation_target_gnomic.new flux_mod_old = flux_modulation_target_gnomic.old assert isinstance(flux_modulation_target_gnomic, Mutation) assert isinstance(flux_mod_old, FeatureTree) assert isinstance(flux_mod_old[0], Feature) assert flux_mod_old[ 0].accession.identifier == flux_modulation_target.id assert flux_mod_old[0].variant is None assert flux_mod_old[0].type == 'flux' assert isinstance(flux_mod_new, FeatureTree) assert isinstance(flux_mod_new[0], Feature) assert flux_mod_new[ 0].accession.identifier == flux_modulation_target.id assert flux_mod_new[0].type == 'flux' assert flux_mod_new[ 0].variant == "over-expression(%.3f)" % flux_modulation_target.fold_change flux_modulation_target = FluxModulationTarget("test", 0.5, 1) flux_modulation_target_gnomic = flux_modulation_target.to_gnomic() flux_mod_new = flux_modulation_target_gnomic.new flux_mod_old = flux_modulation_target_gnomic.old assert isinstance(flux_modulation_target_gnomic, Mutation) assert isinstance(flux_mod_old, FeatureTree) assert isinstance(flux_mod_old[0], Feature) assert flux_mod_old[ 0].accession.identifier == flux_modulation_target.id assert flux_mod_old[0].variant is None assert flux_mod_old[0].type == 'flux' assert isinstance(flux_mod_new, FeatureTree) assert isinstance(flux_mod_new[0], Feature) assert flux_mod_new[ 0].accession.identifier == flux_modulation_target.id assert flux_mod_new[0].type == 'flux' assert flux_mod_new[ 0].variant == "down-regulation(%.3f)" % flux_modulation_target.fold_change flux_modulation_target = FluxModulationTarget("test", 0, 1) flux_modulation_target_gnomic = flux_modulation_target.to_gnomic() assert isinstance(flux_modulation_target_gnomic, Mutation) assert isinstance(flux_modulation_target_gnomic.old, FeatureTree) assert isinstance(flux_modulation_target_gnomic.old[0], Feature) assert flux_modulation_target_gnomic.old[ 0].accession.identifier == flux_modulation_target.id assert flux_modulation_target_gnomic.old[0].variant is None assert flux_modulation_target_gnomic.old[0].type == 'flux' assert flux_modulation_target_gnomic.new is None reaction = Reaction(id="atpzase", name="Cosmic ATP generator") atp_z = Metabolite(id="atp_z", name="Cosmic ATP", compartment="c") reaction.add_metabolites({model.metabolites.atp_c: 1, atp_z: -1}) knockin_target = ReactionKnockinTarget("atpzase", reaction) knockin_target_gnomic = knockin_target.to_gnomic() assert isinstance(knockin_target_gnomic, Mutation) assert isinstance(knockin_target_gnomic.new, FeatureTree) assert isinstance(knockin_target_gnomic.new[0], Feature) assert knockin_target_gnomic.new[ 0].accession.identifier == knockin_target.id assert knockin_target_gnomic.new[0].variant is None assert knockin_target_gnomic.new[0].type == 'reaction' assert knockin_target_gnomic.old is None cofactor_id_swaps = [("nad_c", "nadh_c"), ("nadp_c", "nadph_c")] swap_pairs = ([ model.metabolites.get_by_id(m) for m in cofactor_id_swaps[0] ], [model.metabolites.get_by_id(m) for m in cofactor_id_swaps[1]]) swap_target = ReactionCofactorSwapTarget("GAPD", swap_pairs) swap_target_gnomic = swap_target.to_gnomic() assert isinstance(swap_target_gnomic, Mutation) assert isinstance(swap_target_gnomic.old, FeatureTree) assert isinstance(swap_target_gnomic.old[0], Feature) assert swap_target_gnomic.old[0].accession.identifier == swap_target.id assert swap_target_gnomic.old[0].variant is None assert swap_target_gnomic.old[0].type == 'reaction' assert isinstance(swap_target_gnomic.new, FeatureTree) assert isinstance(swap_target_gnomic.new[0], Feature) assert swap_target_gnomic.new[ 0].accession.identifier == swap_target.id + swap_target.swap_str assert swap_target_gnomic.new[0].variant is None assert swap_target_gnomic.new[0].type == 'reaction'