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
biopipen/scripts/scrna/ScFGSEA.R
CHANGED
|
@@ -1,148 +1,346 @@
|
|
|
1
|
-
source("{{biopipen_dir}}/utils/misc.R")
|
|
2
|
-
source("{{biopipen_dir}}/utils/gsea.R")
|
|
3
|
-
source("{{biopipen_dir}}/utils/mutate_helpers.R")
|
|
4
1
|
library(rlang)
|
|
5
2
|
library(Seurat)
|
|
6
3
|
library(tidyseurat)
|
|
4
|
+
library(biopipen.utils)
|
|
7
5
|
|
|
8
6
|
srtfile <- {{in.srtobj | r}} # nolint
|
|
9
7
|
outdir <- {{out.outdir | r}} # nolint
|
|
8
|
+
joboutdir <- {{job.outdir | r}} # nolint
|
|
10
9
|
mutaters <- {{envs.mutaters | r}} # nolint
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
group_by <- {{envs.group_by | default: envs["group-by"] | default: None | r}} # nolint
|
|
11
|
+
ident_1 <- {{envs.ident_1 | default: envs["ident-1"] | default: None | r}} # nolint
|
|
12
|
+
ident_2 <- {{envs.ident_2 | default: envs["ident-2"] | default: None | r}} # nolint
|
|
13
|
+
assay <- {{envs.assay | r}} # nolint
|
|
14
14
|
each <- {{envs.each | r}} # nolint
|
|
15
|
-
|
|
15
|
+
subset <- {{envs.subset | r}} # nolint
|
|
16
16
|
gmtfile <- {{envs.gmtfile | r}} # nolint
|
|
17
17
|
method <- {{envs.method | r}} # nolint
|
|
18
18
|
top <- {{envs.top | r}} # nolint
|
|
19
|
-
minsize <- {{envs.minsize | r}} # nolint
|
|
20
|
-
maxsize <- {{envs.maxsize | r}} # nolint
|
|
19
|
+
minsize <- {{envs.minSize | default: envs.minsize | r}} # nolint
|
|
20
|
+
maxsize <- {{envs.maxSize | default: envs.maxsize | r}} # nolint
|
|
21
21
|
eps <- {{envs.eps | r}} # nolint
|
|
22
|
+
alleach_plots_defaults <- {{envs.alleach_plots_defaults | r}} # nolint
|
|
23
|
+
alleach_plots <- {{envs.alleach_plots | r}} #
|
|
22
24
|
ncores <- {{envs.ncores | r}} # nolint
|
|
23
25
|
rest <- {{envs.rest | r: todot="-"}} # nolint
|
|
24
26
|
cases <- {{envs.cases | r: todot="-"}} # nolint
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
log <- get_logger()
|
|
29
|
+
reporter <- get_reporter()
|
|
30
|
+
|
|
31
|
+
alleach_plots <- lapply(alleach_plots, function(x) {
|
|
32
|
+
list_update(alleach_plots_defaults, x)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
log$info("Reading Seurat object ...")
|
|
36
|
+
srtobj <- read_obj(srtfile)
|
|
37
|
+
|
|
27
38
|
if (!is.null(mutaters) && length(mutaters) > 0) {
|
|
39
|
+
log$info("Mutating metadata columns ...")
|
|
28
40
|
srtobj@meta.data <- srtobj@meta.data %>% mutate(!!!lapply(mutaters, parse_expr))
|
|
29
41
|
}
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
defaults <- list(
|
|
44
|
+
group_by = group_by,
|
|
45
|
+
ident_1 = ident_1,
|
|
46
|
+
ident_2 = ident_2,
|
|
47
|
+
assay = assay,
|
|
48
|
+
each = each,
|
|
49
|
+
subset = subset,
|
|
50
|
+
gmtfile = gmtfile,
|
|
51
|
+
method = method,
|
|
52
|
+
top = top,
|
|
53
|
+
minsize = minsize,
|
|
54
|
+
maxsize = maxsize,
|
|
55
|
+
eps = eps,
|
|
56
|
+
alleach_plots_defaults = alleach_plots_defaults,
|
|
57
|
+
alleach_plots = alleach_plots,
|
|
58
|
+
ncores = ncores,
|
|
59
|
+
rest = rest
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
expand_each <- function(name, case) {
|
|
63
|
+
outcases <- list()
|
|
64
|
+
|
|
65
|
+
case$group_by <- case$group_by %||% GetIdentityColumn(srtobj)
|
|
66
|
+
|
|
67
|
+
if (is.null(case$each) || is.na(case$each) || nchar(case$each) == 0 || isFALSE(each)) {
|
|
68
|
+
if (length(case$alleach_plots) > 0) {
|
|
69
|
+
stop("Cannot perform `alleach_plots` without `each` defined.")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
outcases[[name]] <- case
|
|
51
73
|
} else {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
each = each,
|
|
60
|
-
section = section,
|
|
61
|
-
gmtfile = gmtfile,
|
|
62
|
-
method = method,
|
|
63
|
-
top = top,
|
|
64
|
-
minsize = minsize,
|
|
65
|
-
maxsize = maxsize,
|
|
66
|
-
eps = eps,
|
|
67
|
-
ncores = ncores,
|
|
68
|
-
rest = rest
|
|
69
|
-
)
|
|
70
|
-
case$rest <- list_setdefault(case$rest, rest)
|
|
71
|
-
filled_cases[[name]] <- case
|
|
74
|
+
eachs <- if (!is.null(case$subset)) {
|
|
75
|
+
srtobj@meta.data %>%
|
|
76
|
+
filter(!!parse_expr(case$subset)) %>%
|
|
77
|
+
pull(case$each) %>% na.omit() %>% unique() %>% as.vector()
|
|
78
|
+
} else {
|
|
79
|
+
srtobj@meta.data %>%
|
|
80
|
+
pull(case$each) %>% na.omit() %>% unique() %>% as.vector()
|
|
72
81
|
}
|
|
73
|
-
}
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (name in names(filled_cases)) {
|
|
78
|
-
case <- filled_cases[[name]]
|
|
79
|
-
if (is.null(case$each) || nchar(case$each) == 0) {
|
|
80
|
-
outcases[[paste0(case$section, ":", name)]] <- case
|
|
83
|
+
if (length(cases) == 0 && name == "GSEA") {
|
|
84
|
+
prefix <- case$each
|
|
81
85
|
} else {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
prefix <- paste0(name, " (", case$each, ")")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (each in eachs) {
|
|
90
|
+
newname <- paste0(prefix, "::", each)
|
|
91
|
+
newcase <- case
|
|
92
|
+
|
|
93
|
+
newcase$original_case <- paste0(name, " (all ", case$each,")")
|
|
94
|
+
newcase$each_name <- case$each
|
|
95
|
+
newcase$each <- each
|
|
96
|
+
|
|
97
|
+
newcase$alleach_plots_defaults <- NULL
|
|
98
|
+
newcase$alleach_plots <- NULL
|
|
99
|
+
|
|
100
|
+
if (!is.null(case$subset)) {
|
|
101
|
+
newcase$subset <- paste0(case$subset, " & ", bQuote(case$each), " == '", each, "'")
|
|
102
|
+
} else {
|
|
103
|
+
newcase$subset <- paste0(bQuote(case$each), " == '", each, "'")
|
|
98
104
|
}
|
|
105
|
+
|
|
106
|
+
outcases[[newname]] <- newcase
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (length(case$alleach_plots) > 0) {
|
|
110
|
+
newcase <- case
|
|
111
|
+
|
|
112
|
+
newcase$gseas <- list()
|
|
113
|
+
newcase$alleach_plots <- lapply(
|
|
114
|
+
newcase$alleach_plots,
|
|
115
|
+
function(x) { list_update(newcase$alleach_plots_defaults, x) }
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
outcases[[paste0(name, " (all ", case$each,")")]] <- newcase
|
|
99
119
|
}
|
|
100
120
|
}
|
|
101
121
|
outcases
|
|
102
122
|
}
|
|
103
123
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
124
|
+
log$info("Expanding cases...")
|
|
125
|
+
cases <- expand_cases(cases, defaults, expand_each, default_case = "GSEA")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
ensure_sobj <- function(expr, allow_empty) {
|
|
129
|
+
tryCatch({ expr }, error = function(e) {
|
|
130
|
+
if (allow_empty) {
|
|
131
|
+
log$warn(" Ignoring this case: {e$message}")
|
|
132
|
+
return(NULL)
|
|
133
|
+
} else {
|
|
134
|
+
stop(e)
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
do_case <- function(name) {
|
|
140
|
+
log$info("- Processing case: {name} ...")
|
|
141
|
+
case <- cases[[name]]
|
|
142
|
+
info <- case_info(name, outdir, create = TRUE)
|
|
143
|
+
|
|
144
|
+
if (!is.null(case$gseas)) {
|
|
145
|
+
|
|
146
|
+
if (length(case$gseas) == 0) {
|
|
147
|
+
log$warn(" No GSEA results found for case {name}. Skipping.")
|
|
148
|
+
return(invisible(NULL))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
each_levels <- names(case$gseas)
|
|
152
|
+
gseas <- do_call(rbind, lapply(each_levels, function(x) {
|
|
153
|
+
gsea_df <- case$gseas[[x]]
|
|
154
|
+
if (nrow(gsea_df) > 0) {
|
|
155
|
+
gsea_df[[case$each]] <- x
|
|
156
|
+
} else {
|
|
157
|
+
gsea_df[[case$each]] <- character(0) # Empty case
|
|
158
|
+
}
|
|
159
|
+
gsea_df
|
|
160
|
+
}))
|
|
161
|
+
gseas[[case$each]] <- factor(gseas[[case$each]], levels = each_levels)
|
|
162
|
+
|
|
163
|
+
for (plotname in names(case$alleach_plots)) {
|
|
164
|
+
plotargs <- case$alleach_plots[[plotname]]
|
|
165
|
+
plotargs <- extract_vars(plotargs, "devpars")
|
|
166
|
+
plotargs$gsea_results <- gseas
|
|
167
|
+
plotargs$group_by <- case$each
|
|
168
|
+
if (plotargs$plot_type == "heatmap") {
|
|
169
|
+
plotargs$show_row_names <- plotargs$show_row_names %||% TRUE
|
|
170
|
+
plotargs$show_column_names <- plotargs$show_column_names %||% TRUE
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
p <- do_call(VizGSEA, plotargs)
|
|
174
|
+
|
|
175
|
+
outprefix <- file.path(info$prefix, paste0("all.", slugify(plotname)))
|
|
176
|
+
save_plot(p, outprefix, devpars, formats = "png")
|
|
177
|
+
reporter$add2(
|
|
178
|
+
list(kind = "descr", content = paste0("Pathways for all ", case$each, ".")),
|
|
179
|
+
list(kind = "image", src = paste0(outprefix, ".png")),
|
|
180
|
+
hs = c(info$section, info$name),
|
|
181
|
+
hs2 = plotname
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return(invisible(NULL))
|
|
186
|
+
}
|
|
111
187
|
|
|
188
|
+
allow_empty = !is.null(case$each)
|
|
112
189
|
# prepare expression matrix
|
|
113
|
-
|
|
114
|
-
sobj <- srtobj %>% filter(!is.na(!!sym(case$
|
|
115
|
-
if (
|
|
116
|
-
|
|
190
|
+
log$info(" Preparing expression matrix...")
|
|
191
|
+
sobj <- ensure_sobj({ srtobj %>% filter(!is.na(!!sym(case$group_by))) }, allow_empty)
|
|
192
|
+
if (is.null(sobj)) {
|
|
193
|
+
reporter$add2(
|
|
194
|
+
list(
|
|
195
|
+
kind = "error",
|
|
196
|
+
content = paste0("No cells with non-NA `", case$group_by, "` in the Seurat object.")
|
|
197
|
+
),
|
|
198
|
+
hs = c(info$section, info$name)
|
|
199
|
+
)
|
|
200
|
+
return(NULL)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!is.null(case$subset)) {
|
|
204
|
+
sobj <- ensure_sobj({ sobj %>% filter(!!!parse_exprs(case$subset)) }, allow_empty)
|
|
205
|
+
if (is.null(sobj)) {
|
|
206
|
+
reporter$add2(
|
|
207
|
+
list(
|
|
208
|
+
kind = "error",
|
|
209
|
+
content = paste0("No cells with non-NA `", case$group_by, "` in the Seurat object.")
|
|
210
|
+
),
|
|
211
|
+
hs = c(info$section, info$name)
|
|
212
|
+
)
|
|
213
|
+
return(NULL)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!is.null(case$ident_2)) {
|
|
217
|
+
sobj <- ensure_sobj({ sobj %>% filter(!!sym(case$group_by) %in% c(case$ident_1, case$ident_2)) }, allow_empty)
|
|
218
|
+
if (is.null(sobj)) {
|
|
219
|
+
reporter$add2(
|
|
220
|
+
list(
|
|
221
|
+
kind = "error",
|
|
222
|
+
content = paste0("No cells with non-NA `", case$group_by, "` in the Seurat object.")
|
|
223
|
+
),
|
|
224
|
+
hs = c(info$section, info$name)
|
|
225
|
+
)
|
|
226
|
+
return(NULL)
|
|
227
|
+
}
|
|
117
228
|
}
|
|
118
229
|
|
|
119
|
-
allclasses <- sobj@meta.data[, case$
|
|
120
|
-
if (is.null(case$
|
|
121
|
-
case$
|
|
122
|
-
allclasses[allclasses != case$
|
|
230
|
+
allclasses <- sobj@meta.data[, case$group_by, drop = TRUE]
|
|
231
|
+
if (is.null(case$ident_2)) {
|
|
232
|
+
case$ident_2 <- "Other"
|
|
233
|
+
allclasses[allclasses != case$ident_1] <- "Other"
|
|
123
234
|
}
|
|
124
|
-
exprs <- GetAssayData(sobj,
|
|
235
|
+
exprs <- GetAssayData(sobj, layer = "data", assay = case$assay)
|
|
125
236
|
|
|
126
237
|
# get preranks
|
|
127
|
-
|
|
128
|
-
ranks <-
|
|
238
|
+
log$info(" Getting preranks...")
|
|
239
|
+
ranks <- RunGSEAPreRank(exprs, allclasses, case$ident_1, case$ident_2, case$method)
|
|
129
240
|
write.table(
|
|
130
|
-
ranks,
|
|
131
|
-
file.path(
|
|
132
|
-
row.names =
|
|
241
|
+
as.data.frame(ranks),
|
|
242
|
+
file.path(info$prefix, "fgsea.rank.txt"),
|
|
243
|
+
row.names = TRUE,
|
|
133
244
|
col.names = TRUE,
|
|
134
245
|
sep = "\t",
|
|
135
246
|
quote = FALSE
|
|
136
247
|
)
|
|
248
|
+
if (all(is.na(ranks))) {
|
|
249
|
+
log$warn(" All gene ranks are NA. It's probably due to high missing rate in the data.")
|
|
250
|
+
log$warn(" Case ignored, you may also try a different ranking method.")
|
|
251
|
+
reporter$add2(
|
|
252
|
+
list(
|
|
253
|
+
kind = "error",
|
|
254
|
+
content = "All gene ranks are NA. It's probably due to high missing rate in the data."
|
|
255
|
+
),
|
|
256
|
+
hs = c(info$section, info$name)
|
|
257
|
+
)
|
|
258
|
+
return(invisible(NULL))
|
|
259
|
+
}
|
|
137
260
|
|
|
138
261
|
# run fgsea
|
|
139
|
-
|
|
140
|
-
case$rest$
|
|
141
|
-
case$rest$
|
|
262
|
+
log$info(" Running fgsea...")
|
|
263
|
+
case$rest$ranks <- ranks
|
|
264
|
+
case$rest$genesets <- ParseGMT(case$gmtfile)
|
|
265
|
+
case$rest$minSize <- case$rest$minSize %||% case$rest$minsize %||% case$minsize
|
|
266
|
+
case$rest$maxSize <- case$rest$maxSize %||% case$rest$maxsize %||% case$maxsize
|
|
142
267
|
case$rest$eps <- case$eps
|
|
143
268
|
case$rest$nproc <- case$ncores
|
|
144
|
-
|
|
269
|
+
case$rest$minsize <- NULL
|
|
270
|
+
case$rest$maxsize <- NULL
|
|
271
|
+
result <- do_call(RunGSEA, case$rest)
|
|
272
|
+
write.table(
|
|
273
|
+
result,
|
|
274
|
+
file.path(info$prefix, "fgsea.tsv"),
|
|
275
|
+
row.names = FALSE,
|
|
276
|
+
col.names = TRUE,
|
|
277
|
+
sep = "\t",
|
|
278
|
+
quote = FALSE
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
aspect.ratio <- sqrt(case$top) / sqrt(10)
|
|
282
|
+
p_summary <- VizGSEA(
|
|
283
|
+
result,
|
|
284
|
+
plot_type = "summary",
|
|
285
|
+
top_term = case$top,
|
|
286
|
+
aspect.ratio = aspect.ratio
|
|
287
|
+
)
|
|
288
|
+
save_plot(
|
|
289
|
+
p_summary,
|
|
290
|
+
file.path(info$prefix, "summary"),
|
|
291
|
+
devpars = list(res = 100, height = attr(p_summary, "height") * 100 / 1.5, width = attr(p_summary, "width") * 100),
|
|
292
|
+
formats = "png"
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
p_gsea <- VizGSEA(
|
|
296
|
+
result,
|
|
297
|
+
plot_type = "gsea",
|
|
298
|
+
gs = result$pathway[1:min(case$top, nrow(result))]
|
|
299
|
+
)
|
|
300
|
+
save_plot(
|
|
301
|
+
p_gsea,
|
|
302
|
+
file.path(info$prefix, "pathways"),
|
|
303
|
+
devpars = list(res = 100, height = attr(p_gsea, "height") * 100, width = attr(p_gsea, "width") * 100),
|
|
304
|
+
formats = "png"
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
reporter$add2(
|
|
309
|
+
list(
|
|
310
|
+
name = paste0("Table (", case$ident_1, " vs ", case$ident_2, ")"),
|
|
311
|
+
contents = list(
|
|
312
|
+
list(kind = "descr", content = paste0(
|
|
313
|
+
"Showing top 50 pathways by padj in descending order. ",
|
|
314
|
+
"Use 'Download the entire data' button to download all pathways."
|
|
315
|
+
)),
|
|
316
|
+
list(kind = "table", src = file.path(info$prefix, "fgsea.tsv"), data = list(nrows = 50))
|
|
317
|
+
)
|
|
318
|
+
),
|
|
319
|
+
list(
|
|
320
|
+
name = "Summary Plot",
|
|
321
|
+
contents = list(
|
|
322
|
+
list(kind = "descr", content = paste0("Showing top ", case$top, " pathways.")),
|
|
323
|
+
list(kind = "image", src = file.path(info$prefix, "summary.png"))
|
|
324
|
+
)
|
|
325
|
+
),
|
|
326
|
+
list(
|
|
327
|
+
name = "GSEA Plots",
|
|
328
|
+
contents = list(
|
|
329
|
+
list(kind = "descr", content = paste0("Showing top ", case$top, " pathways.")),
|
|
330
|
+
list(kind = "image", src = file.path(info$prefix, "pathways.png"))
|
|
331
|
+
)
|
|
332
|
+
),
|
|
333
|
+
hs = c(info$section, info$name),
|
|
334
|
+
ui = "tabs"
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
if (!is.null(case$original_case) && !is.null(cases[[case$original_case]])) {
|
|
338
|
+
cases[[case$original_case]]$gseas[[case$each]] <<- result
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
invisible()
|
|
145
342
|
}
|
|
146
343
|
|
|
147
|
-
cases
|
|
148
|
-
|
|
344
|
+
sapply(names(cases), function(name) do_case(name))
|
|
345
|
+
|
|
346
|
+
reporter$save(joboutdir)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
library(rlang)
|
|
2
|
+
library(splatter)
|
|
3
|
+
library(scater)
|
|
4
|
+
library(biopipen.utils)
|
|
5
|
+
|
|
6
|
+
# Load template variables
|
|
7
|
+
seed <- {{ in.seed | r }}
|
|
8
|
+
outfile <- {{ out.outfile | r }}
|
|
9
|
+
ngenes <- {{ envs.ngenes | r }}
|
|
10
|
+
ncells <- {{ envs.ncells | r }}
|
|
11
|
+
nspikes <- {{ envs.nspikes | r }}
|
|
12
|
+
outtype <- {{ envs.outtype | r }}
|
|
13
|
+
method <- {{ envs.method | r }}
|
|
14
|
+
user_params <- {{ envs.params | r: todot="-" }}
|
|
15
|
+
|
|
16
|
+
log <- get_logger()
|
|
17
|
+
|
|
18
|
+
log$info("Generating simulation parameters ...")
|
|
19
|
+
|
|
20
|
+
seed <- seed %||% 1
|
|
21
|
+
if (length(seed) > 1) {
|
|
22
|
+
log$warn("- multiple seeds provided, using the first one")
|
|
23
|
+
seed <- seed[1]
|
|
24
|
+
}
|
|
25
|
+
if (is.character(seed)) {
|
|
26
|
+
library(digest)
|
|
27
|
+
proj <- seed
|
|
28
|
+
seed <- digest2int(seed)
|
|
29
|
+
} else {
|
|
30
|
+
proj <- paste0("S", seed)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set.seed(seed)
|
|
34
|
+
mock_sce_params <- list()
|
|
35
|
+
if (!is.null(ngenes)) mock_sce_params$ngenes <- ngenes
|
|
36
|
+
if (!is.null(ncells)) mock_sce_params$ncells <- ncells
|
|
37
|
+
if (!is.null(nspikes)) mock_sce_params$nspikes <- nspikes
|
|
38
|
+
sce <- do.call(mockSCE, mock_sce_params)
|
|
39
|
+
params <- splatEstimate(sce)
|
|
40
|
+
user_params$seed <- seed
|
|
41
|
+
user_params$object = params
|
|
42
|
+
do_call(setParams, user_params)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
log$info("Saving simulation parameters to file ...")
|
|
46
|
+
|
|
47
|
+
sim <- splatSimulate(params, method = method, verbose = TRUE)
|
|
48
|
+
|
|
49
|
+
outtype <- tolower(outtype)
|
|
50
|
+
if (outtype == "sce") outtype <- "singlecellexperiment"
|
|
51
|
+
|
|
52
|
+
if (outtype == "singlecellexperiment") {
|
|
53
|
+
log$info("Saving simulation to file ...")
|
|
54
|
+
save_obj(sim, file = outfile)
|
|
55
|
+
} else {
|
|
56
|
+
log$info("Converting simulation to Seurat object ...")
|
|
57
|
+
cnts <- SingleCellExperiment::counts(sim)
|
|
58
|
+
sobj <- Seurat::CreateSeuratObject(counts = cnts, project = proj)
|
|
59
|
+
rm(sim)
|
|
60
|
+
rm(cnts)
|
|
61
|
+
gc()
|
|
62
|
+
|
|
63
|
+
log$info("Saving simulation to file ...")
|
|
64
|
+
save_obj(sobj, file = outfile)
|
|
65
|
+
}
|