biopipen 0.33.0__py3-none-any.whl → 0.34.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 +10 -183
- biopipen/core/proc.py +5 -3
- biopipen/core/testing.py +8 -1
- biopipen/ns/bam.py +40 -4
- biopipen/ns/cnv.py +1 -1
- biopipen/ns/cnvkit.py +1 -1
- biopipen/ns/delim.py +1 -1
- biopipen/ns/gsea.py +63 -37
- biopipen/ns/misc.py +38 -0
- biopipen/ns/plot.py +8 -0
- biopipen/ns/scrna.py +307 -288
- biopipen/ns/scrna_metabolic_landscape.py +207 -366
- biopipen/ns/tcr.py +165 -97
- biopipen/reports/bam/CNVpytor.svelte +4 -9
- biopipen/reports/cnvkit/CNVkitDiagram.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitHeatmap.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitScatter.svelte +1 -1
- biopipen/reports/{delim/SampleInfo.svelte → common.svelte} +2 -3
- biopipen/reports/scrna/DimPlots.svelte +1 -1
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +51 -22
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +46 -42
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +63 -6
- biopipen/reports/snp/PlinkCallRate.svelte +2 -2
- biopipen/reports/snp/PlinkFreq.svelte +1 -1
- biopipen/reports/snp/PlinkHWE.svelte +1 -1
- biopipen/reports/snp/PlinkHet.svelte +1 -1
- biopipen/reports/snp/PlinkIBD.svelte +1 -1
- biopipen/reports/tcr/CDR3AAPhyschem.svelte +1 -1
- biopipen/scripts/bam/CNAClinic.R +41 -6
- biopipen/scripts/bam/CNVpytor.py +2 -1
- biopipen/scripts/bam/ControlFREEC.py +2 -3
- biopipen/scripts/bam/SamtoolsView.py +33 -0
- biopipen/scripts/cnv/AneuploidyScore.R +25 -13
- biopipen/scripts/cnv/AneuploidyScoreSummary.R +218 -163
- biopipen/scripts/cnv/TMADScore.R +4 -4
- biopipen/scripts/cnv/TMADScoreSummary.R +51 -84
- biopipen/scripts/cnvkit/CNVkitGuessBaits.py +3 -3
- biopipen/scripts/cnvkit/CNVkitHeatmap.py +3 -3
- biopipen/scripts/cnvkit/CNVkitReference.py +3 -3
- biopipen/scripts/delim/RowsBinder.R +1 -1
- biopipen/scripts/delim/SampleInfo.R +14 -2
- biopipen/scripts/gene/GeneNameConversion.R +14 -12
- biopipen/scripts/gsea/Enrichr.R +2 -2
- biopipen/scripts/gsea/FGSEA.R +184 -50
- biopipen/scripts/gsea/PreRank.R +3 -3
- biopipen/scripts/misc/Plot.R +80 -0
- biopipen/scripts/plot/VennDiagram.R +2 -2
- biopipen/scripts/protein/ProdigySummary.R +34 -27
- biopipen/scripts/regulatory/MotifAffinityTest.R +11 -9
- biopipen/scripts/regulatory/MotifAffinityTest_AtSNP.R +5 -5
- biopipen/scripts/regulatory/MotifAffinityTest_MotifBreakR.R +4 -4
- biopipen/scripts/regulatory/VariantMotifPlot.R +10 -8
- biopipen/scripts/regulatory/motifs-common.R +10 -9
- biopipen/scripts/rnaseq/Simulation-ESCO.R +14 -11
- biopipen/scripts/rnaseq/Simulation-RUVcorr.R +7 -4
- biopipen/scripts/rnaseq/Simulation.R +0 -2
- biopipen/scripts/rnaseq/UnitConversion.R +6 -5
- biopipen/scripts/scrna/AnnData2Seurat.R +25 -73
- biopipen/scripts/scrna/CellCellCommunication.py +1 -1
- biopipen/scripts/scrna/CellCellCommunicationPlots.R +51 -168
- biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +99 -150
- biopipen/scripts/scrna/CellTypeAnnotation-direct.R +11 -9
- biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +12 -9
- biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +14 -11
- biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +19 -16
- biopipen/scripts/scrna/CellTypeAnnotation.R +10 -2
- biopipen/scripts/scrna/CellsDistribution.R +1 -1
- biopipen/scripts/scrna/ExprImputation-alra.R +87 -11
- biopipen/scripts/scrna/ExprImputation-rmagic.R +247 -21
- biopipen/scripts/scrna/ExprImputation-scimpute.R +8 -5
- biopipen/scripts/scrna/LoomTo10X.R +51 -0
- biopipen/scripts/scrna/MarkersFinder.R +348 -217
- biopipen/scripts/scrna/MetaMarkers.R +3 -3
- biopipen/scripts/scrna/ModuleScoreCalculator.R +14 -13
- biopipen/scripts/scrna/RadarPlots.R +1 -1
- biopipen/scripts/scrna/ScFGSEA.R +157 -75
- biopipen/scripts/scrna/ScSimulation.R +11 -10
- biopipen/scripts/scrna/ScVelo.py +605 -0
- biopipen/scripts/scrna/Seurat2AnnData.R +2 -3
- biopipen/scripts/scrna/SeuratClusterStats-clustree.R +1 -1
- biopipen/scripts/scrna/SeuratClusterStats-features.R +39 -30
- biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +56 -65
- biopipen/scripts/scrna/SeuratClusterStats-stats.R +4 -4
- biopipen/scripts/scrna/SeuratClusterStats.R +9 -6
- biopipen/scripts/scrna/SeuratClustering.R +31 -48
- biopipen/scripts/scrna/SeuratLoading.R +2 -2
- biopipen/scripts/scrna/SeuratMap2Ref.R +66 -367
- biopipen/scripts/scrna/SeuratMetadataMutater.R +5 -7
- biopipen/scripts/scrna/SeuratPreparing.R +76 -24
- biopipen/scripts/scrna/SeuratSubClustering.R +46 -185
- biopipen/scripts/scrna/{SlingShot.R → Slingshot.R} +12 -16
- biopipen/scripts/scrna/Subset10X.R +2 -2
- biopipen/scripts/scrna/TopExpressingGenes.R +141 -184
- biopipen/scripts/scrna/celltypist-wrapper.py +6 -4
- biopipen/scripts/scrna/seurat_anndata_conversion.py +81 -0
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +429 -123
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +346 -245
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +182 -173
- biopipen/scripts/snp/MatrixEQTL.R +39 -20
- biopipen/scripts/snp/PlinkCallRate.R +43 -34
- biopipen/scripts/snp/PlinkFreq.R +34 -41
- biopipen/scripts/snp/PlinkHWE.R +23 -18
- biopipen/scripts/snp/PlinkHet.R +26 -22
- biopipen/scripts/snp/PlinkIBD.R +30 -34
- biopipen/scripts/stats/ChowTest.R +9 -8
- biopipen/scripts/stats/DiffCoexpr.R +13 -11
- biopipen/scripts/stats/LiquidAssoc.R +7 -8
- biopipen/scripts/stats/Mediation.R +8 -8
- biopipen/scripts/stats/MetaPvalue.R +11 -13
- biopipen/scripts/stats/MetaPvalue1.R +6 -5
- biopipen/scripts/tcr/CDR3AAPhyschem.R +105 -164
- biopipen/scripts/tcr/ClonalStats.R +5 -4
- biopipen/scripts/tcr/CloneResidency.R +3 -3
- biopipen/scripts/tcr/CloneSizeQQPlot.R +2 -2
- biopipen/scripts/tcr/Immunarch2VDJtools.R +2 -2
- biopipen/scripts/tcr/ImmunarchFilter.R +3 -3
- biopipen/scripts/tcr/ImmunarchLoading.R +5 -5
- biopipen/scripts/tcr/ScRepCombiningExpression.R +39 -0
- biopipen/scripts/tcr/ScRepLoading.R +114 -92
- biopipen/scripts/tcr/TCRClusterStats.R +2 -2
- biopipen/scripts/tcr/TCRClustering.R +86 -97
- biopipen/scripts/tcr/TESSA.R +65 -115
- biopipen/scripts/tcr/VJUsage.R +5 -5
- biopipen/scripts/vcf/TruvariBenchSummary.R +15 -11
- biopipen/utils/common_docstrs.py +66 -63
- biopipen/utils/reporter.py +177 -0
- {biopipen-0.33.0.dist-info → biopipen-0.34.0.dist-info}/METADATA +2 -1
- {biopipen-0.33.0.dist-info → biopipen-0.34.0.dist-info}/RECORD +131 -144
- {biopipen-0.33.0.dist-info → biopipen-0.34.0.dist-info}/WHEEL +1 -1
- biopipen/reports/scrna/CellCellCommunicationPlots.svelte +0 -14
- biopipen/reports/scrna/SeuratClusterStats.svelte +0 -16
- biopipen/reports/scrna/SeuratMap2Ref.svelte +0 -37
- biopipen/reports/scrna/SeuratPreparing.svelte +0 -15
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +0 -28
- biopipen/reports/utils/gsea.liq +0 -110
- biopipen/scripts/scrna/CellTypeAnnotation-common.R +0 -10
- biopipen/scripts/scrna/SeuratClustering-common.R +0 -213
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +0 -193
- biopipen/utils/caching.R +0 -44
- biopipen/utils/gene.R +0 -95
- biopipen/utils/gsea.R +0 -329
- biopipen/utils/io.R +0 -20
- biopipen/utils/misc.R +0 -602
- biopipen/utils/mutate_helpers.R +0 -581
- biopipen/utils/plot.R +0 -209
- biopipen/utils/repr.R +0 -146
- biopipen/utils/rnaseq.R +0 -48
- biopipen/utils/single_cell.R +0 -207
- {biopipen-0.33.0.dist-info → biopipen-0.34.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,203 +1,64 @@
|
|
|
1
|
-
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
-
{{ biopipen_dir | joinpaths: "utils", "caching.R" | source_r }}
|
|
3
1
|
|
|
4
2
|
library(Seurat)
|
|
5
3
|
library(future)
|
|
6
|
-
library(
|
|
7
|
-
library(tidyr)
|
|
8
|
-
library(dplyr)
|
|
9
|
-
library(tidyseurat)
|
|
10
|
-
library(digest)
|
|
4
|
+
library(biopipen.utils)
|
|
11
5
|
|
|
12
6
|
set.seed(8525)
|
|
13
7
|
|
|
14
|
-
srtfile <- {{in.srtobj |
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
srtfile <- {{in.srtobj | r}}
|
|
9
|
+
outfile <- {{out.outfile | r}}
|
|
10
|
+
ncores <- {{envs.ncores | r}}
|
|
11
|
+
mutaters <- {{envs.mutaters | r}}
|
|
12
|
+
subset <- {{envs.subset | r}}
|
|
13
|
+
cache <- {{envs.cache | r}}
|
|
14
|
+
RunPCAArgs <- {{envs.RunPCA | r: todot = "-"}}
|
|
15
|
+
RunUMAPArgs <- {{envs.RunUMAP | r: todot = "-"}}
|
|
16
|
+
FindNeighborsArgs <- {{envs.FindNeighbors | r: todot = "-"}}
|
|
17
|
+
FindClustersArgs <- {{envs.FindClusters | r: todot = "-"}}
|
|
18
|
+
cases <- {{envs.cases | r}}
|
|
18
19
|
|
|
19
|
-
options(str = strOptions(vec.len = 5, digits.d = 5))
|
|
20
20
|
options(future.globals.maxSize = 80000 * 1024^2)
|
|
21
|
-
plan(strategy = "multicore", workers =
|
|
21
|
+
plan(strategy = "multicore", workers = ncores)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
# Expand dims from 30 to 1:30
|
|
25
|
-
if (!is.null(args) && is.numeric(args[[name]]) && length(args[[name]] == 1)) {
|
|
26
|
-
args[[name]] <- 1:args[[name]]
|
|
27
|
-
}
|
|
28
|
-
args
|
|
29
|
-
}
|
|
23
|
+
log <- get_logger()
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
parts <- trimws(unlist(strsplit(res, ",")))
|
|
39
|
-
for (part in parts) {
|
|
40
|
-
if (grepl(":", part)) {
|
|
41
|
-
ps <- trimws(unlist(strsplit(part, ":")))
|
|
42
|
-
if (length(ps) == 2) { ps <- c(ps, 0.1) }
|
|
43
|
-
if (length(ps) != 3) {
|
|
44
|
-
stop("Invalid resolution format: {part}. Expected 2 or 3 parts separated by ':' for a range.")
|
|
45
|
-
}
|
|
46
|
-
ps <- as.numeric(ps)
|
|
47
|
-
expanded_res <- c(expanded_res, seq(ps[1], ps[2], by = ps[3]))
|
|
48
|
-
} else {
|
|
49
|
-
expanded_res <- c(expanded_res, as.numeric(part))
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
# keep the last resolution at last
|
|
55
|
-
rev(unique(rev(round(expanded_res, 2))))
|
|
56
|
-
}
|
|
25
|
+
cases <- expand_cases(cases, defaults = list(
|
|
26
|
+
RunPCA = RunPCAArgs,
|
|
27
|
+
RunUMAP = RunUMAPArgs,
|
|
28
|
+
FindNeighbors = FindNeighborsArgs,
|
|
29
|
+
FindClusters = FindClustersArgs,
|
|
30
|
+
subset = subset
|
|
31
|
+
))
|
|
57
32
|
|
|
58
|
-
|
|
59
|
-
.recode_clusters <- function(clusters) {
|
|
60
|
-
recode <- function(x) paste0("s", as.integer(as.character(x)) + 1)
|
|
61
|
-
clusters <- factor(recode(clusters), levels = recode(levels(clusters)))
|
|
62
|
-
clusters
|
|
63
|
-
}
|
|
33
|
+
if (isTRUE(cache)) {}
|
|
64
34
|
|
|
65
|
-
|
|
66
|
-
|
|
35
|
+
log$info("Reading Seurat object ...")
|
|
36
|
+
object <- read_obj(srtfile)
|
|
67
37
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
envs$cache <- envs$cache[1]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!is.null(envs$mutaters) && length(envs$mutaters) > 0) {
|
|
78
|
-
log_info("Mutating Seurat object ...")
|
|
79
|
-
srtobj@meta.data <- srtobj@meta.data %>%
|
|
80
|
-
mutate(!!!lapply(mutaters, parse_expr))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (length(envs$cases) == 0) {
|
|
84
|
-
envs$cases <- list(subcluster = list())
|
|
38
|
+
if (!is.null(mutaters) && length(mutaters) > 0) {
|
|
39
|
+
log$info("Mutating meta data ...")
|
|
40
|
+
object@meta.data <- mutate(
|
|
41
|
+
object@meta.data,
|
|
42
|
+
!!!lapply(mutaters, parse_expr)
|
|
43
|
+
)
|
|
85
44
|
}
|
|
86
45
|
|
|
87
|
-
for (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
),
|
|
102
|
-
case
|
|
46
|
+
for (name in names(cases)) {
|
|
47
|
+
case <- cases[[name]]
|
|
48
|
+
log$info("Processing case '{name}' ...")
|
|
49
|
+
|
|
50
|
+
object <- RunSeuratSubClustering(
|
|
51
|
+
object = object,
|
|
52
|
+
subset = case$subset,
|
|
53
|
+
name = name,
|
|
54
|
+
RunPCAArgs = case$RunPCAArgs,
|
|
55
|
+
RunUMAPArgs = case$RunUMAPArgs,
|
|
56
|
+
FindNeighborsArgs = case$FindNeighborsArgs,
|
|
57
|
+
FindClustersArgs = case$FindClustersArgs,
|
|
58
|
+
log = log,
|
|
59
|
+
cache = cache
|
|
103
60
|
)
|
|
104
|
-
|
|
105
|
-
if (is.null(case$subset) || length(case$subset) == 0) {
|
|
106
|
-
stop(paste0("`subset` for case '", key, "' is empty."))
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
log_info("- Subsetting ...")
|
|
110
|
-
sobj <- tryCatch({
|
|
111
|
-
srtobj %>% filter(!!parse_expr(case$subset))
|
|
112
|
-
}, error = function(e) {
|
|
113
|
-
stop(paste0(" Error in subset: ", e$message))
|
|
114
|
-
})
|
|
115
|
-
sobj_sig <- capture.output(str(sobj))
|
|
116
|
-
dig_sig <- digest::digest(sobj_sig, algo = "md5")
|
|
117
|
-
dig_sig <- substr(dig_sig, 1, 8)
|
|
118
|
-
cache_dir <- NULL
|
|
119
|
-
if (is.character(envs$cache)) {
|
|
120
|
-
cache_dir <- file.path(envs$cache, paste0(dig_sig, ".seurat_cache"))
|
|
121
|
-
dir.create(cache_dir, recursive = TRUE, showWarnings = FALSE)
|
|
122
|
-
writeLines(sobj_sig, file.path(cache_dir, "signature.txt"))
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
cached <- get_cached(case$RunUMAP, "RunUMAP", cache_dir)
|
|
126
|
-
reduc_name <- case$RunUMAP$reduction.name %||% "umap"
|
|
127
|
-
if (is.null(cached$data)) {
|
|
128
|
-
log_info("- Running RunUMAP ...")
|
|
129
|
-
umap_args <- list_setdefault(
|
|
130
|
-
case$RunUMAP,
|
|
131
|
-
object = sobj,
|
|
132
|
-
dims = 1:30,
|
|
133
|
-
reduction = sobj@misc$integrated_new_reduction %||% "pca"
|
|
134
|
-
)
|
|
135
|
-
ncells <- ncol(sobj)
|
|
136
|
-
umap_args$dims <- 1:min(max(umap_args$dims), ncells - 1)
|
|
137
|
-
umap_method <- case$RunUMAP$umap.method %||% "uwot"
|
|
138
|
-
if (umap_method == "uwot" && is.null(case$RunUMAP$n.neighbors)) {
|
|
139
|
-
# https://github.com/satijalab/seurat/issues/4312
|
|
140
|
-
umap_args$n.neighbors <- min(ncells - 1, 30)
|
|
141
|
-
}
|
|
142
|
-
sobj <- do_call(RunUMAP, umap_args)
|
|
143
|
-
cached$data <- list(reduc = sobj@reductions[[reduc_name]], commands = sobj@commands)
|
|
144
|
-
save_to_cache(cached, "RunUMAP", cache_dir)
|
|
145
|
-
} else {
|
|
146
|
-
log_info("- Loading cached RunUMAP ...")
|
|
147
|
-
sobj@reductions[[reduc_name]] <- cached$data$reduc
|
|
148
|
-
sobj@commands <- cached$data$commands
|
|
149
|
-
}
|
|
150
|
-
reduc <- cached$data$reduc
|
|
151
|
-
|
|
152
|
-
cached <- get_cached(case$FindNeighbors, "FindNeighbors", cache_dir)
|
|
153
|
-
if (is.null(cached$data)) {
|
|
154
|
-
log_info("- Running FindNeighbors ...")
|
|
155
|
-
case$FindNeighbors$object <- sobj
|
|
156
|
-
if (is.null(case$FindNeighbors$reduction)) {
|
|
157
|
-
case$FindNeighbors$reduction <- sobj@misc$integrated_new_reduction %||% "pca"
|
|
158
|
-
}
|
|
159
|
-
sobj <- do_call(FindNeighbors, case$FindNeighbors)
|
|
160
|
-
cached$data <- list(graphs = sobj@graphs, commands = sobj@commands)
|
|
161
|
-
save_to_cache(cached, "FindNeighbors", cache_dir)
|
|
162
|
-
} else {
|
|
163
|
-
log_info("- Loading cached FindNeighbors ...")
|
|
164
|
-
sobj@graphs <- cached$data$graphs
|
|
165
|
-
sobj@commands <- cached$data$commands
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
case$FindClusters$random.seed <- case$FindClusters$random.seed %||% 8525
|
|
169
|
-
resolution <- case$FindClusters$resolution <- .expand_resolution(case$FindClusters$resolution %||% 0.8)
|
|
170
|
-
cached <- get_cached(case$FindClusters, "SubClustering", cache_dir)
|
|
171
|
-
if (is.null(cached$data)) {
|
|
172
|
-
log_info("- Running FindClusters at resolution: {paste(resolution, collapse = ',')} ...")
|
|
173
|
-
case$FindClusters$object <- sobj
|
|
174
|
-
case$FindClusters$cluster.name <- paste0(key, ".", resolution)
|
|
175
|
-
# use sobj1 to avoid overwriting the previous clustering results (as they have the same graph name
|
|
176
|
-
sobj1 <- do_call(FindClusters, case$FindClusters)
|
|
177
|
-
sobj1@meta.data[[key]] <- .recode_clusters(sobj1@meta.data$seurat_clusters)
|
|
178
|
-
for (clname in case$FindClusters$cluster.name) {
|
|
179
|
-
sobj1@meta.data[[clname]] <- .recode_clusters(sobj1@meta.data[[clname]])
|
|
180
|
-
}
|
|
181
|
-
cached$data <- list(
|
|
182
|
-
clusters = sobj1@meta.data[, c(case$FindClusters$cluster.name, key), drop = FALSE],
|
|
183
|
-
command = sobj1@commands$FindClusters
|
|
184
|
-
)
|
|
185
|
-
save_to_cache(cached, "SubClustering", cache_dir)
|
|
186
|
-
rm(sobj1)
|
|
187
|
-
} else {
|
|
188
|
-
log_info("- Using cached FindClusters at resolution: {paste(resolution, collapse = ',')} ...")
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
ident_table <- table(cached$data$clusters[[key]])
|
|
192
|
-
log_info(" Found {length(ident_table)} clusters at resolution: {resolution[length(resolution)]}")
|
|
193
|
-
print(ident_table)
|
|
194
|
-
cat("\n")
|
|
195
|
-
|
|
196
|
-
log_info("- Updating meta.data with subclusters...")
|
|
197
|
-
srtobj <- AddMetaData(srtobj, metadata = cached$data$clusters)
|
|
198
|
-
srtobj[[paste0("sub_umap_", key)]] <- reduc
|
|
199
|
-
srtobj@commands[[paste0("FindClusters.", key)]] <- cached$data$command
|
|
200
61
|
}
|
|
201
62
|
|
|
202
|
-
|
|
203
|
-
|
|
63
|
+
log$info("Saving results ...")
|
|
64
|
+
biopipen.utils::save_obj(object, file = outfile)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
-
|
|
3
1
|
library(rlang)
|
|
4
2
|
library(Seurat)
|
|
5
3
|
library(slingshot)
|
|
4
|
+
library(biopipen.utils)
|
|
6
5
|
|
|
7
6
|
sobjfile <- {{in.sobjfile | r}}
|
|
8
7
|
outfile <- {{out.outfile | r}}
|
|
@@ -21,15 +20,17 @@ if (is.null(group_by)) {
|
|
|
21
20
|
stop("envs.group_by is required")
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
log <- get_logger()
|
|
24
|
+
|
|
25
|
+
log$info("Reading Seurat object ...")
|
|
26
|
+
srt <- read_obj(sobjfile)
|
|
26
27
|
|
|
27
28
|
if (!group_by %in% colnames(srt@meta.data)) {
|
|
28
29
|
stop(paste("Grouping column", group_by, "not found in the Seurat object"))
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
reduction <- reduction %||% DefaultDimReduc(srt)
|
|
32
|
-
dims <-
|
|
33
|
+
dims <- biopipen.utils:::.expand_number(dims)
|
|
33
34
|
|
|
34
35
|
if (is.null(prefix)) {
|
|
35
36
|
prefix <- ""
|
|
@@ -37,23 +38,16 @@ if (is.null(prefix)) {
|
|
|
37
38
|
prefix <- paste0(prefix, "_")
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
log$info("Filtering cells in NA group_by ...")
|
|
41
42
|
srt_sub <- srt[, !is.na(srt[[group_by, drop = TRUE]])]
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
log$info("Running Slingshot ...")
|
|
44
45
|
sl <- slingshot(
|
|
45
46
|
data = as.data.frame(srt_sub[[reduction]]@cell.embeddings[, dims]),
|
|
46
47
|
clusterLabels = as.character(srt_sub[[group_by, drop = TRUE]]),
|
|
47
48
|
start.clus = start, end.clus = end
|
|
48
49
|
)
|
|
49
50
|
|
|
50
|
-
command <- pbmc_small@commands[[1]]
|
|
51
|
-
attr(command, "name") <- "SlingShot"
|
|
52
|
-
attr(command, "call.string") <- "slingshot(...)"
|
|
53
|
-
attr(command, "params") <- list()
|
|
54
|
-
srt@commands <- srt@commands %||% list()
|
|
55
|
-
srt@commands$Slingshot <- command
|
|
56
|
-
|
|
57
51
|
df <- as.data.frame(slingPseudotime(sl))
|
|
58
52
|
colnames(df) <- paste0(prefix, colnames(df))
|
|
59
53
|
if (isTRUE(reverse)) {
|
|
@@ -67,5 +61,7 @@ if (isTRUE(reverse)) {
|
|
|
67
61
|
srt <- AddMetaData(srt, metadata = df)
|
|
68
62
|
srt <- AddMetaData(srt, metadata = slingBranchID(sl), col.name = paste0(prefix, "BranchID"))
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
srt <- AddSeuratCommand(srt, "Slingshot", "slingshot(...)")
|
|
65
|
+
|
|
66
|
+
log$info("Saving Seurat object ...")
|
|
67
|
+
save_obj(srt, outfile)
|