Hi,
We're working with an aligned BAM file and initially sorted it by read name, in order to bedtools bamtobed
could correctly associate mate information and avoid warning messages.
However, we noticed that not all alignments are being exported after this step. We found that running samtools fixmate after name sorting is recommended to properly fill in mate-pair information.
So, we implement the following code obtained from a forum to our data. However, even after this, bamtobed still seems unable to export the genomic coordinates of all alignments. It only exports warning messages.
samtools sort -@ 10 -n -o ./${file}_bwa_sorted_names_rep_18M.bam ./${file}_bwa_sorted_rep_18M.bam
samtools fixmate -@ 10 ./${file}_bwa_sorted_names_rep_18M.bam ./${file}_bwa_sorted_names_rep_18M_fixed.bam
samtools sort -@ 10 ${file}_bwa_sorted_names_rep_18M_fixed.bam -o ${file}_bwa_sorted_rep_18M_fixed.bam
bedtools bamtobed -bedpe -i ./${file}_bwa_sorted_rep_18M_fixed.bam > ${file}_bwa_sorted_names_rep_18M_paired_fixed.bed
WARNING: Query LH00587:112:22LM2WLT4:1:2392:34049:7079 is marked as paired, but its mate does not occur next to it in your BAM file. Skipping.