allpy
changeset 333:2e9cbe32a554
Command line parameters added
author | Andrei <aba@belozersky.msu.ru> |
---|---|
date | Wed, 12 Jan 2011 19:36:09 +0300 |
parents | 9bf144c25dbd |
children | d85ba73ab26b 20944c113ea3 |
files | test/usecase3.py |
diffstat | 1 files changed, 63 insertions(+), 3 deletions(-) [+] |
line diff
1.1 --- a/test/usecase3.py Fri Dec 17 16:36:00 2010 +0300 1.2 +++ b/test/usecase3.py Wed Jan 12 19:36:09 2011 +0300 1.3 @@ -1,7 +1,67 @@ 1.4 from allpy import protein 1.5 -alignment = protein.Alignment.from_fasta(open("aln.fasta")) 1.6 +import sys 1.7 +import optparse 1.8 + 1.9 +if len(sys.argv)==1: 1.10 + print("usercase3 shisfts left all letters in specified vertical block of input alignment") 1.11 + print("\n Use python usercase3.py -h for help") 1.12 + exit() 1.13 + 1.14 +parser = optparse.OptionParser() 1.15 + 1.16 +parser.add_option("-i", "--in-file", help="Input alignment in fasta format", dest="in_file") 1.17 +parser.add_option("-o", "--out-file", help="Output refined alignment in fasta format", dest="out_file", default='result.fasta') 1.18 +parser.add_option("-f", "--_from", help="First position of refining block", dest="_from") 1.19 +parser.add_option("-t", "--to", help="Last position of refining block", dest="to") 1.20 + 1.21 +options, args = parser.parse_args() 1.22 +in_file = options.in_file 1.23 +out_file = options.out_file 1.24 +_from = options._from 1.25 +to = options.to 1.26 + 1.27 + 1.28 +if in_file==None or _from==None or to==None: 1.29 + print("Missed command line parameters.") 1.30 + print("Use python usercase3.py -h for help") 1.31 + exit() 1.32 + 1.33 +try: 1.34 + f = open(in_file) 1.35 +except: 1.36 + print("File %s was not found" % in_file) 1.37 + exit() 1.38 + 1.39 +try: 1.40 + ifrom = int(_from) 1.41 + ito = int(to) 1.42 +except: 1.43 + print("Values -f %s and -t %s must be interer!" % (_from,to)) 1.44 + exit() 1.45 + 1.46 +alignment = protein.Alignment.from_fasta(open(in_file)) 1.47 + 1.48 +alignment.length = len(alignment.columns) 1.49 + 1.50 +if ito >= alignment.length: 1.51 + print("to must be smaller than alignment length!") 1.52 + exit() 1.53 + 1.54 +if ifrom >= ito : 1.55 + print("from must be greater than to!") 1.56 + exit() 1.57 + 1.58 + 1.59 +conservative = [] 1.60 +if ifrom > 1: 1.61 + conservative.append((0,int(_from))) 1.62 +if ito < alignment.length: 1.63 + conservative.append((ito,alignment.length-1)) 1.64 + 1.65 +print conservative 1.66 + 1.67 #conservative = [(10,20), (40,50)] 1.68 -conservative = [(0,6),(18,37)] 1.69 +#conservative = [(0,6),(18,37)] 1.70 1.71 def ranges_to_markup(ranges): 1.72 """Convert list of ranges to line of markup. 1.73 @@ -31,6 +91,6 @@ 1.74 blocks = markup_to_blocks(markup) 1.75 for block in blocks["-"]: 1.76 block.flush_left() 1.77 - alignment.to_fasta(open("output.fasta", "w")) 1.78 + alignment.to_fasta(open(out_file, "w")) 1.79 1.80 main()