I'm having a problem trying to use GATK on an alignment performed by BWA and sorted by Picard's SortSam. The error message I get is:
Alignments added out of order in SAMFileWriterImpl.addAlignment for s_1_gC2T.realign.bam. Sort order is coordinate. Offending records are at [Group4.3:96] and [Group4.3:85]
I've sorted the BAM file using Picard, as suggested by GATK's documentation. I've also checked that whether the BAM is "properly sorted" using three simple methods:
Inspect header: Marked as "SO:coordinate"
$ samtools view -H s.sort.bam | head -n 1
@HD VN:1.0 SO:coordinate
Indexed the BAM file: No errors, suggesting that it is sorted.
Simple visual inspection: Looks like it is sorted.
Here are the offending records:
seq_118999365 65 Group4.3 85 37 54M1D22M * 0 106 TTTTTGAGTGTTTTTTTTATGATTTTTTGATTTTTTTGGGGGGATTTTTTTTGGTTTTTTTTGGAATGGGGTTATA BBBCCB@CACBBCCBCCB@BB=BBBBBB>:BBBBBBC?ABBBB?BBBBBBBB<A?AABABB@594:B@;;>5A>@2
seq_46302040 73 Group4.3 87 37 52M1D24M * 0 87 TTTGAGTGTTTTTTTTATGATTTTTTGATTTTTTTGGGGGGATTTTTTTTGGTTTTTTTTGGAATGACGTTATATG BBB=?:=><><ABBA@69A>@@?@@@6=7':@@<?;<??;615==91<=:0599978(>?7533<###########
seq_185000411 147 Group4.3 96 29 52S9M1D7M2D7M1S * 0 12 TAACACAAAAAAAAAAAAAAAAAAAAAAAAAAATGAATAAAGTAAAAATAAATTTGTTTGTATTTTTTTTTTTTTT ############################################################################
I'm assuming that I'm missing something obvious here...any ideas?
You could try bamtools sort, and see if the problem persists.
That's what tried first and didn't work, so I used picard (as recommended in GATK pages)