biopipen 0.29.1__py3-none-any.whl → 0.30.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.

Files changed (105) hide show
  1. biopipen/__init__.py +1 -1
  2. biopipen/core/config.toml +2 -0
  3. biopipen/core/filters.py +21 -0
  4. biopipen/ns/plot.py +55 -0
  5. biopipen/ns/scrna.py +49 -13
  6. biopipen/ns/web.py +87 -5
  7. biopipen/scripts/bam/CNAClinic.R +2 -1
  8. biopipen/scripts/cellranger/CellRangerCount.py +3 -3
  9. biopipen/scripts/cellranger/CellRangerSummary.R +2 -1
  10. biopipen/scripts/cnv/AneuploidyScore.R +1 -1
  11. biopipen/scripts/cnv/AneuploidyScoreSummary.R +2 -2
  12. biopipen/scripts/delim/RowsBinder.R +1 -1
  13. biopipen/scripts/delim/SampleInfo.R +3 -2
  14. biopipen/scripts/gene/GeneNameConversion.R +2 -2
  15. biopipen/scripts/gsea/Enrichr.R +3 -3
  16. biopipen/scripts/gsea/FGSEA.R +2 -2
  17. biopipen/scripts/gsea/GSEA.R +2 -2
  18. biopipen/scripts/gsea/PreRank.R +2 -2
  19. biopipen/scripts/plot/Heatmap.R +3 -3
  20. biopipen/scripts/plot/Manhattan.R +2 -1
  21. biopipen/scripts/plot/QQPlot.R +1 -1
  22. biopipen/scripts/plot/ROC.R +1 -1
  23. biopipen/scripts/plot/Scatter.R +112 -0
  24. biopipen/scripts/plot/VennDiagram.R +3 -3
  25. biopipen/scripts/regulatory/MotifAffinityTest.R +3 -7
  26. biopipen/scripts/rnaseq/Simulation.R +1 -1
  27. biopipen/scripts/rnaseq/UnitConversion.R +2 -1
  28. biopipen/scripts/scrna/AnnData2Seurat.R +1 -1
  29. biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +24 -8
  30. biopipen/scripts/scrna/CellTypeAnnotation-common.R +10 -0
  31. biopipen/scripts/scrna/CellTypeAnnotation-direct.R +9 -1
  32. biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +12 -8
  33. biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +15 -2
  34. biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +38 -15
  35. biopipen/scripts/scrna/CellTypeAnnotation.R +3 -0
  36. biopipen/scripts/scrna/CellsDistribution.R +3 -2
  37. biopipen/scripts/scrna/DimPlots.R +1 -1
  38. biopipen/scripts/scrna/ExprImputation-alra.R +1 -1
  39. biopipen/scripts/scrna/MarkersFinder.R +5 -4
  40. biopipen/scripts/scrna/MetaMarkers.R +22 -4
  41. biopipen/scripts/scrna/ModuleScoreCalculator.R +2 -1
  42. biopipen/scripts/scrna/RadarPlots.R +1 -1
  43. biopipen/scripts/scrna/ScFGSEA.R +4 -3
  44. biopipen/scripts/scrna/Seurat2AnnData.R +1 -1
  45. biopipen/scripts/scrna/SeuratClusterStats-clustree.R +73 -0
  46. biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +4 -3
  47. biopipen/scripts/scrna/SeuratClusterStats-features.R +8 -5
  48. biopipen/scripts/scrna/SeuratClusterStats-hists.R +6 -5
  49. biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +4 -3
  50. biopipen/scripts/scrna/SeuratClusterStats-stats.R +4 -3
  51. biopipen/scripts/scrna/SeuratClusterStats.R +24 -8
  52. biopipen/scripts/scrna/SeuratClustering-common.R +213 -0
  53. biopipen/scripts/scrna/SeuratClustering.R +10 -170
  54. biopipen/scripts/scrna/SeuratMap2Ref.R +65 -31
  55. biopipen/scripts/scrna/SeuratMetadataMutater.R +2 -2
  56. biopipen/scripts/scrna/SeuratPreparing-common.R +452 -0
  57. biopipen/scripts/scrna/SeuratPreparing-doublet_detection.R +201 -0
  58. biopipen/scripts/scrna/SeuratPreparing.R +22 -562
  59. biopipen/scripts/scrna/SeuratSubClustering.R +24 -39
  60. biopipen/scripts/scrna/TopExpressingGenes.R +1 -1
  61. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +7 -4
  62. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +7 -3
  63. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +3 -3
  64. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +3 -3
  65. biopipen/scripts/snp/MatrixEQTL.R +1 -1
  66. biopipen/scripts/snp/PlinkCallRate.R +2 -2
  67. biopipen/scripts/snp/PlinkFreq.R +2 -2
  68. biopipen/scripts/snp/PlinkHWE.R +2 -2
  69. biopipen/scripts/snp/PlinkHet.R +2 -2
  70. biopipen/scripts/snp/PlinkIBD.R +2 -2
  71. biopipen/scripts/stats/ChowTest.R +1 -1
  72. biopipen/scripts/stats/DiffCoexpr.R +1 -1
  73. biopipen/scripts/stats/LiquidAssoc.R +1 -1
  74. biopipen/scripts/stats/Mediation.R +26 -12
  75. biopipen/scripts/stats/MetaPvalue.R +4 -1
  76. biopipen/scripts/stats/MetaPvalue1.R +4 -1
  77. biopipen/scripts/tcr/Attach2Seurat.R +1 -1
  78. biopipen/scripts/tcr/CDR3AAPhyschem.R +1 -1
  79. biopipen/scripts/tcr/CloneResidency.R +2 -2
  80. biopipen/scripts/tcr/CloneSizeQQPlot.R +2 -2
  81. biopipen/scripts/tcr/Immunarch-basic.R +0 -4
  82. biopipen/scripts/tcr/Immunarch-clonality.R +0 -4
  83. biopipen/scripts/tcr/Immunarch-diversity.R +2 -24
  84. biopipen/scripts/tcr/Immunarch-geneusage.R +0 -2
  85. biopipen/scripts/tcr/Immunarch-kmer.R +0 -2
  86. biopipen/scripts/tcr/Immunarch-overlap.R +0 -2
  87. biopipen/scripts/tcr/Immunarch-spectratyping.R +0 -2
  88. biopipen/scripts/tcr/Immunarch-tracking.R +0 -2
  89. biopipen/scripts/tcr/Immunarch-vjjunc.R +0 -2
  90. biopipen/scripts/tcr/Immunarch.R +43 -11
  91. biopipen/scripts/tcr/ImmunarchFilter.R +1 -1
  92. biopipen/scripts/tcr/ImmunarchLoading.R +2 -2
  93. biopipen/scripts/tcr/SampleDiversity.R +1 -1
  94. biopipen/scripts/tcr/TCRClusterStats.R +2 -2
  95. biopipen/scripts/tcr/TCRClustering.R +2 -2
  96. biopipen/scripts/tcr/TESSA.R +2 -2
  97. biopipen/scripts/vcf/TruvariBenchSummary.R +2 -2
  98. biopipen/scripts/vcf/TruvariConsistency.R +1 -1
  99. biopipen/scripts/web/GCloudStorageDownloadBucket.py +82 -0
  100. biopipen/scripts/web/GCloudStorageDownloadFile.py +23 -0
  101. biopipen/scripts/web/gcloud_common.py +49 -0
  102. {biopipen-0.29.1.dist-info → biopipen-0.30.0.dist-info}/METADATA +1 -1
  103. {biopipen-0.29.1.dist-info → biopipen-0.30.0.dist-info}/RECORD +105 -96
  104. {biopipen-0.29.1.dist-info → biopipen-0.30.0.dist-info}/WHEEL +0 -0
  105. {biopipen-0.29.1.dist-info → biopipen-0.30.0.dist-info}/entry_points.txt +0 -0
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/caching.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "caching.R" | source_r }}
3
3
 
