A Python library for brain connectivity analysis and visualization
Project description
CoBRA: Connectivity Brain Regional Analysis
A comprehensive Python library for analyzing cortical brain region connectivity using correlation matrices, hierarchical clustering, and network visualization.
Features
- Connectivity Matrix Analysis: Process and analyze correlation matrices between brain regions
- Hierarchical Clustering: Identify clusters of functionally related brain regions
- Network Visualization: Create publication-ready network graphs with flexible customization
- Statistical Analysis: Comprehensive cluster statistics and connectivity metrics
Installation
pip install cobra-brain
Quick Start
import numpy as np
from cobra import clustering, visualization, network
# Load your connectivity matrix and region names
connectivity_matrix = np.load('your_connectivity_matrix.npy')
regions = ['region1', 'region2', ...] # List of region names
# Perform clustering analysis
cluster_labels, reordered_matrix, reordered_regions = clustering.create_main_clustering_visualization(
connectivity_matrix, regions, n_clusters=8
)
# Create network visualization
G, pos = network.make_network_graph(
connectivity_matrix, regions, cluster_labels,
threshold=0.5, layout_type='spring'
)
# Generate cluster summary
clustering.plot_cluster_summary(regions, cluster_labels)
Core Components
Clustering (cobra.clustering)
prepare_clustering_data(): Prepare correlation matrices for hierarchical clusteringcreate_clustered_correlation_matrix(): Generate clustered heatmapsanalyze_clusters(): Statistical analysis of identified clustersplot_cluster_summary(): Visual cluster assignments
Network Analysis (cobra.network)
make_network_graph(): Create network graphs with customizable layouts- Multiple layout algorithms: spring, circular, force-atlas, kamada-kawai
- Flexible node coloring: by cluster, degree, betweenness centrality
- Adjustable edge filtering and styling
Advanced Usage
Custom Clustering
# Custom number of clusters with color coding
region_colors = clustering.generate_example_colors(regions, 'network')
cluster_labels = clustering.create_main_clustering_visualization(
connectivity_matrix, regions,
n_clusters=6,
region_colors=region_colors,
label_interval=10
)
Network Graph Customization
# Create a clean, minimal network
G, pos = network.make_network_graph(
connectivity_matrix, regions, cluster_labels,
threshold=0.6,
cleanliness='minimal',
color_by='degree',
layout_type='spring'
)
# Publication-ready labeled version
G, pos = network.make_network_graph(
connectivity_matrix, regions, cluster_labels,
cleanliness='labeled',
save_path='brain_network.png'
)
Statistical Analysis
# Detailed cluster analysis
clustering.analyze_clusters(connectivity_matrix, regions, cluster_labels)
# Original vs clustered matrix comparison
visualization.plot_original_correlation_matrix(
connectivity_matrix, regions,
region_colors=region_colors
)
Requirements
- Python >= 3.7
- NumPy >= 1.19.0
- SciPy >= 1.5.0
- Matplotlib >= 3.3.0
- NetworkX >= 2.5
- scikit-learn >= 0.23.0
Data Format
CoBRA expects:
- Connectivity Matrix: Square correlation matrix (n_regions × n_regions)
- Region Names: List of strings identifying each brain region
- Values: Correlation coefficients typically range from -1 to 1
Examples
The examples/ directory contains:
basic_usage.py: Simple workflow demonstrationsample_data.py: Generate synthetic brain connectivity data for testing
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use CoBRA in your research, please cite:
@software{cobra,
title={CoBRA: Cortical Brain Region Analysis},
author={Sidd Lokray},
year={2025},
url={https://github.com/siddlokray/cobra}
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For questions and issues, please open an issue on GitHub or contact [siddharthlokray@gmail.com].
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
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 cobra_brain-1.0.4.tar.gz.
File metadata
- Download URL: cobra_brain-1.0.4.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f555e3624829843df96b5060db0715d145cbdad3c539994206116f66ee8d3cf
|
|
| MD5 |
a48fd12d1d621d9330b1f77890f15a53
|
|
| BLAKE2b-256 |
90a2c684545618cb0f262929a77fc218b37c916a4ef9ad9968f2e4ababb2dbea
|
Provenance
The following attestation bundles were made for cobra_brain-1.0.4.tar.gz:
Publisher:
workflow.yml on siddlokray/cobra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cobra_brain-1.0.4.tar.gz -
Subject digest:
8f555e3624829843df96b5060db0715d145cbdad3c539994206116f66ee8d3cf - Sigstore transparency entry: 685285909
- Sigstore integration time:
-
Permalink:
siddlokray/cobra@cc89a0d754d60f2ec230af413c650e0f20ca799e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/siddlokray
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@cc89a0d754d60f2ec230af413c650e0f20ca799e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cobra_brain-1.0.4-py3-none-any.whl.
File metadata
- Download URL: cobra_brain-1.0.4-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eead12b9775101ed5579f05a284a0bc58ca10d015b7735b4c12b16536b6a8ad
|
|
| MD5 |
36a954ea7173beeefd8deef97a1d384a
|
|
| BLAKE2b-256 |
6c87296fa3074704d56c2e1cc33d044866f5f440cae4232392e10c9ed273e615
|
Provenance
The following attestation bundles were made for cobra_brain-1.0.4-py3-none-any.whl:
Publisher:
workflow.yml on siddlokray/cobra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cobra_brain-1.0.4-py3-none-any.whl -
Subject digest:
7eead12b9775101ed5579f05a284a0bc58ca10d015b7735b4c12b16536b6a8ad - Sigstore transparency entry: 685285912
- Sigstore integration time:
-
Permalink:
siddlokray/cobra@cc89a0d754d60f2ec230af413c650e0f20ca799e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/siddlokray
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@cc89a0d754d60f2ec230af413c650e0f20ca799e -
Trigger Event:
workflow_dispatch
-
Statement type: