annotate extract_wrapper.py @ 0:9c8ffce71f7c draft default tip

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