Package 'scFlex'

Title: Flexible Conversion Between Single-Cell Data Objects
Description: Provides conversion among 'Seurat', 'SingleCellExperiment', 'AnnData', and 'Loom' single-cell data representations while preserving expression matrices, cell and feature metadata, and dimensionality reductions when supported by the target format. The package performs alignment and validity checks during conversion and reports unsupported or unavailable components rather than silently reconstructing them.
Authors: Mohamed N. Hassan [aut, cre]
Maintainer: Mohamed N. Hassan <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-09-30 19:39:31 UTC
Source: https://github.com/mohamednhassan/scflex

Help Index


scFlex: Preservation-Aware Single-Cell Interoperability

Description

Tools for conversion among Seurat, SingleCellExperiment, AnnData, and Loom representations.


Convert AnnData to Loom

Description

Reads an AnnData H5AD file and writes a Loom file using loompy, preserving supported matrices, cell and feature attributes, and reductions where representable.

Usage

convert_anndata_to_loom(input, output)

Arguments

input

Path to an input .h5ad file.

output

Path to the output .loom file.

Details

Loom is a more limited interchange format than Seurat, SingleCellExperiment, or AnnData, so only components representable by the current mapping are preserved.

Value

The output path, returned invisibly.


Convert AnnData to SingleCellExperiment

Description

Converts an AnnData H5AD file to a SingleCellExperiment object while preserving counts, normalized expression when available, cell metadata, feature metadata, and dimensional reductions.

Usage

convert_anndata_to_sce(input, output)

Arguments

input

Path to an AnnData H5AD file.

output

Path where the converted SingleCellExperiment RDS file should be written.

Details

An explicit layers["counts"] matrix is preferred as the counts assay. Fractional values are accepted in an explicit counts layer as long as all values are finite and non-negative. If no explicit counts layer is present, X is used as counts only when its values are finite, non-negative, and integer-like.

Normalized expression is optional. If layers["logcounts"] is present it is stored as the SCE logcounts assay. Otherwise, X is used as logcounts when it was not already used as the counts matrix.

Value

Invisibly returns the output file path.


Convert AnnData to Seurat

Description

Reads an AnnData H5AD file and writes a Seurat RDS object while preserving supported counts, normalized expression, metadata, feature metadata, and dimensional reductions.

Usage

convert_anndata_to_seurat(input, output)

Arguments

input

Path to an input .h5ad file.

output

Path to the output Seurat .rds file.

Value

The output path, returned invisibly.


Convert Loom to AnnData

Description

Reads a Loom file through AnnData and writes the resulting object as H5AD while preserving components supported by the Loom-to-AnnData reader.

Usage

convert_loom_to_anndata(input, output)

Arguments

input

Path to an input .loom file.

output

Path to the output .h5ad file.

Details

Loom is a more limited interchange format than Seurat, SingleCellExperiment, or AnnData, so only components representable by the current mapping are preserved.

Value

The output path, returned invisibly.


Convert Loom to SingleCellExperiment

Description

Reads a Loom file through AnnData and creates a SingleCellExperiment while preserving supported count data, normalized data, metadata, feature metadata, and reductions.

Usage

convert_loom_to_sce(input, output)

Arguments

input

Path to an input .loom file.

output

Path to the output SingleCellExperiment .rds file.

Details

Raw counts are selected conservatively from an explicit counts layer when available or from X when it is non-negative and integer-like. The function does not guess raw counts from arbitrary named layers. Loom is a more limited interchange format than Seurat, SingleCellExperiment, or AnnData, so only components representable by the current mapping are preserved.

Value

The output path, returned invisibly on success. If suitable raw count data cannot be identified, the function may return NULL invisibly without writing an output object.


Convert Loom to Seurat

Description

Reads a Loom file through AnnData and creates a Seurat object while preserving supported count data, metadata, feature metadata, and reductions.

Usage

convert_loom_to_seurat(input, output)

Arguments

input

Path to an input .loom file.

output

Path to the output Seurat .rds file.

Details

Raw counts are selected conservatively from an explicit counts layer when available or from X when it is non-negative and integer-like. The function does not guess raw counts from arbitrary named layers. Loom is a more limited interchange format than Seurat, SingleCellExperiment, or AnnData, so only components representable by the current mapping are preserved.

Value

The output path, returned invisibly on success. If suitable raw count data cannot be identified, the function may return NULL invisibly without writing an output object.


Convert between supported single-cell formats

Description

Dispatches a file conversion between Seurat, SingleCellExperiment, AnnData, and Loom using the corresponding scFlex conversion function.

Usage

convert_sc(input, source, destination, output)

Arguments

input

Character string giving the path to the input file.

source

Character string naming the source format. Supported values are "seurat", "sce", "anndata", and "loom". Matching is case-insensitive.

destination

Character string naming the destination format. Supported values are "seurat", "sce", "anndata", and "loom". Matching is case-insensitive.

output

Character string giving the output file path.

