annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
1 # -*- coding: utf-8 -*-
60609a9cef3b Uploaded
crs4
parents:
diff changeset
2 """
60609a9cef3b Uploaded
crs4
parents:
diff changeset
3 Edena (overlapping)
60609a9cef3b Uploaded
crs4
parents:
diff changeset
4 version 0.2.1 (andrea.pinna@crs4.it)
60609a9cef3b Uploaded
crs4
parents:
diff changeset
5 """
60609a9cef3b Uploaded
crs4
parents:
diff changeset
6
60609a9cef3b Uploaded
crs4
parents:
diff changeset
7 import optparse
60609a9cef3b Uploaded
crs4
parents:
diff changeset
8 import shutil
60609a9cef3b Uploaded
crs4
parents:
diff changeset
9 import subprocess
60609a9cef3b Uploaded
crs4
parents:
diff changeset
10 import sys
60609a9cef3b Uploaded
crs4
parents:
diff changeset
11
60609a9cef3b Uploaded
crs4
parents:
diff changeset
12 def __main__():
60609a9cef3b Uploaded
crs4
parents:
diff changeset
13 # load arguments
60609a9cef3b Uploaded
crs4
parents:
diff changeset
14 print 'Parsing Edena (overlapping) input options...'
60609a9cef3b Uploaded
crs4
parents:
diff changeset
15 parser = optparse.OptionParser()
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
16 parser.add_option('--unpaired_input', action='append', dest='unpaired_input', help='')
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
17 parser.add_option('--dr_pair_1', action='append', dest='dr_pair_1', help='')
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
18 parser.add_option('--dr_pair_2', action='append', dest='dr_pair_2', help='')
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
19 parser.add_option('--rd_pair_1', action='append', dest='rd_pair_1', help='')
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
20 parser.add_option('--rd_pair_2', action='append', dest='rd_pair_2', help='')
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
21 parser.add_option('--nThreads', dest='nThreads', type='int', help='')
60609a9cef3b Uploaded
crs4
parents:
diff changeset
22 parser.add_option('--minOlap', dest='minOlap', type='int', help='')
60609a9cef3b Uploaded
crs4
parents:
diff changeset
23 parser.add_option('--readsTruncation', dest='readsTruncation', type='int', help='')
60609a9cef3b Uploaded
crs4
parents:
diff changeset
24 parser.add_option('--output', dest='output', help='')
60609a9cef3b Uploaded
crs4
parents:
diff changeset
25 parser.add_option('--logfile', dest='logfile', help='')
60609a9cef3b Uploaded
crs4
parents:
diff changeset
26 (options, args) = parser.parse_args()
60609a9cef3b Uploaded
crs4
parents:
diff changeset
27 if len(args) > 0:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
28 parser.error('Wrong number of arguments')
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
29
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
30 # build Edena (overlapping) command to be executed
60609a9cef3b Uploaded
crs4
parents:
diff changeset
31 # unpaired input(s)
60609a9cef3b Uploaded
crs4
parents:
diff changeset
32 if options.unpaired_input:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
33 unpaired_input = '-r'
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
34 for item in options.unpaired_input:
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
35 unpaired_input += ' %s' % (item)
60609a9cef3b Uploaded
crs4
parents:
diff changeset
36 else:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
37 unpaired_input = ''
60609a9cef3b Uploaded
crs4
parents:
diff changeset
38 # direct-reverse paired-end files
60609a9cef3b Uploaded
crs4
parents:
diff changeset
39 if options.dr_pair_1 and options.dr_pair_2:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
40 dr_pairs = '-DRpairs'
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
41 for i in range(len(options.dr_pair_1)):
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
42 dr_pairs += ' %s %s' % (options.dr_pair_1[i], options.dr_pair_2[i])
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
43 else:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
44 dr_pairs = ''
60609a9cef3b Uploaded
crs4
parents:
diff changeset
45 # reverse-direct paired-end files
60609a9cef3b Uploaded
crs4
parents:
diff changeset
46 if options.rd_pair_1 and options.rd_pair_2:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
47 rd_pairs = '-RDpairs'
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
48 for i in range(len(options.rd_pair_1)):
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
49 rd_pairs += ' %s %s' % (options.rd_pair_1[i], options.rd_pair_2[i])
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
50 else:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
51 rd_pairs = ''
60609a9cef3b Uploaded
crs4
parents:
diff changeset
52 # nThreads
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
53 nThreads = '-nThreads %d' % (options.nThreads) if options.nThreads is not None else ''
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
54 # minimum overlap
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
55 minOlap = '-M %d' % (options.minOlap) if options.minOlap is not None else ''
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
56 # 3' end reads truncation
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
57 readsTruncation = '-t %d' % (options.readsTruncation) if options.readsTruncation is not None else ''
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
58 # output file(s)
60609a9cef3b Uploaded
crs4
parents:
diff changeset
59 output = options.output
60609a9cef3b Uploaded
crs4
parents:
diff changeset
60 logfile = options.logfile
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
61
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
62 # Build Edena (overlapping) command
60609a9cef3b Uploaded
crs4
parents:
diff changeset
63 cmd = 'edena %s %s %s %s %s %s -p galaxy_output' % (unpaired_input, dr_pairs, rd_pairs, nThreads, minOlap, readsTruncation)
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
64 print '\nEdena (overlapping) command to be executed:\n %s' % (cmd)
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
65
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
66 # Execution of Edena
60609a9cef3b Uploaded
crs4
parents:
diff changeset
67 print 'Executing Edena (overlapping)...'
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
68 log = open(logfile, 'w') if logfile else sys.stdout
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
69 try:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
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...")
60609a9cef3b Uploaded
crs4
parents:
diff changeset
71 finally:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
72 if log != sys.stdout:
60609a9cef3b Uploaded
crs4
parents:
diff changeset
73 log.close()
60609a9cef3b Uploaded
crs4
parents:
diff changeset
74 print 'Edena (overlapping) executed!'
1
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
75
cd6cc6d76708 Simplify passing repeated params to Python script.
crs4
parents: 0
diff changeset
76 shutil.move('galaxy_output.ovl', output)
0
60609a9cef3b Uploaded
crs4
parents:
diff changeset
77
60609a9cef3b Uploaded
crs4
parents:
diff changeset
78
60609a9cef3b Uploaded
crs4
parents:
diff changeset
79 if __name__ == "__main__":
60609a9cef3b Uploaded
crs4
parents:
diff changeset
80 __main__()