def test_added_features():
    genotype = Genotype.parse('+geneA -geneB +geneB -geneC')
    assert genotype.added_features == {Feature('geneA')}
    genotype = Genotype.parse('+{geneA, geneB:geneC}')
    assert genotype.added_features == {
        Feature('geneA'), Feature('geneB'),
        Feature('geneC')
    }
Exemplo n.º 2
0
def test_genotype_gnomic_format(gnomic_formatter):
    assert gnomic_formatter.format_genotype(Genotype.parse('+geneA -geneB site>feature')) \
        == '+geneA -geneB site>feature'
    assert gnomic_formatter.format_genotype(Genotype.parse('+geneA -geneB site>>feature')) \
        == '+geneA -geneB site>feature'
    assert gnomic_formatter.format_genotype(Genotype.parse('+geneA -geneB -geneA')) == '-geneB'
    assert gnomic_formatter.format_genotype(Genotype.parse('+{geneA, geneB} -{geneC, geneD}')) \
        == '+{geneA, geneB} -{geneC, geneD}'
Exemplo n.º 3
0
def test_genotype_gnomic_format(gnomic_formatter):
    assert gnomic_formatter.format_genotype(Genotype.parse('+geneA -geneB site>feature')) \
        == '+geneA -geneB site>feature'
    assert gnomic_formatter.format_genotype(Genotype.parse('+geneA -geneB site>>feature')) \
        == '+geneA -geneB site>feature'
    assert gnomic_formatter.format_genotype(
        Genotype.parse('+geneA -geneB -geneA')) == '-geneB'
    assert gnomic_formatter.format_genotype(Genotype.parse('+{geneA, geneB} -{geneC, geneD}')) \
        == '+{geneA, geneB} -{geneC, geneD}'
Exemplo n.º 4
0
def test_genotype_text_format(text_formatter):
    assert text_formatter.format_genotype(Genotype.parse('+geneA')) == 'geneA'
    assert text_formatter.format_genotype(Genotype.parse('-geneA')) == '\u0394geneA'
    assert text_formatter.format_genotype(Genotype.parse('siteA>(pA)')) == '\u0394siteA\u2192(pA)'
    assert text_formatter.format_genotype(Genotype.parse('foo>bar')) == '\u0394foo\u2192bar'
    assert text_formatter.format_genotype(Genotype.parse('foo>>bar')) == '\u0394foo\u2192bar'
    assert text_formatter.format_genotype(Genotype.parse('-(pA)')) == '\u0394(pA)'
    assert text_formatter.format_genotype(Genotype.parse('+geneA(x)')) == 'geneA(x)'
    assert text_formatter.format_genotype(Genotype.parse('+geneA(var1, var2)')) == 'geneA(var1; var2)'
    assert text_formatter.format_genotype(Genotype.parse('+{geneA, geneB}')) == '{geneA, geneB}'
Exemplo n.º 5
0
 def to_gnomic(self):
     if _gnomic_available_:
         return Genotype([target.to_gnomic() for target in self.targets])
     else:
         raise SystemError(
             "Gnomic is only compatible with python >= 3 (%i.%i)" %
             (sys.version_info.major, sys.version_info.minor))
def test_added_fusion_features():
    genotype = Genotype.parse(
        '+geneA -geneB:geneC +geneB:geneC +{geneA, geneB}')
    assert genotype.added_fusion_features == {
        Feature('geneA'),
        CompositeAnnotation(Feature('geneA'), Feature('geneB'))
    }
Exemplo n.º 7
0
    def test_gnomic_integration_FluxModulationTarget(self, model):
        # with pytest.raises(ValueError):
        #     FluxModulationTarget("test", 0, 0)  # TODO: this should really not be possible
        flux_modulation_target = FluxModulationTarget("test", 1, 0)
        flux_modulation_target_gnomic = flux_modulation_target.to_gnomic()
        assert genotype_to_string(Genotype([flux_modulation_target_gnomic
                                            ])) == "+flux.test(value=1)"

        flux_modulation_target = FluxModulationTarget("PGK",
                                                      0.5,
                                                      1,
                                                      accession_id="PGK",
                                                      accession_db="bigg")
        flux_modulation_target_gnomic = flux_modulation_target.to_gnomic()
        assert genotype_to_string(Genotype([
            flux_modulation_target_gnomic
        ])) == "+flux.PGK(value=0.5)#bigg:PGK"
