Skip to content

Commit

Permalink
Handle empty VCFs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmig committed Apr 16, 2024
1 parent f6990de commit f5bbc56
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions workflow/scripts/report/NV_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ vcf <- vcf %>%
synonimous,
POS,
ALT
)
)

# Df with gene length for scheme
notation_empty <- data.frame(
Expand Down Expand Up @@ -141,12 +141,26 @@ npc <- read_csv(snakemake@params[["nsp"]]) %>%
TRUE ~ POS_f
)
) %>%
filter(NSP != "nsp1")
filter(NSP != "nsp1")


# PLOTS
## SUMMARY FIGURE FOR WHOLE GENOME
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()
)
}

variants <- vcf %>%
filter(ALT_FREQ > 0) %>%
ggplot() +
Expand Down Expand Up @@ -257,10 +271,17 @@ ggsave(

# Zoom in in spike
log_info("Plotting summary for variants in the spike")
spike.pos <- window %>%

spike_pos <- window %>%
filter(gen == "S") %>%
pull(position)

vcf_spike <- vcf %>%
filter(
ALT_FREQ > 0,
POS %in% c(min(spike_pos):max(spike_pos))
)

window_plot_spike <- window %>%
filter(gen == "S") %>%
ggplot() +
Expand All @@ -279,7 +300,7 @@ window_plot_spike <- window %>%
label = scales::percent,
limits = c(0, max(window$fractions) + 0.005)
) +
xlim(c(min(spike.pos), max(spike.pos))) +
xlim(c(min(spike_pos), max(spike_pos))) +
scale_color_manual(
values = gene_colors,
guide = "none"
Expand All @@ -289,11 +310,20 @@ window_plot_spike <- window %>%
x = ""
)

variants_spike <- vcf %>%
filter(
ALT_FREQ > 0,
POS %in% c(min(spike.pos):max(spike.pos))
) %>%
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()
)
}

variants_spike <- vcf_spike %>%
ggplot() +
aes(
x = POS,
Expand All @@ -303,7 +333,7 @@ variants_spike <- vcf %>%
alpha = ALT_FREQ
) +
geom_point(size = 3) +
xlim(c(min(spike.pos), max(spike.pos))) +
xlim(c(min(spike_pos), max(spike_pos))) +
scale_color_manual(
labels = NV_names,
values = NV_colors
Expand Down

0 comments on commit f5bbc56

Please sign in to comment.