4
4
  library(Seurat)
5
5
  library(future)
@@ -8,7 +8,6 @@ library(tidyr)
8
8
  library(dplyr)
9
9
  library(tidyseurat)
10
10
  library(digest)
11
- library(clustree)
12
11
 
13
12
  set.seed(8525)
14
13
 
@@ -39,13 +38,13 @@ plan(strategy = "multicore", workers = envs$ncores)
39
38
  parts <- trimws(unlist(strsplit(res, ",")))
40
39
  for (part in parts) {
41
40
  if (grepl(":", part)) {
42
- parts <- trimws(unlist(strsplit(part, ":")))
43
- if (length(parts) == 2) { parts <- c(parts, 0.1) }
44
- if (length(parts) != 3) {
41
+ ps <- trimws(unlist(strsplit(part, ":")))
42
+ if (length(ps) == 2) { ps <- c(ps, 0.1) }
43
+ if (length(ps) != 3) {
45
44
  stop("Invalid resolution format: {part}. Expected 2 or 3 parts separated by ':' for a range.")
46
45
  }
47
- parts <- as.numeric(parts)
48
- expanded_res <- c(expanded_res, seq(parts[1], parts[2], by = parts[3]))
46
+ ps <- as.numeric(ps)
47
+ expanded_res <- c(expanded_res, seq(ps[1], ps[2], by = ps[3]))
49
48
  } else {
50
49
  expanded_res <- c(expanded_res, as.numeric(part))
51
50
  }
@@ -53,7 +52,7 @@ plan(strategy = "multicore", workers = envs$ncores)
53
52
  }
54
53
  }
