-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnakefile
182 lines (147 loc) · 6.42 KB
/
snakefile
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
import pandas as pd
import numpy as np
from anndata import AnnData
configfile: "runtime-analysis-config.yml"
input_data = "input/sces/"
markers_path = "input/markers/"
output_path = "output/" + config['version'] + "/"
no_of_cells = [50000, 100000, 400000]
no_of_cells_extended = [50000, 100000, 400000, 800000]
marker_options = ['all_markers', 'specified_markers']
phenograph_sizes = [10, 20, 30, 40, 50, 100]
FlowSOM_sizes = [4, 7, 8, 12, 15, 20]
acdc_options = [ 'absent', 'no-consider']
runtime_output = {
'astir_runtime': expand(output_path + "runtime/astir-{cells}-cells.csv", cells = no_of_cells_extended),
'phenograph_runtime': expand(output_path + "runtime/phenograph-{cells}-cells-{markers}-k-{k}.csv",
cells = no_of_cells_extended, markers = marker_options, k = phenograph_sizes),
'FlowSOM_runtime': expand(output_path + "runtime/FlowSOM-{cells}-cells-{markers}-k-{k}.csv",
cells = no_of_cells_extended, markers = marker_options, k = FlowSOM_sizes),
'ClusterX_runtime': expand(output_path + "runtime/ClusterX-{cells}-cells-{markers}.csv",
cells = no_of_cells, markers = marker_options),
'acdc': expand(output_path + 'runtime/ACDC-{cells}-cells-{options}.csv', cells = no_of_cells_extended, options = acdc_options),
'viz': output_path + "figures/runtime.pdf",
'runtime_summary': output_path + 'runtime/all_runtimes.csv'
}
print(runtime_output['acdc'])
rule all:
input:
subsets = expand(output_path + "anndata/basel-{cells}-cells-subset.h5ad", cells = no_of_cells),
astir_assignments = expand(output_path + "astir_assignments/basel_astir_assignments-{cells}-cells.csv", cells = no_of_cells),
fig = expand(output_path + "astir_assignments/basel_astir_assignment-{cells}-cells_loss.png", cells = no_of_cells),
diagnostics = expand(output_path + "astir_assignments/basel_astir_assignment-{cells}-cells_diagnostics.csv", cells = no_of_cells),
runtime = runtime_output['astir_runtime'],
phenograph = runtime_output['phenograph_runtime'],
FlowSOM = runtime_output['FlowSOM_runtime'],
ClusterX = runtime_output['ClusterX_runtime'],
acdc = runtime_output['acdc'],
viz = runtime_output['viz'],
summary = runtime_output['runtime_summary']
rule create_ad_subsets:
input:
basel = input_data + "basel_sce.rds"
output:
h5ad = output_path + "anndata/basel-{cells}-cells-subset.h5ad",
sce = output_path + "sces/basel-{cells}-cells-subset.rds"
script:
"scripts/create_subsets.R"
rule astir:
input:
anndata = output_path + "anndata/basel-{cells}-cells-subset.h5ad",
markers = markers_path + "jackson-2020-markers-v4.yml"
params:
max_epochs = 1000,
learning_rate = 2e-3,
n_init_epochs = 3
output:
csv = output_path + "astir_assignments/basel_astir_assignments-{cells}-cells.csv",
fig = output_path + "astir_assignments/basel_astir_assignment-{cells}-cells_loss.png",
diagnostics = output_path + "astir_assignments/basel_astir_assignment-{cells}-cells_diagnostics.csv",
runtime = output_path + "runtime/astir-{cells}-cells.csv"
run:
# Import
from astir.data import from_anndata_yaml
from datetime import datetime
# Start timing
start = datetime.now()
# Create astir object
ast = from_anndata_yaml(input.anndata, input.markers)
N = ast.get_type_dataset().get_exprs_df().shape[0]
batch_size = int(N/100)
ast.fit_type(max_epochs = int(params.max_epochs),
batch_size = batch_size,
learning_rate = float(params.learning_rate),
n_init_epochs=int(params.n_init_epochs))
time = datetime.now() - start
# Save runtime results
time_df = pd.DataFrame({'time': [time.total_seconds()],
'method': ['Astir'],
'cells': [N]})
time_df.to_csv(output.runtime, index = False)
# Save assignments
ast.get_celltype_probabilities().to_csv(output.csv)
# Run diagnostics
ast.diagnostics_celltype().to_csv(output.diagnostics)
# plot loss
import matplotlib.pyplot as plt
plt.figure(figsize=(5,4))
plt.plot(np.arange(len(ast.get_type_losses())), ast.get_type_losses())
plt.ylabel("Loss")
plt.xlabel("Epoch")
plt.tight_layout()
plt.savefig(output.fig, dpi=300)
rule phenograph:
input:
sce = output_path + "sces/basel-{cells}-cells-subset.rds",
markers = markers_path + "jackson-2020-markers-v4.yml"
output:
runtime = output_path + "runtime/phenograph-{cells}-cells-{markers}-k-{k}.csv"
script:
"scripts/phenograph.R"
rule FlowSOM:
input:
sce = output_path + "sces/basel-{cells}-cells-subset.rds",
markers = markers_path + "jackson-2020-markers-v4.yml"
output:
runtime = output_path + "runtime/FlowSOM-{cells}-cells-{markers}-k-{k}.csv"
script:
"scripts/FlowSOM.R"
rule ClusterX:
input:
sce = output_path + "sces/basel-{cells}-cells-subset.rds",
markers = markers_path + "jackson-2020-markers-v4.yml"
output:
runtime = output_path + "runtime/ClusterX-{cells}-cells-{markers}.csv"
script:
"scripts/ClusterX.R"
rule acdc:
input:
anndata = output_path + "anndata/basel-{cells}-cells-subset.h5ad",
markers = markers_path + "jackson-2020-markers-v4.yml"
output:
csv = output_path + 'runtime/ACDC-{cells}-cells-{options}.csv'
shell:
"python scripts/acdc_runtime.py "
"--input_h5ad {input.anndata} "
"--input_yaml {input.markers} "
"--output_assignments {output.csv} "
"--method {wildcards.options} "
"--cohort {wildcards.cells} "
rule viz_runtime:
input:
runtimes = runtime_output['runtime_summary']
output:
fig = runtime_output['viz']
script:
"scripts/viz.R"
rule summarize:
input:
astir = runtime_output['astir_runtime'],
phenograph = runtime_output['phenograph_runtime'],
clusterx = runtime_output['ClusterX_runtime'],
FlowSOM = runtime_output['FlowSOM_runtime'],
acdc = runtime_output['acdc']
output:
csv = runtime_output['runtime_summary']
script:
"scripts/summarize.R"