This is a test version of Biostars. For the public version, visit https://www.biostars.org.
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
python alignment pysam

but I'm not getting the expected results.

What results are you expecting?

0 answers

No answers yet.

Log in to answer this question.