connectomes
lacuna.assets.connectomes
¶
Connectome asset management for Lacuna.
This module provides connectome registry and loading for both structural (tractography-based) and functional (fMRI voxel-wise) connectomes.
Structural connectomes are used for structural lesion network mapping (sLNM) and require tractogram + TDI files.
Functional connectomes are used for functional lesion network mapping (fLNM) and require HDF5 files with voxel-wise timeseries data (not parcellated matrices).
FunctionalConnectome
dataclass
¶
Loaded functional connectome for fLNM analysis.
Provides path to HDF5 file(s) with voxel-wise timeseries data needed for FunctionalNetworkMapping analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
metadata |
FunctionalConnectomeMetadata
|
Connectome metadata |
data_path |
Path
|
Path to .h5 file or directory with batch files |
is_batched |
bool
|
True if data_path points to directory with multiple files |
Source code in src/lacuna/assets/connectomes/functional.py
FunctionalConnectomeMetadata
dataclass
¶
Bases: SpatialAssetMetadata
Metadata for a functional connectome (voxel-wise timeseries).
Used for functional lesion network mapping (fLNM). Requires HDF5 file(s) containing whole-brain voxel-wise BOLD timeseries data.
HDF5 structure: - 'timeseries': (n_subjects, n_timepoints, n_voxels) array - 'mask_indices': (3, n_voxels) or (n_voxels, 3) brain mask coordinates - 'mask_affine': (4, 4) affine transformation matrix - 'mask_shape': Tuple as attribute (e.g., (91, 109, 91))
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier (e.g., "GSP1000") |
space |
str
|
Coordinate space (typically "MNI152NLin6Asym") |
resolution |
float
|
Resolution in mm (typically 2.0 for functional data) |
description |
str
|
Human-readable description |
n_subjects |
int
|
Sample size in connectome |
modality |
str
|
Imaging modality (always "bold") |
data_path |
Path
|
Path to .h5 file or directory containing batch files |
is_batched |
bool
|
True if data_path is directory with multiple HDF5 files |
Source code in src/lacuna/assets/connectomes/registry.py
__repr__()
¶
Concise representation showing only essential fields.
Source code in src/lacuna/assets/connectomes/registry.py
StructuralConnectome
dataclass
¶
Loaded structural connectome for sLNM analysis.
Provides tractogram path for StructuralNetworkMapping analysis. TDI is computed on-the-fly during analysis (with optional caching).
Attributes:
| Name | Type | Description |
|---|---|---|
metadata |
StructuralConnectomeMetadata
|
Connectome metadata |
tractogram_path |
Path
|
Path to .tck streamlines file |
template_path |
Path | None
|
Optional template image path |
Source code in src/lacuna/assets/connectomes/structural.py
StructuralConnectomeMetadata
dataclass
¶
Bases: SpatialAssetMetadata
Metadata for a structural connectome (tractography-based).
Used for structural lesion network mapping (sLNM). Requires: - Tractogram file (.tck format from MRtrix3) - TDI computed on-the-fly during analysis (with optional caching)
Note: Unlike functional connectomes, structural connectomes (tractograms) don't have an inherent voxel resolution - they exist in continuous 3D space. The output resolution is controlled by the StructuralNetworkMapping analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier (e.g., "dTOR985") |
space |
str
|
Coordinate space (typically "MNI152NLin2009bAsym") |
resolution |
float
|
Resolution in mm (placeholder value, not used for tractograms) |
description |
str
|
Human-readable description |
modality |
str
|
Imaging modality (always "dwi") |
tractogram_path |
Path
|
Path to .tck streamlines file |
template_path |
Path | None
|
Optional path to template image defining output grid |
Source code in src/lacuna/assets/connectomes/registry.py
__repr__()
¶
Concise representation showing only essential fields.
Source code in src/lacuna/assets/connectomes/registry.py
validate()
¶
Validate space only (tractograms don't have inherent resolution).
Raises:
| Type | Description |
|---|---|
ValueError
|
If space is invalid |
Source code in src/lacuna/assets/connectomes/registry.py
list_functional_connectomes(space=None)
¶
List registered functional connectomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
str
|
Filter by coordinate space |
None
|
Returns:
| Type | Description |
|---|---|
list[FunctionalConnectomeMetadata]
|
Matching connectomes |
Examples:
>>> from lacuna.assets.connectomes import list_functional_connectomes
>>>
>>> # List all
>>> connectomes = list_functional_connectomes()
>>>
>>> # Filter by space
>>> mni_connectomes = list_functional_connectomes(space="MNI152NLin6Asym")
Source code in src/lacuna/assets/connectomes/functional.py
list_structural_connectomes(atlas=None, space=None)
¶
List registered structural connectomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas
|
str
|
Filter by atlas name |
None
|
space
|
str
|
Filter by coordinate space |
None
|
Returns:
| Type | Description |
|---|---|
list[StructuralConnectomeMetadata]
|
Matching connectomes |
Examples:
>>> from lacuna.assets.connectomes import list_structural_connectomes
>>>
>>> # List all
>>> connectomes = list_structural_connectomes()
>>>
>>> # Filter by atlas
>>> schaefer_connectomes = list_structural_connectomes(
... atlas="schaefer2018parcels100networks7"
... )
Source code in src/lacuna/assets/connectomes/structural.py
load_functional_connectome(name)
¶
Load a functional connectome for fLNM analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Returns:
| Type | Description |
|---|---|
FunctionalConnectome
|
Loaded connectome with path ready for FunctionalNetworkMapping |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Examples:
>>> from lacuna.assets.connectomes import load_functional_connectome
>>> from lacuna.analysis import FunctionalNetworkMapping
>>>
>>> connectome = load_functional_connectome("GSP1000")
>>> analysis = FunctionalNetworkMapping(
... connectome_path=connectome.data_path,
... method="boes"
... )
Source code in src/lacuna/assets/connectomes/functional.py
load_structural_connectome(name)
¶
Load a structural connectome for sLNM analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Returns:
| Type | Description |
|---|---|
StructuralConnectome
|
Loaded connectome with tractogram path ready for StructuralNetworkMapping. TDI will be computed on-the-fly during analysis. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Examples:
>>> from lacuna.assets.connectomes import load_structural_connectome
>>> from lacuna.analysis import StructuralNetworkMapping
>>>
>>> connectome = load_structural_connectome("dTOR985")
>>> analysis = StructuralNetworkMapping(
... connectome_name="dTOR985",
... cache_tdi=True # Cache computed TDI for reuse
... )
Source code in src/lacuna/assets/connectomes/structural.py
register_functional_connectome(name, space, resolution, data_path, n_subjects=None, description='')
¶
Register a functional connectome for fLNM analysis.
Supports both single HDF5 files and directories with batched files.
HDF5 Required Structure: - 'timeseries': (n_subjects, n_timepoints, n_voxels) array - 'mask_indices': (3, n_voxels) or (n_voxels, 3) coordinates - 'mask_affine': (4, 4) affine matrix - 'mask_shape': Tuple attribute (e.g., (91, 109, 91))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique identifier (e.g., "GSP1000") |
required |
space
|
str
|
Coordinate space (e.g., "MNI152NLin6Asym") |
required |
resolution
|
float
|
Resolution in mm (typically 2.0) |
required |
data_path
|
str or Path
|
Path to .h5 file or directory containing batch files |
required |
n_subjects
|
int
|
Total sample size (for documentation purposes only) |
None
|
description
|
str
|
Human-readable description |
''
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If data_path doesn't exist |
ValueError
|
If HDF5 structure is invalid |
Examples:
>>> from lacuna.assets.connectomes import register_functional_connectome
>>>
>>> # Single file
>>> register_functional_connectome(
... name="GSP1000",
... space="MNI152NLin6Asym",
... resolution=2.0,
... data_path="/data/gsp/gsp1000_connectome.h5",
... description="GSP1000 voxel-wise connectome"
... )
>>>
>>> # Batched directory
>>> register_functional_connectome(
... name="GSP1000_batched",
... space="MNI152NLin6Asym",
... resolution=2.0,
... data_path="/data/gsp/batches/",
... description="GSP1000 voxel-wise connectome (batched)"
... )
Source code in src/lacuna/assets/connectomes/functional.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
register_structural_connectome(name, space, tractogram_path, template_path=None, description='')
¶
Register a structural connectome for sLNM analysis.
TDI is computed on-the-fly during analysis. Use cache_tdi=True (default) in StructuralNetworkMapping to cache computed TDIs for reuse, or cache_tdi=False to compute without caching.
Note: Unlike functional connectomes, structural connectomes (tractograms) don't
have an inherent voxel resolution - they exist in continuous 3D space. The output
resolution is controlled by the output_resolution parameter in
StructuralNetworkMapping analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique identifier (e.g., "dTOR985") |
required |
space
|
str
|
Coordinate space (e.g., "MNI152NLin2009bAsym") |
required |
tractogram_path
|
str or Path
|
Path to .tck whole-brain streamlines file |
required |
template_path
|
str or Path
|
Path to template image for output grid |
None
|
description
|
str
|
Human-readable description |
''
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If tractogram file doesn't exist |
ValueError
|
If file validation fails |
Examples:
>>> from lacuna.assets.connectomes import register_structural_connectome
>>>
>>> # Register tractogram (TDI computed on-the-fly during analysis)
>>> register_structural_connectome(
... name="dTOR985",
... space="MNI152NLin2009cAsym",
... tractogram_path="/data/dtor/dTOR985_tractogram.tck",
... description="dTOR tractogram - TDI computed on-demand"
... )
Source code in src/lacuna/assets/connectomes/structural.py
unregister_functional_connectome(name)
¶
Unregister a functional connectome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Source code in src/lacuna/assets/connectomes/functional.py
unregister_structural_connectome(name)
¶
Unregister a structural connectome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Examples:
>>> from lacuna.assets.connectomes import unregister_structural_connectome
>>> unregister_structural_connectome("dTOR985")