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?
1 answer
It may be that the order of the alignments/reads and @SQ headers are different. I ran into a similar problem recently and used Picard's ReorderSam against a reference FASTA to get the @SQ headers and alignments/reads in the correct order.
EDIT: I found that ReorderSam did not work properly with SAM files but seemed OK with BAM files. When I tried outputting a SAM file it had stripped the RNAME values from the reads.
Log in to answer this question.
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)