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,209 +1,259 @@
|
|
|
1
|
-
source("{{biopipen_dir}}/utils/misc.R")
|
|
2
|
-
|
|
3
1
|
library(Seurat)
|
|
4
2
|
library(future)
|
|
5
3
|
library(bracer)
|
|
6
|
-
library(
|
|
7
|
-
library(
|
|
4
|
+
library(dplyr)
|
|
5
|
+
library(glue)
|
|
6
|
+
library(biopipen.utils)
|
|
7
|
+
|
|
8
|
+
metafile <- {{in.metafile | r}}
|
|
9
|
+
outfile <- {{out.outfile | r}}
|
|
10
|
+
joboutdir <- {{job.outdir | r}}
|
|
11
|
+
envs <- {{envs | r: todot = "-", skip = 1}}
|
|
12
|
+
|
|
13
|
+
if (isTRUE(envs$cache)) { envs$cache <- joboutdir }
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
joboutdir = {{job.outdir | quote}}
|
|
12
|
-
envs = {{envs | r}}
|
|
15
|
+
log <- get_logger()
|
|
16
|
+
reporter <- get_reporter()
|
|
13
17
|
|
|
14
18
|
set.seed(8525)
|
|
15
|
-
|
|
19
|
+
# 8TB
|
|
20
|
+
options(future.globals.maxSize = Inf)
|
|
21
|
+
options(future.rng.onMisuse="ignore")
|
|
22
|
+
options(Seurat.object.assay.version = "v5")
|
|
16
23
|
plan(strategy = "multicore", workers = envs$ncores)
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
reporter$add(
|
|
26
|
+
list(
|
|
27
|
+
kind = "descr",
|
|
28
|
+
name = "Filters applied",
|
|
29
|
+
content = paste0(
|
|
30
|
+
"<p>Cell filters: ", html_escape(envs$cell_qc), "</p>",
|
|
31
|
+
"<p>Gene filters: </p>",
|
|
32
|
+
"<p>- Min Cells: ", envs$gene_qc$min_cells, "</p>",
|
|
33
|
+
"<p>- Excludes: ",
|
|
34
|
+
ifelse(is.null(envs$gene_qc$excludes), "Not set", paste(envs$gene_qc$excludes, collapse = ", ")),
|
|
35
|
+
"</p>"
|
|
36
|
+
)
|
|
37
|
+
),
|
|
38
|
+
h1 = "Filters and QC"
|
|
24
39
|
)
|
|
25
40
|
|
|
26
|
-
|
|
41
|
+
metadata <- tryCatch({
|
|
42
|
+
log$debug("Trying to read Seurat object from metafile ...")
|
|
43
|
+
read_obj(metafile)
|
|
44
|
+
}, error = function(e) {
|
|
45
|
+
log$debug("Failed to read Seurat object from metafile: {e$message}")
|
|
46
|
+
log$debug("Reading metafile as a table (sample info) ...")
|
|
47
|
+
read.table(
|
|
48
|
+
metafile,
|
|
49
|
+
header = TRUE,
|
|
50
|
+
row.names = NULL,
|
|
51
|
+
sep = "\t",
|
|
52
|
+
check.names = FALSE
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
is_seurat <- inherits(metadata, "Seurat")
|
|
56
|
+
|
|
57
|
+
meta_cols <- if (is_seurat) colnames(metadata@meta.data) else colnames(metadata)
|
|
27
58
|
if (!"Sample" %in% meta_cols) {
|
|
28
|
-
stop("Error: Column `Sample` is not found in metafile.")
|
|
59
|
+
stop("Error: Column `Sample` is not found in ", ifelse(is_seurat, "Seurat object's meta.data.", "metafile."))
|
|
29
60
|
}
|
|
30
|
-
if (!"RNAData" %in% meta_cols) {
|
|
61
|
+
if (!"RNAData" %in% meta_cols && !is_seurat) {
|
|
31
62
|
stop("Error: Column `RNAData` is not found in metafile.")
|
|
32
63
|
}
|
|
33
64
|
|
|
65
|
+
qcdir = file.path(joboutdir, "qc")
|
|
66
|
+
dir.create(qcdir, showWarnings = FALSE, recursive = TRUE)
|
|
34
67
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
file.path(tmpdatadir, "barcodes.tsv.gz")
|
|
45
|
-
)
|
|
46
|
-
genefile = glob(file.path(path, "*{genes,features}.tsv.gz"))[1]
|
|
47
|
-
file.symlink(
|
|
48
|
-
normalizePath(genefile),
|
|
49
|
-
file.path(tmpdatadir, "features.tsv.gz")
|
|
50
|
-
)
|
|
51
|
-
matrixfile = Sys.glob(file.path(path, "*matrix.mtx.gz"))[1]
|
|
52
|
-
file.symlink(
|
|
53
|
-
normalizePath(matrixfile),
|
|
54
|
-
file.path(tmpdatadir, "matrix.mtx.gz")
|
|
55
|
-
)
|
|
56
|
-
Read10X(data.dir = tmpdatadir)
|
|
57
|
-
}
|
|
68
|
+
sobj <- LoadSeuratAndPerformQC(
|
|
69
|
+
metadata,
|
|
70
|
+
min_cells = envs$min_cells,
|
|
71
|
+
min_features = envs$min_features,
|
|
72
|
+
cell_qc = envs$cell_qc,
|
|
73
|
+
gene_qc = envs$gene_qc,
|
|
74
|
+
tmpdir = joboutdir,
|
|
75
|
+
log = log,
|
|
76
|
+
cache = envs$cache)
|
|
58
77
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (is.na(path) || !is.character(path) || nchar(path) == 0) {
|
|
64
|
-
warning(paste0("No path found for sample: ", sample))
|
|
65
|
-
return (NULL)
|
|
66
|
-
}
|
|
78
|
+
log$info("Saving and visualizing QC results ...")
|
|
79
|
+
cell_qc_df <- VizSeuratCellQC(sobj, plot_type = "table")
|
|
80
|
+
write.table(cell_qc_df, file = file.path(qcdir, "cell_qc.txt"),
|
|
81
|
+
row.names = FALSE, quote = FALSE, sep = "\t")
|
|
67
82
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
reporter$add(
|
|
84
|
+
list(
|
|
85
|
+
name = "Cell QC metrics",
|
|
86
|
+
contents = list(
|
|
87
|
+
list(
|
|
88
|
+
kind = "descr",
|
|
89
|
+
content = paste0(
|
|
90
|
+
"The table below show the number of cells in each sample that failed and passed the QC filters. ",
|
|
91
|
+
"The last row shows the total number of cells that failed and passed the QC filters across all samples. "
|
|
92
|
+
)
|
|
93
|
+
),
|
|
94
|
+
list(kind = "table", src = file.path(qcdir, "cell_qc.txt"))
|
|
79
95
|
)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
obj = CreateSeuratObject(counts=exprs, project=sample)
|
|
87
|
-
# filter the cells that don't have any gene expressions
|
|
88
|
-
cell_exprs = colSums(obj@assays$RNA)
|
|
89
|
-
obj = subset(obj, cells = names(cell_exprs[cell_exprs > 0]))
|
|
90
|
-
# obj = SCTransform(object=obj, return.only.var.genes=FALSE, verbose=FALSE)
|
|
91
|
-
obj = RenameCells(obj, add.cell.id = sample)
|
|
92
|
-
# Attach meta data
|
|
93
|
-
for (mname in names(mdata)) {
|
|
94
|
-
if (mname %in% c("RNAData", "TCRData")) { next }
|
|
95
|
-
mdt = mdata[[mname]]
|
|
96
|
-
if (is.factor(mdt)) { mdt = levels(mdt)[mdt] }
|
|
97
|
-
obj[[mname]] = mdt
|
|
98
|
-
}
|
|
99
|
-
# obj_list[[sample]] = obj
|
|
100
|
-
|
|
101
|
-
# obj_list
|
|
102
|
-
obj
|
|
103
|
-
}
|
|
96
|
+
),
|
|
97
|
+
h1 = "Filters and QC",
|
|
98
|
+
h2 = "Cell-level Quality Control",
|
|
99
|
+
ui = "tabs"
|
|
100
|
+
)
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
gene_qc_df <- VizSeuratGeneQC(sobj, plot_type = "table")
|
|
103
|
+
write.table(gene_qc_df, file = file.path(qcdir, "gene_qc.txt"),
|
|
104
|
+
row.names = FALSE, quote = FALSE, sep = "\t")
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
reporter$add(
|
|
107
|
+
list(
|
|
108
|
+
name = "Gene QC metrics",
|
|
109
|
+
contents = list(
|
|
110
|
+
list(
|
|
111
|
+
kind = "descr",
|
|
112
|
+
content = paste0(
|
|
113
|
+
"The table below show the number of genes in each sample that failed and passed the QC filters. ",
|
|
114
|
+
"The last row shows the final number of genes that failed and passed the QC filters across all samples. ",
|
|
115
|
+
"Any gene that failed the QC filters will be excluded in the merged Seurat object."
|
|
116
|
+
)
|
|
117
|
+
),
|
|
118
|
+
list(kind = "table", src = file.path(qcdir, "gene_qc.txt")),
|
|
119
|
+
list(kind = "list", items = list(paste0(
|
|
120
|
+
"We may still end up with features slightly less than the final passed ones. ",
|
|
121
|
+
"For example, when SCTransform is used, the number of features may be less than the number of genes that passed the QC filters. ",
|
|
122
|
+
"This is because SCTransform selects the top N features based on variance. "
|
|
123
|
+
)))
|
|
124
|
+
)
|
|
125
|
+
),
|
|
126
|
+
h1 = "Filters and QC",
|
|
127
|
+
h2 = "Gene-level Quality Control",
|
|
128
|
+
ui = "tabs"
|
|
129
|
+
)
|
|
110
130
|
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
131
|
+
for (pname in names(envs$qc_plots)) {
|
|
132
|
+
if (is.null(envs$qc_plots[[pname]])) next
|
|
133
|
+
log$info("- {pname} ...")
|
|
134
|
+
args <- envs$qc_plots[[pname]]
|
|
135
|
+
args$kind <- args$kind %||% "cell"
|
|
136
|
+
args$devpars <- args$devpars %||% list()
|
|
137
|
+
args$more_formats <- args$more_formats %||% character()
|
|
138
|
+
args$save_code <- args$save_code %||% FALSE
|
|
139
|
+
args$descr <- args$descr %||% pname
|
|
140
|
+
extract_vars(args, "kind", "devpars", "more_formats", "save_code", "descr")
|
|
141
|
+
if (kind == "gene") kind <- "gene_qc"
|
|
142
|
+
if (kind == "cell") kind <- "cell_qc"
|
|
143
|
+
args$object <- sobj
|
|
144
|
+
plot_fn <- if (kind == "cell_qc") {
|
|
145
|
+
gglogger::register(VizSeuratCellQC)
|
|
146
|
+
} else {
|
|
147
|
+
gglogger::register(VizSeuratGeneQC)
|
|
148
|
+
}
|
|
149
|
+
p <- do_call(plot_fn, args)
|
|
150
|
+
prefix <- file.path(qcdir, paste0(slugify(pname), ".", kind))
|
|
151
|
+
save_plot(p, prefix, devpars, formats = c("png", more_formats))
|
|
152
|
+
if (save_code) {
|
|
153
|
+
save_plotcode(p, prefix,
|
|
154
|
+
setup = c("library(biopipen.utils)", "load('data.RData')", "invisible(list2env(args, envir = .GlobalEnv))"),
|
|
155
|
+
"args",
|
|
156
|
+
auto_data_setup = FALSE)
|
|
157
|
+
}
|
|
158
|
+
reporter$add(
|
|
159
|
+
list(
|
|
160
|
+
name = pname,
|
|
161
|
+
contents = list(
|
|
162
|
+
list(kind = "descr", content = descr),
|
|
163
|
+
reporter$image(prefix, more_formats, save_code, kind = "image")
|
|
164
|
+
)
|
|
165
|
+
),
|
|
166
|
+
h1 = "Filters and QC",
|
|
167
|
+
h2 = ifelse(kind == "cell_qc", "Cell-level Quality Control", "Gene-level Quality Control"),
|
|
168
|
+
ui = "tabs"
|
|
169
|
+
)
|
|
118
170
|
}
|
|
119
171
|
|
|
120
|
-
|
|
121
|
-
sobj
|
|
122
|
-
sobj$percent.ribo = PercentageFeatureSet(sobj, pattern = "^RP[SL]")
|
|
123
|
-
sobj$percent.hb = PercentageFeatureSet(sobj, pattern = "^HB[^(P)]")
|
|
124
|
-
sobj$percent.plat = PercentageFeatureSet(sobj, pattern = "PECAM1|PF4")
|
|
125
|
-
|
|
126
|
-
dim_df = data.frame(When = "Before_QC", nCells = ncol(sobj), nGenes = nrow(sobj))
|
|
172
|
+
log$info("Filtering with QC criteria ...")
|
|
173
|
+
sobj <- FinishSeuratQC(sobj)
|
|
127
174
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
175
|
+
sobj <- RunSeuratTransformation(
|
|
176
|
+
sobj,
|
|
177
|
+
use_sct = envs$use_sct,
|
|
178
|
+
SCTransformArgs = envs$SCTransform,
|
|
179
|
+
NormalizeDataArgs = envs$NormalizeData,
|
|
180
|
+
FindVariableFeaturesArgs = envs$FindVariableFeatures,
|
|
181
|
+
ScaleDataArgs = envs$ScaleData,
|
|
182
|
+
RunPCAArgs = envs$RunPCA,
|
|
183
|
+
log = log,
|
|
184
|
+
cache = envs$cache
|
|
185
|
+
)
|
|
186
|
+
sobj <- RunSeuratIntegration(
|
|
187
|
+
sobj,
|
|
188
|
+
no_integration = envs$no_integration,
|
|
189
|
+
IntegrateLayersArgs = envs$IntegrateLayers,
|
|
190
|
+
log = log,
|
|
191
|
+
cache = envs$cache
|
|
192
|
+
)
|
|
132
193
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
dir.create(
|
|
194
|
+
# This is the last step, doesn't need to be cached
|
|
195
|
+
if (!identical(envs$doublet_detector, "none")) {
|
|
196
|
+
dbldir <- file.path(joboutdir, "doublets")
|
|
197
|
+
dir.create(dbldir, showWarnings = FALSE, recursive = TRUE)
|
|
137
198
|
|
|
138
|
-
|
|
139
|
-
print("- Plotting violin plots ...")
|
|
140
|
-
for (feat in feats) {
|
|
141
|
-
print(paste0(" ", feat, "..."))
|
|
142
|
-
vln_p = VlnPlot(
|
|
199
|
+
sobj <- RunSeuratDoubletDetection(
|
|
143
200
|
sobj,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
aes(color = .QC),
|
|
151
|
-
data = vln_p$data,
|
|
152
|
-
position = position_jitterdodge(jitter.width = 0.4, dodge.width = 0.9)
|
|
153
|
-
) + scale_color_manual(values = c("black", "red"), breaks = c(TRUE, FALSE))
|
|
154
|
-
|
|
155
|
-
png(
|
|
156
|
-
file.path(plotsdir, paste0(feat, ".vln.png")),
|
|
157
|
-
width = 800 + length(samples) * 15, height = 600, res = 100
|
|
201
|
+
tool = envs$doublet_detector,
|
|
202
|
+
DoubletFinderArgs = envs$DoubletFinder,
|
|
203
|
+
scDblFinderArgs = envs$scDblFinder,
|
|
204
|
+
filter = FALSE,
|
|
205
|
+
log = log,
|
|
206
|
+
cache = envs$cache
|
|
158
207
|
)
|
|
159
|
-
print(vln_p)
|
|
160
|
-
dev.off()
|
|
161
|
-
}
|
|
162
208
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
209
|
+
log$info("Visualizing doublet detection results ...")
|
|
210
|
+
if (identical(tolower(envs$doublet_detector), "doubletfinder")) {
|
|
211
|
+
p <- VizSeuratDoublets(sobj, plot_type = "pK", x_text_angle = 90)
|
|
212
|
+
save_plot(
|
|
213
|
+
p, file.path(dbldir, "doubletfinder_pk"),
|
|
214
|
+
devpars = list(res = 100, width = 800, height = 600),
|
|
215
|
+
formats = "png")
|
|
216
|
+
reporter$add(
|
|
217
|
+
list(
|
|
218
|
+
kind = "descr",
|
|
219
|
+
content = paste(
|
|
220
|
+
"The pK plot from DoubletFinder to select the optimal pK value.",
|
|
221
|
+
"See more at https://github.com/chris-mcginnis-ucsf/DoubletFinder"
|
|
222
|
+
)
|
|
223
|
+
),
|
|
224
|
+
list(
|
|
225
|
+
kind = "image",
|
|
226
|
+
src = file.path(dbldir, "doubletfinder_pk.png")
|
|
227
|
+
),
|
|
228
|
+
h1 = glue("Doublet detection using {envs$doublet_detector}"),
|
|
229
|
+
h2 = "BC metric vs pK"
|
|
230
|
+
)
|
|
231
|
+
}
|
|
183
232
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
sobj$.QC = NULL
|
|
233
|
+
for (pt in c("dim", "pie")) {
|
|
234
|
+
p <- VizSeuratDoublets(sobj, plot_type = pt)
|
|
235
|
+
save_plot(p, file.path(dbldir, paste0("doublets_", pt)), formats = "png")
|
|
188
236
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
237
|
+
reporter$add(
|
|
238
|
+
list(
|
|
239
|
+
src = file.path(dbldir, paste0("doublets_", pt, ".png")),
|
|
240
|
+
descr = ifelse(pt == "dim", "Dimention Reduction Plot", "Pie Chart")
|
|
241
|
+
),
|
|
242
|
+
h1 = glue("Doublet detection using {envs$doublet_detector}"),
|
|
243
|
+
h2 = "Doublets distribution",
|
|
244
|
+
ui = "table_of_images"
|
|
245
|
+
)
|
|
194
246
|
}
|
|
247
|
+
|
|
248
|
+
sobj <- subset(sobj, subset = !!sym(paste0(sobj@misc$doublets$tool, "_DropletType")) != "doublet")
|
|
195
249
|
}
|
|
196
|
-
dim_df = rbind(
|
|
197
|
-
dim_df,
|
|
198
|
-
data.frame(
|
|
199
|
-
When = "After_Gene_QC",
|
|
200
|
-
nCells = ncol(sobj),
|
|
201
|
-
nGenes = nrow(sobj)
|
|
202
|
-
)
|
|
203
|
-
)
|
|
204
250
|
|
|
205
|
-
|
|
206
|
-
|
|
251
|
+
if (!is.null(envs$mutaters) && length(envs$mutaters) > 0) {
|
|
252
|
+
log$info("Mutating metadata ...")
|
|
253
|
+
sobj@meta.data <- sobj@meta.data %>%
|
|
254
|
+
mutate(!!!lapply(envs$mutaters, rlang::parse_expr))
|
|
255
|
+
}
|
|
207
256
|
|
|
208
|
-
|
|
209
|
-
|
|
257
|
+
log$info("Saving QC'ed seurat object ...")
|
|
258
|
+
reporter$save(joboutdir)
|
|
259
|
+
save_obj(sobj, outfile)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
library(Seurat)
|
|
3
|
+
library(future)
|
|
4
|
+
library(biopipen.utils)
|
|
5
|
+
|
|
6
|
+
set.seed(8525)
|
|
7
|
+
|
|
8
|
+
srtfile <- {{in.srtobj | r}}
|
|
9
|
+
outfile <- {{out.outfile | r}}
|
|
10
|
+
ncores <- {{envs.ncores | r}}
|
|
11
|
+
mutaters <- {{envs.mutaters | r}}
|
|
12
|
+
subset <- {{envs.subset | r}}
|
|
13
|
+
cache <- {{envs.cache | r}}
|
|
14
|
+
RunPCAArgs <- {{envs.RunPCA | r: todot = "-"}}
|
|
15
|
+
RunUMAPArgs <- {{envs.RunUMAP | r: todot = "-"}}
|
|
16
|
+
FindNeighborsArgs <- {{envs.FindNeighbors | r: todot = "-"}}
|
|
17
|
+
FindClustersArgs <- {{envs.FindClusters | r: todot = "-"}}
|
|
18
|
+
cases <- {{envs.cases | r}}
|
|
19
|
+
|
|
20
|
+
options(future.globals.maxSize = Inf)
|
|
21
|
+
plan(strategy = "multicore", workers = ncores)
|
|
22
|
+
|
|
23
|
+
log <- get_logger()
|
|
24
|
+
|
|
25
|
+
cases <- expand_cases(cases, defaults = list(
|
|
26
|
+
RunPCA = RunPCAArgs,
|
|
27
|
+
RunUMAP = RunUMAPArgs,
|
|
28
|
+
FindNeighbors = FindNeighborsArgs,
|
|
29
|
+
FindClusters = FindClustersArgs,
|
|
30
|
+
subset = subset
|
|
31
|
+
))
|
|
32
|
+
|
|
33
|
+
if (isTRUE(cache)) {}
|
|
34
|
+
|
|
35
|
+
log$info("Reading Seurat object ...")
|
|
36
|
+
object <- read_obj(srtfile)
|
|
37
|
+
|
|
38
|
+
if (!is.null(mutaters) && length(mutaters) > 0) {
|
|
39
|
+
log$info("Mutating meta data ...")
|
|
40
|
+
object@meta.data <- mutate(
|
|
41
|
+
object@meta.data,
|
|
42
|
+
!!!lapply(mutaters, parse_expr)
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (name in names(cases)) {
|
|
47
|
+
case <- cases[[name]]
|
|
48
|
+
log$info("Processing case '{name}' ...")
|
|
49
|
+
|
|
50
|
+
object <- RunSeuratSubClustering(
|
|
51
|
+
object = object,
|
|
52
|
+
subset = case$subset,
|
|
53
|
+
name = name,
|
|
54
|
+
RunPCAArgs = case$RunPCAArgs,
|
|
55
|
+
RunUMAPArgs = case$RunUMAPArgs,
|
|
56
|
+
FindNeighborsArgs = case$FindNeighborsArgs,
|
|
57
|
+
FindClustersArgs = case$FindClustersArgs,
|
|
58
|
+
log = log,
|
|
59
|
+
cache = cache
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
log$info("Saving results ...")
|
|
64
|
+
biopipen.utils::save_obj(object, file = outfile)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
library(DropletUtils)
|
|
2
|
+
library(Seurat)
|
|
3
|
+
|
|
4
|
+
srtobjfile = {{in.srtobj | r}}
|
|
5
|
+
outdir = {{out.outdir | r}}
|
|
6
|
+
version = {{envs.version | r}}
|
|
7
|
+
split_by = {{envs.split_by | r}}
|
|
8
|
+
|
|
9
|
+
srtobj = readRDS(srtobjfile)
|
|
10
|
+
if (!is.null(split_by)) {
|
|
11
|
+
# check if split_by is a valid column
|
|
12
|
+
if (is.null(srtobj[[split_by]])) {
|
|
13
|
+
stop(paste0("Column ", split_by, " not found in Seurat object"))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
# split Seurat object by split_by column
|
|
17
|
+
objs <- SplitObject(srtobj, split.by = split_by)
|
|
18
|
+
for (s in names(objs)) {
|
|
19
|
+
counts <- GetAssayData(object = objs[[s]], layer = "counts")
|
|
20
|
+
odir <- file.path(outdir, s)
|
|
21
|
+
dir.create(odir, recursive = TRUE, showWarnings = FALSE)
|
|
22
|
+
write10xCounts(odir, counts, version = version, overwrite = TRUE)
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
counts = GetAssayData(object = srtobj, layer = "counts")
|
|
26
|
+
write10xCounts(outdir, counts, version = version, overwrite = TRUE)
|
|
27
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
library(rlang)
|
|
2
|
+
library(Seurat)
|
|
3
|
+
library(slingshot)
|
|
4
|
+
library(biopipen.utils)
|
|
5
|
+
|
|
6
|
+
sobjfile <- {{in.sobjfile | r}}
|
|
7
|
+
outfile <- {{out.outfile | r}}
|
|
8
|
+
group_by <- {{envs.group_by | r}}
|
|
9
|
+
reduction <- {{envs.reduction | r}}
|
|
10
|
+
dims <- {{envs.dims | r}}
|
|
11
|
+
start <- {{envs.start | r}}
|
|
12
|
+
end <- {{envs.end | r}}
|
|
13
|
+
prefix <- {{envs.prefix | r}}
|
|
14
|
+
reverse <- {{envs.reverse | r}}
|
|
15
|
+
align_start <- {{envs.align_start | r}}
|
|
16
|
+
seed <- {{envs.seed | r}}
|
|
17
|
+
|
|
18
|
+
set.seed(seed)
|
|
19
|
+
|
|
20
|
+
log <- get_logger()
|
|
21
|
+
|
|
22
|
+
log$info("Reading Seurat object ...")
|
|
23
|
+
srt <- read_obj(sobjfile)
|
|
24
|
+
group_by <- group_by %||% biopipen.utils::GetIdentityColumn(srt)
|
|
25
|
+
|
|
26
|
+
if (is.null(group_by) || !group_by %in% colnames(srt@meta.data)) {
|
|
27
|
+
stop(paste("Grouping column", group_by, "not found in the Seurat object"))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
reduction <- reduction %||% DefaultDimReduc(srt)
|
|
31
|
+
dims <- biopipen.utils:::.expand_number(dims)
|
|
32
|
+
|
|
33
|
+
if (is.null(prefix)) {
|
|
34
|
+
prefix <- ""
|
|
35
|
+
} else {
|
|
36
|
+
prefix <- paste0(prefix, "_")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
log$info("Filtering cells in NA group_by ...")
|
|
40
|
+
srt_sub <- srt[, !is.na(srt[[group_by, drop = TRUE]])]
|
|
41
|
+
|
|
42
|
+
log$info("Running Slingshot ...")
|
|
43
|
+
sl <- slingshot(
|
|
44
|
+
data = as.data.frame(srt_sub[[reduction]]@cell.embeddings[, dims]),
|
|
45
|
+
clusterLabels = as.character(srt_sub[[group_by, drop = TRUE]]),
|
|
46
|
+
start.clus = start, end.clus = end
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
df <- as.data.frame(slingPseudotime(sl))
|
|
50
|
+
colnames(df) <- paste0(prefix, colnames(df))
|
|
51
|
+
if (isTRUE(reverse)) {
|
|
52
|
+
if (isTRUE(align_start)) {
|
|
53
|
+
df <- apply(df, 2, function(x) max(x, na.rm = TRUE) - x)
|
|
54
|
+
} else {
|
|
55
|
+
df <- max(df, na.rm = TRUE) - df
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
srt <- AddMetaData(srt, metadata = df)
|
|
60
|
+
srt <- AddMetaData(srt, metadata = slingBranchID(sl), col.name = paste0(prefix, "BranchID"))
|
|
61
|
+
|
|
62
|
+
srt <- AddSeuratCommand(srt, "Slingshot", "slingshot(...)")
|
|
63
|
+
|
|
64
|
+
log$info("Saving Seurat object ...")
|
|
65
|
+
save_obj(srt, outfile)
|