-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Generalized contrastive PCA (gcPCA) is a dimensionality reduction method for contrasting datasets. It identifies low-dimensional patterns that are enriched in one experimental condition relative to another. Unlike PCA, which operates on a single dataset, gcPCA enables direct comparisons across conditions.
This repository provides open-source implementations of gcPCA in Python, MATLAB, and R, along with variants designed for different data types.
For full methodological details, see our paper:
Identifying patterns differing between high-dimensional datasets with generalized contrastive PCA
PLOS Computational Biology
https://doi.org/10.1371/journal.pcbi.1012747
- Hyperparameter-free — No manual tuning required
- Symmetric comparison — Both conditions treated equally
- Sparse solutions — Improved interpretability
- Multi-language support — Python, MATLAB, and R
Create an environment and install:
conda create --name gcPCA python>=3.9
conda activate gcPCA
pip install generalized_contrastive_PCAOr install from this repository
conda env create -f environment.ymlinstall.packages("remotes")
remotes::install_github(
"SjulsonLab/generalized_contrastive_PCA",
subdir = "R_package"
)MATLAB implementation is available in:
matlab/gcPCA
Just add the folder to the path.
from generalized_contrastive_PCA import gcPCA
model = gcPCA(method="v4")
model.fit(Ra, Rb)library(gcpca)
fit <- gcPCA(Ra, Rb, method = "v4")
pred <- predict(fit)[B, S, X] = gcPCA(Ra, Rb, 4);If gcPCA is useful in your work, please cite:
de Oliveira, E. F., Garg, P., Hjerling-Leffler, J., Batista-Brito, R., & Sjulson, L. (2025).
Identifying patterns differing between high-dimensional datasets with generalized contrastive PCA.
PLOS Computational Biology.
https://doi.org/10.1371/journal.pcbi.1012747
If you encounter issues or have suggestions for improvement, please open a GitHub issue.
You can also contact the authors of the gcPCA manuscript for questions or feedback.
If you find this project helpful, consider giving the repository a ⭐