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,147 +1,172 @@
1
- source("{{biopipen_dir}}/utils/misc.R")
2
- source("{{biopipen_dir}}/utils/plot.R")
3
-
4
- library(ggplot2)
5
- library(ggprism)
6
1
  library(dplyr)
7
2
  library(tidyr)
8
3
  library(tibble)
9
- library(patchwork)
4
+ library(plotthis)
5
+ library(biopipen.utils)
10
6
 
11
- asdirs = {{in.asdirs | r}}
12
- metafile = {{in.metafile | r}}
13
- outdir = {{out.outdir | r}}
14
- group_cols = {{envs.group_cols | r}}
15
- sample_name_fun = {{envs.sample_name | r}}
16
- heatmap_cases = {{envs.heatmap_cases | r}}
7
+ asdirs <- {{in.asdirs | r}}
8
+ metafile <- {{in.metafile | r}}
9
+ outdir <- {{out.outdir | r}}
10
+ group_cols <- {{envs.group_cols | r}}
11
+ sample_name_fun <- {{envs.sample_name | r}}
12
+ heatmap_cases <- {{envs.heatmap_cases | r}}
17
13
 
18
14
  if (!is.null(sample_name_fun)) {
19
- sample_name_fun = eval(parse(text=sample_name_fun))
15
+ sample_name_fun <- eval(parse(text = sample_name_fun))
20
16
  }
21
17
 
