0
|
1 #!/usr/bin/python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 import sys
|
|
5 import os
|
|
6 import re
|
|
7 import tempfile
|
|
8 import subprocess
|
|
9 import glob
|
|
10 import shutil
|
|
11 import argparse
|
|
12 from os.path import basename
|
|
13 import zipfile
|
|
14 import tarfile
|
|
15 import gzip
|
|
16 from stacks import *
|
|
17
|
|
18
|
|
19 def __main__():
|
|
20
|
|
21 # arguments recuperation
|
|
22
|
|
23 parser = argparse.ArgumentParser()
|
|
24 parser.add_argument('--input_type')
|
|
25 parser.add_argument('--input_enzyme')
|
|
26 parser.add_argument('--input_single')
|
|
27 parser.add_argument('--input_paired1')
|
|
28 parser.add_argument('--input_paired2')
|
|
29 parser.add_argument('--inputype')
|
|
30 parser.add_argument('--sample_name')
|
|
31 parser.add_argument('--barcode')
|
|
32 parser.add_argument('--output_choice')
|
|
33 parser.add_argument('--output_archive')
|
|
34 parser.add_argument('--enzyme1')
|
|
35 parser.add_argument('--enzyme2')
|
|
36 parser.add_argument('--outype')
|
|
37 parser.add_argument('--qualitenc')
|
|
38 parser.add_argument('-D', action='store_true')
|
2
|
39 parser.add_argument('--discard_file')
|
0
|
40 parser.add_argument('-t')
|
|
41 parser.add_argument('-q', action='store_true')
|
|
42 parser.add_argument('--activate_advanced_options')
|
|
43 parser.add_argument('-r', action='store_true')
|
|
44 parser.add_argument('-w', default='0.15')
|
|
45 parser.add_argument('-s', default='10')
|
|
46 parser.add_argument('-c', action='store_true')
|
|
47 parser.add_argument('--inline_null', action='store_true')
|
|
48 parser.add_argument('--index_null', action='store_true')
|
|
49 parser.add_argument('--inline_inline', action='store_true')
|
|
50 parser.add_argument('--index_index', action='store_true')
|
|
51 parser.add_argument('--inline_index', action='store_true')
|
|
52 parser.add_argument('--index_inline', action='store_true')
|
|
53 parser.add_argument('--logfile')
|
|
54 options = parser.parse_args()
|
|
55
|
|
56 # create the working dir
|
|
57 os.mkdir('inputs')
|
|
58 os.mkdir('job_outputs')
|
|
59 os.mkdir('galaxy_outputs')
|
|
60
|
|
61 cmd_line = []
|
|
62 cmd_line.append('process_radtags')
|
|
63 cmd_line.extend(['-p', 'inputs'])
|
|
64 cmd_line.extend(['-i', options.inputype])
|
|
65 cmd_line.extend(['-b', options.barcode])
|
|
66
|
|
67 # parse config files and create symlink into the temp dir
|
|
68
|
|
69 if options.input_type == 'single':
|
|
70
|
|
71 # load the config file
|
|
72 input_single = options.input_single
|
|
73
|
|
74 # parse the input_file to extract filenames and filepaths
|
|
75 tab_files = galaxy_config_to_tabfiles(input_single)
|
|
76
|
|
77 # create symlink into the temp dir
|
|
78 create_symlinks_from_tabfiles(tab_files, 'inputs')
|
|
79 else:
|
|
80
|
|
81 # load config files
|
|
82 input_paired1 = options.input_paired1
|
|
83 input_paired2 = options.input_paired2
|
|
84
|
|
85 # parse the input_file to extract filenames and filepaths
|
|
86
|
|
87 tab_files_paired1 = galaxy_config_to_tabfiles(input_paired1)
|
|
88 tab_files_paired2 = galaxy_config_to_tabfiles(input_paired2)
|
|
89
|
|
90 # create symlinks into the temp dir
|
|
91
|
|
92 create_symlinks_from_tabfiles(tab_files_paired1, 'inputs')
|
|
93 create_symlinks_from_tabfiles(tab_files_paired2, 'inputs')
|
|
94
|
|
95 cmd_line.append('-P')
|
|
96
|
|
97 # test nb enzyme
|
|
98 if options.input_enzyme == '1':
|
|
99 cmd_line.extend(['-e', options.enzyme1])
|
|
100
|
|
101 if options.input_enzyme == '2':
|
|
102 cmd_line.extend(['---renz_1', options.enzyme1, '--renz_2', options.enzyme2])
|
|
103
|
|
104 # quality
|
|
105 cmd_line.extend(['-E', options.qualitenc])
|
|
106
|
|
107 # outputs
|
|
108 cmd_line.extend(['-o', 'job_outputs/'])
|
|
109 cmd_line.extend(['-y', options.outype])
|
|
110
|
|
111 # test capture discards
|
|
112 if options.D:
|
|
113 cmd_line.append('-D')
|
|
114
|
|
115 # optional options
|
|
116 if options.activate_advanced_options == "true":
|
|
117
|
|
118 if options.q:
|
|
119 cmd_line.append('-q')
|
|
120 if options.r:
|
|
121 cmd_line.append('-r')
|
|
122
|
|
123 cmd_line.extend(['-w', options.w, '-s', options.s])
|
|
124
|
|
125 if options.c:
|
|
126 cmd_line.append('-c')
|
|
127 if options.t != '-1':
|
|
128 cmd_line.extend(['-t', options.t])
|
|
129 if options.inline_null:
|
|
130 cmd_line.append('--inline_null')
|
|
131 if options.index_null:
|
|
132 cmd_line.append('--index_null')
|
|
133 if options.inline_inline:
|
|
134 cmd_line.append('--inline_inline')
|
|
135 if options.index_index:
|
|
136 cmd_line.append('--index_index')
|
|
137 if options.inline_index:
|
|
138 cmd_line.append('--inline_index')
|
|
139 if options.index_inline:
|
|
140 cmd_line.append('--index_inline')
|
|
141
|
|
142 print '[CMD_LINE] : ' + ' '.join(cmd_line)
|
|
143
|
|
144 p = subprocess.call(cmd_line)
|
|
145
|
|
146 # postprocesses
|
|
147
|
|
148 try:
|
|
149 shutil.move('job_outputs/process_radtags.log', options.logfile)
|
|
150 except:
|
|
151 sys.stderr.write('Error in process_radtags execution; Please read the additional output (stdout)\n')
|
|
152 sys.exit(1)
|
|
153
|
|
154 if options.discard_file:
|
|
155 discards_file_name = glob.glob('job_outputs/*.discards')[0]
|
|
156 shutil.move(discards_file_name, options.discard_file)
|
|
157
|
|
158 # manage outputs names
|
|
159
|
|
160 change_outputs_procrad_name(os.getcwd() + '/job_outputs', options.sample_name)
|
|
161
|
|
162 # generate additional output archive file
|
|
163
|
|
164 if options.output_choice != '1':
|
|
165 generate_additional_archive_file(os.getcwd() + '/job_outputs', options.output_archive)
|
|
166
|
|
167 # if user has not choose the only zip archive
|
|
168
|
|
169 if options.output_choice != '3':
|
|
170 list_files = glob.glob('job_outputs/*')
|
|
171 for i in list_files:
|
|
172 shutil.move(i, 'galaxy_outputs')
|
|
173
|
|
174
|
|
175 if __name__ == '__main__':
|
|
176 __main__()
|
|
177
|
|
178
|