|
From: John M. <jm...@sa...> - 2013-08-23 13:35:32
|
On 23 Aug 2013, at 02:05, Henrik Bengtsson wrote:
> 'samtools index' gives me the following error:
>
> [bam_index_core] the alignment is not sorted: reads without
> coordinates prior to reads with coordinates.
> [bam_index_build2] fail to index the BAM file.
The samtools index command expects the input file to be coordinate sorted, with mapped reads (and unmapped reads filled in with their mapped mate's positions) for each of the chromosomes in @SQ header order followed by a final group of unmapped reads with * 0 for their RNAME/POS fields. This message means that a read with a position was encountered after an unmapped * 0 read, presumably towards the end of the BAM file.
> if the BAM file was 'samtools sort':ed using samtools v0.1.19, but not
> samtools v0.1.18.
There were a number of changes to samtools sort between 0.1.18 and 0.1.19, but none that would obviously produce a problem like this.
You could apply the patch below and rerun indexing to find the particular read that samtools is complaining about. It would be interesting to see the reads with that QNAME, and also useful if you could show us the dozen or so alignment records around the end of the last chromosome (9) and the start of the unmapped reads in foo.sort.samtools0_1_19.bam.
Cheers,
John
--- a/bam_index.c
+++ b/bam_index.c
@@ -241,7 +241,7 @@ bam_index_t *bam_index_core(bamFile fp)
while ((ret = bam_read1(fp, b)) >= 0) {
++n_no_coor;
if (c->tid >= 0 && n_no_coor) {
- fprintf(stderr, "[bam_index_core] the alignment is not sorted: reads without coordinates prior to reads with coordinates.\n");
+ fprintf(stderr, "[bam_index_core] the alignment is not sorted (%s): reads without coordinates prior to reads with coordinates.\n", bam1_qname(b));
return NULL;
}
}
--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.
|