Skip to content

Commit

Permalink
use query_position_or_next instead of query_position
Browse files Browse the repository at this point in the history
  • Loading branch information
priesgo committed Aug 15, 2022
1 parent dd39e22 commit 5e05302
Showing 1 changed file with 10 additions and 4 deletions.
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 5e05302

Please sign in to comment.