I'm a bioinformatics student and new to bash and programming stuff. I want to calculate genome coverage.
This is my script. I switch the real parameter with xx
but I'm sure xx
s are not problematic. Other students already execute this script with no error.
filename=$1
reference=/xx
filebase=$(basename $filename .bam)
samtools view ${filename} -F 4 -q 30 -b > ${filebase}.f.bam
genomeCoverageBed -ibam -g ${filebase}.f.bam ${reference} > /mnt/ABC/projects/abc/def/${filebase}.cov
coverage=$(grep genome /mnt/ABC/projects/abc/def/${filebase}.cov | awk '{NUM+=$2*$3; DEN+=$3} END {print NUM/DEN}')
echo -e "${filename},${coverage}" >> coverages.txt
When I execute this script with
sh ./coverage.sh /mnt/XYZ/share/sdf_rawdata/hsa/mergedbams/ghj_merged_200203.hs37d5.cons.90perc.bam
it doesn't work and gives me: awk: cmd. line:1: fatal: division by zero attempted and unrecognized parameter:/mnt/XYZ/share/sdf_rawdata/hsa/mergedbams/ghj_merged_200203.hs37d5.cons.90perc.bam
error
and in the coverages.txt file it only has this line:
-e /mnt/NEOGENE2/share/compevo_rawdata/hsa/mergedbams/Ash128_all.merged.hs37d5.fa.cons.90perc.bam
, nothing more.
Thanks for helping.