Skip to main content

cg-gnn

cg-gnn (short for "Cell Graph - Graph Neural Networks") is a library to train a graph neural network model on graphs built out of cell spatial data to predict patient outcomes or any other y-variable you choose. This library is designed to be used with the Spatial Profiling Toolbox (SPT), although independent functionality is also possible provided you can provide cell graphs in the same format as SPT (as implemented in the graphs submodule).

In addition to standalone use, cg-gnn also serves as an example implementation of an SPT-compatible graph neural network pipeline, for open source developers to reference when building their own deep learning tools that use cell graphs created by SPT. The key features that have to be implemented are

  1. model training and inference
  2. cell-level importance score calculation If the input and output schema is followed, your tool will be compatible with the SPT ecosystem, allowing users to easily integrate your tool into their SPT workflows and upload your model's results to an SPT database.

This library is a heavily modified version of histocartography and two of its applications, hact-net and patho-quant-explainer.

Installation

Using pip

In addition to installing via pip,

pip install cg-gnn

you must also install using the instructions on their websites,

  • pytorch
  • DGL
  • CUDA (optional but highly recommended if your machine supports it)

From source

  1. Clone this repository
  2. Create a conda environment that can run this software using
conda env create -f environment.yml

Docker

For convenience, Dockerized versions of this package are provided at nadeemlab/spt-cg-gnn. We recommend using the CUDA-enabled version, provided it will run on your machine.

Quickstart

Use spt graphs extract and spt graphs generate-graphs to create cell graphs from a SPT database instance that this python package can use.

This module includes two scripts that you can call from the command line, or you can use the modules directly in Python.

  1. cg-gnn-train trains a graph neural network model on a set of cell graphs, saves the model to file, and updates the cell graphs it was trained on with cell-level importance-to-classification scores if an explainer model type is provided.
  2. cg-gnn-separability calculates class separability metrics given a trained model and other metadata.

Credits

As mentioned above, this repository is a heavily modified version of the histocartography project and two of its applications: hact-net and patho-quant-explainer. Specifically,

  • Cell graph formatting, saving, and loading using DGL is patterned on how they were implemented in hact-net
  • The neural network training and inference module is modified from the hact-net implementation for cell graphs
  • Importance score and separability calculations are sourced from patho-quant-explainer
  • The dependence on histocartography is indirect, through the functionality used by the above features

Due to dependency issues that arose when using the version of histocartography published on PyPI, we've chosen to copy and make slight updates to only the modules of histocartography used by the features supported in this library.

Metadata

Release files for cg-gnn 0.3.2

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

Source distribution (sdist)

Source distribution for cg-gnn 0.3.2
File Size Uploaded
cg_gnn-0.3.2.tar.gz 49.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cg-gnn 0.3.2
File Interpreter ABI Platform
cg_gnn-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 109.4 kB

Release files / cg_gnn-0.3.2.tar.gz

Download URL cg_gnn-0.3.2.tar.gz
Size 49.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7901e44caddd7fc0275124f9f3a3c8f9a02bc4e3b629e655227149261848e27f
BLAKE2b-256 checksum
How to use checksums
28a4df71465e1534c320ed134a9a727cce5dee3ee8061aa560476b31c65bee59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Linux/4.18.0-193.el8.x86_64

Release files / cg_gnn-0.3.2-py3-none-any.whl

Download URL cg_gnn-0.3.2-py3-none-any.whl
Size 59.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acd9db6c36f0bf86159ba70bfc67f42d524ac9ad9f76a71450d7610c4bac9b62
BLAKE2b-256 checksum
How to use checksums
1a447b92e2903f23c01d2013a3adcd5b472fb641bc208e83eef7d798ddc98989
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Linux/4.18.0-193.el8.x86_64

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3

2 release files

0.2.1

2 release files

0.2

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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