This is a test version of Biostars. For the public version, visit https://www.biostars.org.
sorted bam file

Hi,

I am trying to calculate the sequencing depth for sorted bam files made using bowtie. I am using:

samtools depth bowtie_sorted.bam |  awk '{sum+=$3} END { print "Average = ",sum/NR}'

I have many sorted bam files and I want to calculate the depth for all using one array job rather than calculating for all files individually. Can anyone help writing such an array? Thanks!

next-gen

Your thread is about calculating the depth of bam files. But your title is sorted bam file? Please select a more descriptive title, and use sensible tags.

1 answer

ls *.bam | parallel -j <NumberOfParallelJobs> "samtools flagstat {} > {.}.flagstat"

This gives a complete overview over the number of mapped/unmapped reads etc. Alternatively, index the files and use samtools idxstats followed by summing up the reads of all chromosomes.

I want to calculate the sequencing depth.

Log in to answer this question.