Skip to content

cli

oxytcmri.infrastructure.cli

Command line interface.

Functions:

Name Description
compute_dti_normative_values

Compute DTI normative values for all centers and store the results in the database.

segment_dti_lesions

Attributes:

Name Type Description
command_line_interface

command_line_interface = typer.Typer(add_completion=False) module-attribute

compute_dti_normative_values(settings_filepath=typer.Option(..., '--settings', '-s', help='Path to the settings file'), overwrite_database_file=typer.Option(True, '--overwrite_database_file', '-odbf', help='Delete the database file if it already exists'), dti_metrics=typer.Option(None, '--dti-metrics', '-dti', help="Comma-separated list of DTI metrics to include in computations (e.g. 'FA,MD')"), statistics_strategies=typer.Option(None, '--statistics-strategies', '-stats', help="Comma-separated list of statistical strategies to include in computations (e.g. 'mean,std_dev')"))

Compute DTI normative values for all centers and store the results in the database.

Source code in oxytcmri/infrastructure/cli.py
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 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
@command_line_interface.command()
def compute_dti_normative_values(
        settings_filepath: str = typer.Option(
            ...,
            "--settings",
            "-s",
            help="Path to the settings file"
        ),
        overwrite_database_file: bool = typer.Option(
            True,
            "--overwrite_database_file",
            "-odbf",
            help="Delete the database file if it already exists"
        ),
        dti_metrics: Optional[List[str]] = typer.Option(
            None,
            "--dti-metrics",
            "-dti",
            help="Comma-separated list of DTI metrics to include in computations (e.g. 'FA,MD')"
        ),
        statistics_strategies: Optional[List[str]] = typer.Option(
            None,
            "--statistics-strategies",
            "-stats",
            help="Comma-separated list of statistical strategies to include in computations (e.g. 'mean,std_dev')"
        ),
):
    """
    Compute DTI normative values for all centers and store the results in the database.
    """
    settings = Settings(settings_filepath)
    setup_logging()

    # create a database gateway for persistent storage
    sqlite_database_path = settings.database.path
    if Path(sqlite_database_path).exists():
        if overwrite_database_file:
            Path(sqlite_database_path).unlink()
        else:
            raise FileExistsError(f"Database file already exists: '{sqlite_database_path}'.")
    else:
        # Create the database file
        Path(sqlite_database_path).touch()
    database_gateway: SQLModelSQLiteDataGateway = SQLModelSQLiteDataGateway(sqlite_database_path)

    # Convert string inputs to proper types if provided
    dti_metric_list: List[DTIMetric] = []
    if dti_metrics:
        try:
            acronyms_list = dti_metrics[0].split(',')
            dti_metric_list = [DTIMetric.from_acronym(acronym) for acronym in acronyms_list]
        except KeyError as e:
            raise ValueError(f"Invalid DTI metric: {e}. Valid options are: {', '.join([m.name for m in DTIMetric])}")

    # Initialize with default strategies if none provided
    stat_strategy_list = list(StatisticsStrategies.all())
    if statistics_strategies:
        try:
            stats_names_list = statistics_strategies[0].split(',')
            # Replace underscores with spaces in statistical strategy names
            stats_names_list_without_underscores = [name.replace('_', ' ') for name in stats_names_list]
            stat_strategy_list = [StatisticsStrategies.get_by_name(stat_name)
                                  for stat_name in stats_names_list_without_underscores]
        except ValueError as e:
            valid_strategies = [s.name for s in StatisticsStrategies.all()]
            raise ValueError(f"Invalid statistical strategy: {e}. Valid options are: {', '.join(valid_strategies)}")

    controller = Controller(persistence_gateway=database_gateway,
                            importers=[
                                CSVCenterImporter(settings.paths.centers_list),
                                CSVAtlasImporter(settings.paths.atlases_list),
                                NiftiFoldersImporter(settings.paths.nifti_files_folder),
                                CSVNormativeDTIValuesImporter(settings.paths.normative_dti_values_list)
                            ],
                            listeners=[
                                TqdmProgressListener(),  # Progress bar using tqdm
                            ])

    controller.compute_normative_dti_values(
        dti_metrics=dti_metric_list,
        statistics_strategies=stat_strategy_list
    )

segment_dti_lesions()

Source code in oxytcmri/infrastructure/cli.py
109
110
111
@command_line_interface.command()
def segment_dti_lesions():
    raise NotImplementedError