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.

Files changed (149) hide show
  1. biopipen/__init__.py +1 -1
  2. biopipen/core/filters.py +10 -183
  3. biopipen/core/proc.py +5 -3
  4. biopipen/core/testing.py +8 -1
  5. biopipen/ns/bam.py +40 -4
  6. biopipen/ns/cnv.py +1 -1
  7. biopipen/ns/cnvkit.py +1 -1
  8. biopipen/ns/delim.py +1 -1
  9. biopipen/ns/gsea.py +63 -37
  10. biopipen/ns/misc.py +38 -0
  11. biopipen/ns/plot.py +8 -0
  12. biopipen/ns/scrna.py +290 -288
  13. biopipen/ns/scrna_metabolic_landscape.py +207 -366
  14. biopipen/ns/tcr.py +165 -97
  15. biopipen/reports/bam/CNVpytor.svelte +4 -9
  16. biopipen/reports/cnvkit/CNVkitDiagram.svelte +1 -1
  17. biopipen/reports/cnvkit/CNVkitHeatmap.svelte +1 -1
  18. biopipen/reports/cnvkit/CNVkitScatter.svelte +1 -1
  19. biopipen/reports/{delim/SampleInfo.svelte → common.svelte} +2 -3
  20. biopipen/reports/scrna/DimPlots.svelte +1 -1
  21. biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +51 -22
  22. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +46 -42
  23. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +63 -6
  24. biopipen/reports/snp/PlinkCallRate.svelte +2 -2
  25. biopipen/reports/snp/PlinkFreq.svelte +1 -1
  26. biopipen/reports/snp/PlinkHWE.svelte +1 -1
  27. biopipen/reports/snp/PlinkHet.svelte +1 -1
  28. biopipen/reports/snp/PlinkIBD.svelte +1 -1
  29. biopipen/reports/tcr/CDR3AAPhyschem.svelte +1 -1
  30. biopipen/scripts/bam/CNAClinic.R +41 -6
  31. biopipen/scripts/bam/CNVpytor.py +2 -1
  32. biopipen/scripts/bam/ControlFREEC.py +2 -3
  33. biopipen/scripts/bam/SamtoolsView.py +33 -0
  34. biopipen/scripts/cnv/AneuploidyScore.R +25 -13
  35. biopipen/scripts/cnv/AneuploidyScoreSummary.R +218 -163
  36. biopipen/scripts/cnv/TMADScore.R +4 -4
  37. biopipen/scripts/cnv/TMADScoreSummary.R +51 -84
  38. biopipen/scripts/cnvkit/CNVkitGuessBaits.py +3 -3
  39. biopipen/scripts/cnvkit/CNVkitHeatmap.py +3 -3
  40. biopipen/scripts/cnvkit/CNVkitReference.py +3 -3
  41. biopipen/scripts/delim/RowsBinder.R +1 -1
  42. biopipen/scripts/delim/SampleInfo.R +4 -1
  43. biopipen/scripts/gene/GeneNameConversion.R +14 -12
  44. biopipen/scripts/gsea/Enrichr.R +2 -2
  45. biopipen/scripts/gsea/FGSEA.R +184 -50
  46. biopipen/scripts/gsea/PreRank.R +3 -3
  47. biopipen/scripts/misc/Plot.R +80 -0
  48. biopipen/scripts/plot/VennDiagram.R +2 -2
  49. biopipen/scripts/protein/ProdigySummary.R +34 -27
  50. biopipen/scripts/regulatory/MotifAffinityTest.R +11 -9
  51. biopipen/scripts/regulatory/MotifAffinityTest_AtSNP.R +5 -5
  52. biopipen/scripts/regulatory/MotifAffinityTest_MotifBreakR.R +4 -4
  53. biopipen/scripts/regulatory/VariantMotifPlot.R +10 -8
  54. biopipen/scripts/regulatory/motifs-common.R +10 -9
  55. biopipen/scripts/rnaseq/Simulation-ESCO.R +14 -11
  56. biopipen/scripts/rnaseq/Simulation-RUVcorr.R +7 -4
  57. biopipen/scripts/rnaseq/Simulation.R +0 -2
  58. biopipen/scripts/rnaseq/UnitConversion.R +6 -5
  59. biopipen/scripts/scrna/AnnData2Seurat.R +25 -73
  60. biopipen/scripts/scrna/CellCellCommunication.py +1 -1
  61. biopipen/scripts/scrna/CellCellCommunicationPlots.R +51 -168
  62. biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +99 -150
  63. biopipen/scripts/scrna/CellTypeAnnotation-direct.R +11 -9
  64. biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +12 -9
  65. biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +14 -11
  66. biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +19 -16
  67. biopipen/scripts/scrna/CellTypeAnnotation.R +10 -2
  68. biopipen/scripts/scrna/CellsDistribution.R +1 -1
  69. biopipen/scripts/scrna/ExprImputation-alra.R +87 -11
  70. biopipen/scripts/scrna/ExprImputation-rmagic.R +247 -21
  71. biopipen/scripts/scrna/ExprImputation-scimpute.R +8 -5
  72. biopipen/scripts/scrna/MarkersFinder.R +348 -217
  73. biopipen/scripts/scrna/MetaMarkers.R +3 -3
  74. biopipen/scripts/scrna/ModuleScoreCalculator.R +14 -13
  75. biopipen/scripts/scrna/RadarPlots.R +1 -1
  76. biopipen/scripts/scrna/ScFGSEA.R +157 -75
  77. biopipen/scripts/scrna/ScSimulation.R +11 -10
  78. biopipen/scripts/scrna/ScVelo.py +605 -0
  79. biopipen/scripts/scrna/Seurat2AnnData.R +2 -3
  80. biopipen/scripts/scrna/SeuratClusterStats-clustree.R +1 -1
  81. biopipen/scripts/scrna/SeuratClusterStats-features.R +39 -30
  82. biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +56 -65
  83. biopipen/scripts/scrna/SeuratClusterStats-stats.R +4 -4
  84. biopipen/scripts/scrna/SeuratClusterStats.R +9 -6
  85. biopipen/scripts/scrna/SeuratClustering.R +31 -48
  86. biopipen/scripts/scrna/SeuratLoading.R +2 -2
  87. biopipen/scripts/scrna/SeuratMap2Ref.R +66 -367
  88. biopipen/scripts/scrna/SeuratMetadataMutater.R +5 -7
  89. biopipen/scripts/scrna/SeuratPreparing.R +76 -24
  90. biopipen/scripts/scrna/SeuratSubClustering.R +46 -185
  91. biopipen/scripts/scrna/{SlingShot.R → Slingshot.R} +12 -16
  92. biopipen/scripts/scrna/Subset10X.R +2 -2
  93. biopipen/scripts/scrna/TopExpressingGenes.R +141 -184
  94. biopipen/scripts/scrna/celltypist-wrapper.py +6 -4
  95. biopipen/scripts/scrna/seurat_anndata_conversion.py +81 -0
  96. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +429 -123
  97. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +346 -245
  98. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +182 -173
  99. biopipen/scripts/snp/MatrixEQTL.R +39 -20
  100. biopipen/scripts/snp/PlinkCallRate.R +43 -34
  101. biopipen/scripts/snp/PlinkFreq.R +34 -41
  102. biopipen/scripts/snp/PlinkHWE.R +23 -18
  103. biopipen/scripts/snp/PlinkHet.R +26 -22
  104. biopipen/scripts/snp/PlinkIBD.R +30 -34
  105. biopipen/scripts/stats/ChowTest.R +9 -8
  106. biopipen/scripts/stats/DiffCoexpr.R +13 -11
  107. biopipen/scripts/stats/LiquidAssoc.R +7 -8
  108. biopipen/scripts/stats/Mediation.R +8 -8
  109. biopipen/scripts/stats/MetaPvalue.R +11 -13
  110. biopipen/scripts/stats/MetaPvalue1.R +6 -5
  111. biopipen/scripts/tcr/CDR3AAPhyschem.R +105 -164
  112. biopipen/scripts/tcr/ClonalStats.R +5 -4
  113. biopipen/scripts/tcr/CloneResidency.R +3 -3
  114. biopipen/scripts/tcr/CloneSizeQQPlot.R +2 -2
  115. biopipen/scripts/tcr/Immunarch2VDJtools.R +2 -2
  116. biopipen/scripts/tcr/ImmunarchFilter.R +3 -3
  117. biopipen/scripts/tcr/ImmunarchLoading.R +5 -5
  118. biopipen/scripts/tcr/ScRepCombiningExpression.R +39 -0
  119. biopipen/scripts/tcr/ScRepLoading.R +114 -92
  120. biopipen/scripts/tcr/TCRClusterStats.R +2 -2
  121. biopipen/scripts/tcr/TCRClustering.R +86 -97
  122. biopipen/scripts/tcr/TESSA.R +65 -115
  123. biopipen/scripts/tcr/VJUsage.R +5 -5
  124. biopipen/scripts/vcf/TruvariBenchSummary.R +15 -11
  125. biopipen/utils/common_docstrs.py +66 -63
  126. biopipen/utils/reporter.py +177 -0
  127. {biopipen-0.33.1.dist-info → biopipen-0.34.0.dist-info}/METADATA +2 -1
  128. {biopipen-0.33.1.dist-info → biopipen-0.34.0.dist-info}/RECORD +130 -144
  129. {biopipen-0.33.1.dist-info → biopipen-0.34.0.dist-info}/WHEEL +1 -1
  130. biopipen/reports/scrna/CellCellCommunicationPlots.svelte +0 -14
  131. biopipen/reports/scrna/SeuratClusterStats.svelte +0 -16
  132. biopipen/reports/scrna/SeuratMap2Ref.svelte +0 -37
  133. biopipen/reports/scrna/SeuratPreparing.svelte +0 -15
  134. biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +0 -28
  135. biopipen/reports/utils/gsea.liq +0 -110
  136. biopipen/scripts/scrna/CellTypeAnnotation-common.R +0 -10
  137. biopipen/scripts/scrna/SeuratClustering-common.R +0 -213
  138. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +0 -193
  139. biopipen/utils/caching.R +0 -44
  140. biopipen/utils/gene.R +0 -95
  141. biopipen/utils/gsea.R +0 -329
  142. biopipen/utils/io.R +0 -20
  143. biopipen/utils/misc.R +0 -602
  144. biopipen/utils/mutate_helpers.R +0 -581
  145. biopipen/utils/plot.R +0 -209
  146. biopipen/utils/repr.R +0 -146
  147. biopipen/utils/rnaseq.R +0 -48
  148. biopipen/utils/single_cell.R +0 -207
  149. {biopipen-0.33.1.dist-info → biopipen-0.34.0.dist-info}/entry_points.txt +0 -0
