# This file was auto generated by Styx.
# Do not edit this file directly.

import typing
import pathlib
from styxdefs import *
import dataclasses

CCOPS_METADATA = Metadata(
    id="15f914d7513b2d71d9d54891eb8992cdb8593e4a.boutiques",
    name="ccops",
    package="fsl",
    container_image_tag="brainlife/fsl:6.0.4-patched2",
)


class CcopsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ccops(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    outfile: OutputPathType
    """Output clustered ROI mask"""


def ccops(
    basename: str,
    infile: InputPathType | None = None,
    tract_dir: str | None = None,
    exclusion_mask: InputPathType | None = None,
    reorder_seedspace: bool = False,
    reorder_tractspace: bool = False,
    tract_reord: bool = False,
    connexity_constraint: float | None = 0,
    binarise_val: float | None = 0,
    matrix_power: float | None = 1,
    brain_mask: InputPathType | None = None,
    scheme: str | None = "spectral",
    nclusters: float | None = None,
    help_: bool = False,
    runner: Runner | None = None,
) -> CcopsOutputs:
    """
    ccops - Clustering of Connectomes Using Probabilistic Tractography.
    
    Author: FMRIB Analysis Group, University of Oxford
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki
    
    Args:
        basename: Output basename.
        infile: Input matrix.
        tract_dir: Tractography Results Directory.
        exclusion_mask: Exclusion mask (in tract space).
        reorder_seedspace: Do seedspace reordering (default no).
        reorder_tractspace: Do tractspace reordering (default no).
        tract_reord: Propagate seed reordering onto tract space.
        connexity_constraint: Add connexity constraint - value between 0 and 1\
            (0 is no constraint). Default is 0.
        binarise_val: Binarise at (default 0 - no binarisation).
        matrix_power: Power to raise the correlation matrix to (default 1).
        brain_mask: Brain mask used to output the clustered ROI mask (not\
            necessary if --dir set).
        scheme: Reordering algorithm. Can be either spectral (default), kmeans\
            or fuzzy.
        nclusters: Number of clusters to be used in kmeans or fuzzy.
        help_: Display this help message.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CcopsOutputs`).
    """
    if connexity_constraint is not None and not (0 <= connexity_constraint <= 1): 
        raise ValueError(f"'connexity_constraint' must be between 0 <= x <= 1 but was {connexity_constraint}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(CCOPS_METADATA)
    cargs = []
    cargs.append("ccops")
    cargs.extend([
        "--basename",
        basename
    ])
    if infile is not None:
        cargs.extend([
            "--in",
            execution.input_file(infile)
        ])
    if tract_dir is not None:
        cargs.extend([
            "--dir",
            tract_dir
        ])
    if exclusion_mask is not None:
        cargs.extend([
            "-x",
            execution.input_file(exclusion_mask)
        ])
    if reorder_seedspace:
        cargs.append("--r1")
    if reorder_tractspace:
        cargs.append("--r2")
    if tract_reord:
        cargs.append("--tractreord")
    if connexity_constraint is not None:
        cargs.extend([
            "--con",
            str(connexity_constraint)
        ])
    if binarise_val is not None:
        cargs.extend([
            "--bin",
            str(binarise_val)
        ])
    if matrix_power is not None:
        cargs.extend([
            "--power",
            str(matrix_power)
        ])
    if brain_mask is not None:
        cargs.extend([
            "--mask",
            execution.input_file(brain_mask)
        ])
    if scheme is not None:
        cargs.extend([
            "--scheme",
            scheme
        ])
    if nclusters is not None:
        cargs.extend([
            "--nclusters",
            str(nclusters)
        ])
    if help_:
        cargs.append("--help")
    ret = CcopsOutputs(
        root=execution.output_file("."),
        outfile=execution.output_file(basename + "_output.nii.gz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "CCOPS_METADATA",
    "CcopsOutputs",
    "ccops",
]
