Mercurial > repos > crs4 > glimmer
comparison extract_wrapper.py @ 0:9c8ffce71f7c draft default tip
Uploaded
| author | crs4 |
|---|---|
| date | Mon, 09 Sep 2013 12:16:17 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9c8ffce71f7c |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 """ | |
| 3 Glimmer --> extract | |
| 4 version 0.2 (andrea.pinna@crs4.it) | |
| 5 """ | |
| 6 | |
| 7 import optparse | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 def __main__(): | |
| 12 # load arguments | |
| 13 print 'Parsing Extract input options...' | |
| 14 parser = optparse.OptionParser() | |
| 15 parser.add_option('--exSequence', dest='sequence', help='') | |
| 16 parser.add_option('--exCoords', dest='coords', help='') | |
| 17 parser.add_option('--ex2Fields', action='store_true', dest='twofields', help='') | |
| 18 parser.add_option('--exDir', action='store_true', dest='dir', help='') | |
| 19 parser.add_option('--exMinLen', dest='minlen', type='int', help='') | |
| 20 parser.add_option('--exNoStart', action='store_true', dest='nostart', help='') | |
| 21 parser.add_option('--exNoStop', action='store_true', dest='nostop', help='') | |
| 22 parser.add_option('--exNoWrap', action='store_true', dest='nowrap', help='') | |
| 23 parser.add_option('--exOutput', dest='output', help='') | |
| 24 parser.add_option('--logfile', dest='logfile', help='') | |
| 25 (options, args) = parser.parse_args() | |
| 26 if len(args) > 0: | |
| 27 parser.error('Wrong number of arguments') | |
| 28 | |
| 29 # build Extract command to be executed | |
| 30 sequence = options.sequence | |
| 31 coords = options.coords | |
| 32 if options.twofields: | |
| 33 twofields = '--2_fields' | |
| 34 else: | |
| 35 twofields = '' | |
| 36 if options.dir: | |
| 37 direct = '--dir' | |
| 38 else: | |
| 39 direct = '' | |
| 40 if options.minlen is not None: | |
| 41 minlen = '--minlen %d' % (options.minlen) | |
| 42 else: | |
| 43 minlen = '' | |
| 44 if options.nostart: | |
| 45 nostart = '--nostart' | |
| 46 else: | |
| 47 nostart = '' | |
| 48 if options.nostop: | |
| 49 nostop = '--nostop' | |
| 50 else: | |
| 51 nostop = '' | |
| 52 if options.nowrap: | |
| 53 nowrap = '--nowrap' | |
| 54 else: | |
| 55 nowrap = '' | |
| 56 output = options.output | |
| 57 logfile = options.logfile | |
| 58 | |
| 59 # Build Extract command | |
| 60 cmd = 'extract %s %s %s %s %s %s %s %s > %s' % (twofields, direct, minlen, nostart, nostop, nowrap, sequence, coords, output) | |
| 61 print '\nExtract command to be executed: \n %s' % (cmd) | |
| 62 | |
| 63 print 'Executing Extract...' | |
| 64 if logfile: | |
| 65 log = open(logfile, 'w') | |
| 66 else: | |
| 67 log = sys.stdout | |
| 68 try: | |
| 69 subprocess.check_call(cmd, stdout=log, stderr=subprocess.STDOUT, shell=True) | |
| 70 finally: | |
| 71 if log != sys.stdout: | |
| 72 log.close() | |
| 73 print 'Extract executed!' | |
| 74 | |
| 75 | |
| 76 if __name__ == "__main__": | |
| 77 __main__() |
