Skip to content

Commit

Permalink
Report improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolai-vKuegelgen committed Oct 16, 2024
1 parent 1cc5f0a commit 3dd881d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
8 changes: 4 additions & 4 deletions stemcnv_check/scripts/R/R_plotting_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ make_LRR_BAF_plots <- function(
) +
scale_x_continuous(
expand = expansion(),
labels = label_number(big.mark = '..', decimal.mark = ','),
labels = label_number(big.mark = '.', decimal.mark = ','),
limits = c(win_start, win_end),
oob = oob_keep
) +
Expand Down Expand Up @@ -196,7 +196,7 @@ make_LRR_BAF_plots <- function(
theme_classic() +
scale_x_continuous(
expand = expansion(),
labels = label_number(big.mark = '..', decimal.mark = ','),
labels = label_number(big.mark = '.', decimal.mark = ','),
limits = c(win_start, win_end),
position = 'top'
) +
Expand Down Expand Up @@ -225,7 +225,7 @@ make_LRR_BAF_plots <- function(
theme_classic() +
scale_x_continuous(
expand = expansion(),
labels = label_number(big.mark = '..', decimal.mark = ','),
labels = label_number(big.mark = '.', decimal.mark = ','),
limits = c(win_start, win_end),
oob = oob_keep
) +
Expand Down Expand Up @@ -254,7 +254,7 @@ make_LRR_BAF_plots <- function(
theme_classic() +
scale_x_continuous(
expand = expansion(),
labels = label_number(big.mark = '..', decimal.mark = ','),
labels = label_number(big.mark = '.', decimal.mark = ','),
limits = c(win_start, win_end),
oob = oob_keep
) +
Expand Down
4 changes: 2 additions & 2 deletions stemcnv_check/scripts/R/R_table_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@ gene_table_output <- function(
}

hotspot_table_output <- function(
hotspots, plotsection, high_impact_tb, highlight_tb, report_config, out_format, caption = NULL
hotspots, cnv_type, plotsection, high_impact_tb, highlight_tb, report_config, out_format, caption = NULL
){
tb <- bind_rows(
high_impact_tb,
highlight_tb
) %>%
filter(hotspot %in% hotspots)
filter(hotspot %in% hotspots & call_type %in% c('any', cnv_type))

if (out_format == 'html') {
dt <- datatable(
Expand Down
24 changes: 15 additions & 9 deletions stemcnv_check/scripts/report_template.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ make_CNV_plot_section <- function(call.table, plotsection = 'denovo') {
# message(str_glue('N hotspots: {length(res$hotspots)}'))
if (report_config$call.data.and.plots[[plotsection]]$include.hotspot.table & length(res$hotspots)>0) {
res$hotspots %>%
hotspot_table_output(plotsection, high_impact_tb, highlight_tb, report_config, params$out_format) %>%
hotspot_table_output(plotsection, row$CNV_type, high_impact_tb, highlight_tb, report_config, params$out_format) %>%
subchunkify(str_glue('CNV_call.{plotsection}.nr{i}.hotspots'))
cat('\n\n')
}
Expand Down Expand Up @@ -266,12 +266,12 @@ repo_excl_filters <- ifelse(
cat(paste(
'Call designation takes into account the Check_Score thresholds for critical and optoinally reportable level.',
'Additionally, calls having an exclusion filter (i.e. below minimum size, or having a probe coverage gap) ',
'for a specific designation are assigend the next lower level (i.e. critical -> reportable or reportable -> no label).\n',
'The current thresholds and exclsuion filters are:\n',
' - Critical Check_Score:', config$evaluation_settings$CNV_call_categorisation$check_score.critical, '\n',
' - Critical exclusion Filters:', crit_excl_filters, '\n',
' - Reportable Check_Score:', config$evaluation_settings$CNV_call_categorisation$check_score.reportable, '\n',
' - Reportable exclusion Filters: ', repo_excl_filters
'for a specific designation are assigend the next lower level (i.e. critical -> reportable or reportable -> no label).\n\n',
'The current thresholds and exclsuion filters are:\n\n',
' - Critical Check_Score:', config$evaluation_settings$CNV_call_categorisation$check_score.critical, '\n\n',
' - Critical exclusion Filters:', crit_excl_filters, '\n\n',
' - Reportable Check_Score:', config$evaluation_settings$CNV_call_categorisation$check_score.reportable, '\n\n',
' - Reportable exclusion Filters: ', repo_excl_filters, '\n\n'
))
read_excel(
Expand Down Expand Up @@ -401,7 +401,10 @@ denovo_calls.table <- cnv_calls %>%
dplyr::rename(chrom = seqnames, Size = width) %>%
arrange(desc(Check_Score), desc(Size), chrom, start) %>%
filter(sample_id == !!sample_id & Call_label != 'Reference genotype') %>%
filter(!str_detect(FILTER, denovo_filter_regex)) %>%
filter(
!str_detect(FILTER, denovo_filter_regex) |
Call_label %in% report_config$call.data.and.plots$denovo$always_include
) %>%
mutate(i = row_number())
refgt_filter_regex <- ifelse(
Expand All @@ -412,7 +415,10 @@ refgt_filter_regex <- ifelse(
reference_calls.table <- cnv_calls %>%
dplyr::rename(chrom = seqnames, Size = width) %>%
arrange(desc(Check_Score), desc(Size), chrom, start) %>%
filter(sample_id == !!sample_id & Call_label == 'Reference genotype') %>%
filter(
sample_id == !!sample_id & Call_label == 'Reference genotype' |
Call_label %in% report_config$call.data.and.plots$reference_gt$always_include
) %>%
filter(!str_detect(FILTER, refgt_filter_regex)) %>%
mutate(i = row_number())
Expand Down
24 changes: 18 additions & 6 deletions tests/testthat/test_report_table_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ test_that("format_hotspots_to_badge", {
)
})

# hotspot_table_output(hotspots, plotsection, high_impact_tb, highlight_tb, report_config, out_format) %>%
# hotspot_table_output(hotspots, cnv_type, plotsection, high_impact_tb, highlight_tb, report_config, out_format) %>%
test_that("hotspot_table_output", {
hotspots <- c('dummyC', '1p36')
hotspots <- c('DDX11L1', '1p36')
cnv_type <- 'loss'
high_impact_tb <- load_hotspot_table(config, 'HighImpact')
highlight_tb <- tibble()
# these aren't used so far
Expand Down Expand Up @@ -109,7 +110,7 @@ test_that("hotspot_table_output", {
escape = FALSE
)

hotspot_table_output(hotspots, plotsection, high_impact_tb, highlight_tb, report_config, 'html') %>%
hotspot_table_output(hotspots, cnv_type, plotsection, high_impact_tb, highlight_tb, report_config, 'html') %>%
expect_equal(expected)

# test non-html output
Expand All @@ -118,7 +119,7 @@ test_that("hotspot_table_output", {
dplyr::rename(dois = description_doi) %>%
rename_with(format_column_names) %>%
kable()
hotspot_table_output(hotspots, plotsection, high_impact_tb, highlight_tb, report_config, 'not-html') %>%
hotspot_table_output(hotspots, cnv_type, plotsection, high_impact_tb, highlight_tb, report_config, 'not-html') %>%
expect_equal(expected)

# test with highlight table
Expand All @@ -133,7 +134,7 @@ test_that("hotspot_table_output", {
dplyr::rename(dois = description_doi) %>%
rename_with(format_column_names) %>%
kable()
hotspot_table_output(hotspots, plotsection, high_impact_tb.no_ov, highlight_tb, report_config, 'not-html') %>%
hotspot_table_output(hotspots, cnv_type, plotsection, high_impact_tb.no_ov, highlight_tb, report_config, 'not-html') %>%
expect_equal(expected)
# test with same hotspot in both HighImpact and highlight table
expected <- expected_tb %>%
Expand All @@ -157,6 +158,17 @@ test_that("hotspot_table_output", {
rownames = FALSE,
escape = FALSE
)
hotspot_table_output(hotspots, plotsection, high_impact_tb, highlight_tb, report_config, 'html') %>%
hotspot_table_output(hotspots, cnv_type, plotsection, high_impact_tb, highlight_tb, report_config, 'html') %>%
expect_equal(expected)
# test with only partially matching cnv_type
cnv_type <- 'LOH'
expected <- expected_tb %>%
filter(hotspot == 'DDX11L1') %>%
select(hotspot, call_type, list_name, description, check_score, description_doi) %>%
dplyr::rename(dois = description_doi) %>%
rename_with(format_column_names) %>%
kable()
hotspot_table_output(hotspots, cnv_type, plotsection, high_impact_tb, highlight_tb, report_config, 'not-html') %>%
expect_equal(expected)

})

0 comments on commit 3dd881d

Please sign in to comment.