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
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
+
{{ biopipen_dir | joinpaths: "utils", "repr.R" | source_r }}
|
|
3
|
+
|
|
1
4
|
library(Seurat)
|
|
2
5
|
library(rlang)
|
|
3
6
|
library(dplyr)
|
|
@@ -5,28 +8,97 @@ library(tidyr)
|
|
|
5
8
|
library(tibble)
|
|
6
9
|
library(ggplot2)
|
|
7
10
|
library(ggradar)
|
|
11
|
+
library(ggprism)
|
|
12
|
+
library(glue)
|
|
13
|
+
library(gglogger)
|
|
8
14
|
|
|
9
15
|
# input/output
|
|
10
16
|
srtfile = {{in.srtobj | r}}
|
|
11
17
|
outdir = {{out.outdir | r}}
|
|
18
|
+
joboutdir = {{job.outdir | r}}
|
|
12
19
|
|
|
13
20
|
# envs
|
|
14
21
|
mutaters = {{envs.mutaters | r}}
|
|
15
22
|
by = {{envs.by | r}}
|
|
16
23
|
each = {{envs.each | r}}
|
|
24
|
+
prefix_each = {{envs.prefix_each | r}}
|
|
17
25
|
order = {{envs.order | r}}
|
|
18
|
-
|
|
26
|
+
colors = {{envs.colors | r}}
|
|
27
|
+
ident = {{envs.ident | r}}
|
|
19
28
|
cluster_order = {{envs.cluster_order | r}}
|
|
20
29
|
breaks = {{envs.breaks | r}}
|
|
30
|
+
breakdown = {{envs.breakdown | r}}
|
|
31
|
+
test = {{envs.test | r}}
|
|
21
32
|
direction = {{envs.direction | r}}
|
|
22
33
|
section = {{envs.section | r}}
|
|
34
|
+
subset_ = {{envs.subset | r}}
|
|
35
|
+
bar_devpars = {{envs.bar_devpars | r}}
|
|
23
36
|
devpars = {{envs.devpars | r}}
|
|
24
37
|
cases = {{envs.cases | r}}
|
|
25
38
|
|
|
26
|
-
DEFAULT_CASE = "DEFAULT"
|
|
39
|
+
# DEFAULT_CASE = "DEFAULT"
|
|
40
|
+
# sections = c()
|
|
41
|
+
|
|
42
|
+
log_info("- Reading srtobj ...")
|
|
43
|
+
srtobj = biopipen.utils::read_obj(srtfile)
|
|
44
|
+
meta = srtobj@meta.data
|
|
45
|
+
|
|
46
|
+
log_info("- Mutating meta data if needed ...")
|
|
47
|
+
if (is.list(mutaters) && length(mutaters) > 0) {
|
|
48
|
+
mutaters <- lapply(mutaters, function(x) parse_expr(x))
|
|
49
|
+
meta <- meta %>% mutate(!!!mutaters)
|
|
50
|
+
}
|
|
27
51
|
|
|
28
|
-
|
|
29
|
-
|
|
52
|
+
defaults <- list(
|
|
53
|
+
by = by,
|
|
54
|
+
each = each,
|
|
55
|
+
prefix_each = prefix_each,
|
|
56
|
+
order = order,
|
|
57
|
+
colors = colors,
|
|
58
|
+
ident = ident,
|
|
59
|
+
cluster_order = cluster_order,
|
|
60
|
+
breaks = breaks,
|
|
61
|
+
breakdown = breakdown,
|
|
62
|
+
test = test,
|
|
63
|
+
direction = direction,
|
|
64
|
+
section = section,
|
|
65
|
+
subset = subset_,
|
|
66
|
+
bar_devpars = bar_devpars,
|
|
67
|
+
devpars = devpars
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
expand_each <- function(name, case) {
|
|
71
|
+
outcases <- list()
|
|
72
|
+
if (is.null(case$each) || nchar(case$each) == 0) {
|
|
73
|
+
if (is.null(case$section) || case$section == "DEFAULT") {
|
|
74
|
+
outcases[[name]] <- case
|
|
75
|
+
} else {
|
|
76
|
+
outcases[[paste0(case$section, "::", name)]] <- case
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
if (is.null(case$subset)) {
|
|
80
|
+
eachs <- meta %>%
|
|
81
|
+
pull(case$each) %>% unique() %>% na.omit() %>% as.vector()
|
|
82
|
+
} else {
|
|
83
|
+
eachs <- meta %>% filter(!!parse_expr(case$subset)) %>%
|
|
84
|
+
pull(case$each) %>% unique() %>% na.omit() %>% as.vector()
|
|
85
|
+
}
|
|
86
|
+
for (each in eachs) {
|
|
87
|
+
if (isTRUE(case$prefix_each)) {
|
|
88
|
+
key <- paste0(name, "::", case$each, " - ", each)
|
|
89
|
+
} else {
|
|
90
|
+
key <- paste0(name, "::", each)
|
|
91
|
+
}
|
|
92
|
+
outcases[[key]] <- case
|
|
93
|
+
outcases[[key]]$section <- name
|
|
94
|
+
outcases[[key]]$each_value <- each
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
outcases
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
log_info("- Expanding cases ...")
|
|
101
|
+
cases <- expand_cases(cases, defaults, expand_each)
|
|
30
102
|
|
|
31
103
|
auto_breaks = function(maxval) {
|
|
32
104
|
if (maxval <= 0.1) { # 10%
|
|
@@ -52,24 +124,13 @@ auto_breaks = function(maxval) {
|
|
|
52
124
|
}
|
|
53
125
|
}
|
|
54
126
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# Save the section
|
|
60
|
-
if (is.character(case$section) && nchar(case$section) > 0) {
|
|
61
|
-
sections[[case$section]] <<- c(sections[[case$section]], casename)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
# Get the counts
|
|
65
|
-
counts = if (!is.null(case$each)) meta %>% filter(!!sym(case$each) == case$each_value) else meta
|
|
66
|
-
counts = counts %>%
|
|
67
|
-
filter(!is.na(!!sym(case$by))) %>%
|
|
68
|
-
group_by(!!sym(case$cluster_col), !!sym(case$by)) %>%
|
|
127
|
+
do_radarplot <- function(info, case, counts) {
|
|
128
|
+
rdr_data = counts %>%
|
|
129
|
+
group_by(!!sym(case$ident), !!sym(case$by)) %>%
|
|
69
130
|
count() %>%
|
|
70
131
|
pivot_wider(
|
|
71
132
|
id_cols = case$by,
|
|
72
|
-
names_from = !!sym(case$
|
|
133
|
+
names_from = !!sym(case$ident),
|
|
73
134
|
values_from = n,
|
|
74
135
|
values_fill = 0
|
|
75
136
|
) %>%
|
|
@@ -81,25 +142,26 @@ run_one_case = function(casename) {
|
|
|
81
142
|
|
|
82
143
|
# Reorder the clusters if needed
|
|
83
144
|
if (!is.null(case$cluster_order) && length(case$cluster_order) > 0) {
|
|
84
|
-
|
|
145
|
+
rdr_data = rdr_data[, case$cluster_order]
|
|
85
146
|
}
|
|
86
147
|
|
|
87
148
|
# If clusters are numbers, add a prefix "Cluster"
|
|
88
|
-
if (all(grepl("^\\d+$", colnames(
|
|
89
|
-
colnames(
|
|
149
|
+
if (all(grepl("^\\d+$", colnames(rdr_data)))) {
|
|
150
|
+
colnames(rdr_data) = paste0("Cluster", colnames(rdr_data))
|
|
90
151
|
}
|
|
91
152
|
|
|
92
153
|
if (!is.null(case$order) && length(case$order) > 0) {
|
|
93
|
-
|
|
94
|
-
if (nrow(
|
|
154
|
+
rdr_data = rdr_data[case$order, ]
|
|
155
|
+
if (nrow(rdr_data) == 0) {
|
|
95
156
|
stop("No data after reordering. Are items in `order` correct?")
|
|
96
157
|
}
|
|
97
158
|
}
|
|
98
159
|
|
|
99
160
|
# Save the counts
|
|
161
|
+
counts_file = file.path(info$casedir, "counts.tsv")
|
|
100
162
|
write.table(
|
|
101
|
-
|
|
102
|
-
|
|
163
|
+
t(rdr_data),
|
|
164
|
+
counts_file,
|
|
103
165
|
sep = "\t",
|
|
104
166
|
quote = FALSE,
|
|
105
167
|
col.names = TRUE,
|
|
@@ -107,17 +169,18 @@ run_one_case = function(casename) {
|
|
|
107
169
|
)
|
|
108
170
|
|
|
109
171
|
# Calculate the percentage
|
|
110
|
-
|
|
172
|
+
rdr_data = as.matrix(rdr_data)
|
|
111
173
|
if (case$direction == "inter-cluster") {
|
|
112
|
-
|
|
174
|
+
rdr_data = t(t(rdr_data) / rowSums(t(rdr_data)))
|
|
113
175
|
} else {
|
|
114
|
-
|
|
176
|
+
rdr_data = rdr_data / rowSums(rdr_data)
|
|
115
177
|
}
|
|
116
178
|
|
|
117
179
|
# Save the percentages
|
|
180
|
+
perc_file = file.path(info$casedir, "percentages.tsv")
|
|
118
181
|
write.table(
|
|
119
|
-
|
|
120
|
-
|
|
182
|
+
t(rdr_data),
|
|
183
|
+
perc_file,
|
|
121
184
|
sep = "\t",
|
|
122
185
|
quote = FALSE,
|
|
123
186
|
col.names = TRUE,
|
|
@@ -126,132 +189,290 @@ run_one_case = function(casename) {
|
|
|
126
189
|
|
|
127
190
|
# Get the breaks
|
|
128
191
|
breaks = if (is.null(case$breaks) || length(case$breaks) == 0) {
|
|
129
|
-
auto_breaks(max(
|
|
192
|
+
auto_breaks(max(rdr_data))
|
|
130
193
|
} else {
|
|
131
194
|
case$breaks
|
|
132
195
|
}
|
|
133
196
|
|
|
134
197
|
# Plot
|
|
198
|
+
if (!is.null(case$colors) && length(case$colors) == 1 && case$colors == "biopipen") {
|
|
199
|
+
colors = pal_biopipen()(nrow(rdr_data))
|
|
200
|
+
} else if (!is.null(case$colors) && length(case$colors) > 0) {
|
|
201
|
+
colors = trimws(unlist(strsplit(case$colors, ",")))
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
plotdf <- rdr_data %>%
|
|
205
|
+
as.data.frame() %>%
|
|
206
|
+
rownames_to_column("group") %>%
|
|
207
|
+
mutate(group = factor(group, levels = rownames(rdr_data)))
|
|
208
|
+
|
|
135
209
|
p = ggradar(
|
|
136
|
-
|
|
210
|
+
plotdf,
|
|
137
211
|
values.radar = paste0(breaks, "%"),
|
|
138
212
|
grid.min = breaks[1] / 100,
|
|
139
213
|
grid.mid = breaks[2] / 100,
|
|
140
214
|
grid.max = breaks[3] / 100,
|
|
141
|
-
|
|
215
|
+
group.colours = colors
|
|
142
216
|
)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
217
|
+
prefix <- file.path(info$casedir, "plot")
|
|
218
|
+
save_plot(p, prefix, case$devpars)
|
|
219
|
+
|
|
220
|
+
code_file <- paste0(prefix, ".R")
|
|
221
|
+
code = glue(
|
|
222
|
+
"library(ggradar)
|
|
223
|
+
|
|
224
|
+
plotdf <- {repr(plotdf)}
|
|
225
|
+
breaks <- {repr(breaks)}
|
|
226
|
+
colors <- {repr(colors)}
|
|
227
|
+
|
|
228
|
+
ggradar(
|
|
229
|
+
plotdf,
|
|
230
|
+
values.radar = paste0(breaks, '%'),
|
|
231
|
+
grid.min = breaks[1] / 100,
|
|
232
|
+
grid.mid = breaks[2] / 100,
|
|
233
|
+
grid.max = breaks[3] / 100,
|
|
234
|
+
group.colours = colors
|
|
235
|
+
)"
|
|
148
236
|
)
|
|
149
|
-
|
|
150
|
-
dev.off()
|
|
237
|
+
writeLines(code, code_file)
|
|
151
238
|
}
|
|
152
239
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
240
|
+
do_barplot_and_tests <- function(info, case, counts) {
|
|
241
|
+
bardata <- counts %>%
|
|
242
|
+
group_by(!!sym(case$by), !!sym(case$breakdown), !!sym(case$ident)) %>%
|
|
243
|
+
summarise(.n = n(), .groups = "drop")
|
|
244
|
+
|
|
245
|
+
write.table(
|
|
246
|
+
bardata,
|
|
247
|
+
file.path(info$casedir, "breakdown-counts.txt"),
|
|
248
|
+
sep = "\t",
|
|
249
|
+
quote = FALSE,
|
|
250
|
+
col.names = TRUE,
|
|
251
|
+
row.names = FALSE
|
|
165
252
|
)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
cases[[key]]$order = order
|
|
177
|
-
}
|
|
178
|
-
if (is.null(cases[[key]]$cluster_col)) {
|
|
179
|
-
cases[[key]]$cluster_col = cluster_col
|
|
180
|
-
}
|
|
181
|
-
if (is.null(cases[[key]]$cluster_order)) {
|
|
182
|
-
cases[[key]]$cluster_order = cluster_order
|
|
183
|
-
}
|
|
184
|
-
if (is.null(cases[[key]]$breaks)) {
|
|
185
|
-
cases[[key]]$breaks = breaks
|
|
186
|
-
}
|
|
187
|
-
if (is.null(cases[[key]]$direction)) {
|
|
188
|
-
cases[[key]]$direction = direction
|
|
189
|
-
}
|
|
190
|
-
if (is.null(cases[[key]]$section)) {
|
|
191
|
-
cases[[key]]$section = section
|
|
192
|
-
}
|
|
193
|
-
if (is.null(cases[[key]]$devpars)) {
|
|
194
|
-
cases[[key]]$devpars = devpars
|
|
195
|
-
}
|
|
196
|
-
if (is.null(cases[[key]]$devpars$width)) {
|
|
197
|
-
cases[[key]]$devpars$width = devpars$width
|
|
198
|
-
}
|
|
199
|
-
if (is.null(cases[[key]]$devpars$height)) {
|
|
200
|
-
cases[[key]]$devpars$height = devpars$height
|
|
201
|
-
}
|
|
202
|
-
if (is.null(cases[[key]]$devpars$res)) {
|
|
203
|
-
cases[[key]]$devpars$res = devpars$res
|
|
204
|
-
}
|
|
253
|
+
if (case$direction == "inter-cluster") {
|
|
254
|
+
bardata <- bardata %>%
|
|
255
|
+
group_by(!!sym(case$ident)) %>%
|
|
256
|
+
mutate(.frac = .n / sum(.n)) %>%
|
|
257
|
+
ungroup()
|
|
258
|
+
} else {
|
|
259
|
+
bardata <- bardata %>%
|
|
260
|
+
group_by(!!sym(case$by), !!sym(case$breakdown)) %>%
|
|
261
|
+
mutate(.frac = .n / sum(.n)) %>%
|
|
262
|
+
ungroup()
|
|
205
263
|
}
|
|
206
|
-
}
|
|
207
264
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
265
|
+
# Save the percentages
|
|
266
|
+
write.table(
|
|
267
|
+
bardata,
|
|
268
|
+
file.path(info$casedir, "breakdown-percentages.txt"),
|
|
269
|
+
sep = "\t",
|
|
270
|
+
quote = FALSE,
|
|
271
|
+
col.names = TRUE,
|
|
272
|
+
row.names = FALSE
|
|
273
|
+
)
|
|
211
274
|
|
|
212
|
-
|
|
213
|
-
if (is.
|
|
214
|
-
|
|
215
|
-
|
|
275
|
+
# Reorder the clusters if needed
|
|
276
|
+
if (!is.null(case$cluster_order) && length(case$cluster_order) > 0) {
|
|
277
|
+
bardata <- bardata %>%
|
|
278
|
+
mutate(!!sym(case$ident) := factor(!!sym(case$ident), levels = case$cluster_order))
|
|
279
|
+
}
|
|
280
|
+
# Calculate the mean, mean-sd, mean+sd
|
|
281
|
+
plotdata <- bardata %>%
|
|
282
|
+
group_by(!!sym(case$by), !!sym(case$ident)) %>%
|
|
283
|
+
summarise(.mean = mean(.frac), .sd = sd(.frac), .groups = "drop") %>%
|
|
284
|
+
rowwise() %>%
|
|
285
|
+
mutate(mean_sd1 = max(.mean - .sd, 0), mean_sd2 = .mean + .sd)
|
|
286
|
+
|
|
287
|
+
if (!is.null(case$colors) && length(case$colors) == 1 && case$colors == "biopipen") {
|
|
288
|
+
colors <- pal_biopipen(.8)(length(unique(plotdata[[case$by]])))
|
|
289
|
+
} else if (!is.null(case$colors) && length(case$colors) > 0) {
|
|
290
|
+
colors <- trimws(unlist(strsplit(case$colors, ",")))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
# Plot the barplot
|
|
294
|
+
p = ggplot(plotdata, aes(x = !!sym(case$ident), y = .mean, fill = !!sym(case$by))) +
|
|
295
|
+
geom_bar(stat = "identity", position = "dodge", color = "#333333") +
|
|
296
|
+
geom_errorbar(
|
|
297
|
+
aes(ymin = mean_sd1, ymax = mean_sd2),
|
|
298
|
+
width = 0.2,
|
|
299
|
+
alpha = 0.5,
|
|
300
|
+
linewidth = 0.6,
|
|
301
|
+
position = position_dodge(0.9),
|
|
302
|
+
color = "#333333"
|
|
303
|
+
) +
|
|
304
|
+
theme_prism(axis_text_angle = 45) +
|
|
305
|
+
ylab("Fraction of cells") +
|
|
306
|
+
scale_fill_manual(values = colors)
|
|
307
|
+
|
|
308
|
+
prefix = file.path(info$casedir, "barplot")
|
|
309
|
+
save_plot(p, prefix, case$bar_devpars)
|
|
310
|
+
neat_case <- list(by = case$by, ident = case$ident)
|
|
311
|
+
save_plotcode(
|
|
312
|
+
p,
|
|
313
|
+
setup = c(
|
|
314
|
+
'library(rlang)',
|
|
315
|
+
'library(ggplot2)',
|
|
316
|
+
'library(ggprism)',
|
|
317
|
+
'',
|
|
318
|
+
'load("data.RData")',
|
|
319
|
+
'case <- neat_case'
|
|
320
|
+
),
|
|
321
|
+
prefix,
|
|
322
|
+
"plotdata", "neat_case", "colors")
|
|
323
|
+
|
|
324
|
+
# Do the tests in each cluster between groups on .frac
|
|
325
|
+
bys <- bardata %>% pull(!!sym(case$by)) %>% unique()
|
|
326
|
+
if (!is.null(case$test) && test != "none") {
|
|
327
|
+
if (length(bys) < 2) {
|
|
328
|
+
stop(" Cannot do tests with only one group.")
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
pairs <- combn(bys, 2, simplify = FALSE)
|
|
332
|
+
test_results <- NULL
|
|
333
|
+
for (pair in pairs) {
|
|
334
|
+
dat <- bardata %>%
|
|
335
|
+
filter(!!sym(case$by) %in% pair) %>%
|
|
336
|
+
select(!!sym(case$by), !!sym(case$ident), .frac) %>%
|
|
337
|
+
group_by(!!sym(case$ident)) %>%
|
|
338
|
+
summarise(
|
|
339
|
+
comparison = paste0(pair, collapse = " - "),
|
|
340
|
+
n = paste(as.list(table(!!sym(case$by)))[pair], collapse = "; "),
|
|
341
|
+
mean = paste(
|
|
342
|
+
(tibble(.frac, !!sym(case$by)) %>%
|
|
343
|
+
group_by(!!sym(case$by)) %>%
|
|
344
|
+
summarise(mean = mean(.frac)) %>%
|
|
345
|
+
column_to_rownames(case$by) %>%
|
|
346
|
+
t() %>%
|
|
347
|
+
as.data.frame() %>%
|
|
348
|
+
as.list())[pair] %>% unlist() %>% round(3),
|
|
349
|
+
collapse = "; "
|
|
350
|
+
),
|
|
351
|
+
!!sym(paste0(case$test, "_pval")) := ifelse(
|
|
352
|
+
case$test == "wilcox",
|
|
353
|
+
tryCatch(wilcox.test(.frac ~ !!sym(case$by))$p.value, error = function(e) NA),
|
|
354
|
+
tryCatch(t.test(.frac ~ !!sym(case$by))$p.value, error = function(e) NA)
|
|
355
|
+
)
|
|
356
|
+
)
|
|
357
|
+
test_results <- rbind(test_results, dat)
|
|
358
|
+
}
|
|
359
|
+
write.table(
|
|
360
|
+
test_results,
|
|
361
|
+
file.path(info$casedir, "tests.txt"),
|
|
362
|
+
sep = "\t",
|
|
363
|
+
quote = FALSE,
|
|
364
|
+
col.names = TRUE,
|
|
365
|
+
row.names = FALSE
|
|
366
|
+
)
|
|
367
|
+
}
|
|
216
368
|
}
|
|
217
369
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
immediate. = TRUE
|
|
370
|
+
add_case_report = function(info, breakdown, test) {
|
|
371
|
+
report = list(
|
|
372
|
+
list(
|
|
373
|
+
name = "Radar Plot",
|
|
374
|
+
contents = list(
|
|
375
|
+
list(
|
|
376
|
+
kind = "image",
|
|
377
|
+
src = file.path(info$casedir, "plot.png"),
|
|
378
|
+
download = list(
|
|
379
|
+
file.path(info$casedir, "plot.pdf"),
|
|
380
|
+
list(
|
|
381
|
+
src = file.path(info$casedir, "plot.R"),
|
|
382
|
+
tip = "Download the code used to reproduce the plot",
|
|
383
|
+
icon = "Code"))
|
|
233
384
|
)
|
|
234
|
-
|
|
235
|
-
|
|
385
|
+
)
|
|
386
|
+
),
|
|
387
|
+
list(
|
|
388
|
+
name = "Count Table",
|
|
389
|
+
contents = list(
|
|
390
|
+
list(
|
|
391
|
+
kind = "table",
|
|
392
|
+
data = list(index_col = 0),
|
|
393
|
+
src = file.path(info$casedir, "counts.tsv")
|
|
394
|
+
)
|
|
395
|
+
)
|
|
396
|
+
),
|
|
397
|
+
list(
|
|
398
|
+
name = "Percentage Table",
|
|
399
|
+
contents = list(
|
|
400
|
+
list(
|
|
401
|
+
kind = "table",
|
|
402
|
+
data = list(index_col = 0),
|
|
403
|
+
src = file.path(info$casedir, "percentages.tsv")
|
|
404
|
+
)
|
|
405
|
+
)
|
|
406
|
+
)
|
|
407
|
+
)
|
|
408
|
+
if (!is.null(breakdown)) {
|
|
409
|
+
report = c(
|
|
410
|
+
report,
|
|
411
|
+
list(list(
|
|
412
|
+
name = "Barplot",
|
|
413
|
+
contents = list(
|
|
414
|
+
list(
|
|
415
|
+
kind = "image",
|
|
416
|
+
src = file.path(info$casedir, "barplot.png"),
|
|
417
|
+
download = list(
|
|
418
|
+
file.path(info$casedir, "barplot.pdf"),
|
|
419
|
+
list(
|
|
420
|
+
src = file.path(info$casedir, "barplot.code.zip"),
|
|
421
|
+
tip = "Download the code used to reproduce the plot",
|
|
422
|
+
icon = "Code"
|
|
423
|
+
)
|
|
424
|
+
)
|
|
425
|
+
)
|
|
426
|
+
)
|
|
427
|
+
))
|
|
428
|
+
)
|
|
429
|
+
if (!is.null(test) && test != "none") {
|
|
430
|
+
report = c(
|
|
431
|
+
report,
|
|
432
|
+
list(list(
|
|
433
|
+
name = "Tests",
|
|
434
|
+
contents = list(
|
|
435
|
+
list(
|
|
436
|
+
kind = "table",
|
|
437
|
+
src = file.path(info$casedir, "tests.txt")
|
|
438
|
+
)
|
|
439
|
+
)
|
|
440
|
+
))
|
|
441
|
+
)
|
|
236
442
|
}
|
|
237
443
|
}
|
|
444
|
+
report$h1 = info$h1
|
|
445
|
+
report$h2 = info$h2
|
|
446
|
+
report$ui = "tabs"
|
|
447
|
+
do_call(add_report, report)
|
|
238
448
|
}
|
|
239
449
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
450
|
+
run_one_case <- function(casename) {
|
|
451
|
+
info <- casename_info(casename, cases, outdir, create = TRUE)
|
|
452
|
+
case <- cases[[casename]]
|
|
453
|
+
log_info("- Running for case: {casename}")
|
|
454
|
+
|
|
455
|
+
if (!is.null(case$subset)) {
|
|
456
|
+
m <- meta %>% dplyr::filter(!!rlang::parse_expr(case$subset))
|
|
457
|
+
} else {
|
|
458
|
+
m <- meta
|
|
459
|
+
}
|
|
460
|
+
# Get the counts
|
|
461
|
+
if (!is.null(case$each)) {
|
|
462
|
+
counts <- m %>% dplyr::filter(!!sym(case$each) == case$each_value)
|
|
463
|
+
} else {
|
|
464
|
+
counts <- m
|
|
465
|
+
}
|
|
466
|
+
counts <- counts %>% drop_na(!!sym(case$by)) %>% drop_na(!!sym(case$ident))
|
|
467
|
+
do_radarplot(info, case, counts)
|
|
468
|
+
|
|
469
|
+
if (!is.null(case$breakdown)) {
|
|
470
|
+
do_barplot_and_tests(info, case, counts)
|
|
254
471
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
472
|
+
|
|
473
|
+
add_case_report(info, case$breakdown, case$test)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
sapply(sort(names(cases)), run_one_case)
|
|
477
|
+
|
|
478
|
+
save_report(joboutdir)
|