This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bioawk - using bash variables

Hi, I am using bioawk to extract entries in a fasta file based on partial matches on IDs. Now normally I can use a bash variable in awk by assigning it using -v. However, when using bioawk, the variable does not seem to be stored as gene, and as such I get no matches. I have tested this using the actual ID name instead of the variable and it works, so it must be an issue with assigning the variable. What am I doing wrong?

for i in ${IDs[@]}; do cat humanGeneOrthologs.fa | bioawk -v gene="$i" -c fastx '$name ~ /gene/ \
{ print ">"$name"\n"$seq"\n"; }'; done
awk software error

1 answer

Hi spiral01,

Try changing /gene/ to gene in your awk code:

for i in ${IDs[@]}; do
  cat humanGeneOrthologs.fa \
    | bioawk -v gene="$i" -c fastx '$name ~ gene { print ">"$name"\n"$seq }'
done

Perfect. This works. Sorry but could explain why this change works? Thanks.

Hi spiral01,

When you use /gene/, (bio)awk understands it as a literal "gene", not the variable.

Log in to answer this question.