Skip to main content

Python functions and classes to build connectivity graphs and datasets from Freesurfer's brain cortical measurements.

Project description

Pre-commit enabled License Code style: black Checked with mypy isort pyright Python Security Status Ruff Pre-commit checks Unittests Publish package

Avicortex - Brain Connectivity Graph Builder

Python functions and classes to build connectivity graphs and datasets from Freesurfer’s brain cortical measurements.

Installation

Avicortex datasets are written in torch-based classes and return torch-geometric Data objects as data samples. Therefore you need to have a compatible torch-geometric installation along with the torch installation.

$ pip install avicortex

Usage

First, you need to have the output stats table from Freesurfer outputs. A collection of commands can be executed from fs_utils/stats2table.sh file. In later versions, we will provide Python utilities to extract these stats tables as well.

One class is provided for HCP Young Adult dataset but the you need to access data from: https://www.humanconnectome.org/study/hcp-young-adult

>>> from avicortex.datasets import HCPYoungAdultDataset

After you have the table, you can point the path to your dataset as following:

>>> freesurfer_stat_path = "path/to/hcp/outputs"
>>> hcp_dataset_tr = HCPYoungAdultDataset(hemisphere="left", mode="train", freesurfer_out_path=freesurfer_stat_path)

Note that you can select a hemisphere; ‘right’ or ‘left’ and a mode for dataloading; ‘train’, ‘validation’, ‘test’ or ‘inference’, where ‘test’ is for loading the unseen data after your training is finished, and use ‘inference’ as an in-production mode when you do not have the labels but you want to have predictions.

Moreover, you can select a feature set for the source and target graphs that will be returned. Consider graphs in shape: Data(x=[batch_size, n_nodes, n_features], edge_attr=[batch_size, n_edges, n_features]). After the selection, you will have: Data(x=[batch_size, n_nodes, selection_idx], edge_attr=[batch_size, n_edges, selection_idx]). You can specify this while initializing:

>>> hcp_dataset_tr = HCPYoungAdultDataset(hemisphere="left", mode="train", freesurfer_out_path=freesurfer_stat_path, in_view_idx=0, out_view_idx=3)

Now you can put into a torch_geometric dataloader:

>>> from torch_geometric.loader import DataLoader as PygDataLoader
>>> hcp_dataloader_tr = PygDataLoader(hcp_dataset_tr)

Let’s take a look at the first sample:

>>> input_graph, target_graph = next(iter(hcp_dataloader_tr))

Output input_graph and target_graph will belong to the same patient. And you can also access their medical condition as a classification label:

>>> cls_label = target_graph.y

This class might represent different conditions, such as different diseases, age groups, or gender. For example, in HCP Young Adult dataset, label represents patient gender.

Contributing

Contributions are welcome and highly appreciated. Feel free to open issues and pull requests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

avicortex-0.1.3.tar.gz (572.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

avicortex-0.1.3-py3-none-any.whl (486.7 kB view details)

Uploaded Python 3

File details

Details for the file avicortex-0.1.3.tar.gz.

File metadata

  • Download URL: avicortex-0.1.3.tar.gz
  • Upload date:
  • Size: 572.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for avicortex-0.1.3.tar.gz
Algorithm Hash digest
SHA256 20dee3d0b905ee2fce27c661189c39f1b0e1a8af9ac3079c1f9273ccebfc6343
MD5 41f64e88410458e752edb04cf608519a
BLAKE2b-256 ce070c8c5fd575abe33a7870f6658b14cbca5d7cbe176c1386c3ddc63da57165

See more details on using hashes here.

File details

Details for the file avicortex-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: avicortex-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 486.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for avicortex-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 04242fc387f5a55b5e7512cd7d1bf183cc8a37b6b480470eea06068b2795ffa8
MD5 ae5c12e0081e7d6e8dd3596e49c421af
BLAKE2b-256 505031f5816b30f90e4182258f8f2812a07f63101fe291a999114034cdebdfff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page