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
@@ -5,220 +5,222 @@ import subprocess as sp
5
5
  import pandas as pd
6
6
  from GIANA4 import *
7
7
 
8
- def CreateReference(rFile, outdir='./', Vgene=True, ST=3):
8
+
9
+ def CreateReference(rFile, outdir="./", Vgene=True, ST=3):
9
10
  ## convert input reference file into a python workplace
10
- h=open(rFile)
11
- alines=h.readlines()
12
- ww=alines[0].strip().split('\t')
13
- if not ww[0].startswith('C'):
11
+ h = open(rFile)
12
+ alines = h.readlines()
13
+ ww = alines[0].strip().split("\t")
14
+ if not ww[0].startswith("C"):
14
15
  ## header line
15
- hline=alines[0]
16
- alines=alines[1:]
17
- elif 'CDR3' in ww[0]:
18
- hline=alines[0]
19
- alines=alines[1:]
16
+ hline = alines[0]
17
+ alines = alines[1:]
18
+ elif "CDR3" in ww[0]:
19
+ hline = alines[0]
20
+ alines = alines[1:]
20
21
  else:
21
- hline='CDR3\t'+'\t'.join(['Info'+str(x) for x in range(len(ww)-1)])
22
- seqs=[]
23
- vgs=[]
24
- infoList=[]
25
- count=0
22
+ hline = "CDR3\t" + "\t".join(["Info" + str(x) for x in range(len(ww) - 1)])
23
+ seqs = []
24
+ vgs = []
25
+ infoList = []
26
+ count = 0
26
27
  for ll in alines:
27
- ww=ll.strip().split('\t')
28
- cdr3=ww[0]
29
- if '*' in cdr3:
28
+ ww = ll.strip().split("\t")
29
+ cdr3 = ww[0]
30
+ if "*" in cdr3:
30
31
  continue
31
- if '_' in cdr3:
32
+ if "_" in cdr3:
32
33
  continue
33
34
  seqs.append(ww[0])
34
35
  if Vgene:
35
36
  vgs.append(ww[1])
36
- infoList.append('\t'.join(ww[1:]))
37
+ infoList.append("\t".join(ww[1:]))
37
38
  else:
38
- infoList.append('\t'.join(ww[1:]))
39
- count+=1
40
- LD,VD, ID,SD= BuildLengthDict(seqs, vGene=vgs,INFO=infoList,sIDs=[x for x in range(len(seqs))])
39
+ infoList.append("\t".join(ww[1:]))
40
+ count += 1
41
+ LD, VD, ID, SD = BuildLengthDict(
42
+ seqs, vGene=vgs, INFO=infoList, sIDs=[x for x in range(len(seqs))]
43
+ )
41
44
  LDu_r, VDu_r, IDu_r, SDu_r = CollapseUnique(LD, VD, ID, SD)
42
- flagLD_r={}
43
- dMD_r={}
45
+ flagLD_r = {}
46
+ dMD_r = {}
44
47
  for kk in LDu_r:
45
- vss=SDu_r[kk]
46
- vInfo=IDu_r[kk]
47
- flagL=[len(x)-1 for x in vInfo]
48
- flagLD_r[kk]=flagL
49
- dM=np.array([EncodingCDR3(x[ST:-2], M6, n0) for x in vss])
50
- dM=dM.astype("float32")
51
- dMD_r[kk]=dM
52
- ## ff0=re.sub('.txt','',rFile)
53
- ## outfile=outdir+ff0+'_giana_ref.shelve'
54
- ## giana_shelf = shelve.open(outfile, 'n')
55
- ## giana_shelf['flagLD']=flagLD_r
56
- ## giana_shelf['dMD']=dMD_r
57
- ## giana_shelf['LDu']=LDu_r
58
- ## giana_shelf['VDu']=VDu_r
59
- ## giana_shelf['IDu']=IDu_r
60
- ## giana_shelf['SDu']=SDu_r
61
- ## giana_shelf.close()
48
+ vss = SDu_r[kk]
49
+ vInfo = IDu_r[kk]
50
+ flagL = [len(x) - 1 for x in vInfo]
51
+ flagLD_r[kk] = flagL
52
+ dM = np.array([EncodingCDR3(x[ST:-2], M6, n0) for x in vss])
53
+ dM = dM.astype("float32")
54
+ dMD_r[kk] = dM
55
+ ## ff0=re.sub('.txt','',rFile)
56
+ ## outfile=outdir+ff0+'_giana_ref.shelve'
57
+ ## giana_shelf = shelve.open(outfile, 'n')
58
+ ## giana_shelf['flagLD']=flagLD_r
59
+ ## giana_shelf['dMD']=dMD_r
60
+ ## giana_shelf['LDu']=LDu_r
61
+ ## giana_shelf['VDu']=VDu_r
62
+ ## giana_shelf['IDu']=IDu_r
63
+ ## giana_shelf['SDu']=SDu_r
64
+ ## giana_shelf.close()
62
65
  return [LDu_r, VDu_r, IDu_r, SDu_r, dMD_r]
