-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulated_data.snake
More file actions
232 lines (206 loc) · 14.6 KB
/
simulated_data.snake
File metadata and controls
232 lines (206 loc) · 14.6 KB
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
"""
Explanation of wildcards:
noCNVType: input data type without CNVs.
CNVType: input data type with CNVs, e.g., including or excluding CNVs.
datasetName: simulated dataset names, e.g., 0001, 0002, 0003...
"""
include: "scripts/constants.py"
include: "scripts/utils.py"
#########################################################
# Get categories of wildcards #
#########################################################
SIMUDATASETNAMES = get_dataset_names(SIMUSNVSITESDIR)
SIMUCNVTYPES = get_data_types(
config["benchmark"]["simulatedDataTypes"],
config["benchmark"]["simulation"]["dataTypes"]["CNVTypes"],
True
)
SIMUNOCNVTYPES = get_data_types(
config["benchmark"]["simulatedDataTypes"],
config["benchmark"]["simulation"]["dataTypes"]["CNVTypes"],
False
)
wildcard_constraints:
noCNVType='|'.join([re.escape(i) for i in SIMUNOCNVTYPES]) if SIMUNOCNVTYPES is not None and len(SIMUNOCNVTYPES) > 0 else NONE_PATTERN,
CNVType='|'.join([re.escape(i) for i in SIMUCNVTYPES]) if SIMUCNVTYPES is not None and len(SIMUCNVTYPES) > 0 else NONE_PATTERN
#########################################################
# Reorganize the simulated data #
#########################################################
# Rule: copy simulated data to another directory for consistancy reasons.
rule copySimulatedData:
input:
mpileupFile=SIMUMPILEUPDATADIR + "{datasetName}/" + SIMUMPILEUPWITHOUTNORMAL,
trueSNVSites=SIMUSNVSITESDIR + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"] + ".{datasetName}",
trueSNVEvoEvents=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVEvoEventsPre"] + ".{datasetName}",
trueSNVCov=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVCovPre"] + ".{datasetName}",
trueSNVGenotypesAL=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVGenotypesALPre"] + ".{datasetName}",
trueSNVGenotypesNU=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVGenotypesNUPre"] + ".{datasetName}",
trueSNVGenotypesTer=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVGenotypesTerPre"] + ".{datasetName}"
output:
mpileupFile=protected(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/read_counts" + config["benchmark"]["simulation"]["MPileUpDataSuf"]),
trueSNVSites=protected(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"]),
trueSNVEvoEvents=protected(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVEvoEventsPre"]),
trueSNVCov=protected(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVCovPre"]),
trueSNVGenotypesAL=protected(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesALPre"]),
trueSNVGenotypesNU=protected(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesNUPre"]),
trueSNVGenotypesTerSimple=protected(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesTerPre"] + '.simple')
shell:
"cp -f {input.mpileupFile} {output.mpileupFile} && "
"cp -f {input.trueSNVSites} {output.trueSNVSites} && "
"cp -f {input.trueSNVEvoEvents} {output.trueSNVEvoEvents} && "
"cp -f {input.trueSNVCov} {output.trueSNVCov} && "
"cp -f {input.trueSNVGenotypesAL} {output.trueSNVGenotypesAL} && "
"cp -f {input.trueSNVGenotypesNU} {output.trueSNVGenotypesNU} && "
"cp -f {input.trueSNVGenotypesTer} {output.trueSNVGenotypesTerSimple}"
# Rule: gather copied simulated data.
rule gatherCopiedSimulatedData:
input:
mpileupFile=expand(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/read_counts" + config["benchmark"]["simulation"]["MPileUpDataSuf"], noCNVType=SIMUNOCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVSites=expand(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"], noCNVType=SIMUNOCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVEvoEvents=expand(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVEvoEventsPre"], noCNVType=SIMUNOCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVCov=expand(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVCovPre"], noCNVType=SIMUNOCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVGenotypesAL=expand(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesALPre"], noCNVType=SIMUNOCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVGenotypesNU=expand(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesNUPre"], noCNVType=SIMUNOCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVGenotypesTer=expand(SIMUDATATYPESDIR + "{noCNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesTerPre"] + '.simple', noCNVType=SIMUNOCNVTYPES, datasetName=SIMUDATASETNAMES)
output:
protected(SIMUDATATYPESDIR + "NO_CNV_DONE_FLAG")
shell:
"touch {output}"
# Rule: add CNVs to the simulated data.
rule addCNVs2SimulatedData:
input:
mpileupFile=SIMUMPILEUPDATADIR + "{datasetName}/" + SIMUMPILEUPWITHOUTNORMAL,
trueSNVSites=SIMUSNVSITESDIR + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"] + ".{datasetName}",
trueSNVEvoEvents=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVEvoEventsPre"] + ".{datasetName}",
trueSNVGenotypesAL=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVGenotypesALPre"] + ".{datasetName}"
output:
mpileupFile=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/read_counts" + config["benchmark"]["simulation"]["MPileUpDataSuf"]),
trueSNVSites=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"]),
trueSNVEvoEvents=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVEvoEventsPre"]),
trueSNVCov=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVCovPre"]),
trueSNVGenotypesAL=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesALPre"]),
trueSNVGenotypesNU=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesNUPre"]),
trueSNVGenotypesTer=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesTerPre"]),
trueSNVGenotypesTerSimple=protected(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesTerPre"] + '.simple')
params:
prob=eval(config["fineTune"]["simulateCNVs"]["prob"]) if type(config["fineTune"]["simulateCNVs"]["prob"]) == str else config["fineTune"]["simulateCNVs"]["prob"],
minCNVNum=config["fineTune"]["simulateCNVs"]["minNum"],
maxCNVNum=config["fineTune"]["simulateCNVs"]["maxNum"],
seed=config["fineTune"]["simulateCNVs"]["seed"],
prefix=SIMUDATATYPESDIR,
incCNVLabel=config["benchmark"]["simulation"]["dataTypes"]["CNVTypes"]["incCNV"]["dir"].rstrip("/"),
excCNVLabel=config["benchmark"]["simulation"]["dataTypes"]["CNVTypes"]["excCNV"]["dir"].rstrip("/"),
keep=lambda wildcards: get_cnv_keep_type(wildcards.CNVType, config["benchmark"]["simulation"]["dataTypes"]["CNVTypes"])
shell:
"python scripts/add_cnvs_2_simulated_data.py "
"--reads {input.mpileupFile} "
"--snvs {input.trueSNVSites} "
"--gts {input.trueSNVGenotypesAL} "
"--evo {input.trueSNVEvoEvents} "
"--prob {params.prob} "
"--cnvs {params.minCNVNum} {params.maxCNVNum} "
"--seed {params.seed} "
"--prefix {params.prefix} "
"--inccnvlabel {params.incCNVLabel} "
"--exccnvlabel {params.excCNVLabel} "
"--keep {params.keep}"
# Rule: gather simulated data with CNVs added.
rule gatherAddedCNVs2SimulatedData:
input:
mpileupFile=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/read_counts" + config["benchmark"]["simulation"]["MPileUpDataSuf"], CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVSites=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"], CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVEvoEvents=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVEvoEventsPre"], CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVCov=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVCovPre"], CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVGenotypesAL=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesALPre"], CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVGenotypesNU=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesNUPre"], CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVGenotypesTer=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesTerPre"], CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES),
trueSNVGenotypesTerSimple=expand(SIMUDATATYPESDIR + "{CNVType}/{datasetName}/" + config["benchmark"]["simulation"]["trueSNVGenotypesTerPre"] + '.simple', CNVType=SIMUCNVTYPES, datasetName=SIMUDATASETNAMES)
output:
protected(SIMUDATATYPESDIR + "CNV_DONE_FLAG")
shell:
"touch {output}"
def gather_simulated_data(wildcards=None):
cnv_type_flag = SIMUCNVTYPES is not None and len(SIMUCNVTYPES) > 0
no_cnv_type_flag = SIMUNOCNVTYPES is not None and len(SIMUNOCNVTYPES) > 0
if cnv_type_flag and no_cnv_type_flag:
return [SIMUDATATYPESDIR + "CNV_DONE_FLAG", SIMUDATATYPESDIR + "NO_CNV_DONE_FLAG"]
elif cnv_type_flag:
return SIMUDATATYPESDIR + "CNV_DONE_FLAG"
elif no_cnv_type_flag:
return SIMUDATATYPESDIR + "NO_CNV_DONE_FLAG"
else:
raise ValueError('Empty values of "benchmark - simulatedDataTypes". Have at least one kept.')
# Rule: gather simulated data.
rule gatherSimulatedData:
input:
gather_simulated_data
output:
protected(SIMUDATATYPESDIR + "DONE_FLAG")
shell:
"touch {output}"
########################################################
# Summarize parallel mutations #
########################################################
# Rule: gather the information of parallel mutations.
rule gatherParallelMutations:
input:
trueSNVSites=expand(SIMUSNVSITESDIR + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"] + ".{datasetName}", datasetName=SIMUDATASETNAMES),
parallelMuts=expand(SIMUPARALLELMUTDIR + config["benchmark"]["simulation"]["parallelMutPre"] + ".{datasetName}", datasetName=SIMUDATASETNAMES)
output:
protected(SIMUPARALLELMUTDIR + "summary.tsv")
params:
datasets=SIMUDATASETNAMES,
cellNum=config["benchmark"]["analysis"]["cellNum"],
covMean=config["benchmark"]["analysis"]["covMean"],
covVariance=config["benchmark"]["analysis"]["covVariance"],
effSeqErrRate=config["benchmark"]["analysis"]["effSeqErrRate"],
adoRate=config["benchmark"]["analysis"]["adoRate"],
deletionRate=config["benchmark"]["analysis"]["deletionRate"],
insertionRate=config["benchmark"]["analysis"]["insertionRate"]
script:
"scripts/gather_parallel_mutations.R"
########################################################
# Convert branch lengths of true trees #
########################################################
# Rule: convert branch lengths of true trees measured from in the number of generations per site to in the number of mutations per site.
rule convertTrueTreesWithTrunkWithoutNormal:
input:
SIMUTRUETREEDIR + config["benchmark"]["simulation"]["treesWithTrunkWithoutNormalDir"] + config["benchmark"]["simulation"]["treesPre"] + ".{datasetName}"
output:
protected(SIMUCONVERTEDTRUETREEDIR + config["benchmark"]["simulation"]["treesWithTrunkWithoutNormalDir"] + config["benchmark"]["simulation"]["treesPre"] + ".{datasetName}")
params:
mu = config["benchmark"]["analysis"]["mutationRate"]
shell:
"python scripts/convert_true_tree.py "
"-i {input} "
"-m {params.mu} "
"-o {output}"
# Rule: convert branch lengths of true trees measured from in the number of generations per site to in the number of mutations per site.
rule convertTrueTreesWithoutTrunkWithoutNormal:
input:
SIMUTRUETREEDIR + config["benchmark"]["simulation"]["treesWithoutTrunkWithoutNormalDir"] + config["benchmark"]["simulation"]["treesPre"] + ".{datasetName}"
output:
protected(SIMUCONVERTEDTRUETREEDIR + config["benchmark"]["simulation"]["treesWithoutTrunkWithoutNormalDir"] + config["benchmark"]["simulation"]["treesPre"] + ".{datasetName}")
params:
mu = config["benchmark"]["analysis"]["mutationRate"]
shell:
"python scripts/convert_true_tree.py "
"-i {input} "
"-m {params.mu} "
"-o {output}"
#######################################################
# Get info from true data #
#######################################################
# rule collectTrueSNVAdoInfo:
# input:
# snvSitesNames=SIMUSNVSITESDIR + config["benchmark"]["simulation"]["trueSNVSitesNamesPre"] + ".{datasetName}",
# cellNames=SIMUTUMORCELLNAMES,
# trueGenotypes=SIMUTRUESNVDIR + config["benchmark"]["simulation"]["trueSNVGenotypesNUPre"] + ".{datasetName}",
# trueAdoStates=SIMUTRUEADOSTATESDIR + config["benchmark"]["simulation"]["trueAdoStatesPre"] + ".{datasetName}"
# output:
# withAdoHetero=protected(SIMUTRUESNVADODIR + config["benchmark"]["simulation"]["trueSNVWithAdoHeteroPre"] + ".{datasetName}"),
# withoutAdoHetero=protected(SIMUTRUESNVADODIR + config["benchmark"]["simulation"]["trueSNVWithoutAdoHeteroPre"] + ".{datasetName}"),
# withAdoHomo=protected(SIMUTRUESNVADODIR + config["benchmark"]["simulation"]["trueSNVWithAdoHomoPre"] + ".{datasetName}"),
# withoutAdoHomo=protected(SIMUTRUESNVADODIR + config["benchmark"]["simulation"]["trueSNVWithoutAdoHomoPre"] + ".{datasetName}")
# script:
# "scripts/collect_true_snv_ado_info.py"