SNF2
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snf2-0.2.0.tar.gz.
File metadata
- Download URL: snf2-0.2.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e8396612c43e0a1cf975a2f51d35b9f49ea67662938e240c5b770d01ff6e7ee
|
|
| MD5 |
f47951941f24ba4626ab369c82c60d14
|
|
| BLAKE2b-256 |
4c242b9be97eea522ddabef9f782fde23df8bf21755bd008c57ee974e1d7c99d
|
Provenance
The following attestation bundles were made for snf2-0.2.0.tar.gz:
Publisher:
release-please.yaml on bhklab/snf2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snf2-0.2.0.tar.gz -
Subject digest:
8e8396612c43e0a1cf975a2f51d35b9f49ea67662938e240c5b770d01ff6e7ee - Sigstore transparency entry: 2702742207
- Sigstore integration time:
-
Permalink:
bhklab/snf2@2f0424f43c276214a950a5958f2bfca2fdc61d47 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bhklab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yaml@2f0424f43c276214a950a5958f2bfca2fdc61d47 -
Trigger Event:
push
-
Statement type:
File details
Details for the file snf2-0.2.0-py3-none-any.whl.
File metadata
- Download URL: snf2-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1829559dbb13b81f741ff4864db5a07a79d82270544be1c13e4304d7ffbcabf1
|
|
| MD5 |
db4820eb788dc0ae16130fdb334ecf49
|
|
| BLAKE2b-256 |
6971d012878dbd72f129e78ce896e196aedf2905a8867ad520fa88e30fd0c5d5
|
Provenance
The following attestation bundles were made for snf2-0.2.0-py3-none-any.whl:
Publisher:
release-please.yaml on bhklab/snf2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
snf2-0.2.0-py3-none-any.whl -
Subject digest:
1829559dbb13b81f741ff4864db5a07a79d82270544be1c13e4304d7ffbcabf1 - Sigstore transparency entry: 2702742436
- Sigstore integration time:
-
Permalink:
bhklab/snf2@2f0424f43c276214a950a5958f2bfca2fdc61d47 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/bhklab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yaml@2f0424f43c276214a950a5958f2bfca2fdc61d47 -
Trigger Event:
push
-
Statement type: