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

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

split bam chromosome • 20k views
ADD COMMENT
21
Entering edit mode
13.5 years ago
brentp 24k

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
12
Entering edit mode
13.5 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
12.8 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: 1992 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