Pagine

lunedì 24 ottobre 2011

What is an argument???


Before understanding what an argument was, I spent a lot of time!
Now I try to explain it in a less nerdy as possible.


When you run a script, the goal is, given the input, compute the output.
The input may be passed as argument, from command line instead of directly inside the script.
For example, suppose you have a script that take as input a DNA sequence and convert it in RNA. Such string of character is passed as follow:


python script.py ATCTAGTGTCTGATCCTAGTCTTGATC


the string is an argument.


As well as input, you can pass as arguments also the script parameters.
For example, if you have a script that, given a protein sequence, count the frequency of a certain amino acid, you have:


python script.py PPLMAAIEKSNISAWWNF S


Where the first argument is the protein sequence, and the second argument is the character that you want to count (Serine in this case). 
By this you obtain a more general script, that is useful to count any amino acid in any sequence.
You can apply the same criteria for both python and bach scripts.
Within the script you will find the functions suitable to recognize and to read the arguments.


With python first you have to import the sys module; the sintax is the follow:
import sys
ARGUMENT1=sys.argv[1]
ARGUMENTO2=sys.argv[2]


With bash:
ARGUMENT1=$1
ARGUMENT2=$2


By this, the variables ARGUMENT1 and ARGUMENT2 are the "object" that you passed from command line.



Nessun commento:

Posta un commento