63
66
 
64
- def MakeQuery(qFile, rData=[],dbFile=None, Vgene=True, thr=7, ST=3, thr_s=3.3):
67
+
68
+ def MakeQuery(qFile, rData=[], dbFile=None, Vgene=True, thr=7, ST=3, thr_s=3.3):
65
69
  if dbFile is not None:
66
70
  with shelve.open(dbFile) as db:
67
71
  for key in db:
68
- globals()[key]=db[key]
72
+ globals()[key] = db[key]
69
73
  else:
70
- if len(rData)==0:
71
- raise("Need to provide either a reference file or a shelve")
72
- LDu_r=rData[0]
73
- VDu_r=rData[1]
74
- IDu_r=rData[2]
75
- SDu_r=rData[3]
76
- dMD_r=rData[4]
77
- h=open(qFile)
78
- alines=h.readlines()
79
- ww=alines[0].strip().split('\t')
80
- if not ww[0].startswith('C'):
74
+ if len(rData) == 0:
75
+ raise ("Need to provide either a reference file or a shelve")
76
+ LDu_r = rData[0]
77
+ VDu_r = rData[1]
78
+ IDu_r = rData[2]
79
+ SDu_r = rData[3]
80
+ dMD_r = rData[4]
81
+ h = open(qFile)
82
+ alines = h.readlines()
83
+ ww = alines[0].strip().split("\t")
84
+ if not ww[0].startswith("C"):
81
85
  ## header line
82
- hline=alines[0]
83
- alines=alines[1:]
84
- elif 'CDR3' in ww[0]:
85
- hline=alines[0]
86
- alines=alines[1:]
86
+ hline = alines[0]
87
+ alines = alines[1:]
88
+ elif "CDR3" in ww[0]:
89
+ hline = alines[0]
90
+ alines = alines[1:]
87
91
  else:
88
- hline='CDR3\t'+'\t'.join(['Info'+str(x) for x in range(len(ww)-1)])
89
- seqs=[]
90
- vgs=[]
91
- infoList=[]
92
- count=0
92
+ hline = "CDR3\t" + "\t".join(["Info" + str(x) for x in range(len(ww) - 1)])
93
+ seqs = []
94
+ vgs = []
95
+ infoList = []
96
+ count = 0
93
97
  for ll in alines:
94
- ww=ll.strip().split('\t')
95
- cdr3=ww[0]
96
- if '*' in cdr3:
98
+ ww = ll.strip().split("\t")
99
+ cdr3 = ww[0]
100
+ if "*" in cdr3:
97
101
  continue
98
- if '_' in cdr3:
102
+ if "_" in cdr3:
99
103
  continue
100
104
  seqs.append(ww[0])
101
105
  if Vgene:
102
106
  vgs.append(ww[1])
103
- infoList.append('\t'.join(ww[1:]))
107
+ infoList.append("\t".join(ww[1:]))
104
108
  else:
