Skip to main content

SNF2

PyPI Python Documentation

SNF2 is a modern Python implementation of Similarity Network Fusion for combining multiple data modalities into one sample-similarity network.

SNF2 requires Python 3.12 or newer.

Installation

Install the released package from PyPI:

pip install snf2

Quick start

import numpy as np

from snf2 import fuse, make_affinity

modality_a = np.array(
    [[0.0, 1.0], [0.2, 0.8], [1.0, 0.1], [0.9, 0.2]],
)
modality_b = np.array(
    [[1.0, 0.0], [0.8, 0.1], [0.1, 1.0], [0.2, 0.9]],
)

networks = [
    make_affinity(modality_a, n_neighbors=2),
    make_affinity(modality_b, n_neighbors=2),
]
fused_network = fuse(networks, n_neighbors=2)

Rows are samples and columns are features. SNF2 does not standardize features, align samples, or impute missing values. Preprocess each modality and place its samples in the same order before constructing affinity matrices.

Public API

  • make_affinity(data, ...) computes pairwise distances from a sample-by-feature matrix and constructs an affinity matrix.
  • affinity_matrix(distances, ...) constructs an affinity matrix from a precomputed distance matrix.
  • fuse(affinities, ...) combines two or more affinity matrices.

make_affinity defaults to squared Euclidean distance and accepts the named metrics supported by scipy.spatial.distance.pdist. Metric-specific arguments can be supplied through metric_kwargs:

correlation_network = make_affinity(
    modality_a,
    metric="correlation",
    n_neighbors=2,
)

minkowski_network = make_affinity(
    modality_a,
    metric="minkowski",
    metric_kwargs={"p": 3.5},
    n_neighbors=2,
)

Metric-specific data requirements follow SciPy. SNF2 rejects non-finite or negative pairwise distances.

Use affinity_matrix when distances have already been computed:

from snf2 import affinity_matrix

distances = np.array(
    [
        [0.0, 0.3, 1.2, 1.0],
        [0.3, 0.0, 1.0, 0.8],
        [1.2, 1.0, 0.0, 0.2],
        [1.0, 0.8, 0.2, 0.0],
    ],
)
precomputed_network = affinity_matrix(distances, n_neighbors=2)

The input to affinity_matrix is a distance matrix, not a similarity matrix. Convert similarities using a transformation appropriate to the similarity measure first. For similarities bounded to [0, 1], that transformation may be 1 - similarity. Pairwise-complete correlations and other missing-value policies must be handled upstream.

Documentation

The full documentation is available at bhklab.github.io/snf2. Report problems through the GitHub issue tracker.

Development

Pixi manages the development environments and lock file:

pixi install
pixi run -e dev check
pixi run -e docs docs-build

See the developer notes for the implementation provenance, compatibility boundaries, and release procedure.

Citation and provenance

Similarity Network Fusion was introduced in:

Wang B, Mezlini AM, Demir F, Fiume M, Tu Z, Brudno M, Haibe-Kains B, Goldenberg A. Similarity network fusion for aggregating data types on a genomic scale. Nature Methods. 2014;11:333–337. doi:10.1038/nmeth.2810

SNF2 was informed by pinned versions of SNFpy and SNFtool. Complete attribution and reference commits are recorded in NOTICE.

Authors and license

SNF2 is developed by Michael Tran and James Bannon at BHKLab. Contact bhklab.michaeltran@gmail.com.

SNF2 is distributed under the MIT License.

Metadata

Release files for snf2 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snf2 0.2.0
File Size Uploaded Provenance Actions
snf2-0.2.0.tar.gz 16.6 kB With provenance Details for snf2-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snf2 0.2.0
File Interpreter ABI Platform Actions
snf2-0.2.0-py3-none-any.whl Python 3 none any Details for snf2-0.2.0-py3-none-any.whl

Total release size: 26.6 kB

Release files / snf2-0.2.0.tar.gz

Download URL snf2-0.2.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8e8396612c43e0a1cf975a2f51d35b9f49ea67662938e240c5b770d01ff6e7ee
BLAKE2b-256 checksum
How to use checksums
4c242b9be97eea522ddabef9f782fde23df8bf21755bd008c57ee974e1d7c99d
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 3, 2026.

Transparency log

Release files / snf2-0.2.0-py3-none-any.whl

Download URL snf2-0.2.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1829559dbb13b81f741ff4864db5a07a79d82270544be1c13e4304d7ffbcabf1
BLAKE2b-256 checksum
How to use checksums
6971d012878dbd72f129e78ce896e196aedf2905a8867ad520fa88e30fd0c5d5
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 3, 2026.

Transparency log

Security for snf2 0.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for snf2-0.2.0.tar.gz

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 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page