Details

Source and destination must differ. Unsupported format names or unimplemented conversion paths produce an error.

Value

The result returned by the selected conversion function, invisibly. Current converters normally return the output path invisibly; some conversions may return NULL invisibly when required count data cannot be identified.


Convert SingleCellExperiment to AnnData

Description

Reads a SingleCellExperiment RDS object and writes an H5AD AnnData file, mapping supported assays, metadata, feature metadata, and reduced dimensions.

Usage

convert_sce_to_anndata(input, output)

Arguments

input

Path to an input SingleCellExperiment .rds file.

output

Path to the output .h5ad file.

Value

The output path, returned invisibly.


Convert SingleCellExperiment to Loom

Description

Reads a SingleCellExperiment RDS object and writes a Loom file using loompy, preserving supported assays, attributes, and reductions where representable.

Usage

convert_sce_to_loom(input, output)

Arguments

input

Path to an input SingleCellExperiment .rds file.

output

Path to the output .loom file.

Details

Loom is a more limited interchange format than Seurat, SingleCellExperiment, or AnnData, so only components representable by the current mapping are preserved.

Value

The output path, returned invisibly.


Convert SingleCellExperiment to Seurat

Description

Reads a SingleCellExperiment RDS object and writes a Seurat RDS object while preserving supported counts, normalized expression, metadata, feature metadata, and dimensional reductions.

Usage

convert_sce_to_seurat(input, output)

Arguments

input

Path to an input SingleCellExperiment .rds file.

output

Path to the output Seurat .rds file.

Value

The output path, returned invisibly.


Convert a classic Seurat Assay to Assay5

Description

Converts a selected classic Seurat Assay to a Seurat v5 Assay5 while preserving the supported assay data and object structure.

Usage

convert_seu_classic_to_v5(input, output, assay = "RNA")

Arguments

input

Path to an input Seurat .rds file.

output

Path to the output Seurat .rds file.

assay

Name of the assay to convert. Defaults to "RNA".

Value

The output path, returned invisibly.


Convert a Seurat Assay5 assay to a classic Assay

Description

Converts a selected Seurat v5 Assay5 assay to a classic Seurat Assay while preserving the supported assay data and object structure.

Usage

convert_seu_v5_to_classic(input, output, assay = "RNA")

Arguments

input

Path to an input Seurat .rds file.

output

Path to the output Seurat .rds file.

assay

Name of the assay to convert. Defaults to "RNA".

Value

The output path, returned invisibly.


Convert Seurat to AnnData

Description

Reads a Seurat RDS object and writes an H5AD AnnData file while preserving supported counts, normalized expression, metadata, feature metadata, and dimensional reductions.

Usage

convert_seurat_to_anndata(input, output, assay = "RNA")

Arguments

input

Path to an input Seurat .rds file.

output

Path to the output .h5ad file.

assay

Name of the Seurat assay to convert. Defaults to "RNA".

Value

The output path, returned invisibly.


Convert Seurat to Loom

Description

Reads a Seurat RDS object and writes a Loom file using loompy, preserving supported expression matrices, attributes, and reductions where representable.

Usage

convert_seurat_to_loom(input, output)

Arguments

input

Path to an input Seurat .rds file.

output

Path to the output .loom file.

Details

Loom is a more limited interchange format than Seurat, SingleCellExperiment, or AnnData, so only components representable by the current mapping are preserved.

Value

The output path, returned invisibly.


Convert Seurat to SingleCellExperiment

Description

Reads a Seurat RDS object and writes a SingleCellExperiment RDS object while preserving supported counts, normalized expression, metadata, feature metadata, and dimensional reductions.

Usage

convert_seurat_to_sce(input, output)

Arguments

input

Path to an input Seurat .rds file.

output

Path to the output SingleCellExperiment .rds file.

Value

The output path, returned invisibly.


Inspect a single-cell object

Description

Inspects the structure and contents of a supported single-cell data file without performing a conversion. Supported inputs include Seurat and SingleCellExperiment objects stored as RDS files, AnnData H5AD files, and Loom files.

Usage

inspect_sc(path_to_file)

Arguments

path_to_file

Path to an RDS, H5AD, or Loom file.

Details

The function reports basic information such as the number of cells and features, available assays or layers, dimensional reductions, metadata, and a sample of cell names. Additional format-specific information is reported when available.

Value

Invisibly returns a list containing information about the inspected object. The contents of the list depend on the input format.

Examples

if (requireNamespace("Seurat", quietly = TRUE)) {
  counts <- matrix(
    c(1, 0, 3, 0, 2, 1),
    nrow = 2,
    dimnames = list(
      c("Gene1", "Gene2"),
      c("Cell1", "Cell2", "Cell3")
    )
  )
  obj <- Seurat::CreateSeuratObject(counts = counts)
  path <- tempfile(fileext = ".rds")
  saveRDS(obj, path)
  inspect_sc(path)
  unlink(path)
}