55
54
  # keep the last resolution at last
56
- rev(unique(rev(expanded_res)))
55
+ rev(unique(rev(round(expanded_res, 2))))
57
56
  }
58
57
 
59
58
  # recode clusters from 0, 1, 2, ... to s1, s2, s3, ...
@@ -98,8 +97,7 @@ for (key in names(envs$cases)) {
98
97
  subset = envs$subset,
99
98
  RunUMAP = envs$RunUMAP,
100
99
  FindNeighbors = envs$FindNeighbors,
101
- FindClusters = envs$FindClusters,
102
- clustree_devpars = envs$clustree_devpars
100
+ FindClusters = envs$FindClusters
103
101
  ),
104
102
  case
105
103
  )
@@ -169,49 +167,36 @@ for (key in names(envs$cases)) {
169
167
 
170
168
  case$FindClusters$random.seed <- case$FindClusters$random.seed %||% 8525
171
169
  resolution <- case$FindClusters$resolution <- .expand_resolution(case$FindClusters$resolution %||% 0.8)
172
- cached <- get_cached(case$FindClusters, "FindClusters", cache_dir)
170
+ cached <- get_cached(case$FindClusters, "SubClustering", cache_dir)
173
171
  if (is.null(cached$data)) {
174
172
  log_info("- Running FindClusters at resolution: {paste(resolution, collapse = ',')} ...")
175
173
  case$FindClusters$object <- sobj
176
- # avoid overwriting the previous clustering results (as they have the same graph name
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
177
176
  sobj1 <- do_call(FindClusters, case$FindClusters)
178
- graph_name <- case$FindClusters$graph.name %||% paste0(DefaultAssay(sobj), "_snn_res.")
179
- for (res in resolution) {
180
- cluster_name <- paste0(graph_name, res)
181
- new_cluster_name <- paste0(key, ".", res)
182
- sobj1@meta.data[[new_cluster_name]] <- .recode_clusters(sobj1@meta.data[[cluster_name]])
183
- }
184
177
  sobj1@meta.data[[key]] <- .recode_clusters(sobj1@meta.data$seurat_clusters)
185
- keys <- sapply(resolution, function(res) paste0(key, ".", res))
186
- keys <- c(keys, key)
187
- cached$data <- sobj1@meta.data[, keys, drop = FALSE]
188
- save_to_cache(cached, "FindClusters", cache_dir)
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)
189
186
  rm(sobj1)
190
187
  } else {
191
188
  log_info("- Using cached FindClusters at resolution: {paste(resolution, collapse = ',')} ...")
192
189
  }
