Wednesday, March 11, 2009

9) UNIX Shell Script - automating the benbo script for more than one input file

This is a simple shell script used for running benbo for more than one input file.


Process Code

for i in xx*
do
./benbo.sh 1 $i > $i\_out.txt
done



Usage Notes:

1) To run the script assuming the code is saved in a file called benbo2.sh: ./benbo2.sh.

2) This script will run benbo.sh for more than one input file, however all the input files would have to include "xx" in their filenames.

3)The user may switch to the perl version of benbo by substituting ./benbo.sh to ./benbo.pl in the above code.

4) This script assumes that the index protein/nucleotide sequence is on the first line, the user may change "1" to another number in the above code if their index sequence is not located on the first line of their input file.

5) The output files will be generated on the same folder and named as "input file name"_out.txt


Code by: BenBen
Blog Post by: BenBen

1 comment:

  1. 1. #!/bin/bash on the first line will tell shell to feed all the script to bash, whereas #!/usr/bin/perl or wherever you keep the perl exe will tell shell to feed the script to perl. If the script is bash script, and you feed it to perl...
    2. The iteration construct for bash or shell script is as follows:
    for [variablename] in [list of stuff]
    do
    [script]
    done
    3. [list of stuff] can be an actual list, e.g. xx01, xx02, etc
    It can also be globbing of a filename expansion and substitution of the wildcard, e.g. xx* in your case, where it is a list of all files starting with xx in the current folder where the program was executed.
    It can also be variable substitution, assuming you have previously defined a variable, or you are feeding in $1 from the command line argument for example.
    It can also be command substitution, whereby the output of a shell command or a series of them, becomes the list of items.
    Shell treats spaces as the separator. Unfortunately, I don't know if there is a way of switching space as the separator. So if your output includes spaces, it has to be protected.

    ReplyDelete