-
Notifications
You must be signed in to change notification settings - Fork 9
/
ResetSnakefile
310 lines (298 loc) · 12 KB
/
ResetSnakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import pandas as pd
from snakemake.utils import validate
import multiprocessing as mp
import sys
import os
configfile: f"{sys.path[0]}/DS_progConfig.yaml"
# ~ validate(config, "config.schema.yaml")
samples = pd.read_csv(config["samples"]).set_index("sample", drop=False)
validate(samples, f"{sys.path[0]}/DS_baseSchema.yaml")
config["maxCores"] = min(config["maxCores"], mp.cpu_count())
# ~ print(samples.index)
#print(config["maxCores"])
def get_sample(wildcards):
return samples.loc[wildcards.sample, "sample"]
def get_rglb(wildcards):
return samples.loc[wildcards.sample, "rglb"]
def get_rgpl(wildcards):
return samples.loc[wildcards.sample, "rgpl"]
def get_rgpu(wildcards):
return samples.loc[wildcards.sample, "rgpu"]
def get_rgsm(wildcards):
return samples.loc[wildcards.sample, "rgsm"]
def get_reference(wildcards):
return samples.loc[wildcards.sample, "reference"]
def get_target_bed(wildcards):
return samples.loc[wildcards.sample, "target_bed"]
def get_blast_db(wildcards):
return samples.loc[wildcards.sample, "blast_db"]
def get_blast_db_path(wildcards):
if samples.loc[wildcards.sample, "blast_db"].upper() == "NONE":
return "NONE.nal"
else:
return f'{samples.loc[wildcards.sample, "blast_db"]}.nal'
def get_target_taxon(wildcards):
return samples.loc[wildcards.sample, "targetTaxonId"]
def get_baseDir(wildcards):
return samples.loc[wildcards.sample, "baseDir"]
def get_in1(wildcards):
return f'{samples.loc[wildcards.sample, "baseDir"]}/{samples.loc[wildcards.sample, "in1"]}'
def get_in2(wildcards):
return f'{samples.loc[wildcards.sample, "baseDir"]}/{samples.loc[wildcards.sample, "in2"]}'
def get_mqFilt(wildcards):
return samples.loc[wildcards.sample, "mqFilt"]
def get_minMem(wildcards):
return samples.loc[wildcards.sample, "minMem"]
def get_maxMem(wildcards):
return samples.loc[wildcards.sample, "maxMem"]
def get_cutOff(wildcards):
return samples.loc[wildcards.sample, "cutOff"]
def get_nCutOff(wildcards):
return samples.loc[wildcards.sample, "nCutOff"]
def get_umiLen(wildcards):
return samples.loc[wildcards.sample, "umiLen"]
def get_spacerLen(wildcards):
return samples.loc[wildcards.sample, "spacerLen"]
def get_locLen(wildcards):
return samples.loc[wildcards.sample, "locLen"]
def get_readLen(wildcards):
return samples.loc[wildcards.sample, "readLen"]
def get_clipBegin(wildcards):
return samples.loc[wildcards.sample, "clipBegin"]
def get_clipEnd(wildcards):
return samples.loc[wildcards.sample, "clipEnd"]
def get_runSSCS(wildcards):
return samples.loc[wildcards.sample, "runSSCS"]
def get_runDCS(wildcards):
return samples.loc[wildcards.sample, "runDCS"]
def get_makeDCS(wildcards):
return samples.loc[wildcards.sample, "makeDCS"]
def get_cm_outputs(wildcards):
return samples.loc[wildcards.sample, "cm_outputs"]
def get_cm_sumTypes(wildcards):
return samples.loc[wildcards.sample, "cm_sumTypes"]
def get_minClonal(wildcards):
return samples.loc[wildcards.sample, "minClonal"]
def get_maxClonal(wildcards):
return samples.loc[wildcards.sample, "maxClonal"]
def get_minDepth(wildcards):
return samples.loc[wildcards.sample, "minDepth"]
def get_maxNs(wildcards):
return samples.loc[wildcards.sample, "maxNs"]
def get_cleanup(wildcards):
return samples.loc[wildcards.sample, "cleanup"]
def get_recovery(wildcards):
return f'{sys.path[0]}/scripts/RecoveryScripts/{samples.loc[wildcards.sample, "recovery"]}'
def get_rerun_type(wildcards):
return samples.loc[wildcards.sample, "rerun_type"]
def getGeneralPrepedFiles():
outList = []
tmpList = []
anyRerun = False
for sampIter in samples.index:
if samples.loc[sampIter, "rerun_type"] > 0:
outList.append(f".{sampIter}.preparedForRun")
anyRerun = True
if anyRerun:
tmpList.append(f"{config['samples']}.summary.csv")
tmpList.append(f"{config['samples']}.summaryDepth.pdf")
tmpList.append(f"{config['samples']}.summaryInsertSize.pdf")
tmpList.append(f"{config['samples']}.summaryMutsByCycle.pdf")
tmpList.append(f"{config['samples']}.summaryFamilySize.pdf")
outList.extend([".".join((x, "temp")) for x in tmpList if os.path.exists(x)])
print("general")
print(outList)
return outList
def getSamplePrepedFiles(wildcards):
outList = []
sscsTest = get_runSSCS(wildcards)
blastTest = get_blast_db_path(wildcards) != "NONE.nal"
rerun_type = get_rerun_type(wildcards)
if rerun_type > 0:
# remove post blast recovery files
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/"
f"{wildcards.sample}.report.html"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.countmuts.csv"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.vcf"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.snps.vcf"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.mutated.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.mutated.bam.bai"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.final.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.final.bam.bai"
)
if sscsTest:
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.countmuts.csv"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.vcf"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.snps.vcf"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.mutated.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.mutated.bam.bai"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.final.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.final.bam.bai"
)
if rerun_type > 1:
# remove post blast files
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/"
f"preVariantCalling/{wildcards.sample}.dcs.prevar.bam")
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/"
f"preVariantCalling/{wildcards.sample}.dcs.prevar.bam.bai")
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/"
f"preVariantCalling/{wildcards.sample}.sscs.prevar.bam")
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/"
f"preVariantCalling/{wildcards.sample}.sscs.prevar.bam.bai")
if blastTest:
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/FilteredReads/"
f"{wildcards.sample}_dcs.postRecovery.ambig.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/FilteredReads/"
f"{wildcards.sample}_dcs.postRecovery.ambig.bam.bai"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/FilteredReads/"
f"{wildcards.sample}_dcs.postRecovery.wrongSpecies.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/FilteredReads/"
f"{wildcards.sample}_dcs.postRecovery.wrongSpecies.bam.bai"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/postBlast/"
f"FilteredReads/{wildcards.sample}_dcs.ambig.sort.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/postBlast/"
f"FilteredReads/{wildcards.sample}_dcs.ambig.sort.bam.bai"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/postBlast/"
f"FilteredReads/{wildcards.sample}_dcs.wrongSpecies.sort.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/postBlast/"
f"FilteredReads/{wildcards.sample}_dcs.wrongSpecies.sort.bam.bai"
)
if rerun_type > 2:
if blastTest:
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/postBlast/"
f"{wildcards.sample}_dcs.blast.xml"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/postBlast/"
f"{wildcards.sample}_dcs.preBlast.mutated.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/postBlast/"
f"{wildcards.sample}_dcs.preBlast.unmutated.bam"
)
else:
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.final.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/dcs/"
f"{wildcards.sample}.dcs.final.bam.bai"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.final.bam"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Final/sscs/"
f"{wildcards.sample}.sscs.final.bam.bai"
)
if rerun_type > 3:
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/ConsensusMakerOutputs/"
f"{wildcards.sample}_read1_dcs.fq.gz"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/ConsensusMakerOutputs/"
f"{wildcards.sample}_read2_dcs.fq.gz"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/ConsensusMakerOutputs/"
f"{wildcards.sample}_read1_sscs.fq.gz"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/ConsensusMakerOutputs/"
f"{wildcards.sample}_read2_sscs.fq.gz"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/ConsensusMakerOutputs/"
f"{wildcards.sample}_aln_seq1.fq.gz"
)
outList.append(
f"{samples.loc[wildcards.sample,'baseDir']}/Intermediate/ConsensusMakerOutputs/"
f"{wildcards.sample}_aln_seq2.fq.gz"
)
print(wildcards.sample)
print([".".join((x, "temp")) for x in outList if os.path.exists(x)])
return [".".join((x, "temp")) for x in outList if os.path.exists(x)]
rule all:
input:
getGeneralPrepedFiles()
output:
temp(touch(".preparedForRun"))
rule prepFile:
input:
"{file}"
output:
temp("{file}.temp")
shell:
"""
mv {input} {output}
"""
rule prepSample:
input:
getSamplePrepedFiles
output:
temp(touch(".{sample}.preparedForRun"))