Skip to contents

An R6 class to handle methylation beta value files efficiently, with support for in-memory loading, tabix indexing, BSseq objects, and various file formats.

Public fields

beta

Path to beta values file, or a tabix file, or in-memory beta matrix, or BSseq object

genome

Reference genome

array

Array platform, ignore for mouse genomes or when sorted_locs provided

beta_row_names_file

Path to row names file

sorted_locs

Sorted genomic locations

output_prefix

Prefix used for saving derived beta artifacts

njobs

Number of parallel jobs

beta_chunk_size

Chunk size for subsetting beta values

Methods


BetaHandler$new()

Create a new BetaHandler object

Usage

BetaHandler$new(
  beta = NULL,
  array = c("450K", "27K", "EPIC", "EPICv2"),
  genome = "hg38",
  beta_row_names_file = NULL,
  sorted_locs = NULL,
  chrom_col = "#chrom",
  start_col = "start",
  output_prefix = NULL,
  njobs = 1
)

Arguments

beta

Path to beta values file, or a tabix, or a beta matrix, or a BSseq object

array

Array platform type. Ignored if sorted_locs, a tabix file, or a BSseq object have been provided.

genome

Reference genome version, eg. hg38 or hs1. Only human and mouse genomes are supported. Ignored if sorted_locs, a tabix file, or a BSseq object have been provided.

beta_row_names_file

Path to row names file. If NULL, row names will be read from input beta.

sorted_locs

Sorted genomic locations data frame. If given, the input data will be assumed already sorted. If NULL, will be retrieved automatically

chrom_col

Chromosome column name in tabix file

start_col

Start position column name in tabix file

output_prefix

Prefix used for saving derived beta artifacts

njobs

Number of parallel jobs

Returns

A new BetaHandler object


BetaHandler$load()

Load beta file data into memory or prepare for file-based access

Usage

BetaHandler$load()

Returns

Self (invisibly)


BetaHandler$getGenomicLocs()

Get all provided sorted genomic locations

Usage

BetaHandler$getGenomicLocs()

Returns

data.frame or matrix of the genomic locations


BetaHandler$getBetaRowNames()

Get row names (site IDs) from the beta file

Usage

BetaHandler$getBetaRowNames()

Returns

Character vector of row names


BetaHandler$getBetaColNames()

Get column names (sample IDs) from the beta file

Usage

BetaHandler$getBetaColNames()

Returns

Character vector of column names


BetaHandler$validate()

Validate that the beta file is properly sorted and formatted

Usage

BetaHandler$validate()

Returns

Self (invisibly)


BetaHandler$getBetaLocs()

Get genomic locations for beta values

Usage

BetaHandler$getBetaLocs()

Returns

Data frame of genomic locations


BetaHandler$getBetaChunkSize()

Get the chunk size used for beta subsetting

Usage

BetaHandler$getBetaChunkSize()

Returns

Integer chunk size


BetaHandler$isArrayBased()

Check if the beta data is array-based (i.e. does not have row names in 'chr:pos' format)

Usage

BetaHandler$isArrayBased()

Returns

Logical indicating if the beta data is array-based


BetaHandler$subset()

Build a compact BetaHandler view for a subset of rows/columns

Usage

BetaHandler$subset(row_names = NULL, col_names = NULL, allow_missing = FALSE)

Arguments

row_names

Character vector of site IDs (or numeric row indices) to keep; NULL keeps all rows

col_names

Character vector of sample IDs to keep; NULL keeps all columns

allow_missing

Logical; if TRUE, silently drops missing row names

Returns

A BetaHandler object scoped to the requested subset


BetaHandler$getBeta()

Extract beta values for specific site sites and samples

Usage

BetaHandler$getBeta(
  row_names = NULL,
  col_names = NULL,
  allow_missing = FALSE,
  chr = NULL
)

Arguments

row_names

Character vector of site IDs to extract. If numeric, treated as row indices.

col_names

Character vector of sample IDs to extract (default: NULL for all)

allow_missing

Logical. If TRUE, missing site sites will be ignored instead of throwing an error (default: FALSE)

chr

Character vector of chromosome names to extract, cannot be used along with row_names (default: NULL for all)

Returns

Matrix of beta values


BetaHandler$clone()

The objects of this class are cloneable with this method.

Usage

BetaHandler$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.