22
- get_sample_from_asdir = function(asdir) {
23
- x = basename(asdir)
18
+ get_sample_from_asdir <- function(asdir) {
19
+ x <- basename(asdir)
24
20
  if (endsWith(x, ".aneuploidy_score")) {
25
- x = substr(x, 1, nchar(x) - 17)
21
+ x <- substr(x, 1, nchar(x) - 17)
26
22
  }
27
23
  if (endsWith(x, ".call")) {
28
- x = substr(x, 1, nchar(x) - 5)
24
+ x <- substr(x, 1, nchar(x) - 5)
29
25
  }
30
26
  if (!is.null(sample_name_fun)) {
31
- x = sample_name_fun(x)
27
+ x <- sample_name_fun(x)
32
28
  }
33
29
  x
34
30
  }
35
31
 
36
- sams = sapply(asdirs, get_sample_from_asdir)
32
+ asdir_to_sample <- lapply(asdirs, get_sample_from_asdir)
33
+ names(asdir_to_sample) <- asdirs
34
+ table_sams <- table(unlist(asdir_to_sample))
35
+ if (any(table_sams > 1)) {
36
+ log_warn("Duplicate sample names found in asdirs: ")
37
+ dup_sams <- names(table_sams[table_sams > 1])
38
+ for (dup_sam in dup_sams) {
39
+ i <- 1
40
+ for (asdir in asdirs) {
41
+ if (asdir_to_sample[[asdir]] == dup_sam) {
42
+ dedup_sam <- paste0(dup_sam, "_", i)
43
+ log_warn(paste0("- Changing ", dup_sam, "(", asdir, ") to ", dedup_sam))
44
+ asdir_to_sample[[asdir]] <- paste0(dup_sam, "_", i)
45
+ i <- i + 1
46
+ }
47
+ }
48
+ }
49
+ }
50
+ sams <- unlist(asdir_to_sample)
37
51
 
38
- meta_cols = c()
52
+ meta_cols <- c()
39
53
  if (!is.null(group_cols)) {
40
54
  for (group_col in group_cols) {
41
55
  if (grepl(",", group_col, fixed = TRUE)) {
42
- subcols = strsplit(group_col, ",")[[1]]
56
+ subcols <- strsplit(group_col, ",")[[1]]
43
57
  if (length(subcols) > 2) {
44
58
  stop("Only support 2 columns combined for group_cols")
45
59
  }
46
- meta_cols = union(meta_cols, subcols)
60
+ meta_cols <- union(meta_cols, subcols)
47
61
  } else {
48
- meta_cols = union(meta_cols, group_col)
62
+ meta_cols <- union(meta_cols, group_col)
49
63
  }
50
64
  }
51
65
  }
52
66
 
53
67
  if (!is.null(metafile)) {
54
- metadf = read.table(metafile, header=T, row.names=NULL, sep="\t", stringsAsFactors=F)
55
- sample_col = colnames(metadf)[1]
56
- colnames(metadf)[1] = "Sample"
57
- metadf = metadf[metadf$Sample %in% sams, c("Sample", meta_cols), drop=FALSE]
68
+ metadf <- read.table(metafile, header=T, row.names=NULL, sep="\t", stringsAsFactors=F)
69
+ if (!is.null(metadf$Sample)) {
70
+ metadf$Sample <- as.character(metadf$Sample)
71
+ } else {
72
+ colnames(metadf)[1] <- "Sample"
73
+ }
74
+ metadf <- metadf[metadf$Sample %in% sams, c("Sample", meta_cols), drop=FALSE]
75
+ rownames(metadf) <- metadf$Sample
58
76
  if (nrow(metadf) != length(sams)) {
59
77
  stop(paste("Not all samples in metafile:", paste(setdiff(sams, metadf$Sample), collapse=", ")))
60
78
  }
61
79
  } else {
62
- metadf = NULL
80
+ metadf <- NULL
63
81
  if (!is.null(group_cols) && length(group_cols) > 0) {
64
82
  stop("`envs.group_cols` given but no metafile provided")
65
83
  }
66
84
  }
67
85
 
68
-
69
-
70
- read_caa = function(asdir) {
86
+ read_caa <- function(asdir) {
71
87
  # Sample Arms arm seg
72
- sample = get_sample_from_asdir(asdir)
73
- caa = read.table(
88
+ sample <- asdir_to_sample[[asdir]]
89
+ caa <- read.table(
74
90
  file.path(asdir, "CAA.txt"),
75
91
  header=T,
76
92
  row.names=NULL,
77
93
  sep="\t",
78
94
  stringsAsFactors=F,
79
95
  )
80
- caa$Sample = sample
96
+ caa$Sample <- sample
81
97
  caa
82
98
  }
83
99
 
84
- read_as = function(asdir) {
100
+ read_as <- function(asdir) {
85
101
  # Sample SignalType Signal
86
- sample = get_sample_from_asdir(asdir)
87
- as = read.table(
102
+ sample <- asdir_to_sample[[asdir]]
103
+ as <- read.table(
88
104
  file.path(asdir, "AS.txt"),
89
105
  header=F,
90
106
  row.names=NULL,
91
107
  sep="\t",
92
108
  stringsAsFactors=F,
93
109
  )
94
- colnames(as) = c("SignalType", "Signal")
95
- as$Sample = sample
110
+ colnames(as) <- c("SignalType", "Signal")
111
+ as$Sample <- sample
96
112
  as
97
113
  }
98
114
 
99
115
  # Sample Arms arm seg
100
- caa = do_call(rbind, lapply(asdirs, read_caa))
116
+ caa <- do_call(rbind, lapply(asdirs, read_caa))
101
117
  # Sample SignalType Signal
102
- as = do_call(rbind, lapply(asdirs, read_as))
118
+ as <- do_call(rbind, lapply(asdirs, read_as))
103
119
 
104
120
  # Sample chr1_p chr1_q chr2_p chr2_q ...
105
- caa_arm = caa %>%
121
+ caa_arm <- caa %>%
106
122
  select(-"seg") %>%
107
123
  pivot_wider(names_from="Arms", values_from="arm")
108
124
 
109
125
  # Sample chr1_p chr1_q chr2_p chr2_q ...
110
- caa_seg = caa %>%
126
+ caa_seg <- caa %>%
111
127
  select(-"arm") %>%
112
128
  pivot_wider(names_from="Arms", values_from="seg")
113
129
 
114
130
  # Sample SignalType Signal
115
- as_arm = as %>% filter(SignalType == "arm") %>% select(-"SignalType")
116
- as_seg = as %>% filter(SignalType == "seg") %>% select(-"SignalType")
131
+ as_arm <- as %>% filter(SignalType == "arm") %>% select(-"SignalType")
132
+ as_seg <- as %>% filter(SignalType == "seg") %>% select(-"SignalType")
117
133
 
118
134
  if (!is.null(metadf)) {
119
- caa_arm = caa_arm %>% left_join(metadf, by="Sample")
120
- caa_seg = caa_seg %>% left_join(metadf, by="Sample")
121
- as_arm = as_arm %>% left_join(metadf, by="Sample")
122
- as_seg = as_seg %>% left_join(metadf, by="Sample")
135
+ caa_arm <- caa_arm %>% left_join(metadf, by="Sample")
136
+ caa_seg <- caa_seg %>% left_join(metadf, by="Sample")
137
+ as_arm <- as_arm %>% left_join(metadf, by="Sample")
138
+ as_seg <- as_seg %>% left_join(metadf, by="Sample")
123
139
  }
124
140
 
125
-
126
141
  write.table(caa_arm, file.path(outdir, "CAA_arm.txt"), sep="\t", quote=F, row.names=F, col.names=T)
127
142
  write.table(caa_seg, file.path(outdir, "CAA_seg.txt"), sep="\t", quote=F, row.names=F, col.names=T)
128
143
  write.table(as_arm, file.path(outdir, "AS_arm.txt"), sep="\t", quote=F, row.names=F, col.names=T)
129
144
  write.table(as_seg, file.path(outdir, "AS_seg.txt"), sep="\t", quote=F, row.names=F, col.names=T)
130
145
 
131
146
  # Plot AS without grouping
132
- p_as_arm = ggplot(as_arm) +
133
- geom_bar(aes(x=Sample, y=Signal), stat="identity") +
134
- theme_prism() +
135
- theme(axis.text.x = element_text(angle = 90, hjust = 1))
147
+ p_as_arm <- BarPlot(
148
+ as_arm,
149
+ x="Sample",
150
+ y="Signal",
151
+ title="Aneuploidy Score (Arm)",
152
+ xlab="Sample",
153
+ ylab="Aneuploidy Score",
154
+ x_text_angle = 90
155
+ )
136
156
 
137
157
  png(file.path(outdir, "AS_arm.png"), width=400 + nrow(caa_arm) * 12, height=600, res=100)
138
158
  print(p_as_arm)
139
159
  dev.off()
140
160
 
141
- p_as_seg = ggplot(as_seg) +
142
- geom_bar(aes(x=Sample, y=Signal), stat="identity") +
143
- theme_prism() +
144
- theme(axis.text.x = element_text(angle = 90, hjust = 1))
161
+ p_as_seg <- BarPlot(
162
+ as_seg,
163
+ x="Sample",
164
+ y="Signal",
165
+ title="Aneuploidy Score (Segment)",
166
+ xlab="Sample",
167
+ ylab="Aneuploidy Score",
168
+ x_text_angle = 90
169
+ )
145
170
 
146
171
  png(file.path(outdir, "AS_seg.png"), width=400 + nrow(caa_seg) * 12, height=600, res=100)
147
172
  print(p_as_seg)
@@ -151,49 +176,70 @@ dev.off()
151
176
  if (!is.null(group_cols)) {
152
177
  for (group_col in group_cols) {
153
178
  if (!grepl(",", group_col, fixed = TRUE)) {
154
- # Single layer with group_col
155
- p_as_arm_bar_group = ggplot(
156
- as_arm %>% arrange(!!sym(group_col)) %>% mutate(Sample=factor(Sample, levels=Sample))
157
- ) +
158
- geom_bar(aes(x=Sample, y=Signal, fill=!!sym(group_col)), stat="identity") +
159
- theme_prism() +
160
- theme(axis.text.x = element_text(angle = 90, hjust = 1))
179
+
180
+ p_as_arm_bar_group <- BarPlot(
181
+ as_arm,
182
+ x="Sample",
183
+ y="Signal",
184
+ fill=group_col,
185
+ title=paste0("Aneuploidy Score (Arm) - ", group_col),
186
+ xlab="Sample",
187
+ ylab="Aneuploidy Score",
188
+ x_text_angle = 90
189
+ )
161
190
 
162
191
  png(file.path(outdir, paste0("AS_arm_bar_", group_col, ".png")), width=400 + nrow(caa_arm) * 12, height=600, res=100)
163
192
  print(p_as_arm_bar_group)
164
193
  dev.off()
165
194
 
166
- p_as_seg_bar_group = ggplot(
167
- as_seg %>% arrange(!!sym(group_col)) %>% mutate(Sample=factor(Sample, levels=Sample))
168
- ) +
169
- geom_bar(aes(x=Sample, y=Signal, fill=!!sym(group_col)), stat="identity") +
170
- theme_prism() +
171
- theme(axis.text.x = element_text(angle = 90, hjust = 1))
195
+ p_as_seg_bar_group <- BarPlot(
196
+ as_seg,
197
+ x="Sample",
198
+ y="Signal",
199
+ fill=group_col,
200
+ title=paste0("Aneuploidy Score (Segment) - ", group_col),
201
+ xlab="Sample",
202
+ ylab="Aneuploidy Score",
203
+ x_text_angle = 90
204
+ )
172
205
 
173
206
  png(file.path(outdir, paste0("AS_seg_bar_", group_col, ".png")), width=400 + nrow(caa_seg) * 12, height=600, res=100)
174
207
  print(p_as_seg_bar_group)
175
208
  dev.off()
176
209
 
177
210
  # Voilin + boxplot
178
- p_as_arm_violin_group = ggplot(
179
- as_arm %>% arrange(!!sym(group_col)) %>% mutate(Sample=factor(Sample, levels=Sample))
180
- ) +
181
- geom_violin(aes(x=!!sym(group_col), y=Signal), fill="steelblue", trim=FALSE) +
182
- geom_boxplot(aes(x=!!sym(group_col), y=Signal), width=0.1, outlier.shape=NA) +
183
- theme_prism() +
184
- theme(axis.text.x = element_text(angle = 90, hjust = 1))
211
+
212
+ p_as_arm_violin_group <- ViolinPlot(
213
+ as_arm,
214
+ x=group_col,
215
+ y="Signal",
216
+ title=paste0("Aneuploidy Score (Arm) - ", group_col),
217
+ xlab=group_col,
218
+ ylab="Aneuploidy Score",
219
+ x_text_angle = 90,
220
+ comparisons = TRUE,
221
+ sig_label = "p.format",
222
+ add_point = TRUE,
223
+ add_box = TRUE
224
+ )
185
225
 
186
226
  png(file.path(outdir, paste0("AS_arm_violin_", group_col, ".png")), width=1000, height=600, res=100)
187
227
  print(p_as_arm_violin_group)
188
228
  dev.off()
189
229
 
190
- p_as_seg_violin_group = ggplot(
191
- as_seg %>% arrange(!!sym(group_col)) %>% mutate(Sample=factor(Sample, levels=Sample))
192
- ) +
193
- geom_violin(aes(x=!!sym(group_col), y=Signal), fill="steelblue", trim=FALSE) +
194
- geom_boxplot(aes(x=!!sym(group_col), y=Signal), width=0.1, outlier.shape=NA) +
195
- theme_prism() +
196
- theme(axis.text.x = element_text(angle = 90, hjust = 1))
230
+ p_as_seg_violin_group <- ViolinPlot(
231
+ as_seg,
232
+ x=group_col,
233
+ y="Signal",
234
+ title=paste0("Aneuploidy Score (Segment) - ", group_col),
235
+ xlab=group_col,
236
+ ylab="Aneuploidy Score",
237
+ x_text_angle = 90,
238
+ comparisons = TRUE,
239
+ sig_label = "p.format",
240
+ add_point = TRUE,
241
+ add_box = TRUE
242
+ )
197
243
 
198
244
  png(file.path(outdir, paste0("AS_seg_violin_", group_col, ".png")), width=1000, height=600, res=100)
199
245
  print(p_as_seg_violin_group)
@@ -201,26 +247,27 @@ if (!is.null(group_cols)) {
201
247
 
202
248
  } else {
203
249
  # Multiple layers with group_col
204
- group_cols = strsplit(group_col, ",")[[1]]
205
- group_col1 = group_cols[1]
206
- group_col2 = group_cols[2]
250
+ group_cols <- strsplit(group_col, ",")[[1]]
251
+ group_col1 <- group_cols[1]
252
+ group_col2 <- group_cols[2]
207
253
 
208
254
  # For each group_col1, plot a barplot with group_col2 as fill, and
209
255
  # concatenate them together using patch work, with ncol=2
210
256
  # calcuate the height and width of the plot based on the number of
211
257
  # groups
212
- ps = as_arm %>%
213
- group_by(!!sym(group_col1)) %>%
214
- group_map(function(.x, .y) {
215
- p = ggplot(.x %>% arrange(!!sym(group_col2)) %>% mutate(Sample=factor(Sample, levels=Sample))) +
216
- geom_bar(aes(x=Sample, y=Signal, fill=!!sym(group_col2)), stat="identity") +
217
- theme_prism() +
218
- theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
219
- ggtitle(.y[[group_col1]][1])
220
- p
221
- })
222
-
223
- p = wrap_plots(ps, ncol=2)
258
+ as_arm <- as_arm %>% arrange(!!sym(group_col1), !!sym(group_col2)) %>% mutate(Sample=factor(Sample, levels=Sample))
259
+ p <- BarPlot(
260
+ as_arm,
261
+ x="Sample",
262
+ y="Signal",
263
+ split_by=group_col1,
264
+ fill=group_col2,
265
+ xlab="Sample",
266
+ ylab="Aneuploidy Score",
267
+ x_text_angle = 90,
268
+ ncol = 2
269
+ )
270
+
224
271
  png(
225
272
  file.path(outdir, paste0("AS_arm_bar_", group_col, ".png")),
226
273
  width=1000,
@@ -230,18 +277,18 @@ if (!is.null(group_cols)) {
230
277
  print(p)
231
278
  dev.off()
232
279
 
233
- ps = as_seg %>%
234
- group_by(!!sym(group_col1)) %>%
235
- group_map(function(.x, .y) {
236
- p = ggplot(.x %>% arrange(!!sym(group_col2)) %>% mutate(Sample=factor(Sample, levels=Sample))) +
237
- geom_bar(aes(x=Sample, y=Signal, fill=!!sym(group_col2)), stat="identity") +
238
- theme_prism() +
239
- theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
240
- ggtitle(.y[[group_col1]][1])
241
- p
242
- })
243
-
244
- p = wrap_plots(ps, ncol=2)
280
+ as_seg <- as_seg %>% arrange(!!sym(group_col1), !!sym(group_col2)) %>% mutate(Sample=factor(Sample, levels=Sample))
281
+ p <- BarPlot(
282
+ as_seg,
283
+ x="Sample",
284
+ y="Signal",
285
+ split_by=group_col1,
286
+ fill=group_col2,
287
+ xlab="Sample",
288
+ ylab="Aneuploidy Score",
289
+ x_text_angle = 90,
290
+ ncol = 2
291
+ )
245
292
  png(
246
293
  file.path(outdir, paste0("AS_seg_bar_", group_col, ".png")),
247
294
  width=1000,
@@ -252,19 +299,21 @@ if (!is.null(group_cols)) {
252
299
  dev.off()
253
300
 
254
301
  # Do the same for Voilin + boxplot
255
- ps = as_arm %>%
256
- group_by(!!sym(group_col1)) %>%
257
- group_map(function(.x, .y) {
258
- p = ggplot(.x %>% arrange(!!sym(group_col2)) %>% mutate(Sample=factor(Sample, levels=Sample))) +
259
- geom_violin(aes(x=!!sym(group_col2), y=Signal), fill="steelblue", trim=FALSE) +
260
- geom_boxplot(aes(x=!!sym(group_col2), y=Signal), width=0.1, outlier.shape=NA) +
261
- theme_prism() +
262
- theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
263
- ggtitle(.y[[group_col1]][1])
264
- p
265
- })
266
-
267
- p = wrap_plots(ps, ncol=2)
302
+ p <- ViolinPlot(
303
+ as_arm,
304
+ x=group_col2,
305
+ y="Signal",
306
+ split_by = group_col1,
307
+ xlab=group_col2,
308
+ ylab="Aneuploidy Score",
309
+ x_text_angle = 90,
310
+ comparisons = TRUE,
311
+ sig_label = "p.format",
312
+ add_point = TRUE,
313
+ add_box = TRUE,
314
+ ncol = 2
315
+ )
316
+
268
317
  png(
269
318
  file.path(outdir, paste0("AS_arm_violin_", group_col, ".png")),
270
319
  width=1000,
@@ -274,19 +323,21 @@ if (!is.null(group_cols)) {
274
323
  print(p)
275
324
  dev.off()
276
325
 
277
- ps = as_seg %>%
278
- group_by(!!sym(group_col1)) %>%
279
- group_map(function(.x, .y) {
280
- p = ggplot(.x %>% arrange(!!sym(group_col2)) %>% mutate(Sample=factor(Sample, levels=Sample))) +
281
- geom_violin(aes(x=!!sym(group_col2), y=Signal), fill="steelblue", trim=FALSE) +
282
- geom_boxplot(aes(x=!!sym(group_col2), y=Signal), width=0.1, outlier.shape=NA) +
283
- theme_prism() +
284
- theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
285
- ggtitle(.y[[group_col1]][1])
286
- p
287
- })
288
-
289
- p = wrap_plots(ps, ncol=2)
326
+ p <- ViolinPlot(
327
+ as_seg,
328
+ x=group_col2,
329
+ y="Signal",
330
+ split_by = group_col1,
331
+ xlab=group_col2,
332
+ ylab="Aneuploidy Score",
333
+ x_text_angle = 90,
334
+ comparisons = TRUE,
335
+ sig_label = "p.format",
336
+ add_point = TRUE,
337
+ add_box = TRUE,
338
+ ncol = 2
339
+ )
340
+
290
341
  png(
291
342
  file.path(outdir, paste0("AS_seg_violin_", group_col, ".png")),
292
343
  width=1000,
@@ -301,39 +352,46 @@ if (!is.null(group_cols)) {
301
352
 
302
353
  # Heatmaps
303
354
  for (heatmap_name in names(heatmap_cases)) {
304
- arms = heatmap_cases[[heatmap_name]]
355
+ arms <- heatmap_cases[[heatmap_name]]
305
356
  if (all(arms != "ALL")) {
306
- caa_df = caa_arm %>% select(Sample, !!meta_cols, !!arms)
357
+ caa_df <- caa_arm %>% select(Sample, !!meta_cols, !!arms)
307
358
  } else {
308
- caa_df = caa_arm
359
+ caa_df <- caa_arm
309
360
  }
310
- caa_df = caa_df %>% column_to_rownames("Sample")
361
+ caa_df <- caa_df %>% column_to_rownames("Sample")
311
362
  if (!is.null(metadf)) {
312
- caa_df = caa_df %>% select(-!!meta_cols)
363
+ caa_df <- caa_df %>% select(-!!meta_cols)
313
364
  }
314
-
315
- width = 300 + 20 * ncol(caa_df) # all arms: 300 + 30 * 46 = 1680
316
- height = 300 + 25 * nrow(caa_df) # 10 samples: 300 + 30 * 10 = 600
317
- args = list(
365
+ caa_df <- caa_df %>%
366
+ rownames_to_column("Sample") %>%
367
+ pivot_longer(cols=-"Sample", names_to="Arms", values_to="Signal") %>%
368
+ pivot_wider(names_from="Sample", values_from="Signal")
369
+
370
+ height <- 300 + 20 * ncol(caa_df) # all arms: 300 + 30 * 46 = 1680
371
+ width <- 300 + 25 * nrow(caa_df) # 10 samples: 300 + 30 * 10 = 600
372
+ # print(caa_df)
373
+ hmp <- Heatmap(
374
+ caa_df,
375
+ rows_data = metadf,
318
376
  name = "CAA",
319
- cluster_columns = FALSE,
377
+ rows_by = setdiff(colnames(caa_df), "Arms"),
378
+ columns_by = "Arms",
320
379
  cluster_rows = FALSE,
380
+ cluster_columns = FALSE,
321
381
  row_names_side = "left",
322
- rect_gp = grid::gpar(col = "#FFFFFF", lwd = 1)
382
+ show_row_names = TRUE,
383
+ show_column_names = TRUE,
384
+ row_annotation = colnames(metadf),
385
+ lower_cutoff = -1,
386
+ upper_cutoff = 1
323
387
  )
324
- if (!is.null(metadf)) {
325
- row_annos = list()
326
- for (meta_col in meta_cols) {
327
- row_annos[[meta_col]] = metadf[[meta_col]]
328
- }
329
- if (length(row_annos) > 0) {
330
- args$right_annotation = do_call(ComplexHeatmap::rowAnnotation, row_annos)
331
- }
332
- }
333
- plotHeatmap(
334
- caa_df,
335
- args = args,
336
- devpars = list(width=width, height=height, res=100),
337
- outfile = file.path(outdir, paste0("Heatmap_", heatmap_name, ".png"))
388
+
389
+ png(
390
+ file.path(outdir, paste0("Heatmap_", heatmap_name, ".png")),
391
+ width=width,
392
+ height=height,
393
+ res=100
338
394
  )
395
+ plot(hmp)
396
+ dev.off()
339
397
  }
@@ -1,21 +1,37 @@
1
1
  library(dplyr)
2
2
 
3
- segfile = {{in.segfile | quote}}
4
- outfile = {{out.outfile | quote}}
5
- chrom_col = {{envs.chrom_col | quote}}
3
+ segfile = {{in.segfile | r}}
4
+ outfile = {{out.outfile | r}}
5
+ chrom_col = {{envs.chrom_col | r}}
6
6
  excl_chroms = {{envs.excl_chroms | r}}
7
- seg_col = {{envs.seg_col | quote}}
7
+ seg_col = {{envs.seg_col | r}}
8
8
  segmean_transform = {{envs.segmean_transform | r}}
9
9
 
10
10
  if (is.character(segmean_transform)) {
11
11
  segmean_transform = eval(parse(text=segmean_transform))
12
12
  } # otherwise NULL
13
13
 
14
- segments = read.table(segfile, header=T, row.names=NULL, sep="\t", stringsAsFactors=F)
15
- seg = data.frame(
16
- chrom = segments[, chrom_col],
17
- log2 = segments[, seg_col]
18
- )
14
+
15
+ if (endsWith(segfile, ".vcf") || endsWith(segfile, ".vcf.gz")) {
16
+ library(VariantAnnotation)
17
+ segments = readVcf(segfile)
18
+ seg = data.frame(
19
+ chrom = as.character(seqnames(segments)),
20
+ log2 = segments@info[[seg_col]]
21
+ )
22
+ } else if (endsWith(segfile, ".bed")) {
23
+ segments = read.table(segfile, header=F, row.names=NULL, sep="\t", stringsAsFactors=F)
24
+ seg = data.frame(
25
+ chrom = segments[, 1],
26
+ log2 = segments[, 5]
27
+ )
28
+ } else {
29
+ segments = read.table(segfile, header=T, row.names=NULL, sep="\t", stringsAsFactors=F)
30
+ seg = data.frame(
31
+ chrom = segments[, chrom_col],
32
+ log2 = segments[, seg_col]
33
+ )
34
+ }
19
35
  rm(segments)
20
36
 
21
37
  if (!is.null(excl_chroms) && length(excl_chroms) > 0) {