Mercurial > repos > crs4 > edena
comparison edena_ovl_wrapper.py @ 2:b8c6a38530eb draft default tip
Support Edena v. 3.131028 (new <version_command>, official overlapping log file, covStats output file removed, -lph and -sph options instead of -peHorizon). Use $GALAXY_SLOTS instead of $EDENA
_SITE_OPTIONS. Directly call edena, remove edena_ovl_wrapper.py and edena_ass_wrapper.py . Discard stderr instead of redirecting to stdout. Do not redirect stdout to logfile. Add readme.rst .
| author | crs4 |
|---|---|
| date | Fri, 31 Jan 2014 12:08:21 -0500 |
| parents | cd6cc6d76708 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:cd6cc6d76708 | 2:b8c6a38530eb |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 """ | |
| 3 Edena (overlapping) | |
| 4 version 0.2.1 (andrea.pinna@crs4.it) | |
| 5 """ | |
| 6 | |
| 7 import optparse | |
| 8 import shutil | |
| 9 import subprocess | |
| 10 import sys | |
| 11 | |
| 12 def __main__(): | |
| 13 # load arguments | |
| 14 print 'Parsing Edena (overlapping) input options...' | |
| 15 parser = optparse.OptionParser() | |
| 16 parser.add_option('--unpaired_input', action='append', dest='unpaired_input', help='') | |
| 17 parser.add_option('--dr_pair_1', action='append', dest='dr_pair_1', help='') | |
| 18 parser.add_option('--dr_pair_2', action='append', dest='dr_pair_2', help='') | |
| 19 parser.add_option('--rd_pair_1', action='append', dest='rd_pair_1', help='') | |
| 20 parser.add_option('--rd_pair_2', action='append', dest='rd_pair_2', help='') | |
| 21 parser.add_option('--nThreads', dest='nThreads', type='int', help='') | |
| 22 parser.add_option('--minOlap', dest='minOlap', type='int', help='') | |
| 23 parser.add_option('--readsTruncation', dest='readsTruncation', type='int', help='') | |
| 24 parser.add_option('--output', dest='output', help='') | |
| 25 parser.add_option('--logfile', dest='logfile', help='') | |
| 26 (options, args) = parser.parse_args() | |
| 27 if len(args) > 0: | |
| 28 parser.error('Wrong number of arguments') | |
| 29 | |
| 30 # build Edena (overlapping) command to be executed | |
| 31 # unpaired input(s) | |
| 32 if options.unpaired_input: | |
| 33 unpaired_input = '-r' | |
| 34 for item in options.unpaired_input: | |
| 35 unpaired_input += ' %s' % (item) | |
| 36 else: | |
| 37 unpaired_input = '' | |
| 38 # direct-reverse paired-end files | |
| 39 if options.dr_pair_1 and options.dr_pair_2: | |
| 40 dr_pairs = '-DRpairs' | |
| 41 for i in range(len(options.dr_pair_1)): | |
| 42 dr_pairs += ' %s %s' % (options.dr_pair_1[i], options.dr_pair_2[i]) | |
| 43 else: | |
| 44 dr_pairs = '' | |
| 45 # reverse-direct paired-end files | |
| 46 if options.rd_pair_1 and options.rd_pair_2: | |
| 47 rd_pairs = '-RDpairs' | |
| 48 for i in range(len(options.rd_pair_1)): | |
| 49 rd_pairs += ' %s %s' % (options.rd_pair_1[i], options.rd_pair_2[i]) | |
| 50 else: | |
| 51 rd_pairs = '' | |
| 52 # nThreads | |
| 53 nThreads = '-nThreads %d' % (options.nThreads) if options.nThreads is not None else '' | |
| 54 # minimum overlap | |
| 55 minOlap = '-M %d' % (options.minOlap) if options.minOlap is not None else '' | |
| 56 # 3' end reads truncation | |
| 57 readsTruncation = '-t %d' % (options.readsTruncation) if options.readsTruncation is not None else '' | |
| 58 # output file(s) | |
| 59 output = options.output | |
| 60 logfile = options.logfile | |
| 61 | |
| 62 # Build Edena (overlapping) command | |
| 63 cmd = 'edena %s %s %s %s %s %s -p galaxy_output' % (unpaired_input, dr_pairs, rd_pairs, nThreads, minOlap, readsTruncation) | |
| 64 print '\nEdena (overlapping) command to be executed:\n %s' % (cmd) | |
| 65 | |
| 66 # Execution of Edena | |
| 67 print 'Executing Edena (overlapping)...' | |
| 68 log = open(logfile, 'w') if logfile else sys.stdout | |
| 69 try: | |
| 70 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...") | |
| 71 finally: | |
| 72 if log != sys.stdout: | |
| 73 log.close() | |
| 74 print 'Edena (overlapping) executed!' | |
| 75 | |
| 76 shutil.move('galaxy_output.ovl', output) | |
| 77 | |
| 78 | |
| 79 if __name__ == "__main__": | |
| 80 __main__() |
