No, pysam cannot get the mates when the mate is unmapped read.
The reason for this is that in order to fetch the mate, it must know where the mate is in the BAM file. It does this using the index file. The a bam index tells the parser the position of the reads mapping to each part of each chromosome start in the BAM file as a number of bytes from the start of the file.
As an unmapped read doesn't have a position, the parser cannot find offset to look for it at. In theory the BAM specification could specify that unmapped in a contig, and give its position in the index. Unfortunately it doesn't.
please advice.
I think you should check your data to ensure that you do have the mate in the BAM file.
And only then troubleshoot the code. Make sure that
MG01HX01:920:H3YVTCCX2:8:1223:25530:16850can be found twice in the datanow check the flags etc.