Skip to content

Fix error for insdel position calculation #13

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 23 additions & 3 deletions celltics/tools/vargroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_chr(self, append_chr=False):
:param append_chr: whether to prefix with 'chr'
:return: string of chromosome name
"""
if append_chr:
if append_chr and 'chr' not in self.chrom:
return 'chr{}'.format(self.chrom)
return self.chrom

Expand Down Expand Up @@ -281,7 +281,20 @@ def _get_indel_pos(self, variant_pos, read):
hardclipped = 0 if read.cigartuples[0][0] != 5 else read.cigartuples[0][1] # read location must be adjusted for
# number of hardclipped bases represented in cigar but not in read_seq https://www.biostars.org/p/119537/
iloc = variant_pos - read.reference_start + read.query_alignment_start - 1 + hardclipped
return iloc
rpos = 0
insertions = 0
deletions = 0
for cig in read.cigartuples: # adjust for insertions before variant
rpos += cig[1]
if cig[0] == 1: # insertion
insertions += cig[1]
rpos -= cig[1]
if cig[0] == 2: # deletion
deletions -= cig[1]
rpos += cig[1]
if rpos > iloc:
break
return iloc + insertions + deletions

def _build_existence_matrix(self, reads_existence, reads_coverage):
self.exists = False
Expand Down Expand Up @@ -386,7 +399,14 @@ def merge_records(variants, group_id, seq_dict=None):
shift = 0
for variant in sorted(variants, key=lambda var: int(var.POS)):
var_len = variant.end - variant.POS + 1
var_alt = [sub.sequence for sub in variant.ALT]
try:
var_alt = [sub.sequence for sub in variant.ALT]
except AttributeError as e:
msg = "\nError Merging Records: For use with this tool all variants are expected to have ALT sequences. " \
"In the case of deletions, the base before the deletion is expected " \
"as the ALT value."
e.args = (e.args[0] + msg,)
raise e
if variant.is_deletion:
del_length = variant.end - variant.POS
alt = alt[:shift + variant.POS - start] + "".join(var_alt) + \
Expand Down