biopipen 0.33.1__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 +290 -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 +4 -1
- 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/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.1.dist-info → biopipen-0.34.0.dist-info}/METADATA +2 -1
- {biopipen-0.33.1.dist-info → biopipen-0.34.0.dist-info}/RECORD +130 -144
- {biopipen-0.33.1.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.1.dist-info → biopipen-0.34.0.dist-info}/entry_points.txt +0 -0
|
@@ -15,9 +15,9 @@ library(tidyseurat)
|
|
|
15
15
|
|
|
16
16
|
setEnrichrSite("Enrichr")
|
|
17
17
|
|
|
18
|
-
srtfile <- {{ in.srtobj |
|
|
19
|
-
outdir <- {{ out.outdir |
|
|
20
|
-
joboutdir <- {{ job.outdir |
|
|
18
|
+
srtfile <- {{ in.srtobj | r }}
|
|
19
|
+
outdir <- {{ out.outdir | r }}
|
|
20
|
+
joboutdir <- {{ job.outdir | r }}
|
|
21
21
|
ncores <- {{ envs.ncores | int }}
|
|
22
22
|
mutaters <- {{ envs.mutaters | r }}
|
|
23
23
|
idents <- {{ envs.idents | r }}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
-
|
|
3
1
|
library(Seurat)
|
|
4
2
|
library(dplyr)
|
|
3
|
+
library(biopipen.utils)
|
|
5
4
|
|
|
6
5
|
sobjfile <- {{in.srtobj | r}}
|
|
7
6
|
outfile <- {{out.rdsfile | r}}
|
|
8
7
|
defaults <- {{envs.defaults | r}}
|
|
9
8
|
modules <- {{envs.modules | r}}
|
|
10
9
|
|
|
10
|
+
log <- get_logger()
|
|
11
|
+
|
|
11
12
|
# load seurat object
|
|
12
|
-
|
|
13
|
-
sobj <-
|
|
13
|
+
log$info("Loading Seurat object ...")
|
|
14
|
+
sobj <- read_obj(sobjfile)
|
|
14
15
|
|
|
15
16
|
aggs <- list(
|
|
16
17
|
mean = mean,
|
|
@@ -36,7 +37,7 @@ for (key in names(modules)) {
|
|
|
36
37
|
agg <- aggs[[module$agg]]
|
|
37
38
|
module$keep <- NULL
|
|
38
39
|
module$agg <- NULL
|
|
39
|
-
|
|
40
|
+
log$info("Calculating module '{key}' ...")
|
|
40
41
|
is_cc <- FALSE
|
|
41
42
|
if (!is.null(module$kind) && module$kind %in% c("diffmap", "diffusion_map")) {
|
|
42
43
|
library(destiny)
|
|
@@ -47,30 +48,30 @@ for (key in names(modules)) {
|
|
|
47
48
|
module$kind <- NULL
|
|
48
49
|
|
|
49
50
|
if (!is.null(module$n_pcs)) {
|
|
50
|
-
|
|
51
|
+
log$info("- Using cell embeddings from PCA reduction ...")
|
|
51
52
|
module$data <- Embeddings(sobj, reduction = "pca")
|
|
52
53
|
if (module$n_pcs > ncol(module$data)) {
|
|
53
|
-
|
|
54
|
+
log$warn("- `n_pcs` ({module$n_pcs}) is larger than the number of PCs, using all {ncol(module$data)} PCs ...")
|
|
54
55
|
}
|
|
55
56
|
module$data <- module$data[, 1:min(module$n_pcs, ncol(module$data))]
|
|
56
57
|
module$n_pcs <- NULL
|
|
57
58
|
} else {
|
|
58
|
-
|
|
59
|
+
log$info("- Using assay data ...")
|
|
59
60
|
module$data <- GetAssayData(sobj, layer = "data")
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
log$info("- Calculating diffusion map ...")
|
|
63
64
|
dm <- do_call(DiffusionMap, module)
|
|
64
65
|
ev <- eigenvectors(dm)
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
log$info("- Creating DimReduc object ...")
|
|
67
68
|
sobj[[key]] <- CreateDimReducObject(
|
|
68
69
|
embeddings = data.matrix(as.data.frame(ev[, 1:features])),
|
|
69
70
|
key = paste0(key, "_")
|
|
70
71
|
)
|
|
71
72
|
|
|
72
73
|
# add to meta.data
|
|
73
|
-
|
|
74
|
+
log$info("- Adding to meta.data ...")
|
|
74
75
|
sobj <- AddMetaData(
|
|
75
76
|
sobj,
|
|
76
77
|
sobj[[key]]@cell.embeddings,
|
|
@@ -134,5 +135,5 @@ for (key in names(modules)) {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
# save seurat object
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
log$info("Saving Seurat object ...")
|
|
139
|
+
save_obj(sobj, outfile)
|
biopipen/scripts/scrna/ScFGSEA.R
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
-
{{ biopipen_dir | joinpaths: "utils", "gsea.R" | source_r }}
|
|
3
|
-
{{ biopipen_dir | joinpaths: "utils", "mutate_helpers.R" | source_r }}
|
|
4
|
-
|
|
5
1
|
library(rlang)
|
|
6
2
|
library(Seurat)
|
|
7
3
|
library(tidyseurat)
|
|
4
|
+
library(biopipen.utils)
|
|
8
5
|
|
|
9
6
|
srtfile <- {{in.srtobj | r}} # nolint
|
|
10
7
|
outdir <- {{out.outdir | r}} # nolint
|
|
@@ -14,23 +11,28 @@ group.by <- {{envs["group-by"] | r}} # nolint
|
|
|
14
11
|
ident.1 <- {{envs["ident-1"] | r}} # nolint
|
|
15
12
|
ident.2 <- {{envs["ident-2"] | r}} # nolint
|
|
16
13
|
each <- {{envs.each | r}} # nolint
|
|
17
|
-
prefix_each <- {{envs.prefix_each | r}} # nolint
|
|
18
14
|
subset <- {{envs.subset | r}} # nolint
|
|
19
|
-
section <- {{envs.section | r}} # nolint
|
|
20
15
|
gmtfile <- {{envs.gmtfile | r}} # nolint
|
|
21
16
|
method <- {{envs.method | r}} # nolint
|
|
22
17
|
top <- {{envs.top | r}} # nolint
|
|
23
|
-
minsize <- {{envs.minsize | r}} # nolint
|
|
24
|
-
maxsize <- {{envs.maxsize | r}} # nolint
|
|
18
|
+
minsize <- {{envs.minSize | default: envs.minsize | r}} # nolint
|
|
19
|
+
maxsize <- {{envs.maxSize | default: envs.maxsize | r}} # nolint
|
|
25
20
|
eps <- {{envs.eps | r}} # nolint
|
|
26
21
|
ncores <- {{envs.ncores | r}} # nolint
|
|
27
22
|
rest <- {{envs.rest | r: todot="-"}} # nolint
|
|
28
23
|
cases <- {{envs.cases | r: todot="-"}} # nolint
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
log <- get_logger()
|
|
26
|
+
reporter <- get_reporter()
|
|
27
|
+
|
|
28
|
+
log$info("Reading Seurat object ...")
|
|
29
|
+
srtobj <- read_obj(srtfile)
|
|
30
|
+
if (!"Identity" %in% colnames(srtobj@meta.data)) {
|
|
31
|
+
srtobj@meta.data$Identity <- Idents(srtobj)
|
|
32
|
+
}
|
|
31
33
|
|
|
32
|
-
srtobj <- readRDS(srtfile)
|
|
33
34
|
if (!is.null(mutaters) && length(mutaters) > 0) {
|
|
35
|
+
log$info("Mutating metadata columns ...")
|
|
34
36
|
srtobj@meta.data <- srtobj@meta.data %>% mutate(!!!lapply(mutaters, parse_expr))
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -39,9 +41,7 @@ defaults <- list(
|
|
|
39
41
|
ident.1 = ident.1,
|
|
40
42
|
ident.2 = ident.2,
|
|
41
43
|
each = each,
|
|
42
|
-
prefix_each = prefix_each,
|
|
43
44
|
subset = subset,
|
|
44
|
-
section = section,
|
|
45
45
|
gmtfile = gmtfile,
|
|
46
46
|
method = method,
|
|
47
47
|
top = top,
|
|
@@ -54,54 +54,53 @@ defaults <- list(
|
|
|
54
54
|
|
|
55
55
|
expand_each <- function(name, case) {
|
|
56
56
|
outcases <- list()
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
57
|
+
|
|
58
|
+
case$group.by <- case$group.by %||% "Identity"
|
|
59
|
+
|
|
60
|
+
if (is.null(case$each) || is.na(case$each) || nchar(case$each) == 0 || isFALSE(each)) {
|
|
61
|
+
outcases[[name]] <- case
|
|
63
62
|
} else {
|
|
64
|
-
if (!is.null(case$
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
if (is.null(case$subset)) {
|
|
69
|
-
eachs <- srtobj@meta.data %>%
|
|
63
|
+
eachs <- if (!is.null(case$subset)) {
|
|
64
|
+
srtobj@meta.data %>%
|
|
65
|
+
filter(!!parse_expr(case$subset)) %>%
|
|
70
66
|
pull(case$each) %>% na.omit() %>% unique() %>% as.vector()
|
|
71
67
|
} else {
|
|
72
|
-
|
|
68
|
+
srtobj@meta.data %>%
|
|
73
69
|
pull(case$each) %>% na.omit() %>% unique() %>% as.vector()
|
|
74
70
|
}
|
|
71
|
+
|
|
72
|
+
if (length(cases) == 0 && name == "GSEA") {
|
|
73
|
+
name <- case$each
|
|
74
|
+
}
|
|
75
|
+
|
|
75
76
|
for (each in eachs) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
key <- paste0(name, "::", case$each, " - ", each)
|
|
77
|
+
newname <- paste0(case$each, "::", each)
|
|
78
|
+
newcase <- case
|
|
79
|
+
|
|
80
|
+
newcase$original_case <- name
|
|
81
|
+
newcase$each_name <- case$each
|
|
82
|
+
newcase$each <- each
|
|
83
|
+
|
|
84
|
+
if (!is.null(case$subset)) {
|
|
85
|
+
newcase$subset <- paste0(case$subset, " & ", bQuote(case$each), " == '", each, "'")
|
|
86
86
|
} else {
|
|
87
|
-
|
|
87
|
+
newcase$subset <- paste0(bQuote(case$each), " == '", each, "'")
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
outcases[[
|
|
91
|
-
outcases[[key]]$group.by <- by
|
|
89
|
+
|
|
90
|
+
outcases[[newname]] <- newcase
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
outcases
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
|
|
98
|
-
cases <- expand_cases(cases, defaults, expand_each)
|
|
96
|
+
log$info("Expanding cases...")
|
|
97
|
+
cases <- expand_cases(cases, defaults, expand_each, default_case = "GSEA")
|
|
99
98
|
|
|
100
99
|
|
|
101
100
|
ensure_sobj <- function(expr, allow_empty) {
|
|
102
101
|
tryCatch({ expr }, error = function(e) {
|
|
103
102
|
if (allow_empty) {
|
|
104
|
-
|
|
103
|
+
log$warn(" Ignoring this case: {e$message}")
|
|
105
104
|
return(NULL)
|
|
106
105
|
} else {
|
|
107
106
|
stop(e)
|
|
@@ -110,59 +109,82 @@ ensure_sobj <- function(expr, allow_empty) {
|
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
|
|
113
|
-
do_case <- function(name
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
do_case <- function(name) {
|
|
113
|
+
log$info("- Processing case: {name} ...")
|
|
114
|
+
case <- cases[[name]]
|
|
115
|
+
info <- case_info(name, outdir, create = TRUE)
|
|
116
116
|
|
|
117
|
-
allow_empty =
|
|
117
|
+
allow_empty = !is.null(case$each)
|
|
118
118
|
# prepare expression matrix
|
|
119
|
-
|
|
119
|
+
log$info(" Preparing expression matrix...")
|
|
120
120
|
sobj <- ensure_sobj({ srtobj %>% filter(!is.na(!!sym(case$group.by))) }, allow_empty)
|
|
121
|
-
if (is.null(sobj)) {
|
|
121
|
+
if (is.null(sobj)) {
|
|
122
|
+
reporter$add2(
|
|
123
|
+
list(
|
|
124
|
+
kind = "error",
|
|
125
|
+
content = paste0("No cells with non-NA `", case$group.by, "` in the Seurat object.")
|
|
126
|
+
),
|
|
127
|
+
hs = c(info$section, info$name)
|
|
128
|
+
)
|
|
129
|
+
return(NULL)
|
|
130
|
+
}
|
|
122
131
|
|
|
123
132
|
if (!is.null(case$subset)) {
|
|
124
133
|
sobj <- ensure_sobj({ sobj %>% filter(!!!parse_exprs(case$subset)) }, allow_empty)
|
|
125
|
-
if (is.null(sobj)) {
|
|
134
|
+
if (is.null(sobj)) {
|
|
135
|
+
reporter$add2(
|
|
136
|
+
list(
|
|
137
|
+
kind = "error",
|
|
138
|
+
content = paste0("No cells with non-NA `", case$group.by, "` in the Seurat object.")
|
|
139
|
+
),
|
|
140
|
+
hs = c(info$section, info$name)
|
|
141
|
+
)
|
|
142
|
+
return(NULL)
|
|
143
|
+
}
|
|
126
144
|
}
|
|
127
145
|
if (!is.null(case$ident.2)) {
|
|
128
146
|
sobj <- ensure_sobj({ sobj %>% filter(!!sym(case$group.by) %in% c(case$ident.1, case$ident.2)) }, allow_empty)
|
|
129
|
-
if (is.null(sobj)) {
|
|
147
|
+
if (is.null(sobj)) {
|
|
148
|
+
reporter$add2(
|
|
149
|
+
list(
|
|
150
|
+
kind = "error",
|
|
151
|
+
content = paste0("No cells with non-NA `", case$group.by, "` in the Seurat object.")
|
|
152
|
+
),
|
|
153
|
+
hs = c(info$section, info$name)
|
|
154
|
+
)
|
|
155
|
+
return(NULL)
|
|
156
|
+
}
|
|
130
157
|
}
|
|
131
158
|
|
|
132
159
|
allclasses <- sobj@meta.data[, case$group.by, drop = TRUE]
|
|
133
160
|
if (is.null(case$ident.2)) {
|
|
134
|
-
case$ident.2 <- "
|
|
135
|
-
allclasses[allclasses != case$ident.1] <- "
|
|
161
|
+
case$ident.2 <- "Other"
|
|
162
|
+
allclasses[allclasses != case$ident.1] <- "Other"
|
|
136
163
|
}
|
|
137
164
|
exprs <- GetAssayData(sobj, layer = "data")
|
|
138
165
|
|
|
139
166
|
# get preranks
|
|
140
|
-
|
|
141
|
-
ranks <-
|
|
167
|
+
log$info(" Getting preranks...")
|
|
168
|
+
ranks <- RunGSEAPreRank(exprs, allclasses, case$ident.1, case$ident.2, case$method)
|
|
142
169
|
write.table(
|
|
143
170
|
ranks,
|
|
144
|
-
file.path(info$
|
|
171
|
+
file.path(info$prefix, "fgsea.rank"),
|
|
145
172
|
row.names = FALSE,
|
|
146
173
|
col.names = TRUE,
|
|
147
174
|
sep = "\t",
|
|
148
175
|
quote = FALSE
|
|
149
176
|
)
|
|
150
|
-
if (
|
|
177
|
+
if (all(is.na(ranks))) {
|
|
151
178
|
if (length(allclasses) < 100) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
paste0("Not enough cells (n = ", length(allclasses), ") to run fgsea."),
|
|
155
|
-
file = file.path(info$casedir, "fgsea.log")
|
|
156
|
-
)
|
|
157
|
-
add_report(
|
|
179
|
+
log$warn(" Ignoring this case because all gene ranks are NA and there are <100 cells.")
|
|
180
|
+
reporter$add2(
|
|
158
181
|
list(
|
|
159
182
|
kind = "error",
|
|
160
183
|
content = paste0("Not enough cells (n = ", length(allclasses), ") to run fgsea.")
|
|
161
184
|
),
|
|
162
|
-
|
|
163
|
-
h2 = info$h2
|
|
185
|
+
hs = c(info$section, info$name)
|
|
164
186
|
)
|
|
165
|
-
return()
|
|
187
|
+
return(NULL)
|
|
166
188
|
} else {
|
|
167
189
|
stop(paste0(
|
|
168
190
|
"All gene ranks are NA (# cells = ",
|
|
@@ -175,20 +197,80 @@ do_case <- function(name, case) {
|
|
|
175
197
|
}
|
|
176
198
|
|
|
177
199
|
# run fgsea
|
|
178
|
-
|
|
179
|
-
case$rest$
|
|
180
|
-
case$rest$
|
|
200
|
+
log$info(" Running fgsea...")
|
|
201
|
+
case$rest$ranks <- ranks
|
|
202
|
+
case$rest$genesets <- ParseGMT(case$gmtfile)
|
|
203
|
+
case$rest$minSize <- case$rest$minSize %||% case$rest$minsize %||% case$minsize
|
|
204
|
+
case$rest$maxSize <- case$rest$maxSize %||% case$rest$maxsize %||% case$maxsize
|
|
181
205
|
case$rest$eps <- case$eps
|
|
182
206
|
case$rest$nproc <- case$ncores
|
|
183
|
-
|
|
207
|
+
case$rest$minsize <- NULL
|
|
208
|
+
case$rest$maxsize <- NULL
|
|
209
|
+
result <- do_call(RunGSEA, case$rest)
|
|
210
|
+
write.table(
|
|
211
|
+
result,
|
|
212
|
+
file.path(info$prefix, "fgsea.tsv"),
|
|
213
|
+
row.names = FALSE,
|
|
214
|
+
col.names = TRUE,
|
|
215
|
+
sep = "\t",
|
|
216
|
+
quote = FALSE
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
p_summary <- VizGSEA(
|
|
220
|
+
result,
|
|
221
|
+
plot_type = "summary",
|
|
222
|
+
top_term = case$top
|
|
223
|
+
)
|
|
224
|
+
save_plot(
|
|
225
|
+
p_summary,
|
|
226
|
+
file.path(info$prefix, "summary"),
|
|
227
|
+
devpars = list(res = 100, height = attr(p_summary, "height") * 100, width = attr(p_summary, "width") * 100),
|
|
228
|
+
formats = "png"
|
|
229
|
+
)
|
|
184
230
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
231
|
+
p_gsea <- VizGSEA(
|
|
232
|
+
result,
|
|
233
|
+
plot_type = "gsea",
|
|
234
|
+
gs = result$pathway[1:min(case$top, nrow(result))]
|
|
235
|
+
)
|
|
236
|
+
save_plot(
|
|
237
|
+
p_gsea,
|
|
238
|
+
file.path(info$prefix, "pathways"),
|
|
239
|
+
devpars = list(res = 100, height = attr(p_gsea, "height") * 100, width = attr(p_gsea, "width") * 100),
|
|
240
|
+
formats = "png"
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
reporter$add2(
|
|
245
|
+
list(
|
|
246
|
+
name = "Table",
|
|
247
|
+
contents = list(
|
|
248
|
+
list(kind = "descr", content = paste0(
|
|
249
|
+
"Showing top 50 pathways by padj in descending order. ",
|
|
250
|
+
"Use 'Download the entire data' button to download all pathways."
|
|
251
|
+
)),
|
|
252
|
+
list(kind = "table", src = file.path(info$prefix, "fgsea"), data = list(nrows = 50))
|
|
253
|
+
)
|
|
254
|
+
),
|
|
255
|
+
list(
|
|
256
|
+
name = "Summary Plot",
|
|
257
|
+
contents = list(
|
|
258
|
+
list(kind = "descr", content = paste0("Showing top ", case$top, " pathways.")),
|
|
259
|
+
list(kind = "image", src = file.path(info$prefix, "summary.png"))
|
|
260
|
+
)
|
|
261
|
+
),
|
|
262
|
+
list(
|
|
263
|
+
name = "GSEA Plots",
|
|
264
|
+
contents = list(
|
|
265
|
+
list(kind = "descr", content = paste0("Showing top ", case$top, " pathways.")),
|
|
266
|
+
list(kind = "image", src = file.path(info$prefix, "pathways.png"))
|
|
267
|
+
)
|
|
268
|
+
),
|
|
269
|
+
hs = c(info$section, info$name),
|
|
270
|
+
ui = "tabs"
|
|
189
271
|
)
|
|
190
272
|
}
|
|
191
273
|
|
|
192
|
-
sapply(sort(names(cases)), function(name) do_case(name
|
|
274
|
+
sapply(sort(names(cases)), function(name) do_case(name))
|
|
193
275
|
|
|
194
|
-
|
|
276
|
+
reporter$save(joboutdir)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
-
|
|
3
1
|
library(rlang)
|
|
4
2
|
library(splatter)
|
|
5
3
|
library(scater)
|
|
4
|
+
library(biopipen.utils)
|
|
6
5
|
|
|
7
6
|
# Load template variables
|
|
8
7
|
seed <- {{ in.seed | r }}
|
|
@@ -14,11 +13,13 @@ outtype <- {{ envs.outtype | r }}
|
|
|
14
13
|
method <- {{ envs.method | r }}
|
|
15
14
|
user_params <- {{ envs.params | r: todot="-" }}
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
log <- get_logger()
|
|
17
|
+
|
|
18
|
+
log$info("Generating simulation parameters ...")
|
|
18
19
|
|
|
19
20
|
seed <- seed %||% 1
|
|
20
21
|
if (length(seed) > 1) {
|
|
21
|
-
|
|
22
|
+
log$warn("- multiple seeds provided, using the first one")
|
|
22
23
|
seed <- seed[1]
|
|
23
24
|
}
|
|
24
25
|
if (is.character(seed)) {
|
|
@@ -41,7 +42,7 @@ user_params$object = params
|
|
|
41
42
|
do_call(setParams, user_params)
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
log$info("Saving simulation parameters to file ...")
|
|
45
46
|
|
|
46
47
|
sim <- splatSimulate(params, method = method, verbose = TRUE)
|
|
47
48
|
|
|
@@ -49,16 +50,16 @@ outtype <- tolower(outtype)
|
|
|
49
50
|
if (outtype == "sce") outtype <- "singlecellexperiment"
|
|
50
51
|
|
|
51
52
|
if (outtype == "singlecellexperiment") {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
log$info("Saving simulation to file ...")
|
|
54
|
+
save_obj(sim, file = outfile)
|
|
54
55
|
} else {
|
|
55
|
-
|
|
56
|
+
log$info("Converting simulation to Seurat object ...")
|
|
56
57
|
cnts <- SingleCellExperiment::counts(sim)
|
|
57
58
|
sobj <- Seurat::CreateSeuratObject(counts = cnts, project = proj)
|
|
58
59
|
rm(sim)
|
|
59
60
|
rm(cnts)
|
|
60
61
|
gc()
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
log$info("Saving simulation to file ...")
|
|
64
|
+
save_obj(sobj, file = outfile)
|
|
64
65
|
}
|