105
- infoList.append('\t'.join(ww[1:]))
106
- count+=1
107
- LD,VD, ID,SD= BuildLengthDict(seqs, vGene=vgs,INFO=infoList,sIDs=[x for x in range(len(seqs))])
109
+ infoList.append("\t".join(ww[1:]))
110
+ count += 1
111
+ LD, VD, ID, SD = BuildLengthDict(
112
+ seqs, vGene=vgs, INFO=infoList, sIDs=[x for x in range(len(seqs))]
113
+ )
108
114
  LDu, VDu, IDu, SDu = CollapseUnique(LD, VD, ID, SD)
109
- tmpFile='tmp_query.txt'
110
- g=open(tmpFile,'w')
115
+ tmpFile = "tmp_query.txt"
116
+ g = open(tmpFile, "w")
111
117
  for kk in LDu:
112
- vss=SDu[kk]
113
- vInfo=IDu[kk]
114
- vss_r=SDu_r[kk]
115
- vInfo_r=IDu_r[kk]
116
- flagL=[len(x)-1 for x in vInfo]
117
- dM_r=dMD_r[kk]
118
- dM=np.array([EncodingCDR3(x[ST:-2], M6, n0) for x in vss])
119
- dM=dM.astype("float32")
120
- nq=dM.shape[0]
121
- nr=dM_r.shape[0]
122
- vssc=vss+vss_r
123
- vInfoc=vInfo+vInfo_r
124
- dMc=np.concatenate((dM, dM_r))
125
- index = faiss.IndexFlatL2(Ndim*6)
118
+ vss = SDu[kk]
119
+ vInfo = IDu[kk]
120
+ vss_r = SDu_r[kk]
121
+ vInfo_r = IDu_r[kk]
122
+ flagL = [len(x) - 1 for x in vInfo]
123
+ dM_r = dMD_r[kk]
124
+ dM = np.array([EncodingCDR3(x[ST:-2], M6, n0) for x in vss])
125
+ dM = dM.astype("float32")
126
+ nq = dM.shape[0]
127
+ nr = dM_r.shape[0]
128
+ vssc = vss + vss_r
129
+ vInfoc = vInfo + vInfo_r
130
+ dMc = np.concatenate((dM, dM_r))
131
+ index = faiss.IndexFlatL2(Ndim * 6)
126
132
  index.add(dMc)
127
133
  D, I = index.search(dM, 2)
128
- vv=np.where((D[0:nq,1]<=thr))[0]
129
- flagL=np.array(flagL)
130
- vv0=np.where((D[0:nq,1]>thr) & (flagL>0))[0]
131
- curList=[]
134
+ vv = np.where((D[0:nq, 1] <= thr))[0]
135
+ flagL = np.array(flagL)
136
+ vv0 = np.where((D[0:nq, 1] > thr) & (flagL > 0))[0]
137
+ curList = []
132
138
  for v in vv0:
133
139
  for ii in range(len(vInfoc[v])):
134
- line=vssc[v]+'\t'+vInfoc[v][ii]+'\t'+'query\n'
135
- _=g.write(line)
140
+ line = vssc[v] + "\t" + vInfoc[v][ii] + "\t" + "query\n"
141
+ _ = g.write(line)
136
142
  for v in vv:
137
- tmpI=I[v,]
143
+ tmpI = I[v,]
138
144
  if v not in tmpI:
139
- tmpI[0]=v
140
- idx1=tmpI[0]
141
- idx2=tmpI[1]
142
- c1=vssc[idx1]
143
- c2=vssc[idx2]
144
- info1=vInfoc[idx1]
145
- info2=vInfoc[idx2]
145
+ tmpI[0] = v
146
+ idx1 = tmpI[0]
147
+ idx2 = tmpI[1]
148
+ c1 = vssc[idx1]
149
+ c2 = vssc[idx2]
150
+ info1 = vInfoc[idx1]
151
+ info2 = vInfoc[idx2]
146
152
  for tmpInfo in info1:
147
- tup1=(c1, tmpInfo)
153
+ tup1 = (c1, tmpInfo)
148
154
  if tup1 not in curList:
149
- if idx1<nq:
150
- line1=c1+'\t'+tmpInfo+'\t'+'query\n'
155
+ if idx1 < nq:
156
+ line1 = c1 + "\t" + tmpInfo + "\t" + "query\n"
151
157
  else:
