Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix affected_start/end with a MNP #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ for the regions of interest::

Note that the start and end coordinates are in the zero-based, half-open
coordinate system, similar to ``_Record.start`` and ``_Record.end``. The very
first base of a chromosome is index 0, and the the region includes bases up
first base of a chromosome is index 0, and the region includes bases up
to, but not including the base at the end coordinate. For example::

>>> # fetch all records on chromosome 4 from base 11 through 20
Expand Down
16 changes: 11 additions & 5 deletions vcf/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ def __init__(self, CHROM, POS, ID, REF, ALT, QUAL, FILTER, INFO, FORMAT,


def _set_start_and_end(self):
self.affected_start = self.affected_end = self.POS
self.affected_start = self.affected_end = self.end
for alt in self.ALT:
if alt is None:
start, end = self._compute_coordinates_for_none_alt()
elif alt.type == 'SNV':
start, end = self._compute_coordinates_for_snp()
elif alt.type == 'MNV':
start, end = self._compute_coordinates_for_indel()
start, end = self._compute_coordinates_for_indel(alt)
else:
start, end = self._compute_coordinates_for_sv()
self.affected_start = min(self.affected_start, start)
Expand All @@ -235,10 +235,16 @@ def _compute_coordinates_for_snp(self):
return (start, end)


def _compute_coordinates_for_indel(self):
def _compute_coordinates_for_indel(self, alt):
if len(self.REF) > 1:
start = self.POS
end = start + (len(self.REF) - 1)
# get the number of leading bases that are shared between ref and alt
n = 0
for i in range(min(len(self.REF), len(alt.sequence))):
if self.REF[i] != alt.sequence[i]:
break;
n += 1
start = self.POS + n - 1
end = self.POS + (len(self.REF) - 1)
else:
start = end = self.POS
return (start, end)
Expand Down
19 changes: 19 additions & 0 deletions vcf/test/test_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,25 @@ def test_coordinates_for_breakend(self):
None
)
self.assert_has_expected_coordinates(record, (9, 12), (9, 12))


def test_coordinates_for_mnp(self):
record = model._Record(
'1',
10,
'id13',
'AAA',
[
model._Substitution('AAT')
],
None,
None,
{},
None,
{},
None
)
self.assert_has_expected_coordinates(record, (9, 12), (11, 12))


class TestCall(unittest.TestCase):
Expand Down