diff --git a/workflow/scripts/report/NV_description.R b/workflow/scripts/report/NV_description.R index e94a9f3..4d5a592 100644 --- a/workflow/scripts/report/NV_description.R +++ b/workflow/scripts/report/NV_description.R @@ -8,6 +8,22 @@ library(logger) log_threshold(INFO) +empty_vcf <- function() { + tibble( + variant = character(), + REGION = character(), + ALT_FREQ = numeric(), + GFF_FEATURE = character(), + synonimous = character(), + POS = numeric(), + ALT = character(), + NV_class = character(), + NV_colors = character(), + group = character() + ) +} + + # Import file with plots style source(snakemake@params[["design"]]) @@ -150,15 +166,7 @@ log_info("Plotting summary figure for whole genome") if (nrow(vcf) == 0) { log_warn("Whole-genome VCF has no rows") - vcf <- tibble( - variant = character(), - REGION = character(), - ALT_FREQ = numeric(), - GFF_FEATURE = character(), - synonimous = character(), - POS = numeric(), - ALT = character() - ) + vcf <- empty_vcf() } variants <- vcf %>% @@ -312,15 +320,7 @@ window_plot_spike <- window %>% if (nrow(vcf_spike) == 0) { log_warn("Spike VCF has no rows") - vcf_spike <- tibble( - variant = character(), - REGION = character(), - ALT_FREQ = numeric(), - GFF_FEATURE = character(), - synonimous = character(), - POS = numeric(), - ALT = character() - ) + vcf_spike <- empty_vcf() } variants_spike <- vcf_spike %>% @@ -387,6 +387,11 @@ figur_SNP_table <- vcf_snp %>% ) %>% ungroup() +if (nrow(figur_SNP_table) == 0) { + log_warn("Filtered SNP table has no rows") + figur_SNP_table <- empty_vcf() +} + figur_SNP_time <- figur_SNP_table %>% ggplot() + aes(