Skip to content

Commit 1af57f6

Browse files
authored
Merge pull request #28 from MuhammedHasan/master
Bug fixes for VCFSeqExtractor: #25 , #26 and compare ref with variant file.
2 parents f17215e + db0648c commit 1af57f6

4 files changed

Lines changed: 5 additions & 3 deletions

File tree

kipoiseq/extractors/vcf_seq.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def _region(self, interval):
3030
return '%s:%d-%d' % (interval.chrom, interval.start, interval.end)
3131

3232
def _has_variant(self, variant, sample_id):
33-
return variant.gt_types[self.sample_mapping[sample_id]] != 0
33+
gt_type = variant.gt_types[self.sample_mapping[sample_id]]
34+
return gt_type != 0 and gt_type != 2
3435

3536

3637
class IntervalSeqBuilder(list):
@@ -161,10 +162,10 @@ def _variant_to_sequence(self, variants):
161162
"""
162163
for v in variants:
163164
ref = Sequence(name=v.CHROM, seq=v.REF,
164-
start=v.POS, end=v.POS + len(v.REF))
165+
start=v.start, end=v.start + len(v.REF))
165166
# TO DO: consider alternative alleles.
166167
alt = Sequence(name=v.CHROM, seq=v.ALT[0],
167-
start=v.POS, end=v.POS + len(v.ALT[0]))
168+
start=v.start, end=v.start + len(v.ALT[0]))
168169
yield ref, alt
169170

170171
def _split_overlapping(self, variant_pairs, anchor):

tests/data/test.vcf.gz

5 Bytes
Binary file not shown.

tests/data/test.vcf.gz.tbi

0 Bytes
Binary file not shown.

tests/extractors/test_vcf_seq_extractor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_multi_sample_vcf_fetch_variant(multi_sample_vcf):
1818
interval = Interval('chr1', 3, 5)
1919
assert len(list(multi_sample_vcf.fetch_variants(interval))) == 2
2020
assert len(list(multi_sample_vcf.fetch_variants(interval, 'NA00003'))) == 1
21+
assert len(list(multi_sample_vcf.fetch_variants(interval, 'NA00001'))) == 0
2122

2223
interval = Interval('chr1', 7, 12)
2324
assert len(list(multi_sample_vcf.fetch_variants(interval))) == 0

0 commit comments

Comments
 (0)