Skip to content

Commit 70322c6

Browse files
committed
Reword nucleotide diversity section and update plot
1 parent 8bd4fdc commit 70322c6

2 files changed

Lines changed: 31 additions & 32 deletions

File tree

template.qmd

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,11 @@ output-file: report.html
5252
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap" rel="stylesheet">
5353
</head>
5454

55-
```{r funcs, echo = F, message = F, include = F}
56-
display.num <- function(n) {
57-
sci <- if (n < 1e-3 || n > 1e4) {
58-
sub("e\\+?(-?)(\\d+)", " × 10^{\\1\\2}",
59-
formatC(n, format = "e", digits = 3))
60-
} else {
61-
formatC(n, format = "f", digits = 5)
62-
}
55+
```{r setup, echo = F, message = F, include = F}
56+
display.num <- function(n, digits) {
57+
format(n, digits = digits, nsmall = digits)
6358
}
59+
Sys.setlocale("LC_ALL", "English")
6460
```
6561

6662
```{r read, echo = F, message = F, include = F}
@@ -81,7 +77,7 @@ stats <- append(
8177
)
8278
correlation <- stats[["r2"]]
8379
sub_rate <- stats[["sub_rate"]]
84-
sub_rate <- round(sub_rate, digits = 2)
80+
sub_rate <- display.num(sub_rate, 2)
8581
p_value_lm <- stats[["pvalue"]]
8682
8783
# NV counts
@@ -183,29 +179,28 @@ samples is squared.](`r params$tree_ml`){#fig-tree_ml}
183179
### Nucleotide diversity comparison
184180

185181
Nucleotide diversity (π) has been calculated for $`r div_values[["boot.reps"]]`$ random
186-
sample subsets of size $`r div_values[["sample.size"]]`$, extracted
187-
from the context dataset. The distribution of the nuclotide diversity is assumed to
188-
`r div_values[["norm.text"]]` be normal after performing a Shapiro-Wilk test
189-
(p-value of $`r div_values[["normal.pvalue"]]`$).
190-
191-
The nucleotide diversity of the target samples is $`r format(div_values[["diversity"]], scientific = TRUE) `$ (vertical line in @fig-div).
192-
Assuming the independence of the context samples, the `r div_values[["type.test"]]`
193-
p-value of the context samples having a nucleotide diversity (smooth curve in @fig-div)
194-
as low as that of the target dataset is $`r div_values[["p.value"]]`$.
195-
196-
![Analysis of the nucleotide diversity (π). The smooth curve describes
197-
a normal distribution with the same mean and standard deviation as the distribution
198-
of π from $`r div_values[["boot.reps"]]`$ subsets of $`r div_values[["sample.size"]]`$
199-
sequences from the context. The vertical line indicates the π value of the
200-
target samples.](`r params$div`){#fig-div}
182+
subsets of size $`r div_values[["sample.size"]]`$ drawn from the context dataset.
183+
A Shapiro–Wilk test indicates the distribution is `r div_values[["norm.text"]]`
184+
normal (p-value of $`r div_values[["normal.pvalue"]]`$).
185+
186+
The nucleotide diversity of the target samples is $`r display.num(div_values[["diversity"]], 3)`$
187+
(vertical line in @fig-div). Assuming the context subsets are independent, the
188+
`r div_values[["type.test"]]` test gives a p-value of $`r display.num(div_values[["p.value"]], 3)`$
189+
for observing a nucleotide diversity as low as that of the target samples.
190+
191+
![Distribution of nucleotide diversity (π) calculated from $`r div_values[["boot.reps"]]`$
192+
random subsets of $`r div_values[["sample.size"]]`$ sequences from the context dataset.
193+
The shaded area shows the empirical density; the overlaid curve is the normal distribution
194+
with the same mean and standard deviation.
195+
The vertical line marks the π value of the target samples.](`r params$div`){#fig-div}
201196

202197
## Evolutionary trajectory of the serially-sampled SARS-CoV-2 infection
203198

204199
### Number of polymorphic sites
205200

206201
Sites with minor allele frequency $> `r params$min_ivar_freq`$ are considered polymorphic.
207202
The linear association between the collection date of the samples and the number of
208-
polymorphic sites has an $R^2$ of $`r nv.counts[["r2"]]`$ and a p-value of
203+
polymorphic sites has an $R^2$ of $`r display.num(nv.counts[["r2"]], 4)`$ and a p-value of
209204
$`r nv.counts[["value"]]`$ (@fig-fig_cor_snp).
210205

211206
![Number of polymorphic sites along time. The
@@ -267,7 +262,7 @@ frequency-weighted distances.](`r params$tree`){#fig-tree}
267262

268263
To estimate the evolutionary rate, root-to-tip distances measured on the previous
269264
tree (@fig-tree) have been correlated with time, obtaining a $R^2$ of
270-
$`r correlation`$ and a p-value of $`r p_value_lm`$. The estimated evolutionary
265+
$`r display.num(correlation, 4)`$ and a p-value of $`r p_value_lm`$. The estimated evolutionary
271266
rate is $`r sub_rate`$ number of changes per year (@fig-tempest).
272267

273268
![Scatterplot depicting the relationship between root-to-tip

workflow/scripts/report/diversity_plot.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,25 @@ p <- data.frame(pi = divs) %>%
3131
fill = DIVERSITY_PALETTE["density_fill"],
3232
alpha = 0.7,
3333
bw = 0.000001,
34+
linewidth = 0.5,
3435
color = DIVERSITY_PALETTE["density_color"]
3536
) +
36-
geom_vline(
37-
xintercept = json$diversity,
38-
color = DIVERSITY_PALETTE["value_color"]
39-
) +
4037
stat_function(
4138
fun = dnorm,
4239
args = list(mean = mean(divs), sd = sd(divs)),
43-
color = DIVERSITY_PALETTE["dnorm_color"]
40+
color = DIVERSITY_PALETTE["dnorm_color"],
41+
linewidth = 1
42+
) +
43+
geom_vline(
44+
xintercept = json$diversity,
45+
color = DIVERSITY_PALETTE["value_color"],
46+
linewidth = 1
4447
) +
4548
labs(
4649
x = "π",
4750
y = "Density"
48-
)
51+
) +
52+
xlim(0, NA)
4953

5054
ggsave(
5155
filename = snakemake@output[["plot"]],

0 commit comments

Comments
 (0)