193
190
 
194
- ident_table <- table(cached$data[[key]])
195
- log_info(" Found {length(ident_table)} clusters")
191
+ ident_table <- table(cached$data$clusters[[key]])
192
+ log_info(" Found {length(ident_table)} clusters at resolution: {resolution[length(resolution)]}")
196
193
  print(ident_table)
197
194
  cat("\n")
198
195
 
199
- if (length(resolution) > 1) {
200
- log_info("- Plotting clustree ...")
201
- png(
202
- file.path(joboutdir, paste0(key, ".clustree.png")),
203
- res = case$clustree_devpars$res,
204
- width = case$clustree_devpars$width,
205
- height = case$clustree_devpars$height
206
- )
207
- p <- clustree(cached$data, prefix = paste0(key, "."))
208
- print(p)
209
- dev.off()
210
- }
211
-
212
196
  log_info("- Updating meta.data with subclusters...")
213
- srtobj <- AddMetaData(srtobj, metadata = cached$data)
197
+ srtobj <- AddMetaData(srtobj, metadata = cached$data$clusters)
214
198
  srtobj[[paste0("sub_umap_", key)]] <- reduc
199
+ srtobj@commands[[paste0("FindClusters.", key)]] <- cached$data$command
215
200
  }
216
201
 
217
202
  log_info("Saving results ...")
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(Seurat)
4
4
  library(tibble)
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/gsea.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "gsea.R" | source_r }}
3
3
 
4
4
  library(parallel)
5
5
  library(Seurat)
@@ -139,8 +139,11 @@ do_one_subset <- function(s, subset_col, subset_prefix) {
139
139
  if (any(unlist(lapply(x, class)) == "try-error")) {
140
140
  stop("mclapply error")
141
141
  }
142
-
143
- for (r in x) { do.call(add_report, r) }
142
+ for (r in x) {
143
+ if (!is.null(r)) {
144
+ do.call(add_report, r)
145
+ }
146
+ }
144
147
  }
145
148
 
146
149
  do_one_subset_col <- function(subset_col, subset_prefix) {
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/gsea.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "gsea.R" | source_r }}
3
3
 
4
4
  library(parallel)
5
5
  library(scater)
@@ -184,6 +184,10 @@ if (ncores == 1) {
184
184
  }
185
185
  }
186
186
  report = unlist(x, recursive = FALSE)
187
- for (r in report) { do.call(add_report, r) }
187
+ for (r in report) {
188
+ if (!is.null(r)) {
189
+ do.call(add_report, r)
190
+ }
191
+ }
188
192
 
189
193
  save_report(joboutdir)
@@ -1,6 +1,6 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/gsea.R")
3
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "gsea.R" | source_r }}
3
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
4
4
 
5
5
  library(scater)
6
6
  library(reshape2)
@@ -1,6 +1,6 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/gsea.R")
3
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "gsea.R" | source_r }}
3
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
4
4
 
5
5
  library(gtools)
6
6
  library(parallel)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
  library(rlang)
3
3
  library(rtracklayer)
4
4
  library(MatrixEQTL)
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
3
3
  library(ggprism)
4
4
  theme_set(theme_prism())
5
5
 
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
3
3
  library(rlang)
4
4
  library(ggprism)
5
5
  theme_set(theme_prism())
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
3
3
  library(ggprism)
4
4
  theme_set(theme_prism())
5
5
 
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
3
3
  library(ggprism)
