Skip to contents

This helper function aggregates a peak-by-cell matrix into a chromatin state–by-cell matrix based on the state annotations assigned to each peak. Each cell’s counts across peaks belonging to the same chromatin state are summed to produce a per-state count matrix, which is then transposed to return a cell-by-state matrix suitable for downstream analyses.

Usage

CalculateStateMatrix(peaks_mat, peaks_gr)

Arguments

peaks_mat

A sparse or dense matrix of peak accessibility counts (rows = peaks, columns = cells). Typically obtained from GetAssayData on the ATAC assay.

peaks_gr

A GRanges object of the same length as the number of rows in peaks_mat, containing at least one column named annotation giving the chromatin state label for each peak.

Value

A cell-by-state matrix of summed fragment counts per chromatin state (rows = cells, columns = chromatin states).

Details

This function assumes that each row of peaks_mat corresponds to the same peak as the corresponding entry in peaks_gr, and that each peak has a valid chromatin state annotation in peaks_gr$annotation. Peaks with the same state annotation are grouped and their counts summed across cells. The resulting state-by-cell matrix is transposed to return cell-by-state counts.

Examples

# peaks_mat: peaks x cells matrix from ATAC assay
# peaks_gr: GRanges of peaks with 'annotation' column
state_matrix <- CalculateStateMatrix(peaks_mat, peaks_gr)
#> Error: object 'peaks_mat' not found