2. Installation - SjulsonLab/generalized_contrastive_PCA GitHub Wiki

Installation

This page describes how to install gcPCA for Python, R, and MATLAB.


Python Installation

Option 1 — Install with pip (Recommended)

Create a new environment:

conda create --name gcPCA python=3.9
conda activate gcPCA

Install the package:

pip install generalized_contrastive_PCA

Option 2 — Install from Repository

Clone the repository:

git clone https://github.com/SjulsonLab/generalized_contrastive_PCA.git
cd generalized_contrastive_PCA

Create environment from file:

conda env create -f environment.yml
conda activate gcPCA

Python Requirements

gcPCA requires:

  • Python ≥ 3.9
  • NumPy
  • SciPy
  • Numba
  • scikit-learn
  • matplotlib (optional, for visualization)

These dependencies are installed automatically when using environment.yml.


R Installation

Install the R package directly from GitHub:

install.packages("remotes")
remotes::install_github(
  "SjulsonLab/generalized_contrastive_PCA",
  subdir = "R_package"
)

Alternatively, install locally from a cloned repository:

install.packages("devtools")
devtools::install("R_package")

R Requirements

The R implementation depends on:

  • R ≥ 4.0
  • stats
  • Matrix
  • base R packages

These dependencies will be installed automatically.


MATLAB Installation

MATLAB implementation does not require package installation.

  1. Clone the repository:
git clone https://github.com/SjulsonLab/generalized_contrastive_PCA.git
  1. Add gcPCA to your MATLAB path:
addpath('path_to_repo/matlab')

You can now run gcPCA directly from MATLAB.


Verify Installation

Python

from generalized_contrastive_PCA import gcPCA

model = gcPCA()

If no errors occur, installation was successful.


R

library(gcpca)

?gcPCA

If the help page appears, installation was successful.


MATLAB

help gcPCA

If documentation appears, installation was successful.


Troubleshooting

Python

If you encounter dependency errors:

  • Ensure Python ≥ 3.9
  • Try creating a fresh conda environment
  • Install using environment.yml

R

If installation fails:

  • Update R to latest version
  • Install remotes or devtools
  • Restart R session and retry

MATLAB

If gcPCA is not recognized:

  • Verify the path was added correctly
  • Use addpath again
  • Restart MATLAB

Next Steps

After installation, continue to:

1. Quickstart Guide
3. Conceptual Overview
4. Mathematical Formulation
5. Code Reference
6. Input Data Guidelines
7. Interpreting Results