Mercurial > repos > crs4 > edena
diff edena_ovl_wrapper.py @ 1:cd6cc6d76708 draft
Simplify passing repeated params to Python script.
Add more info to help sections.
author | crs4 |
---|---|
date | Fri, 18 Oct 2013 14:09:11 -0400 |
parents | 60609a9cef3b |
children |
line wrap: on
line diff
--- a/edena_ovl_wrapper.py Mon Sep 09 05:44:31 2013 -0400 +++ b/edena_ovl_wrapper.py Fri Oct 18 14:09:11 2013 -0400 @@ -13,11 +13,11 @@ # load arguments print 'Parsing Edena (overlapping) input options...' parser = optparse.OptionParser() - parser.add_option('--unpaired_input', dest='unpaired_input', help='') - parser.add_option('--dr_pair_1', dest='dr_pair_1', help='') - parser.add_option('--dr_pair_2', dest='dr_pair_2', help='') - parser.add_option('--rd_pair_1', dest='rd_pair_1', help='') - parser.add_option('--rd_pair_2', dest='rd_pair_2', help='') + parser.add_option('--unpaired_input', action='append', dest='unpaired_input', help='') + parser.add_option('--dr_pair_1', action='append', dest='dr_pair_1', help='') + parser.add_option('--dr_pair_2', action='append', dest='dr_pair_2', help='') + parser.add_option('--rd_pair_1', action='append', dest='rd_pair_1', help='') + parser.add_option('--rd_pair_2', action='append', dest='rd_pair_2', help='') parser.add_option('--nThreads', dest='nThreads', type='int', help='') parser.add_option('--minOlap', dest='minOlap', type='int', help='') parser.add_option('--readsTruncation', dest='readsTruncation', type='int', help='') @@ -26,71 +26,54 @@ (options, args) = parser.parse_args() if len(args) > 0: parser.error('Wrong number of arguments') - + # build Edena (overlapping) command to be executed # unpaired input(s) if options.unpaired_input: - unpaired_inputs = options.unpaired_input.split('+')[0:-1] unpaired_input = '-r' - for item in unpaired_inputs: + for item in options.unpaired_input: unpaired_input += ' %s' % (item) else: unpaired_input = '' # direct-reverse paired-end files if options.dr_pair_1 and options.dr_pair_2: - dr_pairs_1 = options.dr_pair_1.split('+')[0:-1] - dr_pairs_2 = options.dr_pair_2.split('+')[0:-1] dr_pairs = '-DRpairs' - for i in xrange(len(dr_pairs_1)): - dr_pairs += ' %s %s' % (dr_pairs_1[i], dr_pairs_2[i]) + for i in range(len(options.dr_pair_1)): + dr_pairs += ' %s %s' % (options.dr_pair_1[i], options.dr_pair_2[i]) else: dr_pairs = '' # reverse-direct paired-end files if options.rd_pair_1 and options.rd_pair_2: - rd_pairs_1 = options.rd_pair_1.split('+')[0:-1] - rd_pairs_2 = options.rd_pair_2.split('+')[0:-1] rd_pairs = '-RDpairs' - for i in xrange(len(rd_pairs_1)): - rd_pairs += ' %s %s' % (rd_pairs_1[i], rd_pairs_2[i]) + for i in range(len(options.rd_pair_1)): + rd_pairs += ' %s %s' % (options.rd_pair_1[i], options.rd_pair_2[i]) else: rd_pairs = '' # nThreads - if options.nThreads is not None: - nThreads = '-nThreads %d' % (options.nThreads) - else: - nThreads = '' + nThreads = '-nThreads %d' % (options.nThreads) if options.nThreads is not None else '' # minimum overlap - if options.minOlap is not None: - minOlap = '-M %d' % (options.minOlap) - else: - minOlap = '' + minOlap = '-M %d' % (options.minOlap) if options.minOlap is not None else '' # 3' end reads truncation - if options.readsTruncation is not None: - readsTruncation = '-t %d' % (options.readsTruncation) - else: - readsTruncation = '' + readsTruncation = '-t %d' % (options.readsTruncation) if options.readsTruncation is not None else '' # output file(s) output = options.output logfile = options.logfile - + # Build Edena (overlapping) command cmd = 'edena %s %s %s %s %s %s -p galaxy_output' % (unpaired_input, dr_pairs, rd_pairs, nThreads, minOlap, readsTruncation) - print '\nEdena (overlapping) command to be executed: \n %s' % ( cmd ) - + print '\nEdena (overlapping) command to be executed:\n %s' % (cmd) + # Execution of Edena print 'Executing Edena (overlapping)...' - if logfile: - log = open(logfile, 'w') - else: - log = sys.stdout + log = open(logfile, 'w') if logfile else sys.stdout try: subprocess.check_call(cmd, stdout=log, stderr=subprocess.STDOUT, shell=True) # need to redirect stderr because edena writes some logging info there (e.g. "Computing overlaps >=30...") finally: if log != sys.stdout: log.close() print 'Edena (overlapping) executed!' - - shutil.move( "galaxy_output.ovl", output) + + shutil.move('galaxy_output.ovl', output) if __name__ == "__main__":