Skip to content

Commit

Permalink
Don't use external expr for arithmetic
Browse files Browse the repository at this point in the history
The external expr command exits with a non-zero exit status, if the
expression evaluates to zero. This is in conflict with the -e setting
of this script.

Bash can do arithmetic by itself with $(( and )) which doesn't have this
complexity, so use that instead.
  • Loading branch information
donald committed Sep 29, 2022
1 parent 88d7814 commit 71fd137
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Adapting_new_script_for_computing_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ execute() {
map=$(grep -Po '[0-9, /.]*% overall alignment rate' $id.mappingStats.txt | grep -Po '[0-9,/.]*')
mapFrac=$(printf "%.4f" $(echo $map / 100 | bc -l))
dedup=$(printf "%.4f" $(grep -Po 'Unknown Library.*' dedup/${id}_dedupMetric.txt | awk '{print $10}'))
filtered=$(expr $(samtools view -c dedup/${id}_dedup.bam) / 2)
fripReads=$(expr $(bedtools intersect -a dedup/${id}_dedup.bam -b dedup_peaks/${id}_peaks.narrowPeak -u -ubam | samtools view -c) / 2)
filtered=$(( $(samtools view -c dedup/${id}_dedup.bam) / 2 ))
fripReads=$(( $(bedtools intersect -a dedup/${id}_dedup.bam -b dedup_peaks/${id}_peaks.narrowPeak -u -ubam | samtools view -c) / 2 ))
FRiP=$(printf "%.4f" $(echo $fripReads / $filtered | bc -l))
peaks=$(expr $(wc -l <"dedup_peaks/${id}_peaks.narrowPeak") - 1)
peaks=$(( $(wc -l <"dedup_peaks/${id}_peaks.narrowPeak") - 1 ))
echo -e "$id\t$fragments\t$filtered\t$mapFrac\t$dedup\t$FRiP\t$peaks" >> cnt_gata_qc_metrics.txt

# Here I have no idea how to transfer this
Expand Down

0 comments on commit 71fd137

Please sign in to comment.