Skip to content

Commit

Permalink
Merge pull request #6 from ccb-hms/main
Browse files Browse the repository at this point in the history
change param names and add ctb
  • Loading branch information
DanielaCorbetta authored Jul 25, 2024
2 parents 13b928c + e1feb4f commit b4d33cb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 31 deletions.
10 changes: 8 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]",
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
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions R/returnCommonAncestor.R → R/getCommonAncestor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
Expand Down
24 changes: 12 additions & 12 deletions R/getPredictionSets.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -136,7 +136,7 @@
#' onto = NULL,
#' alpha = 0.1,
#' follow_ontology = FALSE,
#' resample_cal = FALSE,
#' resample = FALSE,
#' labels = cell_types,
#' return_sc = FALSE
#' )
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions man/returnCommonAncestor.Rd → man/getCommonAncestor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/getPredictionSets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vignettes/scConform.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit b4d33cb

Please sign in to comment.