コード例 #1
0
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 == ()
コード例 #2
0
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 == ()
コード例 #3
0
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')), )
コード例 #4
0
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')
コード例 #5
0
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)')), )
コード例 #6
0
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'))
コード例 #7
0
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),
    )
コード例 #8
0
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'))),
                 )
コード例 #9
0
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')
コード例 #10
0
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')))
コード例 #11
0
    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)
コード例 #12
0
    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)
コード例 #13
0
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')),
    )
コード例 #14
0
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)'
コード例 #15
0
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')),
    )
コード例 #16
0
    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)
コード例 #17
0
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')), )
コード例 #18
0
 def INSERTION(self, ast):
     return Change(after=ast.after)
コード例 #19
0
 def to_gnomic(self):
     accession = Target.to_gnomic(self)
     feature = Feature(name=self.id, accession=accession)
     return Change(before=feature)
コード例 #20
0
 def to_gnomic(self):
     accession = Target.to_gnomic(self)
     feature = Feature(accession=accession, type='reaction', name=self.id)
     return Change(after=feature)
コード例 #21
0
def test_replace_feature_at_locus():
    assert Change(
        before=AtLocus(Feature('a'), Feature('site')),
        after=Feature('b')) == (Feature('a') % Feature('site') > Feature('b'))
コード例 #22
0
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')
コード例 #23
0
def test_insert_fusion():
    assert Change(after=Fusion(Feature('a'), Feature(
        'b'))) == +Feature('a')**Feature('b')
コード例 #24
0
 def PHENE(self, ast):
     return Change(after=self.FEATURE(ast), multiple=True)
コード例 #25
0
 def CHANGE(self, ast):
     if isinstance(ast, Plasmid):
         return Change(after=ast)
     return ast
コード例 #26
0
 def DELETION(self, ast):
     return Change(before=ast.before)
コード例 #27
0
 def REPLACEMENT(self, ast):
     return Change(before=ast.before,
                   after=ast.after,
                   multiple=ast.op == '>>')
コード例 #28
0
def test_remove_feature():
    assert Change(before=Feature('foo')) == -Feature('foo')
コード例 #29
0
def test_insert_feature():
    assert Change(after=Feature('foo')) == +Feature('foo')
コード例 #30
0
def test_remove_fusion():
    assert Change(before=Fusion(Feature('a'), Feature(
        'b'))) == -Feature('a')**Feature('b')