gravatar for ATpoint

3 hours ago by

Germany

## Convert SAM to BAM and index it:
samtools view -o out.bam in.sam
samtools index out.bam

## Extract chromsosome names:
samtools idxstats out.bam | cut -f1 | grep -v '*' > chr.names

## Split bam file with w while loop
while read p
  do
  samtools view -o out_${p}.bam out.bam ${p}
  done < chr.names

If you really want SAM instead of BAM files then use samtools view -ho out_${p}.sam out.bam ${p}.
Given you have the resources you can of course use something like GNU parallel instead of a loop to make it more efficient.

link

modified 3 hours ago

written
3 hours ago
by

ATpoint33k



Source link