biopipen 0.21.2__py3-none-any.whl → 0.22.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of biopipen might be problematic. Click here for more details.
- biopipen/__init__.py +1 -1
- biopipen/core/filters.py +142 -0
- biopipen/ns/scrna.py +19 -1
- biopipen/ns/tcr.py +30 -10
- biopipen/reports/delim/SampleInfo.svelte +2 -22
- biopipen/reports/scrna/CellsDistribution.svelte +4 -39
- biopipen/reports/scrna/MarkersFinder.svelte +6 -126
- biopipen/reports/scrna/MetaMarkers.svelte +3 -75
- biopipen/reports/scrna/RadarPlots.svelte +4 -20
- biopipen/reports/scrna/ScFGSEA.svelte +4 -23
- biopipen/reports/scrna/SeuratClusterStats.svelte +3 -69
- biopipen/reports/scrna/SeuratPreparing.svelte +3 -26
- biopipen/reports/scrna/TopExpressingGenes.svelte +3 -41
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +17 -16
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +13 -16
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +44 -52
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +2 -8
- biopipen/reports/tcr/CDR3AAPhyschem.svelte +18 -65
- biopipen/reports/tcr/CloneResidency.svelte +3 -93
- biopipen/reports/tcr/Immunarch.svelte +4 -168
- biopipen/reports/tcr/TCRClusterStats.svelte +3 -45
- biopipen/reports/tcr/TESSA.svelte +11 -28
- biopipen/scripts/delim/SampleInfo.R +41 -7
- biopipen/scripts/scrna/CellsDistribution.R +127 -16
- biopipen/scripts/scrna/MarkersFinder.R +245 -100
- biopipen/scripts/scrna/MetaMarkers.R +163 -82
- biopipen/scripts/scrna/RadarPlots.R +163 -110
- biopipen/scripts/scrna/ScFGSEA.R +51 -11
- biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +26 -13
- biopipen/scripts/scrna/SeuratClusterStats-features.R +58 -53
- biopipen/scripts/scrna/SeuratClusterStats-stats.R +39 -21
- biopipen/scripts/scrna/SeuratClusterStats.R +4 -2
- biopipen/scripts/scrna/SeuratClustering.R +73 -26
- biopipen/scripts/scrna/SeuratMetadataMutater.R +13 -1
- biopipen/scripts/scrna/SeuratPreparing.R +93 -19
- biopipen/scripts/scrna/TopExpressingGenes.R +100 -18
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +21 -8
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +25 -3
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +1 -0
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +14 -3
- biopipen/scripts/tcr/Attach2Seurat.R +2 -1
- biopipen/scripts/tcr/CDR3AAPhyschem.R +123 -10
- biopipen/scripts/tcr/CloneResidency.R +114 -34
- biopipen/scripts/tcr/Immunarch-basic.R +18 -4
- biopipen/scripts/tcr/Immunarch-clonality.R +14 -0
- biopipen/scripts/tcr/Immunarch-diversity.R +123 -18
- biopipen/scripts/tcr/Immunarch-geneusage.R +23 -1
- biopipen/scripts/tcr/Immunarch-kmer.R +45 -3
- biopipen/scripts/tcr/Immunarch-overlap.R +62 -0
- biopipen/scripts/tcr/Immunarch-spectratyping.R +18 -2
- biopipen/scripts/tcr/Immunarch-tracking.R +24 -1
- biopipen/scripts/tcr/Immunarch-vjjunc.R +17 -2
- biopipen/scripts/tcr/Immunarch.R +7 -0
- biopipen/scripts/tcr/ImmunarchLoading.R +22 -23
- biopipen/scripts/tcr/TCRClusterStats.R +124 -11
- biopipen/scripts/tcr/TCRClustering.R +8 -9
- biopipen/scripts/tcr/TESSA.R +66 -41
- biopipen/utils/misc.R +96 -1
- {biopipen-0.21.2.dist-info → biopipen-0.22.1.dist-info}/METADATA +1 -1
- {biopipen-0.21.2.dist-info → biopipen-0.22.1.dist-info}/RECORD +62 -62
- {biopipen-0.21.2.dist-info → biopipen-0.22.1.dist-info}/WHEEL +0 -0
- {biopipen-0.21.2.dist-info → biopipen-0.22.1.dist-info}/entry_points.txt +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
source("{{biopipen_dir}}/utils/misc.R")
|
|
2
|
+
|
|
1
3
|
library(Seurat)
|
|
2
4
|
library(rlang)
|
|
3
5
|
library(dplyr)
|
|
@@ -5,10 +7,12 @@ library(tidyr)
|
|
|
5
7
|
library(tibble)
|
|
6
8
|
library(ggplot2)
|
|
7
9
|
library(ggradar)
|
|
10
|
+
library(slugify)
|
|
8
11
|
|
|
9
12
|
# input/output
|
|
10
13
|
srtfile = {{in.srtobj | r}}
|
|
11
14
|
outdir = {{out.outdir | r}}
|
|
15
|
+
joboutdir = {{job.outdir | r}}
|
|
12
16
|
|
|
13
17
|
# envs
|
|
14
18
|
mutaters = {{envs.mutaters | r}}
|
|
@@ -24,9 +28,96 @@ devpars = {{envs.devpars | r}}
|
|
|
24
28
|
cases = {{envs.cases | r}}
|
|
25
29
|
|
|
26
30
|
DEFAULT_CASE = "DEFAULT"
|
|
31
|
+
sections = c()
|
|
32
|
+
|
|
33
|
+
log_info("Reading srtobj ...")
|
|
34
|
+
srtobj = readRDS(srtfile)
|
|
35
|
+
meta = srtobj@meta.data
|
|
36
|
+
|
|
37
|
+
log_info("Mutating meta data if needed ...")
|
|
38
|
+
if (is.list(mutaters) && length(mutaters) > 0) {
|
|
39
|
+
mutaters = lapply(mutaters, function(x) parse_expr(x))
|
|
40
|
+
meta = meta %>% mutate(!!!mutaters)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# fill up the cases
|
|
44
|
+
if (length(cases) == 0) {
|
|
45
|
+
cases[[DEFAULT_CASE]] = list(
|
|
46
|
+
by = by,
|
|
47
|
+
each = each,
|
|
48
|
+
order = order,
|
|
49
|
+
cluster_col = cluster_col,
|
|
50
|
+
cluster_order = cluster_order,
|
|
51
|
+
breaks = breaks,
|
|
52
|
+
direction = direction,
|
|
53
|
+
section = section,
|
|
54
|
+
devpars = devpars
|
|
55
|
+
)
|
|
56
|
+
} else {
|
|
57
|
+
# Use the values given directly under `envs` as default
|
|
58
|
+
for (key in names(cases)) {
|
|
59
|
+
if (is.null(cases[[key]]$by)) {
|
|
60
|
+
cases[[key]]$by = by
|
|
61
|
+
}
|
|
62
|
+
if (is.null(cases[[key]]$each)) {
|
|
63
|
+
cases[[key]]$each = each
|
|
64
|
+
}
|
|
65
|
+
if (is.null(cases[[key]]$order)) {
|
|
66
|
+
cases[[key]]$order = order
|
|
67
|
+
}
|
|
68
|
+
if (is.null(cases[[key]]$cluster_col)) {
|
|
69
|
+
cases[[key]]$cluster_col = cluster_col
|
|
70
|
+
}
|
|
71
|
+
if (is.null(cases[[key]]$cluster_order)) {
|
|
72
|
+
cases[[key]]$cluster_order = cluster_order
|
|
73
|
+
}
|
|
74
|
+
if (is.null(cases[[key]]$breaks)) {
|
|
75
|
+
cases[[key]]$breaks = breaks
|
|
76
|
+
}
|
|
77
|
+
if (is.null(cases[[key]]$direction)) {
|
|
78
|
+
cases[[key]]$direction = direction
|
|
79
|
+
}
|
|
80
|
+
if (is.null(cases[[key]]$section)) {
|
|
81
|
+
cases[[key]]$section = section
|
|
82
|
+
}
|
|
83
|
+
if (is.null(cases[[key]]$devpars)) {
|
|
84
|
+
cases[[key]]$devpars = devpars
|
|
85
|
+
}
|
|
86
|
+
if (is.null(cases[[key]]$devpars$width)) {
|
|
87
|
+
cases[[key]]$devpars$width = devpars$width
|
|
88
|
+
}
|
|
89
|
+
if (is.null(cases[[key]]$devpars$height)) {
|
|
90
|
+
cases[[key]]$devpars$height = devpars$height
|
|
91
|
+
}
|
|
92
|
+
if (is.null(cases[[key]]$devpars$res)) {
|
|
93
|
+
cases[[key]]$devpars$res = devpars$res
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
27
97
|
|
|
28
|
-
#
|
|
29
|
-
|
|
98
|
+
# Expand the cases
|
|
99
|
+
newcases = list()
|
|
100
|
+
for (key in names(cases)) {
|
|
101
|
+
if (is.null(cases[[key]]$each)) {
|
|
102
|
+
sections <- c(sections, cases[[key]]$section)
|
|
103
|
+
newcases[[paste0(cases[[key]]$section, ":", key)]] = cases[[key]]
|
|
104
|
+
} else {
|
|
105
|
+
each_values = meta %>% pull(!!sym(cases[[key]]$each)) %>% unique() %>% na.omit()
|
|
106
|
+
sections <- c(sections, key)
|
|
107
|
+
for (evalue in each_values) {
|
|
108
|
+
ekey = paste0(key, ":", evalue)
|
|
109
|
+
newcases[[ekey]] = cases[[key]]
|
|
110
|
+
newcases[[ekey]]$each_value = evalue
|
|
111
|
+
if (!is.null(cases[[key]]$section)) {
|
|
112
|
+
log_warn(
|
|
113
|
+
sprintf("Case %s: `section` is ignored when `each` is specified.", key)
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
single_section <- length(sections) == 1 && sections[[1]] == "DEFAULT"
|
|
30
121
|
|
|
31
122
|
auto_breaks = function(maxval) {
|
|
32
123
|
if (maxval <= 0.1) { # 10%
|
|
@@ -52,14 +143,28 @@ auto_breaks = function(maxval) {
|
|
|
52
143
|
}
|
|
53
144
|
}
|
|
54
145
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
146
|
+
casename_info <- function(casename, create = FALSE) {
|
|
147
|
+
sec_case_names <- strsplit(casename, ":")[[1]]
|
|
148
|
+
cname <- paste(sec_case_names[-1], collapse = ":")
|
|
58
149
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
150
|
+
out <- list(
|
|
151
|
+
casename = casename,
|
|
152
|
+
section = sec_case_names[1],
|
|
153
|
+
case = cname,
|
|
154
|
+
section_slug = slugify(sec_case_names[1], tolower = FALSE),
|
|
155
|
+
case_slug = slugify(cname, tolower = FALSE)
|
|
156
|
+
)
|
|
157
|
+
out$casedir <- file.path(outdir, out$section_slug, out$case_slug)
|
|
158
|
+
if (create) {
|
|
159
|
+
dir.create(out$casedir, showWarnings = FALSE, recursive = TRUE)
|
|
62
160
|
}
|
|
161
|
+
out
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
run_one_case = function(casename) {
|
|
165
|
+
info = casename_info(casename, create = TRUE)
|
|
166
|
+
case = newcases[[casename]]
|
|
167
|
+
log_info("Running for case: {casename}")
|
|
63
168
|
|
|
64
169
|
# Get the counts
|
|
65
170
|
counts = if (!is.null(case$each)) meta %>% filter(!!sym(case$each) == case$each_value) else meta
|
|
@@ -97,9 +202,10 @@ run_one_case = function(casename) {
|
|
|
97
202
|
}
|
|
98
203
|
|
|
99
204
|
# Save the counts
|
|
205
|
+
counts_file = file.path(info$casedir, "counts.tsv")
|
|
100
206
|
write.table(
|
|
101
207
|
counts,
|
|
102
|
-
|
|
208
|
+
counts_file,
|
|
103
209
|
sep = "\t",
|
|
104
210
|
quote = FALSE,
|
|
105
211
|
col.names = TRUE,
|
|
@@ -115,9 +221,10 @@ run_one_case = function(casename) {
|
|
|
115
221
|
}
|
|
116
222
|
|
|
117
223
|
# Save the percentages
|
|
224
|
+
perc_file = file.path(info$casedir, "percentages.tsv")
|
|
118
225
|
write.table(
|
|
119
226
|
counts,
|
|
120
|
-
|
|
227
|
+
perc_file,
|
|
121
228
|
sep = "\t",
|
|
122
229
|
quote = FALSE,
|
|
123
230
|
col.names = TRUE,
|
|
@@ -132,126 +239,72 @@ run_one_case = function(casename) {
|
|
|
132
239
|
}
|
|
133
240
|
|
|
134
241
|
# Plot
|
|
242
|
+
plotfile = file.path(info$casedir, "plot.png")
|
|
135
243
|
p = ggradar(
|
|
136
244
|
counts %>% as.data.frame() %>% rownames_to_column("group"),
|
|
137
245
|
values.radar = paste0(breaks, "%"),
|
|
138
246
|
grid.min = breaks[1] / 100,
|
|
139
247
|
grid.mid = breaks[2] / 100,
|
|
140
248
|
grid.max = breaks[3] / 100,
|
|
141
|
-
|
|
249
|
+
group.colours = pal_biopipen()(nrow(counts))
|
|
142
250
|
)
|
|
143
251
|
png(
|
|
144
|
-
|
|
252
|
+
plotfile,
|
|
145
253
|
width = case$devpars$width,
|
|
146
254
|
height = case$devpars$height,
|
|
147
255
|
res = case$devpars$res
|
|
148
256
|
)
|
|
149
257
|
print(p)
|
|
150
258
|
dev.off()
|
|
151
|
-
}
|
|
152
259
|
|
|
153
|
-
|
|
154
|
-
if (length(cases) == 0) {
|
|
155
|
-
cases[[DEFAULT_CASE]] = list(
|
|
156
|
-
by = by,
|
|
157
|
-
each = each,
|
|
158
|
-
order = order,
|
|
159
|
-
cluster_col = cluster_col,
|
|
160
|
-
cluster_order = cluster_order,
|
|
161
|
-
breaks = breaks,
|
|
162
|
-
direction = direction,
|
|
163
|
-
section = section,
|
|
164
|
-
devpars = devpars
|
|
165
|
-
)
|
|
166
|
-
} else {
|
|
167
|
-
# Use the values given directly under `envs` as default
|
|
168
|
-
for (key in names(cases)) {
|
|
169
|
-
if (is.null(cases[[key]]$by)) {
|
|
170
|
-
cases[[key]]$by = by
|
|
171
|
-
}
|
|
172
|
-
if (is.null(cases[[key]]$each)) {
|
|
173
|
-
cases[[key]]$each = each
|
|
174
|
-
}
|
|
175
|
-
if (is.null(cases[[key]]$order)) {
|
|
176
|
-
cases[[key]]$order = order
|
|
177
|
-
}
|
|
178
|
-
if (is.null(cases[[key]]$cluster_col)) {
|
|
179
|
-
cases[[key]]$cluster_col = cluster_col
|
|
180
|
-
}
|
|
181
|
-
if (is.null(cases[[key]]$cluster_order)) {
|
|
182
|
-
cases[[key]]$cluster_order = cluster_order
|
|
183
|
-
}
|
|
184
|
-
if (is.null(cases[[key]]$breaks)) {
|
|
185
|
-
cases[[key]]$breaks = breaks
|
|
186
|
-
}
|
|
187
|
-
if (is.null(cases[[key]]$direction)) {
|
|
188
|
-
cases[[key]]$direction = direction
|
|
189
|
-
}
|
|
190
|
-
if (is.null(cases[[key]]$section)) {
|
|
191
|
-
cases[[key]]$section = section
|
|
192
|
-
}
|
|
193
|
-
if (is.null(cases[[key]]$devpars)) {
|
|
194
|
-
cases[[key]]$devpars = devpars
|
|
195
|
-
}
|
|
196
|
-
if (is.null(cases[[key]]$devpars$width)) {
|
|
197
|
-
cases[[key]]$devpars$width = devpars$width
|
|
198
|
-
}
|
|
199
|
-
if (is.null(cases[[key]]$devpars$height)) {
|
|
200
|
-
cases[[key]]$devpars$height = devpars$height
|
|
201
|
-
}
|
|
202
|
-
if (is.null(cases[[key]]$devpars$res)) {
|
|
203
|
-
cases[[key]]$devpars$res = devpars$res
|
|
204
|
-
}
|
|
205
|
-
}
|
|
260
|
+
add_case_report(info)
|
|
206
261
|
}
|
|
207
262
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
# Expand the cases
|
|
219
|
-
newcases = list()
|
|
220
|
-
for (key in names(cases)) {
|
|
221
|
-
if (is.null(cases[[key]]$each)) {
|
|
222
|
-
newcases[[key]] = cases[[key]]
|
|
223
|
-
} else {
|
|
224
|
-
each_values = meta %>% pull(!!sym(cases[[key]]$each)) %>% unique() %>% na.omit()
|
|
225
|
-
for (evalue in each_values) {
|
|
226
|
-
ekey = if (key == DEFAULT_CASE) evalue else paste0(key, "_", evalue)
|
|
227
|
-
newcases[[ekey]] = cases[[key]]
|
|
228
|
-
newcases[[ekey]]$each_value = evalue
|
|
229
|
-
if (!is.null(cases[[key]]$section)) {
|
|
230
|
-
warn(
|
|
231
|
-
sprintf("Case %s: `section` is ignored when `each` is specified.", key),
|
|
232
|
-
immediate. = TRUE
|
|
263
|
+
add_case_report = function(info) {
|
|
264
|
+
add_report(
|
|
265
|
+
list(
|
|
266
|
+
name = "Radar Plot",
|
|
267
|
+
contents = list(
|
|
268
|
+
list(
|
|
269
|
+
kind = "image",
|
|
270
|
+
src = file.path(info$casedir, "plot.png")
|
|
233
271
|
)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
272
|
+
)
|
|
273
|
+
),
|
|
274
|
+
list(
|
|
275
|
+
name = "Count Table",
|
|
276
|
+
contents = list(
|
|
277
|
+
list(
|
|
278
|
+
kind = "table",
|
|
279
|
+
src = file.path(info$casedir, "counts.tsv")
|
|
280
|
+
)
|
|
281
|
+
)
|
|
282
|
+
),
|
|
283
|
+
list(
|
|
284
|
+
name = "Percentage Table",
|
|
285
|
+
contents = list(
|
|
286
|
+
list(
|
|
287
|
+
kind = "table",
|
|
288
|
+
src = file.path(info$casedir, "percentages.tsv")
|
|
289
|
+
)
|
|
290
|
+
)
|
|
291
|
+
),
|
|
292
|
+
h1 = ifelse(
|
|
293
|
+
info$section == "DEFAULT",
|
|
294
|
+
info$case,
|
|
295
|
+
ifelse(single_section, paste0(info$section, " - ", info$case), info$section)
|
|
296
|
+
),
|
|
297
|
+
h2 = ifelse(
|
|
298
|
+
info$section == "DEFAULT",
|
|
299
|
+
"#",
|
|
300
|
+
ifelse(single_section, "#", info$case)
|
|
301
|
+
),
|
|
302
|
+
ui = "tabs"
|
|
303
|
+
)
|
|
238
304
|
}
|
|
239
305
|
|
|
306
|
+
|
|
240
307
|
casenames = names(newcases)
|
|
241
308
|
sapply(casenames, run_one_case)
|
|
242
309
|
|
|
243
|
-
|
|
244
|
-
if (length(sections) > 0) {
|
|
245
|
-
# Write as TOML
|
|
246
|
-
# section1 = ["case1", "case2"]
|
|
247
|
-
# section2 = ["case3", "case4"]
|
|
248
|
-
# ...
|
|
249
|
-
outstr = c()
|
|
250
|
-
for (sec in names(sections)) {
|
|
251
|
-
sec_str = paste0(sec, " = ")
|
|
252
|
-
sec_str = paste0(sec_str, "['", paste(sections[[sec]], collapse = "', '"), "']")
|
|
253
|
-
outstr = c(outstr, sec_str)
|
|
254
|
-
}
|
|
255
|
-
section_file = file.path(outdir, "sections.toml")
|
|
256
|
-
writeLines(outstr, section_file)
|
|
257
|
-
}
|
|
310
|
+
save_report(joboutdir)
|
biopipen/scripts/scrna/ScFGSEA.R
CHANGED
|
@@ -4,9 +4,11 @@ source("{{biopipen_dir}}/utils/mutate_helpers.R")
|
|
|
4
4
|
library(rlang)
|
|
5
5
|
library(Seurat)
|
|
6
6
|
library(tidyseurat)
|
|
7
|
+
library(slugify)
|
|
7
8
|
|
|
8
9
|
srtfile <- {{in.srtobj | r}} # nolint
|
|
9
10
|
outdir <- {{out.outdir | r}} # nolint
|
|
11
|
+
joboutdir <- {{job.outdir | r}} # nolint
|
|
10
12
|
mutaters <- {{envs.mutaters | r}} # nolint
|
|
11
13
|
group.by <- {{envs["group-by"] | r}} # nolint
|
|
12
14
|
ident.1 <- {{envs["ident-1"] | r}} # nolint
|
|
@@ -23,11 +25,15 @@ ncores <- {{envs.ncores | r}} # nolint
|
|
|
23
25
|
rest <- {{envs.rest | r: todot="-"}} # nolint
|
|
24
26
|
cases <- {{envs.cases | r: todot="-"}} # nolint
|
|
25
27
|
|
|
28
|
+
log_info("Reading srtobj...")
|
|
29
|
+
|
|
26
30
|
srtobj <- readRDS(srtfile)
|
|
27
31
|
if (!is.null(mutaters) && length(mutaters) > 0) {
|
|
28
32
|
srtobj@meta.data <- srtobj@meta.data %>% mutate(!!!lapply(mutaters, parse_expr))
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
single_section <- TRUE
|
|
36
|
+
|
|
31
37
|
expand_cases <- function() {
|
|
32
38
|
# fill up cases with missing parameters
|
|
33
39
|
if (is.null(cases) || length(cases) == 0) {
|
|
@@ -73,13 +79,16 @@ expand_cases <- function() {
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
outcases <- list()
|
|
82
|
+
sections <- c()
|
|
76
83
|
# expand each
|
|
77
84
|
for (name in names(filled_cases)) {
|
|
78
85
|
case <- filled_cases[[name]]
|
|
79
86
|
if (is.null(case$each) || nchar(case$each) == 0) {
|
|
87
|
+
sections <- c(sections, case$section)
|
|
80
88
|
outcases[[paste0(case$section, ":", name)]] <- case
|
|
81
89
|
} else {
|
|
82
90
|
eachs <- srtobj@meta.data %>% pull(case$each) %>% na.omit() %>% unique() %>% as.vector()
|
|
91
|
+
sections <- c(sections, case$each)
|
|
83
92
|
for (each in eachs) {
|
|
84
93
|
by <- make.names(paste0(".", name, "_", case$each,"_", each))
|
|
85
94
|
srtobj@meta.data <<- srtobj@meta.data %>%
|
|
@@ -98,19 +107,34 @@ expand_cases <- function() {
|
|
|
98
107
|
}
|
|
99
108
|
}
|
|
100
109
|
}
|
|
110
|
+
single_section <- length(unique(sections)) == 1
|
|
101
111
|
outcases
|
|
102
112
|
}
|
|
103
113
|
|
|
114
|
+
casename_info <- function(casename, create = FALSE) {
|
|
115
|
+
sec_case_names <- strsplit(casename, ":")[[1]]
|
|
116
|
+
cname <- paste(sec_case_names[-1], collapse = ":")
|
|
117
|
+
|
|
118
|
+
out <- list(
|
|
119
|
+
casename = casename,
|
|
120
|
+
section = sec_case_names[1],
|
|
121
|
+
case = cname,
|
|
122
|
+
section_slug = slugify(sec_case_names[1], tolower = FALSE),
|
|
123
|
+
case_slug = slugify(cname, tolower = FALSE)
|
|
124
|
+
)
|
|
125
|
+
out$casedir <- file.path(outdir, out$section_slug, out$case_slug)
|
|
126
|
+
if (create) {
|
|
127
|
+
dir.create(out$casedir, showWarnings = FALSE, recursive = TRUE)
|
|
128
|
+
}
|
|
129
|
+
out
|
|
130
|
+
}
|
|
131
|
+
|
|
104
132
|
do_case <- function(name, case) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
section <- section_case[1]
|
|
108
|
-
casename <- paste(section_case[-1], collapse = ":")
|
|
109
|
-
case_dir <- file.path(outdir, section, casename)
|
|
110
|
-
dir.create(case_dir, showWarnings = FALSE, recursive = TRUE)
|
|
133
|
+
log_info("- Doing case: {name} ...")
|
|
134
|
+
info <- casename_info(name, create = TRUE)
|
|
111
135
|
|
|
112
136
|
# prepare expression matrix
|
|
113
|
-
|
|
137
|
+
log_info(" Preparing expression matrix...")
|
|
114
138
|
sobj <- srtobj %>% filter(!is.na(!!sym(case$group.by)))
|
|
115
139
|
if (!is.null(case$ident.2)) {
|
|
116
140
|
sobj <- sobj %>% filter(!!sym(case$group.by) %in% c(case$ident.1, case$ident.2))
|
|
@@ -124,11 +148,11 @@ do_case <- function(name, case) {
|
|
|
124
148
|
exprs <- GetAssayData(sobj, slot = "data", assay = "RNA")
|
|
125
149
|
|
|
126
150
|
# get preranks
|
|
127
|
-
|
|
151
|
+
log_info(" Getting preranks...")
|
|
128
152
|
ranks <- prerank(exprs, case$ident.1, case$ident.2, allclasses, case$method)
|
|
129
153
|
write.table(
|
|
130
154
|
ranks,
|
|
131
|
-
file.path(
|
|
155
|
+
file.path(info$casedir, "fgsea.rank"),
|
|
132
156
|
row.names = FALSE,
|
|
133
157
|
col.names = TRUE,
|
|
134
158
|
sep = "\t",
|
|
@@ -136,13 +160,29 @@ do_case <- function(name, case) {
|
|
|
136
160
|
)
|
|
137
161
|
|
|
138
162
|
# run fgsea
|
|
139
|
-
|
|
163
|
+
log_info(" Running fgsea...")
|
|
140
164
|
case$rest$minSize <- case$minsize
|
|
141
165
|
case$rest$maxSize <- case$maxsize
|
|
142
166
|
case$rest$eps <- case$eps
|
|
143
167
|
case$rest$nproc <- case$ncores
|
|
144
|
-
runFGSEA(ranks, gmtfile, case$top,
|
|
168
|
+
runFGSEA(ranks, gmtfile, case$top, info$casedir, case$rest)
|
|
169
|
+
|
|
170
|
+
add_report(
|
|
171
|
+
list(kind = "fgsea", dir = info$casedir),
|
|
172
|
+
h1 = ifelse(
|
|
173
|
+
info$section == "DEFAULT",
|
|
174
|
+
info$case,
|
|
175
|
+
ifelse(single_section, paste0(info$section, " - ", info$case), info$section)
|
|
176
|
+
),
|
|
177
|
+
h2 = ifelse(
|
|
178
|
+
info$section == "DEFAULT",
|
|
179
|
+
"#",
|
|
180
|
+
ifelse(single_section, "#", info$case)
|
|
181
|
+
)
|
|
182
|
+
)
|
|
145
183
|
}
|
|
146
184
|
|
|
147
185
|
cases <- expand_cases()
|
|
148
186
|
sapply(sort(names(cases)), function(name) do_case(name, cases[[name]]))
|
|
187
|
+
|
|
188
|
+
save_report(joboutdir)
|
|
@@ -5,40 +5,53 @@ dimplots = {{envs.dimplots | r: todot="-", skip=1}}
|
|
|
5
5
|
|
|
6
6
|
odir = file.path(outdir, "dimplots")
|
|
7
7
|
dir.create(odir, recursive=TRUE, showWarnings=FALSE)
|
|
8
|
-
report_toc_file = file.path(odir, "report_toc.json")
|
|
9
|
-
# Realname => file
|
|
10
|
-
report_toc = list()
|
|
11
8
|
|
|
12
9
|
do_one_dimplot = function(name) {
|
|
13
10
|
print(paste0("Doing dimplots for: ", name))
|
|
14
11
|
|
|
15
12
|
case = list_update(dimplots_defaults, dimplots[[name]])
|
|
16
13
|
case$devpars = list_update(dimplots_defaults$devpars, dimplots[[name]]$devpars)
|
|
17
|
-
case$
|
|
14
|
+
if (!is.null(case$subset)) {
|
|
15
|
+
case$object = srtobj %>% filter(!!rlang::parse_expr(case$subset))
|
|
16
|
+
} else {
|
|
17
|
+
case$object = srtobj
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (is.null(case$group.by) && !is.null(case$ident)) {
|
|
21
|
+
case$group.by = case$ident
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
n_uidents = length(unique(case$object@meta.data[[case$group.by]]))
|
|
18
25
|
if (is.null(case$cols)) {
|
|
19
|
-
case$cols =
|
|
26
|
+
case$cols = pal_biopipen()(n_uidents)
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
excluded_args = c("devpars", "ident")
|
|
29
|
+
excluded_args = c("devpars", "ident", "subset")
|
|
23
30
|
for (arg in excluded_args) {
|
|
24
31
|
assign(arg, case[[arg]])
|
|
25
32
|
case[[arg]] = NULL
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
if (is.null(case$group.by) && !is.null(ident)) {
|
|
29
|
-
case$group.by = ident
|
|
30
|
-
}
|
|
31
|
-
|
|
32
35
|
if (case$reduction %in% c("dim", "auto")) {
|
|
33
36
|
case$reduction = NULL
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
figfile = file.path(odir, report_toc[[name]])
|
|
38
|
+
figfile = file.path(odir, paste0(slugify(name), ".dim.png"))
|
|
37
39
|
png(figfile, width=devpars$width, height=devpars$height, res=devpars$res)
|
|
38
40
|
p = do_call(DimPlot, case)
|
|
39
41
|
print(p)
|
|
40
42
|
dev.off()
|
|
43
|
+
|
|
44
|
+
add_report(
|
|
45
|
+
list(
|
|
46
|
+
kind = "descr",
|
|
47
|
+
content = paste0("Dimensionality reduction plot for ", case$group.by)
|
|
48
|
+
),
|
|
49
|
+
list(
|
|
50
|
+
kind = "image",
|
|
51
|
+
src = figfile
|
|
52
|
+
),
|
|
53
|
+
h1 = name
|
|
54
|
+
)
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
sapply(names(dimplots), do_one_dimplot)
|
|
44
|
-
.save_toc()
|