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.
- biopipen/__init__.py +1 -1
- biopipen/core/config.toml +28 -0
- biopipen/core/filters.py +79 -4
- biopipen/core/proc.py +12 -3
- biopipen/core/testing.py +75 -3
- biopipen/ns/bam.py +148 -6
- biopipen/ns/bed.py +75 -0
- biopipen/ns/cellranger.py +186 -0
- biopipen/ns/cellranger_pipeline.py +126 -0
- biopipen/ns/cnv.py +19 -3
- biopipen/ns/cnvkit.py +1 -1
- biopipen/ns/cnvkit_pipeline.py +20 -12
- biopipen/ns/delim.py +34 -35
- biopipen/ns/gene.py +68 -23
- biopipen/ns/gsea.py +63 -37
- biopipen/ns/misc.py +39 -14
- biopipen/ns/plot.py +304 -1
- biopipen/ns/protein.py +183 -0
- biopipen/ns/regulatory.py +290 -0
- biopipen/ns/rnaseq.py +142 -5
- biopipen/ns/scrna.py +2053 -473
- biopipen/ns/scrna_metabolic_landscape.py +228 -382
- biopipen/ns/snp.py +659 -0
- biopipen/ns/stats.py +484 -0
- biopipen/ns/tcr.py +683 -98
- biopipen/ns/vcf.py +236 -2
- biopipen/ns/web.py +97 -6
- biopipen/reports/bam/CNVpytor.svelte +4 -9
- biopipen/reports/cellranger/CellRangerCount.svelte +18 -0
- biopipen/reports/cellranger/CellRangerSummary.svelte +16 -0
- biopipen/reports/cellranger/CellRangerVdj.svelte +18 -0
- biopipen/reports/cnvkit/CNVkitDiagram.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitHeatmap.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitScatter.svelte +1 -1
- biopipen/reports/common.svelte +15 -0
- biopipen/reports/protein/ProdigySummary.svelte +16 -0
- biopipen/reports/scrna/CellsDistribution.svelte +4 -39
- biopipen/reports/scrna/DimPlots.svelte +1 -1
- biopipen/reports/scrna/MarkersFinder.svelte +6 -126
- biopipen/reports/scrna/MetaMarkers.svelte +3 -75
- biopipen/reports/scrna/RadarPlots.svelte +4 -20
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +61 -22
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +88 -82
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +70 -10
- biopipen/reports/snp/PlinkCallRate.svelte +24 -0
- biopipen/reports/snp/PlinkFreq.svelte +18 -0
- biopipen/reports/snp/PlinkHWE.svelte +18 -0
- biopipen/reports/snp/PlinkHet.svelte +18 -0
- biopipen/reports/snp/PlinkIBD.svelte +18 -0
- biopipen/reports/tcr/CDR3AAPhyschem.svelte +19 -66
- biopipen/reports/tcr/ClonalStats.svelte +16 -0
- biopipen/reports/tcr/CloneResidency.svelte +3 -93
- biopipen/reports/tcr/Immunarch.svelte +4 -155
- biopipen/reports/tcr/TCRClusterStats.svelte +3 -45
- biopipen/reports/tcr/TESSA.svelte +11 -28
- biopipen/reports/utils/misc.liq +22 -7
- biopipen/scripts/bam/BamMerge.py +11 -15
- biopipen/scripts/bam/BamSampling.py +90 -0
- biopipen/scripts/bam/BamSort.py +141 -0
- biopipen/scripts/bam/BamSplitChroms.py +10 -10
- biopipen/scripts/bam/BamSubsetByBed.py +38 -0
- biopipen/scripts/bam/CNAClinic.R +41 -5
- biopipen/scripts/bam/CNVpytor.py +153 -54
- biopipen/scripts/bam/ControlFREEC.py +13 -14
- biopipen/scripts/bam/SamtoolsView.py +33 -0
- biopipen/scripts/bed/Bed2Vcf.py +5 -5
- biopipen/scripts/bed/BedConsensus.py +5 -5
- biopipen/scripts/bed/BedLiftOver.sh +6 -4
- biopipen/scripts/bed/BedtoolsIntersect.py +54 -0
- biopipen/scripts/bed/BedtoolsMakeWindows.py +47 -0
- biopipen/scripts/bed/BedtoolsMerge.py +4 -4
- biopipen/scripts/cellranger/CellRangerCount.py +138 -0
- biopipen/scripts/cellranger/CellRangerSummary.R +181 -0
- biopipen/scripts/cellranger/CellRangerVdj.py +112 -0
- biopipen/scripts/cnv/AneuploidyScore.R +55 -20
- biopipen/scripts/cnv/AneuploidyScoreSummary.R +221 -163
- biopipen/scripts/cnv/TMADScore.R +25 -9
- biopipen/scripts/cnv/TMADScoreSummary.R +57 -86
- biopipen/scripts/cnvkit/CNVkitAccess.py +7 -6
- biopipen/scripts/cnvkit/CNVkitAutobin.py +26 -18
- biopipen/scripts/cnvkit/CNVkitBatch.py +6 -6
- biopipen/scripts/cnvkit/CNVkitCall.py +3 -3
- biopipen/scripts/cnvkit/CNVkitCoverage.py +4 -3
- biopipen/scripts/cnvkit/CNVkitDiagram.py +5 -5
- biopipen/scripts/cnvkit/CNVkitFix.py +3 -3
- biopipen/scripts/cnvkit/CNVkitGuessBaits.py +12 -8
- biopipen/scripts/cnvkit/CNVkitHeatmap.py +5 -5
- biopipen/scripts/cnvkit/CNVkitReference.py +6 -5
- biopipen/scripts/cnvkit/CNVkitScatter.py +5 -5
- biopipen/scripts/cnvkit/CNVkitSegment.py +5 -5
- biopipen/scripts/cnvkit/guess_baits.py +166 -93
- biopipen/scripts/delim/RowsBinder.R +1 -1
- biopipen/scripts/delim/SampleInfo.R +116 -118
- biopipen/scripts/gene/GeneNameConversion.R +67 -0
- biopipen/scripts/gene/GenePromoters.R +61 -0
- biopipen/scripts/gsea/Enrichr.R +5 -5
- biopipen/scripts/gsea/FGSEA.R +184 -50
- biopipen/scripts/gsea/GSEA.R +2 -2
- biopipen/scripts/gsea/PreRank.R +5 -5
- biopipen/scripts/misc/Config2File.py +2 -2
- biopipen/scripts/misc/Plot.R +80 -0
- biopipen/scripts/misc/Shell.sh +15 -0
- biopipen/scripts/misc/Str2File.py +2 -2
- biopipen/scripts/plot/Heatmap.R +3 -3
- biopipen/scripts/plot/Manhattan.R +147 -0
- biopipen/scripts/plot/QQPlot.R +146 -0
- biopipen/scripts/plot/ROC.R +88 -0
- biopipen/scripts/plot/Scatter.R +112 -0
- biopipen/scripts/plot/VennDiagram.R +5 -9
- biopipen/scripts/protein/MMCIF2PDB.py +33 -0
- biopipen/scripts/protein/PDB2Fasta.py +60 -0
- biopipen/scripts/protein/Prodigy.py +119 -0
- biopipen/scripts/protein/ProdigySummary.R +140 -0
- biopipen/scripts/protein/RMSD.py +178 -0
- biopipen/scripts/regulatory/MotifAffinityTest.R +102 -0
- biopipen/scripts/regulatory/MotifAffinityTest_AtSNP.R +127 -0
- biopipen/scripts/regulatory/MotifAffinityTest_MotifBreakR.R +104 -0
- biopipen/scripts/regulatory/MotifScan.py +159 -0
- biopipen/scripts/regulatory/VariantMotifPlot.R +78 -0
- biopipen/scripts/regulatory/motifs-common.R +324 -0
- biopipen/scripts/rnaseq/Simulation-ESCO.R +180 -0
- biopipen/scripts/rnaseq/Simulation-RUVcorr.R +45 -0
- biopipen/scripts/rnaseq/Simulation.R +21 -0
- biopipen/scripts/rnaseq/UnitConversion.R +325 -54
- biopipen/scripts/scrna/AnnData2Seurat.R +40 -0
- biopipen/scripts/scrna/CCPlotR-patch.R +161 -0
- biopipen/scripts/scrna/CellCellCommunication.py +150 -0
- biopipen/scripts/scrna/CellCellCommunicationPlots.R +93 -0
- biopipen/scripts/scrna/CellSNPLite.py +30 -0
- biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +185 -0
- biopipen/scripts/scrna/CellTypeAnnotation-direct.R +68 -31
- biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +27 -22
- biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +28 -20
- biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +48 -25
- biopipen/scripts/scrna/CellTypeAnnotation.R +37 -1
- biopipen/scripts/scrna/CellsDistribution.R +456 -167
- biopipen/scripts/scrna/DimPlots.R +1 -1
- biopipen/scripts/scrna/ExprImputation-alra.R +109 -0
- biopipen/scripts/scrna/ExprImputation-rmagic.R +256 -0
- biopipen/scripts/scrna/{ExprImpution-scimpute.R → ExprImputation-scimpute.R} +8 -5
- biopipen/scripts/scrna/ExprImputation.R +7 -0
- biopipen/scripts/scrna/LoomTo10X.R +51 -0
- biopipen/scripts/scrna/MQuad.py +25 -0
- biopipen/scripts/scrna/MarkersFinder.R +679 -400
- biopipen/scripts/scrna/MetaMarkers.R +265 -161
- biopipen/scripts/scrna/ModuleScoreCalculator.R +66 -11
- biopipen/scripts/scrna/PseudoBulkDEG.R +678 -0
- biopipen/scripts/scrna/RadarPlots.R +355 -134
- biopipen/scripts/scrna/ScFGSEA.R +298 -100
- biopipen/scripts/scrna/ScSimulation.R +65 -0
- biopipen/scripts/scrna/ScVelo.py +617 -0
- biopipen/scripts/scrna/Seurat2AnnData.R +7 -0
- biopipen/scripts/scrna/SeuratClusterStats-clustree.R +87 -0
- biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +36 -30
- biopipen/scripts/scrna/SeuratClusterStats-features.R +138 -187
- biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +81 -0
- biopipen/scripts/scrna/SeuratClusterStats-stats.R +78 -89
- biopipen/scripts/scrna/SeuratClusterStats.R +47 -10
- biopipen/scripts/scrna/SeuratClustering.R +36 -233
- biopipen/scripts/scrna/SeuratLoading.R +2 -2
- biopipen/scripts/scrna/SeuratMap2Ref.R +84 -113
- biopipen/scripts/scrna/SeuratMetadataMutater.R +16 -6
- biopipen/scripts/scrna/SeuratPreparing.R +223 -173
- biopipen/scripts/scrna/SeuratSubClustering.R +64 -0
- biopipen/scripts/scrna/SeuratTo10X.R +27 -0
- biopipen/scripts/scrna/Slingshot.R +65 -0
- biopipen/scripts/scrna/Subset10X.R +2 -2
- biopipen/scripts/scrna/TopExpressingGenes.R +169 -135
- biopipen/scripts/scrna/celltypist-wrapper.py +195 -0
- biopipen/scripts/scrna/scvelo_paga.py +313 -0
- biopipen/scripts/scrna/seurat_anndata_conversion.py +98 -0
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +447 -82
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +348 -241
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +188 -166
- biopipen/scripts/snp/MatrixEQTL.R +217 -0
- biopipen/scripts/snp/Plink2GTMat.py +148 -0
- biopipen/scripts/snp/PlinkCallRate.R +199 -0
- biopipen/scripts/snp/PlinkFilter.py +100 -0
- biopipen/scripts/snp/PlinkFreq.R +291 -0
- biopipen/scripts/snp/PlinkFromVcf.py +81 -0
- biopipen/scripts/snp/PlinkHWE.R +85 -0
- biopipen/scripts/snp/PlinkHet.R +96 -0
- biopipen/scripts/snp/PlinkIBD.R +196 -0
- biopipen/scripts/snp/PlinkSimulation.py +124 -0
- biopipen/scripts/snp/PlinkUpdateName.py +124 -0
- biopipen/scripts/stats/ChowTest.R +146 -0
- biopipen/scripts/stats/DiffCoexpr.R +152 -0
- biopipen/scripts/stats/LiquidAssoc.R +135 -0
- biopipen/scripts/stats/Mediation.R +108 -0
- biopipen/scripts/stats/MetaPvalue.R +130 -0
- biopipen/scripts/stats/MetaPvalue1.R +74 -0
- biopipen/scripts/tcgamaf/Maf2Vcf.py +2 -2
- biopipen/scripts/tcgamaf/MafAddChr.py +2 -2
- biopipen/scripts/tcr/Attach2Seurat.R +3 -2
- biopipen/scripts/tcr/CDR3AAPhyschem.R +211 -143
- biopipen/scripts/tcr/CDR3Clustering.R +343 -0
- biopipen/scripts/tcr/ClonalStats.R +526 -0
- biopipen/scripts/tcr/CloneResidency.R +255 -131
- biopipen/scripts/tcr/CloneSizeQQPlot.R +4 -4
- biopipen/scripts/tcr/GIANA/GIANA.py +1356 -797
- biopipen/scripts/tcr/GIANA/GIANA4.py +1362 -789
- biopipen/scripts/tcr/GIANA/query.py +164 -162
- biopipen/scripts/tcr/Immunarch-basic.R +31 -9
- biopipen/scripts/tcr/Immunarch-clonality.R +25 -5
- biopipen/scripts/tcr/Immunarch-diversity.R +352 -134
- biopipen/scripts/tcr/Immunarch-geneusage.R +45 -5
- biopipen/scripts/tcr/Immunarch-kmer.R +68 -8
- biopipen/scripts/tcr/Immunarch-overlap.R +84 -4
- biopipen/scripts/tcr/Immunarch-spectratyping.R +35 -6
- biopipen/scripts/tcr/Immunarch-tracking.R +38 -6
- biopipen/scripts/tcr/Immunarch-vjjunc.R +165 -0
- biopipen/scripts/tcr/Immunarch.R +63 -11
- biopipen/scripts/tcr/Immunarch2VDJtools.R +2 -2
- biopipen/scripts/tcr/ImmunarchFilter.R +4 -4
- biopipen/scripts/tcr/ImmunarchLoading.R +38 -29
- biopipen/scripts/tcr/SampleDiversity.R +1 -1
- biopipen/scripts/tcr/ScRepCombiningExpression.R +40 -0
- biopipen/scripts/tcr/ScRepLoading.R +166 -0
- biopipen/scripts/tcr/TCRClusterStats.R +176 -22
- biopipen/scripts/tcr/TCRDock.py +110 -0
- biopipen/scripts/tcr/TESSA.R +102 -118
- biopipen/scripts/tcr/VJUsage.R +5 -5
- biopipen/scripts/tcr/immunarch-patched.R +142 -0
- biopipen/scripts/tcr/vdjtools-patch.sh +1 -1
- biopipen/scripts/vcf/BcftoolsAnnotate.py +91 -0
- biopipen/scripts/vcf/BcftoolsFilter.py +90 -0
- biopipen/scripts/vcf/BcftoolsMerge.py +31 -0
- biopipen/scripts/vcf/BcftoolsSort.py +113 -0
- biopipen/scripts/vcf/BcftoolsView.py +73 -0
- biopipen/scripts/vcf/TruvariBench.sh +14 -7
- biopipen/scripts/vcf/TruvariBenchSummary.R +16 -13
- biopipen/scripts/vcf/TruvariConsistency.R +1 -1
- biopipen/scripts/vcf/Vcf2Bed.py +2 -2
- biopipen/scripts/vcf/VcfAnno.py +11 -11
- biopipen/scripts/vcf/VcfDownSample.sh +22 -10
- biopipen/scripts/vcf/VcfFilter.py +5 -5
- biopipen/scripts/vcf/VcfFix.py +7 -7
- biopipen/scripts/vcf/VcfFix_utils.py +13 -4
- biopipen/scripts/vcf/VcfIndex.py +3 -3
- biopipen/scripts/vcf/VcfIntersect.py +3 -3
- biopipen/scripts/vcf/VcfLiftOver.sh +5 -0
- biopipen/scripts/vcf/VcfSplitSamples.py +4 -4
- biopipen/scripts/vcf/bcftools_utils.py +52 -0
- biopipen/scripts/web/Download.py +8 -4
- biopipen/scripts/web/DownloadList.py +5 -5
- biopipen/scripts/web/GCloudStorageDownloadBucket.py +82 -0
- biopipen/scripts/web/GCloudStorageDownloadFile.py +23 -0
- biopipen/scripts/web/gcloud_common.py +49 -0
- biopipen/utils/gene.py +108 -60
- biopipen/utils/misc.py +146 -20
- biopipen/utils/reference.py +64 -20
- biopipen/utils/reporter.py +177 -0
- biopipen/utils/vcf.py +1 -1
- biopipen-0.34.26.dist-info/METADATA +27 -0
- biopipen-0.34.26.dist-info/RECORD +292 -0
- {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/WHEEL +1 -1
- {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/entry_points.txt +6 -2
- biopipen/ns/bcftools.py +0 -111
- biopipen/ns/scrna_basic.py +0 -255
- biopipen/reports/delim/SampleInfo.svelte +0 -36
- biopipen/reports/scrna/GeneExpressionInvistigation.svelte +0 -32
- biopipen/reports/scrna/ScFGSEA.svelte +0 -35
- biopipen/reports/scrna/SeuratClusterStats.svelte +0 -82
- biopipen/reports/scrna/SeuratMap2Ref.svelte +0 -20
- biopipen/reports/scrna/SeuratPreparing.svelte +0 -38
- biopipen/reports/scrna/TopExpressingGenes.svelte +0 -55
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +0 -31
- biopipen/reports/utils/gsea.liq +0 -110
- biopipen/scripts/bcftools/BcftoolsAnnotate.py +0 -42
- biopipen/scripts/bcftools/BcftoolsFilter.py +0 -79
- biopipen/scripts/bcftools/BcftoolsSort.py +0 -19
- biopipen/scripts/gene/GeneNameConversion.py +0 -66
- biopipen/scripts/scrna/ExprImpution-alra.R +0 -32
- biopipen/scripts/scrna/ExprImpution-rmagic.R +0 -29
- biopipen/scripts/scrna/ExprImpution.R +0 -7
- biopipen/scripts/scrna/GeneExpressionInvistigation.R +0 -132
- biopipen/scripts/scrna/Write10X.R +0 -11
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +0 -150
- biopipen/scripts/tcr/TCRClustering.R +0 -280
- biopipen/utils/common_docstrs.py +0 -61
- biopipen/utils/gene.R +0 -49
- biopipen/utils/gsea.R +0 -193
- biopipen/utils/io.R +0 -20
- biopipen/utils/misc.R +0 -114
- biopipen/utils/mutate_helpers.R +0 -433
- biopipen/utils/plot.R +0 -173
- biopipen/utils/rnaseq.R +0 -48
- biopipen/utils/single_cell.R +0 -115
- biopipen-0.21.0.dist-info/METADATA +0 -22
- biopipen-0.21.0.dist-info/RECORD +0 -218
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# srtobj, clustrees_defaults, clustrees
|
|
2
|
+
|
|
3
|
+
log$info("clustrees:")
|
|
4
|
+
|
|
5
|
+
if (
|
|
6
|
+
(is.null(clustrees) || length(clustrees) == 0) &&
|
|
7
|
+
(is.null(clustrees_defaults$prefix) || isFALSE(clustrees_defaults$prefix))) {
|
|
8
|
+
log$warn("- no case specified, skipping ...")
|
|
9
|
+
} else { # clustrees set or prefix is not empty
|
|
10
|
+
odir = file.path(outdir, "clustrees")
|
|
11
|
+
dir.create(odir, recursive=TRUE, showWarnings=FALSE)
|
|
12
|
+
|
|
13
|
+
if ((is.null(clustrees) || length(clustrees) == 0) && isTRUE(clustrees_defaults$prefix)) {
|
|
14
|
+
clustrees <- list()
|
|
15
|
+
for (key in names(srtobj@commands)) {
|
|
16
|
+
if (startsWith(key, "FindClusters") && length(srtobj@commands[[key]]$resolution) > 1) {
|
|
17
|
+
pref <- substring(key, 14)
|
|
18
|
+
if (pref == "") {
|
|
19
|
+
pref <- biopipen.utils::GetIdentityColumn(srtobj)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
clustrees[[pref]] <- list(prefix = pref)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (length(clustrees) == 0) {
|
|
27
|
+
log$warn("- no case found, skipping ...")
|
|
28
|
+
} else {
|
|
29
|
+
reporter$add(
|
|
30
|
+
list(
|
|
31
|
+
kind = "descr",
|
|
32
|
+
content = 'The clustree plots displays clustering results from the Seurat object across different
|
|
33
|
+
resolutions of the clustering algorithm
|
|
34
|
+
(<a target="_blank" href="https://satijalab.org/seurat/reference/findclusters">Seurat::FindClusters</a>).
|
|
35
|
+
Each node represents a cluster, with the resolution levels labeled along the vertical (y) axis.
|
|
36
|
+
The size of each node reflects the number of cells in that cluster. Edges connect clusters between
|
|
37
|
+
adjacent resolutions and indicate how cells transition between clusters as resolution increases.
|
|
38
|
+
The thickness of the edges corresponds to the proportion of shared cells (in_prop) between clusters,
|
|
39
|
+
where darker lines signify a higher overlap (up to 100%). The color of the edges indicates the actual
|
|
40
|
+
number of cells that transitioned between clusters.'
|
|
41
|
+
),
|
|
42
|
+
h1 = "Clustree plots"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
reports <- list()
|
|
46
|
+
for (name in names(clustrees)) {
|
|
47
|
+
if (is.null(clustrees[[name]]$prefix)) {
|
|
48
|
+
stop(paste0("clustrees: prefix is required for case: ", name))
|
|
49
|
+
}
|
|
50
|
+
log$info("- Case: {name} ...")
|
|
51
|
+
case <- list_update(clustrees_defaults, clustrees[[name]])
|
|
52
|
+
extract_vars(case, "devpars", "more_formats", "save_code")
|
|
53
|
+
|
|
54
|
+
prefix <- sub("\\.$", "", case$prefix)
|
|
55
|
+
case$prefix <- paste0(prefix, ".")
|
|
56
|
+
case$object <- srtobj
|
|
57
|
+
|
|
58
|
+
command <- srtobj@commands[[paste0("FindClusters.", prefix)]] %||%
|
|
59
|
+
(if(prefix == "seurat_clusters") srtobj@commands$FindClusters else NULL)
|
|
60
|
+
|
|
61
|
+
if (is.null(command)) {
|
|
62
|
+
resolution <- substring(colnames(case$x), nchar(case$prefix) + 1)
|
|
63
|
+
} else {
|
|
64
|
+
resolution <- command$resolution
|
|
65
|
+
}
|
|
66
|
+
resolution_used <- resolution[length(resolution)]
|
|
67
|
+
|
|
68
|
+
plot_prefix <- file.path(odir, paste0(slugify(prefix), ".clustree"))
|
|
69
|
+
p <- do_call(gglogger::register(ClustreePlot), case)
|
|
70
|
+
save_plot(p, plot_prefix, devpars, formats = c("png", more_formats))
|
|
71
|
+
|
|
72
|
+
if (save_code) {
|
|
73
|
+
save_plotcode(p, plot_prefix,
|
|
74
|
+
setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env(case, envir = .GlobalEnv))"),
|
|
75
|
+
"case",
|
|
76
|
+
auto_data_setup = FALSE)
|
|
77
|
+
}
|
|
78
|
+
reports[[length(reports) + 1]] <- reporter$image(
|
|
79
|
+
plot_prefix, more_formats, save_code, kind = "image",
|
|
80
|
+
descr = paste0("Resolutions: ", paste(resolution, collapse = ", "), "; resolution used: ", resolution_used)
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
reports$h1 <- "Clustree plots"
|
|
84
|
+
reports$ui <- "table_of_images"
|
|
85
|
+
do_call(reporter$add, reports)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
# Loaded variables: srtfile, outdir, srtobj
|
|
2
2
|
|
|
3
|
-
dimplots_defaults = {{envs.dimplots_defaults | r: todot="-"}}
|
|
4
|
-
dimplots = {{envs.dimplots | r: todot="-", skip=1}}
|
|
3
|
+
# dimplots_defaults = {{envs.dimplots_defaults | r: todot="-"}}
|
|
4
|
+
# dimplots = {{envs.dimplots | r: todot="-", skip=1}}
|
|
5
|
+
log$info("dimplots:")
|
|
5
6
|
|
|
6
|
-
odir
|
|
7
|
+
odir <- file.path(outdir, "dimplots")
|
|
7
8
|
dir.create(odir, recursive=TRUE, showWarnings=FALSE)
|
|
8
|
-
report_toc_file = file.path(odir, "report_toc.json")
|
|
9
|
-
# Realname => file
|
|
10
|
-
report_toc = list()
|
|
11
9
|
|
|
12
10
|
do_one_dimplot = function(name) {
|
|
13
|
-
|
|
11
|
+
log$info("- Case: {name}")
|
|
14
12
|
|
|
15
|
-
case
|
|
16
|
-
case$devpars = list_update(dimplots_defaults$devpars, dimplots[[name]]$devpars)
|
|
17
|
-
case$object = srtobj
|
|
18
|
-
if (is.null(case$cols)) {
|
|
19
|
-
case$cols = pal_ucscgb()(26)
|
|
20
|
-
}
|
|
13
|
+
case <- list_update(dimplots_defaults, dimplots[[name]])
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
15
|
+
# Get functional arguments and inconsistent arguments
|
|
16
|
+
subset <- case$subset; case$subset <- NULL
|
|
17
|
+
reduction <- case$reduction; case$reduction <- NULL
|
|
18
|
+
devpars <- case$devpars; case$devpars <- NULL
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
# Normalize arguments
|
|
21
|
+
reduction <- if (reduction %in% c("dim", "auto")) DefaultDimReduc(srtobj) else reduction
|
|
22
|
+
devpars <- list_update(dimplots_defaults$devpars, devpars)
|
|
23
|
+
key <- paste0("sub_umap_", case$group_by)
|
|
31
24
|
|
|
32
|
-
if (
|
|
33
|
-
case$
|
|
25
|
+
if (!is.null(subset)) {
|
|
26
|
+
case$object <- srtobj %>% filter(!!parse_expr(subset))
|
|
27
|
+
} else {
|
|
28
|
+
case$object <- srtobj
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
if (key %in% names(case$object@reductions) && is.null(reduction)) {
|
|
31
|
+
case$reduction = key
|
|
32
|
+
} else {
|
|
33
|
+
case$reduction = reduction
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
p <- do_call(CellDimPlot, case)
|
|
37
|
+
prefix <- file.path(odir, paste0(slugify(name), ".dim"))
|
|
38
|
+
save_plot(p, prefix, devpars)
|
|
39
|
+
|
|
40
|
+
reporter$add(
|
|
41
|
+
list(
|
|
42
|
+
kind = "descr",
|
|
43
|
+
content = paste0("Dimensionality reduction plot for ", case$group_by)
|
|
44
|
+
),
|
|
45
|
+
reporter$image(prefix, "pdf", FALSE),
|
|
46
|
+
h1 = name
|
|
47
|
+
)
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
sapply(names(dimplots), do_one_dimplot)
|
|
44
|
-
.save_toc()
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
# Loaded variables: srtfile, outdir, srtobj
|
|
2
2
|
|
|
3
|
-
features_defaults = {{envs.features_defaults | r: todot="-"}}
|
|
4
|
-
features = {{envs.features | r: todot="-", skip=1}}
|
|
3
|
+
# features_defaults = {{envs.features_defaults | r: todot="-"}}
|
|
4
|
+
# features = {{envs.features | r: todot="-", skip=1}}
|
|
5
|
+
log$info("features:")
|
|
5
6
|
|
|
6
7
|
odir = file.path(outdir, "features")
|
|
7
8
|
dir.create(odir, recursive=TRUE, showWarnings=FALSE)
|
|
8
|
-
report_toc_file = file.path(odir, "report_toc.json")
|
|
9
|
-
# Section => list(
|
|
10
|
-
# list(name?, kind, file),
|
|
11
|
-
# ...
|
|
12
|
-
# )
|
|
13
|
-
report_toc = list()
|
|
14
|
-
|
|
15
|
-
.add_toc = function(section, toc) {
|
|
16
|
-
if (section %in% names(report_toc)) {
|
|
17
|
-
report_toc[[section]][[length(report_toc[[section]]) + 1]] <<- toc
|
|
18
|
-
} else {
|
|
19
|
-
report_toc[[section]] <<- list(toc)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
9
|
|
|
23
|
-
|
|
10
|
+
# highly variable features
|
|
11
|
+
hvf <- NULL
|
|
12
|
+
|
|
13
|
+
.get_features = function(features, object) {
|
|
24
14
|
if (is.null(features)) { features = 20 }
|
|
25
15
|
if (is.numeric(features)) {
|
|
26
|
-
|
|
16
|
+
if (!is.null(hvf)) {
|
|
17
|
+
return(hvf[1:features])
|
|
18
|
+
}
|
|
19
|
+
vf <- VariableFeatures(object)
|
|
20
|
+
if (length(vf) == 0) {
|
|
21
|
+
if (DefaultAssay(object) == "SCT") {
|
|
22
|
+
# Still use RNA assay to find variable features
|
|
23
|
+
# See
|
|
24
|
+
# https://github.com/satijalab/seurat/issues/6064
|
|
25
|
+
# https://github.com/satijalab/seurat/issues/8238
|
|
26
|
+
# https://github.com/satijalab/seurat/issues/5761
|
|
27
|
+
vf <- FindVariableFeatures(object, nfeatures = features, assay = "RNA")
|
|
28
|
+
} else {
|
|
29
|
+
vf <- FindVariableFeatures(object, nfeatures = features)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
hvf <<- vf
|
|
33
|
+
return(hvf[1:features])
|
|
27
34
|
}
|
|
28
35
|
if (is.character(features) && length(features) > 1) {
|
|
29
36
|
return (features)
|
|
@@ -46,192 +53,136 @@ report_toc = list()
|
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
55
|
|
|
56
|
+
if (is.list(features)) {
|
|
57
|
+
return(lapply(features, function(x) {.get_features(x, object) }))
|
|
58
|
+
}
|
|
59
|
+
|
|
49
60
|
return (trimws(unlist(strsplit(features, ","))))
|
|
50
61
|
}
|
|
51
62
|
|
|
52
|
-
do_one_features
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
case = list_update(features_defaults, features[[name]])
|
|
56
|
-
toc = list()
|
|
57
|
-
if (!is.null(case$section)) { toc$name = name }
|
|
58
|
-
case$devpars = list_update(features_defaults$devpars, features[[name]]$devpars)
|
|
59
|
-
excluded_args = c(
|
|
60
|
-
"section",
|
|
61
|
-
"devpars",
|
|
62
|
-
"subset",
|
|
63
|
-
"plus",
|
|
64
|
-
"ident",
|
|
65
|
-
"kind"
|
|
66
|
-
)
|
|
63
|
+
do_one_features <- function(name) {
|
|
64
|
+
log$info("- Case: {name}")
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
default_devpars = function(features, ncol, uidents) {
|
|
78
|
-
if (is.null(ncol)) { ncol = 1 }
|
|
79
|
-
list(
|
|
80
|
-
width = 400 * ncol,
|
|
81
|
-
height = ceiling(length(features) / ncol) * ifelse(length(uidents) < 10, 300, 400),
|
|
82
|
-
res = 100
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
} else if ("vln" %in% case$kind || "violin" %in% case$kind) {
|
|
86
|
-
case$kind = "violin"
|
|
87
|
-
if (is.null(case$cols)) {
|
|
88
|
-
case$cols = pal_ucscgb(alpha = .8)(26)
|
|
89
|
-
}
|
|
90
|
-
fn = VlnPlot
|
|
91
|
-
default_devpars = function(features, ncol, uidents) {
|
|
92
|
-
if (is.null(ncol)) { ncol = 1 }
|
|
93
|
-
list(
|
|
94
|
-
width = 400 * ncol,
|
|
95
|
-
height = ceiling(length(features) / ncol) * 400,
|
|
96
|
-
res = 100
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
} else if ("feature" %in% case$kind) {
|
|
100
|
-
case$kind = "feature"
|
|
101
|
-
if (is.null(case$cols)) {
|
|
102
|
-
case$cols = c("lightgrey", pal_ucscgb()(1))
|
|
103
|
-
}
|
|
104
|
-
excluded_args = c(excluded_args, "group.by", "assay")
|
|
105
|
-
case$shape.by = case$group.by
|
|
106
|
-
fn = FeaturePlot
|
|
107
|
-
default_devpars = function(features, ncol, uidents) {
|
|
108
|
-
if (is.null(ncol)) { ncol = 1 }
|
|
109
|
-
list(
|
|
110
|
-
width = 400 * ncol,
|
|
111
|
-
height = ceiling(length(features) / ncol) * 300,
|
|
112
|
-
res = 100
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
} else if ("dot" %in% case$kind) {
|
|
116
|
-
case$kind = "dot"
|
|
117
|
-
if (is.null(case$cols)) {
|
|
118
|
-
case$cols = c("lightgrey", pal_ucscgb()(1))
|
|
119
|
-
}
|
|
120
|
-
if (is.null(case$plus)) {
|
|
121
|
-
case$plus = 'theme_prism(axis_text_angle=90)'
|
|
122
|
-
}
|
|
123
|
-
excluded_args = c(excluded_args, "slot", "ncol")
|
|
124
|
-
fn = DotPlot
|
|
125
|
-
default_devpars = function(features, ncol, uidents) {
|
|
126
|
-
list(
|
|
127
|
-
height = max(length(uidents) * 80 + 150, 420),
|
|
128
|
-
width = length(features) * 50 + 150,
|
|
129
|
-
res = 100
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
} else if ("heatmap" %in% case$kind) {
|
|
133
|
-
case$kind = "heatmap"
|
|
134
|
-
case = list_update(
|
|
135
|
-
list(
|
|
136
|
-
group.colors = pal_ucscgb(alpha = .8)(26),
|
|
137
|
-
size = 3.5,
|
|
138
|
-
group.bar.height = 0.01
|
|
139
|
-
),
|
|
140
|
-
case
|
|
141
|
-
)
|
|
142
|
-
if (is.null(case$plus)) {
|
|
143
|
-
case$plus = 'scale_fill_gradientn(colors = c("lightgrey", pal_ucscgb()(1)), na.value = "white")'
|
|
144
|
-
}
|
|
145
|
-
excluded_args = c(excluded_args, "group.by", "split.by", "downsample", "ncol")
|
|
146
|
-
fn = DoHeatmap
|
|
147
|
-
default_devpars = function(features, ncol, uidents) {
|
|
148
|
-
list(
|
|
149
|
-
width = length(uidents) * 60 + 150,
|
|
150
|
-
height = length(features) * 40 + 150,
|
|
151
|
-
res = 100
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
} else if ("table" %in% case$kind) {
|
|
155
|
-
case$kind = "table"
|
|
156
|
-
excluded_args = c(excluded_args, "group.by", "split.by", "assay")
|
|
157
|
-
case$assays = case$assay
|
|
158
|
-
fn = AverageExpression
|
|
159
|
-
if (is.null(case$slot)) {
|
|
160
|
-
case$slot = "data"
|
|
161
|
-
}
|
|
66
|
+
case <- list_update(features_defaults, features[[name]])
|
|
67
|
+
case <- extract_vars(
|
|
68
|
+
case,
|
|
69
|
+
"devpars", "more_formats", "save_code", "save_data", "order_by",
|
|
70
|
+
"subset", "features", "descr",
|
|
71
|
+
allow_nonexisting = TRUE)
|
|
72
|
+
|
|
73
|
+
if (!is.null(subset)) {
|
|
74
|
+
case$object <- srtobj %>% filter(!!parse_expr(subset))
|
|
162
75
|
} else {
|
|
163
|
-
|
|
76
|
+
case$object <- srtobj
|
|
164
77
|
}
|
|
165
78
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
79
|
+
if (exists("order_by") && !is.null(order_by)) {
|
|
80
|
+
case$ident <- case$ident %||% GetIdentityColumn(case$object)
|
|
81
|
+
if (length(order_by) < 2) {
|
|
82
|
+
clusters <- case$object@meta.data %>%
|
|
83
|
+
group_by(!!sym(case$ident)) %>%
|
|
84
|
+
arrange(!!parse_expr(order_by)) %>%
|
|
85
|
+
ungroup() %>%
|
|
86
|
+
pull(!!sym(case$ident)) %>%
|
|
87
|
+
unique()
|
|
170
88
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
if (!is.null(ident)) {
|
|
177
|
-
Idents(case$object) = ident
|
|
178
|
-
}
|
|
179
|
-
case$features = .get_features(case$features)
|
|
180
|
-
if (!is.null(case$ncol)) {
|
|
181
|
-
case$ncol = min(case$ncol, length(case$features))
|
|
89
|
+
case$object@meta.data[[case$ident]] <- factor(case$object@meta.data[[case$ident]], levels = clusters)
|
|
90
|
+
} else {
|
|
91
|
+
case$object@meta.data[[case$ident]] <- fct_relevel(case$object@meta.data[[case$ident]], order_by)
|
|
92
|
+
}
|
|
182
93
|
}
|
|
183
94
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
95
|
+
info <- case_info(name, odir, is_dir = FALSE, create = TRUE)
|
|
96
|
+
|
|
97
|
+
caching <- Cache$new(
|
|
98
|
+
c(case, list(devpars, more_formats, save_code, save_data, order_by, subset, features, descr)),
|
|
99
|
+
prefix = "biopipen.scrna.SeuratClusterStats.features",
|
|
100
|
+
cache_dir = cache,
|
|
101
|
+
kind = "prefix",
|
|
102
|
+
path = info$prefix
|
|
103
|
+
)
|
|
190
104
|
|
|
191
|
-
|
|
192
|
-
|
|
105
|
+
if (caching$is_cached()) {
|
|
106
|
+
log$info(" plots are cached, restoring ...")
|
|
107
|
+
caching$restore()
|
|
193
108
|
} else {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
case
|
|
206
|
-
|
|
207
|
-
stop("Unknown downsample method.")
|
|
208
|
-
}
|
|
109
|
+
case$features <- .get_features(features, case$object)
|
|
110
|
+
p <- tryCatch({
|
|
111
|
+
do_call(gglogger::register(FeatureStatPlot), case)
|
|
112
|
+
}, error = function(e) {
|
|
113
|
+
if (save_code) { stop(e) }
|
|
114
|
+
do_call(FeatureStatPlot, case)
|
|
115
|
+
})
|
|
116
|
+
save_plot(p, info$prefix, devpars, formats = c("png", more_formats))
|
|
117
|
+
if (save_code) {
|
|
118
|
+
save_plotcode(p, info$prefix,
|
|
119
|
+
setup = c("library(scplotter)", "load('data.RData')", "invisible(list2env(case, envir = .GlobalEnv))"),
|
|
120
|
+
"case",
|
|
121
|
+
auto_data_setup = FALSE)
|
|
209
122
|
}
|
|
210
|
-
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
|
|
123
|
+
|
|
124
|
+
if (save_data) {
|
|
125
|
+
pdata <- attr(p, "data") %||% p$data
|
|
126
|
+
if (!inherits(pdata, "data.frame") && !inherits(pdata, "matrix")) {
|
|
127
|
+
stop("'save_data = TRUE' is not supported for plot_type: ", case$plot_type)
|
|
214
128
|
}
|
|
129
|
+
write.table(pdata, paste0(info$prefix, ".data.txt"), sep="\t", quote=FALSE, row.names=FALSE)
|
|
215
130
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
131
|
+
|
|
132
|
+
caching$save(info$prefix)
|
|
133
|
+
}
|
|
134
|
+
# add reports
|
|
135
|
+
default_descr <- glue(
|
|
136
|
+
"The plot shows the distribution or pattern of the specified features ({paste(case$features %||% features, collapse = ', ')}) ",
|
|
137
|
+
"across cells",
|
|
138
|
+
"{if (!is.null(case$ident)) glue(', identified by \"{case$ident}\"') else ''}",
|
|
139
|
+
"{if (!is.null(case$group_by)) glue(', grouped by \"{case$group_by}\"') else ''}",
|
|
140
|
+
"{if (!is.null(case$split_by)) glue(', and split by \"{case$split_by}\"') else ''}. ",
|
|
141
|
+
"The plot type is '{case$plot_type}', ",
|
|
142
|
+
"{if (case$plot_type == 'dim') 'displaying the features on a dimensional reduction embedding' ",
|
|
143
|
+
" else if (case$plot_type == 'heatmap') 'arranged as a heatmap by rows_name and other grouping variables' ",
|
|
144
|
+
" else if (case$plot_type %in% c('violin', 'box', 'ridge')) 'showing the distribution of feature values by the grouping variables' ",
|
|
145
|
+
" else if (case$plot_type == 'cor') 'showing the correlation between features' ",
|
|
146
|
+
" else 'showing aggregated feature values by the grouping variables'}. ",
|
|
147
|
+
"{if (!is.null(case$facet_by)) glue('Plots are further faceted by \"{case$facet_by}\". ') else ''}",
|
|
148
|
+
"{if (case$plot_type == 'dim') glue('The reduction used is \"{if (!is.null(case$reduction)) case$reduction else DefaultDimReduc(case$object)}\"') else ''}",
|
|
149
|
+
"{if (case$plot_type == 'dim' && !is.null(case$graph)) glue(', with graph \"{case$graph}\" drawn to show cell neighbor edges') else ''}",
|
|
150
|
+
"{if (case$plot_type == 'dim' && !is.null(case$bg_cutoff) && case$bg_cutoff > 0) glue(', and a background cutoff of {case$bg_cutoff}') else ''}",
|
|
151
|
+
"{if (case$plot_type == 'dim') glue(', using dimensions {paste(case$dims %||% 1:2, collapse = \",\")}') else ''}"
|
|
152
|
+
)
|
|
153
|
+
if (!is.null(case$comparisons)) {
|
|
154
|
+
default_descr <- paste0(
|
|
155
|
+
default_descr,
|
|
156
|
+
glue("Statistical comparisons were performed between groups using \"{case$pairwise_method %||% 'wilcox.test'}\" method.")
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
reporter$add2(
|
|
160
|
+
list(kind = "descr", content = descr %||% default_descr),
|
|
161
|
+
hs = c(info$section, info$name)
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
if (save_data) {
|
|
165
|
+
reporter$add2(
|
|
166
|
+
list(
|
|
167
|
+
name = "Plot",
|
|
168
|
+
contents = list(reporter$image(info$prefix, more_formats, save_code, kind = "image"))
|
|
169
|
+
),
|
|
170
|
+
list(
|
|
171
|
+
name = "Data",
|
|
172
|
+
contents = list(
|
|
173
|
+
list(kind = "descr", content = "Data used directly for the plot"),
|
|
174
|
+
list(kind = "table", src = paste0(info$prefix, ".data.txt"), data = list(nrows = 100))
|
|
228
175
|
)
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
|
|
176
|
+
),
|
|
177
|
+
hs = c(info$section, info$name),
|
|
178
|
+
ui = "tabs"
|
|
179
|
+
)
|
|
180
|
+
} else {
|
|
181
|
+
reporter$add2(
|
|
182
|
+
reporter$image(info$prefix, more_formats, save_code, kind = "image"),
|
|
183
|
+
hs = c(info$section, info$name)
|
|
184
|
+
)
|
|
232
185
|
}
|
|
233
|
-
.add_toc(if (is.null(section)) name else section, toc)
|
|
234
186
|
}
|
|
235
187
|
|
|
236
188
|
sapply(names(features), do_one_features)
|
|
237
|
-
.save_toc()
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Loaded variables: srtfile, outdir, srtobj
|
|
2
|
+
|
|
3
|
+
# ngenes_defaults <- {{envs.ngenes_defaults | r: todot="-"}}
|
|
4
|
+
# ngenes <- {{envs.ngenes | r: todot="-", skip=1}}
|
|
5
|
+
log$info("ngenes:")
|
|
6
|
+
|
|
7
|
+
odir <- file.path(outdir, "ngenes")
|
|
8
|
+
dir.create(odir, recursive=TRUE, showWarnings=FALSE)
|
|
9
|
+
|
|
10
|
+
do_one_ngenes <- function(name) {
|
|
11
|
+
log$info("- Case: {name}")
|
|
12
|
+
|
|
13
|
+
case <- list_update(ngenes_defaults, ngenes[[name]])
|
|
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")
|
|
22
|
+
|
|
23
|
+
if (!is.null(case$subset)) {
|
|
24
|
+
case$object <- srtobj %>% filter(!!rlang::parse_expr(subset_))
|
|
25
|
+
} else {
|
|
26
|
+
case$object <- srtobj
|
|
27
|
+
}
|
|
28
|
+
case$object <- AddMetaData(case$object, Matrix::colSums(GetAssayData(case$object) > 0), col.name = "Number of expressed genes")
|
|
29
|
+
|
|
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
|
+
)
|
|
39
|
+
}
|
|
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")
|
|
52
|
+
)
|
|
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
|
+
)
|
|
66
|
+
)
|
|
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
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
sapply(names(ngenes), do_one_ngenes)
|