library(dplyr)
library(ggplot2)
aberr_module <- params$aberr_module

parsed_title <- dplyr::case_when(
  aberr_module == "dicentrics" ~ "Dicentrics curve fitting report",
  aberr_module == "translocations" ~ "Translocation FISH curve fitting report",
  aberr_module == "micronuclei" ~ "Micronuclei curve fitting report"
)

title: r parsed_title

pander::panderOptions("table.style", "grid")
pander::panderOptions("table.split.table", Inf)
pander::panderOptions(
  "table.alignment.default",
  function(df) {
    ifelse(sapply(df, is.numeric), "center", "left")
  }
)

render_table <- function(x, ...) {
  pander::pander(x)
  # TODO: handle alignments via justify parameter
}
# General parameters
count_data <- params$fit_results_list[["fit_raw_data"]]
fit_model_statistics <- params$fit_results_list[["fit_model_statistics"]]
fit_model_summary <- params$fit_results_list[["fit_model_summary"]]
fit_coeffs <- params$fit_results_list[["fit_coeffs"]]
fit_var_cov_mat <- params$fit_results_list[["fit_var_cov_mat"]]
fit_cor_mat <- params$fit_results_list[["fit_cor_mat"]]
fit_formula_tex <- params$fit_results_list[["fit_formula_tex"]]
gg_curve <- params$fit_results_list[["gg_curve"]]
irr_conds <- params$fit_results_list[["irr_conds"]]
# detection_lims <- params$fit_results_list[["detection_lims"]]

# Translocations
genome_factor <- params$fit_results_list[["genome_factor"]]
chromosome_table <- params$fit_results_list[["chromosome_table"]]
trans_sex <- params$fit_results_list[["trans_sex"]]
frequency_select <- params$fit_results_list[["frequency_select"]]

r if (aberr_module == "translocations") {"# Chromosome data"}

r if (aberr_module == "translocations") { paste("The analysed blood sample comes from a", trans_sex, "individual.") }

if (aberr_module == "translocations") {
  num_cols <- as.numeric(ncol(chromosome_table))

  chromosome_table %>%
    dplyr::mutate(
      dplyr::across(
        .cols = dplyr::everything(),
        .fns = function(x) {
          x <- ifelse(is.na(x) | x == "FALSE", "", x)
          x <- ifelse(x == "TRUE", "$\\checkmark$", x)
          return(x)
        }
      )
    ) %>%
    render_table(align =  "c")
}

r if (aberr_module == "translocations") { if (num_cols == 1) { "where each chromosome was stained using M-FISH." } }

Count data used

data <- count_data %>%
  biodosetools:::fix_count_data_names(type = "count", output = "kable")

data %>% 
  render_table(align = "c")
# TODO: handle u > 1.96 highlighting

Results

Fit formula

r paste0("$$", fit_formula_tex, "$$")

Model

r gsub("<=", "$\\\\leq$", fit_model_summary)

r if (aberr_module == "translocations") {"## Translocation frequency"}

r if (aberr_module == "translocations") { paste("The fitting was performed using the ") } r if (aberr_module == "translocations") { if (frequency_select == "full_gen_freq") { paste("full genome translocation frequency.") } else if (frequency_select == "measured_freq") { paste("translocation frequency measured by FISH.") } }

r if (aberr_module == "translocations") {"## Genomic conversion factor"}

r if (aberr_module == "translocations") { paste0("The genomic conversion factor to full genome is ", as.character(round(genome_factor, 3)), ".") }

Coefficients

fit_coeffs %>%
  formatC(format = "e", digits = 3) %>%
  as.data.frame() %>%
  biodosetools:::fix_coeff_names(type = "rows", output = "kable") %>%
  render_table(align = "c")

Model-level statistics

fit_model_statistics %>%
  formatC(format = "f", digits = 3) %>%
  as.data.frame() %>%
  dplyr::mutate(df = as.integer(df)) %>%
  render_table(align = "c")

Correlation matrix

fit_cor_mat %>%
  biodosetools:::fix_coeff_names(type = "rows", output = "kable") %>%
  biodosetools:::fix_coeff_names(type = "cols", output = "kable") %>%
  formatC(format = "f", digits = 3) %>%
  as.data.frame() %>%
  render_table(align = "c")

Variance-covariance matrix

fit_var_cov_mat %>%
  biodosetools:::fix_coeff_names(type = "rows", output = "kable") %>%
  biodosetools:::fix_coeff_names(type = "cols", output = "kable") %>%
  formatC(format = "e", digits = 3) %>%
  as.data.frame() %>%
  render_table(align = "c")

Irradiation conditions

data.frame(
  matrix(
    unlist(irr_conds),
    nrow = length(irr_conds),
    byrow = TRUE
  )
) %>%
  `colnames<-`(c("Characteristic", "Details")) %>%
  dplyr::mutate(
    Details = ifelse(Details == "", "Not specified", Details)
  ) %>%
  render_table(align = "l")

Curve plot

gg_curve


biodosimetry-uab/biodosetools documentation built on Jan. 26, 2024, 5:36 p.m.