filter_low_coverage: Remove high-missingness features from an HDF5Matrix

View source: R/S3_omics.R

filter_low_coverageR Documentation

Remove high-missingness features from an HDF5Matrix

Description

Removes columns (SNPs) or rows (samples) that carry too many missing values. Writes the result to a new dataset.

Missing values are the entries equal to 3, the missing-data code of the 0/1/2/3 genotype encoding shared by the omics functions; NA or NaN entries are not counted, so recode them to 3 beforehand. A column (or row) is removed when its proportion of 3s is greater than or equal to pcent.

Row and column names of x, when present, are carried over to the result: the names of the filtered axis are subset to the surviving elements.

When out_group/out_dataset are NULL (default) the result is written alongside the input dataset with the suffix "_filtered".

Usage

filter_low_coverage(x, ...)

## S3 method for class 'HDF5Matrix'
filter_low_coverage(
  x,
  out_group = NULL,
  out_dataset = NULL,
  pcent = 0.05,
  by_cols = TRUE,
  overwrite = FALSE,
  ...
)

Arguments

x

An HDF5Matrix containing SNP data with missing values coded as 3.

...

Ignored.

out_group

Output group. NULL (default) = same group as input.

out_dataset

Output dataset name. NULL (default) = input name + "_filtered".

pcent

Numeric in [0,1]. Missing-data threshold (default 0.05). Features whose proportion of 3s reaches this value are removed.

by_cols

Logical. Filter columns (TRUE, default) or rows.

overwrite

Logical. Overwrite existing output. Default FALSE.

Value

HDF5Matrix pointing to the filtered dataset, carrying the dimension names of the surviving elements.

Examples


set.seed(42)
fn <- tempfile(fileext = ".h5")
# 0/1/2 genotypes with about 10% missing values, coded as 3
snps <- matrix(sample(c(0, 1, 2, 3), 200, replace = TRUE,
                       prob = c(.3, .3, .3, .1)), 20, 10)
X   <- hdf5_create_matrix(fn, "geno/raw", data = snps)

# Filter with auto output path (adds "_filtered" suffix)
out <- filter_low_coverage(X, pcent = 0.2)

# Filter with explicit output
out2 <- filter_low_coverage(X, pcent = 0.2, out_group = "geno",
                             out_dataset = "filtered", overwrite = TRUE)
hdf5_close_all()
unlink(fn)



BigDataStatMeth documentation built on Sept. 15, 2026, 1:08 a.m.