Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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))
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]