Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def test_gnomic_integration_ReactionCofactorSwapTarget(self, model):

        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()
        expected = "reaction.GAPD(cofactors=nadp_c,nadph_c)"
        assert genotype_to_string(Genotype([swap_target_gnomic])) == expected
Ejemplo n.º 3
0
    def test_reaction_cofactor_swap_target(self, model):
        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)
        with model:
            swap_target.apply(model)
            assert model.metabolites.nad_c not in model.reactions.GAPD.metabolites
            assert model.metabolites.nadh_c not in model.reactions.GAPD.metabolites
            assert model.metabolites.nadp_c in model.reactions.GAPD.metabolites
            assert model.metabolites.nadph_c in model.reactions.GAPD.metabolites

        assert model.metabolites.nadp_c not in model.reactions.GAPD.metabolites
        assert model.metabolites.nadph_c not in model.reactions.GAPD.metabolites
        assert model.metabolites.nad_c in model.reactions.GAPD.metabolites
        assert model.metabolites.nadh_c in model.reactions.GAPD.metabolites

        swap_target = ReactionCofactorSwapTarget("GND", swap_pairs)
        with model:
            swap_target.apply(model)
            assert model.metabolites.nad_c in model.reactions.GND.metabolites
            assert model.metabolites.nadh_c in model.reactions.GND.metabolites
            assert model.metabolites.nadp_c not in model.reactions.GND.metabolites
            assert model.metabolites.nadph_c not in model.reactions.GND.metabolites

        assert model.metabolites.nadp_c in model.reactions.GND.metabolites
        assert model.metabolites.nadph_c in model.reactions.GND.metabolites
        assert model.metabolites.nad_c not in model.reactions.GND.metabolites
        assert model.metabolites.nadh_c not in model.reactions.GND.metabolites
Ejemplo n.º 4
0
    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])
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    def test_invalid_reaction_cofactor_swap_target(self, model):
        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_124", swap_pairs)

        with pytest.raises(KeyError):
            swap_target.apply(model)

        swap_target = ReactionCofactorSwapTarget("ACKr", swap_pairs)

        with pytest.raises(ValueError):
            swap_target.apply(model)
Ejemplo n.º 7
0
    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'