152
- line1=c1+'\t'+tmpInfo+'\t'+'ref\n'
153
- _=g.write(line1)
158
+ line1 = c1 + "\t" + tmpInfo + "\t" + "ref\n"
159
+ _ = g.write(line1)
154
160
  curList.append(tup1)
155
161
  for tmpInfo in info2:
156
- tup2=(c2, tmpInfo)
162
+ tup2 = (c2, tmpInfo)
157
163
  if tup2 not in curList:
158
- if idx2<nq:
159
- line2=c2+'\t'+tmpInfo+'\t'+'query\n'
164
+ if idx2 < nq:
165
+ line2 = c2 + "\t" + tmpInfo + "\t" + "query\n"
160
166
  else:
161
- line2=c2+'\t'+tmpInfo+'\t'+'ref\n'
162
- _=g.write(line2)
167
+ line2 = c2 + "\t" + tmpInfo + "\t" + "ref\n"
168
+ _ = g.write(line2)
163
169
  curList.append(tup2)
164
170
  g.close()
165
- cmd='python3 GIANA4.1.py -f tmp_query.txt -S '+str(thr_s) ## updated to GIANA4.1
166
- p=sp.run(cmd, shell=True)
167
-
168
- def MergeExist(refClusterFile, outFile='queryFinal.txt',queryClusterFile='tmp_query--RotationEncodingBL62.txt', direction='q'):
171
+ cmd = "python3 GIANA4.1.py -f tmp_query.txt -S " + str(
172
+ thr_s
173
+ ) ## updated to GIANA4.1
174
+ p = sp.run(cmd, shell=True)
175
+
176
+
177
+ def MergeExist(
178
+ refClusterFile,
179
+ outFile="queryFinal.txt",
180
+ queryClusterFile="tmp_query--RotationEncodingBL62.txt",
181
+ direction="q",
182
+ ):
169
183
  ## This function compare the query file with ref cluster file and merge the two based on shared TCRs
170
184
  ## If direction is 'q', the overlapping clusters will be added to the query file
171
185
  ## If direction is 'r', the overlapping and non-overlapping clusters will be added to the reference file
172
- refT=pd.read_table(refClusterFile, skiprows=2, delimiter='\t', header=None)
173
- queryT=pd.read_table(queryClusterFile, skiprows=2, delimiter='\t', header=None)
174
- nq=queryT.shape[1]
175
- nr=refT.shape[1]
176
- if nr != nq-1:
186
+ refT = pd.read_table(refClusterFile, skiprows=2, delimiter="\t", header=None)
187
+ queryT = pd.read_table(queryClusterFile, skiprows=2, delimiter="\t", header=None)
188
+ nq = queryT.shape[1]
189
+ nr = refT.shape[1]
190
+ if nr != nq - 1:
177
191
  print("ERROR: Make sure reference and the query samples have the same columns!")
178
192
  print("No query file is generated.")
179
193
  return
180
- gn=np.unique(queryT[1])
181
- queryTs=pd.DataFrame([], columns=queryT.columns)
194
+ gn = np.unique(queryT[1])
195
+ queryTs = pd.DataFrame([], columns=queryT.columns)
182
196
  for nn in gn:
