Open liz-fw opened 11 months ago
early + late detection logic
if (nrow(collect(ots_late)) > 1) {
cli::cli_alert_info("using '{selection_strategy}' to identify a unique assay run")
if (selection_strategy == "positive priority") {
ots_late_priority_results <-
ots_late |> filter(positive_detection) |>
collect()
# if this results in more than one, abort with error
if (nrow(ots_late_priority_results) > 1) {
cli::cli_abort(c(
"x" = "'positive priority' did not identify a unique assay run",
"i" = "try a different strategy or pass plate id of run to use for identification"
))
}
# if this results in no positive then return
else if (nrow(ots_late_priority_results) == 0) {
cli::cli_abort(c(
"x" = "'positive priority' did not yield any results",
"i" = "no results from this query typically means that there are no positive detections for this sample, you can use 'recent priority' to run genetic identification on whatever the most recent sample results are."
))
}
} else if (selection_strategy == "recent priority") {
ots_late_priority_results <-
ots_late |> arrange(desc(created_at)) |>
head(1) |>
collect()
}
} else {
ots_late_priority_results <- collect(ots_late)
}
# positive late negative early --> late/fall run
if (!ots_early_priority_results$positive_detection && ots_late_priority_results$positive_detection) {
return(list(sample_id = sample_id, status_code = "analysis complete", run_type="FAL", early_plate = ots_early_priority_results$plate_run_id, late_plate = ots_late_priority_results$plate_run_id))
}
# positive late and positive early --> HET more testing needed
else if (ots_early_priority_results$positive_detection && ots_late_priority_results$positive_detection) {
return(list(sample_id = sample_id, status_code = "analysis complete", run_type="HET", early_plate = ots_early_priority_results$plate_run_id, late_plate = ots_late_priority_results$plate_run_id))
}
# negative late and positive early --> SPW need ots 16
else if (ots_early_priority_results$positive_detection && !ots_late_priority_results$positive_detection) {
return(list(sample_id = sample_id, status_code = "need ots16", run_type = "SPW", early_plate = ots_early_priority_results$plate_run_id, late_plate = ots_late_priority_results$plate_run_id))
}
# negative late and negative early --> UNK
else if (!ots_early_priority_results$positive_detection && !ots_late_priority_results$positive_detection){
return(list(sample_id = sample_id, status_code = "created", run_type = "UNK", early_plate = ots_early_priority_results$plate_run_id, late_plate = ots_late_priority_results$plate_run_id))
}
else {
cli::cli_abort(c("x" = "uknown combination of test results for {sample_id}, unable to proceed"))
}
winter + spring detection part of the logic:
# positive winter and negative spring ---> WIN
if (!ots_spring_priority_results$positive_detection && ots_winter_priority_results$positive_detection) {
return(list(sample_id = sample_id, status_code = "analysis complete", run_type="WIN",
winter_plate_id = ots_winter_priority_results$plate_run_id, spring_plate_id = ots_spring_priority_results$plate_run_id))
}
# positive winter and positive spring ---> HET
else if (ots_spring_priority_results$positive_detection && ots_winter_priority_results$positive_detection) {
return(list(sample_id = sample_id, status_code = "analysis complete", run_type="HET",
winter_plate_id = ots_winter_priority_results$plate_run_id, spring_plate_id = ots_spring_priority_results$plate_run_id))
}
# negative winter and positive spring --> SPR
else if (ots_spring_priority_results$positive_detection && !ots_winter_priority_results$positive_detection) {
return(list(sample_id = sample_id, status_code = "analysis complete", run_type = "SPR",
winter_plate_id = ots_winter_priority_results$plate_run_id, spring_plate_id = ots_spring_priority_results$plate_run_id))
}
# both negative --> UNK
else if (!ots_spring_priority_results$positive_detection && !ots_winter_priority_results$positive_detection){
return(list(sample_id = sample_id, status_code = "ots16 complete", run_type = "UNK",
winter_plate_id = ots_winter_priority_results$plate_run_id, spring_plate_id = ots_spring_priority_results$plate_run_id))
}
in demo, Sean uploaded the two files and got different results from Emanuel