Skip to contents

Subset per sample

Usage

subsetPerSample(object, ...)

# S4 method for SingleCellExperiment
subsetPerSample(
  object,
  minCells = 1L,
  assignAndSave = FALSE,
  envir = parent.frame(),
  dir = getwd()
)

Arguments

object

Object.

minCells

integer(1). Minimum number of cells required per sample.

assignAndSave

logical(1). Assign and save the individual datasets.

envir

environment. Where to assign the subsets. Only applicable when assignAndSave = TRUE.

dir

character(1). Output directory. Only applicable when assignAndSave = TRUE.

...

Additional arguments.

Value

  • assignAndSave = FALSE: Per sample objects in a list.

  • assignAndSave = TRUE: Subset file paths.

Note

Updated 2022-03-02.

Examples

data(SingleCellExperiment_splatter, package = "AcidTest")

## SingleCellExperiment ====
object <- SingleCellExperiment_splatter

## List mode (default).
list <- subsetPerSample(object, assignAndSave = FALSE)
#>  1 sample matched: "sample1".
#>  95 cells matched.
#>  1 sample matched: "sample2".
#>  96 cells matched.
#>  1 sample matched: "sample3".
#>  121 cells matched.
#>  1 sample matched: "sample4".
#>  88 cells matched.
names(list)
#> [1] "sample1" "sample2" "sample3" "sample4"

## Assign and save mode (useful for large datasets).
subsetPerSample(
    object = object,
    assignAndSave = TRUE,
    envir = parent.frame(),
    dir = "subsetPerSample"
)
#>  1 sample matched: "sample1".
#>  95 cells matched.
#> → Saving sample1.rds to /Users/mike/git/monorepo/r-packages/AcidSingleCell/docs/reference/subsetPerSample.
#>  1 sample matched: "sample2".
#>  96 cells matched.
#> → Saving sample2.rds to /Users/mike/git/monorepo/r-packages/AcidSingleCell/docs/reference/subsetPerSample.
#>  1 sample matched: "sample3".
#>  121 cells matched.
#> → Saving sample3.rds to /Users/mike/git/monorepo/r-packages/AcidSingleCell/docs/reference/subsetPerSample.
#>  1 sample matched: "sample4".
#>  88 cells matched.
#> → Saving sample4.rds to /Users/mike/git/monorepo/r-packages/AcidSingleCell/docs/reference/subsetPerSample.
sort(list.files("subsetPerSample"))
#> [1] "sample1.rds" "sample2.rds" "sample3.rds" "sample4.rds"

## Clean up.
unlink("subsetPerSample", recursive = TRUE)