Retrieve query start and end positions on reverse strand with Pysam
I'm using the pysam library to work with BAM files and extract the alignment positions of my target sequence. I've implemented a conditional logic to handle reverse strand alignments, but I'm not getting the expected results.
for read in bamfile.fetch():
print("ref_name:", read.reference_name)
print("ref_start:", read.reference_start)
print("ref_end:", read.reference_end)
if read.is_reverse:
query_start = len(read.seq) - read.query_alignment_end
query_end = len(read.seq) - read.query_alignment_start
else:
query_start = read.query_alignment_start
query_end = read.query_alignment_end
print("query_start:", query_start)
print("query_end:", query_end)
Reference Name: ref
Reference Start: 0
Reference End: 70
Query Start: 0
Query End: 70
Reference Name: ref
Reference Start: 70
Reference End: 101
Query Start: 0 x -> 70
Query End: 31 x -> 101
• 1,246 views
•
link
0 answers
No answers yet.
Log in to answer this question.
What results are you expecting?