diff --git a/DESCRIPTION b/DESCRIPTION index bc52239..19367c6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,9 +2,15 @@ Package: scConform Type: Package Title: Conformal Inference For Cell Type Annotation Version: 0.99.1 -Authors@R: person("Corbetta", "Daniela", +Authors@R: c( + person("Daniela", "Corbetta", email = "daniela.corbetta@phd.unipd.it", - role = c("aut", "cre")) + role = c("aut", "cre")), + person("Tram", "Nguyen", role = "ctb"), + person("Anthony", "Christidis", role = "ctb"), + person("Nitesh", "Turaga", role = "ctb"), + person("Ludwig", "Geistlinger", role = "ctb") + ) Description: Builds prediction interval for cell type annotation using conformal inference and conformal risk control. It provides two main methods. The first one gives prediction intervals with diff --git a/NAMESPACE b/NAMESPACE index db9fdc1..9526e9d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,8 @@ # Generated by roxygen2: do not edit by hand +export(getCommonAncestor) export(getPredictionSets) export(plotResult) -export(returnCommonAncestor) import(Rgraphviz) importFrom(BiocParallel,SerialParam) importFrom(BiocParallel,bplapply) diff --git a/R/returnCommonAncestor.R b/R/getCommonAncestor.R similarity index 92% rename from R/returnCommonAncestor.R rename to R/getCommonAncestor.R index 2ab2cf1..bf3823d 100644 --- a/R/returnCommonAncestor.R +++ b/R/getCommonAncestor.R @@ -16,12 +16,12 @@ #' ) #' # Let's consider this prediction set #' pred_set <- c("golden", "labrador", "cocker") -#' com_anc <- returnCommonAncestor(pred_set, onto) +#' com_anc <- getCommonAncestor(pred_set, onto) #' @importFrom igraph V distances degree #' @export # Function to return the common ancestor instead of the single leaf nodes -returnCommonAncestor <- function(pred_set, onto) { +getCommonAncestor <- function(pred_set, onto) { com_anc <- Reduce(intersect, lapply(pred_set, function(node) { .ancestors(node, onto) })) diff --git a/R/getPredictionSets.R b/R/getPredictionSets.R index 49d9176..1f865f4 100644 --- a/R/getPredictionSets.R +++ b/R/getPredictionSets.R @@ -25,7 +25,7 @@ #' @param follow_ontology If \code{TRUE}, then the function returns hierarchical #' prediction sets that follow the cell ontology structure. If \code{FALSE}, it #' returns classical conformal prediction sets. See details. -#' @param resample_cal Should the calibration dataset be resampled according to +#' @param resample Should the calibration dataset be resampled according to #' the estimated relative frequencies of cell types in the query data? #' @param labels labels of different considered cell types. Necessary if #' \code{onto=NULL}, otherwise they are set equal to the leaf nodes of the @@ -38,7 +38,7 @@ #' @param pr_name name of the colData variable in the returned #' SingleCellExperiment object that will contain the prediction #' sets. The default name is \code{pred.set}. -#' @param simplify_pred if \code{TRUE}, the output will be the common ancestor +#' @param simplify if \code{TRUE}, the output will be the common ancestor #' of the labels inserted into the prediction set. If \code{FALSE} (default), #' the output will be the set of the leaf labels. #' @param BPPARAM BiocParallel instance for parallel computing. Default is @@ -136,7 +136,7 @@ #' onto = NULL, #' alpha = 0.1, #' follow_ontology = FALSE, -#' resample_cal = FALSE, +#' resample = FALSE, #' labels = cell_types, #' return_sc = FALSE #' ) @@ -151,11 +151,11 @@ getPredictionSets <- function( x_query, x_cal, y_cal, onto = NULL, alpha = 0.1, lambdas = seq(0.001, 0.999, length.out = 100), follow_ontology = TRUE, - resample_cal = FALSE, + resample = FALSE, labels = NULL, return_sc = NULL, pr_name = "pred.set", - simplify_pred = FALSE, + simplify = FALSE, BPPARAM = SerialParam()) { ## Sanity checks @@ -187,8 +187,8 @@ getPredictionSets <- function( } } - if (!follow_ontology & simplify_pred) { - stop("If follow_ontology=FALSE, please set simplify_pred=FALSE") + if (!follow_ontology & simplify) { + stop("If follow_ontology=FALSE, please set simplify=FALSE") } ## If labels parameter is NULL, retrieve labels from the ontology @@ -210,7 +210,7 @@ getPredictionSets <- function( p_cal <- x_cal } - if (!resample_cal) { + if (!resample) { if (follow_ontology) { pred_sets <- .getHierarchicalPredSets( p_cal = p_cal, p_test = p_query, @@ -227,7 +227,7 @@ getPredictionSets <- function( } } - if (resample_cal) { + if (resample) { data <- .resampleTwo( p_cal = p_cal, p_test = p_query, y_cal = y_cal, labels = labels @@ -272,11 +272,11 @@ getPredictionSets <- function( } ## Transform prediction with leaf nodes to prediction sets with the - ## common ancestor if simplify_pred=TRUE - if (simplify_pred) { + ## common ancestor if simplify=TRUE + if (simplify) { pred_sets1 <- vapply( pred_sets, - function(x) returnCommonAncestor(x, onto), + function(x) getCommonAncestor(x, onto), character(1) ) ## Check for ramification. If there is a ramification in the ontology diff --git a/man/returnCommonAncestor.Rd b/man/getCommonAncestor.Rd similarity index 80% rename from man/returnCommonAncestor.Rd rename to man/getCommonAncestor.Rd index c0dbfb1..3c3ddda 100644 --- a/man/returnCommonAncestor.Rd +++ b/man/getCommonAncestor.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/returnCommonAncestor.R -\name{returnCommonAncestor} -\alias{returnCommonAncestor} +% Please edit documentation in R/getCommonAncestor.R +\name{getCommonAncestor} +\alias{getCommonAncestor} \title{Return the common ancestor of the labels in the prediction set} \usage{ -returnCommonAncestor(pred_set, onto) +getCommonAncestor(pred_set, onto) } \arguments{ \item{pred_set}{character vector containing the labels in the prediction set} @@ -29,5 +29,5 @@ onto <- graph_from_literal( ) # Let's consider this prediction set pred_set <- c("golden", "labrador", "cocker") -com_anc <- returnCommonAncestor(pred_set, onto) +com_anc <- getCommonAncestor(pred_set, onto) } diff --git a/man/getPredictionSets.Rd b/man/getPredictionSets.Rd index 2afce38..95802b1 100644 --- a/man/getPredictionSets.Rd +++ b/man/getPredictionSets.Rd @@ -12,11 +12,11 @@ getPredictionSets( alpha = 0.1, lambdas = seq(0.001, 0.999, length.out = 100), follow_ontology = TRUE, - resample_cal = FALSE, + resample = FALSE, labels = NULL, return_sc = NULL, pr_name = "pred.set", - simplify_pred = FALSE, + simplify = FALSE, BPPARAM = SerialParam() ) } @@ -47,7 +47,7 @@ only when \code{follow_ontology=TRUE}.} prediction sets that follow the cell ontology structure. If \code{FALSE}, it returns classical conformal prediction sets. See details.} -\item{resample_cal}{Should the calibration dataset be resampled according to +\item{resample}{Should the calibration dataset be resampled according to the estimated relative frequencies of cell types in the query data?} \item{labels}{labels of different considered cell types. Necessary if @@ -64,7 +64,7 @@ SpatialExperiment object and to \code{FALSE} when \code{x_query} is a matrix.} SingleCellExperiment object that will contain the prediction sets. The default name is \code{pred.set}.} -\item{simplify_pred}{if \code{TRUE}, the output will be the common ancestor +\item{simplify}{if \code{TRUE}, the output will be the common ancestor of the labels inserted into the prediction set. If \code{FALSE} (default), the output will be the set of the leaf labels.} @@ -167,7 +167,7 @@ conf_sets <- getPredictionSets( onto = NULL, alpha = 0.1, follow_ontology = FALSE, - resample_cal = FALSE, + resample = FALSE, labels = cell_types, return_sc = FALSE ) diff --git a/vignettes/scConform.Rmd b/vignettes/scConform.Rmd index d80fe6a..6610854 100644 --- a/vignettes/scConform.Rmd +++ b/vignettes/scConform.Rmd @@ -452,7 +452,7 @@ spe_query <- getPredictionSets( follow_ontology = TRUE, pr_name = "pred_set_hier", BPPARAM = MulticoreParam(workers = 2), - simplify_pred = FALSE + simplify = FALSE ) # See the first six prediction sets @@ -473,14 +473,14 @@ mean(cvg1) As an alternative, we can choose to return only the common ancestor, instead of the entire set of predicted labels. This can be done directly in the -function by setting `simplify_pred=TRUE`. +function by setting `simplify=TRUE`. Alternatively, we can convert the obtained prediction sets invoking -the function `returnCommonAncestor`. +the function `getCommonAncestor`. ```{r common-ancestor} spe_query$pred_set_hier_simp <- vapply( spe_query$pred_set_hier, - function(x) returnCommonAncestor(x, opi2), + function(x) getCommonAncestor(x, opi2), character(1) ) head(spe_query$pred_set_hier_simp)