I'd like to find out the equally best alignments in the bam. I found all the secondary alignments were not taken into consideration on my Linux server. However, with the same script and dataset, the secondary alignments were counted in my MacBook. The version of the pysam and python are all same.
The scripts for test is given below:
import pysam
# Open the sorted BAM file
samfile = pysam.AlignmentFile("/Users/wangminxiao/Downloads/CS4_300.filtered.trimmed.sorted.bam", "rb")
# Initialize counter
secondary_counter = 0
# Iterate over all reads in the file
for read in samfile:
if read.is_secondary and read.qname == "HWI-D00524:206:C6DFGANXX:3:1105:2396:101222":
secondary_counter += 1
samfile.close()
# Print the number of secondary alignments
print(f"The number of secondary alignments: {secondary_counter}")