You can easily access string arguments from the command line in sys.argv
. (For historical reasons, sys.argv[0]
contains the name of the script itself, so ignore that.)
import sys
value={"V": 3.1, "Y": 3.5, "W": 4.7, "T": 5.3, "S": 5.1,
"P": 3.7, "F": 4.7, "M": 1.5, "K": 8.9, "L": 6, "I": 4.3,
"H": 3.3, "G": 7.1, "E": 7, "Q": 5.4, "C": 0.6, "D": 7.6,
"N": 6, "R": 8.7, "A": 3.4}
for AA_seq in sys.argv[1:]:
print("Total length of sequence", AA_seq, "is:", len(AA_seq))
total = 0
for i in AA_seq:
total += value[i]
print(AA_seq, "Total Score is :", total)
You'll notice that I added a loop so you can process multiple sequences in a single run if you like.
Usage:
python3 script.py 'AVTLSPQRS' 'KIIGAPEAR'
(or just python
if that's the name of the Python 3 executable on your platform).
Accepting input from the command line enables you to use the various facilities of the shell (tab completion, history, variable expansion, etc) as well as use this script programmatically from other scripts.
A proper tool should probably include some error handling, too (basically check that there are arguments, and display an error if not) but this should already get you started. Also, perhaps trap KeyError
so you don't get a traceback if the input string contains symbols which are not in the value
hash.