Split a sam file by chromosome
Hi! I'm trying to use PRISM program to detect CNVs and the input files have to be .SAM files for each chromosome, I have the .BAM file of each sample but I don't know it it is convenient to convert it to .SAM and the n split it or the contrary.
for file in *_chr.bam; do
filename=`echo $file | cut -d “.” -f 1`;
for chrom in `seq 1 22` X Y; do
samtools view -bh $file chr${chrom} > ${filename}_${chrom}.bam;
done;
done
• 1,072 views
•
link
1 answer
While some commands have changed over years this should still be useful: How Can I Split Bam Into Chromosome (In A Loop) Using Samtools?
Sounds like you know what you want and how to get there.
• 0 views
•
link
Log in to answer this question.
If you want SAM files the use: