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_parse_fusion(parse): assert [Change(after=Fusion(Feature('foo'), Feature('bar'))) ] == parse('+foo:bar') assert [ Change(before=Fusion(Feature('foo'), Feature('bar')), after=Feature('foo')) ] == parse('foo:bar>foo')
def test_feature_html_format_escape_html(html_formatter): assert html_formatter.format_feature( Feature('geneB&')) == '<span class="gnomic-feature">geneB&</span>' assert html_formatter.format_feature( Feature('geneB<')) == '<span class="gnomic-feature">geneB<</span>' assert html_formatter.format_feature( Feature('geneB>')) == '<span class="gnomic-feature">geneB></span>'
def test_match_on_delete(state): state.change(Change(None, F.parse('species/gene.A'))) assert state.changes == ( Change(None, F.parse('species/gene.A')), ) state.change(Change(F.parse('gene.A'), None)) assert state.changes == ()
def test_change_presence(state): state.change(Present(F.parse('gene.foo(A)'))) assert state.changes == (Change(None, F.parse('gene.foo(A)')), ) state.change(Present(F.parse('gene.foo(B)'))) assert state.changes == (Change(None, F.parse('gene.foo(B)')), )
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 to_gnomic(self): accession = Target.to_gnomic(self) pairs = [(m.id for m in pair) for pair in self.swap_pairs] wt_feature = Feature(name=self.id, accession=accession, type='reaction', variant=["cofactors=%s" % ",".join(pairs[0])]) feature = Feature(name=self.id, accession=accession, type='reaction', variant=["cofactors=%s" % ",".join(pairs[1])]) return Change(before=wt_feature, after=feature)
def test_match_whole_fusion_on_delete_with_variant(state): state.change(+F.parse('gene.A')**F.parse('gene.B')) state.change(+F.parse('gene.C')) state.change(-F.parse('gene.A')**F.parse('gene.B(x)')) assert state.changes == ( +F.parse('gene.A')**F.parse('gene.B'), +F.parse('gene.C'), -F.parse('gene.A')**F.parse('gene.B(x)'), )
def test_replacement_replace_variant(state): state.change(Change(F('a'), F.parse('a(x)'))) assert state.changes == ( Change(F('a'), F.parse('a(x)')), ) state.change(Change(F('a'), F.parse('a(y)'))) assert state.changes == ( Change(F('a'), F.parse('a(y)')), )
def test_change_presence(state): state.change(Present(F.parse('gene.foo(A)'))) assert state.changes == ( Change(None, F.parse('gene.foo(A)')), ) state.change(Present(F.parse('gene.foo(B)'))) assert state.changes == ( Change(None, F.parse('gene.foo(B)')), )
def to_gnomic(self): accession = Target.to_gnomic(self) if self._value == 0: old_feature = Feature(name=self.id, accession=accession, type=self.__gnomic_feature_type__) new_feature = None elif self.fold_change != 0: old_feature = Feature(name=self.id, type=self.__gnomic_feature_type__, variant=tuple(["value={}".format(self._reference_value)])) new_feature = Feature(name=self.id, accession=accession, type=self.__gnomic_feature_type__, variant=tuple(["value={}".format(self._value)])) else: raise RuntimeError("fold_change shouldn't be 0") return Change(before=old_feature, after=new_feature)
def test_update_fusion_with_composite_annotation_in_replacement(state): state.change(+F.parse('gene.A')**F.parse('gene.B')) state.change( F.parse('gene.B') > CompositeAnnotation(F.parse('gene.C'), F.parse('gene.D'))) assert state.changes == (+F.parse('gene.A')**CompositeAnnotation( F.parse('gene.C'), F.parse('gene.D')), )
def test_sequence_variants_dna_repeated(parse): variants = [ 'g.123_124[14]', 'g.123_124[14];[18]', 'c.-128_-126[79]', 'c.-128_-126[(600_800)]', 'c.54GCA[21]', 'c.54GCA[21]ACA[1]GCC[2]' ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_dna_conversion(parse): variants = [ 'g.333_590con1844_2101', # other possibilities with reference to a file or a gene ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_protein_substitution(parse): variants = [ 'p.Trp24Cys', 'p.(Trp24Cys)', 'p.Trp24Ter', 'p.Trp24*', 'p.Cys188=', 'p.0', 'p.?', 'p.Met1?', 'p.(Tyr4*)' ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_protein_duplication(parse): variants = [ 'p.Ala3dup', 'p.(Ala3dup)', 'p.Ala3_Ser5dup', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_dna_deletions(parse): variants = [ 'g.19del', 'g.10_21del', 'c.183_186+48del', 'c.1234del', 'c.1234+1del', 'c.4072-1234_5155-246del', 'c.(?_-245)_(31+1_32-1)del', 'c.(?_-1)_(*1_?)del', 'g.19_21=/del', 'g.19_21del=//del' ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_dna_inversion(parse): variants = [ 'g.1234_1236inv', 'c.77_80inv', 'g.122_123ins123_234inv', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_dna_delins(parse): variants = [ 'g.6775delinsGA', 'g.6775_6777delinsC', 'g.9002_9009delinsTTT', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_integrate_plasmid_with_fusion(state): state.change( F('site') > Plasmid('pA', [F.parse('gene.A')**F.parse('gene.B')])) assert state.changes == (F('site') > Plasmid( 'pA', [F.parse('gene.A')**F.parse('gene.B')]), ) state.change(F.parse('gene.A')**F.parse('gene.B') > F.parse('gene.C')) assert state.changes == (F('site') > CompositeAnnotation( F.parse('gene.C')), )
def test_sequence_variants_protein_frameshift(parse): variants = [ 'p.Arg97ProfsTer23', 'p.Arg97fs', 'p.Ile327Argfs*?', 'p.Gln151Thrfs*9', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_protein_repeated(parse): variants = [ 'p.Ala2[10]', 'p.Ala2[10];[11]', 'p.Gln18[23]', 'p.(Gln18)[(70_80)]', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_protein_extension(parse): variants = [ 'p.Met1ext-5', 'p.Met1Valext-12', 'p.Ter110Clnext*17', 'p.(Ter315TyrextAsnLysGlyThrTer)', 'p.Ter327Argext*?', 'p.*327Argext*', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_parse_composite_annotation(parse): assert [ Change(after=CompositeAnnotation(Feature('geneA'), Feature('geneB'))) ] == parse('+{geneA, geneB}') assert [ Change(before=CompositeAnnotation(Feature('geneA'), Feature('geneB'))) ] == parse('-{geneA, geneB}') assert [ Change(before=Feature('geneX'), after=Fusion( CompositeAnnotation(Feature('geneA'), Feature('geneB')), Feature('geneX'))) ] == parse('geneX>{geneA, geneB}:geneX')
def test_sequence_variants_protein_insertion(parse): variants = [ 'p.His4_Gln5insAla', 'p.Lys2_Gly3insGlnSerLys', 'p.(Met3_His4insGlyTer)', 'p.Arg78_Gly79ins23', 'p.Cys28delinsTrpVal', 'p.Cys28_Lys29delinsTrp', 'p.(Pro578_Lys579delinsLeuTer)', 'p.[Ser44Arg;Trp46Arg]', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_dna_insertion(parse): variants = [ 'g.4426_4426insA', 'g.5756_5757insAGG', 'g.123_124insL1234.1:23_361', 'g.122_123ins123_234inv', # 'g.122_123ins213_234invinsAins123_211inv', 'g.122_123ins212_234inv123_199inv', 'c.(67_70)insG(p.Gly23fs)', 'g.123_124ins(100)', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_sequence_variants_dna_substitutions(parse): variants = [ 'g.123C>A', 'c.93+1G>T', 'c.79_80delinsTT', 'c.[12C>T;13C>G]', 'c.12G>H', 'c.123=', 'c.85=/T>C', 'c.85=//T>C', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_imply_locus_with_substitution(): assert chain('gene.A>promoter.X:gene.B', 'gene.C>promoter.X:gene.D', '[email protected]>promoter.Y').changes() == ( Change(Feature.parse('gene.C'), Fusion(Feature.parse('promoter.X'), Feature.parse('gene.D'))), Change(Feature.parse('gene.A'), Fusion(Feature.parse('promoter.Y'), Feature.parse('gene.B'))), )
def test_parse_feature(): assert Feature('foo') == Feature.parse('foo') assert Feature('foo', type='gene') == Feature.parse('gene.foo') assert Feature('foo', organism='organism') == Feature.parse('organism/foo') assert Feature('foo', accession=Accession('id', 'database')) == Feature.parse('foo#database:id') assert Feature('foo', accession=Accession('id123')) == Feature.parse('foo#id123') assert Feature('foo', type='gene', organism='organism', accession=Accession('id', 'database'), variant=tuple('variant')) == Feature.parse('organism/gene.foo#database:id(variant)')
def test_sequence_variants_dna_duplication(parse): variants = [ 'g.7dup', 'g.6_8dup', 'c.120_123+48dup', 'c.123dup', 'c.4072-1234_5146-246dup', 'c.(4071+1_4072-1)_(5145+1_5146-1)dup', 'c.(4071+1_4072-1)_(5145+1_5146-1)[3]', 'c.(?_-30)_(12+1_13-1)dup', 'c.(?_-1)_(*1_?)dup', ] assert parse('geneA({})'.format('; '.join(variants))) == Feature( 'geneA', variant=tuple(variants))
def test_replacement_of_variants(state): state.change(Change(F.parse('a(x)'), F('b'))) assert state.changes == (Change(F.parse('a(x)'), F('b')), ) state.change(Change(F.parse('a(y)'), F('b'))) assert state.changes == ( Change(F.parse('a(x)'), F('b')), Change(F.parse('a(y)'), F('b')), ) state.change(Change(F.parse('a(y)'), F('c'))) assert state.changes == ( Change(F.parse('a(x)'), F('b')), Change(F.parse('a(y)'), F('c')), )
def test_feature_gnomic_format(gnomic_formatter): assert gnomic_formatter.format_annotation(Feature(name='foo')) == 'foo' assert gnomic_formatter.format_annotation(Feature.parse('foo(f)')) == 'foo(f)' assert gnomic_formatter.format_annotation(Feature.parse('foo(f, g)')) == 'foo(f; g)' assert gnomic_formatter.format_annotation(Feature.parse('organism/type.gene#db:123(f, g)')) \ == 'organism/type.gene#db:123(f; g)' assert gnomic_formatter.format_annotation(Feature.parse('#db:123')) == '#db:123' assert gnomic_formatter.format_annotation(Feature.parse('gene#123')) == 'gene#123' assert gnomic_formatter.format_annotation(Feature.parse('foo(mutant; variant)')) == 'foo(mutant; variant)'
def test_feature_gnomic_format(gnomic_formatter): assert gnomic_formatter.format_annotation(Feature(name='foo')) == 'foo' assert gnomic_formatter.format_annotation( Feature.parse('foo(f)')) == 'foo(f)' assert gnomic_formatter.format_annotation( Feature.parse('foo(f, g)')) == 'foo(f; g)' assert gnomic_formatter.format_annotation(Feature.parse('organism/type.gene#db:123(f, g)')) \ == 'organism/type.gene#db:123(f; g)' assert gnomic_formatter.format_annotation( Feature.parse('#db:123')) == '#db:123' assert gnomic_formatter.format_annotation( Feature.parse('gene#123')) == 'gene#123' assert gnomic_formatter.format_annotation( Feature.parse('foo(mutant; variant)')) == 'foo(mutant; variant)'
def test_replacement_of_variants(state): state.change(Change(F.parse('a(x)'), F('b'))) assert state.changes == ( Change(F.parse('a(x)'), F('b')), ) state.change(Change(F.parse('a(y)'), F('b'))) assert state.changes == ( Change(F.parse('a(x)'), F('b')), Change(F.parse('a(y)'), F('b')), ) state.change(Change(F.parse('a(y)'), F('c'))) assert state.changes == ( Change(F.parse('a(x)'), F('b')), Change(F.parse('a(y)'), F('c')), )
def test_imply_locus_with_substitution(): assert chain('gene.A>promoter.X:gene.B', 'gene.C>promoter.X:gene.D', '[email protected]>promoter.Y').changes() == ( Change( Feature.parse('gene.C'), Fusion(Feature.parse('promoter.X'), Feature.parse('gene.D'))), Change( Feature.parse('gene.A'), Fusion(Feature.parse('promoter.Y'), Feature.parse('gene.B'))), )
def test_scenario_1c_disambiguate_site_using_repeat_site(state): state.change(Change(F.parse('gene.A'), F.parse('promoter.X') ** F.parse('gene.B'))) state.change(Change(F.parse('gene.C'), F.parse('promoter.X') ** F.parse('gene.D'))) state.change(Change(F.parse('gene.A'), F.parse('promoter.Y') ** F.parse('gene.B'))) assert state.changes == ( Change(F.parse('gene.C'), F.parse('promoter.X') ** F.parse('gene.D')), Change(F.parse('gene.A'), F.parse('promoter.Y') ** F.parse('gene.B')) )
def test_genotype_parse_plasmid_insertion(parse): assert [Change(after=Plasmid('foo'))] == parse('(foo)') assert [Change(after=Plasmid('foo', [Feature.parse('gene.A')]))] == parse('(foo gene.A)')
def to_gnomic(self): accession = Target.to_gnomic(self) feature = Feature(name=self.id, accession=accession) return Change(before=feature)
def to_gnomic(self): accession = Target.to_gnomic(self) feature = Feature(accession=accession, type='reaction', name=self.id) return Change(after=feature)
def test_scenario_2_change_at_unknown_locus(state): state.change(Change(F.parse('promoter.A') % F.parse('gene.foo'), F.parse('promoter.B'))) assert state.changes == ( Change(F.parse('promoter.A') % F.parse('gene.foo'), F.parse('promoter.B')), ) state.change(Change(None, F.parse('gene.foo'))) assert state.changes == ( Change(F.parse('promoter.A') % F.parse('gene.foo'), F.parse('promoter.B')), Change(None, F.parse('gene.foo')), ) state.change(Change(F.parse('promoter.B') % F.parse('gene.foo'), F.parse('promoter.A'))) assert state.changes == ( Change(None, F.parse('gene.foo')), )