Altering bioawk script to take list.txt file as a command line parameter
1
0
Entering edit mode
3.7 years ago
dk0319 ▴ 70
#!/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?

bash shell-script • 900 views
ADD COMMENT
0
Entering edit mode
3.7 years ago
Mensur Dlakic ★ 28k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 1723 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6