The confused result of samtools sort
2
0
Entering edit mode
5.7 years ago
younglin113 ▴ 60

Recently, I was doing an RNA-seq project, and I used spike-in control sequences in my experiment. So I mapped the reads to both human genome and spike-in sequences. And I successfully got the bam file, but when I tried to use the command samtools sort -o aa_sorted.bam aa.bam to sort the bam file according to the chromosome name, and got those confused order, here is the sorted bam file's header:

enter image description here

As you can see, The chromosomes marked with a red frame are placed in front of the chromosome 1. This result is really confusing. Can anyone help me here, thanks in advance.

rna-seq software error alignment • 2.6k views
ADD COMMENT
1
Entering edit mode
5.7 years ago

samtools sort doesn't change the order of the chromosomes, it just sorts the alignments according to them. There are many tools that require that the order of the chromosomes match between fasta and BAM files, so if you start playing around with that order you're likely to run into problems. Note that you CAN do this, but you'll need to do something like:

# make a new header with the chromosomes in the order you'd like
# name it "header"
cat header <(samtools view original_sorting.bam) | samtools sort -o desired_sorting.bam -
ADD COMMENT
0
Entering edit mode

Oh, so it is. Thanks a lot. So I just need to change the header and it can sort as I want it to, is that what you mean ?

ADD REPLY
0
Entering edit mode

Yes, but don't reheader the BAM file (this will completely screw things up), use something like I outlined where there's a SAM file produced and then piped into samtools sort.

ADD REPLY
1
Entering edit mode
5.7 years ago

Hello,

samtools sort sort the reads by position for each contig. It doesn't sort the contig itself, because this is usually not necessary.

The order of the contig names you see, is given by the order of the contigs in the reference file you specify during alignment.

fin swimmer

ADD COMMENT
0
Entering edit mode

Thanks a lot. It's really helped my doubts.

ADD REPLY

Login before adding your answer.

Traffic: 1495 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6