How to use the kipoiseq.dataclasses.Variant.from_str function in kipoiseq

To help you get started, we’ve selected a few kipoiseq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kipoi / kipoiseq / tests / test_dataclasses.py View on Github external
assert isinstance(v.info, dict)
    assert len(v.info) == 0
    assert v.qual == 0
    assert v.filter == 'PASS'
    v.info['test'] = 10
    assert v.info['test'] == 10
    assert isinstance(str(v), str)

    # make sure the original got unchangd
    v2 = v.copy()
    v.info['test'] = 20
    assert v2.info['test'] == 10
    v.__repr__()

    # __str__, from_str
    assert v == Variant.from_str(str(v))

    # hash test
    assert isinstance(hash(v), int)
    assert hash(v) == hash(Variant.from_str(str(v)))

    # fixed arguments
    with pytest.raises(AttributeError):
        v.chrom = 'asd'
    with pytest.raises(AttributeError):
        v.pos = 10
    with pytest.raises(AttributeError):
        v.ref = 'asd'
    with pytest.raises(AttributeError):
        v.alt = 'asd'

    # non-fixed arguments
github kipoi / kipoiseq / tests / test_dataclasses.py View on Github external
v.info['test'] = 10
    assert v.info['test'] == 10
    assert isinstance(str(v), str)

    # make sure the original got unchangd
    v2 = v.copy()
    v.info['test'] = 20
    assert v2.info['test'] == 10
    v.__repr__()

    # __str__, from_str
    assert v == Variant.from_str(str(v))

    # hash test
    assert isinstance(hash(v), int)
    assert hash(v) == hash(Variant.from_str(str(v)))

    # fixed arguments
    with pytest.raises(AttributeError):
        v.chrom = 'asd'
    with pytest.raises(AttributeError):
        v.pos = 10
    with pytest.raises(AttributeError):
        v.ref = 'asd'
    with pytest.raises(AttributeError):
        v.alt = 'asd'

    # non-fixed arguments
    v.id = 'asd'
    v.qual = 10
    v.filter = 'asd'
    v.source = 2
github kipoi / kipoiseq / kipoiseq / extractors / vcf.py View on Github external
def get_variant(self, variant):
        """Returns variant from vcf file. Lets you use vcf file as dict.

        # Arguments:
            variant: variant object or variant id as string.

        # Returns
            Variant object.

        # Example
            ```python
              >>> MultiSampleVCF(vcf_path).get_variant("chr1:4:T:['C']")
            ```
        """
        if type(variant) == str:
            variant = Variant.from_str(variant)

        variants = self.fetch_variants(
            Interval(variant.chrom, variant.pos - 1, variant.pos))
        for v in variants:
            if v.ref == variant.ref and v.alt == variant.alt:
                return v
        raise KeyError('Variant %s not found in vcf file.' % str(variant))
github kipoi / kipoiseq / kipoiseq / extractors / vcf.py View on Github external
def get_variants(self, variants, regions=None, variant_gap=150):
        """Returns list of variants from vcf file. Lets you use vcf file as dict.

        # Arguments:
            variants: list of variants
            regions: list of regions to seek for variants.
              Automatically generated from variants if not given.
            strategy: strategy if there is not variant in region.

        # Returns
           List of variants
        """
        variants = [
            Variant.from_str(v) if type(v) == str else v
            for v in variants
        ]
        regions = regions or self._regions_from_variants(
            variants, variant_gap=variant_gap)
        variant_map = dict()

        for r in regions:
            r_variants = self.fetch_variants(r)
            for v in r_variants:
                variant_map[v] = v

        return [variant_map.get(v) for v in variants]