Exemplo n.º 8
0
    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"
Exemplo n.º 9
0
def test_genotype_text_format(text_formatter):
    assert text_formatter.format_genotype(Genotype.parse('+geneA')) == 'geneA'
    assert text_formatter.format_genotype(
        Genotype.parse('-geneA')) == '\u0394geneA'
    assert text_formatter.format_genotype(
        Genotype.parse('siteA>(pA)')) == '\u0394siteA\u2192(pA)'
    assert text_formatter.format_genotype(
        Genotype.parse('foo>bar')) == '\u0394foo\u2192bar'
    assert text_formatter.format_genotype(
        Genotype.parse('foo>>bar')) == '\u0394foo\u2192bar'
    assert text_formatter.format_genotype(
        Genotype.parse('-(pA)')) == '\u0394(pA)'
    assert text_formatter.format_genotype(
        Genotype.parse('+geneA(x)')) == 'geneA(x)'
    assert text_formatter.format_genotype(
        Genotype.parse('+geneA(var1, var2)')) == 'geneA(var1; var2)'
    assert text_formatter.format_genotype(
        Genotype.parse('+{geneA, geneB}')) == '{geneA, geneB}'
Exemplo n.º 10
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()
        assert genotype_to_string(Genotype([
            swap_target_gnomic
        ])) == "+reaction.GAPD(nad_c=nadp_c;nadh_c=nadph_c)"
Exemplo n.º 11
0
    def test_gene_knockout_target(self, model):
        gene = "b4025"
        knockout_target = GeneKnockoutTarget(gene,
                                             accession_id=gene,
                                             accession_db='bigg')
        knockout_target_gnomic = knockout_target.to_gnomic()
        assert genotype_to_string(Genotype([knockout_target_gnomic
                                            ])) == "-b4025#bigg:b4025"
        with model:
            knockout_target.apply(model)
            assert model.reactions.PGI.lower_bound == 0
            assert model.reactions.PGI.upper_bound == 0
            assert abs(model.optimize().f - 0.8631) < 0.0001

        assert model.reactions.PGI.lower_bound == -1000
        assert model.reactions.PGI.upper_bound == 1000
Exemplo n.º 12
0
def test_genotype_html_format(html_formatter):
    assert html_formatter.format_genotype(Genotype.parse('+geneA')) == '<span class="gnomic-feature">geneA</span>'
    assert html_formatter.format_genotype(Genotype.parse('-geneB')) \
        == '\u0394<span class="gnomic-feature">geneB</span>'
    assert html_formatter.format_genotype(Genotype.parse('foo>>bar')) \
        == '\u0394<span class="gnomic-feature">foo</span>\u2192<span class="gnomic-feature">bar</span>'
    assert html_formatter.format_genotype(Genotype.parse('(pA)')) \
        == '<span class="gnomic-plasmid">(<span class="gnomic-plasmid-name">pA</span>)</span>'
    assert html_formatter.format_genotype(Genotype.parse('+geneA(x)')) \
        == '<span class="gnomic-feature">geneA<sup>x</sup></span>'
    assert html_formatter.format_genotype(Genotype.parse('+geneA(x; wild-type; mutant; y)')) \
        == '<span class="gnomic-feature">geneA<sup>x; wild-type; mutant; y</sup></span>'
    assert html_formatter.format_genotype(Genotype.parse('+foo:bar')) \
        == '<span class="gnomic-fusion"><span class="gnomic-feature">foo</span>:' \
           '<span class="gnomic-feature">bar</span></span>'
