biopipen 0.17.7__py3-none-any.whl → 0.18.0__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 +36 -23
- biopipen/ns/delim.py +1 -1
- biopipen/ns/scrna.py +132 -49
- biopipen/ns/tcr.py +5 -1
- biopipen/reports/scrna/MarkersFinder.svelte +30 -8
- biopipen/reports/scrna/SeuratClusterStats.svelte +64 -109
- biopipen/scripts/delim/SampleInfo.R +18 -15
- biopipen/scripts/scrna/MarkersFinder.R +58 -2
- biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +40 -0
- biopipen/scripts/scrna/SeuratClusterStats-features.R +236 -0
- biopipen/scripts/scrna/SeuratClusterStats-stats.R +105 -0
- biopipen/scripts/scrna/SeuratClusterStats.R +7 -521
- biopipen/scripts/scrna/SeuratClustering.R +20 -1
- biopipen/scripts/tcr/TESSA.R +9 -5
- biopipen/scripts/tcr/TESSA_source/BriseisEncoder.py +2 -2
- biopipen/scripts/tcr/TESSA_source/real_data.R +1 -1
- {biopipen-0.17.7.dist-info → biopipen-0.18.0.dist-info}/METADATA +8 -8
- {biopipen-0.17.7.dist-info → biopipen-0.18.0.dist-info}/RECORD +21 -18
- {biopipen-0.17.7.dist-info → biopipen-0.18.0.dist-info}/WHEEL +0 -0
- {biopipen-0.17.7.dist-info → biopipen-0.18.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,535 +1,21 @@
|
|
|
1
1
|
source("{{biopipen_dir}}/utils/misc.R")
|
|
2
2
|
source("{{biopipen_dir}}/utils/plot.R")
|
|
3
|
+
library(jsonlite)
|
|
4
|
+
library(slugify)
|
|
3
5
|
library(Seurat)
|
|
4
6
|
library(rlang)
|
|
5
7
|
library(dplyr)
|
|
6
8
|
library(tibble)
|
|
7
9
|
library(ggprism)
|
|
10
|
+
library(ggsci)
|
|
11
|
+
library(ggrepel)
|
|
8
12
|
library(tidyseurat)
|
|
9
13
|
|
|
10
14
|
srtfile = {{in.srtobj | r}}
|
|
11
15
|
outdir = {{out.outdir | r}}
|
|
12
|
-
envs = {{envs | r: todot="-"}}
|
|
13
16
|
|
|
14
17
|
srtobj = readRDS(srtfile)
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (is.null(devpars)) {
|
|
20
|
-
devpars = list(res = 100, height = 1000)
|
|
21
|
-
} else {
|
|
22
|
-
devpars$res = if (is.null(devpars$res)) default_devpars$res else devpars$res
|
|
23
|
-
devpars$height = if (is.null(devpars$height)) default_devpars$height else devpars$height
|
|
24
|
-
}
|
|
25
|
-
if (frac) {
|
|
26
|
-
ylab = paste("Fraction of cells")
|
|
27
|
-
mapping_y = "cellFraction"
|
|
28
|
-
} else {
|
|
29
|
-
ylab = paste("Number of cells")
|
|
30
|
-
mapping_y = "nCells"
|
|
31
|
-
}
|
|
32
|
-
df_cells = srtobj@meta.data
|
|
33
|
-
if (!is.null(filtering)) {
|
|
34
|
-
df_cells = df_cells %>% filter(!!rlang::parse_expr(filtering))
|
|
35
|
-
}
|
|
36
|
-
if (is.null(by)) {
|
|
37
|
-
df_cells = df_cells %>%
|
|
38
|
-
group_by(seurat_clusters) %>%
|
|
39
|
-
summarize(nCells = n(), .groups = "keep") %>%
|
|
40
|
-
mutate(cellFraction = nCells / sum(nCells))
|
|
41
|
-
|
|
42
|
-
if (is.null(devpars$width)) { devpars$width = 1000 }
|
|
43
|
-
plotGG(
|
|
44
|
-
df_cells,
|
|
45
|
-
geom = "col",
|
|
46
|
-
args = list(
|
|
47
|
-
mapping = aes_string(x="seurat_clusters", y=mapping_y)
|
|
48
|
-
),
|
|
49
|
-
ggs = c(
|
|
50
|
-
paste0('ggtitle("', ylab, ' for each cluster")'),
|
|
51
|
-
'theme_prism()',
|
|
52
|
-
'theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))',
|
|
53
|
-
paste0('labs(x="Seurat Cluster", y="', ylab, '")')
|
|
54
|
-
),
|
|
55
|
-
devpars = devpars,
|
|
56
|
-
outfile = plotfile
|
|
57
|
-
)
|
|
58
|
-
} else {
|
|
59
|
-
df_cells = df_cells %>%
|
|
60
|
-
group_by(!!sym(by), seurat_clusters) %>%
|
|
61
|
-
summarize(nCells = n()) %>%
|
|
62
|
-
group_by(seurat_clusters) %>%
|
|
63
|
-
mutate(cellFraction = nCells / sum(nCells))
|
|
64
|
-
|
|
65
|
-
if (is.null(devpars$width)) {
|
|
66
|
-
devpars$width = 800 + 200 * ceiling(length(unique(df_cells[[by]])) / 20)
|
|
67
|
-
}
|
|
68
|
-
plotGG(
|
|
69
|
-
df_cells,
|
|
70
|
-
geom = "col",
|
|
71
|
-
args = list(
|
|
72
|
-
mapping = aes_string(x="seurat_clusters", y=mapping_y, fill=by),
|
|
73
|
-
position = "stack"
|
|
74
|
-
),
|
|
75
|
-
ggs = c(
|
|
76
|
-
paste0('ggtitle("', ylab, ' for each cluster by ', by, '")'),
|
|
77
|
-
'theme_prism()',
|
|
78
|
-
'theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))',
|
|
79
|
-
paste0('labs(x="Seurat Cluster", y="', ylab, '")')
|
|
80
|
-
),
|
|
81
|
-
devpars = devpars,
|
|
82
|
-
outfile = plotfile
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
write.table(
|
|
87
|
-
df_cells,
|
|
88
|
-
file = txtfile,
|
|
89
|
-
quote = FALSE,
|
|
90
|
-
sep = "\t",
|
|
91
|
-
row.names = FALSE,
|
|
92
|
-
col.names = TRUE
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
do_stats = function() {
|
|
97
|
-
odir = file.path(outdir, "stats")
|
|
98
|
-
dir.create(odir, showWarnings = FALSE)
|
|
99
|
-
for (name in names(envs$stats)) {
|
|
100
|
-
stat_pars = envs$stats[[name]]
|
|
101
|
-
args = list(
|
|
102
|
-
casename = name,
|
|
103
|
-
devpars = stat_pars$devpars,
|
|
104
|
-
odir = odir,
|
|
105
|
-
by = stat_pars$by,
|
|
106
|
-
frac = FALSE,
|
|
107
|
-
filtering = stat_pars$filter
|
|
108
|
-
)
|
|
109
|
-
if (startsWith(name, "fracCells")) {
|
|
110
|
-
args$frac = TRUE
|
|
111
|
-
} else if (!startsWith(name, "nCells")) {
|
|
112
|
-
warning(paste("Unknown stat:", name, ", skipping"))
|
|
113
|
-
next
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
do_call(do_stats_cells, args)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
.get_outfile = function(odir, prefix, ext = "png") {
|
|
121
|
-
i = 1
|
|
122
|
-
while (TRUE) {
|
|
123
|
-
outfile = file.path(odir, paste0(prefix, "-", i, ".", ext))
|
|
124
|
-
if (!file.exists(outfile)) {
|
|
125
|
-
return(outfile)
|
|
126
|
-
}
|
|
127
|
-
i = i + 1
|
|
128
|
-
}
|
|
129
|
-
return(outfile)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
.get_features = function(features, default_features, default = NULL) {
|
|
133
|
-
if (is.null(default)) {
|
|
134
|
-
default = VariableFeatures(srtobj)
|
|
135
|
-
}
|
|
136
|
-
# When nothing passed, use the genes
|
|
137
|
-
if (is.null(features)) {
|
|
138
|
-
if (is.null(default_features)) {
|
|
139
|
-
return (default[1:20])
|
|
140
|
-
} else {
|
|
141
|
-
return (default_features)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
# When multiple items passed, use them as features
|
|
145
|
-
if (length(features) > 1) {
|
|
146
|
-
return (features)
|
|
147
|
-
}
|
|
148
|
-
# See if it is "default"
|
|
149
|
-
if (is.integer(features)) {
|
|
150
|
-
return (default[1:features])
|
|
151
|
-
}
|
|
152
|
-
# See if it is a file
|
|
153
|
-
if (!file.exists(features)) {
|
|
154
|
-
return (features)
|
|
155
|
-
}
|
|
156
|
-
# length(features) == 1 && file.exists(features[1])
|
|
157
|
-
feats = read.table(features, header = FALSE, row.names = NULL, check.names = FALSE)
|
|
158
|
-
feats$V1
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
do_feats_ridgeplots = function(odir, pms, default_features) {
|
|
162
|
-
outfile = .get_outfile(odir, "ridgeplots")
|
|
163
|
-
|
|
164
|
-
devpars = pms$devpars
|
|
165
|
-
pms$devpars = NULL
|
|
166
|
-
plus = pms$plus
|
|
167
|
-
pms$plus = NULL
|
|
168
|
-
title = pms$title
|
|
169
|
-
pms$title = NULL
|
|
170
|
-
if (is.null(title)) {
|
|
171
|
-
title = tools::file_path_sans_ext(basename(outfile))
|
|
172
|
-
}
|
|
173
|
-
cat(title, file = paste0(outfile, ".title"))
|
|
174
|
-
subsetpms = pms$subset
|
|
175
|
-
pms$subset = NULL
|
|
176
|
-
if (is.null(plus)) {
|
|
177
|
-
plus = c()
|
|
178
|
-
}
|
|
179
|
-
pms$features = .get_features(pms$features, default_features)
|
|
180
|
-
if (is.null(pms$ncol)) {
|
|
181
|
-
pms$ncol = min(2, length(pms$features))
|
|
182
|
-
}
|
|
183
|
-
if (is.null(devpars)) {
|
|
184
|
-
devpars = list(
|
|
185
|
-
width = 400 * pms$ncol,
|
|
186
|
-
height = ceiling(length(pms$features) / pms$ncol) * 400,
|
|
187
|
-
res = 100
|
|
188
|
-
)
|
|
189
|
-
}
|
|
190
|
-
if (is.null(subsetpms)) {
|
|
191
|
-
pms$object = srtobj
|
|
192
|
-
} else {
|
|
193
|
-
pms$object = srtobj %>% filter(eval(parse(text=subsetpms)))
|
|
194
|
-
}
|
|
195
|
-
p = do_call(RidgePlot, pms)
|
|
196
|
-
for (pls in plus) {
|
|
197
|
-
p = p + eval(parse(text = pls))
|
|
198
|
-
}
|
|
199
|
-
devpars$filename = outfile
|
|
200
|
-
do_call(png, devpars)
|
|
201
|
-
print(p)
|
|
202
|
-
dev.off()
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
do_feats_vlnplots = function(odir, pms, default_features) {
|
|
207
|
-
outfile = .get_outfile(odir, "vlnplots")
|
|
208
|
-
|
|
209
|
-
devpars = pms$devpars
|
|
210
|
-
pms$devpars = NULL
|
|
211
|
-
boxplot = pms$boxplot
|
|
212
|
-
pms$boxplot = NULL
|
|
213
|
-
plus = pms$plus
|
|
214
|
-
pms$plus = NULL
|
|
215
|
-
subsetpms = pms$subset
|
|
216
|
-
pms$subset = NULL
|
|
217
|
-
title = pms$title
|
|
218
|
-
pms$title = NULL
|
|
219
|
-
if (is.null(title)) {
|
|
220
|
-
title = tools::file_path_sans_ext(basename(outfile))
|
|
221
|
-
}
|
|
222
|
-
cat(title, file = paste0(outfile, ".title"))
|
|
223
|
-
if (is.null(plus)) {
|
|
224
|
-
plus = c()
|
|
225
|
-
}
|
|
226
|
-
if (!is.null(boxplot) && length(boxplot) == 0) {
|
|
227
|
-
boxplot = list(width = .1, fill = "white")
|
|
228
|
-
}
|
|
229
|
-
pms$features = .get_features(pms$features, default_features)
|
|
230
|
-
if (is.null(pms$ncol)) {
|
|
231
|
-
pms$ncol = min(2, length(pms$features))
|
|
232
|
-
}
|
|
233
|
-
if (is.null(devpars)) {
|
|
234
|
-
devpars = list(
|
|
235
|
-
width = 400 * pms$ncol,
|
|
236
|
-
height = ceiling(length(pms$features) / pms$ncol) * 400,
|
|
237
|
-
res = 100
|
|
238
|
-
)
|
|
239
|
-
}
|
|
240
|
-
if (is.null(subsetpms)) {
|
|
241
|
-
pms$object = srtobj
|
|
242
|
-
} else {
|
|
243
|
-
pms$object = srtobj %>% tidyseurat::filter(eval(parse(text=subsetpms)))
|
|
244
|
-
}
|
|
245
|
-
p = do_call(VlnPlot, pms)
|
|
246
|
-
if (!is.null(boxplot)) {
|
|
247
|
-
p = p + do_call(geom_boxplot, boxplot)
|
|
248
|
-
}
|
|
249
|
-
for (pls in plus) {
|
|
250
|
-
p = p + eval(parse(text = pls))
|
|
251
|
-
}
|
|
252
|
-
devpars$filename = outfile
|
|
253
|
-
do_call(png, devpars)
|
|
254
|
-
print(p)
|
|
255
|
-
dev.off()
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
do_feats_featureplots = function(odir, pms, default_features) {
|
|
260
|
-
outfile = .get_outfile(odir, "featureplots")
|
|
261
|
-
|
|
262
|
-
devpars = pms$devpars
|
|
263
|
-
pms$devpars = NULL
|
|
264
|
-
title = pms$title
|
|
265
|
-
pms$title = NULL
|
|
266
|
-
if (is.null(title)) {
|
|
267
|
-
title = tools::file_path_sans_ext(basename(outfile))
|
|
268
|
-
}
|
|
269
|
-
cat(title, file = paste0(outfile, ".title"))
|
|
270
|
-
pms$features = .get_features(pms$features, default_features)
|
|
271
|
-
if (is.null(pms$ncol)) {
|
|
272
|
-
pms$ncol = min(2, length(pms$features))
|
|
273
|
-
}
|
|
274
|
-
if (is.null(devpars)) {
|
|
275
|
-
devpars = list(
|
|
276
|
-
width = 400 * pms$ncol,
|
|
277
|
-
height = ceiling(length(pms$features) / pms$ncol) * 300,
|
|
278
|
-
res = 100
|
|
279
|
-
)
|
|
280
|
-
}
|
|
281
|
-
subsetpms = pms$subset
|
|
282
|
-
pms$subset = NULL
|
|
283
|
-
if (is.null(subsetpms)) {
|
|
284
|
-
pms$object = srtobj
|
|
285
|
-
} else {
|
|
286
|
-
pms$object = srtobj %>% filter(eval(parse(text=subsetpms)))
|
|
287
|
-
}
|
|
288
|
-
p = do_call(FeaturePlot, pms)
|
|
289
|
-
devpars$filename = outfile
|
|
290
|
-
|
|
291
|
-
tryCatch({
|
|
292
|
-
do_call(png, devpars)
|
|
293
|
-
print(p)
|
|
294
|
-
dev.off()
|
|
295
|
-
}, error = function(e) {
|
|
296
|
-
stop(
|
|
297
|
-
paste(
|
|
298
|
-
paste(names(devpars), collapse=" "),
|
|
299
|
-
paste(devpars, collapse=" "),
|
|
300
|
-
e,
|
|
301
|
-
sep = "\n"
|
|
302
|
-
)
|
|
303
|
-
)
|
|
304
|
-
})
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
do_feats_dotplot = function(odir, pms, default_features) {
|
|
308
|
-
outfile = .get_outfile(odir, "dotplot")
|
|
309
|
-
|
|
310
|
-
devpars = pms$devpars
|
|
311
|
-
pms$devpars = NULL
|
|
312
|
-
plus = pms$plus
|
|
313
|
-
pms$plus = NULL
|
|
314
|
-
subsetpms = pms$subset
|
|
315
|
-
pms$subset = NULL
|
|
316
|
-
title = pms$title
|
|
317
|
-
pms$title = NULL
|
|
318
|
-
if (is.null(title)) {
|
|
319
|
-
title = tools::file_path_sans_ext(basename(outfile))
|
|
320
|
-
}
|
|
321
|
-
cat(title, file = paste0(outfile, ".title"))
|
|
322
|
-
if (is.null(plus)) {
|
|
323
|
-
plus = c()
|
|
324
|
-
}
|
|
325
|
-
pms$features = .get_features(pms$features, default_features)
|
|
326
|
-
if (is.null(devpars)) {
|
|
327
|
-
devpars = list(
|
|
328
|
-
height = length(unique(srtobj@meta.data$seurat_clusters)) * 80 + 150,
|
|
329
|
-
width = length(pms$features) * 50 + 150,
|
|
330
|
-
res = 100
|
|
331
|
-
)
|
|
332
|
-
}
|
|
333
|
-
if (is.null(subsetpms)) {
|
|
334
|
-
pms$object = srtobj
|
|
335
|
-
} else {
|
|
336
|
-
pms$object = srtobj %>% filter(eval(parse(text=subsetpms)))
|
|
337
|
-
}
|
|
338
|
-
p = do_call(DotPlot, pms)
|
|
339
|
-
for (pls in plus) {
|
|
340
|
-
p = p + eval(parse(text = pls))
|
|
341
|
-
}
|
|
342
|
-
devpars$filename = outfile
|
|
343
|
-
tryCatch({
|
|
344
|
-
do_call(png, devpars)
|
|
345
|
-
print(p)
|
|
346
|
-
dev.off()
|
|
347
|
-
}, error = function(e) {
|
|
348
|
-
stop(
|
|
349
|
-
paste(
|
|
350
|
-
paste(names(devpars), collapse=" "),
|
|
351
|
-
paste(devpars, collapse=" "),
|
|
352
|
-
e,
|
|
353
|
-
sep = "\n"
|
|
354
|
-
)
|
|
355
|
-
)
|
|
356
|
-
})
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
do_feats_heatmap = function(odir, pms, default_features) {
|
|
361
|
-
outfile = .get_outfile(odir, "heatmap")
|
|
362
|
-
|
|
363
|
-
devpars = pms$devpars
|
|
364
|
-
pms$devpars = NULL
|
|
365
|
-
plus = pms$plus
|
|
366
|
-
pms$plus = NULL
|
|
367
|
-
subsetpms = pms$subset
|
|
368
|
-
pms$subset = NULL
|
|
369
|
-
title = pms$title
|
|
370
|
-
pms$title = NULL
|
|
371
|
-
if (is.null(title)) {
|
|
372
|
-
title = tools::file_path_sans_ext(basename(outfile))
|
|
373
|
-
}
|
|
374
|
-
cat(title, file = paste0(outfile, ".title"))
|
|
375
|
-
if (is.null(plus)) {
|
|
376
|
-
plus = c()
|
|
377
|
-
}
|
|
378
|
-
pms$features = .get_features(pms$features, default_features)
|
|
379
|
-
if (is.null(devpars)) {
|
|
380
|
-
devpars = list(
|
|
381
|
-
width = length(unique(srtobj@meta.data$seurat_clusters)) * 60 + 150,
|
|
382
|
-
height = length(pms$features) * 40 + 150,
|
|
383
|
-
res = 100
|
|
384
|
-
)
|
|
385
|
-
}
|
|
386
|
-
downsample = pms$downsample
|
|
387
|
-
pms$downsample = NULL
|
|
388
|
-
|
|
389
|
-
if (is.null(subsetpms)) {
|
|
390
|
-
sobj = srtobj
|
|
391
|
-
} else {
|
|
392
|
-
sobj = srtobj %>% filter(eval(parse(text=subsetpms)))
|
|
393
|
-
}
|
|
394
|
-
if (is.null(downsample)) {
|
|
395
|
-
pms$object = sobj
|
|
396
|
-
warn(
|
|
397
|
-
paste0(
|
|
398
|
-
"DoHeatmap: `downsample` not specified, using full data. ",
|
|
399
|
-
"This may cause a blank heatmap. ",
|
|
400
|
-
"See: https://github.com/satijalab/seurat/issues/2724"
|
|
401
|
-
),
|
|
402
|
-
immediate. = TRUE
|
|
403
|
-
)
|
|
404
|
-
} else if (downsample %in% c("average", "mean")) {
|
|
405
|
-
pms$object = AverageExpression(sobj, return.seurat = TRUE)
|
|
406
|
-
} else {
|
|
407
|
-
pms$object = subset(sobj, downsample = downsample)
|
|
408
|
-
}
|
|
409
|
-
p = do_call(DoHeatmap, pms)
|
|
410
|
-
for (pls in plus) {
|
|
411
|
-
p = p + eval(parse(text = pls))
|
|
412
|
-
}
|
|
413
|
-
mapal = colorRampPalette(RColorBrewer::brewer.pal(11,"RdBu"))(256)
|
|
414
|
-
p = p + scale_fill_gradientn(colours = rev(mapal))
|
|
415
|
-
devpars$filename = outfile
|
|
416
|
-
do_call(png, devpars)
|
|
417
|
-
print(p)
|
|
418
|
-
dev.off()
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
do_feats_table = function(odir, pms, default_features) {
|
|
423
|
-
outfile = .get_outfile(odir, "table", "tsv")
|
|
424
|
-
|
|
425
|
-
subsetpms = pms$subset
|
|
426
|
-
log2_scale = pms$log2
|
|
427
|
-
if (is.null(log2_scale)) { log2_scale = TRUE }
|
|
428
|
-
features = .get_features(pms$features, default_features)
|
|
429
|
-
title = pms$title
|
|
430
|
-
if (is.null(title)) { title = tools::file_path_sans_ext(basename(outfile)) }
|
|
431
|
-
cat(title, file = paste0(outfile, ".title"))
|
|
432
|
-
|
|
433
|
-
if (is.null(subsetpms)) {
|
|
434
|
-
sobj = srtobj
|
|
435
|
-
} else {
|
|
436
|
-
sobj = srtobj %>% filter(eval(parse(text=subsetpms)))
|
|
437
|
-
}
|
|
438
|
-
# default slot (data), assay
|
|
439
|
-
# values are exponentiated prior to averaging so that averaging is done in non-log space.
|
|
440
|
-
avgdata = AverageExpression(sobj, features = features)
|
|
441
|
-
edata = avgdata$RNA
|
|
442
|
-
# replace the missing genes
|
|
443
|
-
edata[rownames(avgdata$integrated), ] = avgdata$integrated
|
|
444
|
-
if (log2_scale) { edata = log2(edata) }
|
|
445
|
-
edata = as.data.frame(edata) %>%
|
|
446
|
-
rownames_to_column("Gene") %>%
|
|
447
|
-
select(Gene, everything())
|
|
448
|
-
write.table(edata, file = outfile, sep = "\t", quote = FALSE, row.names = FALSE, col.names = TRUE)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
do_feats = function() {
|
|
453
|
-
if (length(envs$features) == 0) {
|
|
454
|
-
return (NULL)
|
|
455
|
-
}
|
|
456
|
-
odir = file.path(outdir, "features")
|
|
457
|
-
dir.create(odir, showWarnings = FALSE)
|
|
458
|
-
default_features = envs$features$features
|
|
459
|
-
envs$features$features = NULL
|
|
460
|
-
if (!is.null(default_features) && is.character(default_features) && file.exists(default_features)) {
|
|
461
|
-
default_features = read.table(default_features, header = FALSE, sep = "\t", row.names = NULL, check.names = FALSE)
|
|
462
|
-
default_features = default_features[,1,drop=TRUE]
|
|
463
|
-
} else if (!is.null(default_features) && is.character(default_features)) {
|
|
464
|
-
default_features = trimws(strsplit(default_features, ",")[[1]])
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
exprplots = names(envs$features)
|
|
468
|
-
for (name in exprplots) {
|
|
469
|
-
cat(paste0("Expr plot: ", name, " ...\n"), file = stderr())
|
|
470
|
-
if (startsWith(name, "ridgeplots")) {
|
|
471
|
-
do_feats_ridgeplots(odir, envs$features[[name]], default_features)
|
|
472
|
-
} else if (startsWith(name, "vlnplots")) {
|
|
473
|
-
do_feats_vlnplots(odir, envs$features[[name]], default_features)
|
|
474
|
-
} else if (startsWith(name, "featureplots")) {
|
|
475
|
-
do_feats_featureplots(odir, envs$features[[name]], default_features)
|
|
476
|
-
} else if (startsWith(name, "dotplot")) {
|
|
477
|
-
do_feats_dotplot(odir, envs$features[[name]], default_features)
|
|
478
|
-
} else if (startsWith(name, "heatmap")) {
|
|
479
|
-
do_feats_heatmap(odir, envs$features[[name]], default_features)
|
|
480
|
-
} else if (startsWith(name, "table")) {
|
|
481
|
-
do_feats_table(odir, envs$features[[name]], default_features)
|
|
482
|
-
} else {
|
|
483
|
-
print(paste("Unrecognized expression plot type: ", name))
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
do_dimplot = function(odir, dpname, dpenvs) {
|
|
489
|
-
devpars = dpenvs$devpars
|
|
490
|
-
dpenvs$devpars = NULL
|
|
491
|
-
if (is.null(devpars)) {
|
|
492
|
-
devpars = list(
|
|
493
|
-
width = 1000,
|
|
494
|
-
height = 1000,
|
|
495
|
-
res = 100
|
|
496
|
-
)
|
|
497
|
-
}
|
|
498
|
-
plus = dpenvs$plus
|
|
499
|
-
dpenvs$plus = NULL
|
|
500
|
-
if (is.null(plus)) {
|
|
501
|
-
plus = c()
|
|
502
|
-
}
|
|
503
|
-
if (!any(grepl("ggtitle(", plus, fixed=T))) {
|
|
504
|
-
plus = c(plus, paste0("ggtitle(", dQuote(dpname, q=F), ")"))
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
dpenvs$object = srtobj
|
|
508
|
-
p = do_call(DimPlot, dpenvs)
|
|
509
|
-
for (pls in plus) {
|
|
510
|
-
p = p + eval(parse(text = pls))
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
devpars$filename = file.path(odir, paste0(slugify(dpname), ".png"))
|
|
514
|
-
do_call(png, devpars)
|
|
515
|
-
print(p)
|
|
516
|
-
dev.off()
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
do_dimplots = function() {
|
|
520
|
-
if (length(envs$dimplots) == 0) {
|
|
521
|
-
return (NULL)
|
|
522
|
-
}
|
|
523
|
-
odir = file.path(outdir, "dimplots")
|
|
524
|
-
dir.create(odir, showWarnings = FALSE)
|
|
525
|
-
|
|
526
|
-
for (dpname in names(envs$dimplots)) {
|
|
527
|
-
dpenvs = envs$dimplots[[dpname]]
|
|
528
|
-
do_dimplot(odir, dpname, dpenvs)
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
do_stats()
|
|
534
|
-
do_feats()
|
|
535
|
-
do_dimplots()
|
|
19
|
+
{% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-stats.R" %}
|
|
20
|
+
{% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-features.R" %}
|
|
21
|
+
{% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-dimplots.R" %}
|
|
@@ -114,7 +114,26 @@ id_args = list_setdefault(
|
|
|
114
114
|
dims = 1:30
|
|
115
115
|
)
|
|
116
116
|
id_args$dims = 1:min(min_dim, max(id_args$dims))
|
|
117
|
-
|
|
117
|
+
tryCatch({
|
|
118
|
+
obj_list = do_call(IntegrateData, id_args)
|
|
119
|
+
}, error = function(e) {
|
|
120
|
+
msg = ""
|
|
121
|
+
if (grepl("number of items to replace is not a multiple of replacement length", e)) {
|
|
122
|
+
default_kweight = 100
|
|
123
|
+
if (!is.null(envs$IntegrateData$k.weight)) {
|
|
124
|
+
default_kweight = envs$IntegrateData$k.weight
|
|
125
|
+
}
|
|
126
|
+
msg = paste0(
|
|
127
|
+
"It's possible that you have too few cells in some samples, ",
|
|
128
|
+
"causing a small number of anchor cells in the anchorset. \n",
|
|
129
|
+
" Try changing `k.weight` for `IntegrateData` by setting ",
|
|
130
|
+
"`envs.IntegrateData.k-weight` to a smaller number (it's now ",
|
|
131
|
+
default_kweight, "). \n",
|
|
132
|
+
" See also https://github.com/satijalab/seurat/issues/6341"
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
stop(paste0(msg, "\n", e))
|
|
136
|
+
})
|
|
118
137
|
|
|
119
138
|
{%- else -%}
|
|
120
139
|
# ############################
|
biopipen/scripts/tcr/TESSA.R
CHANGED
|
@@ -13,6 +13,7 @@ exprfile <- {{in.srtobj | r}}
|
|
|
13
13
|
outfile <- {{out.outfile | r}}
|
|
14
14
|
python <- {{envs.python | r}}
|
|
15
15
|
within_sample <- {{envs.within_sample | r}}
|
|
16
|
+
assay <- {{envs.assay | r}}
|
|
16
17
|
predefined_b <- {{envs.predefined_b | r}}
|
|
17
18
|
max_iter <- {{envs.max_iter | int}}
|
|
18
19
|
tessa_srcdir <- "{{biopipen_dir}}/scripts/tcr/TESSA_source"
|
|
@@ -55,15 +56,18 @@ tcrdata <- do_call(rbind, lapply(seq_len(nrow(immdata$meta)), function(i) {
|
|
|
55
56
|
mutate(Barcode = glue("{{envs.prefix}}{Barcode}"), sample = Sample)
|
|
56
57
|
}))
|
|
57
58
|
if (has_VJ) {
|
|
58
|
-
tcrdata <- tcrdata %>%
|
|
59
|
+
tcrdata <- tcrdata %>% dplyr::mutate(
|
|
60
|
+
v_gene = sub("-\\d+$", "", V.name),
|
|
61
|
+
j_gene = sub("-\\d+$", "", J.name)
|
|
62
|
+
) %>% dplyr::select(
|
|
59
63
|
contig_id = Barcode,
|
|
60
64
|
cdr3 = CDR3.aa,
|
|
61
|
-
v_gene
|
|
62
|
-
j_gene
|
|
65
|
+
v_gene,
|
|
66
|
+
j_gene,
|
|
63
67
|
sample
|
|
64
68
|
)
|
|
65
69
|
} else {
|
|
66
|
-
tcrdata <- tcrdata %>% select(
|
|
70
|
+
tcrdata <- tcrdata %>% dplyr::select(
|
|
67
71
|
contig_id = Barcode,
|
|
68
72
|
cdr3 = CDR3.aa,
|
|
69
73
|
sample
|
|
@@ -77,7 +81,7 @@ is_gz <- endsWith(tolower(exprfile), ".gz")
|
|
|
77
81
|
|
|
78
82
|
if (is_seurat) {
|
|
79
83
|
sobj <- readRDS(exprfile)
|
|
80
|
-
expr <- GetAssayData(sobj)
|
|
84
|
+
expr <- GetAssayData(sobj, slot = "data", assay = assay)
|
|
81
85
|
} else if (is_gz) {
|
|
82
86
|
expr <- read.table(gzfile(exprfile), sep="\t", header=TRUE, row.names=1)
|
|
83
87
|
} else {
|
|
@@ -59,7 +59,7 @@ def preprocess(filedir):
|
|
|
59
59
|
dataset = pd.read_csv(filedir, header=0)
|
|
60
60
|
if dataset.isnull().values.any():
|
|
61
61
|
print("Input data contains NAs.")
|
|
62
|
-
dataset = dataset.dropna()
|
|
62
|
+
# dataset = dataset.dropna()
|
|
63
63
|
data_new = pd.DataFrame(
|
|
64
64
|
{
|
|
65
65
|
"contig_id": dataset["contig_id"],
|
|
@@ -119,7 +119,7 @@ def embedVJ(genelist, maplist):
|
|
|
119
119
|
ind[find] = 1
|
|
120
120
|
VJ_array.append(ind)
|
|
121
121
|
except ValueError:
|
|
122
|
-
print("Gene out of bound!" + gene)
|
|
122
|
+
print("Gene out of bound!" + str(gene))
|
|
123
123
|
VJ_array.append(ind)
|
|
124
124
|
next
|
|
125
125
|
return np.asarray(VJ_array)
|
|
@@ -31,7 +31,7 @@ run_tessa <- function(
|
|
|
31
31
|
# (optional) sample_id: a column vector of sample categories. If is_sampleCluster=TRUE, users must provide an additional
|
|
32
32
|
# column next to the cdr3 column.
|
|
33
33
|
# (optional) fixed_b: a vector of pre-defined b. The vector must be numerical and has the length of TCR embeddings.
|
|
34
|
-
exp_data <- read.csv(exp_file, row.names=1, stringsAsFactors=F)
|
|
34
|
+
exp_data <- read.csv(exp_file, row.names=1, stringsAsFactors=F, check.names = FALSE)
|
|
35
35
|
n <- ncol(exp_data)
|
|
36
36
|
tmp <- apply(exp_data, 1, sd)
|
|
37
37
|
# Run TSNE
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: biopipen
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.18.0
|
|
4
4
|
Summary: Bioinformatics processes/pipelines that can be run from `pipen run`
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: pwwang
|
|
@@ -13,10 +13,10 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Provides-Extra: runinfo
|
|
16
|
-
Requires-Dist: datar[pandas] (>=0.
|
|
17
|
-
Requires-Dist: pipen (>=0.
|
|
18
|
-
Requires-Dist: pipen-board[report] (>=0.
|
|
19
|
-
Requires-Dist: pipen-cli-run (>=0.
|
|
20
|
-
Requires-Dist: pipen-filters (>=0.
|
|
21
|
-
Requires-Dist: pipen-runinfo (>=0.
|
|
22
|
-
Requires-Dist: pipen-verbose (>=0.
|
|
16
|
+
Requires-Dist: datar[pandas] (>=0.15.2,<0.16.0)
|
|
17
|
+
Requires-Dist: pipen (>=0.11,<0.12)
|
|
18
|
+
Requires-Dist: pipen-board[report] (>=0.12,<0.13)
|
|
19
|
+
Requires-Dist: pipen-cli-run (>=0.10,<0.11)
|
|
20
|
+
Requires-Dist: pipen-filters (>=0.9,<0.10)
|
|
21
|
+
Requires-Dist: pipen-runinfo (>=0.3,<0.4) ; extra == "runinfo"
|
|
22
|
+
Requires-Dist: pipen-verbose (>=0.8,<0.9)
|