How to get chrM chr1 ...chr22 chrX chrY order in my bam file
1
0
Entering edit mode
5.1 years ago
Ada • 0

Hi

I went BWA alignment and sorted my bam file when I was doing my WES analysis to find SNP and Indel, however, my bam file look like this: chr1 ... chr22 chrX chrY chrM, now I want get my bam file : chrM chr1 ...chr22 chrX chrY ,what should I do?

Thank you

snp bam gatk picard sort • 2.4k views
ADD COMMENT
1
Entering edit mode

I think you should go for variant calling and then sort the resulted vcf file as per your liking..!!

ADD REPLY
1
Entering edit mode

Why would you do that? Which larger problem are you trying to solve by changing the order of chromosomes in your bam file?

ADD REPLY
0
Entering edit mode

I need to do variant calling with GATK and GATK may give incorrect results if the order of my bam file is chr1 ... chr22 chrX chrY chrM

ADD REPLY
2
Entering edit mode

No it wouldn't. What makes you think that?

ADD REPLY
0
Entering edit mode

cause I found that someone else had a bam file with the order of chrM, chr1, chr2, ... ,chrX, chrY and he mentioned it's very important. I will check it again and find the original information about the order of bam files.

ADD REPLY
0
Entering edit mode

I found it. These are defined by historical karotyping of largest to smallest chromosomes, followed by the X, Y, and MT for the b3x references; the order is thus 1, 2, 3, ..., 10, 11, 12, ... 20, 21, 22, X, Y, MT. The hg1x references differ in that the chromosome names are prefixed with "chr" and chrM appears first instead of last hg

ADD REPLY
1
Entering edit mode
5.1 years ago
jkbonfield ★ 1.3k

I don't agree that it is necessary to have your chromosome names in any particular order, but if you absolutely must do this the only way I can think of it is convert to SAM format (not BAM), replace the header with a reordered one, convert back to BAM again and re-sort to get the alignments in the same order as the header. Some of these steps can be amalgamated. You cannot replace the header while in BAM format as internally BAM stored chromosome by the Nth SQ number in the header, thus it would simply migrate alignments to the wrong chromosomes.

That's all very messy, and IMO pointless, but something like this (untested) ought to work:

(cat new_header; samtools view in.bam) | samtools sort -o out.bam -
ADD COMMENT
0
Entering edit mode

Thanks a lot, I'll give it a shot.

ADD REPLY

Login before adding your answer.

Traffic: 1553 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