Skip to content

Commit 8d45f57

Browse files
committed
fix variant end
1 parent ade80c6 commit 8d45f57

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

kipoiseq/dataclasses.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ def start(self):
8585
"""
8686
return self.pos - 1
8787

88+
@property
89+
def end(self):
90+
"""1-based variant end position
91+
"""
92+
return self.start + len(self.ref)
93+
8894
@classmethod
8995
def from_cyvcf(cls, obj):
9096
if len(obj.ALT) > 1:

kipoiseq/extractors/vcf_matching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def variants_to_pyranges(variants: List[Variant]) -> PyRanges:
3030
(
3131
v.chrom,
3232
v.start,
33-
v.start + max(len(v.ref), len(v.alt)),
33+
v.end,
3434
v
3535
)
3636
for v in variants
@@ -200,7 +200,7 @@ def iter_rows(self):
200200
for _, row in df.iterrows():
201201
yield row
202202

203-
def __iter__(self):
203+
def __iter__(self) -> (Interval, Variant):
204204
"""
205205
Iterate interval and variant object.
206206
"""

tests/extractors/test_vcf_matching.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from kipoiseq.dataclasses import Interval, Variant
55
from kipoiseq.extractors.vcf import MultiSampleVCF
66
from kipoiseq.extractors.vcf_matching import variants_to_pyranges, \
7-
pyranges_to_intervals, intervals_to_pyranges, BaseVariantMatcher, \
7+
pyranges_to_intervals, intervals_to_pyranges, BaseVariantMatcher, \
88
SingleVariantMatcher, MultiVariantsMatcher
99

1010
intervals = [
@@ -112,27 +112,24 @@ def test_BaseVariantMatcher__read_intervals():
112112
def test_SingleVariantMatcher__iter__():
113113
inters = intervals + [Interval('chr1', 5, 50)]
114114

115-
matcher = SingleVariantMatcher(
116-
vcf_file, intervals=inters)
115+
matcher = SingleVariantMatcher(vcf_file, intervals=inters)
117116
pairs = list(matcher)
118117

119118
assert (inters[0], variants[0]) in pairs
120119
assert (inters[0], variants[1]) in pairs
121120
assert (inters[1], variants[2]) in pairs
122-
assert (inters[2], variants[1]) in pairs
123121
assert (inters[2], variants[2]) in pairs
124122

125-
assert len(pairs) == 5
123+
assert len(pairs) == 4
126124

127125
matcher = SingleVariantMatcher(vcf_file, pranges=pr)
128126
pairs = list(matcher)
129127

130128
assert (inters[0], variants[0]) in pairs
131129
assert (inters[0], variants[1]) in pairs
132130
assert (inters[1], variants[2]) in pairs
133-
assert (inters[2], variants[1]) in pairs
134131
assert (inters[2], variants[2]) in pairs
135-
assert len(pairs) == 5
132+
assert len(pairs) == 4
136133

137134

138135
def test_MultiVariantMatcher__iter__():

0 commit comments

Comments
 (0)