biopipen 0.21.0__py3-none-any.whl → 0.34.26__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- biopipen/__init__.py +1 -1
- biopipen/core/config.toml +28 -0
- biopipen/core/filters.py +79 -4
- biopipen/core/proc.py +12 -3
- biopipen/core/testing.py +75 -3
- biopipen/ns/bam.py +148 -6
- biopipen/ns/bed.py +75 -0
- biopipen/ns/cellranger.py +186 -0
- biopipen/ns/cellranger_pipeline.py +126 -0
- biopipen/ns/cnv.py +19 -3
- biopipen/ns/cnvkit.py +1 -1
- biopipen/ns/cnvkit_pipeline.py +20 -12
- biopipen/ns/delim.py +34 -35
- biopipen/ns/gene.py +68 -23
- biopipen/ns/gsea.py +63 -37
- biopipen/ns/misc.py +39 -14
- biopipen/ns/plot.py +304 -1
- biopipen/ns/protein.py +183 -0
- biopipen/ns/regulatory.py +290 -0
- biopipen/ns/rnaseq.py +142 -5
- biopipen/ns/scrna.py +2053 -473
- biopipen/ns/scrna_metabolic_landscape.py +228 -382
- biopipen/ns/snp.py +659 -0
- biopipen/ns/stats.py +484 -0
- biopipen/ns/tcr.py +683 -98
- biopipen/ns/vcf.py +236 -2
- biopipen/ns/web.py +97 -6
- biopipen/reports/bam/CNVpytor.svelte +4 -9
- biopipen/reports/cellranger/CellRangerCount.svelte +18 -0
- biopipen/reports/cellranger/CellRangerSummary.svelte +16 -0
- biopipen/reports/cellranger/CellRangerVdj.svelte +18 -0
- biopipen/reports/cnvkit/CNVkitDiagram.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitHeatmap.svelte +1 -1
- biopipen/reports/cnvkit/CNVkitScatter.svelte +1 -1
- biopipen/reports/common.svelte +15 -0
- biopipen/reports/protein/ProdigySummary.svelte +16 -0
- biopipen/reports/scrna/CellsDistribution.svelte +4 -39
- biopipen/reports/scrna/DimPlots.svelte +1 -1
- biopipen/reports/scrna/MarkersFinder.svelte +6 -126
- biopipen/reports/scrna/MetaMarkers.svelte +3 -75
- biopipen/reports/scrna/RadarPlots.svelte +4 -20
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +61 -22
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +88 -82
- biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +70 -10
- biopipen/reports/snp/PlinkCallRate.svelte +24 -0
- biopipen/reports/snp/PlinkFreq.svelte +18 -0
- biopipen/reports/snp/PlinkHWE.svelte +18 -0
- biopipen/reports/snp/PlinkHet.svelte +18 -0
- biopipen/reports/snp/PlinkIBD.svelte +18 -0
- biopipen/reports/tcr/CDR3AAPhyschem.svelte +19 -66
- biopipen/reports/tcr/ClonalStats.svelte +16 -0
- biopipen/reports/tcr/CloneResidency.svelte +3 -93
- biopipen/reports/tcr/Immunarch.svelte +4 -155
- biopipen/reports/tcr/TCRClusterStats.svelte +3 -45
- biopipen/reports/tcr/TESSA.svelte +11 -28
- biopipen/reports/utils/misc.liq +22 -7
- biopipen/scripts/bam/BamMerge.py +11 -15
- biopipen/scripts/bam/BamSampling.py +90 -0
- biopipen/scripts/bam/BamSort.py +141 -0
- biopipen/scripts/bam/BamSplitChroms.py +10 -10
- biopipen/scripts/bam/BamSubsetByBed.py +38 -0
- biopipen/scripts/bam/CNAClinic.R +41 -5
- biopipen/scripts/bam/CNVpytor.py +153 -54
- biopipen/scripts/bam/ControlFREEC.py +13 -14
- biopipen/scripts/bam/SamtoolsView.py +33 -0
- biopipen/scripts/bed/Bed2Vcf.py +5 -5
- biopipen/scripts/bed/BedConsensus.py +5 -5
- biopipen/scripts/bed/BedLiftOver.sh +6 -4
- biopipen/scripts/bed/BedtoolsIntersect.py +54 -0
- biopipen/scripts/bed/BedtoolsMakeWindows.py +47 -0
- biopipen/scripts/bed/BedtoolsMerge.py +4 -4
- biopipen/scripts/cellranger/CellRangerCount.py +138 -0
- biopipen/scripts/cellranger/CellRangerSummary.R +181 -0
- biopipen/scripts/cellranger/CellRangerVdj.py +112 -0
- biopipen/scripts/cnv/AneuploidyScore.R +55 -20
- biopipen/scripts/cnv/AneuploidyScoreSummary.R +221 -163
- biopipen/scripts/cnv/TMADScore.R +25 -9
- biopipen/scripts/cnv/TMADScoreSummary.R +57 -86
- biopipen/scripts/cnvkit/CNVkitAccess.py +7 -6
- biopipen/scripts/cnvkit/CNVkitAutobin.py +26 -18
- biopipen/scripts/cnvkit/CNVkitBatch.py +6 -6
- biopipen/scripts/cnvkit/CNVkitCall.py +3 -3
- biopipen/scripts/cnvkit/CNVkitCoverage.py +4 -3
- biopipen/scripts/cnvkit/CNVkitDiagram.py +5 -5
- biopipen/scripts/cnvkit/CNVkitFix.py +3 -3
- biopipen/scripts/cnvkit/CNVkitGuessBaits.py +12 -8
- biopipen/scripts/cnvkit/CNVkitHeatmap.py +5 -5
- biopipen/scripts/cnvkit/CNVkitReference.py +6 -5
- biopipen/scripts/cnvkit/CNVkitScatter.py +5 -5
- biopipen/scripts/cnvkit/CNVkitSegment.py +5 -5
- biopipen/scripts/cnvkit/guess_baits.py +166 -93
- biopipen/scripts/delim/RowsBinder.R +1 -1
- biopipen/scripts/delim/SampleInfo.R +116 -118
- biopipen/scripts/gene/GeneNameConversion.R +67 -0
- biopipen/scripts/gene/GenePromoters.R +61 -0
- biopipen/scripts/gsea/Enrichr.R +5 -5
- biopipen/scripts/gsea/FGSEA.R +184 -50
- biopipen/scripts/gsea/GSEA.R +2 -2
- biopipen/scripts/gsea/PreRank.R +5 -5
- biopipen/scripts/misc/Config2File.py +2 -2
- biopipen/scripts/misc/Plot.R +80 -0
- biopipen/scripts/misc/Shell.sh +15 -0
- biopipen/scripts/misc/Str2File.py +2 -2
- biopipen/scripts/plot/Heatmap.R +3 -3
- biopipen/scripts/plot/Manhattan.R +147 -0
- biopipen/scripts/plot/QQPlot.R +146 -0
- biopipen/scripts/plot/ROC.R +88 -0
- biopipen/scripts/plot/Scatter.R +112 -0
- biopipen/scripts/plot/VennDiagram.R +5 -9
- biopipen/scripts/protein/MMCIF2PDB.py +33 -0
- biopipen/scripts/protein/PDB2Fasta.py +60 -0
- biopipen/scripts/protein/Prodigy.py +119 -0
- biopipen/scripts/protein/ProdigySummary.R +140 -0
- biopipen/scripts/protein/RMSD.py +178 -0
- biopipen/scripts/regulatory/MotifAffinityTest.R +102 -0
- biopipen/scripts/regulatory/MotifAffinityTest_AtSNP.R +127 -0
- biopipen/scripts/regulatory/MotifAffinityTest_MotifBreakR.R +104 -0
- biopipen/scripts/regulatory/MotifScan.py +159 -0
- biopipen/scripts/regulatory/VariantMotifPlot.R +78 -0
- biopipen/scripts/regulatory/motifs-common.R +324 -0
- biopipen/scripts/rnaseq/Simulation-ESCO.R +180 -0
- biopipen/scripts/rnaseq/Simulation-RUVcorr.R +45 -0
- biopipen/scripts/rnaseq/Simulation.R +21 -0
- biopipen/scripts/rnaseq/UnitConversion.R +325 -54
- biopipen/scripts/scrna/AnnData2Seurat.R +40 -0
- biopipen/scripts/scrna/CCPlotR-patch.R +161 -0
- biopipen/scripts/scrna/CellCellCommunication.py +150 -0
- biopipen/scripts/scrna/CellCellCommunicationPlots.R +93 -0
- biopipen/scripts/scrna/CellSNPLite.py +30 -0
- biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +185 -0
- biopipen/scripts/scrna/CellTypeAnnotation-direct.R +68 -31
- biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +27 -22
- biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +28 -20
- biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +48 -25
- biopipen/scripts/scrna/CellTypeAnnotation.R +37 -1
- biopipen/scripts/scrna/CellsDistribution.R +456 -167
- biopipen/scripts/scrna/DimPlots.R +1 -1
- biopipen/scripts/scrna/ExprImputation-alra.R +109 -0
- biopipen/scripts/scrna/ExprImputation-rmagic.R +256 -0
- biopipen/scripts/scrna/{ExprImpution-scimpute.R → ExprImputation-scimpute.R} +8 -5
- biopipen/scripts/scrna/ExprImputation.R +7 -0
- biopipen/scripts/scrna/LoomTo10X.R +51 -0
- biopipen/scripts/scrna/MQuad.py +25 -0
- biopipen/scripts/scrna/MarkersFinder.R +679 -400
- biopipen/scripts/scrna/MetaMarkers.R +265 -161
- biopipen/scripts/scrna/ModuleScoreCalculator.R +66 -11
- biopipen/scripts/scrna/PseudoBulkDEG.R +678 -0
- biopipen/scripts/scrna/RadarPlots.R +355 -134
- biopipen/scripts/scrna/ScFGSEA.R +298 -100
- biopipen/scripts/scrna/ScSimulation.R +65 -0
- biopipen/scripts/scrna/ScVelo.py +617 -0
- biopipen/scripts/scrna/Seurat2AnnData.R +7 -0
- biopipen/scripts/scrna/SeuratClusterStats-clustree.R +87 -0
- biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +36 -30
- biopipen/scripts/scrna/SeuratClusterStats-features.R +138 -187
- biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +81 -0
- biopipen/scripts/scrna/SeuratClusterStats-stats.R +78 -89
- biopipen/scripts/scrna/SeuratClusterStats.R +47 -10
- biopipen/scripts/scrna/SeuratClustering.R +36 -233
- biopipen/scripts/scrna/SeuratLoading.R +2 -2
- biopipen/scripts/scrna/SeuratMap2Ref.R +84 -113
- biopipen/scripts/scrna/SeuratMetadataMutater.R +16 -6
- biopipen/scripts/scrna/SeuratPreparing.R +223 -173
- biopipen/scripts/scrna/SeuratSubClustering.R +64 -0
- biopipen/scripts/scrna/SeuratTo10X.R +27 -0
- biopipen/scripts/scrna/Slingshot.R +65 -0
- biopipen/scripts/scrna/Subset10X.R +2 -2
- biopipen/scripts/scrna/TopExpressingGenes.R +169 -135
- biopipen/scripts/scrna/celltypist-wrapper.py +195 -0
- biopipen/scripts/scrna/scvelo_paga.py +313 -0
- biopipen/scripts/scrna/seurat_anndata_conversion.py +98 -0
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +447 -82
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +348 -241
- biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +188 -166
- biopipen/scripts/snp/MatrixEQTL.R +217 -0
- biopipen/scripts/snp/Plink2GTMat.py +148 -0
- biopipen/scripts/snp/PlinkCallRate.R +199 -0
- biopipen/scripts/snp/PlinkFilter.py +100 -0
- biopipen/scripts/snp/PlinkFreq.R +291 -0
- biopipen/scripts/snp/PlinkFromVcf.py +81 -0
- biopipen/scripts/snp/PlinkHWE.R +85 -0
- biopipen/scripts/snp/PlinkHet.R +96 -0
- biopipen/scripts/snp/PlinkIBD.R +196 -0
- biopipen/scripts/snp/PlinkSimulation.py +124 -0
- biopipen/scripts/snp/PlinkUpdateName.py +124 -0
- biopipen/scripts/stats/ChowTest.R +146 -0
- biopipen/scripts/stats/DiffCoexpr.R +152 -0
- biopipen/scripts/stats/LiquidAssoc.R +135 -0
- biopipen/scripts/stats/Mediation.R +108 -0
- biopipen/scripts/stats/MetaPvalue.R +130 -0
- biopipen/scripts/stats/MetaPvalue1.R +74 -0
- biopipen/scripts/tcgamaf/Maf2Vcf.py +2 -2
- biopipen/scripts/tcgamaf/MafAddChr.py +2 -2
- biopipen/scripts/tcr/Attach2Seurat.R +3 -2
- biopipen/scripts/tcr/CDR3AAPhyschem.R +211 -143
- biopipen/scripts/tcr/CDR3Clustering.R +343 -0
- biopipen/scripts/tcr/ClonalStats.R +526 -0
- biopipen/scripts/tcr/CloneResidency.R +255 -131
- biopipen/scripts/tcr/CloneSizeQQPlot.R +4 -4
- biopipen/scripts/tcr/GIANA/GIANA.py +1356 -797
- biopipen/scripts/tcr/GIANA/GIANA4.py +1362 -789
- biopipen/scripts/tcr/GIANA/query.py +164 -162
- biopipen/scripts/tcr/Immunarch-basic.R +31 -9
- biopipen/scripts/tcr/Immunarch-clonality.R +25 -5
- biopipen/scripts/tcr/Immunarch-diversity.R +352 -134
- biopipen/scripts/tcr/Immunarch-geneusage.R +45 -5
- biopipen/scripts/tcr/Immunarch-kmer.R +68 -8
- biopipen/scripts/tcr/Immunarch-overlap.R +84 -4
- biopipen/scripts/tcr/Immunarch-spectratyping.R +35 -6
- biopipen/scripts/tcr/Immunarch-tracking.R +38 -6
- biopipen/scripts/tcr/Immunarch-vjjunc.R +165 -0
- biopipen/scripts/tcr/Immunarch.R +63 -11
- biopipen/scripts/tcr/Immunarch2VDJtools.R +2 -2
- biopipen/scripts/tcr/ImmunarchFilter.R +4 -4
- biopipen/scripts/tcr/ImmunarchLoading.R +38 -29
- biopipen/scripts/tcr/SampleDiversity.R +1 -1
- biopipen/scripts/tcr/ScRepCombiningExpression.R +40 -0
- biopipen/scripts/tcr/ScRepLoading.R +166 -0
- biopipen/scripts/tcr/TCRClusterStats.R +176 -22
- biopipen/scripts/tcr/TCRDock.py +110 -0
- biopipen/scripts/tcr/TESSA.R +102 -118
- biopipen/scripts/tcr/VJUsage.R +5 -5
- biopipen/scripts/tcr/immunarch-patched.R +142 -0
- biopipen/scripts/tcr/vdjtools-patch.sh +1 -1
- biopipen/scripts/vcf/BcftoolsAnnotate.py +91 -0
- biopipen/scripts/vcf/BcftoolsFilter.py +90 -0
- biopipen/scripts/vcf/BcftoolsMerge.py +31 -0
- biopipen/scripts/vcf/BcftoolsSort.py +113 -0
- biopipen/scripts/vcf/BcftoolsView.py +73 -0
- biopipen/scripts/vcf/TruvariBench.sh +14 -7
- biopipen/scripts/vcf/TruvariBenchSummary.R +16 -13
- biopipen/scripts/vcf/TruvariConsistency.R +1 -1
- biopipen/scripts/vcf/Vcf2Bed.py +2 -2
- biopipen/scripts/vcf/VcfAnno.py +11 -11
- biopipen/scripts/vcf/VcfDownSample.sh +22 -10
- biopipen/scripts/vcf/VcfFilter.py +5 -5
- biopipen/scripts/vcf/VcfFix.py +7 -7
- biopipen/scripts/vcf/VcfFix_utils.py +13 -4
- biopipen/scripts/vcf/VcfIndex.py +3 -3
- biopipen/scripts/vcf/VcfIntersect.py +3 -3
- biopipen/scripts/vcf/VcfLiftOver.sh +5 -0
- biopipen/scripts/vcf/VcfSplitSamples.py +4 -4
- biopipen/scripts/vcf/bcftools_utils.py +52 -0
- biopipen/scripts/web/Download.py +8 -4
- biopipen/scripts/web/DownloadList.py +5 -5
- biopipen/scripts/web/GCloudStorageDownloadBucket.py +82 -0
- biopipen/scripts/web/GCloudStorageDownloadFile.py +23 -0
- biopipen/scripts/web/gcloud_common.py +49 -0
- biopipen/utils/gene.py +108 -60
- biopipen/utils/misc.py +146 -20
- biopipen/utils/reference.py +64 -20
- biopipen/utils/reporter.py +177 -0
- biopipen/utils/vcf.py +1 -1
- biopipen-0.34.26.dist-info/METADATA +27 -0
- biopipen-0.34.26.dist-info/RECORD +292 -0
- {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/WHEEL +1 -1
- {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/entry_points.txt +6 -2
- biopipen/ns/bcftools.py +0 -111
- biopipen/ns/scrna_basic.py +0 -255
- biopipen/reports/delim/SampleInfo.svelte +0 -36
- biopipen/reports/scrna/GeneExpressionInvistigation.svelte +0 -32
- biopipen/reports/scrna/ScFGSEA.svelte +0 -35
- biopipen/reports/scrna/SeuratClusterStats.svelte +0 -82
- biopipen/reports/scrna/SeuratMap2Ref.svelte +0 -20
- biopipen/reports/scrna/SeuratPreparing.svelte +0 -38
- biopipen/reports/scrna/TopExpressingGenes.svelte +0 -55
- biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +0 -31
- biopipen/reports/utils/gsea.liq +0 -110
- biopipen/scripts/bcftools/BcftoolsAnnotate.py +0 -42
- biopipen/scripts/bcftools/BcftoolsFilter.py +0 -79
- biopipen/scripts/bcftools/BcftoolsSort.py +0 -19
- biopipen/scripts/gene/GeneNameConversion.py +0 -66
- biopipen/scripts/scrna/ExprImpution-alra.R +0 -32
- biopipen/scripts/scrna/ExprImpution-rmagic.R +0 -29
- biopipen/scripts/scrna/ExprImpution.R +0 -7
- biopipen/scripts/scrna/GeneExpressionInvistigation.R +0 -132
- biopipen/scripts/scrna/Write10X.R +0 -11
- biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +0 -150
- biopipen/scripts/tcr/TCRClustering.R +0 -280
- biopipen/utils/common_docstrs.py +0 -61
- biopipen/utils/gene.R +0 -49
- biopipen/utils/gsea.R +0 -193
- biopipen/utils/io.R +0 -20
- biopipen/utils/misc.R +0 -114
- biopipen/utils/mutate_helpers.R +0 -433
- biopipen/utils/plot.R +0 -173
- biopipen/utils/rnaseq.R +0 -48
- biopipen/utils/single_cell.R +0 -115
- biopipen-0.21.0.dist-info/METADATA +0 -22
- biopipen-0.21.0.dist-info/RECORD +0 -218
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import os
|
|
3
|
+
import warnings
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from diot import Diot # type: ignore[import]
|
|
7
|
+
import scanpy as sc
|
|
8
|
+
import scvelo as scv
|
|
9
|
+
import numpy as np
|
|
10
|
+
import matplotlib
|
|
11
|
+
matplotlib.use('Agg')
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
from biopipen.utils.misc import logger, require_package
|
|
14
|
+
from biopipen.scripts.scrna.seurat_anndata_conversion import (
|
|
15
|
+
convert_seurat_to_anndata,
|
|
16
|
+
convert_anndata_to_seurat,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
require_package("scvelo", ">=0.3.3")
|
|
20
|
+
from biopipen.scripts.scrna import scvelo_paga # noqa: F401
|
|
21
|
+
|
|
22
|
+
warnings.simplefilter("ignore", category=UserWarning)
|
|
23
|
+
warnings.simplefilter("ignore", category=FutureWarning)
|
|
24
|
+
warnings.simplefilter("ignore", category=DeprecationWarning)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def SCVELO(
|
|
28
|
+
adata,
|
|
29
|
+
group_by,
|
|
30
|
+
dirpath,
|
|
31
|
+
logger,
|
|
32
|
+
palette=None,
|
|
33
|
+
linear_reduction=None,
|
|
34
|
+
nonlinear_reduction=None,
|
|
35
|
+
basis=None,
|
|
36
|
+
mode=["deterministic", "stochastic", "dynamical"],
|
|
37
|
+
fitting_by="stochastic",
|
|
38
|
+
min_shared_counts=30,
|
|
39
|
+
n_pcs=30,
|
|
40
|
+
n_neighbors=30,
|
|
41
|
+
stream_smooth=None,
|
|
42
|
+
stream_density=2,
|
|
43
|
+
arrow_size=5,
|
|
44
|
+
arrow_length=5,
|
|
45
|
+
arrow_density=0.5,
|
|
46
|
+
denoise=False,
|
|
47
|
+
denoise_topn=3,
|
|
48
|
+
kinetics=False,
|
|
49
|
+
kinetics_topn=100,
|
|
50
|
+
calculate_velocity_genes=False,
|
|
51
|
+
top_n=6,
|
|
52
|
+
ncores=1,
|
|
53
|
+
dpi=100,
|
|
54
|
+
fileprefix="",
|
|
55
|
+
):
|
|
56
|
+
os.chdir(os.path.expanduser(dirpath))
|
|
57
|
+
if linear_reduction is None:
|
|
58
|
+
sc.pp.pca(adata, n_comps=n_pcs)
|
|
59
|
+
linear_reduction = "X_pca"
|
|
60
|
+
elif linear_reduction not in adata.obsm.keys():
|
|
61
|
+
logger.warning(
|
|
62
|
+
f"Linear reduction '{linear_reduction}' not found in adata.obsm. "
|
|
63
|
+
"Running PCA to generate it."
|
|
64
|
+
)
|
|
65
|
+
sc.pp.pca(adata, n_comps=n_pcs)
|
|
66
|
+
linear_reduction = "X_pca"
|
|
67
|
+
|
|
68
|
+
if basis is None:
|
|
69
|
+
if nonlinear_reduction is not None:
|
|
70
|
+
basis = nonlinear_reduction
|
|
71
|
+
else:
|
|
72
|
+
basis = "basis"
|
|
73
|
+
adata.obsm["X_basis"] = adata.obsm[linear_reduction][
|
|
74
|
+
:, 0:2
|
|
75
|
+
]
|
|
76
|
+
scv.pl.utils.check_basis(adata, basis)
|
|
77
|
+
|
|
78
|
+
if "spliced" not in adata.layers.keys():
|
|
79
|
+
raise ValueError("'spliced' data must be provided.")
|
|
80
|
+
|
|
81
|
+
if "unspliced" not in adata.layers.keys():
|
|
82
|
+
raise ValueError("'unspliced' data must be provided.")
|
|
83
|
+
|
|
84
|
+
if type(mode) is str:
|
|
85
|
+
mode = [mode]
|
|
86
|
+
|
|
87
|
+
mode.append(fitting_by)
|
|
88
|
+
if kinetics is True or denoise is True:
|
|
89
|
+
mode.append("dynamical")
|
|
90
|
+
|
|
91
|
+
mode = list(set(mode))
|
|
92
|
+
if "dynamical" in mode:
|
|
93
|
+
mode.sort(key="dynamical".__eq__)
|
|
94
|
+
|
|
95
|
+
adata.obs[group_by] = adata.obs[group_by].astype(dtype="category")
|
|
96
|
+
scv.pl.proportions(adata, groupby=group_by, save=False, show=False)
|
|
97
|
+
|
|
98
|
+
plt.savefig(
|
|
99
|
+
".".join(filter(None, [fileprefix, "proportions.png"])), dpi=dpi
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
logger.info("- Filtering and normalizing data ...")
|
|
103
|
+
scv.pp.filter_and_normalize(adata, min_shared_counts=min_shared_counts)
|
|
104
|
+
|
|
105
|
+
logger.info("- Running moments ...")
|
|
106
|
+
# adata.var['highly_variable_genes'].astype(bool)
|
|
107
|
+
# adata.var['highly_variable_genes'].fillna(False, inplace=True)
|
|
108
|
+
scv.pp.moments(
|
|
109
|
+
adata, n_pcs=n_pcs, n_neighbors=n_neighbors, use_rep=linear_reduction
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
highly_variable_genes = adata.var["highly_variable_genes"].index.tolist()
|
|
113
|
+
adata.uns["layer_features_RNA"] = highly_variable_genes
|
|
114
|
+
adata.uns["layer_features_spliced"] = highly_variable_genes
|
|
115
|
+
adata.uns["layer_features_unspliced"] = highly_variable_genes
|
|
116
|
+
|
|
117
|
+
for m in mode:
|
|
118
|
+
vkey_list = [m]
|
|
119
|
+
dk_list = [False]
|
|
120
|
+
gene_subset_list = [None]
|
|
121
|
+
autoscale_list = [True]
|
|
122
|
+
|
|
123
|
+
logger.info(f"- mode: {m}")
|
|
124
|
+
adata.uns["layer_features_" + m] = highly_variable_genes
|
|
125
|
+
adata.uns["layer_features_variance_" + m] = highly_variable_genes
|
|
126
|
+
if m == "dynamical":
|
|
127
|
+
adata2 = adata[:, adata.var[fitting_by + "_genes"]].copy()
|
|
128
|
+
Ms = adata2.layers["Ms"]
|
|
129
|
+
Mu = adata2.layers["Mu"]
|
|
130
|
+
adata2.layers.clear()
|
|
131
|
+
adata2.layers["Ms"] = Ms
|
|
132
|
+
adata2.layers["Mu"] = Mu
|
|
133
|
+
connectivities = adata2.obsp["connectivities"]
|
|
134
|
+
adata2.obsp.clear()
|
|
135
|
+
adata2.obsp["connectivities"] = connectivities
|
|
136
|
+
adata.uns["layer_features_Ms"] = highly_variable_genes
|
|
137
|
+
adata.uns["layer_features_Mu"] = highly_variable_genes
|
|
138
|
+
|
|
139
|
+
scv.tl.recover_dynamics(
|
|
140
|
+
adata2,
|
|
141
|
+
var_names=fitting_by + "_genes",
|
|
142
|
+
use_raw=False,
|
|
143
|
+
n_jobs=ncores,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
var_add = [
|
|
147
|
+
i
|
|
148
|
+
for i in list(adata2.var.columns)
|
|
149
|
+
if not i in list(adata.var.columns)
|
|
150
|
+
]
|
|
151
|
+
adata.var = adata.var.merge(
|
|
152
|
+
adata2.var[var_add], how="left", left_index=True, right_index=True
|
|
153
|
+
)
|
|
154
|
+
adata.uns["recover_dynamics"] = adata2.uns["recover_dynamics"]
|
|
155
|
+
|
|
156
|
+
adata.varm["loss"] = np.empty(
|
|
157
|
+
(adata.shape[1], adata2.varm["loss"].shape[1])
|
|
158
|
+
)
|
|
159
|
+
adata.varm["loss"][:] = np.nan
|
|
160
|
+
adata.varm["loss"][adata.var[fitting_by + "_genes"], :] = adata2.varm[
|
|
161
|
+
"loss"
|
|
162
|
+
]
|
|
163
|
+
|
|
164
|
+
empty_layer = np.empty((adata.layers["spliced"].shape))
|
|
165
|
+
empty_layer[:] = np.nan
|
|
166
|
+
adata.layers["fit_t"] = adata.layers["fit_tau"] = adata.layers[
|
|
167
|
+
"fit_tau_"
|
|
168
|
+
] = empty_layer
|
|
169
|
+
adata.layers["fit_t"][:, adata.var[fitting_by + "_genes"]] = (
|
|
170
|
+
adata2.layers["fit_t"]
|
|
171
|
+
)
|
|
172
|
+
adata.layers["fit_tau"][:, adata.var[fitting_by + "_genes"]] = (
|
|
173
|
+
adata2.layers["fit_tau"]
|
|
174
|
+
)
|
|
175
|
+
adata.layers["fit_tau_"][:, adata.var[fitting_by + "_genes"]] = (
|
|
176
|
+
adata2.layers["fit_tau_"]
|
|
177
|
+
)
|
|
178
|
+
adata.uns["layer_features_fit_t"] = highly_variable_genes
|
|
179
|
+
adata.uns["layer_features_fit_tau"] = highly_variable_genes
|
|
180
|
+
adata.uns["layer_features_fit_tau_"] = highly_variable_genes
|
|
181
|
+
|
|
182
|
+
if kinetics is True:
|
|
183
|
+
vkey_list.append("dynamical_kinetics")
|
|
184
|
+
dk_list.append(True)
|
|
185
|
+
gene_subset_list.append(None)
|
|
186
|
+
autoscale_list.append(True)
|
|
187
|
+
top_genes = (
|
|
188
|
+
adata.var["fit_likelihood"]
|
|
189
|
+
.sort_values(ascending=False)
|
|
190
|
+
.index[:kinetics_topn]
|
|
191
|
+
)
|
|
192
|
+
scv.tl.differential_kinetic_test(
|
|
193
|
+
adata, var_names=top_genes, groupby=group_by
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
if denoise is True:
|
|
197
|
+
vkey_list.append("dynamical_denoise")
|
|
198
|
+
dk_list.append(False)
|
|
199
|
+
gene_subset_list.append(
|
|
200
|
+
adata.var["fit_likelihood"]
|
|
201
|
+
.sort_values(ascending=False)
|
|
202
|
+
.index[:denoise_topn]
|
|
203
|
+
)
|
|
204
|
+
autoscale_list.append(False)
|
|
205
|
+
adata.layers["dynamical_denoise"] = adata.layers[m] + np.random.normal(
|
|
206
|
+
adata.layers[m], scale=adata.layers["Ms"].std(0)
|
|
207
|
+
)
|
|
208
|
+
adata.uns["layer_features_dynamical_denoise"] = highly_variable_genes
|
|
209
|
+
|
|
210
|
+
for i in range(len(vkey_list)):
|
|
211
|
+
vkey = vkey_list[i]
|
|
212
|
+
dk = dk_list[i]
|
|
213
|
+
gene_subset = gene_subset_list[i]
|
|
214
|
+
autoscale = autoscale_list[i]
|
|
215
|
+
|
|
216
|
+
# Velocity graph
|
|
217
|
+
scv.tl.velocity(adata, mode=m, vkey=vkey, diff_kinetics=dk)
|
|
218
|
+
scv.tl.velocity_graph(
|
|
219
|
+
adata,
|
|
220
|
+
vkey=vkey,
|
|
221
|
+
gene_subset=gene_subset,
|
|
222
|
+
n_neighbors=n_neighbors,
|
|
223
|
+
n_jobs=ncores,
|
|
224
|
+
)
|
|
225
|
+
if m == "dynamical":
|
|
226
|
+
adata.var["velocity_genes"] = adata.var[m + "_genes"]
|
|
227
|
+
adata.layers["velocity"] = adata.layers[m]
|
|
228
|
+
adata.layers["variance_u"] = adata.layers[m + "_u"]
|
|
229
|
+
adata.uns["layer_features_velocity"] = highly_variable_genes
|
|
230
|
+
adata.uns["layer_features_variance_u"] = highly_variable_genes
|
|
231
|
+
adata.uns["layer_features_dynamical_u"] = highly_variable_genes
|
|
232
|
+
else:
|
|
233
|
+
adata.var["velocity_gamma"] = adata.var[m + "_gamma"]
|
|
234
|
+
adata.var["velocity_r2"] = adata.var[m + "_r2"]
|
|
235
|
+
adata.var["velocity_genes"] = adata.var[m + "_genes"]
|
|
236
|
+
adata.layers["velocity"] = adata.layers[m]
|
|
237
|
+
# adata.layers["variance_velocity"] = adata.layers["variance_" + m]
|
|
238
|
+
adata.uns["layer_features_velocity"] = highly_variable_genes
|
|
239
|
+
|
|
240
|
+
# Velocity embedding
|
|
241
|
+
scv.tl.velocity_embedding(
|
|
242
|
+
adata, basis=basis, vkey=vkey, autoscale=autoscale
|
|
243
|
+
)
|
|
244
|
+
scv.pl.velocity_embedding_stream(
|
|
245
|
+
adata,
|
|
246
|
+
vkey=vkey,
|
|
247
|
+
basis=basis,
|
|
248
|
+
title=vkey,
|
|
249
|
+
color=group_by,
|
|
250
|
+
palette=palette,
|
|
251
|
+
smooth=stream_smooth,
|
|
252
|
+
density=stream_density,
|
|
253
|
+
legend_loc="none",
|
|
254
|
+
save=False,
|
|
255
|
+
show=False,
|
|
256
|
+
)
|
|
257
|
+
plt.savefig(
|
|
258
|
+
".".join(filter(None, [fileprefix, vkey + "_stream.png"])),
|
|
259
|
+
dpi=dpi,
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
scv.pl.velocity_embedding(
|
|
263
|
+
adata,
|
|
264
|
+
vkey=vkey,
|
|
265
|
+
basis=basis,
|
|
266
|
+
title=vkey,
|
|
267
|
+
color=group_by,
|
|
268
|
+
palette=palette,
|
|
269
|
+
arrow_length=arrow_length,
|
|
270
|
+
arrow_size=arrow_size,
|
|
271
|
+
density=arrow_density,
|
|
272
|
+
linewidth=0.3,
|
|
273
|
+
save=False,
|
|
274
|
+
show=False,
|
|
275
|
+
)
|
|
276
|
+
plt.savefig(
|
|
277
|
+
".".join(filter(None, [fileprefix, vkey + "_arrow.png"])),
|
|
278
|
+
dpi=dpi,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
scv.pl.velocity_embedding_grid(
|
|
282
|
+
adata,
|
|
283
|
+
vkey=vkey,
|
|
284
|
+
basis=basis,
|
|
285
|
+
title=vkey,
|
|
286
|
+
color=group_by,
|
|
287
|
+
palette=palette,
|
|
288
|
+
arrow_length=arrow_length / 2,
|
|
289
|
+
arrow_size=arrow_size / 2,
|
|
290
|
+
density=arrow_density * 2,
|
|
291
|
+
save=False,
|
|
292
|
+
show=False,
|
|
293
|
+
)
|
|
294
|
+
plt.savefig(
|
|
295
|
+
".".join(
|
|
296
|
+
filter(None, [fileprefix, vkey + "_embedding_grid.png"])
|
|
297
|
+
),
|
|
298
|
+
dpi=dpi,
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
# Velocity confidence
|
|
302
|
+
scv.tl.velocity_confidence(adata, vkey=vkey)
|
|
303
|
+
scv.pl.scatter(
|
|
304
|
+
adata,
|
|
305
|
+
basis=basis,
|
|
306
|
+
title=vkey + " length",
|
|
307
|
+
color=vkey + "_length",
|
|
308
|
+
cmap="coolwarm",
|
|
309
|
+
save=False,
|
|
310
|
+
show=False,
|
|
311
|
+
)
|
|
312
|
+
plt.savefig(
|
|
313
|
+
".".join(filter(None, [fileprefix, vkey + "_length.png"])),
|
|
314
|
+
dpi=dpi,
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
scv.pl.scatter(
|
|
318
|
+
adata,
|
|
319
|
+
basis=basis,
|
|
320
|
+
title=vkey + " confidence",
|
|
321
|
+
color=vkey + "_confidence",
|
|
322
|
+
cmap="magma",
|
|
323
|
+
save=False,
|
|
324
|
+
show=False,
|
|
325
|
+
)
|
|
326
|
+
plt.savefig(
|
|
327
|
+
".".join(filter(None, [fileprefix, vkey + "_confidence.png"])),
|
|
328
|
+
dpi=dpi,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
# Terminal states
|
|
332
|
+
for term in [
|
|
333
|
+
"root_cells",
|
|
334
|
+
"end_points",
|
|
335
|
+
vkey + "_root_cells",
|
|
336
|
+
vkey + "_end_points",
|
|
337
|
+
]:
|
|
338
|
+
if term in adata.obs.columns:
|
|
339
|
+
adata.obs.drop(term, axis=1, inplace=True)
|
|
340
|
+
|
|
341
|
+
scv.tl.terminal_states(
|
|
342
|
+
adata,
|
|
343
|
+
vkey=vkey,
|
|
344
|
+
)
|
|
345
|
+
for term in ["root_cells", "end_points"]:
|
|
346
|
+
adata.obs[vkey + "_" + term] = adata.obs[term]
|
|
347
|
+
adata.obs.drop(term, axis=1, inplace=True)
|
|
348
|
+
|
|
349
|
+
# scv.pl.scatter(adata,basis=basis,title=vkey+" terminal_states",color_gradients=[vkey+'_root_cells', vkey+'_end_points'], legend_loc="best", save=False, show=False)
|
|
350
|
+
# if show_plot is True:
|
|
351
|
+
# plt.show()
|
|
352
|
+
# if save:
|
|
353
|
+
# plt.savefig('.'.join(filter(None, [fileprefix, vkey+"_terminal_states.png"])), dpi=dpi)
|
|
354
|
+
|
|
355
|
+
# Pseudotime
|
|
356
|
+
scv.tl.velocity_pseudotime(
|
|
357
|
+
adata,
|
|
358
|
+
vkey=vkey,
|
|
359
|
+
root_key=vkey + "_root_cells",
|
|
360
|
+
end_key=vkey + "_end_points",
|
|
361
|
+
)
|
|
362
|
+
scv.pl.scatter(
|
|
363
|
+
adata,
|
|
364
|
+
basis=basis,
|
|
365
|
+
title=vkey + " pseudotime",
|
|
366
|
+
color=vkey + "_pseudotime",
|
|
367
|
+
cmap="cividis",
|
|
368
|
+
save=False,
|
|
369
|
+
show=False,
|
|
370
|
+
)
|
|
371
|
+
plt.savefig(
|
|
372
|
+
".".join(filter(None, [fileprefix, vkey + "_pseudotime.png"])),
|
|
373
|
+
dpi=dpi,
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
# Latent time
|
|
377
|
+
if m == "dynamical":
|
|
378
|
+
scv.tl.latent_time(
|
|
379
|
+
adata,
|
|
380
|
+
vkey=vkey,
|
|
381
|
+
root_key=vkey + "_root_cells",
|
|
382
|
+
end_key=vkey + "_end_points",
|
|
383
|
+
)
|
|
384
|
+
scv.pl.scatter(
|
|
385
|
+
adata,
|
|
386
|
+
basis=basis,
|
|
387
|
+
title=vkey + " latent time",
|
|
388
|
+
color="latent_time",
|
|
389
|
+
color_map="cividis",
|
|
390
|
+
save=False,
|
|
391
|
+
show=False,
|
|
392
|
+
)
|
|
393
|
+
plt.savefig(
|
|
394
|
+
".".join(
|
|
395
|
+
filter(None, [fileprefix, vkey + "_latent_time.png"])
|
|
396
|
+
),
|
|
397
|
+
dpi=dpi,
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
# PAGA
|
|
401
|
+
adata.uns["neighbors"]["distances"] = adata.obsp["distances"]
|
|
402
|
+
adata.uns["neighbors"]["connectivities"] = adata.obsp["connectivities"]
|
|
403
|
+
scv.tl.paga(
|
|
404
|
+
adata,
|
|
405
|
+
groups=group_by,
|
|
406
|
+
vkey=vkey,
|
|
407
|
+
root_key=vkey + "_root_cells",
|
|
408
|
+
end_key=vkey + "_end_points",
|
|
409
|
+
)
|
|
410
|
+
scv.pl.paga(
|
|
411
|
+
adata,
|
|
412
|
+
title=vkey + " PAGA (" + group_by + ")",
|
|
413
|
+
node_colors=palette,
|
|
414
|
+
basis=basis,
|
|
415
|
+
alpha=0.5,
|
|
416
|
+
min_edge_width=2,
|
|
417
|
+
node_size_scale=1.5, # type: ignore
|
|
418
|
+
legend_loc="none",
|
|
419
|
+
save=False,
|
|
420
|
+
show=False,
|
|
421
|
+
)
|
|
422
|
+
plt.savefig(
|
|
423
|
+
".".join(filter(None, [fileprefix, vkey + "_paga.png"])),
|
|
424
|
+
dpi=dpi,
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
# Velocity genes
|
|
428
|
+
if calculate_velocity_genes is True:
|
|
429
|
+
if m != "dynamical":
|
|
430
|
+
scv.tl.rank_velocity_genes(adata, vkey=vkey, groupby=group_by)
|
|
431
|
+
adata.var[vkey + "_score"] = adata.var["spearmans_score"]
|
|
432
|
+
df1 = scv.get_df(adata.uns["rank_velocity_genes"]["names"])
|
|
433
|
+
adata.uns["rank_" + vkey + "_genenames"] = df1
|
|
434
|
+
df2 = scv.get_df(adata.uns["rank_velocity_genes"]["scores"])
|
|
435
|
+
adata.uns["rank_" + vkey + "_genescores"] = df2
|
|
436
|
+
del adata.uns["rank_velocity_genes"]
|
|
437
|
+
else:
|
|
438
|
+
scv.tl.rank_dynamical_genes(adata, groupby=group_by)
|
|
439
|
+
df1 = scv.get_df(adata.uns["rank_dynamical_genes"]["names"])
|
|
440
|
+
adata.uns["rank_" + vkey + "_genenames"] = df1
|
|
441
|
+
df2 = scv.get_df(adata.uns["rank_dynamical_genes"]["scores"])
|
|
442
|
+
adata.uns["rank_" + vkey + "_genescores"] = df2
|
|
443
|
+
del adata.uns["rank_dynamical_genes"]
|
|
444
|
+
|
|
445
|
+
for cluster in df1.columns:
|
|
446
|
+
# df1[0:1].values.ravel()[:12] ### by row
|
|
447
|
+
|
|
448
|
+
scv.pl.scatter(
|
|
449
|
+
adata,
|
|
450
|
+
color=group_by,
|
|
451
|
+
palette=palette,
|
|
452
|
+
basis=df1[cluster].values[:top_n],
|
|
453
|
+
vkey=vkey,
|
|
454
|
+
size=10,
|
|
455
|
+
linewidth=2,
|
|
456
|
+
alpha=1,
|
|
457
|
+
ylabel="cluster: " + cluster + "\nunspliced",
|
|
458
|
+
add_linfit=True,
|
|
459
|
+
add_rug=True,
|
|
460
|
+
add_outline=True,
|
|
461
|
+
ncols=3,
|
|
462
|
+
frameon=True,
|
|
463
|
+
save=False,
|
|
464
|
+
show=False,
|
|
465
|
+
)
|
|
466
|
+
plt.savefig(
|
|
467
|
+
".".join(
|
|
468
|
+
filter(
|
|
469
|
+
None,
|
|
470
|
+
[fileprefix, cluster, vkey + "_genes1.png"],
|
|
471
|
+
)
|
|
472
|
+
),
|
|
473
|
+
dpi=dpi,
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
scv.pl.velocity(
|
|
477
|
+
adata,
|
|
478
|
+
color=group_by,
|
|
479
|
+
var_names=df1[cluster].values[:top_n],
|
|
480
|
+
vkey=vkey,
|
|
481
|
+
size=10,
|
|
482
|
+
linewidth=2,
|
|
483
|
+
alpha=1,
|
|
484
|
+
ylabel="cluster: " + cluster + "\nunspliced",
|
|
485
|
+
add_outline=True,
|
|
486
|
+
basis=basis,
|
|
487
|
+
color_map=["Blues", "YlOrRd"],
|
|
488
|
+
ncols=2,
|
|
489
|
+
save=False,
|
|
490
|
+
show=False,
|
|
491
|
+
)
|
|
492
|
+
plt.savefig(
|
|
493
|
+
".".join(
|
|
494
|
+
filter(
|
|
495
|
+
None,
|
|
496
|
+
[fileprefix, cluster, vkey + "_genes2.png"],
|
|
497
|
+
)
|
|
498
|
+
),
|
|
499
|
+
dpi=dpi,
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
try:
|
|
503
|
+
adata.__dict__["_raw"].__dict__["_var"] = (
|
|
504
|
+
adata.__dict__["_raw"]
|
|
505
|
+
.__dict__["_var"]
|
|
506
|
+
.rename(columns={"_index": "features"})
|
|
507
|
+
)
|
|
508
|
+
except:
|
|
509
|
+
pass
|
|
510
|
+
|
|
511
|
+
return adata
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
sobjfile: str = {{in.sobjfile | quote}} # pyright: ignore # noqa: E999
|
|
515
|
+
outfile: str = {{out.outfile | quote}} # pyright: ignore # noqa: E999
|
|
516
|
+
outdir: str = os.path.dirname(outfile)
|
|
517
|
+
|
|
518
|
+
ncores: int = {{envs.ncores | repr}} # pyright: ignore # noqa: E999
|
|
519
|
+
group_by: str | None = {{envs.group_by | repr}} # pyright: ignore # noqa: E999
|
|
520
|
+
mode: str | list[str] = {{envs.mode | repr}} # pyright: ignore # noqa: E999
|
|
521
|
+
fitting_by: str = {{envs.fitting_by | repr}} # pyright: ignore # noqa: E999
|
|
522
|
+
min_shared_counts: int = {{envs.min_shared_counts | repr}} # pyright: ignore # noqa: E999
|
|
523
|
+
n_pcs: int = {{envs.n_pcs | repr}} # pyright: ignore # noqa: E999
|
|
524
|
+
n_neighbors: int = {{envs.n_neighbors | repr}} # pyright: ignore # noqa: E999
|
|
525
|
+
denoise: bool = {{envs.denoise | repr}} # pyright: ignore # noqa: E999
|
|
526
|
+
denoise_topn: int = {{envs.denoise_topn | repr}} # pyright: ignore # noqa: E999
|
|
527
|
+
kinetics: bool = {{envs.kinetics | repr}} # pyright: ignore # noqa: E999
|
|
528
|
+
kinetics_topn: int = {{envs.kinetics_topn | repr}} # pyright: ignore # noqa: E999
|
|
529
|
+
calculate_velocity_genes: bool = {{envs.calculate_velocity_genes | repr}} # pyright: ignore # noqa: E999
|
|
530
|
+
top_n: int = {{envs.top_n | repr}} # pyright: ignore # noqa: E999
|
|
531
|
+
rscript: str = {{envs.rscript | repr}} # pyright: ignore # noqa: E999
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
if sobjfile.endswith(".h5ad"):
|
|
535
|
+
h5ad_file = Path(sobjfile)
|
|
536
|
+
else:
|
|
537
|
+
h5ad_file = Path(outfile).with_suffix(".input.h5ad")
|
|
538
|
+
logger.info("Converting Seurat object to AnnData (h5ad) format...")
|
|
539
|
+
seurat_ident_col = convert_seurat_to_anndata(
|
|
540
|
+
input_file=sobjfile,
|
|
541
|
+
output_file=h5ad_file,
|
|
542
|
+
rscript=rscript,
|
|
543
|
+
return_ident_col=not group_by,
|
|
544
|
+
)
|
|
545
|
+
group_by = group_by or seurat_ident_col
|
|
546
|
+
|
|
547
|
+
if group_by is None:
|
|
548
|
+
group_by = "seurat_clusters"
|
|
549
|
+
logger.warning(
|
|
550
|
+
"`envs.group_by` is not provided. "
|
|
551
|
+
"Using 'seurat_clusters' as the default groupby column. "
|
|
552
|
+
"It is recommended to provide the `envs.group_by` parameter."
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
logger.info(f"Reading AnnData (h5ad) file ...")
|
|
556
|
+
adata = sc.read_h5ad(h5ad_file)
|
|
557
|
+
|
|
558
|
+
if group_by not in adata.obs.columns:
|
|
559
|
+
raise ValueError(
|
|
560
|
+
f"The group_by column envs.group_by = '{group_by}' is not found in the AnnData object."
|
|
561
|
+
)
|
|
562
|
+
|
|
563
|
+
logger.info(f"Running scVelo analysis ...")
|
|
564
|
+
|
|
565
|
+
if isinstance(mode, str):
|
|
566
|
+
mode = [mode]
|
|
567
|
+
|
|
568
|
+
if not all([m in ["deterministic","stochastic","dynamical"] for m in mode]):
|
|
569
|
+
raise ValueError(
|
|
570
|
+
"The 'envs.mode' parameter must be one or more of 'deterministic', 'stochastic', or 'dynamical'."
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
if not fitting_by in ["deterministic","stochastic"]:
|
|
574
|
+
raise ValueError(
|
|
575
|
+
"The 'envs.fitting_by' parameter must be either 'deterministic' or 'stochastic'."
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
adata = SCVELO(
|
|
579
|
+
adata=adata,
|
|
580
|
+
group_by=group_by,
|
|
581
|
+
dirpath=outdir,
|
|
582
|
+
linear_reduction="X_pca",
|
|
583
|
+
mode=mode,
|
|
584
|
+
fitting_by=fitting_by,
|
|
585
|
+
min_shared_counts=min_shared_counts,
|
|
586
|
+
n_pcs=n_pcs,
|
|
587
|
+
n_neighbors=n_neighbors,
|
|
588
|
+
stream_smooth=None,
|
|
589
|
+
stream_density=2,
|
|
590
|
+
arrow_size=5,
|
|
591
|
+
arrow_length=5,
|
|
592
|
+
arrow_density=0.5,
|
|
593
|
+
denoise=denoise,
|
|
594
|
+
denoise_topn=denoise_topn,
|
|
595
|
+
kinetics=kinetics,
|
|
596
|
+
kinetics_topn=kinetics_topn,
|
|
597
|
+
calculate_velocity_genes=calculate_velocity_genes,
|
|
598
|
+
top_n=top_n,
|
|
599
|
+
ncores=ncores,
|
|
600
|
+
logger=logger,
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
if outfile.endswith(".h5ad"):
|
|
604
|
+
h5ad_file = Path(outfile)
|
|
605
|
+
else:
|
|
606
|
+
h5ad_file = Path(outfile).with_suffix(".output.h5ad")
|
|
607
|
+
|
|
608
|
+
logger.info(f"Writing object to AnnData (h5ad) file ...")
|
|
609
|
+
adata.write_h5ad(h5ad_file)
|
|
610
|
+
|
|
611
|
+
if not outfile.endswith(".h5ad"):
|
|
612
|
+
logger.info(f"Converting AnnData (h5ad) file to Seurat format ...")
|
|
613
|
+
convert_anndata_to_seurat(
|
|
614
|
+
input_file=h5ad_file,
|
|
615
|
+
output_file=outfile,
|
|
616
|
+
rscript=rscript,
|
|
617
|
+
)
|