Calculate per-cell chromatin state counts from annotated peaks
Source:R/scoring.R
CalculateStateMatrix.RdThis 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.
Arguments
- peaks_mat
A sparse or dense matrix of peak accessibility counts (rows = peaks, columns = cells). Typically obtained from
GetAssayDataon the ATAC assay.- peaks_gr
A
GRangesobject of the same length as the number of rows inpeaks_mat, containing at least one column namedannotationgiving 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.