Why Weight Accessibility Counts?
An ATAC-seq accessibility matrix records counts for peaks across cells. A peak observed in nearly every cell may contribute little to distinguishing cells, while a peak observed in only a small subset may be more informative for an embedding. TF–IDF combines two ideas: normalize counts within each cell, then weight each peak according to how widely it occurs across cells. Latent semantic indexing (LSI) applies a truncated singular value decomposition (SVD) to the resulting weighted matrix and uses its cell coordinates as an embedding.
The representation is useful for summarizing broad patterns in a sparse peak-by-cell matrix. It is not a statistical model that proves a biological interpretation: the result depends on the peak set, weighting convention, and cells included. In particular, per-cell normalization does not guarantee that sequencing depth has no influence on the resulting components.
Deriving TF–IDF for Peaks and Cells
Here, a “term” is a peak and a “document” is a cell. The term-frequency part expresses a peak count as a fraction of that cell’s total counts. The inverse-document-frequency part follows from the prevalence of the peak: the prevalence is \(df_j/N\), its inverse is \(N/df_j\), and taking the logarithm gives \(\log(N/df_j)\). Thus, an observed peak found in every cell has weight zero, while a peak found in fewer cells receives a larger weight. The logarithm moderates the increase for rare peaks.
This tutorial uses this specific TF–IDF convention. Implementations may instead use a pseudocount, an extra scale factor, a logarithm of the term frequency, or a different IDF formula. Those choices change the numerical matrix and can change the embedding; report the convention used rather than treating all TF–IDF matrices as identical. Peaks with \(df_j=0\) provide no information in the observed data and should be excluded before calculating IDF. A cell with \(L_i=0\) has undefined term frequencies and requires a defined filtering or handling rule before this transformation.
Worked Example: Calculating TF–IDF From Accessibility Counts
Suppose a hypothetical dataset has three peaks and three cells, with the following count matrix. Rows are peaks and columns are cells.
The cell totals are \(L_1=4\), \(L_2=4\), and \(L_3=4\). The document frequencies are \(df_1=2\), \(df_2=2\), and \(df_3=1\), with \(N=3\). Therefore,
For example, \(TF_{12}=2/4=0.5\), so \(W_{12}=0.5(0.4055)\approx0.2027\). For peak 3 in cell 3, \(TF_{33}=3/4=0.75\), so \(W_{33}=0.75(1.0986)\approx0.8240\). Applying the same calculation to every entry gives
Peak 3 receives a larger IDF because it occurs in only one cell. This is a weighting consequence, not evidence by itself that peak 3 is biologically more important.
From the Weighted Matrix to LSI Cell Coordinates
Apply SVD to \(W\), keeping its peak-by-cell orientation. For a matrix of rank \(r\), write its thin SVD as \(W=U\Sigma V^T\), where \(U\) has peak directions as columns, \(V\) has cell directions as columns, and \(\Sigma\) is diagonal with nonnegative singular values in descending order. Retaining the first \(K\) components gives \(W\approx U_K\Sigma_KV_K^T\). Under the convention used here, the coordinates for cells, with cells as rows, are the first \(K\) columns of \(V\Sigma\), an \(N\times K\) matrix. Equivalently, the transpose of that coordinate matrix has components as rows and cells as columns.
The singular values scale the component directions. Other workflows may use \(V\) alone or apply further scaling, so coordinate definitions should be checked when comparing software outputs. Also, the sign of any singular vector is arbitrary: flipping the signs of a matching pair of columns of \(U\) and \(V\) leaves \(W\) unchanged. A positive or negative component score therefore has no fixed biological direction on its own.
The low-rank representation is justified by a standard SVD property: among matrices of rank at most \(K\), \(U_K\Sigma_KV_K^T\) minimizes the sum of squared entrywise reconstruction errors from \(W\). In the SVD basis, the squared Frobenius error after retaining \(K\) components is the sum of the squared omitted singular values. Since orthogonal changes of basis preserve sums of squares, retaining the largest singular values leaves the smallest possible such error. This makes the truncated representation a compact summary of weighted-matrix variation; it does not guarantee that the retained variation corresponds to the biological question of interest.
Worked Example: Checking the Orientation of Cell Scores
Consider the hypothetical rank-one matrix \(W=qr^T\), where \(q=(1,2)^T\) describes two peak values and \(r=(1,2,3)^T\) describes three cell values. Then
The vector lengths are \(\|q\|=\sqrt{5}\) and \(\|r\|=\sqrt{14}\). Thus, a rank-one SVD has \(u=q/\sqrt{5}\), \(v=r/\sqrt{14}\), and singular value \(\sigma_1=\sqrt{5}\sqrt{14}=\sqrt{70}\). The matrix \(V\Sigma\) is an \(N\times1\) matrix of cell scores:
There are three cell scores, one in each row. The first \(K\) columns—not the first \(K\) rows—of \(V\Sigma\) give the cell coordinates for a \(K\)-dimensional embedding. Here \(K=1\), so the displayed \(3\times1\) matrix is the embedding. Its transpose would place the one component in a row and the three cells in columns.
Why the First LSI Component Can Track Sequencing Depth
Term-frequency normalization removes a simple form of library-size scaling. If every entry in one cell is multiplied by the same positive constant \(c\), then
So, for exactly proportional count profiles, TF is unchanged. This does not make an LSI embedding independent of depth. Real shallow and deep cells may not have proportional profiles: deeper sequencing can detect more low-abundance peaks, change which peaks are nonzero, and alter the observed distribution of counts among peaks. The IDF weights are also based on which cells have nonzero counts. Together, these features can make the weighted profiles and their leading SVD directions associated with library size or detected-peak count.
There is no rule that the first component must be depth, or that depth association makes the entire embedding unusable. Rather, inspect it. Compare component scores with total counts and the number of detected peaks, and examine whether cells are ordered by these technical quantities. Also check whether the association is concentrated in a small number of high-weight rare peaks, or coincides with a batch or other technical factor. A depth-associated leading component may reflect technical structure, genuine biological variation correlated with depth, or both; a plot alone cannot establish which explanation is correct.
Worked Example: What Per-Cell Normalization Does—and Does Not—Remove
Consider two hypothetical cells with counts over three peaks: cell A has \((10,5,0)^T\), and cell B has \((100,50,0)^T\). Their total counts are 15 and 150, respectively. Their term-frequency vectors are
The second cell has ten times the total count, but exactly the same proportions, so the TF vectors match. Since both cells also have the same nonzero peaks, applying the same peak IDF weights leaves their TF–IDF vectors equal. In real data, however, a deeper cell may have additional nonzero peaks. For example, its observed profile might be \((100,50,10)^T\), whose total is 160 and whose TF vector is approximately \((0.6250,0.3125,0.0625)^T\). That change in relative composition can affect the weighted matrix and the SVD. The arithmetic shows why normalization removes proportional scaling but does not ensure that depth has no association with LSI scores.
Assumptions, Diagnostics, and Alternatives
TF–IDF and LSI are descriptive transformations, not hypothesis tests with a null distribution or a \(p\)-value. Their usefulness depends on the input and preprocessing being meaningful. The peak definitions should be comparable across cells, the matrix should record nonnegative accessibility counts, and each included cell should have a positive total count. The interpretation of IDF also assumes that prevalence across the included cells is a useful measure of how discriminating a peak is. If cells are very heterogeneous in depth, batch, or composition, prevalence may reflect those differences as well as cell identity.
Useful checks include verifying matrix orientation and dimensions, confirming that cell totals and nonzero peak counts are sensible, and checking that no \(df_j=0\) peak enters the IDF calculation. Inspect the IDF distribution: peaks present in nearly all cells receive small or zero weights under this convention, while very rare peaks receive larger weights and may be sensitive to isolated observations. Examine the leading cell scores against total counts, detected peaks, and known technical groupings. Check whether the embedding is stable to reasonable choices of peak set, weighting convention, or retained component count. These checks reveal potential problems; they do not by themselves identify a uniquely correct embedding.
Alternatives emphasize different properties. TF alone adjusts cell totals but does not downweight widespread peaks. Binary accessibility replaces counts with indicators before weighting, giving less influence to repeated counts at an already accessible peak. Log-transformed counts retain information about within-cell count differences in a different way. PCA on a transformed matrix is another dimension-reduction approach, but centering and scaling choices affect its result; uncentered SVD of TF–IDF is not the same calculation as centered PCA. No alternative is uniformly superior. The choice should match the intended representation and be reported clearly.
A common mistake is to conclude that the first LSI component cannot be technical because TF divides each cell’s counts by its total. That conclusion assumes depth changes every peak count by exactly the same factor and leaves the detected peaks unchanged. When additional peaks are observed, or peak proportions differ with depth, the normalized columns can differ. Check depth associations in the computed coordinates instead of assuming normalization has removed them.
Check Your Understanding
Try each question, then compare your reasoning with the solutions below.
- If a peak is observed in every cell, what is its IDF under the convention used here? What does that imply for its TF–IDF values?
- A peak is observed in 2 of 8 cells. Calculate its IDF to three significant figures.
- For a peak-by-cell matrix with \(N\) cells, what are the dimensions of the cell-coordinate matrix formed from the first \(K\) columns of \(V\Sigma\)?
- Why can two cells with different total counts have identical term-frequency vectors, and why might depth still affect an LSI component in real data?
- A researcher sees the first LSI component associated with detected-peak count. Does this prove the component is purely technical? Give one appropriate diagnostic interpretation.
Solutions. (1) \(IDF=\log(N/N)=0\), so that peak has zero TF–IDF weight in every cell under this convention. (2) \(IDF=\log(8/2)=\log(4)\approx1.386\). (3) It is \(N\times K\): rows are cells and columns are components. (4) If one count vector is a positive constant multiple of the other, dividing by each cell’s total gives the same proportions. In real data, depth can change which peaks are detected and the observed proportions, so weighted profiles and their SVD scores can differ. (5) No. The association is a reason to investigate technical structure and possible biological confounding; it does not establish that the component is purely technical. Compare scores with other technical measures and assess the pattern in context.