annotate STACKS_denovomap.py @ 3:0e0ff9e9c761 default tip

fix inputs clean name
author cmonjeau
date Mon, 28 Sep 2015 13:21:35 +0000
parents d6ba40f6c824
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
1 #!/usr/bin/python
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
2 # -*- coding: utf-8 -*-
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
3
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
4 import sys
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
5 import re
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
6 import os
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
7 import tempfile
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
8 import shutil
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
9 import subprocess
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
10 import glob
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
11 import argparse
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
12 from os.path import basename
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
13 import zipfile
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
14 import tarfile
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
15 import gzip
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
16 from galaxy.datatypes.checkers import *
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
17 from stacks import *
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
18
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
19
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
20 def __main__():
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
21
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
22 # arguments recuperation
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
23
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
24 parser = argparse.ArgumentParser()
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
25 parser.add_argument('-p')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
26 parser.add_argument('-b')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
27 parser.add_argument('-r')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
28 parser.add_argument('-s')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
29 parser.add_argument('-O')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
30 parser.add_argument('-m')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
31 parser.add_argument('-P')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
32 parser.add_argument('-M')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
33 parser.add_argument('-N')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
34 parser.add_argument('-n')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
35 parser.add_argument('-t')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
36 parser.add_argument('-H')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
37 parser.add_argument('--bound_low')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
38 parser.add_argument('--bound_high')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
39 parser.add_argument('--alpha')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
40 parser.add_argument('--logfile')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
41 parser.add_argument('--compress_output')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
42 parser.add_argument('--catalogsnps')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
43 parser.add_argument('--catalogalleles')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
44 parser.add_argument('--catalogtags')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
45
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
46 # additionnal outputs
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
47 parser.add_argument('--total_output')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
48 parser.add_argument('--tags_output')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
49 parser.add_argument('--snps_output')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
50 parser.add_argument('--alleles_output')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
51 parser.add_argument('--matches_output')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
52
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
53 options = parser.parse_args()
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
54
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
55 # create working directories
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
56
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
57 os.mkdir('inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
58 os.mkdir('job_outputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
59 os.mkdir('galaxy_outputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
60
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
61 cmd_line = []
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
62 cmd_line.append('denovo_map.pl')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
63
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
64 # if genetic map
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
65
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
66 if options.p:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
67
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
68 # parse config files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
69
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
70 tab_parent_files = galaxy_config_to_tabfiles_for_STACKS(options.p)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
71
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
72 # check if zipped files are into the tab and change tab content
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
73
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
74 extract_compress_files_from_tabfiles(tab_parent_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
75
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
76 # check files extension (important to have .fq or .fasta files)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
77
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
78 check_fastq_extension_and_add(tab_parent_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
79
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
80 # create symlink into the temp dir
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
81
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
82 create_symlinks_from_tabfiles(tab_parent_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
83
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
84 # parse the input dir and store all file names into a tab
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
85
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
86 fastq_files = []
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
87 for fastq_file in glob.glob('inputs/*'):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
88 # if is a file (skip repository created after a decompression)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
89 if os.path.isfile(fastq_file):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
90 fastq_files.append(fastq_file)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
91
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
92 fastq_files.sort()
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
93
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
94 # test if fastq are paired-end
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
95 if options.b == 'true':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
96 for n in range(0, len(fastq_files), 2):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
97 cmd_line.extend(['-p', fastq_files[n]])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
98 else:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
99 for myfastqfile in fastq_files:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
100 cmd_line.extend(['-p', myfastqfile])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
101
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
102 # if genetic map with progeny files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
103
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
104 if options.r:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
105
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
106 # parse config files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
107 tab_progeny_files = galaxy_config_to_tabfiles_for_STACKS(options.r)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
108
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
109 # check if zipped files are into the tab and change tab content
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
110 extract_compress_files_from_tabfiles(tab_progeny_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
111
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
112 # check files extension (important to have .fq or .fasta files)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
113 check_fastq_extension_and_add(tab_progeny_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
114
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
115 # create symlink into the temp dir
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
116 create_symlinks_from_tabfiles(tab_progeny_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
117
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
118 for key in tab_progeny_files:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
119
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
120 # if is a file (skip repository created after a decompression)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
121
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
122 if os.path.isfile('inputs/' + key):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
123 cmd_line.extend(['-r', 'inputs/' + key])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
124
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
125 # if population is checked
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
126 if options.s:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
127
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
128 tab_individual_files = galaxy_config_to_tabfiles_for_STACKS(options.s)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
129
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
130 # check if zipped files are into the tab and change tab content
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
131 extract_compress_files_from_tabfiles(tab_individual_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
132
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
133 # check files extension (important to have .fq or .fasta files)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
134 check_fastq_extension_and_add(tab_individual_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
135
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
136 # create symlink into the temp dir
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
137 create_symlinks_from_tabfiles(tab_individual_files, 'inputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
138
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
139 # create the command input line
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
140 for key in tab_individual_files:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
141
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
142 # if is a file (skip repository created after a decompression)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
143 if os.path.isfile('inputs/' + key):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
144 cmd_line.extend(['-s', 'inputs/' + key])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
145
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
146 # create the command line
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
147 cmd_line.extend([
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
148 '-S',
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
149 '-b',
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
150 '1',
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
151 '-T',
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
152 '4',
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
153 '-o',
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
154 'job_outputs/'
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
155 ])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
156
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
157 if options.O:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
158 cmd_line.extend(['-O', options.O])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
159
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
160 if options.m and options.m != '-1':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
161 cmd_line.extend(['-m', options.m])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
162
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
163 if options.P and options.P != '-1':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
164 cmd_line.extend(['-P', options.P])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
165
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
166 if options.M and options.M != '-1':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
167 cmd_line.extend(['-M', options.M])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
168
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
169 if options.N and options.N != '-1':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
170 cmd_line.extend(['-N', options.N])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
171
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
172 if options.n and options.n != '-1':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
173 cmd_line.extend(['-n', options.n])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
174
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
175 if options.t and options.t == 'true':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
176 cmd_line.append('-t')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
177
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
178 if options.H and options.H == 'true':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
179 cmd_line.append('-H')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
180
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
181 ## SNP model
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
182 if options.bound_low:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
183 cmd_line.extend(['--bound_low', options.bound_low])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
184 cmd_line.extend(['--bound_high', options.bound_high])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
185
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
186 if options.alpha:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
187 cmd_line.extend(['--alpha', options.alpha])
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
188
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
189 # launch the command line
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
190 print "[CMD_LINE] : "+' '.join(cmd_line)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
191
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
192 p = subprocess.call(cmd_line)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
193
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
194 # postprocesses
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
195 try:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
196 shutil.move('job_outputs/denovo_map.log', options.logfile)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
197 except:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
198 sys.stderr.write('Error in denovo_map execution; Please read the additional output (stdout)\n')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
199 sys.exit(1)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
200
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
201 # go inside the outputs dir
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
202 os.chdir('job_outputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
203
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
204 # move files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
205 for i in glob.glob('*'):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
206 if re.search('catalog.snps.tsv$', i):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
207 shutil.copy(i, options.catalogsnps)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
208 if re.search('catalog.alleles.tsv$', i):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
209 shutil.copy(i, options.catalogalleles)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
210 if re.search('catalog.tags.tsv$', i):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
211 shutil.copy(i, options.catalogtags)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
212
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
213 list_files = glob.glob('*')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
214
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
215 # if compress output is total
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
216 if options.compress_output == 'total':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
217
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
218 mytotalzipfile = zipfile.ZipFile('total.zip.temp', 'w',
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
219 allowZip64=True)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
220
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
221 for i in list_files:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
222 mytotalzipfile.write(os.path.basename(i))
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
223
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
224 # return the unique archive
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
225 shutil.move('total.zip.temp', options.total_output)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
226 elif options.compress_output == 'categories':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
227
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
228 # if compress output is by categories
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
229 mytagszip = zipfile.ZipFile('tags.zip.temp', 'w', allowZip64=True)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
230 mysnpszip = zipfile.ZipFile('snps.zip.temp', 'w', allowZip64=True)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
231 myalleleszip = zipfile.ZipFile('alleles.zip.temp', 'w', allowZip64=True)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
232 mymatcheszip = zipfile.ZipFile('matches.zip.temp', 'w', allowZip64=True)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
233
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
234 for i in list_files:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
235 # for each type of files
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
236 if re.search("tags\.tsv$", i) and not re.search('batch', i):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
237 mytagszip.write(os.path.basename(i))
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
238 os.remove(i)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
239 elif re.search("snps\.tsv$", i) and not re.search('batch', i):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
240 mysnpszip.write(os.path.basename(i))
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
241 os.remove(i)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
242 elif re.search("alleles\.tsv$", i) and not re.search('batch', i):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
243 myalleleszip.write(os.path.basename(i))
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
244 os.remove(i)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
245 elif re.search("matches\.tsv$", i) and not re.search('batch', i):
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
246 mymatcheszip.write(os.path.basename(i))
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
247 os.remove(i)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
248 else:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
249 shutil.move(os.path.basename(i), '../galaxy_outputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
250
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
251 # return archives....
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
252 shutil.move('tags.zip.temp', options.tags_output)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
253 shutil.move('snps.zip.temp', options.snps_output)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
254 shutil.move('alleles.zip.temp', options.alleles_output)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
255 shutil.move('matches.zip.temp', options.matches_output)
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
256 else:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
257 # else no compression
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
258 for i in list_files:
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
259 shutil.move(os.path.basename(i), '../galaxy_outputs')
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
260
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
261
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
262 if __name__ == '__main__':
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
263 __main__()
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
264
d6ba40f6c824 first commit
cmonjeau
parents:
diff changeset
265