obnb


Nameobnb JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryA Python toolkit for biological network learning evaluation
upload_time2023-06-16 18:54:31
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords data processing gene classification machine learning network biology network repositories
VCS
bugtrack_url
requirements class-resolver matplotlib mygene ndex2 numpy outdated pandas pyroe pyyaml requests scanpy scikit-learn tqdm
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI version](https://badge.fury.io/py/obnb.svg)](https://badge.fury.io/py/obnb)
[![Documentation Status](https://readthedocs.org/projects/obnb/badge/?version=latest)](https://obnb.readthedocs.io/en/latest/?badge=latest)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

[![Tests](https://github.com/krishnanlab/obnb/actions/workflows/tests.yml/badge.svg)](https://github.com/krishnanlab/obnb/actions/workflows/tests.yml)
[![Test Examples](https://github.com/krishnanlab/obnb/actions/workflows/examples.yml/badge.svg)](https://github.com/krishnanlab/obnb/actions/workflows/examples.yml)
[![Test Data](https://github.com/krishnanlab/obnb/actions/workflows/test_data.yml/badge.svg)](https://github.com/krishnanlab/obnb/actions/workflows/test_data.yml)

# Open Biomedical Network Benchmark

The Open Biomedical Network Benchmark (OBNB) is a comprehensive resource for setting up benchmarking graph datasets using _biomedical networks_ and _gene annotations_.
Our goal is to accelerate the adoption of advanced graph machine learning techniques, such as graph neural networks and graph embeddings, in network biology for gaining novel insights into genes' function, trait, and disease associations using biological networks.
To make this adoption convenient, OBNB also provides dataset objects compatible with popular graph deep learning frameworks, including [PyTorch Geometric (PyG)](https://github.com/pyg-team/pytorch_geometric) and [Deep Graph Library (DGL)](https://github.com/dmlc/dgl).

A comprehensive benchmarking study with a wide-range of graph neural networks and graph embedding methods on OBNB datasets can be found in our benchmarking repository [`obnbench`](https://github.com/krishnanlab/obnbench).

## Package usage

### Construct default datasets

We provide a high-level dataset constructor to help users easily set up benchmarking graph datasets
for a combination of network and label. In particular, the dataset will be set up with study-bias
holdout split (6/2/2), where 60% of the most well-studied genes according to the number of
associated PubMed publications are used for training, 20% of the least studied genes are used for
testing, and the rest of the 20% genes are used for validation. For more customizable data loading
and processing options, see the [customized dataset construction](#customized-dataset-construction)
section below.

```python
from obnb.dataset import OpenBiomedNetBench
from obnb.util.version import get_available_data_versions

root = "datasets"  # save dataset and cache under the datasets/ directory
version = "current"  # use the last archived version
# Optionally, set version to the specific data version number
# Or, set version to "latest" to download the latest data from source and process it from scratch

# Download and process network/label data. Use the adjacency matrix as the ML feature
dataset = OpenBiomedNetBench(root=root, graph_name="BioGRID", label_name="DisGeNET",
                             version=version, graph_as_feature=True, use_dense_graph=True)

# Check the specific archive data version used
print(dataset.version)

# Check all available stable archive data versions
print(get_available_data_versions())
```

Users can also load the dataset objects into ones that are compatible with PyG or DGL (see below).

#### PyG dataset

```python
from obnb.dataset import OpenBiomedNetBenchPyG
dataset = OpenBiomedNetBenchPyG(root, "BioGRID", "DisGeNET")
```

**Note**: requires installing PyG first (see [installation instructions](https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html))

#### DGL dataset

```python
from obnb.dataset import OpenBiomedNetBenchDGL
dataset = OpenBiomedNetBenchDGL(root, "BioGRID", "DisGeNET")
```

**Note**: requires installing DGL first (see [installation instructions](https://www.dgl.ai/pages/start.html))

### Evaluating standard models

Evaluation of simple machine learning methods such as logistic regression and label propagation
can be done easily using the trainer objects.

```python
from obnb.model_trainer import SupervisedLearningTrainer, LabelPropagationTrainer

sl_trainer = SupervisedLearningTrainer()
lp_trainer = LabelPropagationTrainer()
```

Then, use the `fit_and_eval` method of the trainer to evaluate a given ML model over all tasks
in a one-vs-rest setting.

```python
from sklearn.linear_model import LogisticRegression
from obnb.model.label_propagation import OneHopPropagation

# Initialize models
sl_mdl = LogisticRegression(penalty="l2", solver="lbfgs")
lp_mdl = OneHopPropagation()

# Evaluate the models over all tasks
sl_results = sl_trainer.fit_and_eval(sl_mdl, dataset)
lp_results = lp_trainer.fit_and_eval(lp_mdl, dataset)
```

### Evaluating GNN models

Training and evaluation of Graph Neural Network (GNN) models can be done in a very similar fashion.

```python
from torch_geometric.nn import GCN
from obnb.model_trainer.gnn import SimpleGNNTrainer

# Use 1-dimensional trivial node feature by default
dataset = OpenBiomedNetBench(root=root, graph_name="BioGRID", label_name="DisGeNET", version=version)

# Train and evaluate a GCN
gcn_mdl = GCN(in_channels=1, hidden_channels=64, num_layers=5, out_channels=n_tasks)
gcn_trainer = SimpleGNNTrainer(device="cuda", metric_best="apop")
gcn_results = gcn_trainer.train(gcn_mdl, dataset)
```

### Customized dataset construction

#### Load network and labels

```python
from obnb import data

# Load processed BioGRID data from archive.
g = data.BioGRID(root, version=version)

# Load DisGeNET gene set collections.
lsc = data.DisGeNET(root, version=version)
```

#### Setting up data and splits

```python
from obnb.util.converter import GenePropertyConverter
from obnb.label.split import RatioHoldout

# Load PubMed count gene property converter and use it to set up study-bias holdout split
pubmedcnt_converter = GenePropertyConverter(root, name="PubMedCount")
splitter = RatioHoldout(0.6, 0.4, ascending=False, property_converter=pubmedcnt_converter)
```

#### Filter labeled data based on network genes and splits

```python
# Apply in-place filters to the labelset collection
lsc.iapply(
    filters.Compose(
        # Only use genes that are present in the network
        filters.EntityExistenceFilter(list(g.node_ids)),
        # Remove any labelsets with less than 50 network genes
        filters.LabelsetRangeFilterSize(min_val=50),
        # Make sure each split has at least 10 positive examples
        filters.LabelsetRangeFilterSplit(min_val=10, splitter=splitter),
    ),
)
```

#### Combine into dataset

```python
from obnb import Dataset
dataset = Dataset(graph=g, feature=g.to_dense_graph().to_feature(), label=lsc, splitter=splitter)
```

## Installation

OBNB can be installed easily via pip from [PyPI](https://pypi.org/project/obnb/):

```bash
pip install obnb
```

### Install with extension modules (optional)

OBNB provides interfaces with several other packages for network feature extractions, such as
[PecanPy](https://github.com/krishnanlab/PecanPy) and [GraPE](https://github.com/AnacletoLAB/grape).
To enable those extensions, install `obnb` with the `ext` extra option enabled:

```bash
pip install obnb[ext]
```

### Install graph deep learning libraries (optional)

Follow installation instructions for [PyG](https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html) or [DGL](https://www.dgl.ai/pages/start.html) to set up the graph deep learning library of your choice.

Alternatively, we also provide an [installation script](install.sh) that helps you installthe graph deep-learning dependencies in a new conda environment `obnb`:

```bash
git clone https://github.com/krishnanlab/obnb && cd obnb
source install.sh cu117  # other options are [cpu,cu118]
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "obnb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "Data Processing,Gene Classification,Machine Learning,Network Biology,Network Repositories",
    "author": "",
    "author_email": "Remy Liu <liurenmi@msu.edu>",
    "download_url": "https://files.pythonhosted.org/packages/7c/6e/581f60b1b0acf07c3ba8b51f3357ae31e38374276ab62e0d87e5b28871cc/obnb-0.1.0.tar.gz",
    "platform": null,
    "description": "[![PyPI version](https://badge.fury.io/py/obnb.svg)](https://badge.fury.io/py/obnb)\n[![Documentation Status](https://readthedocs.org/projects/obnb/badge/?version=latest)](https://obnb.readthedocs.io/en/latest/?badge=latest)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n\n[![Tests](https://github.com/krishnanlab/obnb/actions/workflows/tests.yml/badge.svg)](https://github.com/krishnanlab/obnb/actions/workflows/tests.yml)\n[![Test Examples](https://github.com/krishnanlab/obnb/actions/workflows/examples.yml/badge.svg)](https://github.com/krishnanlab/obnb/actions/workflows/examples.yml)\n[![Test Data](https://github.com/krishnanlab/obnb/actions/workflows/test_data.yml/badge.svg)](https://github.com/krishnanlab/obnb/actions/workflows/test_data.yml)\n\n# Open Biomedical Network Benchmark\n\nThe Open Biomedical Network Benchmark (OBNB) is a comprehensive resource for setting up benchmarking graph datasets using _biomedical networks_ and _gene annotations_.\nOur goal is to accelerate the adoption of advanced graph machine learning techniques, such as graph neural networks and graph embeddings, in network biology for gaining novel insights into genes' function, trait, and disease associations using biological networks.\nTo make this adoption convenient, OBNB also provides dataset objects compatible with popular graph deep learning frameworks, including [PyTorch Geometric (PyG)](https://github.com/pyg-team/pytorch_geometric) and [Deep Graph Library (DGL)](https://github.com/dmlc/dgl).\n\nA comprehensive benchmarking study with a wide-range of graph neural networks and graph embedding methods on OBNB datasets can be found in our benchmarking repository [`obnbench`](https://github.com/krishnanlab/obnbench).\n\n## Package usage\n\n### Construct default datasets\n\nWe provide a high-level dataset constructor to help users easily set up benchmarking graph datasets\nfor a combination of network and label. In particular, the dataset will be set up with study-bias\nholdout split (6/2/2), where 60% of the most well-studied genes according to the number of\nassociated PubMed publications are used for training, 20% of the least studied genes are used for\ntesting, and the rest of the 20% genes are used for validation. For more customizable data loading\nand processing options, see the [customized dataset construction](#customized-dataset-construction)\nsection below.\n\n```python\nfrom obnb.dataset import OpenBiomedNetBench\nfrom obnb.util.version import get_available_data_versions\n\nroot = \"datasets\"  # save dataset and cache under the datasets/ directory\nversion = \"current\"  # use the last archived version\n# Optionally, set version to the specific data version number\n# Or, set version to \"latest\" to download the latest data from source and process it from scratch\n\n# Download and process network/label data. Use the adjacency matrix as the ML feature\ndataset = OpenBiomedNetBench(root=root, graph_name=\"BioGRID\", label_name=\"DisGeNET\",\n                             version=version, graph_as_feature=True, use_dense_graph=True)\n\n# Check the specific archive data version used\nprint(dataset.version)\n\n# Check all available stable archive data versions\nprint(get_available_data_versions())\n```\n\nUsers can also load the dataset objects into ones that are compatible with PyG or DGL (see below).\n\n#### PyG dataset\n\n```python\nfrom obnb.dataset import OpenBiomedNetBenchPyG\ndataset = OpenBiomedNetBenchPyG(root, \"BioGRID\", \"DisGeNET\")\n```\n\n**Note**: requires installing PyG first (see [installation instructions](https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html))\n\n#### DGL dataset\n\n```python\nfrom obnb.dataset import OpenBiomedNetBenchDGL\ndataset = OpenBiomedNetBenchDGL(root, \"BioGRID\", \"DisGeNET\")\n```\n\n**Note**: requires installing DGL first (see [installation instructions](https://www.dgl.ai/pages/start.html))\n\n### Evaluating standard models\n\nEvaluation of simple machine learning methods such as logistic regression and label propagation\ncan be done easily using the trainer objects.\n\n```python\nfrom obnb.model_trainer import SupervisedLearningTrainer, LabelPropagationTrainer\n\nsl_trainer = SupervisedLearningTrainer()\nlp_trainer = LabelPropagationTrainer()\n```\n\nThen, use the `fit_and_eval` method of the trainer to evaluate a given ML model over all tasks\nin a one-vs-rest setting.\n\n```python\nfrom sklearn.linear_model import LogisticRegression\nfrom obnb.model.label_propagation import OneHopPropagation\n\n# Initialize models\nsl_mdl = LogisticRegression(penalty=\"l2\", solver=\"lbfgs\")\nlp_mdl = OneHopPropagation()\n\n# Evaluate the models over all tasks\nsl_results = sl_trainer.fit_and_eval(sl_mdl, dataset)\nlp_results = lp_trainer.fit_and_eval(lp_mdl, dataset)\n```\n\n### Evaluating GNN models\n\nTraining and evaluation of Graph Neural Network (GNN) models can be done in a very similar fashion.\n\n```python\nfrom torch_geometric.nn import GCN\nfrom obnb.model_trainer.gnn import SimpleGNNTrainer\n\n# Use 1-dimensional trivial node feature by default\ndataset = OpenBiomedNetBench(root=root, graph_name=\"BioGRID\", label_name=\"DisGeNET\", version=version)\n\n# Train and evaluate a GCN\ngcn_mdl = GCN(in_channels=1, hidden_channels=64, num_layers=5, out_channels=n_tasks)\ngcn_trainer = SimpleGNNTrainer(device=\"cuda\", metric_best=\"apop\")\ngcn_results = gcn_trainer.train(gcn_mdl, dataset)\n```\n\n### Customized dataset construction\n\n#### Load network and labels\n\n```python\nfrom obnb import data\n\n# Load processed BioGRID data from archive.\ng = data.BioGRID(root, version=version)\n\n# Load DisGeNET gene set collections.\nlsc = data.DisGeNET(root, version=version)\n```\n\n#### Setting up data and splits\n\n```python\nfrom obnb.util.converter import GenePropertyConverter\nfrom obnb.label.split import RatioHoldout\n\n# Load PubMed count gene property converter and use it to set up study-bias holdout split\npubmedcnt_converter = GenePropertyConverter(root, name=\"PubMedCount\")\nsplitter = RatioHoldout(0.6, 0.4, ascending=False, property_converter=pubmedcnt_converter)\n```\n\n#### Filter labeled data based on network genes and splits\n\n```python\n# Apply in-place filters to the labelset collection\nlsc.iapply(\n    filters.Compose(\n        # Only use genes that are present in the network\n        filters.EntityExistenceFilter(list(g.node_ids)),\n        # Remove any labelsets with less than 50 network genes\n        filters.LabelsetRangeFilterSize(min_val=50),\n        # Make sure each split has at least 10 positive examples\n        filters.LabelsetRangeFilterSplit(min_val=10, splitter=splitter),\n    ),\n)\n```\n\n#### Combine into dataset\n\n```python\nfrom obnb import Dataset\ndataset = Dataset(graph=g, feature=g.to_dense_graph().to_feature(), label=lsc, splitter=splitter)\n```\n\n## Installation\n\nOBNB can be installed easily via pip from [PyPI](https://pypi.org/project/obnb/):\n\n```bash\npip install obnb\n```\n\n### Install with extension modules (optional)\n\nOBNB provides interfaces with several other packages for network feature extractions, such as\n[PecanPy](https://github.com/krishnanlab/PecanPy) and [GraPE](https://github.com/AnacletoLAB/grape).\nTo enable those extensions, install `obnb` with the `ext` extra option enabled:\n\n```bash\npip install obnb[ext]\n```\n\n### Install graph deep learning libraries (optional)\n\nFollow installation instructions for [PyG](https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html) or [DGL](https://www.dgl.ai/pages/start.html) to set up the graph deep learning library of your choice.\n\nAlternatively, we also provide an [installation script](install.sh) that helps you installthe graph deep-learning dependencies in a new conda environment `obnb`:\n\n```bash\ngit clone https://github.com/krishnanlab/obnb && cd obnb\nsource install.sh cu117  # other options are [cpu,cu118]\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python toolkit for biological network learning evaluation",
    "version": "0.1.0",
    "project_urls": {
        "bug-tracker": "https://github.com/krishnanlab/obnb/issues",
        "home": "https://github.com/krishnanlab/obnb"
    },
    "split_keywords": [
        "data processing",
        "gene classification",
        "machine learning",
        "network biology",
        "network repositories"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cb820668dd37ab8013defac84f6e7be8ad4d534d3bba34e6a0abc79e02c8f37e",
                "md5": "2b92247d26674060725ec4579208817c",
                "sha256": "a4789ad797a650dc958cf93beac1a9161a0001ad3c0b3d4860a6ec475b78b590"
            },
            "downloads": -1,
            "filename": "obnb-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2b92247d26674060725ec4579208817c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 145053,
            "upload_time": "2023-06-16T18:54:29",
            "upload_time_iso_8601": "2023-06-16T18:54:29.385190Z",
            "url": "https://files.pythonhosted.org/packages/cb/82/0668dd37ab8013defac84f6e7be8ad4d534d3bba34e6a0abc79e02c8f37e/obnb-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c6e581f60b1b0acf07c3ba8b51f3357ae31e38374276ab62e0d87e5b28871cc",
                "md5": "1c68d476b23e6696d573d998ad01950c",
                "sha256": "4ed8c64fed201ab54f4342a5ab0ff54d00fb563c87e83294a839b85888a8a081"
            },
            "downloads": -1,
            "filename": "obnb-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1c68d476b23e6696d573d998ad01950c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 117753,
            "upload_time": "2023-06-16T18:54:31",
            "upload_time_iso_8601": "2023-06-16T18:54:31.189143Z",
            "url": "https://files.pythonhosted.org/packages/7c/6e/581f60b1b0acf07c3ba8b51f3357ae31e38374276ab62e0d87e5b28871cc/obnb-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-16 18:54:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "krishnanlab",
    "github_project": "obnb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "class-resolver",
            "specs": [
                [
                    "==",
                    "0.4.2"
                ]
            ]
        },
        {
            "name": "matplotlib",
            "specs": [
                [
                    "<",
                    "3.8"
                ]
            ]
        },
        {
            "name": "mygene",
            "specs": [
                [
                    "==",
                    "3.2.2"
                ]
            ]
        },
        {
            "name": "ndex2",
            "specs": [
                [
                    "==",
                    "3.5.1"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "1.23.3"
                ]
            ]
        },
        {
            "name": "outdated",
            "specs": [
                [
                    "==",
                    "0.2.2"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    "==",
                    "2.0.2"
                ]
            ]
        },
        {
            "name": "pyroe",
            "specs": [
                [
                    "==",
                    "0.9.0"
                ]
            ]
        },
        {
            "name": "pyyaml",
            "specs": [
                [
                    "==",
                    "6.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "scanpy",
            "specs": [
                [
                    "==",
                    "1.9.3"
                ]
            ]
        },
        {
            "name": "scikit-learn",
            "specs": [
                [
                    "==",
                    "1.2.2"
                ]
            ]
        },
        {
            "name": "tqdm",
            "specs": [
                [
                    "==",
                    "4.65.0"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "obnb"
}
        
Elapsed time: 1.51155s