183
- tmp_ddq=queryT.loc[np.where(queryT[1]==nn)[0],:]
184
- cls_lab=np.unique(tmp_ddq[nq-1])
185
- if len(cls_lab)==1:
186
- if cls_lab[0]=='ref':
187
- continue
188
- queryTs=queryTs.append(tmp_ddq)
189
- queryTs.index=range(queryTs.shape[0])
190
- keyr=refT[0]+'_'+refT[2]
191
- keyq=queryTs[0]+'_'+queryTs[2]
192
- vvr=np.where(queryTs[nq-1]=='ref')[0]
193
- vvr_in=np.where(keyr.isin(keyq[vvr]))[0]
194
- gn_r=list(refT.loc[vvr_in,1].drop_duplicates())
195
- ddo=pd.DataFrame([], columns=refT.columns)
197
+ tmp_ddq = queryT.loc[np.where(queryT[1] == nn)[0], :]
198
+ cls_lab = np.unique(tmp_ddq[nq - 1])
199
+ if len(cls_lab) == 1:
200
+ if cls_lab[0] == "ref":
201
+ continue
202
+ queryTs = queryTs.append(tmp_ddq)
203
+ queryTs.index = range(queryTs.shape[0])
204
+ keyr = refT[0] + "_" + refT[2]
205
+ keyq = queryTs[0] + "_" + queryTs[2]
206
+ vvr = np.where(queryTs[nq - 1] == "ref")[0]
207
+ vvr_in = np.where(keyr.isin(keyq[vvr]))[0]
208
+ gn_r = list(refT.loc[vvr_in, 1].drop_duplicates())
209
+ ddo = pd.DataFrame([], columns=refT.columns)
196
210
  for nn in gn_r:
197
- tmp_dd=refT.loc[np.where(refT[1]==nn)[0],:]
198
- tmpkey=tmp_dd[0]+'_'+tmp_dd[2]
199
- vv=np.where(keyq.isin(tmpkey))[0][0]
200
- gq=queryTs[1][vv]
201
- tmp_dd[1]=gq
202
- ddo=ddo.append(tmp_dd)
203
- if direction=='q':
204
- ddo[nq-1]='ref'
211
+ tmp_dd = refT.loc[np.where(refT[1] == nn)[0], :]
212
+ tmpkey = tmp_dd[0] + "_" + tmp_dd[2]
213
+ vv = np.where(keyq.isin(tmpkey))[0][0]
214
+ gq = queryTs[1][vv]
215
+ tmp_dd[1] = gq
216
+ ddo = ddo.append(tmp_dd)
217
+ if direction == "q":
218
+ ddo[nq - 1] = "ref"
205
219
  ## remove groups that contain only ref group
206
- queryTs=queryTs.append(ddo)
207
- queryTs=queryTs.drop_duplicates()
208
- queryTs.to_csv(outFile, sep='\t',header=False,index=False)
209
- # queryTs.index=range(queryTs.shape[0])
210
- if direction=='r':
220
+ queryTs = queryTs.append(ddo)
221
+ queryTs = queryTs.drop_duplicates()
222
+ queryTs.to_csv(outFile, sep="\t", header=False, index=False)
223
+ # queryTs.index=range(queryTs.shape[0])
224
+ if direction == "r":
211
225
  ## to be developed
212
226
  pass
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
@@ -1,12 +1,13 @@
1
1
  # loaded variables
2
2
  # immfile, outdir, mutaters, immdata, n_samples
3
3
 
4
- volumes = {{envs.volumes | r}}
5
- lens = {{envs.lens | r}}
6
- counts = {{envs.counts | r}}
4
+ log_info("")
5
+ log_info("# Basic analysis")
6
+ log_info("-----------------------------------")
7
7
 
8
8
  # Fill up cases
