Mercurial > repos > crs4 > edena
comparison edena_ovl_wrapper.py @ 0:60609a9cef3b draft
Uploaded
author | crs4 |
---|---|
date | Mon, 09 Sep 2013 05:44:31 -0400 |
parents | |
children | cd6cc6d76708 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:60609a9cef3b |
---|---|
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', dest='unpaired_input', help='') | |
17 parser.add_option('--dr_pair_1', dest='dr_pair_1', help='') | |
18 parser.add_option('--dr_pair_2', dest='dr_pair_2', help='') | |
19 parser.add_option('--rd_pair_1', dest='rd_pair_1', help='') | |
20 parser.add_option('--rd_pair_2', 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_inputs = options.unpaired_input.split('+')[0:-1] | |
34 unpaired_input = '-r' | |
35 for item in unpaired_inputs: | |
36 unpaired_input += ' %s' % (item) | |
37 else: | |
38 unpaired_input = '' | |
39 # direct-reverse paired-end files | |
40 if options.dr_pair_1 and options.dr_pair_2: | |
41 dr_pairs_1 = options.dr_pair_1.split('+')[0:-1] | |
42 dr_pairs_2 = options.dr_pair_2.split('+')[0:-1] | |
43 dr_pairs = '-DRpairs' | |
44 for i in xrange(len(dr_pairs_1)): | |
45 dr_pairs += ' %s %s' % (dr_pairs_1[i], dr_pairs_2[i]) | |
46 else: | |
47 dr_pairs = '' | |
48 # reverse-direct paired-end files | |
49 if options.rd_pair_1 and options.rd_pair_2: | |
50 rd_pairs_1 = options.rd_pair_1.split('+')[0:-1] | |
51 rd_pairs_2 = options.rd_pair_2.split('+')[0:-1] | |
52 rd_pairs = '-RDpairs' | |
53 for i in xrange(len(rd_pairs_1)): | |
54 rd_pairs += ' %s %s' % (rd_pairs_1[i], rd_pairs_2[i]) | |
55 else: | |
56 rd_pairs = '' | |
57 # nThreads | |
58 if options.nThreads is not None: | |
59 nThreads = '-nThreads %d' % (options.nThreads) | |
60 else: | |
61 nThreads = '' | |
62 # minimum overlap | |
63 if options.minOlap is not None: | |
64 minOlap = '-M %d' % (options.minOlap) | |
65 else: | |
66 minOlap = '' | |
67 # 3' end reads truncation | |
68 if options.readsTruncation is not None: | |
69 readsTruncation = '-t %d' % (options.readsTruncation) | |
70 else: | |
71 readsTruncation = '' | |
72 # output file(s) | |
73 output = options.output | |
74 logfile = options.logfile | |
75 | |
76 # Build Edena (overlapping) command | |
77 cmd = 'edena %s %s %s %s %s %s -p galaxy_output' % (unpaired_input, dr_pairs, rd_pairs, nThreads, minOlap, readsTruncation) | |
78 print '\nEdena (overlapping) command to be executed: \n %s' % ( cmd ) | |
79 | |
80 # Execution of Edena | |
81 print 'Executing Edena (overlapping)...' | |
82 if logfile: | |
83 log = open(logfile, 'w') | |
84 else: | |
85 log = sys.stdout | |
86 try: | |
87 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...") | |
88 finally: | |
89 if log != sys.stdout: | |
90 log.close() | |
91 print 'Edena (overlapping) executed!' | |
92 | |
93 shutil.move( "galaxy_output.ovl", output) | |
94 | |
95 | |
96 if __name__ == "__main__": | |
97 __main__() |