From 0b16164d4a82c9e247ed61c9a9f1b2c92bbc578e Mon Sep 17 00:00:00 2001 From: cvanderaa Date: Fri, 8 Mar 2024 23:12:32 +0100 Subject: [PATCH] Removed .splitSCE() artefact --- R/QFeatures-constructors.R | 52 -------------------------------------- 1 file changed, 52 deletions(-) diff --git a/R/QFeatures-constructors.R b/R/QFeatures-constructors.R index 4c3d3098..a37f1cdd 100644 --- a/R/QFeatures-constructors.R +++ b/R/QFeatures-constructors.R @@ -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) -}