Average read depth from Samtools depth output - an issue with my awk command?

I am trying to replicate a command line script in galaxy where I have used awk to calculate the average read depth across a BAM file where depth at each position (including zero bases) has been calculated using samtools depth. My awk output is always empty but it works perfectly when performed in the command line. I have 2 questions:

  1. is there another way to calculate the average of column 3 from a samtools depth output in galaxy

OR

  1. Can anyone explain why I get no output from awk for this command when running it on the samtools depth output file or could anyone make any suggestions for how to fix it?

β€˜{sum+=$3; sumsq+=$3*$3} END { print "Average = ",sum/NR; print "Stdev = ",sqrt(sumsq/NR - (sum/NR)**2)}’

Thanks

Hi @Emma_Davies
Summary Statistics calculates average and stdev for any column, among other metrics. It also takes custom formulas.
Datamesh is another option.

Kind regards,
Igor

Thanks Igor, summary stats has worked perfectly.

@Emma_Davies
awk script: maybe replace β€œ; print” with β€œ,”
Hope that helps.
Kind regards,
Igor

1 Like