biopipen 0.21.1__py3-none-any.whl → 0.22.0__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.

Potentially problematic release.


This version of biopipen might be problematic. Click here for more details.

Files changed (58) hide show
  1. biopipen/__init__.py +1 -1
  2. biopipen/core/filters.py +142 -0
  3. biopipen/ns/scrna.py +19 -1
  4. biopipen/ns/tcr.py +27 -0
  5. biopipen/reports/delim/SampleInfo.svelte +2 -22
  6. biopipen/reports/scrna/CellsDistribution.svelte +4 -39
  7. biopipen/reports/scrna/MarkersFinder.svelte +6 -126
  8. biopipen/reports/scrna/MetaMarkers.svelte +3 -75
  9. biopipen/reports/scrna/RadarPlots.svelte +4 -20
  10. biopipen/reports/scrna/ScFGSEA.svelte +4 -23
  11. biopipen/reports/scrna/SeuratClusterStats.svelte +3 -69
  12. biopipen/reports/scrna/SeuratPreparing.svelte +3 -26
  13. biopipen/reports/scrna/TopExpressingGenes.svelte +3 -41
  14. biopipen/reports/scrna_metabolic_landscape/MetabolicFeatures.svelte +17 -16
  15. biopipen/reports/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.svelte +13 -16
  16. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayActivity.svelte +44 -52
  17. biopipen/reports/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.svelte +2 -8
  18. biopipen/reports/tcr/CDR3AAPhyschem.svelte +18 -65
  19. biopipen/reports/tcr/CloneResidency.svelte +3 -93
  20. biopipen/reports/tcr/Immunarch.svelte +4 -155
  21. biopipen/reports/tcr/TCRClusterStats.svelte +3 -45
  22. biopipen/reports/tcr/TESSA.svelte +11 -28
  23. biopipen/scripts/delim/SampleInfo.R +41 -7
  24. biopipen/scripts/scrna/CellsDistribution.R +121 -16
  25. biopipen/scripts/scrna/MarkersFinder.R +245 -100
  26. biopipen/scripts/scrna/MetaMarkers.R +163 -82
  27. biopipen/scripts/scrna/RadarPlots.R +163 -110
  28. biopipen/scripts/scrna/ScFGSEA.R +51 -11
  29. biopipen/scripts/scrna/SeuratClusterStats-dimplots.R +26 -13
  30. biopipen/scripts/scrna/SeuratClusterStats-features.R +58 -53
  31. biopipen/scripts/scrna/SeuratClusterStats-stats.R +39 -21
  32. biopipen/scripts/scrna/SeuratClusterStats.R +4 -2
  33. biopipen/scripts/scrna/SeuratClustering.R +73 -26
  34. biopipen/scripts/scrna/SeuratPreparing.R +93 -19
  35. biopipen/scripts/scrna/TopExpressingGenes.R +100 -18
  36. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeatures.R +21 -8
  37. biopipen/scripts/scrna_metabolic_landscape/MetabolicFeaturesIntraSubset.R +25 -3
  38. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayActivity.R +1 -0
  39. biopipen/scripts/scrna_metabolic_landscape/MetabolicPathwayHeterogeneity.R +14 -3
  40. biopipen/scripts/tcr/CDR3AAPhyschem.R +122 -9
  41. biopipen/scripts/tcr/CloneResidency.R +114 -34
  42. biopipen/scripts/tcr/Immunarch-basic.R +26 -6
  43. biopipen/scripts/tcr/Immunarch-clonality.R +22 -2
  44. biopipen/scripts/tcr/Immunarch-diversity.R +132 -22
  45. biopipen/scripts/tcr/Immunarch-geneusage.R +33 -4
  46. biopipen/scripts/tcr/Immunarch-kmer.R +57 -7
  47. biopipen/scripts/tcr/Immunarch-overlap.R +72 -3
  48. biopipen/scripts/tcr/Immunarch-spectratyping.R +28 -5
  49. biopipen/scripts/tcr/Immunarch-tracking.R +33 -4
  50. biopipen/scripts/tcr/Immunarch-vjjunc.R +118 -0
  51. biopipen/scripts/tcr/Immunarch.R +17 -0
  52. biopipen/scripts/tcr/TCRClusterStats.R +124 -11
  53. biopipen/scripts/tcr/TESSA.R +43 -11
  54. biopipen/utils/misc.R +96 -1
  55. {biopipen-0.21.1.dist-info → biopipen-0.22.0.dist-info}/METADATA +1 -1
  56. {biopipen-0.21.1.dist-info → biopipen-0.22.0.dist-info}/RECORD +58 -57
  57. {biopipen-0.21.1.dist-info → biopipen-0.22.0.dist-info}/WHEEL +0 -0
  58. {biopipen-0.21.1.dist-info → biopipen-0.22.0.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,11 @@
1
1
  # Diversity estimation
2
2
  # https://immunarch.com/articles/web_only/v6_diversity.html
3
3
 
4
+ log_info("")
5
+ log_info("#####################################")
6
+ log_info("# Diversity estimation #")
7
+ log_info("#####################################")
8
+
4
9
  # Other variables are loaded in the parent template
5
10
  # immdata is already loaded, meta is mutated
6
11
  div_method = {{envs.divs.method | r}}
@@ -22,10 +27,9 @@ div_ymax = {{envs.divs.ymax | r}}
22
27
  div_dir = file.path(outdir, "diversity")
23
28
  dir.create(div_dir, showWarnings = FALSE)
24
29
 
25
- print("- Diversity estimation ...")
26
-
27
30
  # Fill up the cases
28
31
  update_case = function(case) {
32
+ log_info("Filling up cases ...")
29
33
  if (is.null(case$subset)) {
30
34
  case$subset = div_subset
31
35
  }
@@ -161,7 +165,7 @@ filter_div = function(div, samples) {
161
165
  # case: the case with argument to be run
162
166
  # ddir: the directory to save the results
163
167
  # value_col: the column name of the value
164
- run_general = function(d, case, ddir, value_col = "Value") {
168
+ run_general = function(casename, d, case, ddir, value_col = "Value") {
165
169
  args = case$args
166
170
  args$.data = d$data
167
171
  args$.method = case$method
@@ -278,6 +282,63 @@ run_general = function(d, case, ddir, value_col = "Value") {
278
282
  print(p)
279
283
  dev.off()
280
284
 
285
+ add_report(
286
+ list(
287
+ kind = "descr",
288
+ content = paste0(
289
+ "Diversity estimation using ",
290
+ "<code>",
291
+ case$method,
292
+ "</code>: ",
293
+ switch(case$method,
294
+ chao1 = paste0(
295
+ "a nonparameteric asymptotic estimator of species richness ",
296
+ "(number of species in a population)."),
297
+ hill = paste0(
298
+ "Hill numbers are a mathematically unified family of ",
299
+ "diversity indices (differing only by an exponent q)."),
300
+ div = paste0(
301
+ "true diversity, or the effective number of types, ",
302
+ "refers to the number of equally abundant types needed for ",
303
+ "the average proportional abundance of the types to equal that ",
304
+ "observed in the dataset of interest where all types may ",
305
+ "not be equally abundant."),
306
+ gini.simp = paste0(
307
+ "the Gini-Simpson index is the probability of interspecific ",
308
+ "encounter, i.e., probability that two entities represent different types."),
309
+ inv.simp = paste0(
310
+ "Inverse Simpson index is the effective number of types ",
311
+ "that is obtained when the weighted arithmetic mean is used ",
312
+ "to quantify average proportional abundance of types in ",
313
+ "the dataset of interest."),
314
+ gini = paste0(
315
+ "the Gini coefficient measures the inequality among ",
316
+ "values of a frequency distribution (for example levels of income). ",
317
+ "A Gini coefficient of zero expresses perfect equality, ",
318
+ "where all values are the same (for example, where everyone has ",
319
+ "the same income). A Gini coefficient of one (or 100 percents ) ",
320
+ "expresses maximal inequality among values (for example where only ",
321
+ "one person has all the income).")
322
+ )
323
+ )
324
+ ),
325
+ h1 = "Diversity Estimation",
326
+ h2 = casename
327
+ )
328
+ add_report(
329
+ list(
330
+ name = "Diversity Plot",
331
+ contents = list(list(kind = "image", src = file.path(ddir, "diversity.png")))
332
+ ),
333
+ list(
334
+ name = "Diversity Table",
335
+ contents = list(list(kind = "table", src = file.path(ddir, "diversity.txt")))
336
+ ),
337
+ h1 = "Diversity Estimation",
338
+ h2 = casename,
339
+ ui = "tabs"
340
+ )
341
+
281
342
  # Test
282
343
  if (!is.null(case$test) && case$test$method != "none") {
283
344
  # Use pairwise.t.test or pairwise.wilcox.test
@@ -340,6 +401,19 @@ run_general = function(d, case, ddir, value_col = "Value") {
340
401
  row.names = FALSE,
341
402
  col.names = TRUE
342
403
  )
404
+
405
+ add_report(
406
+ list(
407
+ name = paste0("Test (", case$test$method, ")"),
408
+ contents = list(list(
409
+ kind = "table",
410
+ src = file.path(ddir, paste0("diversity.test.", case$test$method, ".txt"))
411
+ ))
412
+ ),
413
+ h1 = "Diversity Estimation",
414
+ h2 = casename,
415
+ ui = "tabs"
416
+ )
343
417
  }
344
418
  }
345
419
 
@@ -421,7 +495,8 @@ run_raref_multi = function(d, case, ddir) {
421
495
  widths = list()
422
496
  plots = list()
423
497
  for (sepvar in sepvars) {
424
- print(paste0(" ", case$separate_by, ": ", sepvar))
498
+ # print(paste0(" ", case$separate_by, ": ", sepvar))
499
+ log_info(" {case$separate_by}: {sepvar}")
425
500
  q = list(include(sepvar))
426
501
  names(q) = case$separate_by
427
502
  single_run = run_raref_single(
@@ -466,19 +541,24 @@ run_raref_multi = function(d, case, ddir) {
466
541
  } else {
467
542
  height = case$devpars$height
468
543
  }
469
- png(file.path(ddir, paste0("raref-", case$separate_by, ".png")), width = width, height = height, res = res)
544
+ png(
545
+ file.path(ddir, paste0("raref-", slugify(case$separate_by), ".png")),
546
+ width = width,
547
+ height = height,
548
+ res = res
549
+ )
470
550
  print(p)
471
551
  dev.off()
472
552
  }
473
553
 
474
554
  # Run the diversity estimation for one case
475
555
  run_div_case = function(casename) {
476
- print(paste0(" Case: ", casename))
556
+ log_info("Processing case: {casename} ...")
477
557
  case = div_cases[[casename]]
478
558
  if (case$method == "raref") {
479
- ddir = file.path(outdir, "rarefraction", casename)
559
+ ddir = file.path(outdir, "rarefraction", slugify(casename, tolower = FALSE))
480
560
  } else {
481
- ddir = file.path(div_dir, casename)
561
+ ddir = file.path(div_dir, slugify(casename, tolower = FALSE))
482
562
  }
483
563
  dir.create(ddir, recursive = TRUE, showWarnings = FALSE)
484
564
 
@@ -490,26 +570,56 @@ run_div_case = function(casename) {
490
570
  }
491
571
 
492
572
  # Run repDiversity
493
- if (case$method == "chao1") {
494
- run_general(d, case, ddir, "Estimator")
495
- } else if (case$method == "hill") {
496
- run_general(d, case, ddir)
497
- } else if (case$method == "div") {
498
- run_general(d, case, ddir)
499
- } else if (case$method == "gini.simp") {
500
- run_general(d, case, ddir)
501
- } else if (case$method == "inv.simp") {
502
- run_general(d, case, ddir)
503
- } else if (case$method == "gini") {
504
- run_general(d, case, ddir, "V1")
505
- } else if (case$method == "raref") {
573
+ if (case$method == "raref") {
574
+ add_report(
575
+ list(
576
+ kind = "descr",
577
+ content = paste0(
578
+ "Rarefaction is a technique to assess species richness from the ",
579
+ "results of sampling through extrapolation. "
580
+ )
581
+ ),
582
+ h1 = "Rarefraction",
583
+ h2 = casename
584
+ )
585
+
506
586
  if (!is.null(case$separate_by)) {
507
587
  run_raref_multi(d, case, ddir)
588
+ add_report(
589
+ list(
590
+ kind = "image",
591
+ src = file.path(ddir, paste0("raref-", slugify(case$separate_by), ".png"))
592
+ ),
593
+ h1 = "Rarefraction",
594
+ h2 = casename
595
+ )
508
596
  } else {
509
597
  run_raref_single(d, case, ddir)
598
+ add_report(
599
+ list(
600
+ kind = "image",
601
+ src = file.path(ddir, "raref.png")
602
+ ),
603
+ h1 = "Rarefraction",
604
+ h2 = casename
605
+ )
510
606
  }
511
607
  } else {
512
- stop(paste0("Unknown diversity method: ", case$method))
608
+ if (case$method == "chao1") {
609
+ run_general(casename, d, case, ddir, "Estimator")
610
+ } else if (case$method == "hill") {
611
+ run_general(casename, d, case, ddir)
612
+ } else if (case$method == "div") {
613
+ run_general(casename, d, case, ddir)
614
+ } else if (case$method == "gini.simp") {
615
+ run_general(casename, d, case, ddir)
616
+ } else if (case$method == "inv.simp") {
617
+ run_general(casename, d, case, ddir)
618
+ } else if (case$method == "gini") {
619
+ run_general(casename, d, case, ddir, "V1")
620
+ } else {
621
+ stop(paste0("Unknown diversity method: ", case$method))
622
+ }
513
623
  }
514
624
  }
515
625
 
@@ -1,9 +1,15 @@
1
1
  # loaded variables
2
2
  # immfile, outdir, mutaters, immdata, n_samples
3
3
 
4
+ log_info("")
5
+ log_info("#####################################")
6
+ log_info("# Gene usage analysis #")
7
+ log_info("#####################################")
8
+
4
9
  gene_usages = {{ envs.gene_usages | r: todot="-" }}
5
10
 
6
11
  # Fill up cases
12
+ log_info("Filling up cases ...")
7
13
  cases = gene_usages$cases
8
14
  if (is.null(cases) || length(cases) == 0) {
9
15
  cases$DEFAULT = list(
@@ -92,7 +98,8 @@ for (name in names(cases)) {
92
98
  }
93
99
 
94
100
  do_one_case_geneusage = function(name, case, gu_dir) {
95
- print(paste0(" Case: ", name))
101
+ # print(paste0(" Case: ", name))
102
+ log_info("Processing case: {name} ...")
96
103
  odir = file.path(gu_dir, name)
97
104
  dir.create(odir, showWarnings = FALSE)
98
105
 
@@ -119,15 +126,30 @@ do_one_case_geneusage = function(name, case, gu_dir) {
119
126
 
120
127
  ofig = file.path(odir, paste0(name, ".png"))
121
128
  png(ofig, width = case$devpars$width, height = case$devpars$height, res = case$devpars$res)
122
- print(p)
129
+ print(p + scale_fill_biopipen())
123
130
  dev.off()
124
131
 
132
+ add_report(
133
+ list(
134
+ kind = "table_image",
135
+ src = ofig,
136
+ descr = paste0(
137
+ "Distribution of known gene segments following the ",
138
+ '<a href="http://www.imgt.org/IMGTrepertoire/LocusGenes/" target="_blank">IMGT</a> ',
139
+ "nomenclature."
140
+ )
141
+ ),
142
+ h1 = "Gene Usage",
143
+ h2 = ifelse(name == "DEFAULT", "#", name)
144
+ )
145
+
125
146
  if (!is.null(case$analyses$cases) && length(case$analyses$cases) > 0) {
126
147
  for (aname in names(case$analyses$cases)) {
127
148
  if (case$analyses$cases[[aname]]$method == "none") {
128
149
  next
129
150
  }
130
- print(paste0(" Analysis: ", aname))
151
+ # print(paste0(" Analysis: ", aname))
152
+ log_info("- Processing analysis: {aname} ...")
131
153
  tryCatch({
132
154
  imm_gua = geneUsageAnalysis(imm_gu, .method = case$analyses$cases[[aname]]$method)
133
155
  }, error = function(e) {
@@ -152,6 +174,14 @@ do_one_case_geneusage = function(name, case, gu_dir) {
152
174
  png(aofig, width = case$analyses$cases[[aname]]$devpars$width, height = case$analyses$cases[[aname]]$devpars$height, res = case$analyses$cases[[aname]]$devpars$res)
153
175
  print(ap)
154
176
  dev.off()
177
+
178
+ add_report(
179
+ list(src = aofig, name = aname),
180
+ h1 = "Gene Usage",
181
+ h2 = ifelse(name == "DEFAULT", "#", name),
182
+ h3 = "Gene Usage Analysis",
183
+ ui = "table_of_images"
184
+ )
155
185
  }
156
186
  }
157
187
  }
@@ -159,7 +189,6 @@ do_one_case_geneusage = function(name, case, gu_dir) {
159
189
  gu_dir = file.path(outdir, "gene_usage")
160
190
  dir.create(gu_dir, showWarnings = FALSE)
161
191
 
162
- print("- Gene usage")
163
192
  for (name in names(cases)) {
164
193
  do_one_case_geneusage(name, cases[[name]], gu_dir)
165
194
  }
@@ -1,9 +1,15 @@
1
1
  # loaded variables
2
2
  # immfile, outdir, mutaters, immdata, n_samples
3
3
 
4
+ log_info("")
5
+ log_info("#####################################")
6
+ log_info("# K-mer analysis #")
7
+ log_info("#####################################")
8
+
4
9
  kmers = {{ envs.kmers | r: todot="-" }}
5
10
 
6
11
  # Fill up cases
12
+ log_info("Filling up cases ...")
7
13
  cases = kmers$cases
8
14
  if (is.null(cases) || length(cases) == 0) {
9
15
  cases$DEFAULT = list(
@@ -80,8 +86,9 @@ for (name in names(cases)) {
80
86
  }
81
87
 
82
88
  do_one_case_kmer = function(name, case, kmer_dir) {
83
- print(paste0(" Case: ", name))
84
- odir = file.path(kmer_dir, name)
89
+ # print(paste0(" Case: ", name))
90
+ log_info("Processing case: {name} ...")
91
+ odir = file.path(kmer_dir, slugify(name, tolower = FALSE))
85
92
  dir.create(odir, showWarnings = FALSE)
86
93
 
87
94
  if (!is.null(case$subset)) {
@@ -101,34 +108,77 @@ do_one_case_kmer = function(name, case, kmer_dir) {
101
108
  print(p)
102
109
  dev.off()
103
110
 
111
+ add_report(
112
+ list(
113
+ kind = "descr",
114
+ content = "K-mer sequence occurrences and motif analysis of CDR3 amino acid sequences"
115
+ ),
116
+ h1 = "Kmer and sequence motif analysis",
117
+ h2 = ifelse(name == "DEFAULT", "#", name),
118
+ h3 = "Kmer sequence occurrences"
119
+ )
120
+
121
+ add_report(
122
+ list(kind = "image", src = ofig),
123
+ h1 = "Kmer and sequence motif analysis",
124
+ h2 = ifelse(name == "DEFAULT", "#", name),
125
+ h3 = "Kmer sequence occurrences"
126
+ )
127
+
128
+ add_report(
129
+ h1 = "Kmer and sequence motif analysis",
130
+ h2 = ifelse(name == "DEFAULT", "#", name),
131
+ h3 = "Motif analysis"
132
+ )
133
+
104
134
  for (sample in names(d$data)) {
105
- print(paste0(" Sample: ", sample))
135
+ # print(paste0(" Sample: ", sample))
136
+ log_info("- Sample: {sample} ...")
106
137
  imm_kmer = getKmers(d$data[[sample]], case$k)
107
138
 
108
139
  if (!is.null(case$profiles$cases) && length(case$profiles$cases) > 0) {
109
140
  for (aname in names(case$profiles$cases)) {
110
- print(paste0(" Profiling: ", aname))
141
+ # print(paste0(" Profiling: ", aname))
142
+ log_info(" Profiling: {aname} ...")
111
143
  imm_kmera = kmer_profile(imm_kmer, case$profiles$cases[[aname]]$method)
112
144
  avis_args = case$profiles$cases[[aname]]$vis_args
113
145
  avis_args$.data = imm_kmera
114
146
  ap = do_call(vis, avis_args)
115
147
  if (aname == "DEFAULT") {
116
- aofig = file.path(odir, paste0(sample, "-profile.png"))
148
+ aofig = file.path(odir, paste0(slugify(sample), "-profile.png"))
117
149
  } else {
118
- aofig = file.path(odir, paste0(sample, "-", aname, "-profile.png"))
150
+ aofig = file.path(odir, paste0(slugify(sample), "-", slugify(aname), "-profile.png"))
119
151
  }
120
152
  png(aofig, width = case$profiles$cases[[aname]]$devpars$width, height = case$profiles$cases[[aname]]$devpars$height, res = case$profiles$cases[[aname]]$devpars$res)
121
153
  print(ap)
122
154
  dev.off()
155
+
156
+ add_report(
157
+ list(
158
+ src = aofig,
159
+ name = paste0(sample, ifelse(aname == "DEFAULT", "", paste0(" - ", aname)))
160
+ ),
161
+ h1 = "Kmer and sequence motif analysis",
162
+ h2 = ifelse(name == "DEFAULT", "#", name),
163
+ h3 = "Motif analysis",
164
+ ui = "table_of_images"
165
+ )
123
166
  }
124
167
  }
125
168
  }
126
169
  }
127
170
 
171
+ add_report(
172
+ list(
173
+ kind = "descr",
174
+ content = "Counting k-mer occurrences"
175
+ ),
176
+ h1 = "Kmer and sequence motif analysis"
177
+ )
178
+
128
179
  kmer_dir = file.path(outdir, "kmer")
129
180
  dir.create(kmer_dir, showWarnings = FALSE)
130
181
 
131
- print("- K-mer analysis")
132
182
  for (name in names(cases)) {
133
183
  do_one_case_kmer(name, cases[[name]], kmer_dir)
134
184
  }
@@ -1,6 +1,11 @@
1
1
  # loaded variables
2
2
  # immfile, outdir, mutaters, immdata, n_samples
3
3
 
4
+ log_info("")
5
+ log_info("#####################################")
6
+ log_info("# Overlap analysis #")
7
+ log_info("#####################################")
8
+
4
9
  overlaps = {{ envs.overlaps | r: todot="-" }}
5
10
 
6
11
  # Fill up cases
@@ -75,8 +80,48 @@ for (name in names(cases)) {
75
80
  cases[[name]]$analyses = analyses
76
81
  }
77
82
 
83
+ get_method_descr <- function(method) {
84
+ descr <- switch(method,
85
+ public = paste0(
86
+ "number of public (shared) clonotypes, ",
87
+ "a classic measure of overlap similarity"
88
+ ),
89
+ overlap = paste0(
90
+ "overlap coefficient, a normalised measure of overlap similarity. ",
91
+ "It is defined as the size of the intersection divided by the smaller of ",
92
+ "the size of the two sets."
93
+ ),
94
+ jaccard = paste0(
95
+ "Jaccard index, measures the similarity between finite sample sets, ",
96
+ "and is defined as the size of the intersection divided by the size of ",
97
+ "the union of the sample sets."
98
+ ),
99
+ tversky = paste0(
100
+ "Tversky index, an asymmetric similarity measure on sets that compares ",
101
+ "a variant to a prototype. ",
102
+ "If using default arguments, it’s similar to Dice’s coefficient."
103
+ ),
104
+ cosine = "cosine similarity, a measure of similarity between two non-zero vectors",
105
+ morisita = paste0(
106
+ "Morisita's overlap index, a statistical measure of dispersion of ",
107
+ "individuals in a population. ",
108
+ "It is used to compare overlap among samples."
109
+ )
110
+ )
111
+
112
+ if (!is.null(descr)) {
113
+ return(descr)
114
+ }
115
+
116
+ return(paste0(
117
+ "incremental overlap, ",
118
+ "overlaps of the N most abundant clonotypes with incrementally growing N"
119
+ ))
120
+ }
121
+
78
122
  do_one_case_overlap = function(name, case, ov_dir) {
79
- print(paste0(" Case: ", name))
123
+ # print(paste0(" Case: ", name))
124
+ log_info("Processing case: {name} ...")
80
125
  odir = file.path(ov_dir, name)
81
126
  dir.create(odir, showWarnings = FALSE)
82
127
 
@@ -96,11 +141,26 @@ do_one_case_overlap = function(name, case, ov_dir) {
96
141
  print(p)
97
142
  dev.off()
98
143
 
144
+ add_report(
145
+ list(
146
+ kind = "table_image",
147
+ src = ofig,
148
+ descr = paste0(
149
+ "Repertoire overlap is the most common approach to measure repertoire similarity, ",
150
+ "using method <code>", case$method, "</code>, ",
151
+ get_method_descr(case$method)
152
+ )
153
+ ),
154
+ h1 = "Repertoire Overlaps",
155
+ h2 = ifelse(name == "DEFAULT", "#", name)
156
+ )
157
+
99
158
  if (!is.null(case$analyses$cases) && length(case$analyses$cases) > 0) {
100
159
  for (aname in names(case$analyses$cases)) {
101
160
  if (case$analyses$cases[[aname]]$method == "none") next
102
161
 
103
- print(paste0(" Analysis: ", aname))
162
+ # print(paste0(" Analysis: ", aname))
163
+ log_info("- Processing analysis: {aname} ...")
104
164
  k = min(n_samples - 1, 2)
105
165
  tryCatch({
106
166
  imm_ova = repOverlapAnalysis(
@@ -128,6 +188,15 @@ do_one_case_overlap = function(name, case, ov_dir) {
128
188
  png(aofig, width = case$analyses$cases[[aname]]$devpars$width, height = case$analyses$cases[[aname]]$devpars$height, res = case$analyses$cases[[aname]]$devpars$res)
129
189
  print(ap)
130
190
  dev.off()
191
+
192
+ add_report(
193
+ list(src = aofig, name = aname),
194
+ h1 = "Repertoire Overlaps",
195
+ h2 = ifelse(name == "DEFAULT", "#", name),
196
+ h3 = "Repertoire Overlap Analysis",
197
+ ui = "table_of_images"
198
+ )
199
+
131
200
  }
132
201
  }
133
202
  }
@@ -135,7 +204,7 @@ do_one_case_overlap = function(name, case, ov_dir) {
135
204
  ov_dir = file.path(outdir, "overlap")
136
205
  dir.create(ov_dir, showWarnings = FALSE)
137
206
 
138
- print("- Overlap")
207
+ # print("- Overlap")
139
208
  for (name in names(cases)) {
140
209
  do_one_case_overlap(name, cases[[name]], ov_dir)
141
210
  }
@@ -1,9 +1,15 @@
1
1
  # loaded variables
2
2
  # immfile, outdir, mutaters, immdata, n_samples
3
3
 
4
+ log_info("")
5
+ log_info("#####################################")
6
+ log_info("# Spectratyping analysis #")
7
+ log_info("#####################################")
8
+
4
9
  spects = {{ envs.spects | r }}
5
10
 
6
11
  # Fill up cases
12
+ log_info("Filling up cases ...")
7
13
  if (is.null(spects$cases) || length(spects$cases) == 0) {
8
14
  spects$cases$DEFAULT = list(
9
15
  quant = spects$quant,
@@ -37,8 +43,9 @@ if (is.null(spects$cases) || length(spects$cases) == 0) {
37
43
  }
38
44
 
39
45
  do_one_case_spectratyping = function(name, case, spect_dir) {
40
- print(paste0(" Case: ", name))
41
- odir = file.path(spect_dir, name)
46
+ # print(paste0(" Case: ", name))
47
+ log_info("- Processing case: {name} ...")
48
+ odir = file.path(spect_dir, slugify(name, tolower = FALSE))
42
49
  dir.create(odir, showWarnings = FALSE)
43
50
 
44
51
  if (!is.null(case$subset)) {
@@ -48,24 +55,40 @@ do_one_case_spectratyping = function(name, case, spect_dir) {
48
55
  }
49
56
 
50
57
  for (sample in names(d$data)) {
51
- print(paste0(" Sample: ", sample))
58
+ # print(paste0(" Sample: ", sample))
59
+ log_info(" Sample: {sample} ...")
52
60
  spec_obj = spectratype(
53
61
  d$data[[sample]],
54
62
  .quant = case$quant,
55
63
  .col = case$col
56
64
  )
65
+ spectfile = file.path(odir, paste0(slugify(sample, tolower = FALSE), ".spect"))
57
66
  png(
58
- file.path(odir, paste0(sample, ".png")),
67
+ spectfile,
59
68
  res = case$devpars$res,
60
69
  width = case$devpars$width,
61
70
  height = case$devpars$height
62
71
  )
63
72
  print(vis(spec_obj))
64
73
  dev.off()
74
+
75
+ add_report(
76
+ list(src = spectfile, name = sample),
77
+ h1 = "Spectratyping",
78
+ h2 = name,
79
+ ui = "table_of_images"
80
+ )
65
81
  }
66
82
  }
67
83
 
68
- print("- Spectratyping")
84
+ add_report(
85
+ list(
86
+ kind = "descr",
87
+ content = "Spectratype is a useful way to represent distributions of genes per sequence length."
88
+ ),
89
+ h1 = "Spectratyping"
90
+ )
91
+
69
92
  spect_dir = file.path(outdir, "spectratyping")
70
93
  dir.create(spect_dir, showWarnings = FALSE)
71
94
 
@@ -1,7 +1,11 @@
1
- print("- Clonotype tracking")
1
+ log_info("")
2
+ log_info("#####################################")
3
+ log_info("# Clonotype tracking #")
4
+ log_info("#####################################")
2
5
 
3
6
  trackings = {{ envs.trackings | r }}
4
7
 
8
+ log_info("Filling up cases ...")
5
9
  if (is.null(trackings$subjects)) {
6
10
  trackings$subjects = c()
7
11
  }
@@ -41,9 +45,11 @@ run_tracking_case = function(casename) {
41
45
  }
42
46
 
43
47
  if (is.null(case$targets)) {
44
- print(paste0(" ", casename, ", skip, no targets"))
48
+ # print(paste0(" ", casename, ", skip, no targets"))
49
+ log_info("- Case: {casename}, skip, no targets")
45
50
  } else {
46
- print(paste0(" ", casename))
51
+ # print(paste0(" ", casename))
52
+ log_info("- Case: {casename}")
47
53
  allsubjects = d$meta %>% pull(case$subject_col) %>% unlist() %>% unique() %>% na.omit()
48
54
  if (is.null(case$subjects) || length(case$subjects) == 0) {
49
55
  subjects = allsubjects
@@ -80,10 +86,33 @@ run_tracking_case = function(casename) {
80
86
  imm_tracking = trackClonotypes(newdata, targets, .col = "aa")
81
87
  }
82
88
 
83
- tracking_png = file.path(tracking_dir, paste0(casename, ".png"))
89
+ tracking_png = file.path(tracking_dir, paste0(slugify(casename), ".png"))
84
90
  png(tracking_png, res=100, height=1000, width=600 + 150 * length(subjects))
85
91
  print(vis(imm_tracking))
86
92
  dev.off()
93
+
94
+ add_report(
95
+ list(
96
+ kind = "descr",
97
+ content = paste0(
98
+ "Clonotype tracking is a popular approach to monitor changes in the frequency of ",
99
+ "clonotypes of interest in vaccination and cancer immunology. ",
100
+ "For example, a researcher can track a clonotype across different time points ",
101
+ "in pre- and post-vaccination repertoires, or analyse the growth of ",
102
+ "malignant clonotypes in a tumor sample."
103
+ )
104
+ ),
105
+ h1 = "Tracking of clonotypes"
106
+ )
107
+
108
+ add_report(
109
+ list(
110
+ src = tracking_png,
111
+ name = if (casename == "DEFAULT") NULL else casename
112
+ ),
113
+ h1 = "Tracking of clonotypes",
114
+ ui = "table_of_images"
115
+ )
87
116
  }
88
117
  }
89
118