Exemplo n.º 13
0
def test_genotype_html_format(html_formatter):
    assert html_formatter.format_genotype(Genotype.parse(
        '+geneA')) == '<span class="gnomic-feature">geneA</span>'
    assert html_formatter.format_genotype(Genotype.parse('-geneB')) \
        == '\u0394<span class="gnomic-feature">geneB</span>'
    assert html_formatter.format_genotype(Genotype.parse('foo>>bar')) \
        == '\u0394<span class="gnomic-feature">foo</span>\u2192<span class="gnomic-feature">bar</span>'
    assert html_formatter.format_genotype(Genotype.parse('(pA)')) \
        == '<span class="gnomic-plasmid">(<span class="gnomic-plasmid-name">pA</span>)</span>'
    assert html_formatter.format_genotype(Genotype.parse('+geneA(x)')) \
        == '<span class="gnomic-feature">geneA<sup>x</sup></span>'
    assert html_formatter.format_genotype(Genotype.parse('+geneA(x; wild-type; mutant; y)')) \
        == '<span class="gnomic-feature">geneA<sup>x; wild-type; mutant; y</sup></span>'
    assert html_formatter.format_genotype(Genotype.parse('+foo:bar')) \
        == '<span class="gnomic-fusion"><span class="gnomic-feature">foo</span>:' \
           '<span class="gnomic-feature">bar</span></span>'
Exemplo n.º 14
0
def test_at_locus_gnomic_format(gnomic_formatter):
    assert gnomic_formatter.format_at_locus(AtLocus(Feature('foo'), Feature('bar'))) == 'foo@bar'
    assert gnomic_formatter.format_genotype(Genotype.parse('foo@bar>new')) == 'foo@bar>new'
Exemplo n.º 15
0
def test_at_locus_gnomic_format(gnomic_formatter):
    assert gnomic_formatter.format_at_locus(
        AtLocus(Feature('foo'), Feature('bar'))) == 'foo@bar'
    assert gnomic_formatter.format_genotype(
        Genotype.parse('foo@bar>new')) == 'foo@bar>new'
Exemplo n.º 16
0
 def _repr_html_(self):
     return genotype_to_text(Genotype([self.to_gnomic()]))
Exemplo n.º 17
0
def test_removed_fusions():
    genotype = Genotype.parse('+A:B +B:C -B:C -C:D')
    assert genotype.removed_fusions == {Fusion(Feature('C'), Feature('D'))}
Exemplo n.º 18
0
 def to_gnomic(self):
     return Genotype([target.to_gnomic() for target in self.targets])
Exemplo n.º 19
0
def test_added_plasmids():
    genotype = Genotype.parse('+gene.B (pA) (pB) -(pB) -(pC)')
    assert genotype.added_plasmids == {Plasmid('pA')}
Exemplo n.º 20
0
def test_removed_features():
    genotype = Genotype.parse('+geneA -geneB +geneB -geneC')
    assert genotype.removed_features == {Feature('geneC')}
Exemplo n.º 21
0
 def __str__(self):
     return genotype_to_string(Genotype([self.to_gnomic()]))
Exemplo n.º 22
0
def test_removed_fusion_features():
    genotype = Genotype.parse('+geneA -geneB:geneC -geneA +{geneA, geneB}')
    assert genotype.removed_fusion_features == {
        Fusion(Feature('geneB'), Feature('geneC'))
    }
Exemplo n.º 23
0
def test_added_fusions():
    genotype = Genotype.parse('+A:B +B:C -B:C -C:D')
    assert genotype.added_fusions == {Fusion(Feature('A'), Feature('B'))}
Exemplo n.º 24
0
def parse(string):
    return Genotype._parse_string(string,
                                  organisms=DEFAULT_ORGANISMS,
                                  types=DEFAULT_TYPES)
Exemplo n.º 25
0
def test_removed_plasmids():
    genotype = Genotype.parse('+gene.A (pA) (pB) -(pB) -(pC)')
    assert genotype.removed_plasmids == {Plasmid('pC')}
Exemplo n.º 26
0
def chain(*gnomic_strings, **kwargs):
    parent = kwargs.pop('parent', None)
    genotype = Genotype.parse(gnomic_strings[0], parent=parent, **kwargs)
    for gnomic_string in gnomic_strings[1:]:
        genotype = Genotype.parse(gnomic_string, parent=genotype, **kwargs)
    return genotype
Exemplo n.º 27
0
 def chain(self, *definitions, **kwargs):
     genotype = Genotype.parse(definitions[0], **kwargs)
     for definition in definitions[1:]:
         genotype = Genotype.parse(definition, parent=genotype, **kwargs)
     return genotype