Mercurial > repos > crs4 > glimmer
comparison long-orfs_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 --> long-orfs | |
| 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 Long-ORFs input options...' | |
| 14 parser = optparse.OptionParser() | |
| 15 parser.add_option('--loSequence', dest='sequence', help='') | |
| 16 parser.add_option('--loStartCodons', dest='start_codons', help='') | |
| 17 parser.add_option('--loEntropy', dest='entropy', help='') | |
| 18 parser.add_option('--loFixed', action='store_true', dest='fixed', help='') | |
| 19 parser.add_option('--loMinLen', dest='min_len', type='int', help='') | |
| 20 parser.add_option('--loIgnore', dest='ignore', help='') | |
| 21 parser.add_option('--loLinear', action='store_true', dest='linear', help='') | |
| 22 parser.add_option('--loLengthOpt', action='store_true', dest='length_opt', help='') | |
| 23 parser.add_option('--loNoHeader', action='store_true', dest='no_header', help='') | |
| 24 parser.add_option('--loMaxOverlap', dest='max_olap', type='int', help='') | |
| 25 parser.add_option('--loCutoff', dest='cutoff', type='float', help='') | |
| 26 parser.add_option('--loWithoutStops', action='store_true', dest='without_stops', help='') | |
| 27 parser.add_option('--loTransTable', dest='trans_table', type='int', help='') | |
| 28 parser.add_option('--loStopCodons', dest='stop_codons', help='') | |
| 29 parser.add_option('--loOutput', dest='output', help='') | |
| 30 parser.add_option('--logfile', dest='logfile', help='') | |
| 31 (options, args) = parser.parse_args() | |
| 32 if len(args) > 0: | |
| 33 parser.error('Wrong number of arguments') | |
| 34 | |
| 35 # build Long-ORFs command to be executed | |
| 36 sequence = options.sequence | |
| 37 if options.start_codons: | |
| 38 start_codons = '--start_codons %s' % (options.start_codons) | |
| 39 else: | |
| 40 start_codons = '' | |
| 41 if options.entropy: | |
| 42 entropy = '--entropy %s' % (options.entropy) | |
| 43 else: | |
| 44 entropy = '' | |
| 45 if options.fixed: | |
| 46 fixed = '--fixed' | |
| 47 else: | |
| 48 fixed = '' | |
| 49 if options.min_len is not None: | |
| 50 min_len = '--min_len %d' % (options.min_len) | |
| 51 else: | |
| 52 min_len = '' | |
| 53 if options.ignore: | |
| 54 ignore = '--ignore %s' % (options.ignore) | |
| 55 else: | |
| 56 ignore = '' | |
| 57 if options.linear: | |
| 58 linear = '--linear' | |
| 59 else: | |
| 60 linear = '' | |
| 61 if options.length_opt: | |
| 62 length_opt = '--length_opt' | |
| 63 else: | |
| 64 length_opt = '' | |
| 65 if options.no_header: | |
| 66 no_header = '--no_header' | |
| 67 else: | |
| 68 no_header = '' | |
| 69 if options.max_olap is not None: | |
| 70 max_olap = '--max_olap %d' % (options.max_olap) | |
| 71 else: | |
| 72 max_olap = '' | |
| 73 if options.cutoff is not None: | |
| 74 cutoff = '--cutoff %s' % (options.cutoff) | |
| 75 else: | |
| 76 cutoff = '' | |
| 77 if options.without_stops: | |
| 78 without_stops = '--without_stops' | |
| 79 else: | |
| 80 without_stops = '' | |
| 81 if options.trans_table is not None: | |
| 82 trans_table = '--trans_table %s' % (options.trans_table) | |
| 83 else: | |
| 84 trans_table = '' | |
| 85 if options.stop_codons: | |
| 86 stop_codons = '--stop_codons %s' % (options.stop_codons) | |
| 87 else: | |
| 88 stop_codons = '' | |
| 89 output = options.output | |
| 90 logfile = options.logfile | |
| 91 | |
| 92 # Build Long-ORFs command | |
| 93 cmd = 'long-orfs %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s' % (sequence, start_codons, entropy, fixed, min_len, ignore, linear, length_opt, no_header, max_olap, cutoff, without_stops, trans_table, stop_codons, output) | |
| 94 print '\nLong-ORFs command to be executed: \n %s' % (cmd) | |
| 95 | |
| 96 print 'Executing Long-ORFs...' | |
| 97 if logfile: | |
| 98 log = open(logfile, 'w') | |
| 99 else: | |
| 100 log = sys.stdout | |
| 101 try: | |
| 102 subprocess.check_call(cmd, stdout=log, stderr=subprocess.STDOUT, shell=True) | |
| 103 finally: | |
| 104 if log != sys.stdout: | |
| 105 log.close() | |
| 106 print 'Long-ORFs executed!' | |
| 107 | |
| 108 | |
| 109 if __name__ == "__main__": | |
| 110 __main__() |
