/
02d_manual_use_r.Rmd
293 lines (230 loc) · 10.9 KB
/
02d_manual_use_r.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Usage (R API) {#manual-use-r}
The following examples illustrate the functionality of {biodosetools}'s R API to perform dose-effect fitting and dose estimation for the dicentric and translocation assays. The equivalent examples using the {shiny} user interface can be found in Chapter \@ref(manual-use-shiny).
The full {biodosetools} R API reference detailing the available functions and parameters can be found on the project's website at https://biodosetools-team.github.io/biodosetools/reference/.
## Dicentrics dose-effect fitting
### Input count data
The first step is to input the count data. This step is accomplished in R by calling the `calculate_aberr_table()` function. This will calculate the total number of cells ($N$), total number of aberrations ($X$), as well as mean ($\bar{y}$), variance ($\sigma^{2}$), dispersion index ($\sigma^{2}/\bar{y}$), and $u$-value.
```{r dic-count-data}
count_data <- system.file("extdata", "count-data-barquinero-1995.csv",
package = "biodosetools"
) |>
utils::read.csv() |>
calculate_aberr_table(type = "count")
```
```{r dic-count-data-r}
count_data
```
### Perform fitting
To perform the fitting in R we call the `fit()` function, whilst selecting the appropriate `aberr_module` (`"dicentrics"` in this example), `model_formula` (`"lin-quad"` or `"lin"` for LQ or L models, respectively), and `model_family` (`"automatic"`, `"poisson"`, or `"quasipoisson"`) parameters:
```{r dic-fit-results}
fit_results <- fit(
count_data = count_data,
model_formula = "lin-quad",
model_family = "automatic",
aberr_module = "dicentrics"
)
```
The `fit_results` object is a list that contains all necessary information about the count data as well as options selected when performing the fitting. This is a vital step to ensure traceability and reproducibility. Below we can see its elements:
```{r dic-fit-results-names}
names(fit_results)
```
In particular, we can see how `fit_coeffs` matches the results obtained in the UI (Figure \@ref(fig:sc-dic-fit-04)):
```{r dic-fit-coeffs-r}
fit_results$fit_coeffs
```
To visualise the dose-effect curve, we call the `plot_fit_dose_curve()` function:
```{r dic-fit-dose-curve, out.width="100%", fig.dpi=300, fig.align="center", fig.height=3, fig.width=6, fig.cap="Plot of dose-effect curve generated by {biodosetools}. The grey shading indicates the uncertainties associated with the calibration curve."}
plot_fit_dose_curve(
fit_results,
aberr_name = "Dicentrics"
)
```
## Dicentrics dose estimation
### Input case data
Next we can choose to either load the case data from a file or to input the data manually. The data is then parsed in R by calling the `calculate_aberr_table()` function. This will calculate the total number of cells ($N$), total number of aberrations ($X$), as well as mean ($\bar{y}$), standard error ($\sigma$), dispersion index ($\sigma^{2}/\bar{y}$), and $u$-value.
```{r dic-case-data}
case_data <- system.file("extdata", "cases-data-partial.csv",
package = "biodosetools"
) |>
utils::read.csv(header = TRUE) |>
calculate_aberr_table(
type = "case",
assessment_u = 1,
aberr_module = "dicentrics"
)
```
```{r dic-case-data-r}
case_data
```
### Perform dose estimation
Finally, to perform the dose estimation in R we can call the adequate `estimate_*()` functions and parameters depending on the characteristics of the accident. In this example, we will use `estimate_whole_body_merkle()` and `estimate_partial_body_dolphin()`. First of all, however, we will need to load the fit coefficients and variance-covariance matrix from the previously calculated `fit_results`:
```{r dic-parse-fit-results}
fit_coeffs <- fit_results$fit_coeffs
fit_var_cov_mat <- fit_results$fit_var_cov_mat
```
After that is done, we can simply call `estimate_whole_body_merkle()` and `estimate_partial_body_dolphin()`:
```{r dic-dose-estimation-whole}
results_whole_merkle <- estimate_whole_body_merkle(
case_data,
fit_coeffs,
fit_var_cov_mat,
conf_int_yield = 0.83,
conf_int_curve = 0.83,
protracted_g_value = 1,
aberr_module = "dicentrics"
)
```
```{r dic-dose-estimation-partial}
results_partial <- estimate_partial_body_dolphin(
case_data,
fit_coeffs,
fit_var_cov_mat,
conf_int = 0.95,
gamma = 1 / 2.7,
aberr_module = "dicentrics"
)
```
To visualise the estimated doses, we call the `plot_estimated_dose_curve()` function:
```{r dic-estimated-dose-curve, out.width="100%", fig.dpi=300, fig.align="center", fig.height=3, fig.width=6, fig.cap="Plot of estimated doses generated by {biodosetools}. The grey shading indicates the uncertainties associated with the calibration curve."}
plot_estimated_dose_curve(
est_doses = list(
whole = results_whole_merkle,
partial = results_partial
),
fit_coeffs,
fit_var_cov_mat,
protracted_g_value = 1,
conf_int_curve = 0.95,
aberr_name = "Dicentrics"
)
```
## Translocations dose-effect fitting
### Calculate genomic conversion factor
To be able to fit the equivalent full genome dose-effect curve, we need to calculate the genomic conversion factor. To calculate the genomic conversion factor in R we call the `calculate_genome_factor()` function:
```{r trans-genome-factor-fit}
genome_factor <- calculate_genome_factor(
dna_table = dna_content_fractions_morton,
chromosome = c(1, 4, 11),
color = rep("Red", 3),
sex = "female"
)
```
```{r trans-genome-factor-fit-r}
genome_factor
```
### Input count data
Once the genomic conversion factor has been calculated, we can input the count data. This step is accomplished in R by calling the `calculate_aberr_table()` function. This will calculate the total number of cells ($N$), total number of aberrations ($X$), as well as mean ($\bar{y}$), variance ($\sigma^{2}$), dispersion index ($\sigma^{2}/\bar{y}$), and $u$-value.
```{r trans-count-data}
count_data <- system.file("extdata", "count-data-rodriguez-2004.csv", package = "biodosetools") |>
utils::read.csv() |>
calculate_aberr_table(type = "count") |>
dplyr::mutate(N = N * genome_factor)
```
```{r trans-count-data-r}
count_data
```
### Perform fitting
To perform the fitting in R we call the `fit()` function, whilst selecting the appropriate `aberr_module` (`"translocations"` in this example), `model_formula` (`"lin-quad"` or `"lin"` for LQ or L models, respectively), and `model_family` (`"automatic"`, `"poisson"`, or `"quasipoisson"`) parameters:
```{r trans-fit-results}
fit_results <- fit(
count_data = count_data,
model_formula = "lin-quad",
model_family = "automatic",
fit_link = "identity",
aberr_module = "translocations"
)
```
The `fit_results` object is a list that contains all necessary information about the count data as well as options selected when performing the fitting. This is a vital step to ensure traceability and reproducibility. Below we can see its elements:
```{r trans-fit-results-names}
names(fit_results)
```
In particular, we can see how `fit_coeffs` matches the results obtained in the UI (Figure \@ref(fig:sc-trans-fit-04)):
```{r trans-fit-coeffs-r}
fit_results$fit_coeffs
```
To visualise the dose-effect curve, we call the `plot_fit_dose_curve()` function:
```{r trans-fit-dose-curve, out.width="100%", fig.dpi=300, fig.align="center", fig.height=3, fig.width=6, fig.cap="Plot of dose-effect curve generated by {biodosetools}. The grey shading indicates the uncertainties associated with the calibration curve."}
plot_fit_dose_curve(
fit_results,
aberr_name = "Translocations"
)
```
## Translocations dose estimation
### Calculate genomic conversion factor
To be able to fit the equivalent full genome case data, we need to calculate the genomic conversion factor.
To do this, in the "Stain color options" box we select the sex of the individual, and the list of chromosomes and stains used for the translocation assay. Clicking on "Generate table" will show a table in the "Chromosome data" box in which we select the chromosome-stain pairs. Clicking on the "Calculate fraction" will calculate the genomic conversion factor.
To calculate the genomic conversion factor in R we call the `calculate_genome_factor()` function:
```{r trans-genome-factor-est}
genome_factor <- calculate_genome_factor(
dna_table = dna_content_fractions_morton,
chromosome = c(1, 2, 3, 4, 5, 6),
color = c("Red", "Red", "Green", "Red", "Green", "Green"),
sex = "male"
)
```
```{r}
genome_factor
```
### Input case data
Next we can choose to either load the case data from a file or to input the data manually. The data is then parsed in R by calling the `calculate_aberr_table()` function. If needed, the user can select to use confounders (either using Sigurdson's method, or by inputting the translocation frequency per cell). Once the table is generated and filled, the "Calculate parameters" button will calculate the total number of cells ($N$), total number of aberrations ($X$), as well as mean ($\bar{F}_{p}$), standard error ($\sigma_{p}$), dispersion index ($\sigma^{2}/\bar{y}$), $u$-value, expected translocation rate ($X_{c}$), full genome mean ($\bar{F}_{g}$), and full genome error ($\sigma_{g}$).
```{r trans-case-data}
case_data <- data.frame(
C0 = 288, C1 = 52, C2 = 9, C3 = 1
) |>
calculate_aberr_table(
type = "case",
assessment_u = 1,
aberr_module = "translocations"
) |>
dplyr::mutate(
Xc = calculate_trans_rate_sigurdson(
cells = N,
genome_factor = genome_factor,
age_value = 30,
smoker_bool = TRUE
),
Fg = (X - Xc) / (N * genome_factor),
Fg_err = Fp_err / sqrt(genome_factor)
)
```
```{r}
case_data
```
### Perform dose estimation
Finally, to perform the dose estimation in R we can call the adequate `estimate_*()` functions and parameters depending on the characteristics of the accident. In this example, we will use `estimate_whole_body_delta()`. First of all, however, we will need to load the fit coefficients and variance-covariance matrix from the previously calculated `fit_results`:
```{r trans-parse-fit-results}
fit_coeffs <- fit_results$fit_coeffs
fit_var_cov_mat <- fit_results$fit_var_cov_mat
```
Since we have a protracted exposure, we need to calculate the value of $G(x)$:
```{r trans-protracted-g-value}
protracted_g_value <- protracted_g_function(
time = 0.5,
time_0 = 2
)
```
```{r}
protracted_g_value
```
After that is done, we can simply call `estimate_whole_body_delta()`:
```{r trans-dose-estimation-whole-delta}
results_whole_delta <- estimate_whole_body_delta(
case_data,
fit_coeffs,
fit_var_cov_mat,
conf_int = 0.95,
protracted_g_value,
aberr_module = "translocations"
)
```
To visualise the estimated doses, we call the `plot_estimated_dose_curve()` function:
```{r trans-estimated-dose-curve, out.width="100%", fig.dpi=300, fig.align="center", fig.height=3, fig.width=6, fig.cap="Plot of estimated doses generated by {biodosetools}. The grey shading indicates the uncertainties associated with the calibration curve."}
plot_estimated_dose_curve(
est_doses = list(whole = results_whole_delta),
fit_coeffs,
fit_var_cov_mat,
protracted_g_value,
conf_int_curve = 0.95,
aberr_name = "Translocations"
)
```