#!/usr/bin/env bash
Fasta="$1"
Output="$2"
#ID_list="$3" causes script to fail when put in for "list.txt"
bioawk -c fastx 'BEGIN{while((getline k <"list.txt")>0)i[k]=1}{if(i[$name])print ">"$name"\n"$seq}' "$Fasta" | bioawk -c fastx '{ print $name, gc($seq) }' > "$Output"
This script allows me to designate an input fasta file and output a .txt file using command line parameters. It uses a list.txt file to designate specific fasta ID's. I have tried to make the list.txt a 3rd parameter (e.g. List=$3), however this causes the script to fail. Is it possible to make the bioawk command accept a list.txt file as parameter?
1 answer
I suggest you check the xargs command. What I will write below should work for awk, but never tried bioawk so it may be different in that case.
cat list.txt | xargs -i setenv tmp_var="{}" | bioawk -v env_var="$tmp_var" -c fastx 'BEGIN{while((getline k < env_var)>0)i[k]=1}{if(i[$name])print ">"$name"\n"$seq}' "$Fasta" | bioawk -c fastx '{ print $name, gc($seq) }' > "$Output"
It reads your list line by line, and for each line it defines an environmental variable $tmp_var that contains whatever was in list.txt. Then awk (and presumably bioawk) converts that shell environmental variable in a way that can be used like any other internal variable.
I use (t)csh, and instead of setenv you may need export in the command above if you are using bash.
Log in to answer this question.