How Can I Split Bam Into Chromosome (In A Loop) Using Samtools?
3
6
Entering edit mode
10.3 years ago
Hmm ▴ 500

i want to split my bam file into chromosome and then index it.

split bam chromosome • 16k views
ADD COMMENT
18
Entering edit mode
10.3 years ago
brentp 23k

Depending on your chromosomes, something like:

for chrom in `seq 1 22` X Y
do

    samtools view -bh $BAM chr${chrom} | samtools sort - chr${chrom}
    samtools index chr${chrom}.bam
done
ADD COMMENT
1
Entering edit mode

do we need to sort bam everytime we split it...or are we doing it to be on the safe side? Thanks for your response.

ADD REPLY
1
Entering edit mode

if your input bam is sorted, then you don't need to resort.

ADD REPLY
10
Entering edit mode
10.3 years ago

bamtools has a "split" command for exactly this purpose.

ADD COMMENT
0
Entering edit mode

Cool. I didn't know that. It's a bit sparse on docs

ADD REPLY
1
Entering edit mode
9.6 years ago
Dan ▴ 10

You can use this tool to do exactly that.

http://code.google.com/p/chrom-bed/

ADD COMMENT

Login before adding your answer.

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