def test_insertion_followed_by_deletion(state): state.change(Change(None, F('foo'))) assert state.changes == (Change(None, F('foo')), ) state.change(Change(F('foo'), None)) assert state.changes == ()
def test_change_that_cancels_out(state): state.change(Change(F('a'), F('b'))) assert state.changes == (Change(F('a'), F('b')), ) state.change(Change(F('b'), F('a'))) assert state.changes == ()
def test_standalone_change_at_replaced_locus(state): state.change(Change(F('a'), F('b'))) assert state.changes == (Change(F('a'), F('b')), ) state.change(Change(AtLocus(F('b'), F('a')), F('c'))) assert state.changes == (Change(F('a'), F('c')), )
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_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_replace_fusion(): assert Change( before=Feature('a'), after=Fusion( Feature('b'), Feature('c'))) == (Feature('a') > Feature('b')**Feature('c')) assert Change( before=Fusion(Feature('a'), Feature('b')), after=Feature('c')) == (Feature('a')**Feature('b') > Feature('c'))
def test_change_at_locus_when_before_is_at_locus(state): state.change(Change(F('a') % F('a'), F('b'))) assert state.changes == (Change(F('a'), F('b')), ) state.change(Change(F('c') % F('c'), None)) assert state.changes == ( Change(F('a'), F('b')), Change(F('c'), None), )
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_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_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 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 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_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_change_gnomic_format(gnomic_formatter): assert gnomic_formatter.format_change( Change(before=Feature('foo'))) == '-foo' assert gnomic_formatter.format_change( Change(after=Feature('foo'))) == '+foo' assert gnomic_formatter.format_change( Change(before=Feature('foo'), after=Feature('bar'))) == 'foo>bar' assert gnomic_formatter.format_change( Change(before=Feature('foo'), after=Feature('bar'), multiple=True)) == 'foo>>bar' assert gnomic_formatter.format_change( Change(after=Plasmid('foo'))) == '(foo)' assert gnomic_formatter.format_change( Change(before=Feature('foo'), after=Feature('foo', variant=['x']))) == 'foo(x)' assert gnomic_formatter.format_change( Change(before=Feature('foo', variant=['x']), after=Feature('foo', variant=['y']))) == 'foo(y)' assert gnomic_formatter.format_change( Change(before=AtLocus(Feature('foo', variant=['x']), Feature('f')), after=Feature('foo', variant=['y']))) == 'foo(x)@f>foo(y)'
def test_replacement_in_fusion_at_locus(state): state.change(Change(F('x'), F('a')**F('b'))) state.change(Change(F('y'), F('a')**F('b'))) assert state.changes == ( Change(F('x'), F('a')**F('b')), Change(F('y'), F('a')**F('b')), ) state.change(Change(F('b') % F('y'), F('b')**F('c'))) assert state.changes == ( Change(F('x'), F('a')**F('b')), Change(F('y'), F('a')**F('b')**F('c')), )
def change(self, change): # XXX consider not simplifying (foo@foo>... and -foo@foo) if there is a logical use # simplify change at locus where annotation and locus are the same (e.g. foo@foo>... or -foo@foo) if change.before and isinstance( change.before, AtLocus) and change.before.annotation == change.before.locus: change = Change(change.before.annotation, change.after, multiple=change.multiple) if change.before is None: # e.g. +gene.A self.insert(change.after, multiple=change.multiple) elif change.after is None: # e.g. -gene.A self.remove(change.before, multiple=change.multiple) else: # e.g. gene.A>gene.B assert change.before and change.after self.replace(change.before, change.after, multiple=change.multiple)
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')), )
def INSERTION(self, ast): return Change(after=ast.after)
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_replace_feature_at_locus(): assert Change( before=AtLocus(Feature('a'), Feature('site')), after=Feature('b')) == (Feature('a') % Feature('site') > Feature('b'))
def test_remove_feature_at_locus(): assert Change(before=AtLocus(Feature('foo'), Feature( 'site'))) == -Feature('foo') % Feature('site') with pytest.raises(ValueError): -Feature('foo') % Feature('a') % Feature('b')
def test_insert_fusion(): assert Change(after=Fusion(Feature('a'), Feature( 'b'))) == +Feature('a')**Feature('b')
def PHENE(self, ast): return Change(after=self.FEATURE(ast), multiple=True)
def CHANGE(self, ast): if isinstance(ast, Plasmid): return Change(after=ast) return ast
def DELETION(self, ast): return Change(before=ast.before)
def REPLACEMENT(self, ast): return Change(before=ast.before, after=ast.after, multiple=ast.op == '>>')
def test_remove_feature(): assert Change(before=Feature('foo')) == -Feature('foo')
def test_insert_feature(): assert Change(after=Feature('foo')) == +Feature('foo')
def test_remove_fusion(): assert Change(before=Fusion(Feature('a'), Feature( 'b'))) == -Feature('a')**Feature('b')