Skip to content

Commit

Permalink
Merge pull request #38 from TRON-Bioinformatics/bugfix-non-query-posi…
Browse files Browse the repository at this point in the history
…tion

Bugfix non query position
  • Loading branch information
priesgo authored Aug 15, 2022
2 parents dd39e22 + 1257834 commit 36eb7b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vafator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION='2.0.2'
VERSION='2.0.3'
14 changes: 10 additions & 4 deletions vafator/pileups.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def get_insertion_metrics(variant: Variant, pileups: IteratorColumnRegion) -> Co
# the read contains the insertion
ac[alt_upper] = ac[alt_upper] + 1
mq[alt_upper].append(pileup_read.alignment.mapping_quality)
pos[alt_upper].append(pileup_read.query_position)
pos[alt_upper].append(pileup_read.query_position_or_next)
elif pileup_read.indel == 0:
# NOTE: considers all reads without indels to be the reference!
mq[variant.REF].append(pileup_read.alignment.mapping_quality)
pos[variant.REF].append(pileup_read.query_position)
pos[variant.REF].append(pileup_read.query_position_or_next)

except StopIteration:
# no reads
Expand Down Expand Up @@ -122,22 +122,28 @@ def get_deletion_metrics(variant: Variant, pileups: IteratorColumnRegion) -> Cov
if pileup_read.indel < 0:
# read with a deletion
start = pileup_read.alignment.reference_start
match = False
for cigar_type, cigar_length in pileup_read.alignment.cigartuples:
if cigar_type in [0, 3, 7, 8]: # consumes reference M, N, =, X
start += cigar_length
elif cigar_type == 2: # D
if start == variant_position and cigar_length == deletion_length:
ac[alt_upper] = ac[alt_upper] + 1
mq[alt_upper].append(pileup_read.alignment.mapping_quality)
pos[alt_upper].append(pileup_read.query_position)
pos[alt_upper].append(pileup_read.query_position_or_next)
match = True
break
else:
start += cigar_length
if start > variant_position:
break
if not match:
# TODO: when finds a read with an indel not matching our particular indel it counts it
pass
elif pileup_read.indel == 0:
# NOTE: considers all reads without indels to be the reference!
mq[variant.REF].append(pileup_read.alignment.mapping_quality)
pos[variant.REF].append(pileup_read.query_position)
pos[variant.REF].append(pileup_read.query_position_or_next)
except StopIteration:
# no reads
pass
Expand Down

0 comments on commit 36eb7b2

Please sign in to comment.