Reimplementation
PCA from first principles, applied to RNA-seq
Rebuilding principal component analysis with linear algebra, then using it to ask what really drives variation in a public RNA-seq dataset.
This is a live research note. The implementation, dataset analysis and figures will be added as the work progresses; the scope and validation criteria are published first so the final result can be judged against them.
The question
PCA is often the first figure produced in an RNA-seq analysis. It is also frequently interpreted too quickly: separation between groups is described as biological signal even when library size, batch or another technical factor may explain the same geometry.
The aim is not simply to call a PCA function. It is to rebuild the method and then use that implementation to answer a concrete question:
What sources of variation do the leading components capture, and how sensitive are they to the choices made before PCA?
From expression matrix to components
Let X be a matrix with samples in rows and genes in columns. After transforming and centring the data, PCA looks for orthogonal directions that capture as much variance as possible.
The implementation will use the singular value decomposition:
X = UΣVᵀ
The columns of V define the principal axes. The sample scores are obtained from UΣ, while the squared singular values quantify the variance associated with each component.
Building this directly with NumPy makes every decision visible: orientation, centring, scaling, numerical tolerance and sign indeterminacy. The output will then be checked against scikit-learn rather than assumed to be correct.
Analysis plan
The same public RNA-seq dataset will be analysed under several preprocessing choices:
- Raw counts after library-size normalisation.
- A variance-stabilising or log-like transformation.
- Filtering of very low-expression genes.
- Selection of the most variable genes.
For each version, the leading components will be related to the biological condition and available technical covariates. Loadings will be inspected to determine which genes contribute most strongly to the observed separation.
Validation criteria
The implementation will be considered successful only if:
- its explained-variance ratios match a trusted implementation within numerical tolerance;
- pairwise distances between sample scores agree despite arbitrary component signs;
- every preprocessing step is explicit and reproducible;
- biological interpretation is kept separate from geometric description; and
- the complete environment, data provenance and random seeds are recorded.
Expected output
The finished note will include the derivation, tested implementation, diagnostic figures, biological interpretation and a public repository containing the complete workflow.