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') }
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}'
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}'
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}'
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')) }
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"
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 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}'
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)"
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
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>'
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>'
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'
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'
def _repr_html_(self): return genotype_to_text(Genotype([self.to_gnomic()]))
def test_removed_fusions(): genotype = Genotype.parse('+A:B +B:C -B:C -C:D') assert genotype.removed_fusions == {Fusion(Feature('C'), Feature('D'))}
def to_gnomic(self): return Genotype([target.to_gnomic() for target in self.targets])
def test_added_plasmids(): genotype = Genotype.parse('+gene.B (pA) (pB) -(pB) -(pC)') assert genotype.added_plasmids == {Plasmid('pA')}
def test_removed_features(): genotype = Genotype.parse('+geneA -geneB +geneB -geneC') assert genotype.removed_features == {Feature('geneC')}
def __str__(self): return genotype_to_string(Genotype([self.to_gnomic()]))
def test_removed_fusion_features(): genotype = Genotype.parse('+geneA -geneB:geneC -geneA +{geneA, geneB}') assert genotype.removed_fusion_features == { Fusion(Feature('geneB'), Feature('geneC')) }
def test_added_fusions(): genotype = Genotype.parse('+A:B +B:C -B:C -C:D') assert genotype.added_fusions == {Fusion(Feature('A'), Feature('B'))}
def parse(string): return Genotype._parse_string(string, organisms=DEFAULT_ORGANISMS, types=DEFAULT_TYPES)
def test_removed_plasmids(): genotype = Genotype.parse('+gene.A (pA) (pB) -(pB) -(pC)') assert genotype.removed_plasmids == {Plasmid('pC')}
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
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