0
|
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()
|
1
|
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='')
|
0
|
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')
|
1
|
29
|
0
|
30 # build Edena (overlapping) command to be executed
|
|
31 # unpaired input(s)
|
|
32 if options.unpaired_input:
|
|
33 unpaired_input = '-r'
|
1
|
34 for item in options.unpaired_input:
|
0
|
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'
|
1
|
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])
|
0
|
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'
|
1
|
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])
|
0
|
50 else:
|
|
51 rd_pairs = ''
|
|
52 # nThreads
|
1
|
53 nThreads = '-nThreads %d' % (options.nThreads) if options.nThreads is not None else ''
|
0
|
54 # minimum overlap
|
1
|
55 minOlap = '-M %d' % (options.minOlap) if options.minOlap is not None else ''
|
0
|
56 # 3' end reads truncation
|
1
|
57 readsTruncation = '-t %d' % (options.readsTruncation) if options.readsTruncation is not None else ''
|
0
|
58 # output file(s)
|
|
59 output = options.output
|
|
60 logfile = options.logfile
|
1
|
61
|
0
|
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)
|
1
|
64 print '\nEdena (overlapping) command to be executed:\n %s' % (cmd)
|
|
65
|
0
|
66 # Execution of Edena
|
|
67 print 'Executing Edena (overlapping)...'
|
1
|
68 log = open(logfile, 'w') if logfile else sys.stdout
|
0
|
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!'
|
1
|
75
|
|
76 shutil.move('galaxy_output.ovl', output)
|
0
|
77
|
|
78
|
|
79 if __name__ == "__main__":
|
|
80 __main__()
|