Entering edit mode
11 days ago
María José
▴
10
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
What results are you expecting?