Skip to content

Commit

Permalink
Further conditioning down the use of Suggests in example/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvfki committed Mar 27, 2024
1 parent 56ad78f commit 290366c
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 51 deletions.
43 changes: 24 additions & 19 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -479,27 +479,32 @@ setGeneric("normPeak<-", function(x, dataset, check = TRUE, value) standardGener
#' pbmc2
#'
#' \donttest{
#' sce <- SingleCellExperiment::SingleCellExperiment(
#' assays = list(counts = multiSampleMatrix)
#' )
#' sce$sample <- pbmc$dataset
#' pbmc3 <- as.liger(sce, datasetVar = "sample")
#' pbmc3
#' if (requireNamespace("SingleCellExperiment", quietly = TRUE)) {
#' sce <- SingleCellExperiment::SingleCellExperiment(
#' assays = list(counts = multiSampleMatrix)
#' )
#' sce$sample <- pbmc$dataset
#' pbmc3 <- as.liger(sce, datasetVar = "sample")
#' pbmc3
#' }
#'
#' seu <- SeuratObject::CreateSeuratObject(multiSampleMatrix)
#' # Seurat creates variable "orig.ident" by identifying the cell barcode
#' # prefixes, which is indeed what we need in this case. Users might need
#' # to be careful and have it confirmed first.
#' pbmc4 <- as.liger(seu, datasetVar = "orig.ident")
#' pbmc4
#' if (requireNamespace("Seurat", quietly = TRUE)) {
#' seu <- SeuratObject::CreateSeuratObject(multiSampleMatrix)
#' # Seurat creates variable "orig.ident" by identifying the cell barcode
#' # prefixes, which is indeed what we need in this case. Users might need
#' # to be careful and have it confirmed first.
#' pbmc4 <- as.liger(seu, datasetVar = "orig.ident")
#' pbmc4
#'
#' # As per Seurat V5 updates with layered data, specifically helpful udner the
#' # scenario of dataset integration. "counts" and etc for each datasets can be
#' # split into layers.
#' seu5 <- seu
#' seu5[["RNA"]] <- split(seu5[["RNA"]], pbmc$dataset)
#' print(SeuratObject::Layers(seu5))
#' pbmc5 <- as.liger(seu5)
#' # As per Seurat V5 updates with layered data, specifically helpful udner the
#' # scenario of dataset integration. "counts" and etc for each datasets can be
#' # split into layers.
#' seu5 <- seu
#' seu5[["RNA"]] <- split(seu5[["RNA"]], pbmc$dataset)
#' print(SeuratObject::Layers(seu5))
#' pbmc5 <- as.liger(seu5)
#' pbmc5
#' }
#' }
as.liger <- function(object, ...) UseMethod("as.liger", object)

Expand Down
26 changes: 20 additions & 6 deletions R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' common with 10X data). Default \code{"auto"} detects if matrix columns
#' already has the exact prefix or not. Logical value forces the action.
#' @param formatType Select preset of H5 file structure. Current available
#' options are \code{"10X"} and \code{"AnnData"}. Can be either a single
#' options are \code{"10x"} and \code{"anndata"}. Can be either a single
#' specification for all datasets or a character vector that match with each
#' dataset.
#' @param anndataX The HDF5 path to the raw count data in an H5AD file. See
Expand Down Expand Up @@ -59,9 +59,11 @@
#' lig <- createLiger(list(ctrl = tempPath))
#'
#' # Create from other container object
#' ctrl.seu <- SeuratObject::CreateSeuratObject(ctrl.raw)
#' stim.seu <- SeuratObject::CreateSeuratObject(stim.raw)
#' pbmc2 <- createLiger(list(ctrl = ctrl.seu, stim = stim.seu))
#' if (requireNamespace("SeuratObject", quietly = TRUE)) {
#' ctrl.seu <- SeuratObject::CreateSeuratObject(ctrl.raw)
#' stim.seu <- SeuratObject::CreateSeuratObject(stim.raw)
#' pbmc2 <- createLiger(list(ctrl = ctrl.seu, stim = stim.seu))
#' }
createLiger <- function(
rawData,
modal = NULL,
Expand Down Expand Up @@ -276,7 +278,7 @@ createLigerDataset <- function(
#' the AnnData was originally created.
#' @param h5file Filename of an H5 file
#' @param formatType Select preset of H5 file structure. Default \code{"10X"}.
#' Current available option is only \code{"10X"}.
#' Alternatively, we also support \code{"anndata"} for H5AD files.
#' @param rawData,indicesName,indptrName The path in a H5 file for the raw
#' sparse matrix data. These three types of data stands for the \code{x},
#' \code{i}, and \code{p} slots of a \code{\link[Matrix]{dgCMatrix-class}}
Expand Down Expand Up @@ -304,7 +306,7 @@ createLigerDataset <- function(
#' ld <- createH5LigerDataset(tempPath)
createH5LigerDataset <- function(
h5file,
formatType = "10X",
formatType = "10x",
rawData = NULL,
normData = NULL,
scaleData = NULL,
Expand Down Expand Up @@ -453,6 +455,18 @@ createH5LigerDataset <- function(
#' tempPath <- tempfile(fileext = ".rds")
#' saveRDS(lig, tempPath)
#' lig <- readLiger(tempPath)
#'
#' \dontrun{
#' # Read a old liger object <= 1.0.1
#' # Assume the dimensionality reduction method applied was UMAP
#' # Assume the clustering was derived with Louvain method
#' lig <- readLiger(
#' filename = "path/to/oldLiger.rds",
#' dimredName = "UMAP",
#' clusterName = "louvain",
#' update = TRUE
#' )
#' }
readLiger <- function(
filename,
dimredName = "tsne_coords",
Expand Down
43 changes: 24 additions & 19 deletions man/as.liger.Rd

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

4 changes: 2 additions & 2 deletions man/createH5LigerDataset.Rd

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

10 changes: 6 additions & 4 deletions man/createLiger.Rd

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

12 changes: 12 additions & 0 deletions man/readLiger.Rd

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

5 changes: 4 additions & 1 deletion tests/testthat/test_visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,18 @@ test_that("Plot spatial coordinates", {

context("Sankey")
test_that("PlotSankey", {
skip_if_not_installed("sankey")
cellMeta(pbmcPlot, "ctrl_cluster", "ctrl") <-
cellMeta(pbmcPlot, "leiden_cluster", "ctrl")
cellMeta(pbmcPlot, "stim_cluster", "stim") <-
cellMeta(pbmcPlot, "leiden_cluster", "stim")
grDevices::pdf(file = tempfile(pattern = "fig_", fileext = ".pdf"))
pdfName <- tempfile(pattern = "fig_", fileext = ".pdf")
grDevices::pdf(file = pdfName)
expect_no_error({
plotSankey(pbmcPlot, "ctrl_cluster", "stim_cluster",
titles = c("control", "LIGER", "stim"),
prefixes = c("c", NA, "s"))
})
grDevices::dev.off()
if (file.exists(pdfName)) unlink(pdfName)
})

0 comments on commit 290366c

Please sign in to comment.