9
9
  fill_up_cases_basic = function(config) {
10
+ log_debug("Filling up cases ...")
10
11
  cases = config$cases
11
12
  if (is.null(cases) || length(cases) == 0) {
12
13
  cases$DEFAULT = list(by = config$by, devpars = config$devpars, subset = config$subset)
@@ -42,7 +43,7 @@ fill_up_cases_basic = function(config) {
42
43
  }
43
44
 
44
45
  do_one_case_basic = function(name, case, method) {
45
- print(paste0(" Case: ", name))
46
+ log_info("- Processing case: {name} ...")
46
47
  odir = file.path(outdir, method)
47
48
  dir.create(odir, showWarnings = FALSE)
48
49
 
@@ -62,25 +63,46 @@ do_one_case_basic = function(name, case, method) {
62
63
  } else {
63
64
  p = vis(exp, .by = case$by, .meta = d$meta)
64
65
  }
66
+
65
67
  ofig = file.path(odir, paste0(name, ".png"))
66
68
  png(ofig, width = case$devpars$width, height = case$devpars$height, res = case$devpars$res)
67
- print(p)
69
+ print(p + scale_fill_biopipen())
70
+ dev.off()
71
+
72
+ ofig_pdf = file.path(odir, paste0(name, ".pdf"))
73
+ pdf(ofig_pdf, width = case$devpars$width / case$devpars$res, height = case$devpars$height / case$devpars$res)
74
+ print(p + scale_fill_biopipen())
68
75
  dev.off()
76
+
77
+ add_report(
78
+ list(
79
+ src = ofig,
80
+ name = if (name == "DEFAULT") NULL else name,
81
+ download = ofig_pdf
82
+ ),
83
+ h1 = "Exploratory Analysis",
84
+ h2 = switch(method,
85
+ len = "CDR3 length distribution",
86
+ volume = "Clonotype volume (Number of clonotypes)",
87
+ count = "Clonotype abundances"
88
+ ),
89
+ ui = "table_of_images"
90
+ )
69
91
  }
70
92
 
71
93
  # Do cases
72
94
  do_cases_basic = function(cases, method) {
73
- print(paste0("- Basic analysls: ", method))
95
+ log_info("Handling cases (method={method}) ...")
74
96
  for (name in names(cases)) {
75
97
  do_one_case_basic(name, cases[[name]], method)
76
98
  }
77
99
  }
78
100
 
79
- volumes = fill_up_cases_basic(volumes)
80
- do_cases_basic(volumes, "volume")
81
-
82
101
  lens = fill_up_cases_basic(lens)
83
102
  do_cases_basic(lens, "len")
84
103
 
104
+ volumes = fill_up_cases_basic(volumes)
105
+ do_cases_basic(volumes, "volume")
106
+
85
107
  counts = fill_up_cases_basic(counts)
86
108
  do_cases_basic(counts, "count")
@@ -1,9 +1,9 @@
1
1
  # loaded variables
2
2
  # immfile, outdir, mutaters, immdata, n_samples
3
3
 
4
- top_clones = {{envs.top_clones | r}}
5
- rare_clones = {{envs.rare_clones | r}}
6
- hom_clones = {{envs.hom_clones | r}}
4
+ log_info("")
5
+ log_info("# Clonality analysis")
6
+ log_info("-----------------------------------")
7
7
 
8
8
  # Fill up cases
9
9
  fill_up_cases_clonality = function(config) {
@@ -45,9 +45,10 @@ fill_up_cases_clonality = function(config) {
45
45
  }
46
46
 
47
47
  do_one_case_clonality = function(name, case, method) {
48
- print(paste0(" Case: ", name))
48
+ log_info("- Processing case: {name} ...")
49
49
  odir = file.path(outdir, paste0(method, "_clones"))
50
50
  dir.create(odir, showWarnings = FALSE)
51
+
51
52
  if (is.null(case$subset)) {
52
53
  d = immdata
53
54
  } else {
@@ -76,11 +77,30 @@ do_one_case_clonality = function(name, case, method) {
76
77
  png(ofig, width = case$devpars$width, height = case$devpars$height, res = case$devpars$res)
77
78
  print(p)
78
79
  dev.off()
80
+
81
+ ofig_pdf = file.path(odir, paste0(name, ".pdf"))
82
+ pdf(ofig_pdf, width = case$devpars$width / case$devpars$res, height = case$devpars$height / case$devpars$res)
83
+ print(p)
84
+ dev.off()
85
+
86
+ add_report(
87
+ list(
88
+ src = ofig,
89
+ name = if (name == "DEFAULT") NULL else name
90
+ ),
91
+ h1 = "Clonality Analysis",
92
+ h2 = switch(method,
93
+ top = "Top Clones",
94
+ rare = "Rare Clones",
95
+ homeo = "Clonal Space Homeostasis"
96
+ ),
97
+ ui = "table_of_images"
98
+ )
79
99
  }
80
100
 
81
101
  # Do cases
82
102
  do_cases_clonality = function(cases, method) {
83
- print(paste0("- Clonality analysls: ", method))
103
+ log_info("Handling cases (method={method}) ...")
84
104
  for (name in names(cases)) {
85
105
  do_one_case_clonality(name, cases[[name]], method)
86
106
  }