keys
lacuna.core.keys
¶
BIDS-style result key helpers for analysis results.
This module provides utilities for building and parsing structured result keys that follow a BIDS-inspired key-value format:
atlas-{atlas}_source-{source}[_desc-{description}]
The desc component is optional and only included when needed (e.g., omitted for InputMask source since the mask itself is the primary data).
Examples:
>>> from lacuna.core.keys import build_result_key, parse_result_key
>>> key = build_result_key("Schaefer100", "FunctionalNetworkMapping", "rmap")
>>> key
'atlas-Schaefer100_source-FunctionalNetworkMapping_desc-rmap'
>>> parse_result_key(key)
{'atlas': 'Schaefer100', 'source': 'FunctionalNetworkMapping', 'desc': 'rmap'}
BidsFilename
dataclass
¶
Structured representation of a BIDS-compliant filename.
Entity ordering: method > space > atlas > desc > suffix. None fields are omitted from the string representation.
Source code in src/lacuna/core/keys.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
from_result_key(result_key, suffix, namespace=None)
classmethod
¶
Build a BidsFilename from an internal result key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_key
|
str
|
Internal result key — either a simple name (e.g. |
required |
suffix
|
str
|
Internal suffix ( |
required |
namespace
|
str
|
Analysis class name that produced the result (e.g.
|
None
|
Source code in src/lacuna/core/keys.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
build_result_key(atlas, source, desc=None)
¶
Build a BIDS-style result key from components.
Creates a structured key string in the format:
atlas-{atlas}_source-{source}[_desc-{desc}]
The desc component is optional and automatically omitted when source is InputMask/SubjectData (the mask itself is the primary data, no additional description needed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas
|
str
|
Atlas/parcellation name (e.g., "Schaefer100", "Tian_S4"). |
required |
source
|
str
|
Source analysis class name (e.g., "SubjectData", "FunctionalNetworkMapping"). Will be converted to appropriate source abbreviation (e.g., SubjectData -> InputMask). |
required |
desc
|
str
|
Description/key within the source (e.g., "rmap"). Ignored for InputMask source (automatically omitted). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
BIDS-style result key. |
Examples:
>>> build_result_key("Schaefer100", "FunctionalNetworkMapping", "rmap")
'atlas-Schaefer100_source-FunctionalNetworkMapping_desc-rmap'
>>> build_result_key("tian2020parcels16", "SubjectData", "maskimg")
'atlas-tian2020parcels16_source-InputMask'
>>> build_result_key("schaefer2018parcels200networks7", "RegionalDamage", "damagescore")
'atlas-schaefer2018parcels200networks7_source-RegionalDamage_desc-damagescore'
Source code in src/lacuna/core/keys.py
get_source_abbreviation(class_name)
¶
Validate and return the source name for an analysis class.
This function validates that the class name is a known analysis type and returns the appropriate source abbreviation for result keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name
|
str
|
Analysis class name (e.g., "FunctionalNetworkMapping", "SubjectData"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The source abbreviation for use in result keys. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If class_name is not a known analysis class. |
Examples:
>>> get_source_abbreviation("FunctionalNetworkMapping")
'FunctionalNetworkMapping'
>>> get_source_abbreviation("SubjectData")
'InputMask'
Source code in src/lacuna/core/keys.py
parse_result_key(key)
¶
Parse a BIDS-style result key into its components.
Extracts key-value pairs from a structured key string in the format:
atlas-{atlas}_source-{source}[_desc-{desc}]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
BIDS-style result key to parse. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary with parsed components. Keys are "atlas", "source", "desc". Missing components will not be present in the returned dict. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If key is empty or has invalid format. |
Examples:
>>> parse_result_key("atlas-Schaefer100_source-FunctionalNetworkMapping_desc-rmap")
{'atlas': 'Schaefer100', 'source': 'FunctionalNetworkMapping', 'desc': 'rmap'}
Source code in src/lacuna/core/keys.py
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 158 159 160 161 162 163 164 165 166 167 168 169 | |
to_bids_label(value)
¶
Convert a value to a BIDS-compliant label (single component).
BIDS labels cannot contain underscores (reserved for key-value separation). This function converts to lowercase and removes underscores for simple values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Value to convert to a single BIDS label component. |
required |
Returns:
| Type | Description |
|---|---|
str
|
BIDS-compliant lowercase label without underscores. |
Examples: