biopipen 0.21.0__py3-none-any.whl → 0.34.26__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.
Files changed (290) hide show
  1. biopipen/__init__.py +1 -1
  2. biopipen/core/config.toml +28 -0
  3. biopipen/core/filters.py +79 -4
  4. biopipen/core/proc.py +12 -3
  5. biopipen/core/testing.py +75 -3
  6. biopipen/ns/bam.py +148 -6
  7. biopipen/ns/bed.py +75 -0
  8. biopipen/ns/cellranger.py +186 -0
  9. biopipen/ns/cellranger_pipeline.py +126 -0
  10. biopipen/ns/cnv.py +19 -3
  11. biopipen/ns/cnvkit.py +1 -1
  12. biopipen/ns/cnvkit_pipeline.py +20 -12
  13. biopipen/ns/delim.py +34 -35
  14. biopipen/ns/gene.py +68 -23
  15. biopipen/ns/gsea.py +63 -37
  16. biopipen/ns/misc.py +39 -14
  17. biopipen/ns/plot.py +304 -1
  18. biopipen/ns/protein.py +183 -0
  19. biopipen/ns/regulatory.py +290 -0
  20. biopipen/ns/rnaseq.py +142 -5
  21. biopipen/ns/scrna.py +2053 -473
  22. biopipen/ns/scrna_metabolic_landscape.py +228 -382
  23. biopipen/ns/snp.py +659 -0
  24. biopipen/ns/stats.py +484 -0
  25. biopipen/ns/tcr.py +683 -98
  26. biopipen/ns/vcf.py +236 -2
  27. biopipen/ns/web.py +97 -6
  28. biopipen/reports/bam/CNVpytor.svelte +4 -9
  29. biopipen/reports/cellranger/CellRangerCount.svelte +18 -0
  30. biopipen/reports/cellranger/CellRangerSummary.svelte +16 -0
  31. biopipen/reports/cellranger/CellRangerVdj.svelte +18 -0
  32. biopipen/reports/cnvkit/CNVkitDiagram.svelte +1 -1
  33. biopipen/reports/cnvkit/CNVkitHeatmap.svelte +1 -1
  34. biopipen/reports/cnvkit/CNVkitScatter.svelte +1 -1
  35. biopipen/reports/common.svelte +15 -0
  36. biopipen/reports/protein/ProdigySummary.svelte +16 -0
  37. biopipen/reports/scrna/CellsDistribution.svelte +4 -39
  38. biopipen/reports/scrna/DimPlots.svelte +1 -1
  39. biopipen/reports/scrna/MarkersFinder.svelte +6 -126
  40. biopipen/reports/scrna/MetaMarkers.svelte +3 -75
  41. biopipen/reports/scrna/RadarPlots.svelte +4 -20
  42. biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +61 -22
  43. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +88 -82
  44. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +70 -10
  45. biopipen/reports/snp/PlinkCallRate.svelte +24 -0
  46. biopipen/reports/snp/PlinkFreq.svelte +18 -0
  47. biopipen/reports/snp/PlinkHWE.svelte +18 -0
  48. biopipen/reports/snp/PlinkHet.svelte +18 -0
  49. biopipen/reports/snp/PlinkIBD.svelte +18 -0
  50. biopipen/reports/tcr/CDR3AAPhyschem.svelte +19 -66
  51. biopipen/reports/tcr/ClonalStats.svelte +16 -0
  52. biopipen/reports/tcr/CloneResidency.svelte +3 -93
  53. biopipen/reports/tcr/Immunarch.svelte +4 -155
  54. biopipen/reports/tcr/TCRClusterStats.svelte +3 -45
  55. biopipen/reports/tcr/TESSA.svelte +11 -28
  56. biopipen/reports/utils/misc.liq +22 -7
  57. biopipen/scripts/bam/BamMerge.py +11 -15
  58. biopipen/scripts/bam/BamSampling.py +90 -0
  59. biopipen/scripts/bam/BamSort.py +141 -0
  60. biopipen/scripts/bam/BamSplitChroms.py +10 -10
  61. biopipen/scripts/bam/BamSubsetByBed.py +38 -0
  62. biopipen/scripts/bam/CNAClinic.R +41 -5
  63. biopipen/scripts/bam/CNVpytor.py +153 -54
  64. biopipen/scripts/bam/ControlFREEC.py +13 -14
  65. biopipen/scripts/bam/SamtoolsView.py +33 -0
  66. biopipen/scripts/bed/Bed2Vcf.py +5 -5
  67. biopipen/scripts/bed/BedConsensus.py +5 -5
  68. biopipen/scripts/bed/BedLiftOver.sh +6 -4
  69. biopipen/scripts/bed/BedtoolsIntersect.py +54 -0
  70. biopipen/scripts/bed/BedtoolsMakeWindows.py +47 -0
  71. biopipen/scripts/bed/BedtoolsMerge.py +4 -4
  72. biopipen/scripts/cellranger/CellRangerCount.py +138 -0
  73. biopipen/scripts/cellranger/CellRangerSummary.R +181 -0
  74. biopipen/scripts/cellranger/CellRangerVdj.py +112 -0
  75. biopipen/scripts/cnv/AneuploidyScore.R +55 -20
  76. biopipen/scripts/cnv/AneuploidyScoreSummary.R +221 -163
  77. biopipen/scripts/cnv/TMADScore.R +25 -9
  78. biopipen/scripts/cnv/TMADScoreSummary.R +57 -86
  79. biopipen/scripts/cnvkit/CNVkitAccess.py +7 -6
  80. biopipen/scripts/cnvkit/CNVkitAutobin.py +26 -18
  81. biopipen/scripts/cnvkit/CNVkitBatch.py +6 -6
  82. biopipen/scripts/cnvkit/CNVkitCall.py +3 -3
  83. biopipen/scripts/cnvkit/CNVkitCoverage.py +4 -3
  84. biopipen/scripts/cnvkit/CNVkitDiagram.py +5 -5
  85. biopipen/scripts/cnvkit/CNVkitFix.py +3 -3
  86. biopipen/scripts/cnvkit/CNVkitGuessBaits.py +12 -8
  87. biopipen/scripts/cnvkit/CNVkitHeatmap.py +5 -5
  88. biopipen/scripts/cnvkit/CNVkitReference.py +6 -5
  89. biopipen/scripts/cnvkit/CNVkitScatter.py +5 -5
  90. biopipen/scripts/cnvkit/CNVkitSegment.py +5 -5
  91. biopipen/scripts/cnvkit/guess_baits.py +166 -93
  92. biopipen/scripts/delim/RowsBinder.R +1 -1
  93. biopipen/scripts/delim/SampleInfo.R +116 -118
  94. biopipen/scripts/gene/GeneNameConversion.R +67 -0
  95. biopipen/scripts/gene/GenePromoters.R +61 -0
  96. biopipen/scripts/gsea/Enrichr.R +5 -5
  97. biopipen/scripts/gsea/FGSEA.R +184 -50
  98. biopipen/scripts/gsea/GSEA.R +2 -2
  99. biopipen/scripts/gsea/PreRank.R +5 -5
  100. biopipen/scripts/misc/Config2File.py +2 -2
  101. biopipen/scripts/misc/Plot.R +80 -0
  102. biopipen/scripts/misc/Shell.sh +15 -0
  103. biopipen/scripts/misc/Str2File.py +2 -2
  104. biopipen/scripts/plot/Heatmap.R +3 -3
  105. biopipen/scripts/plot/Manhattan.R +147 -0
  106. biopipen/scripts/plot/QQPlot.R +146 -0
  107. biopipen/scripts/plot/ROC.R +88 -0
  108. biopipen/scripts/plot/Scatter.R +112 -0
  109. biopipen/scripts/plot/VennDiagram.R +5 -9
  110. biopipen/scripts/protein/MMCIF2PDB.py +33 -0
  111. biopipen/scripts/protein/PDB2Fasta.py +60 -0
  112. biopipen/scripts/protein/Prodigy.py +119 -0
  113. biopipen/scripts/protein/ProdigySummary.R +140 -0
  114. biopipen/scripts/protein/RMSD.py +178 -0
  115. biopipen/scripts/regulatory/MotifAffinityTest.R +102 -0
  116. biopipen/scripts/regulatory/MotifAffinityTest_AtSNP.R +127 -0
  117. biopipen/scripts/regulatory/MotifAffinityTest_MotifBreakR.R +104 -0
  118. biopipen/scripts/regulatory/MotifScan.py +159 -0
  119. biopipen/scripts/regulatory/VariantMotifPlot.R +78 -0
  120. biopipen/scripts/regulatory/motifs-common.R +324 -0
  121. biopipen/scripts/rnaseq/Simulation-ESCO.R +180 -0
  122. biopipen/scripts/rnaseq/Simulation-RUVcorr.R +45 -0
  123. biopipen/scripts/rnaseq/Simulation.R +21 -0
  124. biopipen/scripts/rnaseq/UnitConversion.R +325 -54
  125. biopipen/scripts/scrna/AnnData2Seurat.R +40 -0
  126. biopipen/scripts/scrna/CCPlotR-patch.R +161 -0
  127. biopipen/scripts/scrna/CellCellCommunication.py +150 -0
  128. biopipen/scripts/scrna/CellCellCommunicationPlots.R +93 -0
  129. biopipen/scripts/scrna/CellSNPLite.py +30 -0
  130. biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +185 -0
  131. biopipen/scripts/scrna/CellTypeAnnotation-direct.R +68 -31
  132. biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +27 -22
  133. biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +28 -20
  134. biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +48 -25
  135. biopipen/scripts/scrna/CellTypeAnnotation.R +37 -1
  136. biopipen/scripts/scrna/CellsDistribution.R +456 -167
  137. biopipen/scripts/scrna/DimPlots.R +1 -1
  138. biopipen/scripts/scrna/ExprImputation-alra.R +109 -0
  139. biopipen/scripts/scrna/ExprImputation-rmagic.R +256 -0
  140. biopipen/scripts/scrna/{ExprImpution-scimpute.R → ExprImputation-scimpute.R} +8 -5
  141. biopipen/scripts/scrna/ExprImputation.R +7 -0
  142. biopipen/scripts/scrna/LoomTo10X.R +51 -0
  143. biopipen/scripts/scrna/MQuad.py +25 -0
  144. biopipen/scripts/scrna/MarkersFinder.R +679 -400
  145. biopipen/scripts/scrna/MetaMarkers.R +265 -161
  146. biopipen/scripts/scrna/ModuleScoreCalculator.R +66 -11
  147. biopipen/scripts/scrna/PseudoBulkDEG.R +678 -0
  148. biopipen/scripts/scrna/RadarPlots.R +355 -134
  149. biopipen/scripts/scrna/ScFGSEA.R +298 -100
  150. biopipen/scripts/scrna/ScSimulation.R +65 -0
  151. biopipen/scripts/scrna/ScVelo.py +617 -0
  152. biopipen/scripts/scrna/Seurat2AnnData.R +7 -0
  153. biopipen/scripts/scrna/SeuratClusterStats-clustree.R +87 -0
  154. biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +36 -30
  155. biopipen/scripts/scrna/SeuratClusterStats-features.R +138 -187
  156. biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +81 -0
  157. biopipen/scripts/scrna/SeuratClusterStats-stats.R +78 -89
  158. biopipen/scripts/scrna/SeuratClusterStats.R +47 -10
  159. biopipen/scripts/scrna/SeuratClustering.R +36 -233
  160. biopipen/scripts/scrna/SeuratLoading.R +2 -2
  161. biopipen/scripts/scrna/SeuratMap2Ref.R +84 -113
  162. biopipen/scripts/scrna/SeuratMetadataMutater.R +16 -6
  163. biopipen/scripts/scrna/SeuratPreparing.R +223 -173
  164. biopipen/scripts/scrna/SeuratSubClustering.R +64 -0
  165. biopipen/scripts/scrna/SeuratTo10X.R +27 -0
  166. biopipen/scripts/scrna/Slingshot.R +65 -0
  167. biopipen/scripts/scrna/Subset10X.R +2 -2
  168. biopipen/scripts/scrna/TopExpressingGenes.R +169 -135
  169. biopipen/scripts/scrna/celltypist-wrapper.py +195 -0
  170. biopipen/scripts/scrna/scvelo_paga.py +313 -0
  171. biopipen/scripts/scrna/seurat_anndata_conversion.py +98 -0
  172. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +447 -82
  173. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +348 -241
  174. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +188 -166
  175. biopipen/scripts/snp/MatrixEQTL.R +217 -0
  176. biopipen/scripts/snp/Plink2GTMat.py +148 -0
  177. biopipen/scripts/snp/PlinkCallRate.R +199 -0
  178. biopipen/scripts/snp/PlinkFilter.py +100 -0
  179. biopipen/scripts/snp/PlinkFreq.R +291 -0
  180. biopipen/scripts/snp/PlinkFromVcf.py +81 -0
  181. biopipen/scripts/snp/PlinkHWE.R +85 -0
  182. biopipen/scripts/snp/PlinkHet.R +96 -0
  183. biopipen/scripts/snp/PlinkIBD.R +196 -0
  184. biopipen/scripts/snp/PlinkSimulation.py +124 -0
  185. biopipen/scripts/snp/PlinkUpdateName.py +124 -0
  186. biopipen/scripts/stats/ChowTest.R +146 -0
  187. biopipen/scripts/stats/DiffCoexpr.R +152 -0
  188. biopipen/scripts/stats/LiquidAssoc.R +135 -0
  189. biopipen/scripts/stats/Mediation.R +108 -0
  190. biopipen/scripts/stats/MetaPvalue.R +130 -0
  191. biopipen/scripts/stats/MetaPvalue1.R +74 -0
  192. biopipen/scripts/tcgamaf/Maf2Vcf.py +2 -2
  193. biopipen/scripts/tcgamaf/MafAddChr.py +2 -2
  194. biopipen/scripts/tcr/Attach2Seurat.R +3 -2
  195. biopipen/scripts/tcr/CDR3AAPhyschem.R +211 -143
  196. biopipen/scripts/tcr/CDR3Clustering.R +343 -0
  197. biopipen/scripts/tcr/ClonalStats.R +526 -0
  198. biopipen/scripts/tcr/CloneResidency.R +255 -131
  199. biopipen/scripts/tcr/CloneSizeQQPlot.R +4 -4
  200. biopipen/scripts/tcr/GIANA/GIANA.py +1356 -797
  201. biopipen/scripts/tcr/GIANA/GIANA4.py +1362 -789
  202. biopipen/scripts/tcr/GIANA/query.py +164 -162
  203. biopipen/scripts/tcr/Immunarch-basic.R +31 -9
  204. biopipen/scripts/tcr/Immunarch-clonality.R +25 -5
  205. biopipen/scripts/tcr/Immunarch-diversity.R +352 -134
  206. biopipen/scripts/tcr/Immunarch-geneusage.R +45 -5
  207. biopipen/scripts/tcr/Immunarch-kmer.R +68 -8
  208. biopipen/scripts/tcr/Immunarch-overlap.R +84 -4
  209. biopipen/scripts/tcr/Immunarch-spectratyping.R +35 -6
  210. biopipen/scripts/tcr/Immunarch-tracking.R +38 -6
  211. biopipen/scripts/tcr/Immunarch-vjjunc.R +165 -0
  212. biopipen/scripts/tcr/Immunarch.R +63 -11
  213. biopipen/scripts/tcr/Immunarch2VDJtools.R +2 -2
  214. biopipen/scripts/tcr/ImmunarchFilter.R +4 -4
  215. biopipen/scripts/tcr/ImmunarchLoading.R +38 -29
  216. biopipen/scripts/tcr/SampleDiversity.R +1 -1
  217. biopipen/scripts/tcr/ScRepCombiningExpression.R +40 -0
  218. biopipen/scripts/tcr/ScRepLoading.R +166 -0
  219. biopipen/scripts/tcr/TCRClusterStats.R +176 -22
  220. biopipen/scripts/tcr/TCRDock.py +110 -0
  221. biopipen/scripts/tcr/TESSA.R +102 -118
  222. biopipen/scripts/tcr/VJUsage.R +5 -5
  223. biopipen/scripts/tcr/immunarch-patched.R +142 -0
  224. biopipen/scripts/tcr/vdjtools-patch.sh +1 -1
  225. biopipen/scripts/vcf/BcftoolsAnnotate.py +91 -0
  226. biopipen/scripts/vcf/BcftoolsFilter.py +90 -0
  227. biopipen/scripts/vcf/BcftoolsMerge.py +31 -0
  228. biopipen/scripts/vcf/BcftoolsSort.py +113 -0
  229. biopipen/scripts/vcf/BcftoolsView.py +73 -0
  230. biopipen/scripts/vcf/TruvariBench.sh +14 -7
  231. biopipen/scripts/vcf/TruvariBenchSummary.R +16 -13
  232. biopipen/scripts/vcf/TruvariConsistency.R +1 -1
  233. biopipen/scripts/vcf/Vcf2Bed.py +2 -2
  234. biopipen/scripts/vcf/VcfAnno.py +11 -11
  235. biopipen/scripts/vcf/VcfDownSample.sh +22 -10
  236. biopipen/scripts/vcf/VcfFilter.py +5 -5
  237. biopipen/scripts/vcf/VcfFix.py +7 -7
  238. biopipen/scripts/vcf/VcfFix_utils.py +13 -4
  239. biopipen/scripts/vcf/VcfIndex.py +3 -3
  240. biopipen/scripts/vcf/VcfIntersect.py +3 -3
  241. biopipen/scripts/vcf/VcfLiftOver.sh +5 -0
  242. biopipen/scripts/vcf/VcfSplitSamples.py +4 -4
  243. biopipen/scripts/vcf/bcftools_utils.py +52 -0
  244. biopipen/scripts/web/Download.py +8 -4
  245. biopipen/scripts/web/DownloadList.py +5 -5
  246. biopipen/scripts/web/GCloudStorageDownloadBucket.py +82 -0
  247. biopipen/scripts/web/GCloudStorageDownloadFile.py +23 -0
  248. biopipen/scripts/web/gcloud_common.py +49 -0
  249. biopipen/utils/gene.py +108 -60
  250. biopipen/utils/misc.py +146 -20
  251. biopipen/utils/reference.py +64 -20
  252. biopipen/utils/reporter.py +177 -0
  253. biopipen/utils/vcf.py +1 -1
  254. biopipen-0.34.26.dist-info/METADATA +27 -0
  255. biopipen-0.34.26.dist-info/RECORD +292 -0
  256. {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/WHEEL +1 -1
  257. {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/entry_points.txt +6 -2
  258. biopipen/ns/bcftools.py +0 -111
  259. biopipen/ns/scrna_basic.py +0 -255
  260. biopipen/reports/delim/SampleInfo.svelte +0 -36
  261. biopipen/reports/scrna/GeneExpressionInvistigation.svelte +0 -32
  262. biopipen/reports/scrna/ScFGSEA.svelte +0 -35
  263. biopipen/reports/scrna/SeuratClusterStats.svelte +0 -82
  264. biopipen/reports/scrna/SeuratMap2Ref.svelte +0 -20
  265. biopipen/reports/scrna/SeuratPreparing.svelte +0 -38
  266. biopipen/reports/scrna/TopExpressingGenes.svelte +0 -55
  267. biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +0 -31
  268. biopipen/reports/utils/gsea.liq +0 -110
  269. biopipen/scripts/bcftools/BcftoolsAnnotate.py +0 -42
  270. biopipen/scripts/bcftools/BcftoolsFilter.py +0 -79
  271. biopipen/scripts/bcftools/BcftoolsSort.py +0 -19
  272. biopipen/scripts/gene/GeneNameConversion.py +0 -66
  273. biopipen/scripts/scrna/ExprImpution-alra.R +0 -32
  274. biopipen/scripts/scrna/ExprImpution-rmagic.R +0 -29
  275. biopipen/scripts/scrna/ExprImpution.R +0 -7
  276. biopipen/scripts/scrna/GeneExpressionInvistigation.R +0 -132
  277. biopipen/scripts/scrna/Write10X.R +0 -11
  278. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +0 -150
  279. biopipen/scripts/tcr/TCRClustering.R +0 -280
  280. biopipen/utils/common_docstrs.py +0 -61
  281. biopipen/utils/gene.R +0 -49
  282. biopipen/utils/gsea.R +0 -193
  283. biopipen/utils/io.R +0 -20
  284. biopipen/utils/misc.R +0 -114
  285. biopipen/utils/mutate_helpers.R +0 -433
  286. biopipen/utils/plot.R +0 -173
  287. biopipen/utils/rnaseq.R +0 -48
  288. biopipen/utils/single_cell.R +0 -115
  289. biopipen-0.21.0.dist-info/METADATA +0 -22
  290. biopipen-0.21.0.dist-info/RECORD +0 -218
@@ -1,108 +1,97 @@
1
1
  # Loaded variables: srtfile, outdir, srtobj
2
2
 
3
- stats_defaults = {{envs.stats_defaults | r: todot="-"}}
4
- stats = {{envs.stats | r: todot="-", skip=1}}
3
+ log$info("stats:")
5
4
 
6
- odir = file.path(outdir, "stats")
5
+ odir <- file.path(outdir, "stats")
7
6
  dir.create(odir, recursive=TRUE, showWarnings=FALSE)
8
- report_toc_file = file.path(odir, "report_toc.json")
9
- # Realname => {bar: ..., pie: ..., table: ...}
10
- report_toc = list()
11
7
 
12
- .add_toc = function(name, toc) {
13
- report_toc[[name]] <<- toc
14
- }
15
8
 
16
- .save_toc = function() {
17
- writeLines(toJSON(report_toc, pretty = TRUE, auto_unbox = TRUE), report_toc_file)
18
- }
19
9
 
20
- do_one_stats = function(name) {
21
- print(paste0("Doing stats for: ", name))
10
+ do_one_stats <- function(name) {
11
+ log$info("- Case: {name}")
22
12
 
23
- toc = list()
13
+ case <- list_update(stats_defaults, stats[[name]])
14
+ case <- extract_vars(case, "devpars", "more_formats", "save_code", "save_data", "subset", "descr")
24
15
 
25
- case = list_update(stats_defaults, stats[[name]])
26
- case$devpars = list_update(stats_defaults$devpars, case$devpars)
27
- if (isTRUE(case$pie) && !is.null(case$group.by)) {
28
- stop(paste0(name, ": pie charts are not supported for group-by"))
16
+ if (!is.null(subset)) {
17
+ case$object <- srtobj %>% filter(!!parse_expr(subset))
18
+ } else {
19
+ case$object <- srtobj
29
20
  }
30
-
31
- figfile = file.path(odir, paste0(slugify(name), ".bar.png"))
32
- piefile = file.path(odir, paste0(slugify(name), ".pie.png"))
33
- tablefile = file.path(odir, paste0(slugify(name), ".txt"))
34
-
35
- df_cells = srtobj@meta.data
36
- if (!is.null(case$subset)) {
37
- df_cells = df_cells %>% filter(!!rlang::parse_expr(case$subset))
21
+ ident <- case$ident %||% GetIdentityColumn(case$object)
22
+ groupings <- unique(c(case$group_by, case$rows_by, case$columns_by, case$pie_group_by, ident))
23
+ if (length(groupings) > 0) {
24
+ for (g in groupings) {
25
+ case$object <- filter(case$object, !is.na(!!sym(g)))
26
+ }
38
27
  }
39
28
 
40
- select_cols = c(case$ident, case$group.by, case$split.by)
41
- df_cells = df_cells %>%
42
- select(all_of(select_cols)) %>%
43
- group_by(!!!syms(select_cols)) %>%
44
- summarise(.n = n(), .groups = "drop") %>%
45
- mutate(.frac = .n / sum(.n))
46
-
47
- if (isTRUE(case$table)) {
48
- toc$table = basename(tablefile)
49
- write.table(df_cells, tablefile, sep="\t", quote=FALSE, row.names=FALSE)
29
+ info <- case_info(name, odir, is_dir = FALSE, create = TRUE)
30
+ p <- do_call(gglogger::register(CellStatPlot), case)
31
+ save_plot(p, info$prefix, devpars, formats = c("png", more_formats))
32
+ if (save_code) {
33
+ save_plotcode(p, info$prefix,
34
+ setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env(case, envir = .GlobalEnv))"),
35
+ "case",
36
+ auto_data_setup = FALSE)
50
37
  }
51
- if (isTRUE(case$pie)) {
52
- p_pie = df_cells %>%
53
- arrange(!!sym(case$ident)) %>%
54
- ggplot(aes(x="", y=.n, fill=!!sym(case$ident))) +
55
- geom_bar(stat="identity", width=1, alpha=.8, position = position_stack(reverse = TRUE)) +
56
- coord_polar("y", start=0) +
57
- scale_fill_ucscgb(alpha=.8) +
58
- guides(fill = guide_legend(title = case$ident)) +
59
- theme_void() +
60
- geom_label(
61
- if (isTRUE(case$frac))
62
- aes(label=sprintf("%.1f%%", .frac * 100))
63
- else
64
- aes(label=.n),
65
- position = position_stack(vjust = 0.5),
66
- color="#333333",
67
- fill="#EEEEEE",
68
- size=5
69
- )
70
38
 
71
- if (!is.null(case$split.by)) {
72
- p_pie = p_pie + facet_wrap(case$split.by)
73
- }
74
-
75
- toc$pie = basename(piefile)
76
- png(piefile, width=case$devpars$width, height=case$devpars$height, res=case$devpars$res)
77
- print(p_pie)
78
- dev.off()
39
+ frac <- case$frac %||% "none"
40
+ default_descr <- glue(
41
+ "The {case$plot_type} plot shows the distribution of cells across categories defined by '{ident}'",
42
+ "{if (!is.null(case$group_by)) glue(', grouped by {case$group_by}') else ''}",
43
+ "{if (!is.null(case$split_by)) glue(', and split by {case$split_by}') else ''}. ",
44
+ "The values represent ",
45
+ "{if (frac == 'none') 'the number of cells' else glue('the fraction of cells calculated by \"{frac}\"')}. "
46
+ )
47
+ if (!is.null(case$comparisons)) {
48
+ default_descr <- paste0(
49
+ default_descr,
50
+ glue("Statistical comparisons were performed between groups using \"{case$pairwise_method %||% 'wilcox.test'}\" method.")
51
+ )
79
52
  }
80
-
81
- ngroups = ifelse(is.null(case$group.by), 1, length(unique(df_cells[[case$group.by]])))
82
- nidents = length(unique(df_cells[[case$ident]]))
83
- bar_position = ifelse(ngroups > 5, "stack", "dodge")
84
- p = df_cells %>%
85
- ggplot(aes(
86
- x=!!sym(case$ident),
87
- y=if (isTRUE(case$frac)) .frac else .n,
88
- fill=!!sym(ifelse(is.null(case$group.by), case$ident, case$group.by))
89
- )) +
90
- geom_bar(stat="identity", position=bar_position, alpha=.8) +
91
- theme_prism(axis_text_angle = 90) +
92
- scale_fill_manual(values=rep(pal_ucscgb(alpha=.8)(26), 10)[1:max(ngroups, nidents)]) +
93
- ylab(ifelse(isTRUE(case$frac), "Fraction of cells", "Number of cells"))
94
-
95
- if (!is.null(case$split.by)) {
96
- p = p + facet_wrap(case$split.by)
53
+ if (save_data) {
54
+ pdata <- attr(p, "data") %||% p$data
55
+ if (!inherits(pdata, "data.frame") && !inherits(pdata, "matrix")) {
56
+ stop("'save_data = TRUE' is not supported for plot_type: ", case$plot_type)
57
+ }
58
+ write.table(pdata, paste0(info$prefix, ".data.txt"), sep="\t", quote=FALSE, row.names=FALSE)
59
+ reporter$add2(
60
+ list(
61
+ name = "Plot",
62
+ contents = list(
63
+ list(
64
+ kind = "descr",
65
+ content = case$descr %||% default_descr
66
+ ),
67
+ reporter$image(
68
+ info$prefix, more_formats, save_code, kind = "image")
69
+ )
70
+ ),
71
+ list(
72
+ name = "Data",
73
+ contents = list(
74
+ list(
75
+ kind = "descr",
76
+ content = "Data used directly for the plot"
77
+ ),
78
+ list(
79
+ kind = "table",
80
+ src = paste0(info$prefix, ".data.txt"),
81
+ data = list(nrows = 100)
82
+ )
83
+ )
84
+ ),
85
+ hs = c(info$section, info$name),
86
+ ui = "tabs"
87
+ )
88
+ } else {
89
+ reporter$add2(
90
+ list(kind = "descr", content = case$descr %||% default_descr),
91
+ reporter$image(info$prefix, more_formats, save_code, kind = "image"),
92
+ hs = c(info$section, info$name)
93
+ )
97
94
  }
98
-
99
- toc$bar = basename(figfile)
100
- png(figfile, width=case$devpars$width, height=case$devpars$height, res=case$devpars$res)
101
- print(p)
102
- dev.off()
103
-
104
- .add_toc(name, toc)
105
95
  }
106
96
 
107
97
  sapply(names(stats), do_one_stats)
108
- .save_toc()
@@ -1,21 +1,58 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
3
- library(jsonlite)
4
- library(slugify)
5
1
  library(Seurat)
6
2
  library(rlang)
7
3
  library(dplyr)
4
+ library(tidyr)
8
5
  library(tibble)
9
- library(ggprism)
10
- library(ggsci)
11
- library(ggrepel)
6
+ library(glue)
7
+ library(forcats)
12
8
  library(tidyseurat)
9
+ library(gglogger)
10
+ library(scplotter)
11
+ library(biopipen.utils)
13
12
 
14
- srtfile = {{in.srtobj | r}}
15
- outdir = {{out.outdir | r}}
13
+ log <- get_logger()
14
+ reporter <- get_reporter()
16
15
 
17
- srtobj = readRDS(srtfile)
16
+ srtfile <- {{in.srtobj | r}}
17
+ outdir <- {{out.outdir | r}}
18
+ joboutdir <- {{job.outdir | r}}
19
+ mutaters <- {{envs.mutaters | r}}
20
+ cache <- {{envs.cache | r}}
18
21
 
22
+ if (isTRUE(cache)) { cache = joboutdir }
23
+
24
+ log$info("Loading Seurat object ...")
25
+ srtobj = read_obj(srtfile)
26
+
27
+ log$info("Applying mutaters if any ...")
28
+ if (!is.null(mutaters) && length(mutaters) > 0) {
29
+ srtobj@meta.data = srtobj@meta.data %>%
30
+ mutate(!!!lapply(mutaters, parse_expr))
31
+ }
32
+
33
+ ############## clustree ##############
34
+ clustrees_defaults <- {{envs.clustrees_defaults | r: todot="-"}}
35
+ clustrees <- {{envs.clustrees | r: todot="-", skip=1}}
36
+ {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-clustree.R" %}
37
+
38
+ ############## stats ##############
39
+ stats_defaults = {{envs.stats_defaults | r: todot="-"}}
40
+ stats = {{envs.stats | r: todot="-", skip=1}}
19
41
  {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-stats.R" %}
42
+
43
+ ############## ngenes ##############
44
+ ngenes_defaults <- {{envs.ngenes_defaults | r: todot="-"}}
45
+ ngenes <- {{envs.ngenes | r: todot="-", skip=1}}
46
+ {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-ngenes.R" %}
47
+
48
+ ############## features ##############
49
+ features_defaults = {{envs.features_defaults | r: todot="-"}}
50
+ features = {{envs.features | r: todot="-", skip=1}}
20
51
  {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-features.R" %}
52
+
53
+ ############## dimplots ##############
54
+ dimplots_defaults = {{envs.dimplots_defaults | r: todot="-"}}
55
+ dimplots = {{envs.dimplots | r: todot="-", skip=1}}
21
56
  {% include biopipen_dir + "/scripts/scrna/SeuratClusterStats-dimplots.R" %}
57
+
58
+ reporter$save(joboutdir)
@@ -1,240 +1,43 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
1
 
2
+ library(rlang)
3
3
  library(Seurat)
4
- library(future)
5
- library(tidyr)
6
- library(dplyr)
4
+ library(biopipen.utils)
7
5
 
8
6
  set.seed(8525)
9
7
 
10
- srtfile = {{in.srtobj | quote}}
11
- rdsfile = {{out.rdsfile | quote}}
12
- envs = {{envs | r: todot="-"}}
13
-
14
- options(future.globals.maxSize = 80000 * 1024^2)
15
- plan(strategy = "multicore", workers = envs$ncores)
16
-
17
- .expand_dims = function(args, name = "dims") {
18
- # Expand dims from 30 to 1:30
19
- if (is.numeric(args[[name]]) && length(args[[name]] == 1)) {
20
- args[[name]] = 1:args[[name]]
21
- }
22
- args
23
- }
24
- envs$FindIntegrationAnchors = .expand_dims(envs$FindIntegrationAnchors)
25
- envs$IntegrateData = .expand_dims(envs$IntegrateData)
26
- envs$RunUMAP = .expand_dims(envs$RunUMAP)
27
- envs$FindNeighbors = .expand_dims(envs$FindNeighbors)
28
-
29
- sobj = readRDS(srtfile)
30
- obj_list = SplitObject(sobj, split.by = "Sample")
31
- rm(sobj)
32
-
33
- # Convert envs$FindIntegrationAnchors$reference to index of given as sample names
34
- samples = unlist(lapply(obj_list, function(x) x@meta.data$Sample[1]))
35
- if (!is.null(envs$FindIntegrationAnchors$reference)) {
36
- ref = envs$FindIntegrationAnchors$reference
37
- if (length(ref) == 1) {
38
- ref = trimws(strsplit(ref, ",")[[1]])
39
- }
40
- ref = sapply(ref, function(x) {
41
- x_int = as.integer(x)
42
- if (!is.na(x_int)) {
43
- return(x_int)
44
- }
45
- which(samples == x)
46
- })
47
- envs$FindIntegrationAnchors$reference = ref
48
- }
49
-
50
- {% if envs.use_sct -%}
51
- # ############################
52
- # Using SCT
53
- # https://satijalab.org/seurat/articles/integration_rpca.html#performing-integration-on-datasets-normalized-with-sctransform-1
54
- print("- Performing SCTransform on each sample ...")
55
- obj_list <- lapply(X = obj_list, FUN = function(x) {
56
- print(paste(" Performing SCTransform on sample:", x@meta.data$Sample[1], "..."))
57
- # # Needed?
58
- # DefaultAssay(x) <- "RNA"
59
- args = list_update(envs$SCTransform, list(object = x))
60
- do_call(SCTransform, args)
61
- })
62
-
63
- print("- Running SelectIntegrationFeatures ...")
64
- envs$SelectIntegrationFeatures$object.list = obj_list
65
- features = do_call(SelectIntegrationFeatures, envs$SelectIntegrationFeatures)
66
-
67
- print("- Running PrepSCTIntegration ...")
68
- envs$PrepSCTIntegration$object.list = obj_list
69
- envs$PrepSCTIntegration$anchor.features = features
70
- obj_list = do_call(PrepSCTIntegration, envs$PrepSCTIntegration)
71
-
72
- print("- Running PCA on each sample ...")
73
- obj_list = lapply(X = obj_list, FUN = function(x) {
74
- print(paste(" On sample:", x@meta.data$Sample[1], "..."))
75
- npcs = if (is.null(envs$RunPCA1$npcs)) 50 else envs$RunPCA1$npcs
76
- args = list_setdefault(
77
- envs$RunPCA1,
78
- object = x,
79
- features = features,
80
- verbose = FALSE,
81
- npcs = min(npcs, ncol(x) - 1)
82
- )
83
- do_call(RunPCA, args)
84
- })
85
-
86
- print("- Running FindIntegrationAnchors ...")
87
- if (!is.null(envs$FindIntegrationAnchors$reference)) {
88
- print(
89
- paste(
90
- " Using samples as reference:",
91
- paste(envs$FindIntegrationAnchors$reference, collapse = ", ")
92
- )
93
- )
94
- }
95
- fia_args = list_setdefault(
96
- envs$FindIntegrationAnchors,
97
- object.list = obj_list,
98
- anchor.features = features,
99
- normalization.method = "SCT",
100
- reduction = "rpca",
101
- dims = 1:30,
102
- k.score = 30
103
- )
104
- min_dim = min(unlist(lapply(obj_list, ncol))) - 1
105
- fia_args$dims = 1:min(min_dim, max(fia_args$dims))
106
- fia_args$k.score = min(30, min_dim - 1)
107
- anchors = do_call(FindIntegrationAnchors, fia_args)
108
-
109
- print("- Running IntegrateData ...")
110
- envs$IntegrateData$anchorset = anchors
111
- id_args = list_setdefault(
112
- envs$IntegrateData,
113
- normalization.method = "SCT",
114
- dims = 1:30
115
- )
116
- id_args$dims = 1:min(min_dim, max(id_args$dims))
117
- tryCatch({
118
- obj_list = do_call(IntegrateData, id_args)
119
- }, error = function(e) {
120
- msg = ""
121
- if (grepl("number of items to replace is not a multiple of replacement length", e)) {
122
- default_kweight = 100
123
- if (!is.null(envs$IntegrateData$k.weight)) {
124
- default_kweight = envs$IntegrateData$k.weight
125
- }
126
- msg = paste0(
127
- "It's possible that you have too few cells in some samples, ",
128
- "causing a small number of anchor cells in the anchorset. \n",
129
- " Try changing `k.weight` for `IntegrateData` by setting ",
130
- "`envs.IntegrateData.k-weight` to a smaller number (it's now ",
131
- default_kweight, "). \n",
132
- " See also https://github.com/satijalab/seurat/issues/6341"
133
- )
134
- }
135
- stop(paste0(msg, "\n", e))
136
- })
137
-
138
- {%- else -%}
139
- # ############################
140
- # Using rpca
141
- # https://satijalab.org/seurat/articles/integration_rpca.html
142
- print("- Performing NormalizeData + FindVariableFeatures on each sample ...")
143
- obj_list <- lapply(X = obj_list, FUN = function(x) {
144
- print(paste(" On sample:", x@meta.data$Sample[1], "..."))
145
- DefaultAssay(x) <- "RNA"
146
- args = list_update(envs$NormalizeData, list(object = x))
147
- x <- do_call(NormalizeData, args)
148
-
149
- args = list_update(envs$FindVariableFeatures, list(object = x))
150
- do_call(FindVariableFeatures, args)
151
- })
152
-
153
-
154
- print("- Running SelectIntegrationFeatures ...")
155
- envs$SelectIntegrationFeatures$object.list = obj_list
156
- features = do_call(SelectIntegrationFeatures, envs$SelectIntegrationFeatures)
157
-
158
- print("- Running ScaleData + RunPCA on each sample ...")
159
- obj_list <- lapply(X = obj_list, FUN = function(x) {
160
- print(paste(" On sample:", x@meta.data$Sample[1], "..."))
161
- args = list_setdefault(envs$ScaleData1, object = x, features = features)
162
- x <- do_call(ScaleData, args)
163
-
164
- npcs = if (is.null(envs$RunPCA1$npcs)) 50 else envs$RunPCA1$npcs
165
- args = list_setdefault(
166
- envs$RunPCA1,
167
- object = x,
168
- features = features,
169
- verbose = FALSE,
170
- npcs = min(npcs, ncol(x) - 1)
171
- )
172
- do_call(RunPCA, args)
173
- })
174
-
175
- print("- Running FindIntegrationAnchors ...")
176
- if (!is.null(envs$FindIntegrationAnchors$reference)) {
177
- print(
178
- paste(
179
- " Using samples as reference:",
180
- paste(envs$FindIntegrationAnchors$reference, collapse = ", ")
181
- )
182
- )
183
- }
184
- fia_args = list_setdefault(
185
- envs$FindIntegrationAnchors,
186
- object.list = obj_list,
187
- anchor.features = features,
188
- reduction = "rpca",
189
- dims = 1:30,
190
- k.score = 30
8
+ srtfile <- {{in.srtobj | r}}
9
+ outfile <- {{out.outfile | r}}
10
+ joboutdir <- {{job.outdir | r}}
11
+ RunPCAArgs <- {{envs.RunPCA | r: todot="-"}}
12
+ FindNeighborsArgs <- {{envs.FindNeighbors | r: todot="-"}}
13
+ FindClustersArgs <- {{envs.FindClusters | r: todot="-"}}
14
+ RunUMAPArgs <- {{envs.RunUMAP | r: todot="-"}}
15
+ ident <- {{envs.ident | r }}
16
+ cache <- {{envs.cache | r}}
17
+ ncores <- {{envs.ncores | r}}
18
+
19
+ FindClustersArgs$cluster.name <- FindClustersArgs$cluster.name %||% ident %||% "seurat_clusters"
20
+
21
+ log <- get_logger()
22
+
23
+ # options(str = strOptions(vec.len = 5, digits.d = 5))
24
+ options(future.globals.maxSize = Inf)
25
+ plan(strategy = "multicore", workers = ncores)
26
+
27
+ log$info("Reading Seurat object ...")
28
+ sobj <- read_obj(srtfile)
29
+
30
+ if (isTRUE(cache)) { cache <- joboutdir }
31
+
32
+ sobj <- RunSeuratClustering(
33
+ sobj,
34
+ RunPCAArgs = RunPCAArgs,
35
+ RunUMAPArgs = RunUMAPArgs,
36
+ FindNeighborsArgs = FindNeighborsArgs,
37
+ FindClustersArgs = FindClustersArgs,
38
+ log = log,
39
+ cache = cache
191
40
  )
192
- min_dim = min(unlist(lapply(obj_list, ncol))) - 1
193
- fia_args$dims = 1:min(min_dim, max(fia_args$dims))
194
- fia_args$k.score = min(30, min_dim - 1)
195
- anchors = do_call(FindIntegrationAnchors, fia_args)
196
-
197
- print("- Running IntegrateData ...")
198
- envs$IntegrateData$anchorset = anchors
199
- id_args = list_setdefault(envs$IntegrateData, dims = 1:30)
200
- id_args$dims = 1:min(min_dim, max(id_args$dims))
201
- obj_list = do_call(IntegrateData, id_args)
202
-
203
- DefaultAssay(obj_list) <- "integrated"
204
-
205
- envs$ScaleData$object = obj_list
206
- obj_list = do_call(ScaleData, envs$ScaleData)
207
-
208
- {%- endif %}
209
-
210
- print("- Running RunPCA ...")
211
- pca_args = list_setdefault(
212
- envs$RunPCA,
213
- object = obj_list,
214
- npcs = 50
215
- )
216
- pca_args$npcs = min(pca_args$npcs, ncol(obj_list) - 1)
217
- obj_list = do_call(RunPCA, pca_args)
218
-
219
- print("- Running RunUMAP ...")
220
- umap_args = list_setdefault(
221
- envs$RunUMAP,
222
- object = obj_list,
223
- dims = 1:30
224
- )
225
- umap_args$dims = 1:min(max(umap_args$dims), ncol(obj_list) - 1)
226
- obj_list = do_call(RunUMAP, umap_args)
227
-
228
- print("- Running FindNeighbors ...")
229
- envs$FindNeighbors$object = obj_list
230
- obj_list = do_call(FindNeighbors, envs$FindNeighbors)
231
-
232
- print("- Running FindClusters ...")
233
- envs$FindClusters$object = obj_list
234
- obj_list = do_call(FindClusters, envs$FindClusters)
235
-
236
- nclusters = length(unique(Idents(obj_list)))
237
- print(paste0("- Identified ", nclusters, " clusters."))
238
41
 
239
- print("- Saving results ...")
240
- saveRDS(obj_list, file = rdsfile)
42
+ log$info("Saving results ...")
43
+ 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,