Integrative, high-resolution analysis of single cells across experimental conditions with PARAFAC2
parafac2 contains the code for the PARAFAC2 (Pf2) python package, a tensor decomposition technique, used in our study for identifying variation patterns in single-cell populations across conditions. In our study, we discovered association patterns to specific cell populations, genes, and experimental conditions in both a drug perturbational study and systemic lupus erythematosus cohort study.
Full package documentation is available at meyer-lab.github.io/parafac2.
Installation
To install parafac2 with standard CPU support:
pip install parafac2
Hardware Acceleration ([gpu] extra)
parafac2 supports hardware acceleration (mlx on Apple Silicon and cupy on Linux/Windows) via a single gpu extra:
pip install "parafac2[gpu]"
Or with uv:
uv sync --extra gpu
Environment markers automatically select mlx when on macOS Apple Silicon, and cupy on other platforms. If no GPU backend is installed, parafac2 falls back to CPU computation seamlessly.
Input Requirements
- Your AnnData object must include an observations
column condition_unique_idxsthat is a 0-indexed array of which condition each cell is derived from along with the cell barcode Preprocessing your data - Your AnnData object must be preprocessed (removed doublets, normalized, log transformed) before running the algorithm
- The function
parafac2_ndis the Pf2 algorithm with various parameters that can be altered such as rank, tolerance, etc.
Outputs
The output of parafac2_nd is the first AnnData object and the reconstruction error (R2X). The results of parafac2_nd are added to the AnnData object. These include:
- The weights for each component
X.uns["Pf2_weights"] - The factors with respect to each dimension in the data where
X.uns[“Pf2_A”]is the condition factors,X.uns[“Pf2_B”]is the eigen-state factors, andX.varm[“Pf2_C”]is the genes, where the width of the matrix is the rank used for the algorithm - Each cell will have the corresponding values for the projections,
X.obsm["projections"], where the width of the matrix is the rank used for the algorithm - In addition, each cell has the corresponding weighted projections for each cell in the
X.obsm["weighted_projections"]for all components, to determine how each cell related to each component pattern, where the width of the matrix is the rank used for the algorithm - We recommend implementing an embedding algorithm such as PaCMAP or UMAP on the
X.obsm["projections"]to visualize cell-to-cell heterogeneity, creating a new columns coinedX.obsm["embedding"]for example
Examples
You can find example scripts that load single-cell scRNA-seq data across conditions, implement Pf2, and various ways to interpret and plot Pf2 on Github via the RISE repository (Basic familiarity with the python programming languages is recommended to navigate repository).
Release files for parafac2 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| parafac2-1.6.0.tar.gz | 28.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| parafac2-1.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.5 kB
Release files / parafac2-1.6.0.tar.gz
| Download URL | parafac2-1.6.0.tar.gz |
|---|---|
| Size | 28.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7e7817a28fc59ba1f1d80469c65d74d4a6044bf9f383364eb07cef1f4d3516e
|
|
BLAKE2b-256 checksum How to use checksums |
5b11f69fc560bf17fbdcf269fdb63d9106724ded27dee395e74afb40e061e93f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logRelease files / parafac2-1.6.0-py3-none-any.whl
| Download URL | parafac2-1.6.0-py3-none-any.whl |
|---|---|
| Size | 33.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd5b1575bc7c1a779f794ec1c0d2e9c5dc0c32feb8ad6e46e60b0c592b57223a
|
|
BLAKE2b-256 checksum How to use checksums |
0658654144ff025927b36895e515b7b01083959afa7ada96909acf49d364a08f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency log