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/tcr/Immunarch.R
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
+
{{ biopipen_dir | joinpaths: "utils", "single_cell.R" | source_r }}
|
|
3
3
|
# Basic analysis and clonality
|
|
4
4
|
# TODO: How about TRA chain?
|
|
5
5
|
library(rlang)
|
|
@@ -11,19 +11,29 @@ library(dplyr)
|
|
|
11
11
|
library(glue)
|
|
12
12
|
library(tidyr)
|
|
13
13
|
library(tibble)
|
|
14
|
+
library(logger)
|
|
14
15
|
|
|
16
|
+
log_info("Loading arguments ...")
|
|
15
17
|
theme_set(theme_prism())
|
|
16
18
|
|
|
17
19
|
immfile = {{ in.immdata | r }}
|
|
18
20
|
metafile = {{ in.metafile | r }}
|
|
19
21
|
outdir = {{ out.outdir | r }}
|
|
22
|
+
joboutdir = {{ job.outdir | r }}
|
|
20
23
|
mutaters = {{ envs.mutaters | r }}
|
|
21
24
|
prefix = {{ envs.prefix | r }}
|
|
22
25
|
|
|
26
|
+
log_info("Loading immdata ...")
|
|
23
27
|
immdata = readRDS(immfile)
|
|
28
|
+
|
|
29
|
+
if (is.null(prefix)) { prefix = immdata$prefix }
|
|
30
|
+
if (is.null(prefix)) { prefix = "" }
|
|
31
|
+
|
|
32
|
+
log_info("Expanding immdata ...")
|
|
24
33
|
exdata = expand_immdata(immdata)
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
log_info("Loading metadata if provided ...")
|
|
36
|
+
if (!is.null(metafile) && (endsWith(metafile, ".rds") || endsWith(metafile, ".RDS"))) {
|
|
27
37
|
meta = readRDS(metafile)@meta.data
|
|
28
38
|
} else if (!is.null(metafile) && nchar(metafile) > 0) {
|
|
29
39
|
meta = read.table(metafile, sep = "\t", header = TRUE, row.names = 1)
|
|
@@ -31,6 +41,7 @@ if (endsWith(metafile, ".rds") || endsWith(metafile, ".RDS")) {
|
|
|
31
41
|
meta = NULL
|
|
32
42
|
}
|
|
33
43
|
|
|
44
|
+
log_info("Merging metadata if provided ...")
|
|
34
45
|
if (!is.null(meta)) {
|
|
35
46
|
cell_ids = glue_data(exdata, paste0(prefix, "{Barcode}"))
|
|
36
47
|
dup_names = intersect(colnames(meta), colnames(exdata))
|
|
@@ -43,8 +54,10 @@ if (!is.null(meta)) {
|
|
|
43
54
|
}
|
|
44
55
|
rm(meta)
|
|
45
56
|
|
|
57
|
+
log_info("Mutating data if `envs.mutaters` is provided ...")
|
|
46
58
|
if (!is.null(mutaters) && length(mutaters) > 0) {
|
|
47
59
|
exdata = mutate(exdata, !!!lapply(mutaters, parse_expr))
|
|
60
|
+
immdata = immdata_from_expanded(exdata)
|
|
48
61
|
}
|
|
49
62
|
|
|
50
63
|
n_samples = length(immdata$data)
|
|
@@ -52,39 +65,78 @@ n_samples = length(immdata$data)
|
|
|
52
65
|
##################
|
|
53
66
|
# Basic analysis #
|
|
54
67
|
##################
|
|
55
|
-
|
|
68
|
+
volumes = {{envs.volumes | r}}
|
|
69
|
+
lens = {{envs.lens | r}}
|
|
70
|
+
counts = {{envs.counts | r}}
|
|
71
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-basic.R" | source_r }}
|
|
56
72
|
|
|
57
73
|
##################
|
|
58
74
|
# Clonality #
|
|
59
75
|
##################
|
|
60
|
-
|
|
76
|
+
top_clones = {{envs.top_clones | r}}
|
|
77
|
+
rare_clones = {{envs.rare_clones | r}}
|
|
78
|
+
hom_clones = {{envs.hom_clones | r}}
|
|
79
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-clonality.R" | source_r }}
|
|
61
80
|
|
|
62
81
|
##################
|
|
63
82
|
# Overlap #
|
|
64
83
|
##################
|
|
65
|
-
{
|
|
84
|
+
overlaps = {{ envs.overlaps | r: todot="-" }}
|
|
85
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-overlap.R" | source_r }}
|
|
66
86
|
|
|
67
87
|
##################
|
|
68
88
|
# Gene usage #
|
|
69
89
|
##################
|
|
70
|
-
{
|
|
90
|
+
gene_usages = {{ envs.gene_usages | r: todot="-" }}
|
|
91
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-geneusage.R" | source_r }}
|
|
71
92
|
|
|
72
93
|
##################
|
|
73
94
|
# Spectratyping #
|
|
74
95
|
##################
|
|
75
|
-
{
|
|
96
|
+
spects = {{ envs.spects | r }}
|
|
97
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-spectratyping.R" | source_r }}
|
|
76
98
|
|
|
77
99
|
########################
|
|
78
100
|
# Diversity estimation #
|
|
79
101
|
########################
|
|
80
|
-
{
|
|
102
|
+
div_method = {{envs.divs.method | default: "gini" | r}}
|
|
103
|
+
div_by = {{envs.divs.by | default: None | r}}
|
|
104
|
+
div_plot_type = {{envs.divs.plot_type | default: "bar" | r}}
|
|
105
|
+
div_order = {{envs.divs.order | default: [] | r}}
|
|
106
|
+
div_args = {{envs.divs.args | default: {} | r: todot="-"}}
|
|
107
|
+
div_test = {{envs.divs.test | default: None | r}}
|
|
108
|
+
div_cases = {{envs.divs.cases | default: {} | r: todot="-"}}
|
|
109
|
+
div_devpars = {{envs.divs.devpars | default: None | r}}
|
|
110
|
+
div_separate_by = {{envs.divs.separate_by | default: None | r}}
|
|
111
|
+
div_split_by = {{envs.divs.split_by | default: None | r}}
|
|
112
|
+
div_split_order = {{envs.divs.split_order | default: None | r}}
|
|
113
|
+
div_align_x = {{envs.divs.align_x | default: False | r}}
|
|
114
|
+
div_align_y = {{envs.divs.align_y | default: False | r}}
|
|
115
|
+
div_subset = {{envs.divs.subset | default: None | r}}
|
|
116
|
+
div_log = {{envs.divs.log | default: False | r}}
|
|
117
|
+
div_ncol = {{envs.divs.ncol | default: 2 | r}}
|
|
118
|
+
div_ymin = {{envs.divs.ymin | default: None | r}}
|
|
119
|
+
div_ymax = {{envs.divs.ymax | default: None | r}}
|
|
120
|
+
|
|
121
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "immunarch-patched.R" | source_r }}
|
|
122
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-diversity.R" | source_r }}
|
|
81
123
|
|
|
82
124
|
######################
|
|
83
125
|
# Clonotype tracking #
|
|
84
126
|
######################
|
|
85
|
-
{
|
|
127
|
+
trackings = {{ envs.trackings | r }}
|
|
128
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-tracking.R" | source_r }}
|
|
86
129
|
|
|
87
130
|
######################
|
|
88
131
|
# K-mer analysis #
|
|
89
132
|
######################
|
|
90
|
-
{
|
|
133
|
+
kmers = {{ envs.kmers | r: todot="-" }}
|
|
134
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-kmer.R" | source_r }}
|
|
135
|
+
|
|
136
|
+
######################
|
|
137
|
+
# VJ junction #
|
|
138
|
+
######################
|
|
139
|
+
vj_juncs <- {{envs.vj_junc | r}}
|
|
140
|
+
{{ biopipen_dir | joinpaths: "scripts", "tcr", "Immunarch-vjjunc.R" | source_r }}
|
|
141
|
+
|
|
142
|
+
save_report(joboutdir)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
2
|
|
|
3
3
|
library(dplyr)
|
|
4
4
|
library(glue)
|
|
@@ -6,15 +6,15 @@ library(tidyr)
|
|
|
6
6
|
library(tibble)
|
|
7
7
|
library(immunarch)
|
|
8
8
|
|
|
9
|
-
immfile = {{in.immdata |
|
|
9
|
+
immfile = {{in.immdata | r}}
|
|
10
10
|
{% if in.filterfile %}
|
|
11
11
|
filters = {{in.filterfile | toml_load | r}}
|
|
12
12
|
{% else %}
|
|
13
13
|
filters = {{envs.filters | r}}
|
|
14
14
|
{% endif %}
|
|
15
15
|
metacols = {{envs.metacols | r}}
|
|
16
|
-
outfile = {{out.outfile |
|
|
17
|
-
groupfile = {{out.groupfile |
|
|
16
|
+
outfile = {{out.outfile | r}}
|
|
17
|
+
groupfile = {{out.groupfile | r}}
|
|
18
18
|
|
|
19
19
|
immdata0 = readRDS(immfile)
|
|
20
20
|
groupname = filters$name
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
{{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
|
|
2
|
+
{{ biopipen_dir | joinpaths: "utils", "single_cell.R" | source_r }}
|
|
2
3
|
|
|
3
4
|
# Loading 10x data into immunarch
|
|
4
5
|
library(immunarch)
|
|
@@ -8,12 +9,13 @@ library(tibble)
|
|
|
8
9
|
library(glue)
|
|
9
10
|
library(bracer)
|
|
10
11
|
|
|
11
|
-
metafile = {{ in.metafile |
|
|
12
|
-
rdsfile = {{ out.rdsfile |
|
|
13
|
-
metatxt = {{ out.metatxt |
|
|
14
|
-
tmpdir = {{ envs.tmpdir |
|
|
15
|
-
mode = {{ envs.mode |
|
|
16
|
-
|
|
12
|
+
metafile = {{ in.metafile | r }}
|
|
13
|
+
rdsfile = {{ out.rdsfile | r }}
|
|
14
|
+
metatxt = {{ out.metatxt | r }}
|
|
15
|
+
tmpdir = {{ envs.tmpdir | r }}
|
|
16
|
+
mode = {{ envs.mode | r }}
|
|
17
|
+
extracols = {{ envs.extracols | r}}
|
|
18
|
+
prefix = {{ envs.prefix | r }}
|
|
17
19
|
|
|
18
20
|
metadata = read.table(
|
|
19
21
|
metafile,
|
|
@@ -34,6 +36,11 @@ if (!"TCRData" %in% colnames(metadata)) {
|
|
|
34
36
|
## Helpers
|
|
35
37
|
|
|
36
38
|
get_contig_annofile = function(dir, sample, warn=TRUE) {
|
|
39
|
+
if (is.na(dir) || !is.character(dir) || nchar(dir) == 0 || dir == "NA") {
|
|
40
|
+
warning(paste0("No path found for sample: ", sample), immediate. = TRUE)
|
|
41
|
+
return (NULL)
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
annofilepat = paste0(
|
|
38
45
|
"*", "{all,filtered}", "_contig_annotations.csv*" # .gz
|
|
39
46
|
)
|
|
@@ -86,6 +93,9 @@ for (i in seq_len(nrow(metadata))) {
|
|
|
86
93
|
sample = as.character(metadata[i, "Sample"])
|
|
87
94
|
|
|
88
95
|
annofile = get_contig_annofile(metadata[i, "TCRData"], sample)
|
|
96
|
+
if (is.null(annofile)) {
|
|
97
|
+
next
|
|
98
|
+
}
|
|
89
99
|
anno = read.delim2(annofile, sep=",", header=TRUE, stringsAsFactors=FALSE)
|
|
90
100
|
# Add cdr1, cdr2, fwr1, fwr2, etc columns
|
|
91
101
|
if (!"cdr1" %in% colnames(anno)) {
|
|
@@ -134,6 +144,7 @@ for (i in seq_len(nrow(metadata))) {
|
|
|
134
144
|
# file.symlink(normalizePath(annofile), file.path(datadir, paste0(sample, ext)))
|
|
135
145
|
}
|
|
136
146
|
|
|
147
|
+
log_info("Loading TCR data ...")
|
|
137
148
|
immdata = repLoad(datadir, .mode=mode)
|
|
138
149
|
if (mode == "single") {
|
|
139
150
|
data = immdata$data
|
|
@@ -164,27 +175,25 @@ immdata$meta = left_join(
|
|
|
164
175
|
by = "Sample"
|
|
165
176
|
)
|
|
166
177
|
|
|
178
|
+
immdata$prefix = prefix
|
|
179
|
+
|
|
167
180
|
saveRDS(immdata, file=rdsfile)
|
|
168
181
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
column_to_rownames("Barcode")
|
|
188
|
-
|
|
189
|
-
}))
|
|
190
|
-
write.table(metadf, metatxt, sep="\t", quote=FALSE, row.names=TRUE, col.names=TRUE)
|
|
182
|
+
log_info("Saving cell-level data ...")
|
|
183
|
+
exdata <- expand_immdata(immdata, cell_id = "Barcode") %>%
|
|
184
|
+
distinct(Sample, Barcode, .keep_all = TRUE) %>%
|
|
185
|
+
mutate(Barcode = glue(paste0(prefix, "{Barcode}"))) %>%
|
|
186
|
+
select(any_of(c(
|
|
187
|
+
colnames(immdata$meta),
|
|
188
|
+
"Barcode",
|
|
189
|
+
"CDR3.aa",
|
|
190
|
+
"Clones",
|
|
191
|
+
"Proportion",
|
|
192
|
+
"V.name",
|
|
193
|
+
"D.name",
|
|
194
|
+
"J.name",
|
|
195
|
+
extracols
|
|
196
|
+
))) %>%
|
|
197
|
+
column_to_rownames("Barcode")
|
|
198
|
+
|
|
199
|
+
write.table(exdata, metatxt, sep="\t", quote=FALSE, row.names=TRUE, col.names=TRUE)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
library(scRepertoire)
|
|
2
|
+
library(Seurat)
|
|
3
|
+
library(biopipen.utils)
|
|
4
|
+
|
|
5
|
+
screpfile <- {{in.screpfile | r}}
|
|
6
|
+
srtobjfile <- {{in.srtobj | r}}
|
|
7
|
+
outfile <- {{out.outfile | r}}
|
|
8
|
+
cloneCall <- {{envs.cloneCall | r}}
|
|
9
|
+
chain <- {{envs.chain | r}}
|
|
10
|
+
group_by <- {{envs.group_by | default: envs["group-by"] | default: None | r}}
|
|
11
|
+
proportion <- {{envs.proportion | r}}
|
|
12
|
+
filterNA <- {{envs.filterNA | r}}
|
|
13
|
+
cloneSize <- {{envs.cloneSize | r}}
|
|
14
|
+
addLabel <- {{envs.addLabel | r}}
|
|
15
|
+
|
|
16
|
+
log <- get_logger()
|
|
17
|
+
|
|
18
|
+
log$info("Loading scRepertoire object ...")
|
|
19
|
+
screp <- read_obj(screpfile)
|
|
20
|
+
|
|
21
|
+
log$info("Loading Seurat object ...")
|
|
22
|
+
srtobj <- read_obj(srtobjfile)
|
|
23
|
+
|
|
24
|
+
log$info("Combining expression data ...")
|
|
25
|
+
|
|
26
|
+
obj <- combineExpression(
|
|
27
|
+
input.data = screp,
|
|
28
|
+
sc.data = srtobj,
|
|
29
|
+
cloneCall = cloneCall,
|
|
30
|
+
chain = chain,
|
|
31
|
+
group.by = group_by,
|
|
32
|
+
proportion = proportion,
|
|
33
|
+
filterNA = filterNA,
|
|
34
|
+
cloneSize = unlist(cloneSize),
|
|
35
|
+
addLabel = addLabel
|
|
36
|
+
)
|
|
37
|
+
obj$VDJ_Presence <- !is.na(obj$CTaa)
|
|
38
|
+
|
|
39
|
+
log$info("Saving combined object ...")
|
|
40
|
+
save_obj(obj, outfile)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
library(rlang)
|
|
2
|
+
library(bracer)
|
|
3
|
+
library(scRepertoire)
|
|
4
|
+
library(biopipen.utils)
|
|
5
|
+
|
|
6
|
+
metafile <- {{in.metafile | r}}
|
|
7
|
+
outfile <- {{out.outfile | r}}
|
|
8
|
+
combineTCR_args <- {{envs.combineTCR | r}}
|
|
9
|
+
combineBCR_args <- {{envs.combineBCR | r}}
|
|
10
|
+
type <- {{envs.type | r}}
|
|
11
|
+
exclude <- {{envs.exclude | r}}
|
|
12
|
+
format <- {{envs.format | r}}
|
|
13
|
+
tmpdir <- {{envs.tmpdir | r}}
|
|
14
|
+
|
|
15
|
+
type = toupper(type)
|
|
16
|
+
if (length(exclude) == 1) {
|
|
17
|
+
exclude <- strsplit(exclude, ",")[[1]]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
log <- get_logger()
|
|
21
|
+
|
|
22
|
+
log$info("Loading metadata ...")
|
|
23
|
+
metadata <- read.table(metafile, header = TRUE, sep = "\t", row.names = NULL, check.names = FALSE)
|
|
24
|
+
if (type == "AUTO") {
|
|
25
|
+
if ("TCRData" %in% colnames(metadata) && "BCRData" %in% colnames(metadata)) {
|
|
26
|
+
log$warn("Both TCRData and BCRData columns found in metadata. Defaulting to TCR.")
|
|
27
|
+
type <- "TCR"
|
|
28
|
+
} else if ("TCRData" %in% colnames(metadata)) {
|
|
29
|
+
type <- "TCR"
|
|
30
|
+
} else if ("BCRData" %in% colnames(metadata)) {
|
|
31
|
+
type <- "BCR"
|
|
32
|
+
} else {
|
|
33
|
+
stop("Error: Neither TCRData nor BCRData column found in metadata.")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
data_column <- ifelse(type == "TCR", "TCRData", "BCRData")
|
|
38
|
+
combine_fn <- ifelse(type == "TCR", combineTCR, combineBCR)
|
|
39
|
+
combine_args <- if (type == "TCR") { combineTCR_args } else { combineBCR_args }
|
|
40
|
+
|
|
41
|
+
stopifnot("Error: Column `Sample` is not found in metafile." = "Sample" %in% colnames(metadata))
|
|
42
|
+
if (!data_column %in% colnames(metadata)) {
|
|
43
|
+
stop(paste0("Error: Column `", data_column, "` is not found in metafile."))
|
|
44
|
+
}
|
|
45
|
+
rownames(metadata) <- metadata$Sample
|
|
46
|
+
|
|
47
|
+
.gunzip <- function(input, output) {
|
|
48
|
+
# Open connections
|
|
49
|
+
con_in <- gzfile(input, "rt") # "rt" = read text mode
|
|
50
|
+
con_out <- file(output, "wt") # "wt" = write text mode
|
|
51
|
+
|
|
52
|
+
# Read line by line and write
|
|
53
|
+
while(length(line <- readLines(con_in, n = 10, warn = FALSE)) > 0) {
|
|
54
|
+
writeLines(line, con_out)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# Close connections
|
|
58
|
+
close(con_in)
|
|
59
|
+
close(con_out)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get_file_name <- function(fmt) {
|
|
63
|
+
if (is.null(fmt)) { return("filtered_contig_annotations.csv") }
|
|
64
|
+
fmt <- tolower(fmt)
|
|
65
|
+
if (fmt == "10x") { return("filtered_contig_annotations.csv") }
|
|
66
|
+
if (fmt == "airr") { return("airr_rearrangement.tsv") }
|
|
67
|
+
if (fmt == "bd") { return("Contigs_AIRR.tsv") }
|
|
68
|
+
if (fmt == "dandelion") { return("all_contig_dandelion.tsv") }
|
|
69
|
+
if (fmt == "immcantation") { return("data.tsv") }
|
|
70
|
+
if (fmt == "json") { return("contigs.json") }
|
|
71
|
+
if (fmt == "parsebio") { return("barcode_report.tsv") }
|
|
72
|
+
if (fmt == "mixcr") { return("clones.tsv") }
|
|
73
|
+
if (fmt == "omniscope") { return("contigs.csv") }
|
|
74
|
+
if (fmt == "trust4") { return("barcode_report.tsv") }
|
|
75
|
+
if (fmt == "wat3r") { return("barcode_results.csv") }
|
|
76
|
+
|
|
77
|
+
stop("Unsupported format: ", fmt)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get_format <- function(filename) {
|
|
81
|
+
if (identical(filename, "filtered_contig_annotations.csv")) { return("10X") }
|
|
82
|
+
if (identical(filename, "airr_rearrangement.tsv")) { return("AIRR") }
|
|
83
|
+
if (identical(filename, "Contigs_AIRR.tsv")) { return("BD") }
|
|
84
|
+
if (identical(filename, "all_contig_dandelion.tsv")) { return("Dandelion") }
|
|
85
|
+
if (identical(filename, "data.tsv")) { return("Immcantation") }
|
|
86
|
+
if (endsWith(filename, ".json")) { return("JSON") }
|
|
87
|
+
if (identical(filename, "barcode_report.tsv")) { return("ParseBio") }
|
|
88
|
+
if (identical(filename, "clones.tsv")) { return("MiXCR") }
|
|
89
|
+
if (identical(filename, "contigs.csv")) { return("Omniscope") }
|
|
90
|
+
# if (identical(filename, "barcode_report.tsv")) { return("TRUST4") }
|
|
91
|
+
if (identical(filename, "barcode_results.csv")) { return("WAT3R") }
|
|
92
|
+
|
|
93
|
+
return("10X")
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# helper function
|
|
97
|
+
get_contig_dir <- function(input, sample, fmt) {
|
|
98
|
+
if (is.na(input) || !is.character(input) || nchar(input) == 0 || input == "NA") {
|
|
99
|
+
warning(paste0("No path found for sample: ", sample), immediate. = TRUE)
|
|
100
|
+
return(list(NULL, fmt))
|
|
101
|
+
}
|
|
102
|
+
if (!file.exists(input)) {
|
|
103
|
+
stop(paste0("Input path does not exist for sample: ", sample, ": ", input))
|
|
104
|
+
}
|
|
105
|
+
if (dir.exists(input)) {
|
|
106
|
+
return(list(input, fmt))
|
|
107
|
+
}
|
|
108
|
+
# file
|
|
109
|
+
filedir <- file.path(tmpdir, slugify(sample))
|
|
110
|
+
dir.create(filedir, recursive = TRUE, showWarnings = FALSE)
|
|
111
|
+
|
|
112
|
+
# if it is gzipped
|
|
113
|
+
if (grepl("\\.gz$", input)) {
|
|
114
|
+
flatfile <- file.path(filedir, sub("\\.gz$", "", basename(input)))
|
|
115
|
+
.gunzip(input, flatfile)
|
|
116
|
+
input <- flatfile
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fmt <- fmt %||% get_format(basename(input))
|
|
120
|
+
filename <- get_file_name(fmt)
|
|
121
|
+
file.symlink(input, file.path(filedir, filename))
|
|
122
|
+
|
|
123
|
+
return(list(filedir, fmt))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
load_contig <- function(input, sample, fmt) {
|
|
127
|
+
log$info("- Sample: {sample}")
|
|
128
|
+
dirfmt <- get_contig_dir(input, sample, fmt)
|
|
129
|
+
dir <- dirfmt[[1]]
|
|
130
|
+
fmt <- dirfmt[[2]]
|
|
131
|
+
if (is.null(dir)) { return(NULL) }
|
|
132
|
+
x <- loadContigs(dir, format = fmt %||% "10X")
|
|
133
|
+
x <- x[[1]]
|
|
134
|
+
x$sample <- NULL
|
|
135
|
+
if (identical(fmt %||% "10X", "10X") && colnames(x)[1] == "X") {
|
|
136
|
+
x$X <- NULL
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
x
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
log$info("Reading {type} data ...")
|
|
144
|
+
contig_list <- lapply(seq_len(nrow(metadata)), function(i) {
|
|
145
|
+
sample <- as.character(metadata$Sample[i])
|
|
146
|
+
path <- metadata[[data_column]][i]
|
|
147
|
+
load_contig(path, sample, fmt = format)
|
|
148
|
+
})
|
|
149
|
+
names(contig_list) <- as.character(metadata$Sample)
|
|
150
|
+
contig_list <- contig_list[!sapply(contig_list, is.null)]
|
|
151
|
+
|
|
152
|
+
log$info("Combining {type} data and adding meta data ...")
|
|
153
|
+
if (isTRUE(combine_args$samples)) {
|
|
154
|
+
combine_args$samples <- names(contig_list)
|
|
155
|
+
}
|
|
156
|
+
combine_args$input.data <- contig_list
|
|
157
|
+
screp_data <- do_call(combine_fn, combine_args)
|
|
158
|
+
for (col in colnames(metadata)) {
|
|
159
|
+
if (col %in% exclude) { next }
|
|
160
|
+
screp_data <- addVariable(screp_data, col, metadata[names(screp_data), col])
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
rm(contig_list, combine_args)
|
|
164
|
+
|
|
165
|
+
log$info("Saving {type} data ...")
|
|
166
|
+
save_obj(screp_data, outfile)
|