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,343 @@
|
|
|
1
|
+
library(dplyr)
|
|
2
|
+
library(tidyr)
|
|
3
|
+
library(tibble)
|
|
4
|
+
library(glue)
|
|
5
|
+
library(biopipen.utils)
|
|
6
|
+
|
|
7
|
+
screpfile <- {{in.screpfile | r}}
|
|
8
|
+
outdir <- normalizePath({{job.outdir | r}})
|
|
9
|
+
outfile <- {{out.outfile | r}}
|
|
10
|
+
|
|
11
|
+
tool <- {{envs.tool | r}}
|
|
12
|
+
python <- {{envs.python | r}}
|
|
13
|
+
within_sample <- {{envs.within_sample | r}}
|
|
14
|
+
args <- {{envs.args | r}}
|
|
15
|
+
chain <- {{envs.chain | r}}
|
|
16
|
+
type <- {{envs.type | r}}
|
|
17
|
+
|
|
18
|
+
setwd(outdir)
|
|
19
|
+
|
|
20
|
+
log <- get_logger()
|
|
21
|
+
|
|
22
|
+
log$info("Reading input file ...")
|
|
23
|
+
obj <- read_obj(screpfile)
|
|
24
|
+
is_seurat <- inherits(obj, "Seurat")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
get_type <- function() {
|
|
28
|
+
if (!is_seurat) {
|
|
29
|
+
for (sample in names(obj)) {
|
|
30
|
+
for (gene in obj[[sample]]$CTgene) {
|
|
31
|
+
if (grepl("^TRB", gene) || grepl("^TRG", gene) || grepl("^TRA", gene) || grepl("^TRD", gene)) {
|
|
32
|
+
return("TCR")
|
|
33
|
+
} else if (grepl("^IGH", gene) || grepl("^IGK", gene) || grepl("^IGL", gene)) {
|
|
34
|
+
return("BCR")
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
for (gene in obj@meta.data$CTgene) {
|
|
40
|
+
if (grepl("^TRB", gene) || grepl("^TRG", gene) || grepl("^TRA", gene) || grepl("^TRD", gene)) {
|
|
41
|
+
return("TCR")
|
|
42
|
+
} else if (grepl("^IGH", gene) || grepl("^IGK", gene) || grepl("^IGL", gene)) {
|
|
43
|
+
return("BCR")
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
stop("Cannot determine the type of the data (TCR or BCR). Please set envs.type to 'TCR' or 'BCR'.")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (type == "auto") {
|
|
51
|
+
type <- get_type()
|
|
52
|
+
log$info("Auto-detected data type: {type}")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get_cdr3aa_df <- function() {
|
|
56
|
+
if (!is_seurat) {
|
|
57
|
+
out <- NULL
|
|
58
|
+
for (sample in names(obj)) {
|
|
59
|
+
df <- data.frame(
|
|
60
|
+
Sample = sample,
|
|
61
|
+
Barcode = obj[[sample]]$barcode
|
|
62
|
+
)
|
|
63
|
+
if (chain == "both") {
|
|
64
|
+
df$CDR3.aa <- obj[[sample]]$CTaa
|
|
65
|
+
} else if ((type == "BCR" && chain == "heavy") || (type == "TCR" && chain == "light")) {
|
|
66
|
+
df$CDR3.aa <- obj[[sample]]$cdr3_aa1
|
|
67
|
+
} else if ((type == "BCR" && chain == "light") || (type == "TCR" && chain == "heavy")) {
|
|
68
|
+
df$CDR3.aa <- obj[[sample]]$cdr3_aa2
|
|
69
|
+
} else {
|
|
70
|
+
stop(paste("Unknown chain:", chain, "for", type))
|
|
71
|
+
}
|
|
72
|
+
out <- rbind(out, df)
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
out <- obj@meta.data
|
|
76
|
+
out$Barcode <- rownames(out)
|
|
77
|
+
out <- out %>% filter(!is.na(CTaa))
|
|
78
|
+
if (grepl("_", out$CTaa[1])) {
|
|
79
|
+
if (chain == "both") {
|
|
80
|
+
out$CDR3.aa <- out$CTaa
|
|
81
|
+
} else {
|
|
82
|
+
out <- separate(out, CTaa, into = c("first", "second"), sep = "_")
|
|
83
|
+
if ((type == "BCR" && chain == "heavy") || (type == "TCR" && chain == "light")) {
|
|
84
|
+
out$CDR3.aa <- out$first
|
|
85
|
+
} else if ((type == "BCR" && chain == "light") || (type == "TCR" && chain == "heavy")) {
|
|
86
|
+
out$CDR3.aa <- out$second
|
|
87
|
+
} else {
|
|
88
|
+
stop(paste("Unknown chain:", chain, "for", type))
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
out$CDR3.aa <- out$CTaa
|
|
93
|
+
}
|
|
94
|
+
out <- select(out, Sample, Barcode, CDR3.aa)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Sample, Barcode, CDR3.aa
|
|
98
|
+
out
|
|
99
|
+
}
|
|
100
|
+
cdr3aa_df = get_cdr3aa_df()
|
|
101
|
+
|
|
102
|
+
prepare_clustcr = function(clustcr_dir) {
|
|
103
|
+
clustering_args = ""
|
|
104
|
+
for (name in names(args)) {
|
|
105
|
+
value = args[[name]]
|
|
106
|
+
if (is.logical(value)) {
|
|
107
|
+
value = tools::toTitleCase(as.character(value))
|
|
108
|
+
} else if (is.character(value)) {
|
|
109
|
+
value = paste0("'", value, "'")
|
|
110
|
+
}
|
|
111
|
+
clustering_args = paste(name, "=", value)
|
|
112
|
+
}
|
|
113
|
+
clustcr_source = '
|
|
114
|
+
import sys
|
|
115
|
+
import atexit
|
|
116
|
+
|
|
117
|
+
import pandas as pd
|
|
118
|
+
from scipy import sparse as scipy_sparse
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@atexit.register
|
|
122
|
+
def clustcr_exit():
|
|
123
|
+
import pandas as pd
|
|
124
|
+
import numpy
|
|
125
|
+
import scipy
|
|
126
|
+
import sklearn
|
|
127
|
+
import matplotlib
|
|
128
|
+
sys.stderr.write("Session info:\\n")
|
|
129
|
+
sys.stderr.write(f"- pandas: {pd.__version__}\\n")
|
|
130
|
+
sys.stderr.write(f"- numpy: {numpy.__version__}\\n")
|
|
131
|
+
sys.stderr.write(f"- scipy: {scipy.__version__}\\n")
|
|
132
|
+
sys.stderr.write(f"- sklearn: {sklearn.__version__}\\n")
|
|
133
|
+
sys.stderr.write(f"- matplotlib: {matplotlib.__version__}\\n")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# Monkey-patch scipy.sparse.isspmatrix to adopt latest scipy v1.14
|
|
137
|
+
# If not, an error is raised:
|
|
138
|
+
# numpy.linalg.LinAlgError: 0-dimensional array given.
|
|
139
|
+
# Array must be at least two-dimensional
|
|
140
|
+
scipy_sparse.isspmatrix = lambda x: isinstance(
|
|
141
|
+
x,
|
|
142
|
+
(
|
|
143
|
+
scipy_sparse.spmatrix,
|
|
144
|
+
scipy_sparse.csr_array,
|
|
145
|
+
scipy_sparse.csr_matrix,
|
|
146
|
+
scipy_sparse.csc_array,
|
|
147
|
+
scipy_sparse.csc_matrix,
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
import clustcr # noqa: #402
|
|
153
|
+
|
|
154
|
+
clustcr_dir, clustcr_infile = sys.argv[1:3]
|
|
155
|
+
cdr3df = pd.read_csv(clustcr_infile, index_col=None)
|
|
156
|
+
cdr3 = cdr3df.iloc[:, 0]
|
|
157
|
+
|
|
158
|
+
clustering = clustcr.Clustering()
|
|
159
|
+
output = clustering.fit(cdr3)
|
|
160
|
+
output.clusters_df.to_csv(clustcr_dir + "/clusters.txt", sep="\t", index=False)
|
|
161
|
+
'
|
|
162
|
+
clustcr_file = file.path(clustcr_dir, "_clustcr.py")
|
|
163
|
+
cat(sprintf(clustcr_source, clustering_args), file=clustcr_file)
|
|
164
|
+
clustcr_file
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
clean_clustcr_output = function(clustcr_outfile) {
|
|
168
|
+
clustcr_out = read.delim2(clustcr_outfile, header=TRUE, row.names = NULL)
|
|
169
|
+
colnames(clustcr_out) = c("CDR3.aa", "CDR3_Cluster")
|
|
170
|
+
out = left_join(cdr3aa_df, distinct(clustcr_out), by=c(cdr3seq4clustering = "CDR3.aa")) %>%
|
|
171
|
+
mutate(
|
|
172
|
+
CDR3_Cluster = if_else(
|
|
173
|
+
is.na(CDR3_Cluster),
|
|
174
|
+
paste0("S_", row_number()),
|
|
175
|
+
paste0("M_", as.character(CDR3_Cluster))
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
if (within_sample) {
|
|
180
|
+
out <- mutate(out, CDR3_Cluster = paste0(Sample, ".", CDR3_Cluster))
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
# This join would result in more rows than dplyr can handle
|
|
184
|
+
# left_join(cdr3aa_df, out, by = "CDR3.aa")
|
|
185
|
+
out <- out[match(cdr3aa_df$CDR3.aa, out$CDR3.aa), , drop=FALSE]
|
|
186
|
+
cbind(cdr3aa_df, out[, setdiff(colnames(out), "CDR3.aa"), drop=FALSE])
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
run_clustcr = function() {
|
|
190
|
+
log$info("Running ClusTCR ...")
|
|
191
|
+
clustcr_dir = file.path(outdir, "ClusTCR_Output")
|
|
192
|
+
dir.create(clustcr_dir, showWarnings = FALSE)
|
|
193
|
+
clustcr_file = prepare_clustcr(clustcr_dir)
|
|
194
|
+
clustcr_input = prepare_input()
|
|
195
|
+
clustcr_cmd = paste(
|
|
196
|
+
python,
|
|
197
|
+
clustcr_file,
|
|
198
|
+
clustcr_dir,
|
|
199
|
+
clustcr_input
|
|
200
|
+
)
|
|
201
|
+
print("Running:")
|
|
202
|
+
print(clustcr_cmd)
|
|
203
|
+
log$debug("- Running command: {clustcr_cmd}")
|
|
204
|
+
rc = system(clustcr_cmd)
|
|
205
|
+
if (rc != 0) {
|
|
206
|
+
quit(status=rc)
|
|
207
|
+
}
|
|
208
|
+
clustcr_outfile = file.path(clustcr_dir, "clusters.txt")
|
|
209
|
+
clean_clustcr_output(clustcr_outfile)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
prepare_giana = function() {
|
|
213
|
+
biopipen_dir <- get_biopipen_dir(python)
|
|
214
|
+
giana_srcdir = file.path(biopipen_dir, "scripts", "tcr", "GIANA")
|
|
215
|
+
|
|
216
|
+
# # The source code of GIANA is downloaded now to giana_srcdir
|
|
217
|
+
# giana_file = file.path(giana_srcdir, "GIANA.py")
|
|
218
|
+
# giana4_file = file.path(giana_srcdir, "GIANA4.py")
|
|
219
|
+
# giana_query = file.path(giana_srcdir, "query.py")
|
|
220
|
+
# giana_trbv = file.path(giana_srcdir, "Imgt_Human_TRBV.fasta")
|
|
221
|
+
# if (!file.exists(giana_file)) {
|
|
222
|
+
# download.file(paste(giana_repo, "GIANA4.1.py", sep="/"), giana_file)
|
|
223
|
+
# download.file(paste(giana_repo, "GIANA4.py", sep="/"), giana4_file)
|
|
224
|
+
# download.file(paste(giana_repo, "query.py", sep="/"), giana_query)
|
|
225
|
+
# download.file(paste(giana_repo, "Imgt_Human_TRBV.fasta", sep="/"), giana_trbv)
|
|
226
|
+
# }
|
|
227
|
+
|
|
228
|
+
giana_srcdir
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
prepare_input = function() {
|
|
232
|
+
cdr3aa_df$cdr3seq4clustering <<- gsub("[^A-Z]", "", cdr3aa_df$CDR3.aa) # Remove non-amino acid characters
|
|
233
|
+
cdr3 <- unique(cdr3aa_df$cdr3seq4clustering)
|
|
234
|
+
|
|
235
|
+
# cdr3 = distinct(cdr3, aminoAcid, vMaxResolved)
|
|
236
|
+
|
|
237
|
+
cdr3file = file.path(outdir, "cdr3.csv")
|
|
238
|
+
write.table(
|
|
239
|
+
data.frame(CDR3.aa=cdr3),
|
|
240
|
+
cdr3file,
|
|
241
|
+
row.names=FALSE, col.names=TRUE, quote=FALSE
|
|
242
|
+
)
|
|
243
|
+
cdr3file
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
clean_giana_output = function(giana_outfile) {
|
|
247
|
+
# generate an output file with columns:
|
|
248
|
+
# CDR3.aa, CDR3_Cluster, V.name, Sample
|
|
249
|
+
# If sequence doesn't exist in the input file,
|
|
250
|
+
# Then a unique cluster id is assigned to it.
|
|
251
|
+
giana_out = read.delim2(giana_outfile, header=FALSE, comment.char = "#", row.names = NULL)[, 1:2, drop=FALSE]
|
|
252
|
+
colnames(giana_out) = c("CDR3.aa", "CDR3_Cluster")
|
|
253
|
+
out = left_join(cdr3aa_df, distinct(giana_out), by=c(cdr3seq4clustering = "CDR3.aa")) %>%
|
|
254
|
+
mutate(
|
|
255
|
+
CDR3_Cluster = if_else(
|
|
256
|
+
is.na(CDR3_Cluster),
|
|
257
|
+
paste0("S_", row_number()),
|
|
258
|
+
paste0("M_", as.character(CDR3_Cluster))
|
|
259
|
+
)
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
if (within_sample) {
|
|
263
|
+
out <- mutate(out, CDR3_Cluster = paste0(Sample, ".", CDR3_Cluster))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
# This join would result in more rows than dplyr can handle
|
|
267
|
+
# left_join(cdr3aa_df, out, by = "CDR3.aa")
|
|
268
|
+
out <- out[match(cdr3aa_df$CDR3.aa, out$CDR3.aa), , drop=FALSE]
|
|
269
|
+
cbind(cdr3aa_df, out[, setdiff(colnames(out), "CDR3.aa"), drop=FALSE])
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
run_giana = function() {
|
|
273
|
+
log$info("Running GIANA ...")
|
|
274
|
+
giana_srcdir = prepare_giana()
|
|
275
|
+
giana_input = prepare_input()
|
|
276
|
+
giana_outdir = file.path(outdir, "GIANA_Output")
|
|
277
|
+
dir.create(giana_outdir, showWarnings = FALSE)
|
|
278
|
+
args_str = ""
|
|
279
|
+
for (argname in names(args)) {
|
|
280
|
+
argvalue = args[[argname]]
|
|
281
|
+
if (!startsWith(argname, "-")) {
|
|
282
|
+
if (nchar(argname) == 1) {
|
|
283
|
+
argname = paste0("-", argname)
|
|
284
|
+
} else {
|
|
285
|
+
argname = paste0("--", argname)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (isTRUE(argvalue) || toupper(as.character(argvalue)) == "TRUE") {
|
|
289
|
+
argvalue = ""
|
|
290
|
+
} else {
|
|
291
|
+
argvalue = as.character(argvalue)
|
|
292
|
+
}
|
|
293
|
+
args_str = paste(args_str, argname, argvalue)
|
|
294
|
+
}
|
|
295
|
+
giana_cmd = paste(
|
|
296
|
+
python,
|
|
297
|
+
file.path(giana_srcdir, "GIANA.py"),
|
|
298
|
+
"-f", giana_input,
|
|
299
|
+
"-o", giana_outdir,
|
|
300
|
+
"-v", # TRBV mutation not supported
|
|
301
|
+
args_str
|
|
302
|
+
)
|
|
303
|
+
print("Running:")
|
|
304
|
+
print(giana_cmd)
|
|
305
|
+
log$debug("- Running command: {giana_cmd}")
|
|
306
|
+
rc = system(giana_cmd)
|
|
307
|
+
if (rc != 0) {
|
|
308
|
+
quit(status=rc)
|
|
309
|
+
}
|
|
310
|
+
giana_outfile = file.path(giana_outdir, "cdr3--RotationEncodingBL62.txt")
|
|
311
|
+
clean_giana_output(giana_outfile)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
attach_to_obj = function(obj, out) {
|
|
315
|
+
out <- as.data.frame(out)
|
|
316
|
+
rownames(out) <- out$Barcode
|
|
317
|
+
if (is_seurat) {
|
|
318
|
+
# Attach results to Seurat object
|
|
319
|
+
obj@meta.data$CDR3_Cluster <- out[rownames(obj@meta.data), "CDR3_Cluster"]
|
|
320
|
+
} else {
|
|
321
|
+
# Attach results to the list of data frames
|
|
322
|
+
for (sample in names(obj)) {
|
|
323
|
+
sout <- filter(out, Sample == sample)
|
|
324
|
+
obj[[sample]]$CDR3_Cluster <- sout[obj[[sample]]$barcode, "CDR3_Cluster"]
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
obj
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
if (tolower(tool) == "clustcr") {
|
|
332
|
+
out = run_clustcr()
|
|
333
|
+
} else if (tolower(tool) == "giana") {
|
|
334
|
+
out = run_giana()
|
|
335
|
+
} else {
|
|
336
|
+
stop(paste("Unknown tool:", tool))
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
log$info("Attaching results to the input object ...")
|
|
340
|
+
out <- attach_to_obj(obj, out)
|
|
341
|
+
|
|
342
|
+
log$info("Saving results ...")
|
|
343
|
+
save_obj(out, outfile)
|