10
10
11
11
def createPath (config , group , project , organism , libraryType , tuples ):
12
12
"""Ensures that the output path exists, creates it otherwise, and return where it is"""
13
- if tuples [0 ][3 ] == True : # if external data
13
+ if tuples [0 ][3 ]:
14
14
baseDir = "{}/{}/Analysis_{}" .format (config .get ('Paths' , 'baseData' ),
15
15
config .get ('Options' , 'runID' ),
16
16
BRB .misc .pacifier (project ))
@@ -29,7 +29,7 @@ def createPath(config, group, project, organism, libraryType, tuples):
29
29
30
30
def linkFiles (config , group , project , odir , tuples ):
31
31
"""Create symlinks in odir to fastq files in {project}. Return 1 if paired-end, 0 otherwise."""
32
- if tuples [0 ][3 ] == True : # if external data
32
+ if tuples [0 ][3 ]:
33
33
baseDir = "{}/{}/Project_{}" .format (config .get ('Paths' , 'baseData' ),
34
34
config .get ('Options' , 'runID' ),
35
35
BRB .misc .pacifier (project ))
@@ -57,20 +57,15 @@ def linkFiles(config, group, project, odir, tuples):
57
57
58
58
def removeLinkFiles (d ):
59
59
"""Remove symlinks created by linkFiles()"""
60
- try :
61
- files = glob . glob ( "{}/originalFASTQ/*_R?.fastq.gz" . format ( d ))
60
+ files = glob . glob ( "{}/originalFASTQ/*_R?.fastq.gz" . format ( d ))
61
+ if files :
62
62
for fname in files :
63
63
os .unlink (fname )
64
- except :
65
- print ("check if originalFASTQ exists!" )
66
- log .warning ("removeLinkeFiles: check if originalFASTQ exists!" )
67
64
files = glob .glob ("{}/*_R?.fastq.gz" .format (d ))
68
65
for fname in files :
69
66
os .unlink (fname )
70
67
71
68
72
-
73
-
74
69
def relinkFiles (config , group , project , organism , libraryType , tuples ):
75
70
"""
76
71
Generate symlinks under the snakepipes originalFASTQ folder directly from the project folder.
@@ -86,10 +81,7 @@ def relinkFiles(config, group, project, organism, libraryType, tuples):
86
81
log .info (f"Multiqc report found for { group } project { project } ." )
87
82
of = Path (config .get ('Paths' , 'bioinfoCoreDir' )) / 'Analysis' + project + '_multiqc.html'
88
83
log .info (f"Trying to copy mqc report to { of } ." )
89
- try :
90
- shutil .copyfile (mqcf , of )
91
- except :
92
- log .warning (f"Copying { mqcf } to { of } failed." )
84
+ shutil .copyfile (mqcf , of )
93
85
else :
94
86
log .info (f"no multiqc report under { mqcf } ." )
95
87
@@ -136,15 +128,10 @@ def copyCellRanger(config, d):
136
128
short_fid = str (os .path .basename (lane_dir )).split ('_' )[2 ] + '_'
137
129
bioinfoCoreDirPath = Path (config .get ('Paths' , 'bioinfoCoreDir' )) / Path (short_fid + nname )
138
130
nname = seqfac_lane_dir / nname
139
- try :
140
- shutil .copyfile (fname , nname )
141
- except :
142
- log .warning ("copyCellRanger from {} to {} failed." .format (fname , nname ))
131
+ shutil .copyfile (fname , nname )
143
132
# to bioinfocore dir
144
- try :
145
- shutil .copyfile (fname , bioinfoCoreDirPath )
146
- except :
147
- log .warning ("copyCellRanger from {} to {} failed." .format (fname , bioinfoCoreDirPath ))
133
+ shutil .copyfile (fname , bioinfoCoreDirPath )
134
+ log .warning ("copyCellRanger from {} to {} failed." .format (fname , bioinfoCoreDirPath ))
148
135
149
136
150
137
def copyRELACS (config , d ):
@@ -176,49 +163,41 @@ def copyRELACS(config, d):
176
163
seqfac_lane_dir = Path (config .get ('Paths' , 'seqFacDir' )) / year_postfix / lane_dir
177
164
os .makedirs (seqfac_lane_dir , exist_ok = True )
178
165
nname = seqfac_lane_dir / nname
179
- try :
180
- shutil .copyfile (fname , nname )
181
- except :
182
- log .warning ("copyCellRanger from {} to {} failed." .format (fname , nname ))
183
-
166
+ shutil .copyfile (fname , nname )
184
167
185
168
def tidyUpABit (d ):
186
169
"""
187
170
Reduce the number of files in the analysis folder.
188
171
"""
189
- try :
190
- shutil .rmtree (os .path .join (d , 'cluster_logs' ))
191
- os .unlink (os .path .join (d , 'config.yaml' ))
192
- shutil .rmtree (os .path .join (d , '.snakemake' ))
193
- # multiqc data
194
- mqc_log = os .path .join (d , 'multiQC' , 'multiqc_data' , 'multiqc.log' )
195
- mqc_out = os .path .join (d , 'multiQC' , 'multiQC.out' )
196
- mqc_err = os .path .join (d , 'multiQC' , 'multiQC.err' )
197
- if os .path .exists (mqc_log ):
198
- os .unlink (mqc_log )
199
- if os .path .exists (mqc_out ):
200
- os .unlink (mqc_out )
201
- if os .path .exists (mqc_err ):
202
- os .unlink (mqc_err )
203
-
204
- for f in glob .glob (os .path .join (d , '*.log' )):
205
- os .unlink (f )
206
-
207
- for d2 in glob .glob (os .path .join (d , 'FASTQ*' )):
208
- shutil .rmtree (d2 )
209
- except :
210
- pass
172
+ shutil .rmtree (os .path .join (d , 'cluster_logs' ))
173
+ os .unlink (os .path .join (d , 'config.yaml' ))
174
+ shutil .rmtree (os .path .join (d , '.snakemake' ))
175
+ # multiqc data
176
+ mqc_log = os .path .join (d , 'multiQC' , 'multiqc_data' , 'multiqc.log' )
177
+ mqc_out = os .path .join (d , 'multiQC' , 'multiQC.out' )
178
+ mqc_err = os .path .join (d , 'multiQC' , 'multiQC.err' )
179
+ if os .path .exists (mqc_log ):
180
+ os .unlink (mqc_log )
181
+ if os .path .exists (mqc_out ):
182
+ os .unlink (mqc_out )
183
+ if os .path .exists (mqc_err ):
184
+ os .unlink (mqc_err )
185
+
186
+ for f in glob .glob (os .path .join (d , '*.log' )):
187
+ os .unlink (f )
188
+
189
+ for d2 in glob .glob (os .path .join (d , 'FASTQ*' )):
190
+ shutil .rmtree (d2 )
191
+
211
192
212
193
def stripRights (d ):
213
194
# Strip rights.
214
- try :
215
- for r , dirs , files in os .walk (d ):
216
- for d in dirs :
217
- os .chmod (os .path .join (r , d ), stat .S_IRWXU | stat .S_IRGRP | stat .S_IXGRP )
218
- for f in files :
219
- os .chmod (os .path .join (r , f ), stat .S_IRWXU | stat .S_IRGRP )
220
- except :
221
- pass
195
+ for r , dirs , files in os .walk (d ):
196
+ for d in dirs :
197
+ os .chmod (os .path .join (r , d ), stat .S_IRWXU | stat .S_IRGRP | stat .S_IXGRP )
198
+ for f in files :
199
+ os .chmod (os .path .join (r , f ), stat .S_IRWXU | stat .S_IRGRP )
200
+
222
201
223
202
def touchDone (outputDir , fname = "analysis.done" ):
224
203
open (os .path .join (outputDir , fname ), "w" ).close ()
0 commit comments