Skip to content

Commit bbb51c5

Browse files
committed
Fix broken edge cases for unsufficient data
1 parent a0426ff commit bbb51c5

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

workflow/scripts/download_context.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ dates <- sample.metadata %>%
5252
pull(snakemake@params[["date_column"]]) %>%
5353
as.numeric
5454
window.quantile.offset <- (1 - snakemake@params[["date_window_span"]]) / 2
55-
min.date <- as_date(quantile(dates, window.quantile.offset))
56-
max.date <- as_date(quantile(dates, 1 - window.quantile.offset))
55+
min.date <- as_date(quantile(dates, window.quantile.offset, na.rm = TRUE))
56+
max.date <- as_date(quantile(dates, 1 - window.quantile.offset, na.rm = TRUE))
5757
padded.min.date <- min.date - snakemake@params[["date_window_paddding_days"]]
5858
padded.max.date <- max.date + snakemake@params[["date_window_paddding_days"]]
5959
print(glue("Time window (span={snakemake@params[['date_window_span']]}): {round(interval(min.date, max.date) / days(1))} days (from {min.date} to {max.date})"))

workflow/scripts/report/NV_description.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,24 @@ n_indels <- vcf %>%
448448

449449
n_snv <- length(unique(vcf$variant)) - n_indels
450450
model <- lm(n ~ CollectionDate, data = figur_SNP_table)
451-
cortest <- cor.test(figur_SNP_table$n, as.numeric(figur_SNP_table$CollectionDate))
451+
452+
# Calculate correlation, if possible
453+
if (nrow(figur_SNP_table) > 2) {
454+
p.cor <- cor.test(
455+
figur_SNP_table$n,
456+
as.numeric(figur_SNP_table$CollectionDate)
457+
)$p.value
458+
} else {
459+
p.cor <- NA
460+
}
452461

453462
list(
454463
"INDELS" = n_indels,
455464
"SNV" = n_snv,
456465
"window" = snakemake@params[["window"]],
457466
"step" = snakemake@params[["step"]],
458467
"r2" = summary(model)$r.squared[[1]],
459-
"value" = ifelse(cortest$p.value < 0.001, "< 0.001", cortest$p.value)
468+
"value" = ifelse(p.cor < 0.001, "< 0.001", p.cor)
460469
) %>%
461470
toJSON() %>%
462471
write(snakemake@output[["json"]])

0 commit comments

Comments
 (0)