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.
Files changed (290) hide show
  1. biopipen/__init__.py +1 -1
  2. biopipen/core/config.toml +28 -0
  3. biopipen/core/filters.py +79 -4
  4. biopipen/core/proc.py +12 -3
  5. biopipen/core/testing.py +75 -3
  6. biopipen/ns/bam.py +148 -6
  7. biopipen/ns/bed.py +75 -0
  8. biopipen/ns/cellranger.py +186 -0
  9. biopipen/ns/cellranger_pipeline.py +126 -0
  10. biopipen/ns/cnv.py +19 -3
  11. biopipen/ns/cnvkit.py +1 -1
  12. biopipen/ns/cnvkit_pipeline.py +20 -12
  13. biopipen/ns/delim.py +34 -35
  14. biopipen/ns/gene.py +68 -23
  15. biopipen/ns/gsea.py +63 -37
  16. biopipen/ns/misc.py +39 -14
  17. biopipen/ns/plot.py +304 -1
  18. biopipen/ns/protein.py +183 -0
  19. biopipen/ns/regulatory.py +290 -0
  20. biopipen/ns/rnaseq.py +142 -5
  21. biopipen/ns/scrna.py +2053 -473
  22. biopipen/ns/scrna_metabolic_landscape.py +228 -382
  23. biopipen/ns/snp.py +659 -0
  24. biopipen/ns/stats.py +484 -0
  25. biopipen/ns/tcr.py +683 -98
  26. biopipen/ns/vcf.py +236 -2
  27. biopipen/ns/web.py +97 -6
  28. biopipen/reports/bam/CNVpytor.svelte +4 -9
  29. biopipen/reports/cellranger/CellRangerCount.svelte +18 -0
  30. biopipen/reports/cellranger/CellRangerSummary.svelte +16 -0
  31. biopipen/reports/cellranger/CellRangerVdj.svelte +18 -0
  32. biopipen/reports/cnvkit/CNVkitDiagram.svelte +1 -1
  33. biopipen/reports/cnvkit/CNVkitHeatmap.svelte +1 -1
  34. biopipen/reports/cnvkit/CNVkitScatter.svelte +1 -1
  35. biopipen/reports/common.svelte +15 -0
  36. biopipen/reports/protein/ProdigySummary.svelte +16 -0
  37. biopipen/reports/scrna/CellsDistribution.svelte +4 -39
  38. biopipen/reports/scrna/DimPlots.svelte +1 -1
  39. biopipen/reports/scrna/MarkersFinder.svelte +6 -126
  40. biopipen/reports/scrna/MetaMarkers.svelte +3 -75
  41. biopipen/reports/scrna/RadarPlots.svelte +4 -20
  42. biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +61 -22
  43. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +88 -82
  44. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +70 -10
  45. biopipen/reports/snp/PlinkCallRate.svelte +24 -0
  46. biopipen/reports/snp/PlinkFreq.svelte +18 -0
  47. biopipen/reports/snp/PlinkHWE.svelte +18 -0
  48. biopipen/reports/snp/PlinkHet.svelte +18 -0
  49. biopipen/reports/snp/PlinkIBD.svelte +18 -0
  50. biopipen/reports/tcr/CDR3AAPhyschem.svelte +19 -66
  51. biopipen/reports/tcr/ClonalStats.svelte +16 -0
  52. biopipen/reports/tcr/CloneResidency.svelte +3 -93
  53. biopipen/reports/tcr/Immunarch.svelte +4 -155
  54. biopipen/reports/tcr/TCRClusterStats.svelte +3 -45
  55. biopipen/reports/tcr/TESSA.svelte +11 -28
  56. biopipen/reports/utils/misc.liq +22 -7
  57. biopipen/scripts/bam/BamMerge.py +11 -15
  58. biopipen/scripts/bam/BamSampling.py +90 -0
  59. biopipen/scripts/bam/BamSort.py +141 -0
  60. biopipen/scripts/bam/BamSplitChroms.py +10 -10
  61. biopipen/scripts/bam/BamSubsetByBed.py +38 -0
  62. biopipen/scripts/bam/CNAClinic.R +41 -5
  63. biopipen/scripts/bam/CNVpytor.py +153 -54
  64. biopipen/scripts/bam/ControlFREEC.py +13 -14
  65. biopipen/scripts/bam/SamtoolsView.py +33 -0
  66. biopipen/scripts/bed/Bed2Vcf.py +5 -5
  67. biopipen/scripts/bed/BedConsensus.py +5 -5
  68. biopipen/scripts/bed/BedLiftOver.sh +6 -4
  69. biopipen/scripts/bed/BedtoolsIntersect.py +54 -0
  70. biopipen/scripts/bed/BedtoolsMakeWindows.py +47 -0
  71. biopipen/scripts/bed/BedtoolsMerge.py +4 -4
  72. biopipen/scripts/cellranger/CellRangerCount.py +138 -0
  73. biopipen/scripts/cellranger/CellRangerSummary.R +181 -0
  74. biopipen/scripts/cellranger/CellRangerVdj.py +112 -0
  75. biopipen/scripts/cnv/AneuploidyScore.R +55 -20
  76. biopipen/scripts/cnv/AneuploidyScoreSummary.R +221 -163
  77. biopipen/scripts/cnv/TMADScore.R +25 -9
  78. biopipen/scripts/cnv/TMADScoreSummary.R +57 -86
  79. biopipen/scripts/cnvkit/CNVkitAccess.py +7 -6
  80. biopipen/scripts/cnvkit/CNVkitAutobin.py +26 -18
  81. biopipen/scripts/cnvkit/CNVkitBatch.py +6 -6
  82. biopipen/scripts/cnvkit/CNVkitCall.py +3 -3
  83. biopipen/scripts/cnvkit/CNVkitCoverage.py +4 -3
  84. biopipen/scripts/cnvkit/CNVkitDiagram.py +5 -5
  85. biopipen/scripts/cnvkit/CNVkitFix.py +3 -3
  86. biopipen/scripts/cnvkit/CNVkitGuessBaits.py +12 -8
  87. biopipen/scripts/cnvkit/CNVkitHeatmap.py +5 -5
  88. biopipen/scripts/cnvkit/CNVkitReference.py +6 -5
  89. biopipen/scripts/cnvkit/CNVkitScatter.py +5 -5
  90. biopipen/scripts/cnvkit/CNVkitSegment.py +5 -5
  91. biopipen/scripts/cnvkit/guess_baits.py +166 -93
  92. biopipen/scripts/delim/RowsBinder.R +1 -1
  93. biopipen/scripts/delim/SampleInfo.R +116 -118
  94. biopipen/scripts/gene/GeneNameConversion.R +67 -0
  95. biopipen/scripts/gene/GenePromoters.R +61 -0
  96. biopipen/scripts/gsea/Enrichr.R +5 -5
  97. biopipen/scripts/gsea/FGSEA.R +184 -50
  98. biopipen/scripts/gsea/GSEA.R +2 -2
  99. biopipen/scripts/gsea/PreRank.R +5 -5
  100. biopipen/scripts/misc/Config2File.py +2 -2
  101. biopipen/scripts/misc/Plot.R +80 -0
  102. biopipen/scripts/misc/Shell.sh +15 -0
  103. biopipen/scripts/misc/Str2File.py +2 -2
  104. biopipen/scripts/plot/Heatmap.R +3 -3
  105. biopipen/scripts/plot/Manhattan.R +147 -0
  106. biopipen/scripts/plot/QQPlot.R +146 -0
  107. biopipen/scripts/plot/ROC.R +88 -0
  108. biopipen/scripts/plot/Scatter.R +112 -0
  109. biopipen/scripts/plot/VennDiagram.R +5 -9
  110. biopipen/scripts/protein/MMCIF2PDB.py +33 -0
  111. biopipen/scripts/protein/PDB2Fasta.py +60 -0
  112. biopipen/scripts/protein/Prodigy.py +119 -0
  113. biopipen/scripts/protein/ProdigySummary.R +140 -0
  114. biopipen/scripts/protein/RMSD.py +178 -0
  115. biopipen/scripts/regulatory/MotifAffinityTest.R +102 -0
  116. biopipen/scripts/regulatory/MotifAffinityTest_AtSNP.R +127 -0
  117. biopipen/scripts/regulatory/MotifAffinityTest_MotifBreakR.R +104 -0
  118. biopipen/scripts/regulatory/MotifScan.py +159 -0
  119. biopipen/scripts/regulatory/VariantMotifPlot.R +78 -0
  120. biopipen/scripts/regulatory/motifs-common.R +324 -0
  121. biopipen/scripts/rnaseq/Simulation-ESCO.R +180 -0
  122. biopipen/scripts/rnaseq/Simulation-RUVcorr.R +45 -0
  123. biopipen/scripts/rnaseq/Simulation.R +21 -0
  124. biopipen/scripts/rnaseq/UnitConversion.R +325 -54
  125. biopipen/scripts/scrna/AnnData2Seurat.R +40 -0
  126. biopipen/scripts/scrna/CCPlotR-patch.R +161 -0
  127. biopipen/scripts/scrna/CellCellCommunication.py +150 -0
  128. biopipen/scripts/scrna/CellCellCommunicationPlots.R +93 -0
  129. biopipen/scripts/scrna/CellSNPLite.py +30 -0
  130. biopipen/scripts/scrna/CellTypeAnnotation-celltypist.R +185 -0
  131. biopipen/scripts/scrna/CellTypeAnnotation-direct.R +68 -31
  132. biopipen/scripts/scrna/CellTypeAnnotation-hitype.R +27 -22
  133. biopipen/scripts/scrna/CellTypeAnnotation-sccatch.R +28 -20
  134. biopipen/scripts/scrna/CellTypeAnnotation-sctype.R +48 -25
  135. biopipen/scripts/scrna/CellTypeAnnotation.R +37 -1
  136. biopipen/scripts/scrna/CellsDistribution.R +456 -167
  137. biopipen/scripts/scrna/DimPlots.R +1 -1
  138. biopipen/scripts/scrna/ExprImputation-alra.R +109 -0
  139. biopipen/scripts/scrna/ExprImputation-rmagic.R +256 -0
  140. biopipen/scripts/scrna/{ExprImpution-scimpute.R → ExprImputation-scimpute.R} +8 -5
  141. biopipen/scripts/scrna/ExprImputation.R +7 -0
  142. biopipen/scripts/scrna/LoomTo10X.R +51 -0
  143. biopipen/scripts/scrna/MQuad.py +25 -0
  144. biopipen/scripts/scrna/MarkersFinder.R +679 -400
  145. biopipen/scripts/scrna/MetaMarkers.R +265 -161
  146. biopipen/scripts/scrna/ModuleScoreCalculator.R +66 -11
  147. biopipen/scripts/scrna/PseudoBulkDEG.R +678 -0
  148. biopipen/scripts/scrna/RadarPlots.R +355 -134
  149. biopipen/scripts/scrna/ScFGSEA.R +298 -100
  150. biopipen/scripts/scrna/ScSimulation.R +65 -0
  151. biopipen/scripts/scrna/ScVelo.py +617 -0
  152. biopipen/scripts/scrna/Seurat2AnnData.R +7 -0
  153. biopipen/scripts/scrna/SeuratClusterStats-clustree.R +87 -0
  154. biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +36 -30
  155. biopipen/scripts/scrna/SeuratClusterStats-features.R +138 -187
  156. biopipen/scripts/scrna/SeuratClusterStats-ngenes.R +81 -0
  157. biopipen/scripts/scrna/SeuratClusterStats-stats.R +78 -89
  158. biopipen/scripts/scrna/SeuratClusterStats.R +47 -10
  159. biopipen/scripts/scrna/SeuratClustering.R +36 -233
  160. biopipen/scripts/scrna/SeuratLoading.R +2 -2
  161. biopipen/scripts/scrna/SeuratMap2Ref.R +84 -113
  162. biopipen/scripts/scrna/SeuratMetadataMutater.R +16 -6
  163. biopipen/scripts/scrna/SeuratPreparing.R +223 -173
  164. biopipen/scripts/scrna/SeuratSubClustering.R +64 -0
  165. biopipen/scripts/scrna/SeuratTo10X.R +27 -0
  166. biopipen/scripts/scrna/Slingshot.R +65 -0
  167. biopipen/scripts/scrna/Subset10X.R +2 -2
  168. biopipen/scripts/scrna/TopExpressingGenes.R +169 -135
  169. biopipen/scripts/scrna/celltypist-wrapper.py +195 -0
  170. biopipen/scripts/scrna/scvelo_paga.py +313 -0
  171. biopipen/scripts/scrna/seurat_anndata_conversion.py +98 -0
  172. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +447 -82
  173. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +348 -241
  174. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +188 -166
  175. biopipen/scripts/snp/MatrixEQTL.R +217 -0
  176. biopipen/scripts/snp/Plink2GTMat.py +148 -0
  177. biopipen/scripts/snp/PlinkCallRate.R +199 -0
  178. biopipen/scripts/snp/PlinkFilter.py +100 -0
  179. biopipen/scripts/snp/PlinkFreq.R +291 -0
  180. biopipen/scripts/snp/PlinkFromVcf.py +81 -0
  181. biopipen/scripts/snp/PlinkHWE.R +85 -0
  182. biopipen/scripts/snp/PlinkHet.R +96 -0
  183. biopipen/scripts/snp/PlinkIBD.R +196 -0
  184. biopipen/scripts/snp/PlinkSimulation.py +124 -0
  185. biopipen/scripts/snp/PlinkUpdateName.py +124 -0
  186. biopipen/scripts/stats/ChowTest.R +146 -0
  187. biopipen/scripts/stats/DiffCoexpr.R +152 -0
  188. biopipen/scripts/stats/LiquidAssoc.R +135 -0
  189. biopipen/scripts/stats/Mediation.R +108 -0
  190. biopipen/scripts/stats/MetaPvalue.R +130 -0
  191. biopipen/scripts/stats/MetaPvalue1.R +74 -0
  192. biopipen/scripts/tcgamaf/Maf2Vcf.py +2 -2
  193. biopipen/scripts/tcgamaf/MafAddChr.py +2 -2
  194. biopipen/scripts/tcr/Attach2Seurat.R +3 -2
  195. biopipen/scripts/tcr/CDR3AAPhyschem.R +211 -143
  196. biopipen/scripts/tcr/CDR3Clustering.R +343 -0
  197. biopipen/scripts/tcr/ClonalStats.R +526 -0
  198. biopipen/scripts/tcr/CloneResidency.R +255 -131
  199. biopipen/scripts/tcr/CloneSizeQQPlot.R +4 -4
  200. biopipen/scripts/tcr/GIANA/GIANA.py +1356 -797
  201. biopipen/scripts/tcr/GIANA/GIANA4.py +1362 -789
  202. biopipen/scripts/tcr/GIANA/query.py +164 -162
  203. biopipen/scripts/tcr/Immunarch-basic.R +31 -9
  204. biopipen/scripts/tcr/Immunarch-clonality.R +25 -5
  205. biopipen/scripts/tcr/Immunarch-diversity.R +352 -134
  206. biopipen/scripts/tcr/Immunarch-geneusage.R +45 -5
  207. biopipen/scripts/tcr/Immunarch-kmer.R +68 -8
  208. biopipen/scripts/tcr/Immunarch-overlap.R +84 -4
  209. biopipen/scripts/tcr/Immunarch-spectratyping.R +35 -6
  210. biopipen/scripts/tcr/Immunarch-tracking.R +38 -6
  211. biopipen/scripts/tcr/Immunarch-vjjunc.R +165 -0
  212. biopipen/scripts/tcr/Immunarch.R +63 -11
  213. biopipen/scripts/tcr/Immunarch2VDJtools.R +2 -2
  214. biopipen/scripts/tcr/ImmunarchFilter.R +4 -4
  215. biopipen/scripts/tcr/ImmunarchLoading.R +38 -29
  216. biopipen/scripts/tcr/SampleDiversity.R +1 -1
  217. biopipen/scripts/tcr/ScRepCombiningExpression.R +40 -0
  218. biopipen/scripts/tcr/ScRepLoading.R +166 -0
  219. biopipen/scripts/tcr/TCRClusterStats.R +176 -22
  220. biopipen/scripts/tcr/TCRDock.py +110 -0
  221. biopipen/scripts/tcr/TESSA.R +102 -118
  222. biopipen/scripts/tcr/VJUsage.R +5 -5
  223. biopipen/scripts/tcr/immunarch-patched.R +142 -0
  224. biopipen/scripts/tcr/vdjtools-patch.sh +1 -1
  225. biopipen/scripts/vcf/BcftoolsAnnotate.py +91 -0
  226. biopipen/scripts/vcf/BcftoolsFilter.py +90 -0
  227. biopipen/scripts/vcf/BcftoolsMerge.py +31 -0
  228. biopipen/scripts/vcf/BcftoolsSort.py +113 -0
  229. biopipen/scripts/vcf/BcftoolsView.py +73 -0
  230. biopipen/scripts/vcf/TruvariBench.sh +14 -7
  231. biopipen/scripts/vcf/TruvariBenchSummary.R +16 -13
  232. biopipen/scripts/vcf/TruvariConsistency.R +1 -1
  233. biopipen/scripts/vcf/Vcf2Bed.py +2 -2
  234. biopipen/scripts/vcf/VcfAnno.py +11 -11
  235. biopipen/scripts/vcf/VcfDownSample.sh +22 -10
  236. biopipen/scripts/vcf/VcfFilter.py +5 -5
  237. biopipen/scripts/vcf/VcfFix.py +7 -7
  238. biopipen/scripts/vcf/VcfFix_utils.py +13 -4
  239. biopipen/scripts/vcf/VcfIndex.py +3 -3
  240. biopipen/scripts/vcf/VcfIntersect.py +3 -3
  241. biopipen/scripts/vcf/VcfLiftOver.sh +5 -0
  242. biopipen/scripts/vcf/VcfSplitSamples.py +4 -4
  243. biopipen/scripts/vcf/bcftools_utils.py +52 -0
  244. biopipen/scripts/web/Download.py +8 -4
  245. biopipen/scripts/web/DownloadList.py +5 -5
  246. biopipen/scripts/web/GCloudStorageDownloadBucket.py +82 -0
  247. biopipen/scripts/web/GCloudStorageDownloadFile.py +23 -0
  248. biopipen/scripts/web/gcloud_common.py +49 -0
  249. biopipen/utils/gene.py +108 -60
  250. biopipen/utils/misc.py +146 -20
  251. biopipen/utils/reference.py +64 -20
  252. biopipen/utils/reporter.py +177 -0
  253. biopipen/utils/vcf.py +1 -1
  254. biopipen-0.34.26.dist-info/METADATA +27 -0
  255. biopipen-0.34.26.dist-info/RECORD +292 -0
  256. {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/WHEEL +1 -1
  257. {biopipen-0.21.0.dist-info → biopipen-0.34.26.dist-info}/entry_points.txt +6 -2
  258. biopipen/ns/bcftools.py +0 -111
  259. biopipen/ns/scrna_basic.py +0 -255
  260. biopipen/reports/delim/SampleInfo.svelte +0 -36
  261. biopipen/reports/scrna/GeneExpressionInvistigation.svelte +0 -32
  262. biopipen/reports/scrna/ScFGSEA.svelte +0 -35
  263. biopipen/reports/scrna/SeuratClusterStats.svelte +0 -82
  264. biopipen/reports/scrna/SeuratMap2Ref.svelte +0 -20
  265. biopipen/reports/scrna/SeuratPreparing.svelte +0 -38
  266. biopipen/reports/scrna/TopExpressingGenes.svelte +0 -55
  267. biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +0 -31
  268. biopipen/reports/utils/gsea.liq +0 -110
  269. biopipen/scripts/bcftools/BcftoolsAnnotate.py +0 -42
  270. biopipen/scripts/bcftools/BcftoolsFilter.py +0 -79
  271. biopipen/scripts/bcftools/BcftoolsSort.py +0 -19
  272. biopipen/scripts/gene/GeneNameConversion.py +0 -66
  273. biopipen/scripts/scrna/ExprImpution-alra.R +0 -32
  274. biopipen/scripts/scrna/ExprImpution-rmagic.R +0 -29
  275. biopipen/scripts/scrna/ExprImpution.R +0 -7
  276. biopipen/scripts/scrna/GeneExpressionInvistigation.R +0 -132
  277. biopipen/scripts/scrna/Write10X.R +0 -11
  278. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +0 -150
  279. biopipen/scripts/tcr/TCRClustering.R +0 -280
  280. biopipen/utils/common_docstrs.py +0 -61
  281. biopipen/utils/gene.R +0 -49
  282. biopipen/utils/gsea.R +0 -193
  283. biopipen/utils/io.R +0 -20
  284. biopipen/utils/misc.R +0 -114
  285. biopipen/utils/mutate_helpers.R +0 -433
  286. biopipen/utils/plot.R +0 -173
  287. biopipen/utils/rnaseq.R +0 -48
  288. biopipen/utils/single_cell.R +0 -115
  289. biopipen-0.21.0.dist-info/METADATA +0 -22
  290. biopipen-0.21.0.dist-info/RECORD +0 -218
@@ -1,5 +1,5 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/single_cell.R")
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
- if (endsWith(metafile, ".rds") || endsWith(metafile, ".RDS")) {
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-basic.R" %}
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-clonality.R" %}
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-overlap.R" %}
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-geneusage.R" %}
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-spectratyping.R" %}
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-diversity.R" %}
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-tracking.R" %}
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
- {% include biopipen_dir + "/scripts/tcr/Immunarch-kmer.R" %}
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)
@@ -3,8 +3,8 @@ library(dplyr)
3
3
  library(tidyr)
4
4
  library(stringr)
5
5
 
6
- immfile = {{in.immdata | quote}}
7
- outdir = {{out.outdir | quote}}
6
+ immfile = {{in.immdata | r}}
7
+ outdir = {{out.outdir | r}}
8
8
 
9
9
  immdata = readRDS(immfile)
10
10
 
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
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 | quote}}
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 | quote}}
17
- groupfile = {{out.groupfile | quote}}
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
- source("{{biopipen_dir}}/utils/misc.R")
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 | quote }}
12
- rdsfile = {{ out.rdsfile | quote }}
13
- metatxt = {{ out.metatxt | quote }}
14
- tmpdir = {{ envs.tmpdir | quote }}
15
- mode = {{ envs.mode | quote }}
16
- metacols = {{ envs.metacols | r}}
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
- metadf = do_call(rbind, lapply(seq_len(nrow(immdata$meta)), function(i) {
170
- # Clones Proportion CDR3.aa Barcode
171
- # 5 4 0.008583691 CAVRDTGNTPLVF;CASSEYSNQPQHF GTTCGGGCACTTACGA-1;TCTCTAAGTACCAGTT-1
172
- # 6 4 0.008583691 CALTQAAGNKLTF;CASRPEDLRGQPQHF GCTTGAAGTCGGCACT-1;TACTCGCTCCTAAGTG-1
173
- cldata = immdata$data[[i]][, unique(c(metacols, "Barcode"))]
174
- # # A tibble: 4 × 5
175
- # Sample Patient Timepoint Tissue
176
- # <chr> <chr> <chr> <chr>
177
- # 1 MC1685Pt011-Baseline-PB MC1685Pt011 Baseline PB
178
- mdata = as.list(immdata$meta[i, , drop=FALSE])
179
- for (mname in names(mdata)) {
180
- assign(mname, mdata[[mname]])
181
- }
182
-
183
- cldata %>%
184
- separate_rows(Barcode, sep=";") %>%
185
- distinct(Barcode, .keep_all = TRUE) %>%
186
- mutate(Barcode = glue("{{envs.prefix}}{Barcode}")) %>%
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)
@@ -1,4 +1,4 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
1
+ {{ biopipen_dir | joinpaths: "utils", "misc.R" | source_r }}
2
2
  library(immunarch)
3
3
 
4
4
  immdatafile = {{in.immdata | r}}
@@ -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)