Question: Bioawk - using bash variables
0
gravatar for spiral01
13 months ago by
spiral01100
spiral01100 wrote:

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 • 458 views
ADD COMMENTlink modified 13 months ago by SMK1.9k • written 13 months ago by spiral01100
1
gravatar for SMK
13 months ago by
SMK1.9k
SMK1.9k wrote:

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
ADD COMMENTlink written 13 months ago by SMK1.9k

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

ADD REPLYlink written 13 months ago by spiral01100

Hi spiral01,

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

ADD REPLYlink modified 13 months ago • written 13 months ago by SMK1.9k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1329 users visited in the last hour