I am trying to allow a user to enter in text and then store that text in a variable $gene
to run in an awk
command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :).
The awk
runs great if it is a pre-defined file that is used, but it could also be user input.
/home/cmccabe/Desktop/loop.sh: line 87: syntax error near unexpected token `for'
/home/cmccabe/Desktop/loop.sh: line 87: `for f in /home/cmccabe/Desktop/NGS/API/2-12-2015/bedtools/*base_counts.txt ; do'
other() {
printf "\n\n"
printf "Please enter the gene(s) of interest, use a comma between multiple: "; IFS="," read -a gene
printf "the indicated genes will now be loaded and used to calculate coverage\n"
[ -z "$gene" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
[ "$gene" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
for ((i=0; i<${#gene[@]}; i++))
logfile=/home/cmccabe/Desktop/NGS/API/2-12-2015/process.log
for f in /home/cmccabe/Desktop/NGS/API/2-12-2015/bedtools/*base_counts.txt ; do
echo "Start custom panel creation: $(date) - File: $f"
bname=$(basename $f)
pref=${bname%%.txt}
awk '
NR == FNR {input[$0]; next}
{
split($5, a, "-")
if (a[1] in input) {
key = $4 OFS $5
n[key]++
sum[key] += $7
}
}
END {
for (key in n)
printf "%s %.1f\n", key, sum[key]/n[key]
}
' /home/cmccabe/Desktop/panels/$gene $f | awk '{split($2,a,"-"); print a[1] "\t" $0}' | sort | cut -f2-> /home/cmccabe/Desktop/NGS/API/2-12-2015/bedtools/${pref}_genescoverage.bed
echo "End custom panel creation: $(date) - File: $f"
done >> "$logfile"
printf "coverage calculated and log created\n"
}