oxytcmri.infrastructure.cli
¶
Command line interface.
Classes:
| Name | Description |
|---|---|
CLIOptionFactory |
Factory class for creating Typer CLI options with consistent parameters. |
DatabaseSetup |
Utility class for database configuration. |
CLIArgumentParser |
Parser for CLI arguments with support for various data types. |
ControllerFactory |
Factory for creating controllers with appropriate configurations. |
BaseDTICommand |
Abstract base class defining the common workflow for DTI commands. |
ComputeDTINormativeValuesCommand |
Command to compute DTI normative values. |
SegmentDTILesionsCommand |
Command to segment DTI lesions. |
ComputeBrainLesionsVolumesCommand |
Command to compute brain lesions volumes. |
LoadData |
Command to load data into the database. |
Functions:
| Name | Description |
|---|---|
load_data |
Load data into the database from configured importers. |
compute_dti_normative_values |
Compute DTI normative values for all centers and store the results in the database. |
segment_dti_lesions |
Segment DTI lesions based on normative values. |
compute_brain_lesions_volumes |
Compute brain lesions volumes for specified DTI metrics and MRI exam. |
Attributes:
| Name | Type | Description |
|---|---|---|
command_line_interface |
|
command_line_interface = typer.Typer(add_completion=False)
module-attribute
¶
CLIOptionFactory
¶
Factory class for creating Typer CLI options with consistent parameters.
Methods:
| Name | Description |
|---|---|
settings_option |
Create a standard settings file option. |
dti_metrics_option |
Create a standard DTI metrics option. |
statistics_strategies_option |
Create a statistics strategies option. |
mri_exam_id_option |
Create a standard MRI exam ID option. |
regions_of_interest_option |
Create a regions of interest option. |
settings_option()
staticmethod
¶
Create a standard settings file option.
Returns:
| Type | Description |
|---|---|
Option
|
Option for settings file path |
Source code in oxytcmri/infrastructure/cli.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
dti_metrics_option()
staticmethod
¶
Create a standard DTI metrics option.
Returns:
| Type | Description |
|---|---|
Option
|
Option for DTI metrics |
Source code in oxytcmri/infrastructure/cli.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
statistics_strategies_option()
staticmethod
¶
Create a statistics strategies option.
Returns:
| Type | Description |
|---|---|
Option
|
Option for statistics strategies |
Source code in oxytcmri/infrastructure/cli.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
mri_exam_id_option()
classmethod
¶
Create a standard MRI exam ID option.
Returns:
| Type | Description |
|---|---|
Option
|
Option for MRI exam ID |
Source code in oxytcmri/infrastructure/cli.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
regions_of_interest_option()
classmethod
¶
Create a regions of interest option.
Returns:
| Type | Description |
|---|---|
Option
|
Option for regions of interest |
Source code in oxytcmri/infrastructure/cli.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
DatabaseSetup
¶
Utility class for database configuration.
Methods:
| Name | Description |
|---|---|
create_database_gateway |
Configure and return a database gateway. |
create_database_gateway(settings)
staticmethod
¶
Configure and return a database gateway.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Settings
|
The application settings |
required |
Returns:
| Type | Description |
|---|---|
SQLModelSQLiteDataGateway
|
Configured database gateway |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If database file exists and overwrite_database_file is False |
Source code in oxytcmri/infrastructure/cli.py
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 | |
CLIArgumentParser
¶
Parser for CLI arguments with support for various data types.
This class centralizes the parsing logic for different types of CLI arguments, providing consistent error handling and format conversion.
Methods:
| Name | Description |
|---|---|
parse_dti_metrics |
Parse DTI metrics input and return a typed list. |
parse_statistics_strategies |
Parse statistics strategies input and return a typed list. |
parse_mri_exam_id |
Parse MRI exam ID input. |
parse_dti_metrics(metrics_input)
staticmethod
¶
Parse DTI metrics input and return a typed list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics_input
|
Optional[List[str]]
|
Raw input from CLI for DTI metrics |
required |
Returns:
| Type | Description |
|---|---|
List[DTIMetric]
|
Parsed DTI metrics |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid metrics are provided |
Source code in oxytcmri/infrastructure/cli.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
parse_statistics_strategies(strategies_input)
staticmethod
¶
Parse statistics strategies input and return a typed list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategies_input
|
Optional[List[str]]
|
Raw input from CLI for statistics strategies |
required |
Returns:
| Type | Description |
|---|---|
List[StatisticStrategy]
|
List of statistics strategies |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid strategies are provided |
Source code in oxytcmri/infrastructure/cli.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
parse_mri_exam_id(mri_exam_id)
classmethod
¶
Parse MRI exam ID input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mri_exam_id
|
Optional[str]
|
Raw input from CLI for MRI exam ID |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Parsed MRI exam ID |
Source code in oxytcmri/infrastructure/cli.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
ControllerFactory
¶
Factory for creating controllers with appropriate configurations.
Methods:
| Name | Description |
|---|---|
create_dti_controller |
Create and configure a controller for DTI operations. |
create_dti_controller(settings, database_gateway)
staticmethod
¶
Create and configure a controller for DTI operations.
Source code in oxytcmri/infrastructure/cli.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
BaseDTICommand(settings_filepath)
¶
Bases: ABC
Abstract base class defining the common workflow for DTI commands.
Initialize the command with common parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_filepath
|
str
|
Path to settings file |
required |
Methods:
| Name | Description |
|---|---|
execute |
Template method defining the workflow. |
Attributes:
| Name | Type | Description |
|---|---|---|
controller |
|
Source code in oxytcmri/infrastructure/cli.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
controller = ControllerFactory.create_dti_controller(settings, database_gateway)
instance-attribute
¶
execute()
abstractmethod
¶
Template method defining the workflow.
Source code in oxytcmri/infrastructure/cli.py
296 297 298 299 300 | |
ComputeDTINormativeValuesCommand(settings_filepath, dti_metrics=None, statistics_strategies=None)
¶
Bases: BaseDTICommand
Command to compute DTI normative values.
Initialize the command with specific parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_filepath
|
str
|
Path to settings file |
required |
dti_metrics
|
Optional[List[str]]
|
List of DTI metrics to compute |
None
|
statistics_strategies
|
Optional[List[str]]
|
List of statistics strategies to use |
None
|
Methods:
| Name | Description |
|---|---|
execute |
Process the compute DTI normative values command. |
Attributes:
| Name | Type | Description |
|---|---|---|
dti_metric_list |
|
|
statistics_strategies |
|
Source code in oxytcmri/infrastructure/cli.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
dti_metric_list = CLIArgumentParser.parse_dti_metrics(dti_metrics)
instance-attribute
¶
statistics_strategies = CLIArgumentParser.parse_statistics_strategies(statistics_strategies)
instance-attribute
¶
execute()
¶
Process the compute DTI normative values command.
Source code in oxytcmri/infrastructure/cli.py
326 327 328 329 330 331 332 | |
SegmentDTILesionsCommand(settings_filepath, dti_metrics=None, mri_exam_id=None)
¶
Bases: BaseDTICommand
Command to segment DTI lesions.
Initialize the command with specific parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_filepath
|
str
|
Path to settings file |
required |
dti_metrics
|
Optional[List[str]]
|
List of DTI metrics to segment |
None
|
mri_exam_id
|
Optional[str]
|
MRI exam ID to segment lesions |
None
|
Methods:
| Name | Description |
|---|---|
execute |
Process the segment DTI lesions command. |
Attributes:
| Name | Type | Description |
|---|---|---|
dti_metric_list |
|
|
mri_exam_id |
|
Source code in oxytcmri/infrastructure/cli.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
dti_metric_list = CLIArgumentParser.parse_dti_metrics(dti_metrics)
instance-attribute
¶
mri_exam_id = CLIArgumentParser.parse_mri_exam_id(mri_exam_id)
instance-attribute
¶
execute()
¶
Process the segment DTI lesions command.
Source code in oxytcmri/infrastructure/cli.py
357 358 359 360 361 362 363 364 | |
ComputeBrainLesionsVolumesCommand(settings_filepath, dti_metrics=None, mri_exam_id=None, regions_of_interest=None)
¶
Bases: BaseDTICommand
Command to compute brain lesions volumes.
Initialize the command with specific parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_filepath
|
str
|
Path to settings file |
required |
dti_metrics
|
Optional[List[str]]
|
List of DTI metrics to compute volumes for |
None
|
mri_exam_id
|
Optional[str]
|
MRI exam ID to compute volumes for |
None
|
regions_of_interest
|
Optional[List[str]]
|
Regions of interest for volume computation |
None
|
Methods:
| Name | Description |
|---|---|
execute |
Process the compute brain lesions volumes command. |
Attributes:
| Name | Type | Description |
|---|---|---|
dti_metric_list |
|
|
mri_exam_id |
|
|
regions_of_interest |
|
Source code in oxytcmri/infrastructure/cli.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
dti_metric_list = CLIArgumentParser.parse_dti_metrics(dti_metrics)
instance-attribute
¶
mri_exam_id = CLIArgumentParser.parse_mri_exam_id(mri_exam_id)
instance-attribute
¶
regions_of_interest = regions_of_interest or []
instance-attribute
¶
execute()
¶
Process the compute brain lesions volumes command.
Source code in oxytcmri/infrastructure/cli.py
393 394 395 396 397 398 399 | |
LoadData(settings_filepath)
¶
Bases: BaseDTICommand
Command to load data into the database.
Initialize the command with specific parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_filepath
|
str
|
Path to settings file |
required |
Methods:
| Name | Description |
|---|---|
execute |
Process the load data command. |
Source code in oxytcmri/infrastructure/cli.py
405 406 407 408 409 410 411 412 413 414 | |
execute()
¶
Process the load data command.
Source code in oxytcmri/infrastructure/cli.py
416 417 418 | |
load_data(settings_filepath=CLIOptionFactory.settings_option())
¶
Load data into the database from configured importers.
This command initializes the database and imports data from CSV files and NIfTI folders as specified in the settings.
Source code in oxytcmri/infrastructure/cli.py
421 422 423 424 425 426 427 428 429 430 431 | |
compute_dti_normative_values(settings_filepath=CLIOptionFactory.settings_option(), dti_metrics=CLIOptionFactory.dti_metrics_option(), statistics_strategies=CLIOptionFactory.statistics_strategies_option())
¶
Compute DTI normative values for all centers and store the results in the database.
This command processes DTI data to calculate normative values across centers for specified metrics and statistical strategies.
Source code in oxytcmri/infrastructure/cli.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
segment_dti_lesions(settings_filepath=CLIOptionFactory.settings_option(), dti_metrics=CLIOptionFactory.dti_metrics_option(), mri_exam_id=CLIOptionFactory.mri_exam_id_option())
¶
Segment DTI lesions based on normative values.
This command uses previously computed normative values to identify and segment abnormal regions in DTI data.
Source code in oxytcmri/infrastructure/cli.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
compute_brain_lesions_volumes(settings_filepath=CLIOptionFactory.settings_option(), dti_metrics=CLIOptionFactory.dti_metrics_option(), mri_exam_id=CLIOptionFactory.mri_exam_id_option(), regions_of_interest=CLIOptionFactory.regions_of_interest_option())
¶
Compute brain lesions volumes for specified DTI metrics and MRI exam.
This command calculates the volumes of brain lesions based on DTI metrics and specified regions of interest.
Source code in oxytcmri/infrastructure/cli.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |