diff --git a/NAMESPACE b/NAMESPACE index e4b4354..e56cca0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(get_convergence) export(get_lineage_info) export(get_mutation_defs) export(get_res) +export(parse_ivar) export(parse_mutations) export(pos_from_aa) export(provoc) diff --git a/R/provoc_methods.R b/R/provoc_methods.R index bfddfc5..a74da86 100644 --- a/R/provoc_methods.R +++ b/R/provoc_methods.R @@ -1,4 +1,3 @@ - #' Predict using Proportions of Variants of Concern #' #' Takes a named list with an estimate of the proportions and the @@ -6,6 +5,8 @@ #' predict outcomes, and returns results in the same order as the original data. #' #' @param provoc_obj Named list with `proportions` and `variant_matrix`. +#' @param b1 Name of the first sra sample group. +#' @param b2 Name of the second sra sample group. #' @param newdata Not yet implemented. #' @param type Not yet implemented. #' @param se.fit Not yet implemented. @@ -13,24 +14,36 @@ #' @param terms Not yet implemented. #' @param na.action Not yet implemented. #' @return Predicted values in the same order as the input data. -#' @export #' @examples -#' predicted_results <- predict(provoc_obj) -predict.provoc <- function(provoc_obj, +#' library(provoc) +#' data("Baaijens") +#' Baaijens$mutation <- parse_mutations(Baaijens$label) +#' res <- provoc(formula = cbind(count, coverage) ~ B.1.1.7 + B.1.617.2, data = Baaijens) +#' b1 <- Baaijens[Baaijens$sra == unique(Baaijens$sra)[1], ] +#' b2 <- Baaijens[Baaijens$sra == unique(Baaijens$sra)[2], ] +#' predicted_values <- predict.provoc(res, b1, b2) +#' print(predicted_values) +#' @export +predict.provoc <- function( + provoc_obj, + b1, b2, newdata = NULL, type = NULL, dispersion = NULL, terms = NULL) { - if (!"provoc" %in% class(provoc_obj)) { stop("Object must be of class 'provoc'") } + b1_index <- match(b1, provoc_obj$group) + b2_index <- match(b2, provoc_obj$group) + proportions <- as.numeric(provoc_obj$rho) - variant_matrix <- get_varmat(provoc_obj) + variant_matrix <- attr(provoc_obj, "variant_matrix") + if (any(!rownames(variant_matrix) %in% provoc_obj$variant)) { stop("Variant matrix does not match variants in results") } - results <- proportions %*% variant_matrix[provoc_obj$variant, ] + results <- proportions[b1_index] %*% variant_matrix[b2_index, ] return(results) } diff --git a/man/find_mutation_column.Rd b/man/find_mutation_column.Rd new file mode 100644 index 0000000..2a3e090 --- /dev/null +++ b/man/find_mutation_column.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/provoc.R +\name{find_mutation_column} +\alias{find_mutation_column} +\title{Finds the right mutation column in mutation_defs.} +\usage{ +find_mutation_column(data, mutation_defs) +} +\arguments{ +\item{data}{Data frame containing count, coverage, and lineage columns} + +\item{mutation_defs}{Optional mutation definitions} +} +\value{ +A list of length 2 containing the possibly transposed mutation_defs and +the right mutation column. +} +\description{ +Checks the columns of mutation_defs and if not found in columns will check the rows +and transpose mutation_defs. +} diff --git a/man/parse_ivar.Rd b/man/parse_ivar.Rd new file mode 100644 index 0000000..cabb349 --- /dev/null +++ b/man/parse_ivar.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parse_mutations.R +\name{parse_ivar} +\alias{parse_ivar} +\title{Parse Mutations from the ivar pipeline} +\usage{ +parse_ivar(ivar_output) +} +\arguments{ +\item{ivar_output}{A data frame imported from the ivar output. Must have columns POS and ALT} +} +\description{ +Parse Mutations from the ivar pipeline +} diff --git a/man/parse_one_ivar.Rd b/man/parse_one_ivar.Rd new file mode 100644 index 0000000..4313460 --- /dev/null +++ b/man/parse_one_ivar.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parse_mutations.R +\name{parse_one_ivar} +\alias{parse_one_ivar} +\title{Parse mutations from ivar pipeline} +\usage{ +parse_one_ivar(pos, alt) +} +\arguments{ +\item{pos}{The position on the genome} + +\item{alt}{The alternate genotype} +} +\description{ +Parse mutations from ivar pipeline +} diff --git a/man/predict.provoc.Rd b/man/predict.provoc.Rd index b502d47..dcf752d 100644 --- a/man/predict.provoc.Rd +++ b/man/predict.provoc.Rd @@ -6,6 +6,8 @@ \usage{ \method{predict}{provoc}( provoc_obj, + b1, + b2, newdata = NULL, type = NULL, dispersion = NULL, @@ -15,6 +17,10 @@ \arguments{ \item{provoc_obj}{Named list with \code{proportions} and \code{variant_matrix}.} +\item{b1}{Name of the first sra sample group.} + +\item{b2}{Name of the second sra sample group.} + \item{newdata}{Not yet implemented.} \item{type}{Not yet implemented.} @@ -36,5 +42,12 @@ associated variant matrix, performs matrix multiplication to predict outcomes, and returns results in the same order as the original data. } \examples{ -predicted_results <- predict(provoc_obj) +library(provoc) +data("Baaijens") +Baaijens$mutation <- parse_mutations(Baaijens$label) +res <- provoc(formula = cbind(count, coverage) ~ B.1.1.7 + B.1.617.2, data = Baaijens) +b1 <- Baaijens[Baaijens$sra == unique(Baaijens$sra)[1], ] +b2 <- Baaijens[Baaijens$sra == unique(Baaijens$sra)[2], ] +predicted_values <- predict.provoc(res, b1, b2) +print(predicted_values) } diff --git a/man/provoc.Rd b/man/provoc.Rd index d540fe6..595dd16 100644 --- a/man/provoc.Rd +++ b/man/provoc.Rd @@ -10,7 +10,7 @@ provoc( mutation_defs = NULL, by = NULL, update_interval = 20, - verbose = TRUE, + verbose = FALSE, annihilate = FALSE ) } diff --git a/man/variants_similarity.Rd b/man/variants_similarity.Rd index 937247f..b9fdeea 100644 --- a/man/variants_similarity.Rd +++ b/man/variants_similarity.Rd @@ -9,7 +9,7 @@ variants_similarity(data, is_varmat) \arguments{ \item{data}{A dataframe either before or after it has been fused with varmat} -\item{is_varmat}{TRUE if data is a varaint matrix, FALSE if data is a fused dataframe} +\item{is_varmat}{TRUE if data is a variant matrix, FALSE if data is a fused dataframe} } \value{ none