Skip to content

Commit

Permalink
Removed .splitSCE() artefact
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanderaa committed Mar 8, 2024
1 parent ef5da35 commit 0b16164
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions R/QFeatures-constructors.R
Original file line number Diff line number Diff line change
Expand Up @@ -578,55 +578,3 @@ readQFeaturesFromDIANN <- function(colData, reportData, extractedData = NULL,
"the same experiment?")
extractedData[, cnames]
}


##' Split SingleCellExperiment into an ExperimentList
##'
##' The fonction creates an [ExperimentList] containing
##' [SingleCellExperiment] objects from a [SingleCellExperiment]
##' object. `f` is used to split `x`` along the rows (`f`` was a feature
##' variable name) or samples/columns (f was a phenotypic variable
##' name). If f is passed as a factor, its length will be matched to
##' nrow(x) or ncol(x) (in that order) to determine if x will be split
##' along the features (rows) or sample (columns). Hence, the length of
##' f must match exactly to either dimension.
##'
##' This function is not exported. If this is needed, create a pull
##' request to `rformassspectrometry/QFeatures`.
##'
##' @param x a single [SingleCellExperiment] object
##'
##' @param f a factor or a character of length 1. In the latter case,
##' `f` will be matched to the row and column data variable names
##' (in that order). If a match is found, the respective variable
##' is extracted, converted to a factor if needed
##' @noRd
.splitSCE <- function(x,
f) {
## Check that f is a factor
if (is.character(f)) {
if (length(f) != 1)
stop("'f' must be of lenght one")
if (f %in% colnames(rowData(x))) {
f <- rowData(x)[, f]
}
else if (f %in% colnames(colData(x))) {
f <- colData(x)[, f]
}
else {
stop("'", f, "' not found in rowData or colData")
}
if (!is.factor(f))
f <- factor(f)
}
## Check that the factor matches one of the dimensions
if (!length(f) %in% dim(x))
stop("length(f) not compatible with dim(x).")
if (length(f) == nrow(x)) { ## Split along rows
xl <- lapply(split(rownames(x), f = f), function(i) x[i, ])
} else { ## Split along columns
xl <- lapply(split(colnames(x), f = f), function(i) x[, i])
}
## Convert list to an ExperimentList
do.call(ExperimentList, xl)
}

0 comments on commit 0b16164

Please sign in to comment.