4
4
  theme_set(theme_prism())
5
5
 
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
3
3
  suppressPackageStartupMessages({
4
4
  library(dplyr)
5
5
  library(tidyr)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(rlang)
4
4
  library(dplyr)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
  library(dcanr)
3
3
  library(scuttle)
4
4
  library(doRNG)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(rlang)
4
4
  library(dplyr)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(rlang)
4
4
  library(parallel)
@@ -35,9 +35,20 @@ if (!is.null(fmlfile)) {
35
35
 
36
36
  args <- args %||% list()
37
37
 
38
- medanalysis = function(casename) {
38
+ medanalysis <- function(i, total) {
39
+ casename <- names(cases)[i]
39
40
  case <- cases[[casename]]
40
- log_info("- Case:", casename)
41
+ if (total < 50) {
42
+ log_info("- Case: ", casename)
43
+ } else if (total < 500) {
44
+ if (i %% 10 == 0) {
45
+ log_info("- Processing case {i}/{total} ...")
46
+ }
47
+ } else {
48
+ if (i %% 100 == 0) {
49
+ log_info("- Processing case {i}/{total} ...")
50
+ }
51
+ }
41
52
  M <- case$M
42
53
  Y <- case$Y
43
54
  X <- case$X
@@ -55,17 +66,19 @@ medanalysis = function(casename) {
55
66
  fmly <- update.formula(fmly, cov_fml)
56
67
  }
57
68
 
69
+ data <- indata[, c(M, X, Y, covs), drop = FALSE]
70
+ data <- data[complete.cases(data), , drop = FALSE]
58
71
  margs <- args
59
- args$sims <- sims
60
- args$model.m <- modelm(fmlm, data = indata)
61
- args$model.y <- modely(fmly, data = indata)
62
- args$treat <- X
63
- args$mediator <- M
64
- args$outcome <- Y
72
+ margs$sims <- sims
73
+ margs$model.m <- modelm(fmlm, data = data)
74
+ margs$model.y <- modely(fmly, data = data)
75
+ margs$treat <- X
76
+ margs$mediator <- M
77
+ margs$outcome <- Y
65
78
  if (!is.null(covs)) {
66
- args$covariates <- indata[, covs, drop = FALSE]
79
+ margs$covariates <- data[, covs, drop = FALSE]
67
80
  }
68
- med <- do_call(mediate, args)
81
+ med <- do_call(mediate, margs)
69
82
  if (is.na(med$d1.p) || is.na(med$n1)) {
70
83
  NULL
71
84
  } else {
@@ -85,7 +98,8 @@ medanalysis = function(casename) {
85
98
  }
86
99
  }
87
100
 
88
- out <- do_call(rbind, mclapply(names(cases), medanalysis, mc.cores = ncores))
101
+ total <- length(cases)
102
+ out <- do_call(rbind, mclapply(1:total, medanalysis, total = total, mc.cores = ncores))
89
103
 
90
104
  if (padj != "none") {
91
105
  out$Padj <- p.adjust(out$Pval, method = padj)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(metap)
4
4
  library(rlang)
@@ -106,6 +106,9 @@ if (length(infiles) == 1 && padj == "none") {
106
106
  } else if (length(ps) == 1 && keep_single) {
107
107
  metaps <- c(metaps, ps)
108
108
  ns <- c(ns, 1)
109
+ } else if (any(ps == 0)) {
110
+ metaps <- c(metaps, 0)
111
+ ns <- c(ns, length(ps))
109
112
  } else {
110
113
  metaps <- c(metaps, do.call(method, list(ps))$p)
111
114
  ns <- c(ns, length(ps))
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(metap)
4
4
  library(rlang)
@@ -50,6 +50,9 @@ for (ps in outdata$.pvals) {
50
50
  } else if (length(ps) == 1 && keep_single) {
51
51
  metaps <- c(metaps, ps)
52
52
  ns <- c(ns, 1)
53
+ } else if (any(ps == 0)) {
54
+ metaps <- c(metaps, 0)
55
+ ns <- c(ns, length(ps))
53
56
  } else {
54
57
  metaps <- c(metaps, do.call(method, list(ps))$p)
55
58
  ns <- c(ns, length(ps))
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(Seurat)
4
4
  library(immunarch)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
  library(dplyr)
3
3
  library(tidyr)
4
4
  library(tibble)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(rlang)
4
4
  library(dplyr)
@@ -414,7 +414,7 @@ handle_subject <- function(i, subjects, casename, case) {
414
414
  mutate(across(everything(), as.character)) %>%
415
415
  paste(collapse = "-")
416
416
 
417
- log_info(" Handling {subject} ({i}/{nrow(subjects)}) ...")
417
+ log_info(" Handling {i}/{nrow(subjects)}: {subject} ...")
418
418
 
419
419
  if (!is.null(case$subset)) {
420
420
  counts <- cldata %>% filter(!!parse_expr(case$subset))
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "plot.R" | source_r }}
3
3
 
4
4
  library(dplyr)
5
5
  library(tidyr)
@@ -5,10 +5,6 @@ log_info("")
5
5
  log_info("# Basic analysis")
6
6
  log_info("-----------------------------------")
7
7
 
8
- volumes = {{envs.volumes | r}}
9
- lens = {{envs.lens | r}}
10
- counts = {{envs.counts | r}}
11
-
12
8
  # Fill up cases
13
9
  fill_up_cases_basic = function(config) {
14
10
  log_debug("Filling up cases ...")
@@ -5,10 +5,6 @@ log_info("")
5
5
  log_info("# Clonality analysis")
6
6
  log_info("-----------------------------------")
7
7
 
8
- top_clones = {{envs.top_clones | r}}
9
- rare_clones = {{envs.rare_clones | r}}
10
- hom_clones = {{envs.hom_clones | r}}
11
-
12
8
  # Fill up cases
13
9
  fill_up_cases_clonality = function(config) {
14
10
  cases = config$cases
@@ -1,32 +1,10 @@
1
- # Diversity estimation
2
- source("{{biopipen_dir}}/scripts/tcr/immunarch-patched.R")
1
+
3
2
  # https://immunarch.com/articles/web_only/v6_diversity.html
4
3
 
5
4
  log_info("")
6
5
  log_info("# Diversity estimation")
7
6
  log_info("-----------------------------------")
8
7
 
9
- # Other variables are loaded in the parent template
10
- # immdata is already loaded, meta is mutated
11
- div_method = {{envs.divs.method | default: "gini" | r}}
12
- div_by = {{envs.divs.by | default: None | r}}
13
- div_plot_type = {{envs.divs.plot_type | default: "bar" | r}}
14
- div_order = {{envs.divs.order | default: [] | r}}
15
- div_args = {{envs.divs.args | default: {} | r: todot="-"}}
16
- div_test = {{envs.divs.test | default: None | r}}
17
- div_cases = {{envs.divs.cases | default: {} | r: todot="-"}}
18
- div_devpars = {{envs.divs.devpars | default: None | r}}
19
- div_separate_by = {{envs.divs.separate_by | default: None | r}}
20
- div_split_by = {{envs.divs.split_by | default: None | r}}
21
- div_split_order = {{envs.divs.split_order | default: None | r}}
22
- div_align_x = {{envs.divs.align_x | default: False | r}}
23
- div_align_y = {{envs.divs.align_y | default: False | r}}
24
- div_subset = {{envs.divs.subset | default: None | r}}
25
- div_log = {{envs.divs.log | default: False | r}}
26
- div_ncol = {{envs.divs.ncol | default: 2 | r}}
27
- div_ymin = {{envs.divs.ymin | default: None | r}}
28
- div_ymax = {{envs.divs.ymax | default: None | r}}
29
-
30
8
  div_test = div_test %||% list(method = "none", padjust = "none")
31
9
  div_devpars = div_devpars %||% list(res = 100, width = 800, height = 800)
32
10
 
@@ -77,7 +55,7 @@ update_case = function(case, name) {
77
55
  if (!is.null(case$args) && length(case$args) > 0) {
78
56
  names(case$args) = paste0(".", names(case$args))
79
57
  }
80
- if (!is.null(case$test) && case$test != "none" && (is.null(case$by) || length(case$by) == 0)) {
58
+ if (!is.null(case$test) && case$test$method != "none" && (is.null(case$by) || length(case$by) == 0)) {
81
59
  stop("For diversity estimation, `test` is only supported when `by` is specified")
82
60
  }
83
61
  # Just ignore them for rarefraction
@@ -5,8 +5,6 @@ log_info("")
5
5
  log_info("# Gene usage analysis")
6
6
  log_info("-----------------------------------")
7
7
 
8
- gene_usages = {{ envs.gene_usages | r: todot="-" }}
9
-
10
8
  # Fill up cases
11
9
  log_info("Filling up cases ...")
12
10
  cases = gene_usages$cases
@@ -5,8 +5,6 @@ log_info("")
5
5
  log_info("# K-mer analysis")
6
6
  log_info("-----------------------------------")
7
7
 
8
- kmers = {{ envs.kmers | r: todot="-" }}
9
-
10
8
  # Fill up cases
11
9
  log_info("Filling up cases ...")
12
10
  cases = kmers$cases
@@ -5,8 +5,6 @@ log_info("")
5
5
  log_info("# Overlap analysis")
6
6
  log_info("-----------------------------------")
7
7
 
8
- overlaps = {{ envs.overlaps | r: todot="-" }}
9
-
10
8
  # Fill up cases
11
9
  cases = overlaps$cases
12
10
  if (is.null(cases) || length(cases) == 0) {
@@ -5,8 +5,6 @@ log_info("")
5
5
  log_info("# Spectratyping analysis")
6
6
  log_info("-----------------------------------")
7
7
 
8
- spects = {{ envs.spects | r }}
9
-
10
8
  # Fill up cases
11
9
  log_info("Filling up cases ...")
12
10
  if (is.null(spects$cases) || length(spects$cases) == 0) {
@@ -2,8 +2,6 @@ log_info("")
2
2
  log_info("# Clonotype tracking")
3
3
  log_info("-----------------------------------")
4
4
 
5
- trackings = {{ envs.trackings | r }}
6
-
7
5
  log_info("Filling up cases ...")
8
6
  if (is.null(trackings$subjects)) {
9
7
  trackings$subjects = c()
@@ -5,8 +5,6 @@ log_info("-----------------------------------")
5
5
  # Already required by immunarch
6
6
  library(circlize)
7
7
 
8
- vj_juncs <- {{envs.vj_junc | r}}
9
-
10
8
  log_info("Filling up cases ...")
11
9
  cases <- vj_juncs$cases
12
10
  if (is.null(cases) || length(cases) == 0) {
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/single_cell.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
+ {{ biopipen_dir | joinpaths: "utils", "single_cell.R" | source_r }}
3
3
  # Basic analysis and clonality
4
4
  # TODO: How about TRA chain?
5
5
  library(rlang)
@@ -65,46 +65,78 @@ n_samples = length(immdata$data)
65
65
  ##################
66
66
  # Basic analysis #
67
67
  ##################
68
- {% include biopipen_dir + "/scripts/tcr/Immunarch-basic.R" %}
68
+ volumes = {{envs.volumes | r}}
69
+ lens = {{envs.lens | r}}
70
+ counts = {{envs.counts | r}}
71
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-basic.R" | source_r }}
69
72
 
70
73
  ##################
71
74
  # Clonality #
72
75
  ##################
73
- {% include biopipen_dir + "/scripts/tcr/Immunarch-clonality.R" %}
76
+ top_clones = {{envs.top_clones | r}}
77
+ rare_clones = {{envs.rare_clones | r}}
78
+ hom_clones = {{envs.hom_clones | r}}
79
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-clonality.R" | source_r }}
74
80
 
75
81
  ##################
76
82
  # Overlap #
77
83
  ##################
78
- {% include biopipen_dir + "/scripts/tcr/Immunarch-overlap.R" %}
84
+ overlaps = {{ envs.overlaps | r: todot="-" }}
85
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-overlap.R" | source_r }}
79
86
 
80
87
  ##################
81
88
  # Gene usage #
82
89
  ##################
83
- {% include biopipen_dir + "/scripts/tcr/Immunarch-geneusage.R" %}
90
+ gene_usages = {{ envs.gene_usages | r: todot="-" }}
91
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-geneusage.R" | source_r }}
84
92
 
85
93
  ##################
86
94
  # Spectratyping #
87
95
  ##################
88
- {% include biopipen_dir + "/scripts/tcr/Immunarch-spectratyping.R" %}
96
+ spects = {{ envs.spects | r }}
97
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-spectratyping.R" | source_r }}
89
98
 
90
99
  ########################
91
100
  # Diversity estimation #
92
101
  ########################
93
- {% include biopipen_dir + "/scripts/tcr/Immunarch-diversity.R" %}
102
+ div_method = {{envs.divs.method | default: "gini" | r}}
103
+ div_by = {{envs.divs.by | default: None | r}}
104
+ div_plot_type = {{envs.divs.plot_type | default: "bar" | r}}
105
+ div_order = {{envs.divs.order | default: [] | r}}
106
+ div_args = {{envs.divs.args | default: {} | r: todot="-"}}
107
+ div_test = {{envs.divs.test | default: None | r}}
108
+ div_cases = {{envs.divs.cases | default: {} | r: todot="-"}}
109
+ div_devpars = {{envs.divs.devpars | default: None | r}}
110
+ div_separate_by = {{envs.divs.separate_by | default: None | r}}
111
+ div_split_by = {{envs.divs.split_by | default: None | r}}
112
+ div_split_order = {{envs.divs.split_order | default: None | r}}
113
+ div_align_x = {{envs.divs.align_x | default: False | r}}
114
+ div_align_y = {{envs.divs.align_y | default: False | r}}
115
+ div_subset = {{envs.divs.subset | default: None | r}}
116
+ div_log = {{envs.divs.log | default: False | r}}
117
+ div_ncol = {{envs.divs.ncol | default: 2 | r}}
118
+ div_ymin = {{envs.divs.ymin | default: None | r}}
119
+ div_ymax = {{envs.divs.ymax | default: None | r}}
120
+
121
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "immunarch-patched.R" | source_r }}
122
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-diversity.R" | source_r }}
94
123
 
95
124
  ######################
96
125
  # Clonotype tracking #
97
126
  ######################
98
- {% include biopipen_dir + "/scripts/tcr/Immunarch-tracking.R" %}
127
+ trackings = {{ envs.trackings | r }}
128
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-tracking.R" | source_r }}
99
129
 
100
130
  ######################
101
131
  # K-mer analysis #
102
132
  ######################
103
- {% include biopipen_dir + "/scripts/tcr/Immunarch-kmer.R" %}
133
+ kmers = {{ envs.kmers | r: todot="-" }}
134
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-kmer.R" | source_r }}
104
135
 
105
136
  ######################
106
137
  # VJ junction #
107
138
  ######################
108
- {% include biopipen_dir + "/scripts/tcr/Immunarch-vjjunc.R" %}
139
+ vj_juncs <- {{envs.vj_junc | r}}
140
+ {{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-vjjunc.R" | source_r }}
109
141
 
110
142
  save_report(joboutdir)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
 
3
3
  library(dplyr)
4
4
  library(glue)