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_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'))
Пример #3
0
def change_annotation(annotation, site=None, replacement=None):
    """
    Apply a change to an annotation.

    - If ``site`` is specified, looks for ``site`` and replaces with ``replacement``.
    - If ``site`` is not specified, create a :class:`CompositeAnnotation` of ``annotation`` and ``replacement``.
    """
    if not (site or replacement):
        raise ValueError()

    if site:
        if isinstance(annotation, (Fusion, CompositeAnnotation, Plasmid)):
            if not annotation.contains(site):
                if replacement:
                    return CompositeAnnotation(annotation, replacement)
                return annotation
            elif isinstance(annotation, (CompositeAnnotation, Plasmid)) \
                    or isinstance(site, (Feature, CompositeAnnotation)):
                if replacement is None:
                    annotations = tuple(b for b in annotation if b != site)
                else:
                    annotations = tuple(replacement if b == site else b
                                        for b in annotation
                                        if b != replacement)

                if isinstance(annotation, Fusion):
                    return Fusion.fuse(annotations)
                return CompositeAnnotation(*annotations)
            elif isinstance(site, Fusion):
                before_index = annotation.index(site)
                upstream = annotation.annotations[:before_index]
                downstream = annotation.annotations[before_index + len(site):]

                if replacement is None:
                    return Fusion.fuse(upstream + downstream)
                else:
                    return Fusion.fuse(upstream + (replacement, ) + downstream)
            else:
                raise NotImplementedError()
        elif isinstance(annotation, Feature):
            if annotation == site:
                return replacement
            elif replacement:
                return CompositeAnnotation(annotation, replacement)
            return annotation
        else:
            raise NotImplementedError()

    elif isinstance(annotation, (Feature, Fusion)):
        return CompositeAnnotation(annotation, replacement)
    elif isinstance(annotation, (CompositeAnnotation, Plasmid)):
        if any(a == replacement for a in annotation):  # ignore duplicates
            return annotation
        return CompositeAnnotation(annotation, replacement)
    else:
        raise NotImplementedError()
Пример #4
0
def change_annotation(annotation, site=None, replacement=None):
    """
    Apply a change to an annotation.

    - If ``site`` is specified, looks for ``site`` and replaces with ``replacement``.
    - If ``site`` is not specified, create a :class:`CompositeAnnotation` of ``annotation`` and ``replacement``.
    """
    if not (site or replacement):
        raise ValueError()

    if site:
        if isinstance(annotation, (Fusion, CompositeAnnotation, Plasmid)):
            if not annotation.contains(site):
                if replacement:
                    return CompositeAnnotation(annotation, replacement)
                return annotation
            elif isinstance(annotation, (CompositeAnnotation, Plasmid)) \
                    or isinstance(site, (Feature, CompositeAnnotation)):
                if replacement is None:
                    annotations = tuple(b for b in annotation if b != site)
                else:
                    annotations = tuple(replacement if b == site else b for b in annotation if b != replacement)

                if isinstance(annotation, Fusion):
                    return Fusion.fuse(annotations)
                return CompositeAnnotation(*annotations)
            elif isinstance(site, Fusion):
                before_index = annotation.index(site)
                upstream = annotation.annotations[:before_index]
                downstream = annotation.annotations[before_index + len(site):]

                if replacement is None:
                    return Fusion.fuse(upstream + downstream)
                else:
                    return Fusion.fuse(upstream + (replacement,) + downstream)
            else:
                raise NotImplementedError()
        elif isinstance(annotation, Feature):
            if annotation == site:
                return replacement
            elif replacement:
                return CompositeAnnotation(annotation, replacement)
            return annotation
        else:
            raise NotImplementedError()

    elif isinstance(annotation, (Feature, Fusion)):
        return CompositeAnnotation(annotation, replacement)
    elif isinstance(annotation, (CompositeAnnotation, Plasmid)):
        if any(a == replacement for a in annotation):  # ignore duplicates
            return annotation
        return CompositeAnnotation(annotation, replacement)
    else:
        raise NotImplementedError()
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'))),
                 )
Пример #6
0
def test_fusion_contains():
    assert Fusion(F('a'), F('b'), F('c'), F('d')).contains(
        Fusion(F('b'), F('c'))) is True
    assert Fusion(F('a'), F('b'), F('c'), F('d')).contains(
        Fusion(F('a'), F('c'))) is False
    assert Fusion(F('a'), F('b'), F('c'), F('d')).contains(F('a')) is True
    assert Fusion(F('a'), F('b'), F('c'), F('d')).contains(F('x')) is False
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')
Пример #8
0
def test_fusion_gnomic_format(gnomic_formatter):
    assert gnomic_formatter.format_fusion(
        Fusion(Feature('foo'), Feature('bar'))) == 'foo:bar'
    assert gnomic_formatter.format_fusion(
        Fusion(Feature('foo'), Feature('bar'), Plasmid('p'))) == 'foo:bar:(p)'
Пример #9
0
 def FEATURE_FUSION(self, ast):
     return Fusion(*ast)
Пример #10
0
 def FUSION(self, ast):
     return Fusion(*ast)
def test_remove_fusion():
    assert Change(before=Fusion(Feature('a'), Feature(
        'b'))) == -Feature('a')**Feature('b')
def test_insert_fusion():
    assert Change(after=Fusion(Feature('a'), Feature(
        'b'))) == +Feature('a')**Feature('b')
def test_fusion():
    assert Fusion(Feature('a'), Feature('b')) == Feature('a')**Feature('b')
    assert Fusion(Feature('a'), Feature('b'),
                  Feature('c')) == Feature('a')**Feature('b')**Feature('c')
Пример #14
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'))
    }
Пример #15
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'))}
Пример #16
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'))}