Metadata-Version: 2.4
Name: nsppk
Version: 3.3.0
Summary: Neighbourhood Subgraph Pairwise Pathway Kernel for graph feature extraction.
Author: Fabrizio Costa
License-Expression: MIT
Project-URL: Homepage, https://github.com/fabriziocosta/NSPPK
Project-URL: Documentation, https://nsppk.readthedocs.io/en/latest/
Project-URL: Repository, https://github.com/fabriziocosta/NSPPK
Project-URL: Issues, https://github.com/fabriziocosta/NSPPK/issues
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: networkx>=3.0
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Requires-Dist: scikit-learn>=1.3
Requires-Dist: matplotlib>=3.7
Requires-Dist: multiprocessing-on-dill>=3.5.0a4
Provides-Extra: docs
Requires-Dist: sphinx<9,>=7.2; extra == "docs"
Requires-Dist: myst-parser<5,>=2.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme<4,>=2.0; extra == "docs"
Dynamic: license-file

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14261713.svg)](https://doi.org/10.5281/zenodo.14261713)


<p align="center">
  <img src="https://raw.githubusercontent.com/fabriziocosta/NSPPK/main/assets/nsppk.png" alt="NSPPK graph logo" width="200">
</p>

# NSPPK


Neighbourhood Subgraph Pairwise Pathway Kernel (NSPPK) turns labeled NetworkX graphs into fixed-width feature vectors for graph-level prediction, node-level analysis, and scikit-learn workflows.

[**Read the documentation**](https://nsppk.readthedocs.io/en/latest/) · [Getting started](docs/GETTING_STARTED.md) · [API reference](docs/API.md)

## Install

NSPPK requires Python 3.10 or newer. Install the latest release from PyPI:

```bash
python -m pip install nsppk
```

## Your first graph features

Pass NSPPK a list of NetworkX `Graph`, `DiGraph`, `MultiGraph`, or `MultiDiGraph` objects. Each graph becomes one sample. For directed inputs, distances and neighborhoods use the undirected projection while hashes retain arc direction. Parallel edges and self-loops contribute individually. Node and edge labels can be any hashable values; a missing `label` is treated as `0`.

```python
import networkx as nx
from nsppk import NSPPK


def make_graph(node_labels):
    graph = nx.Graph()
    graph.add_nodes_from(
        (node_id, {"label": label})
        for node_id, label in enumerate(node_labels)
    )
    graph.add_edges_from(
        (u, v, {"label": "bond"})
        for u, v in [(0, 1), (1, 2)]
    )
    return graph


graphs = [
    make_graph(["C", "O", "C"]),
    make_graph(["C", "N", "C"]),
    make_graph(["O", "C", "O"]),
]

encoder = NSPPK(nbits=8, dense=False, parallel=False)
X = encoder.fit_transform(graphs)
print(X.shape)  # (3, 256): one row per graph
```

With `nbits=8` and no continuous node attributes, this example produces 256 structural features per graph. `dense=False` returns a SciPy sparse matrix; the default `dense=True` returns a NumPy array. For the default discrete-label setup, you can also call `encoder.transform(graphs)` directly.

## Choose what you need

- **Graph features:** `NSPPK` returns one feature row per graph, as shown above.
- **Node features:** `NodeNSPPK` returns one node-by-feature matrix per graph. Rows follow each graph’s `graph.nodes()` iteration order.
- **Edge features:** `EdgeNSPPK` returns one edge-by-feature matrix per graph. Rows follow NetworkX edge iteration order; multigraph rows retain each keyed edge, and directed rows include the ordered arc pattern.
- **Prediction:** `NSPPKClassifier` and `NSPPKRegressor` wrap graph vectorization with a scikit-learn estimator.

See the [getting-started guide](docs/GETTING_STARTED.md) for runnable examples of node features and prediction, and the [API reference](docs/API.md) for parameters and output details.

## Read graphs from files

The core install supports NetworkX graphs. Optional input formats require extra dependencies:

- SMILES and SDF: `python -m pip install rdkit`
- PyTorch Geometric files: install PyTorch for your platform, then `python -m pip install torch_geometric`. See the [PyTorch installation guide](https://pytorch.org/get-started/locally/) and [PyG installation guide](https://pytorch-geometric.readthedocs.io/en/stable/install/installation.html) for compatible platform and accelerator commands.

See [graph loading and streaming](docs/IO.md) for supported formats and examples. These optional packages are not installed with NSPPK.

## Documentation and examples

- [Getting started](docs/GETTING_STARTED.md)
- [API and output reference](docs/API.md)
- [Graph loading and streaming](docs/IO.md)
- [Node attributes](docs/ATTRIBUTES_INTEGRATION.md)
- [Hashing procedure](docs/HASH.md)
- [Node and feature importance](docs/IMPORTANCE_NSPPK.md)
- [Development and releases](docs/DEVELOPMENT.md)
- [Changelog](CHANGELOG.md)

Runnable notebooks are in `notebooks/`: `Demo.ipynb` covers graph features, `Graph Types Vectorization Demo.ipynb` compares multigraph, directed, and undirected inputs, `Importance Demo.ipynb` covers explanations, and `Streaming Benchmark.ipynb` covers loading and streaming. Other notebooks benchmark molecular graphs and supervised learning; some require optional packages. See [IO.md](docs/IO.md) for reader requirements.

## Develop from a checkout

From the repository root, install NSPPK in editable mode:

```bash
python -m pip install -e ".[docs]"
```

## Citation

The repository’s Zenodo DOI is [10.5281/zenodo.14261713](https://doi.org/10.5281/zenodo.14261713).
