Skip to content

Commit

Permalink
Fix bug with empty cpg set
Browse files Browse the repository at this point in the history
  • Loading branch information
sigven committed Apr 23, 2024
1 parent 7ca2e6b commit b1478db
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 48 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: cpsr
Type: Package
Title: Cancer Predisposition Sequencing Reporter (CPSR)
Version: 1.0.1.9003
Date: 2024-03-10
Date: 2024-04-23
Authors@R:
c(person(given = "Sigve",
family = "Nakken",
Expand Down
2 changes: 1 addition & 1 deletion R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ write_cpsr_output <- function(report,
cpsr_rep_template_path, "cpsr_report.qmd")

if (output_format == "html") {
if(report$content$snv_indel$v_stat_cpg$n < 3000){
if(report$content$snv_indel$v_stat_cpg$n < 15000){
if(file.exists(quarto_input)){

## make temporary directory for quarto report rendering
Expand Down
9 changes: 6 additions & 3 deletions inst/templates/cpsr_report.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ nocite: |
@Martin2019-nq, @Nykamp2017-rj, Dienstmann2015-od
format:
html:
link-external-newwindow: true
embed-resources: true
smooth-scroll: true
page-layout: full
fontsize: 0.92em
fontsize: 0.93em
toc: true
toc_depth: 2
toc-depth: 3
toc-expqand: 3
toc-title: Contents
grid:
body-width: 940px
css: cpsr.css
Expand Down Expand Up @@ -104,7 +107,7 @@ options(scipen = 0)
```{r documentation_cpsr, child='quarto/cpsr_documentation.qmd', eval = TRUE}
```

<br><br>
<br>

<font size="-1">

Expand Down
60 changes: 35 additions & 25 deletions inst/templates/quarto/cpsr_classification.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,30 @@ for (c in c("class1", "class2", "class3", "class4", "class5")) {
tot_variants[[c]][[m]] <- 0
show_class_filters[[c]][[m]] <- F
missing_class_items[[c]][[m]] <- T
if (NROW(callset_cpg[callset_cpg$CPSR_CLASSIFICATION_SOURCE == m &
callset_cpg$FINAL_CLASSIFICATION == path_level,]) > 0) {
tot_variants[[c]][[m]] <-
NROW(callset_cpg[callset_cpg$CPSR_CLASSIFICATION_SOURCE == m &
callset_cpg$FINAL_CLASSIFICATION == path_level,])
}
if (tot_variants[[c]][[m]] > 0) {
show_class_filters[[c]][[m]] <- T
missing_class_items[[c]][[m]] <- F
if(NROW(callset_cpg) > 0){
if (NROW(callset_cpg[callset_cpg$CPSR_CLASSIFICATION_SOURCE == m &
callset_cpg$FINAL_CLASSIFICATION == path_level,]) > 0) {
tot_variants[[c]][[m]] <-
NROW(callset_cpg[callset_cpg$CPSR_CLASSIFICATION_SOURCE == m &
callset_cpg$FINAL_CLASSIFICATION == path_level,])
}
if (tot_variants[[c]][[m]] > 0) {
show_class_filters[[c]][[m]] <- T
missing_class_items[[c]][[m]] <- F
}
}
}
}
cps_report[["content"]][["snv_indel"]]$callset$variant_display$cpg_non_sf <-
cps_report[["content"]][["snv_indel"]]$callset$variant_display$cpg_non_sf |>
dplyr::mutate(CONSEQUENCE = stringr::str_replace_all(CONSEQUENCE,"&", ", ")) |>
dplyr::mutate(CDS_CHANGE = stringr::str_replace_all(CDS_CHANGE,"&", ", "))
if(NROW(cps_report$content$snv_indel$variant_display$cpg_non_sf) > 0){
cps_report[["content"]][["snv_indel"]]$callset$variant_display$cpg_non_sf <-
cps_report[["content"]][["snv_indel"]]$callset$variant_display$cpg_non_sf |>
dplyr::mutate(
CONSEQUENCE = stringr::str_replace_all(CONSEQUENCE,"&", ", ")) |>
dplyr::mutate(
CDS_CHANGE = stringr::str_replace_all(CDS_CHANGE,"&", ", "))
}
tag_gnomad <-
cps_report[["settings"]][["conf"]][["variant_classification"]][["vcftag_gnomad_AF"]]
desc_gnomad <-
Expand All @@ -73,7 +79,11 @@ formula_gnomad <- as.formula(paste0("~", rlang::sym(tag_gnomad)))
* A total of __N = `r tot_variants[['class5']][['CPSR_ACMG']]`__ <i><b>non-ClinVar</b></i> variants (i.e. not submitted to/recorded in ClinVar) are classified with a <i>Pathogenic</i> clinical significance by CPSR (refined ACMG criteria - based on population frequency and variant effect).

::: {.callout-note}
Variants displayed here constitute the top 2000 variants for each of the ClinVar and non-ClinVar variant sets (due to display limitations with client-side tables)

## Note - output limitations

In order to maintain responsiveness of client-side data interaction, variants displayed here constitute the top 2,000 variants for each of the ClinVar and non-ClinVar variant sets.

:::


Expand Down Expand Up @@ -102,7 +112,7 @@ if (missing_class_items[["class5"]][["ClinVar"]] == F |
```{r class5_cpsr_clinvar}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class5']][['ClinVar']]
#| eval: !expr show_class_filters[['class5']][['ClinVar']] == TRUE
cat("\n")
htmltools::br()
Expand Down Expand Up @@ -185,7 +195,7 @@ if (missing_class_items[["class5"]][["ClinVar"]] == T &
```{r class5_cpsr_other}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class5']][['CPSR_ACMG']]
#| eval: !expr show_class_filters[['class5']][['CPSR_ACMG']] == TRUE
variants_class5_other <-
dplyr::filter(
Expand Down Expand Up @@ -286,7 +296,7 @@ if (missing_class_items[["class4"]][["ClinVar"]] == F |
```{r class4_cpsr_clinvar}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class4']][['ClinVar']]
#| eval: !expr show_class_filters[['class4']][['ClinVar']] == TRUE
cat("\n")
htmltools::br()
Expand Down Expand Up @@ -369,7 +379,7 @@ if (missing_class_items[["class4"]][["ClinVar"]] == T &
```{r class4_cpsr_other}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class4']][['CPSR_ACMG']]
#| eval: !expr show_class_filters[['class4']][['CPSR_ACMG']] == TRUE
cat("\n")
htmltools::br()
Expand Down Expand Up @@ -471,7 +481,7 @@ if (missing_class_items[["class3"]][["ClinVar"]] == F |
```{r class3_cpsr_clinvar}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class3']][['ClinVar']]
#| eval: !expr show_class_filters[['class3']][['ClinVar']] == TRUE
cat("\n")
htmltools::br()
Expand Down Expand Up @@ -560,7 +570,7 @@ if (missing_class_items[["class3"]][["ClinVar"]] == T & missing_class_items[["cl
```{r vus_caution_note}
#| echo: false
#| output: asis
#| include: !expr show_class_filters[['class3']][['CPSR_ACMG']]
#| include: !expr show_class_filters[['class3']][['CPSR_ACMG']] == TRUE
htmltools::br()
Expand Down Expand Up @@ -690,7 +700,7 @@ if (missing_class_items[["class2"]][["ClinVar"]] == F |
```{r class2_cpsr_clinvar}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class2']][['ClinVar']]
#| eval: !expr show_class_filters[['class2']][['ClinVar']] == TRUE
cat("\n")
htmltools::br()
Expand Down Expand Up @@ -773,7 +783,7 @@ if (missing_class_items[["class2"]][["ClinVar"]] == T &
```{r class2_cpsr_other}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class2']][['CPSR_ACMG']]
#| eval: !expr show_class_filters[['class2']][['CPSR_ACMG']] == TRUE
cat("\n")
htmltools::br()
Expand Down Expand Up @@ -876,7 +886,7 @@ if (missing_class_items[["class1"]][["ClinVar"]] == F |
```{r class1_cpsr_clinvar}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class1']][['ClinVar']]
#| eval: !expr show_class_filters[['class1']][['ClinVar']] == TRUE
cat("\n")
htmltools::br()
Expand Down Expand Up @@ -959,7 +969,7 @@ if (missing_class_items[["class1"]][["ClinVar"]] == T &
```{r class1_cpsr_other}
#| echo: false
#| output: asis
#| eval: !expr show_class_filters[['class1']][['CPSR_ACMG']]
#| eval: !expr show_class_filters[['class1']][['CPSR_ACMG']] == TRUE
cat("\n")
htmltools::br()
Expand Down
43 changes: 25 additions & 18 deletions inst/templates/quarto/cpsr_summary.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,31 @@ color_clinvar <- color_report
color_novel <- color_report
color_vus <- "#2c313c"
n_clinvar <- cps_report$content$snv_indel$callset$variant_display$cpg_non_sf |>
dplyr::filter(.data$CPSR_CLASSIFICATION_SOURCE == "ClinVar") |>
NROW()
n_novel <- cps_report$content$snv_indel$callset$variant_display$cpg_non_sf |>
dplyr::filter(.data$CPSR_CLASSIFICATION_SOURCE == "CPSR_ACMG") |>
NROW()
n_vus <- cps_report$content$snv_indel$callset$variant_display$cpg_non_sf |>
dplyr::filter(.data$FINAL_CLASSIFICATION == "VUS") |>
NROW()
n_clinvar <- 0
n_novel <- 0
n_vus <- 0
genes_affected <- data.frame()
if(NROW(cps_report$content$snv_indel$callset$variant_display$cpg_non_sf) > 0){
n_clinvar <- cps_report$content$snv_indel$callset$variant_display$cpg_non_sf |>
dplyr::filter(.data$CPSR_CLASSIFICATION_SOURCE == "ClinVar") |>
NROW()
n_novel <- cps_report$content$snv_indel$callset$variant_display$cpg_non_sf |>
dplyr::filter(.data$CPSR_CLASSIFICATION_SOURCE == "CPSR_ACMG") |>
NROW()
n_vus <- cps_report$content$snv_indel$callset$variant_display$cpg_non_sf |>
dplyr::filter(.data$FINAL_CLASSIFICATION == "VUS") |>
NROW()
genes_affected <-
dplyr::filter(
cps_report$content$snv_indel$callset$variant$cpg_non_sf,
.data$FINAL_CLASSIFICATION == "Pathogenic" |
.data$FINAL_CLASSIFICATION == "Likely_Pathogenic") |>
dplyr::select("SYMBOL") |>
dplyr::distinct() |>
head(3)
}
if(n_clinvar == 0){
color_clinvar <- color_none
Expand All @@ -34,15 +50,6 @@ if(n_vus == 0){
color_vus <- color_none
}
genes_affected <-
dplyr::filter(
cps_report$content$snv_indel$callset$variant$cpg_non_sf,
.data$FINAL_CLASSIFICATION == "Pathogenic" |
.data$FINAL_CLASSIFICATION == "Likely_Pathogenic") |>
dplyr::select("SYMBOL") |>
dplyr::distinct() |>
head(3)
genes_value_box <- "None"
if(NROW(genes_affected) > 0){
genes_value_box =
Expand Down

0 comments on commit b1478db

Please sign in to comment.