@@ -60,6 +60,7 @@ do_one_features <- function(name) {
60
60
  log$info("- Case: {name}")
61
61
 
62
62
  case <- list_update(features_defaults, features[[name]])
63
+ case$descr <- case$descr %||% ""
63
64
  case <- extract_vars(
64
65
  case,
65
66
  "devpars", "more_formats", "save_code", "save_data", "order_by",
@@ -87,50 +88,58 @@ do_one_features <- function(name) {
87
88
  }
88
89
 
89
90
  info <- case_info(name, odir, is_dir = FALSE, create = TRUE)
90
- case$features <- .get_features(features, case$object)
91
- p <- do_call(gglogger::register(FeatureStatPlot), case)
92
- save_plot(p, info$prefix, devpars, formats = c("png", more_formats))
93
- if (save_code) {
94
- save_plotcode(p, info$prefix,
95
- setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env('case'))"),
96
- "case",
97
- auto_data_setup = FALSE)
91
+
92
+ caching <- Cache$new(
93
+ c(case, list(devpars, more_formats, save_code, save_data, order_by, subset, features, descr)),
94
+ prefix = "biopipen.scrna.SeuratClusterStats.features",
95
+ cache_dir = cache,
96
+ kind = "prefix",
97
+ path = info$prefix
98
+ )
99
+
100
+ if (caching$is_cached()) {
101
+ log$info(" plots are cached, restoring ...")
102
+ caching$restore()
103
+ } else {
104
+ case$features <- .get_features(features, case$object)
105
+ p <- do_call(gglogger::register(FeatureStatPlot), case)
106
+ save_plot(p, info$prefix, devpars, formats = c("png", more_formats))
107
+ if (save_code) {
108
+ save_plotcode(p, info$prefix,
109
+ setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env(case, envir = .GlobalEnv))"),
110
+ "case",
111
+ auto_data_setup = FALSE)
112
+ }
113
+
114
+ if (save_data) {
115
+ pdata <- attr(p, "data") %||% p$data
116
+ if (!inherits(pdata, "data.frame") && !inherits(pdata, "matrix")) {
117
+ stop("'save_data = TRUE' is not supported for plot_type: ", case$plot_type)
118
+ }
119
+ write.table(pdata, paste0(info$prefix, ".data.txt"), sep="\t", quote=FALSE, row.names=FALSE)
120
+ }
121
+
122
+ caching$save(info$prefix)
98
123
  }
99
- if (exists("descr") && !is.null(descr)) {
124
+ # add reports
125
+ if (!is.null(descr) && nchar(descr) > 0) {
100
126
  reporter$add2(
101
- list(
102
- kind = "descr",
103
- content = descr
104
- ),
127
+ list(kind = "descr", content = descr),
105
128
  hs = c(info$section, info$name)
106
129
  )
107
130
  }
108
131
 
109
132
  if (save_data) {
110
- if (!inherits(p$data, "data.frame") && !inherits(p$data, "matrix")) {
111
- stop("'save_data = TRUE' is not supported for plot_type: ", case$plot_type)
112
- }
113
- write.table(p$data, paste0(info$prefix, ".data.txt"), sep="\t", quote=FALSE, row.names=FALSE)
114
133
  reporter$add2(
115
134
  list(
116
135
  name = "Plot",
117
- contents = list(
118
- reporter$image(
119
- info$prefix, more_formats, save_code, kind = "image")
120
- )
136
+ contents = list(reporter$image(info$prefix, more_formats, save_code, kind = "image"))
121
137
  ),
122
138
  list(
123
139
  name = "Data",
124
140
  contents = list(
125
- list(
126
- kind = "descr",
127
- content = "Data used directly for the plot"
128
- ),
129
- list(
130
- kind = "table",
131
- src = paste0(info$prefix, ".data.txt"),
132
- data = list(nrows = 100)
133
- )
141
+ list(kind = "descr", content = "Data used directly for the plot"),
142
+ list(kind = "table", src = paste0(info$prefix, ".data.txt"), data = list(nrows = 100))
134
143
  )
135
144
  ),
136
145
  hs = c(info$section, info$name),
@@ -12,79 +12,70 @@ do_one_ngenes <- function(name) {
12
12
 
13
13
  case <- list_update(ngenes_defaults, ngenes[[name]])
14
14
  case$devpars <- list_update(ngenes_defaults$devpars, case$devpars)
15
+ case$more_formats <- case$more_formats %||% character(0)
16
+ case$save_code <- case$save_code %||% FALSE
17
+ case$descr <- case$descr %||% name
18
+ case$save_data <- case$save_data %||% FALSE
19
+ case$ylab <- case$ylab %||% "Number of expressed genes"
20
+ case$features <- "Number of expressed genes"
21
+ extract_vars(case, "devpars", "more_formats", "descr", "save_code", "save_data", subset_ = "subset")
15
22
 
16
23
  if (!is.null(case$subset)) {
17
- sobj <- srtobj %>% filter(!!rlang::parse_expr(case$subset))
24
+ case$object <- srtobj %>% filter(!!rlang::parse_expr(subset_))
18
25
  } else {
19
- sobj <- srtobj
26
+ case$object <- srtobj
20
27
  }
21
- df_cells <- sobj@meta.data %>% mutate(.nexpr = colSums(GetAssayData(sobj) > 0))
28
+ case$object <- AddMetaData(case$object, Matrix::colSums(GetAssayData(case$object) > 0), col.name = "Number of expressed genes")
22
29
 
23
- select_cols = c(case$ident, case$group.by, case$split.by, ".nexpr")
24
- df_cells = df_cells %>% select(all_of(select_cols))
25
-
26
- p = df_cells |>
27
- ggplot(aes(
28
- x=!!sym(case$ident),
29
- y=.nexpr,
30
- fill=!!sym(ifelse(is.null(case$group.by), case$ident, case$group.by))
31
- )) +
32
- geom_violin(alpha = 0.6, position = ifelse(is.null(case$group.by), "identity", "dodge")) +
33
- geom_boxplot(
34
- position = ifelse(is.null(case$group.by), "identity", "dodge"),
35
- width = .1,
36
- fill = "white"
37
- ) +
38
- plotthis::theme_this() +
39
- # scale_fill_biopipen() +
40
- ylab("Number of genes expressed")
41
-
42
- if (!is.null(case$split.by)) {
43
- p = p + facet_wrap(case$split.by)
30
+ info <- case_info(name, odir, is_dir = FALSE, create = TRUE)
31
+ p <- do_call(gglogger::register(FeatureStatPlot), case)
32
+ save_plot(p, info$prefix, case$devpars, formats = c("png", more_formats))
33
+ if (save_code) {
34
+ save_plotcode(p, info$prefix,
35
+ setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env(case, envir = .GlobalEnv))"),
36
+ "case",
37
+ auto_data_setup = FALSE
38
+ )
44
39
  }
45
-
46
- figprefix = file.path(odir, paste0(slugify(name), ".boxplot"))
47
-
48
- save_plot(p, figprefix, case$devpars)
49
- save_plotcode(
50
- p,
51
- figprefix,
52
- c(
53
- 'library(rlang)',
54
- 'library(ggplot2)',
55
- 'library(ggprism)',
56
- '',
57
- 'load("data.RData")'
58
- ),
59
- "df_cells", "case"
60
- )
61
-
62
- reporter$add(
63
- list(
64
- kind = "descr",
65
- content = paste0(
66
- "Plots showing the number of genes expressed in each ",
67
- case$ident,
68
- ifelse(
69
- is.null(case$group.by),
70
- "",
71
- paste0(", by ", paste0(case$group.by, collapse = ", "))
40
+ if (save_data) {
41
+ pdata <- attr(p, "data") %||% p$data
42
+ if (!inherits(pdata, "data.frame") && !inherits(pdata, "matrix")) {
43
+ stop("'save_data = TRUE' is not supported for plot_type: ", case$plot_type)
44
+ }
45
+ write.table(pdata, paste0(info$prefix, ".data.txt"), sep = "\t", quote = FALSE, row.names = FALSE)
46
+ reporter$add2(
47
+ list(
48
+ name = "Plot",
49
+ contents = list(
50
+ list(kind = "descr", content = case$descr),
51
+ reporter$image(info$prefix, more_formats, save_code, kind = "image")
72
52
  )
73
- )
74
- ),
75
- list(
76
- kind = "image",
77
- src = paste0(figprefix, ".png"),
78
- download = list(
79
- paste0(figprefix, ".pdf"),
80
- list(
81
- src = paste0(figprefix, ".code.zip"),
82
- tip = "Download the code to reproduce the plot",
83
- icon = "Code"
53
+ ),
54
+ list(
55
+ name = "Data",
56
+ contents = list(
57
+ list(
58
+ kind = "descr",
59
+ content = "Data used directly for the plot"
60
+ ),
61
+ list(
62
+ kind = "table",
63
+ src = paste0(info$prefix, ".data.txt"),
64
+ data = list(nrows = 100)
65
+ )
84
66
  )
85
- )),
86
- h1 = name
87
- )
67
+ ),
68
+ hs = c(info$section, info$name),
69
+ ui = "tabs"
70
+ )
71
+ }
72
+ else {
73
+ reporter$add2(
74
+ list(kind = "descr", content = case$descr),
75
+ reporter$image(info$prefix, more_formats, save_code, kind = "image"),
76
+ hs = c(info$section, info$name)
77
+ )
78
+ }
88
79
  }
89
80
 
90
81
  sapply(names(ngenes), do_one_ngenes)
@@ -1,5 +1,4 @@
1
1
  # Loaded variables: srtfile, outdir, srtobj
2
- library(circlize)
3
2
 
4
3
  log$info("stats:")
5
4
 
@@ -23,16 +22,17 @@ do_one_stats <- function(name) {
23
22
  save_plot(p, info$prefix, devpars, formats = c("png", more_formats))
24
23
  if (save_code) {
25
24
  save_plotcode(p, info$prefix,
26
- setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env('case'))"),
25
+ setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env(case, envir = .GlobalEnv))"),
27
26
  "case",
28
27
  auto_data_setup = FALSE)
29
28
  }
30
29
 
31
30
  if (save_data) {
32
- if (!inherits(p$data, "data.frame") && !inherits(p$data, "matrix")) {
31
+ pdata <- attr(p, "data") %||% p$data
32
+ if (!inherits(pdata, "data.frame") && !inherits(pdata, "matrix")) {
33
33
  stop("'save_data = TRUE' is not supported for plot_type: ", case$plot_type)
34
34
  }
35
- write.table(p$data, paste0(info$prefix, ".data.txt"), sep="\t", quote=FALSE, row.names=FALSE)
35
+ write.table(pdata, paste0(info$prefix, ".data.txt"), sep="\t", quote=FALSE, row.names=FALSE)
36
36
  reporter$add2(
37
37
  list(
38
38
  name = "Plot",
@@ -16,9 +16,12 @@ srtfile <- {{in.srtobj | r}}
16
16
  outdir <- {{out.outdir | r}}
17
17
  joboutdir <- {{job.outdir | r}}
18
18
  mutaters <- {{envs.mutaters | r}}
19
+ cache <- {{envs.cache | r}}
20
+
21
+ if (isTRUE(cache)) { cache = joboutdir }
19
22
 
20
23
  log$info("Loading Seurat object ...")
21
- srtobj = readRDS(srtfile)
24
+ srtobj = read_obj(srtfile)
22
25
 
23
26
  log$info("Applying mutaters if any ...")
24
27
  if (!is.null(mutaters) && length(mutaters) > 0) {
@@ -29,26 +32,26 @@ if (!is.null(mutaters) && length(mutaters) > 0) {
29
32
  ############## clustree ##############
30
33
  clustrees_defaults <- {{envs.clustrees_defaults | r: todot="-"}}
31
34
  clustrees <- {{envs.clustrees | r: todot="-", skip=1}}
32
- {{ biopipen_dir | joinpaths: "scripts", "scrna", "SeuratClusterStats-clustree.R" | source_r }}
35
+ {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-clustree.R" %}
33
36
 
34
37
  ############## stats ##############
35
38
  stats_defaults = {{envs.stats_defaults | r: todot="-"}}
36
39
  stats = {{envs.stats | r: todot="-", skip=1}}
37
- {{ biopipen_dir | joinpaths: "scripts", "scrna", "SeuratClusterStats-stats.R" | source_r }}
40
+ {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-stats.R" %}
38
41
 
39
42
  ############## ngenes ##############
40
43
  ngenes_defaults <- {{envs.ngenes_defaults | r: todot="-"}}
41
44
  ngenes <- {{envs.ngenes | r: todot="-", skip=1}}
42
- {{ biopipen_dir | joinpaths: "scripts", "scrna", "SeuratClusterStats-ngenes.R" | source_r }}
45
+ {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-ngenes.R" %}
43
46
 
44
47
  ############## features ##############
45
48
  features_defaults = {{envs.features_defaults | r: todot="-"}}
46
49
  features = {{envs.features | r: todot="-", skip=1}}
47
- {{ biopipen_dir | joinpaths: "scripts", "scrna", "SeuratClusterStats-features.R" | source_r: chdir = False }}
50
+ {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-features.R" %}
48
51
 
49
52
  ############## dimplots ##############
50
53
  dimplots_defaults = {{envs.dimplots_defaults | r: todot="-"}}
51
54
  dimplots = {{envs.dimplots | r: todot="-", skip=1}}
52
- {{ biopipen_dir | joinpaths: "scripts", "scrna", "SeuratClusterStats-dimplots.R" | source_r }}
55
+ {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-dimplots.R" %}
53
56
 
54
57
  reporter$save(joboutdir)
@@ -1,56 +1,39 @@
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
- library(future)
6
- library(rlang)
7
- library(tidyr)
8
- library(dplyr)
9
- library(digest)
3
+ library(biopipen.utils)
10
4
 
11
5
  set.seed(8525)
12
6
 
13
- srtfile <- {{in.srtobj | quote}}
14
- rdsfile <- {{out.rdsfile | quote}}
15
- joboutdir <- {{job.outdir | quote}}
16
- envs <- {{envs | r: todot="-"}}
7
+ srtfile <- {{in.srtobj | r}}
8
+ outfile <- {{out.outfile | r}}
9
+ joboutdir <- {{job.outdir | r}}
10
+ RunPCAArgs <- {{envs.RunPCA | r: todot="-"}}
11
+ FindNeighborsArgs <- {{envs.FindNeighbors | r: todot="-"}}
12
+ FindClustersArgs <- {{envs.FindClusters | r: todot="-"}}
13
+ RunUMAPArgs <- {{envs.RunUMAP | r: todot="-"}}
14
+ cache <- {{envs.cache | r}}
15
+ ncores <- {{envs.ncores | r}}
17
16
 
18
- if (length(envs$ScaleData) > 0 && length(envs$SCTransform) > 0) {
19
- stop("Cannot specify both ScaleData and SCTransform")
20
- }
17
+ log <- get_logger()
21
18
 
22
- options(str = strOptions(vec.len = 5, digits.d = 5))
19
+ # options(str = strOptions(vec.len = 5, digits.d = 5))
23
20
  options(future.globals.maxSize = 80000 * 1024^2)
24
- plan(strategy = "multicore", workers = envs$ncores)
25
-
26
- {{ biopipen_dir | joinpaths: "scripts", "scrna", "SeuratClustering-common.R" | source_r }}
27
-
28
- envs$RunUMAP <- expand_dims(envs$RunUMAP)
29
- envs$FindNeighbors <- expand_dims(envs$FindNeighbors)
30
-
31
- log_info("Reading Seurat object ...")
32
- sobj <- readRDS(srtfile)
33
-
34
- if (isTRUE(envs$cache)) { envs$cache <- joboutdir }
35
- if (length(envs$cache) > 1) {
36
- log_warn("Multiple cache directories (envs.cache) detected, using the first one.")
37
- envs$cache <- envs$cache[1]
38
- }
39
- sobj_sig <- capture.output(str(sobj))
40
- dig_sig <- digest::digest(sobj_sig, algo = "md5")
41
- dig_sig <- substr(dig_sig, 1, 8)
42
- cache_dir <- NULL
43
- if (is.character(envs$cache)) {
44
- cache_dir <- file.path(envs$cache, paste0(dig_sig, ".seurat_cache"))
45
- dir.create(cache_dir, recursive = TRUE, showWarnings = FALSE)
46
- writeLines(sobj_sig, file.path(cache_dir, "signature.txt"))
47
- }
48
-
49
- sobj <- run_transformation(sobj)
50
- sobj <- run_umap(sobj)
51
- sobj <- run_findneighbors(sobj)
52
- sobj <- run_findclusters(sobj)
53
- sobj <- run_prepsctfindmarkers(sobj)
54
-
55
- log_info("Saving results ...")
56
- saveRDS(sobj, file = rdsfile)
21
+ plan(strategy = "multicore", workers = ncores)
22
+
23
+ log$info("Reading Seurat object ...")
24
+ sobj <- read_obj(srtfile)
25
+
26
+ if (isTRUE(cache)) { cache <- joboutdir }
27
+
28
+ sobj <- RunSeuratClustering(
29
+ sobj,
30
+ RunPCAArgs = RunPCAArgs,
31
+ RunUMAPArgs = RunUMAPArgs,
32
+ FindNeighborsArgs = FindNeighborsArgs,
33
+ FindClustersArgs = FindClustersArgs,
34
+ log = log,
35
+ cache = cache
36
+ )
37
+
38
+ log$info("Saving results ...")
39
+ save_obj(sobj, file = outfile)
@@ -1,7 +1,7 @@
1
1
  library(Seurat)
2
2
 
3
- metafile = {{in.metafile | quote}}
4
- rdsfile = {{out.rdsfile | quote}}
3
+ metafile = {{in.metafile | r}}
4
+ rdsfile = {{out.rdsfile | r}}
5
5
 
6
6
  metadata = read.table(
7
7
  metafile,