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

import typing
import pathlib
from styxdefs import *

FIXELCFESTATS_METADATA = Metadata(
    id="977582ec85abc36abca54062935b4e3d34f0c9f9.boutiques",
    name="fixelcfestats",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_FixelcfestatsColumnParamsDictNoTag = typing.TypedDict('_FixelcfestatsColumnParamsDictNoTag', {
    "path": InputPathType,
})
FixelcfestatsColumnParamsDictTagged = typing.TypedDict('FixelcfestatsColumnParamsDictTagged', {
    "@type": typing.Literal["column"],
    "path": InputPathType,
})
FixelcfestatsColumnParamsDict = _FixelcfestatsColumnParamsDictNoTag | FixelcfestatsColumnParamsDictTagged


_FixelcfestatsConfigParamsDictNoTag = typing.TypedDict('_FixelcfestatsConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
FixelcfestatsConfigParamsDictTagged = typing.TypedDict('FixelcfestatsConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
FixelcfestatsConfigParamsDict = _FixelcfestatsConfigParamsDictNoTag | FixelcfestatsConfigParamsDictTagged


_FixelcfestatsVariousStringParamsDictNoTag = typing.TypedDict('_FixelcfestatsVariousStringParamsDictNoTag', {
    "obj": str,
})
FixelcfestatsVariousStringParamsDictTagged = typing.TypedDict('FixelcfestatsVariousStringParamsDictTagged', {
    "@type": typing.Literal["VariousString"],
    "obj": str,
})
FixelcfestatsVariousStringParamsDict = _FixelcfestatsVariousStringParamsDictNoTag | FixelcfestatsVariousStringParamsDictTagged


_FixelcfestatsVariousFileParamsDictNoTag = typing.TypedDict('_FixelcfestatsVariousFileParamsDictNoTag', {
    "obj": InputPathType,
})
FixelcfestatsVariousFileParamsDictTagged = typing.TypedDict('FixelcfestatsVariousFileParamsDictTagged', {
    "@type": typing.Literal["VariousFile"],
    "obj": InputPathType,
})
FixelcfestatsVariousFileParamsDict = _FixelcfestatsVariousFileParamsDictNoTag | FixelcfestatsVariousFileParamsDictTagged


_FixelcfestatsParamsDictNoTag = typing.TypedDict('_FixelcfestatsParamsDictNoTag', {
    "mask": typing.NotRequired[InputPathType | None],
    "notest": bool,
    "errors": typing.NotRequired[str | None],
    "exchange_within": typing.NotRequired[InputPathType | None],
    "exchange_whole": typing.NotRequired[InputPathType | None],
    "strong": bool,
    "nshuffles": typing.NotRequired[int | None],
    "permutations": typing.NotRequired[InputPathType | None],
    "nonstationarity": bool,
    "skew_nonstationarity": typing.NotRequired[float | None],
    "nshuffles_nonstationarity": typing.NotRequired[int | None],
    "permutations_nonstationarity": typing.NotRequired[InputPathType | None],
    "cfe_dh": typing.NotRequired[float | None],
    "cfe_e": typing.NotRequired[float | None],
    "cfe_h": typing.NotRequired[float | None],
    "cfe_c": typing.NotRequired[float | None],
    "cfe_legacy": bool,
    "variance": typing.NotRequired[InputPathType | None],
    "ftests": typing.NotRequired[InputPathType | None],
    "fonly": bool,
    "column": typing.NotRequired[list[FixelcfestatsColumnParamsDict] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[FixelcfestatsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in_fixel_directory": InputPathType,
    "subjects": InputPathType,
    "design": InputPathType,
    "contrast": InputPathType,
    "connectivity": typing.Union[FixelcfestatsVariousStringParamsDictTagged, FixelcfestatsVariousFileParamsDictTagged],
    "out_fixel_directory": str,
})
FixelcfestatsParamsDictTagged = typing.TypedDict('FixelcfestatsParamsDictTagged', {
    "@type": typing.Literal["mrtrix/fixelcfestats"],
    "mask": typing.NotRequired[InputPathType | None],
    "notest": bool,
    "errors": typing.NotRequired[str | None],
    "exchange_within": typing.NotRequired[InputPathType | None],
    "exchange_whole": typing.NotRequired[InputPathType | None],
    "strong": bool,
    "nshuffles": typing.NotRequired[int | None],
    "permutations": typing.NotRequired[InputPathType | None],
    "nonstationarity": bool,
    "skew_nonstationarity": typing.NotRequired[float | None],
    "nshuffles_nonstationarity": typing.NotRequired[int | None],
    "permutations_nonstationarity": typing.NotRequired[InputPathType | None],
    "cfe_dh": typing.NotRequired[float | None],
    "cfe_e": typing.NotRequired[float | None],
    "cfe_h": typing.NotRequired[float | None],
    "cfe_c": typing.NotRequired[float | None],
    "cfe_legacy": bool,
    "variance": typing.NotRequired[InputPathType | None],
    "ftests": typing.NotRequired[InputPathType | None],
    "fonly": bool,
    "column": typing.NotRequired[list[FixelcfestatsColumnParamsDict] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[FixelcfestatsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in_fixel_directory": InputPathType,
    "subjects": InputPathType,
    "design": InputPathType,
    "contrast": InputPathType,
    "connectivity": typing.Union[FixelcfestatsVariousStringParamsDictTagged, FixelcfestatsVariousFileParamsDictTagged],
    "out_fixel_directory": str,
})
FixelcfestatsParamsDict = _FixelcfestatsParamsDictNoTag | FixelcfestatsParamsDictTagged


def fixelcfestats_connectivity_cargs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "VariousString": fixelcfestats_various_string_cargs,
        "VariousFile": fixelcfestats_various_file_cargs,
    }.get(t)


def fixelcfestats_connectivity_validate_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get validate params function by command type.
    
    Args:
        t: Command type.
    Returns:
        Validate params function.
    """
    return {
        "VariousString": fixelcfestats_various_string_validate,
        "VariousFile": fixelcfestats_various_file_validate,
    }.get(t)


def fixelcfestats_column(
    path: InputPathType,
) -> FixelcfestatsColumnParamsDictTagged:
    """
    Build parameters.
    
    Args:
        path: add a column to the design matrix corresponding to subject\
            fixel-wise values (note that the contrast matrix must include an\
            additional column for each use of this option); the text file provided\
            via this option should contain a file name for each subject.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "column",
        "path": path,
    }
    return params


def fixelcfestats_column_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FixelcfestatsColumnParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("path", None) is None:
        raise StyxValidationError("`path` must not be None")
    if not isinstance(params["path"], (pathlib.Path, str)):
        raise StyxValidationError(f'`path` has the wrong type: Received `{type(params.get("path", None))}` expected `InputPathType`')


def fixelcfestats_column_cargs(
    params: FixelcfestatsColumnParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-column")
    cargs.append(execution.input_file(params.get("path", None)))
    return cargs


def fixelcfestats_config(
    key: str,
    value: str,
) -> FixelcfestatsConfigParamsDictTagged:
    """
    Build parameters.
    
    Args:
        key: temporarily set the value of an MRtrix config file entry.
        value: temporarily set the value of an MRtrix config file entry.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "config",
        "key": key,
        "value": value,
    }
    return params


def fixelcfestats_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FixelcfestatsConfigParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("key", None) is None:
        raise StyxValidationError("`key` must not be None")
    if not isinstance(params["key"], str):
        raise StyxValidationError(f'`key` has the wrong type: Received `{type(params.get("key", None))}` expected `str`')
    if params.get("value", None) is None:
        raise StyxValidationError("`value` must not be None")
    if not isinstance(params["value"], str):
        raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `str`')


def fixelcfestats_config_cargs(
    params: FixelcfestatsConfigParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-config")
    cargs.append(params.get("key", None))
    cargs.append(params.get("value", None))
    return cargs


def fixelcfestats_various_string(
    obj: str,
) -> FixelcfestatsVariousStringParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: String object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousString",
        "obj": obj,
    }
    return params


def fixelcfestats_various_string_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FixelcfestatsVariousStringParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("obj", None) is None:
        raise StyxValidationError("`obj` must not be None")
    if not isinstance(params["obj"], str):
        raise StyxValidationError(f'`obj` has the wrong type: Received `{type(params.get("obj", None))}` expected `str`')


def fixelcfestats_various_string_cargs(
    params: FixelcfestatsVariousStringParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append(params.get("obj", None))
    return cargs


def fixelcfestats_various_file(
    obj: InputPathType,
) -> FixelcfestatsVariousFileParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: File object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousFile",
        "obj": obj,
    }
    return params


def fixelcfestats_various_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FixelcfestatsVariousFileParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("obj", None) is None:
        raise StyxValidationError("`obj` must not be None")
    if not isinstance(params["obj"], (pathlib.Path, str)):
        raise StyxValidationError(f'`obj` has the wrong type: Received `{type(params.get("obj", None))}` expected `InputPathType`')


def fixelcfestats_various_file_cargs(
    params: FixelcfestatsVariousFileParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append(execution.input_file(params.get("obj", None)))
    return cargs


class FixelcfestatsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `FixelcfestatsParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def fixelcfestats_params(
    in_fixel_directory: InputPathType,
    subjects: InputPathType,
    design: InputPathType,
    contrast: InputPathType,
    connectivity: typing.Union[FixelcfestatsVariousStringParamsDictTagged, FixelcfestatsVariousFileParamsDictTagged],
    out_fixel_directory: str,
    mask: InputPathType | None = None,
    notest: bool = False,
    errors: str | None = None,
    exchange_within: InputPathType | None = None,
    exchange_whole: InputPathType | None = None,
    strong: bool = False,
    nshuffles: int | None = None,
    permutations: InputPathType | None = None,
    nonstationarity: bool = False,
    skew_nonstationarity: float | None = None,
    nshuffles_nonstationarity: int | None = None,
    permutations_nonstationarity: InputPathType | None = None,
    cfe_dh: float | None = None,
    cfe_e: float | None = None,
    cfe_h: float | None = None,
    cfe_c: float | None = None,
    cfe_legacy: bool = False,
    variance: InputPathType | None = None,
    ftests: InputPathType | None = None,
    fonly: bool = False,
    column: list[FixelcfestatsColumnParamsDict] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[FixelcfestatsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> FixelcfestatsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        in_fixel_directory: the fixel directory containing the data files for\
            each subject (after obtaining fixel correspondence.
        subjects: a text file listing the subject identifiers (one per line).\
            This should correspond with the filenames in the fixel directory\
            (including the file extension), and be listed in the same order as the\
            rows of the design matrix.
        design: the design matrix.
        contrast: the contrast matrix, specified as rows of weights.
        connectivity: the fixel-fixel connectivity matrix.
        out_fixel_directory: the output directory where results will be saved.\
            Will be created if it does not exist.
        mask: provide a fixel data file containing a mask of those fixels to be\
            used during processing.
        notest: don't perform statistical inference; only output population\
            statistics (effect size, stdev etc).
        errors: specify nature of errors for shuffling; options are:\
            ee,ise,both (default: ee).
        exchange_within: specify blocks of observations within each of which\
            data may undergo restricted exchange.
        exchange_whole: specify blocks of observations that may be exchanged\
            with one another (for independent and symmetric errors, sign-flipping\
            will occur block-wise).
        strong: use strong familywise error control across multiple hypotheses.
        nshuffles: the number of shuffles (default: 5000).
        permutations: manually define the permutations (relabelling). The input\
            should be a text file defining a m x n matrix, where each relabelling\
            is defined as a column vector of size m, and the number of columns, n,\
            defines the number of permutations. Can be generated with the\
            palm_quickperms function in PALM\
            (http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/PALM). Overrides the -nshuffles\
            option.
        nonstationarity: perform non-stationarity correction.
        skew_nonstationarity: specify the skew parameter for empirical\
            statistic calculation (default for this command is 1).
        nshuffles_nonstationarity: the number of shuffles to use when\
            precomputing the empirical statistic image for non-stationarity\
            correction (default: 5000).
        permutations_nonstationarity: manually define the permutations\
            (relabelling) for computing the emprical statistics for\
            non-stationarity correction. The input should be a text file defining a\
            m x n matrix, where each relabelling is defined as a column vector of\
            size m, and the number of columns, n, defines the number of\
            permutations. Can be generated with the palm_quickperms function in\
            PALM (http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/PALM) Overrides the\
            -nshuffles_nonstationarity option.
        cfe_dh: the height increment used in the cfe integration (default: 0.1).
        cfe_e: cfe extent exponent (default: 2).
        cfe_h: cfe height exponent (default: 3).
        cfe_c: cfe connectivity exponent (default: 0.5).
        cfe_legacy: use the legacy (non-normalised) form of the cfe equation.
        variance: define variance groups for the G-statistic; measurements for\
            which the expected variance is equivalent should contain the same index.
        ftests: perform F-tests; input text file should contain, for each\
            F-test, a row containing ones and zeros, where ones indicate the rows\
            of the contrast matrix to be included in the F-test.
        fonly: only assess F-tests; do not perform statistical inference on\
            entries in the contrast matrix.
        column: add a column to the design matrix corresponding to subject\
            fixel-wise values (note that the contrast matrix must include an\
            additional column for each use of this option); the text file provided\
            via this option should contain a file name for each subject.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mrtrix/fixelcfestats",
        "notest": notest,
        "strong": strong,
        "nonstationarity": nonstationarity,
        "cfe_legacy": cfe_legacy,
        "fonly": fonly,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "in_fixel_directory": in_fixel_directory,
        "subjects": subjects,
        "design": design,
        "contrast": contrast,
        "connectivity": connectivity,
        "out_fixel_directory": out_fixel_directory,
    }
    if mask is not None:
        params["mask"] = mask
    if errors is not None:
        params["errors"] = errors
    if exchange_within is not None:
        params["exchange_within"] = exchange_within
    if exchange_whole is not None:
        params["exchange_whole"] = exchange_whole
    if nshuffles is not None:
        params["nshuffles"] = nshuffles
    if permutations is not None:
        params["permutations"] = permutations
    if skew_nonstationarity is not None:
        params["skew_nonstationarity"] = skew_nonstationarity
    if nshuffles_nonstationarity is not None:
        params["nshuffles_nonstationarity"] = nshuffles_nonstationarity
    if permutations_nonstationarity is not None:
        params["permutations_nonstationarity"] = permutations_nonstationarity
    if cfe_dh is not None:
        params["cfe_dh"] = cfe_dh
    if cfe_e is not None:
        params["cfe_e"] = cfe_e
    if cfe_h is not None:
        params["cfe_h"] = cfe_h
    if cfe_c is not None:
        params["cfe_c"] = cfe_c
    if variance is not None:
        params["variance"] = variance
    if ftests is not None:
        params["ftests"] = ftests
    if column is not None:
        params["column"] = column
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def fixelcfestats_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FixelcfestatsParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("mask", None) is not None:
        if not isinstance(params["mask"], (pathlib.Path, str)):
            raise StyxValidationError(f'`mask` has the wrong type: Received `{type(params.get("mask", None))}` expected `InputPathType | None`')
    if params.get("notest", False) is None:
        raise StyxValidationError("`notest` must not be None")
    if not isinstance(params["notest"], bool):
        raise StyxValidationError(f'`notest` has the wrong type: Received `{type(params.get("notest", False))}` expected `bool`')
    if params.get("errors", None) is not None:
        if not isinstance(params["errors"], str):
            raise StyxValidationError(f'`errors` has the wrong type: Received `{type(params.get("errors", None))}` expected `str | None`')
    if params.get("exchange_within", None) is not None:
        if not isinstance(params["exchange_within"], (pathlib.Path, str)):
            raise StyxValidationError(f'`exchange_within` has the wrong type: Received `{type(params.get("exchange_within", None))}` expected `InputPathType | None`')
    if params.get("exchange_whole", None) is not None:
        if not isinstance(params["exchange_whole"], (pathlib.Path, str)):
            raise StyxValidationError(f'`exchange_whole` has the wrong type: Received `{type(params.get("exchange_whole", None))}` expected `InputPathType | None`')
    if params.get("strong", False) is None:
        raise StyxValidationError("`strong` must not be None")
    if not isinstance(params["strong"], bool):
        raise StyxValidationError(f'`strong` has the wrong type: Received `{type(params.get("strong", False))}` expected `bool`')
    if params.get("nshuffles", None) is not None:
        if not isinstance(params["nshuffles"], int):
            raise StyxValidationError(f'`nshuffles` has the wrong type: Received `{type(params.get("nshuffles", None))}` expected `int | None`')
    if params.get("permutations", None) is not None:
        if not isinstance(params["permutations"], (pathlib.Path, str)):
            raise StyxValidationError(f'`permutations` has the wrong type: Received `{type(params.get("permutations", None))}` expected `InputPathType | None`')
    if params.get("nonstationarity", False) is None:
        raise StyxValidationError("`nonstationarity` must not be None")
    if not isinstance(params["nonstationarity"], bool):
        raise StyxValidationError(f'`nonstationarity` has the wrong type: Received `{type(params.get("nonstationarity", False))}` expected `bool`')
    if params.get("skew_nonstationarity", None) is not None:
        if not isinstance(params["skew_nonstationarity"], (float, int)):
            raise StyxValidationError(f'`skew_nonstationarity` has the wrong type: Received `{type(params.get("skew_nonstationarity", None))}` expected `float | None`')
    if params.get("nshuffles_nonstationarity", None) is not None:
        if not isinstance(params["nshuffles_nonstationarity"], int):
            raise StyxValidationError(f'`nshuffles_nonstationarity` has the wrong type: Received `{type(params.get("nshuffles_nonstationarity", None))}` expected `int | None`')
    if params.get("permutations_nonstationarity", None) is not None:
        if not isinstance(params["permutations_nonstationarity"], (pathlib.Path, str)):
            raise StyxValidationError(f'`permutations_nonstationarity` has the wrong type: Received `{type(params.get("permutations_nonstationarity", None))}` expected `InputPathType | None`')
    if params.get("cfe_dh", None) is not None:
        if not isinstance(params["cfe_dh"], (float, int)):
            raise StyxValidationError(f'`cfe_dh` has the wrong type: Received `{type(params.get("cfe_dh", None))}` expected `float | None`')
    if params.get("cfe_e", None) is not None:
        if not isinstance(params["cfe_e"], (float, int)):
            raise StyxValidationError(f'`cfe_e` has the wrong type: Received `{type(params.get("cfe_e", None))}` expected `float | None`')
    if params.get("cfe_h", None) is not None:
        if not isinstance(params["cfe_h"], (float, int)):
            raise StyxValidationError(f'`cfe_h` has the wrong type: Received `{type(params.get("cfe_h", None))}` expected `float | None`')
    if params.get("cfe_c", None) is not None:
        if not isinstance(params["cfe_c"], (float, int)):
            raise StyxValidationError(f'`cfe_c` has the wrong type: Received `{type(params.get("cfe_c", None))}` expected `float | None`')
    if params.get("cfe_legacy", False) is None:
        raise StyxValidationError("`cfe_legacy` must not be None")
    if not isinstance(params["cfe_legacy"], bool):
        raise StyxValidationError(f'`cfe_legacy` has the wrong type: Received `{type(params.get("cfe_legacy", False))}` expected `bool`')
    if params.get("variance", None) is not None:
        if not isinstance(params["variance"], (pathlib.Path, str)):
            raise StyxValidationError(f'`variance` has the wrong type: Received `{type(params.get("variance", None))}` expected `InputPathType | None`')
    if params.get("ftests", None) is not None:
        if not isinstance(params["ftests"], (pathlib.Path, str)):
            raise StyxValidationError(f'`ftests` has the wrong type: Received `{type(params.get("ftests", None))}` expected `InputPathType | None`')
    if params.get("fonly", False) is None:
        raise StyxValidationError("`fonly` must not be None")
    if not isinstance(params["fonly"], bool):
        raise StyxValidationError(f'`fonly` has the wrong type: Received `{type(params.get("fonly", False))}` expected `bool`')
    if params.get("column", None) is not None:
        if not isinstance(params["column"], list):
            raise StyxValidationError(f'`column` has the wrong type: Received `{type(params.get("column", None))}` expected `list[FixelcfestatsColumnParamsDict] | None`')
        for e in params["column"]:
            fixelcfestats_column_validate(e)
    if params.get("info", False) is None:
        raise StyxValidationError("`info` must not be None")
    if not isinstance(params["info"], bool):
        raise StyxValidationError(f'`info` has the wrong type: Received `{type(params.get("info", False))}` expected `bool`')
    if params.get("quiet", False) is None:
        raise StyxValidationError("`quiet` must not be None")
    if not isinstance(params["quiet"], bool):
        raise StyxValidationError(f'`quiet` has the wrong type: Received `{type(params.get("quiet", False))}` expected `bool`')
    if params.get("debug", False) is None:
        raise StyxValidationError("`debug` must not be None")
    if not isinstance(params["debug"], bool):
        raise StyxValidationError(f'`debug` has the wrong type: Received `{type(params.get("debug", False))}` expected `bool`')
    if params.get("force", False) is None:
        raise StyxValidationError("`force` must not be None")
    if not isinstance(params["force"], bool):
        raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", False))}` expected `bool`')
    if params.get("nthreads", None) is not None:
        if not isinstance(params["nthreads"], int):
            raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `int | None`')
    if params.get("config", None) is not None:
        if not isinstance(params["config"], list):
            raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[FixelcfestatsConfigParamsDict] | None`')
        for e in params["config"]:
            fixelcfestats_config_validate(e)
    if params.get("help", False) is None:
        raise StyxValidationError("`help` must not be None")
    if not isinstance(params["help"], bool):
        raise StyxValidationError(f'`help` has the wrong type: Received `{type(params.get("help", False))}` expected `bool`')
    if params.get("version", False) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], bool):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", False))}` expected `bool`')
    if params.get("in_fixel_directory", None) is None:
        raise StyxValidationError("`in_fixel_directory` must not be None")
    if not isinstance(params["in_fixel_directory"], (pathlib.Path, str)):
        raise StyxValidationError(f'`in_fixel_directory` has the wrong type: Received `{type(params.get("in_fixel_directory", None))}` expected `InputPathType`')
    if params.get("subjects", None) is None:
        raise StyxValidationError("`subjects` must not be None")
    if not isinstance(params["subjects"], (pathlib.Path, str)):
        raise StyxValidationError(f'`subjects` has the wrong type: Received `{type(params.get("subjects", None))}` expected `InputPathType`')
    if params.get("design", None) is None:
        raise StyxValidationError("`design` must not be None")
    if not isinstance(params["design"], (pathlib.Path, str)):
        raise StyxValidationError(f'`design` has the wrong type: Received `{type(params.get("design", None))}` expected `InputPathType`')
    if params.get("contrast", None) is None:
        raise StyxValidationError("`contrast` must not be None")
    if not isinstance(params["contrast"], (pathlib.Path, str)):
        raise StyxValidationError(f'`contrast` has the wrong type: Received `{type(params.get("contrast", None))}` expected `InputPathType`')
    if params.get("connectivity", None) is None:
        raise StyxValidationError("`connectivity` must not be None")
    if not isinstance(params["connectivity"], dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params["connectivity"])}\'')
    if "@type" not in params["connectivity"]:
        raise StyxValidationError("Params object is missing `@type`")
    if params["connectivity"]["@type"] not in ["VariousString", "VariousFile"]:
        raise StyxValidationError("Parameter `connectivity`s `@type` must be one of [\"VariousString\", \"VariousFile\"]")
    fixelcfestats_connectivity_validate_dyn_fn(params["connectivity"]["@type"])(params["connectivity"])
    if params.get("out_fixel_directory", None) is None:
        raise StyxValidationError("`out_fixel_directory` must not be None")
    if not isinstance(params["out_fixel_directory"], str):
        raise StyxValidationError(f'`out_fixel_directory` has the wrong type: Received `{type(params.get("out_fixel_directory", None))}` expected `str`')


def fixelcfestats_cargs(
    params: FixelcfestatsParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("fixelcfestats")
    if params.get("mask", None) is not None:
        cargs.extend([
            "-mask",
            execution.input_file(params.get("mask", None))
        ])
    if params.get("notest", False):
        cargs.append("-notest")
    if params.get("errors", None) is not None:
        cargs.extend([
            "-errors",
            params.get("errors", None)
        ])
    if params.get("exchange_within", None) is not None:
        cargs.extend([
            "-exchange_within",
            execution.input_file(params.get("exchange_within", None))
        ])
    if params.get("exchange_whole", None) is not None:
        cargs.extend([
            "-exchange_whole",
            execution.input_file(params.get("exchange_whole", None))
        ])
    if params.get("strong", False):
        cargs.append("-strong")
    if params.get("nshuffles", None) is not None:
        cargs.extend([
            "-nshuffles",
            str(params.get("nshuffles", None))
        ])
    if params.get("permutations", None) is not None:
        cargs.extend([
            "-permutations",
            execution.input_file(params.get("permutations", None))
        ])
    if params.get("nonstationarity", False):
        cargs.append("-nonstationarity")
    if params.get("skew_nonstationarity", None) is not None:
        cargs.extend([
            "-skew_nonstationarity",
            str(params.get("skew_nonstationarity", None))
        ])
    if params.get("nshuffles_nonstationarity", None) is not None:
        cargs.extend([
            "-nshuffles_nonstationarity",
            str(params.get("nshuffles_nonstationarity", None))
        ])
    if params.get("permutations_nonstationarity", None) is not None:
        cargs.extend([
            "-permutations_nonstationarity",
            execution.input_file(params.get("permutations_nonstationarity", None))
        ])
    if params.get("cfe_dh", None) is not None:
        cargs.extend([
            "-cfe_dh",
            str(params.get("cfe_dh", None))
        ])
    if params.get("cfe_e", None) is not None:
        cargs.extend([
            "-cfe_e",
            str(params.get("cfe_e", None))
        ])
    if params.get("cfe_h", None) is not None:
        cargs.extend([
            "-cfe_h",
            str(params.get("cfe_h", None))
        ])
    if params.get("cfe_c", None) is not None:
        cargs.extend([
            "-cfe_c",
            str(params.get("cfe_c", None))
        ])
    if params.get("cfe_legacy", False):
        cargs.append("-cfe_legacy")
    if params.get("variance", None) is not None:
        cargs.extend([
            "-variance",
            execution.input_file(params.get("variance", None))
        ])
    if params.get("ftests", None) is not None:
        cargs.extend([
            "-ftests",
            execution.input_file(params.get("ftests", None))
        ])
    if params.get("fonly", False):
        cargs.append("-fonly")
    if params.get("column", None) is not None:
        cargs.extend([a for c in [fixelcfestats_column_cargs(s, execution) for s in params.get("column", None)] for a in c])
    if params.get("info", False):
        cargs.append("-info")
    if params.get("quiet", False):
        cargs.append("-quiet")
    if params.get("debug", False):
        cargs.append("-debug")
    if params.get("force", False):
        cargs.append("-force")
    if params.get("nthreads", None) is not None:
        cargs.extend([
            "-nthreads",
            str(params.get("nthreads", None))
        ])
    if params.get("config", None) is not None:
        cargs.extend([a for c in [fixelcfestats_config_cargs(s, execution) for s in params.get("config", None)] for a in c])
    if params.get("help", False):
        cargs.append("-help")
    if params.get("version", False):
        cargs.append("-version")
    cargs.append(execution.input_file(params.get("in_fixel_directory", None)))
    cargs.append(execution.input_file(params.get("subjects", None)))
    cargs.append(execution.input_file(params.get("design", None)))
    cargs.append(execution.input_file(params.get("contrast", None)))
    cargs.extend(fixelcfestats_connectivity_cargs_dyn_fn(params.get("connectivity", None)["@type"])(params.get("connectivity", None), execution))
    cargs.append(params.get("out_fixel_directory", None))
    return cargs


def fixelcfestats_outputs(
    params: FixelcfestatsParamsDict,
    execution: Execution,
) -> FixelcfestatsOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = FixelcfestatsOutputs(
        root=execution.output_file("."),
    )
    return ret


def fixelcfestats_execute(
    params: FixelcfestatsParamsDict,
    runner: Runner | None = None,
) -> FixelcfestatsOutputs:
    """
    fixelcfestats
    
    Fixel-based analysis using connectivity-based fixel enhancement and
    non-parametric permutation testing.
    
    Unlike previous versions of this command, where a whole-brain tractogram
    file would be provided as input in order to generate the fixel-fixel
    connectivity matrix and smooth fixel data, this version expects to be
    provided with the directory path to a pre-calculated fixel-fixel
    connectivity matrix (likely generated using the MRtrix3 command
    fixelconnectivity), and for the input fixel data to have already been
    smoothed (likely using the MRtrix3 command fixelfilter).
    
    Note that if the -mask option is used, the output fixel directory will still
    contain the same set of fixels as that present in the input fixel template,
    in order to retain fixel correspondence. However a consequence of this is
    that all fixels in the template will be initialy visible when the output
    fixel directory is loaded in mrview. Those fixels outside the processing
    mask will immediately disappear from view as soon as any data-file-based
    fixel colouring or thresholding is applied.
    
    In some software packages, a column of ones is automatically added to the
    GLM design matrix; the purpose of this column is to estimate the "global
    intercept", which is the predicted value of the observed variable if all
    explanatory variables were to be zero. However there are rare situations
    where including such a column would not be appropriate for a particular
    experimental design. Hence, in MRtrix3 statistical inference commands, it is
    up to the user to determine whether or not this column of ones should be
    included in their design matrix, and add it explicitly if necessary. The
    contrast matrix must also reflect the presence of this additional column.
    
    References:
    
    Raffelt, D.; Smith, RE.; Ridgway, GR.; Tournier, JD.; Vaughan, DN.; Rose,
    S.; Henderson, R.; Connelly, A. Connectivity-based fixel enhancement:
    Whole-brain statistical analysis of diffusion MRI measures in the presence
    of crossing fibres.Neuroimage, 2015, 15(117):40-55
    
    * If not using the -cfe_legacy option:
    Smith, RE.; Dimond, D; Vaughan, D.; Parker, D.; Dhollander, T.; Jackson, G.;
    Connelly, A. Intrinsic non-stationarity correction for Fixel-Based Analysis.
    In Proc OHBM 2019 M789
    
    * If using the -nonstationary option:
    Salimi-Khorshidi, G. Smith, S.M. Nichols, T.E. Adjusting the effect of
    nonstationarity in cluster-based and TFCE inference. NeuroImage, 2011,
    54(3), 2006-19.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FixelcfestatsOutputs`).
    """
    fixelcfestats_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(FIXELCFESTATS_METADATA)
    params = execution.params(params)
    cargs = fixelcfestats_cargs(params, execution)
    ret = fixelcfestats_outputs(params, execution)
    execution.run(cargs)
    return ret


def fixelcfestats(
    in_fixel_directory: InputPathType,
    subjects: InputPathType,
    design: InputPathType,
    contrast: InputPathType,
    connectivity: typing.Union[FixelcfestatsVariousStringParamsDictTagged, FixelcfestatsVariousFileParamsDictTagged],
    out_fixel_directory: str,
    mask: InputPathType | None = None,
    notest: bool = False,
    errors: str | None = None,
    exchange_within: InputPathType | None = None,
    exchange_whole: InputPathType | None = None,
    strong: bool = False,
    nshuffles: int | None = None,
    permutations: InputPathType | None = None,
    nonstationarity: bool = False,
    skew_nonstationarity: float | None = None,
    nshuffles_nonstationarity: int | None = None,
    permutations_nonstationarity: InputPathType | None = None,
    cfe_dh: float | None = None,
    cfe_e: float | None = None,
    cfe_h: float | None = None,
    cfe_c: float | None = None,
    cfe_legacy: bool = False,
    variance: InputPathType | None = None,
    ftests: InputPathType | None = None,
    fonly: bool = False,
    column: list[FixelcfestatsColumnParamsDict] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[FixelcfestatsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> FixelcfestatsOutputs:
    """
    fixelcfestats
    
    Fixel-based analysis using connectivity-based fixel enhancement and
    non-parametric permutation testing.
    
    Unlike previous versions of this command, where a whole-brain tractogram
    file would be provided as input in order to generate the fixel-fixel
    connectivity matrix and smooth fixel data, this version expects to be
    provided with the directory path to a pre-calculated fixel-fixel
    connectivity matrix (likely generated using the MRtrix3 command
    fixelconnectivity), and for the input fixel data to have already been
    smoothed (likely using the MRtrix3 command fixelfilter).
    
    Note that if the -mask option is used, the output fixel directory will still
    contain the same set of fixels as that present in the input fixel template,
    in order to retain fixel correspondence. However a consequence of this is
    that all fixels in the template will be initialy visible when the output
    fixel directory is loaded in mrview. Those fixels outside the processing
    mask will immediately disappear from view as soon as any data-file-based
    fixel colouring or thresholding is applied.
    
    In some software packages, a column of ones is automatically added to the
    GLM design matrix; the purpose of this column is to estimate the "global
    intercept", which is the predicted value of the observed variable if all
    explanatory variables were to be zero. However there are rare situations
    where including such a column would not be appropriate for a particular
    experimental design. Hence, in MRtrix3 statistical inference commands, it is
    up to the user to determine whether or not this column of ones should be
    included in their design matrix, and add it explicitly if necessary. The
    contrast matrix must also reflect the presence of this additional column.
    
    References:
    
    Raffelt, D.; Smith, RE.; Ridgway, GR.; Tournier, JD.; Vaughan, DN.; Rose,
    S.; Henderson, R.; Connelly, A. Connectivity-based fixel enhancement:
    Whole-brain statistical analysis of diffusion MRI measures in the presence
    of crossing fibres.Neuroimage, 2015, 15(117):40-55
    
    * If not using the -cfe_legacy option:
    Smith, RE.; Dimond, D; Vaughan, D.; Parker, D.; Dhollander, T.; Jackson, G.;
    Connelly, A. Intrinsic non-stationarity correction for Fixel-Based Analysis.
    In Proc OHBM 2019 M789
    
    * If using the -nonstationary option:
    Salimi-Khorshidi, G. Smith, S.M. Nichols, T.E. Adjusting the effect of
    nonstationarity in cluster-based and TFCE inference. NeuroImage, 2011,
    54(3), 2006-19.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        in_fixel_directory: the fixel directory containing the data files for\
            each subject (after obtaining fixel correspondence.
        subjects: a text file listing the subject identifiers (one per line).\
            This should correspond with the filenames in the fixel directory\
            (including the file extension), and be listed in the same order as the\
            rows of the design matrix.
        design: the design matrix.
        contrast: the contrast matrix, specified as rows of weights.
        connectivity: the fixel-fixel connectivity matrix.
        out_fixel_directory: the output directory where results will be saved.\
            Will be created if it does not exist.
        mask: provide a fixel data file containing a mask of those fixels to be\
            used during processing.
        notest: don't perform statistical inference; only output population\
            statistics (effect size, stdev etc).
        errors: specify nature of errors for shuffling; options are:\
            ee,ise,both (default: ee).
        exchange_within: specify blocks of observations within each of which\
            data may undergo restricted exchange.
        exchange_whole: specify blocks of observations that may be exchanged\
            with one another (for independent and symmetric errors, sign-flipping\
            will occur block-wise).
        strong: use strong familywise error control across multiple hypotheses.
        nshuffles: the number of shuffles (default: 5000).
        permutations: manually define the permutations (relabelling). The input\
            should be a text file defining a m x n matrix, where each relabelling\
            is defined as a column vector of size m, and the number of columns, n,\
            defines the number of permutations. Can be generated with the\
            palm_quickperms function in PALM\
            (http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/PALM). Overrides the -nshuffles\
            option.
        nonstationarity: perform non-stationarity correction.
        skew_nonstationarity: specify the skew parameter for empirical\
            statistic calculation (default for this command is 1).
        nshuffles_nonstationarity: the number of shuffles to use when\
            precomputing the empirical statistic image for non-stationarity\
            correction (default: 5000).
        permutations_nonstationarity: manually define the permutations\
            (relabelling) for computing the emprical statistics for\
            non-stationarity correction. The input should be a text file defining a\
            m x n matrix, where each relabelling is defined as a column vector of\
            size m, and the number of columns, n, defines the number of\
            permutations. Can be generated with the palm_quickperms function in\
            PALM (http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/PALM) Overrides the\
            -nshuffles_nonstationarity option.
        cfe_dh: the height increment used in the cfe integration (default: 0.1).
        cfe_e: cfe extent exponent (default: 2).
        cfe_h: cfe height exponent (default: 3).
        cfe_c: cfe connectivity exponent (default: 0.5).
        cfe_legacy: use the legacy (non-normalised) form of the cfe equation.
        variance: define variance groups for the G-statistic; measurements for\
            which the expected variance is equivalent should contain the same index.
        ftests: perform F-tests; input text file should contain, for each\
            F-test, a row containing ones and zeros, where ones indicate the rows\
            of the contrast matrix to be included in the F-test.
        fonly: only assess F-tests; do not perform statistical inference on\
            entries in the contrast matrix.
        column: add a column to the design matrix corresponding to subject\
            fixel-wise values (note that the contrast matrix must include an\
            additional column for each use of this option); the text file provided\
            via this option should contain a file name for each subject.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FixelcfestatsOutputs`).
    """
    params = fixelcfestats_params(
        mask=mask,
        notest=notest,
        errors=errors,
        exchange_within=exchange_within,
        exchange_whole=exchange_whole,
        strong=strong,
        nshuffles=nshuffles,
        permutations=permutations,
        nonstationarity=nonstationarity,
        skew_nonstationarity=skew_nonstationarity,
        nshuffles_nonstationarity=nshuffles_nonstationarity,
        permutations_nonstationarity=permutations_nonstationarity,
        cfe_dh=cfe_dh,
        cfe_e=cfe_e,
        cfe_h=cfe_h,
        cfe_c=cfe_c,
        cfe_legacy=cfe_legacy,
        variance=variance,
        ftests=ftests,
        fonly=fonly,
        column=column,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        in_fixel_directory=in_fixel_directory,
        subjects=subjects,
        design=design,
        contrast=contrast,
        connectivity=connectivity,
        out_fixel_directory=out_fixel_directory,
    )
    return fixelcfestats_execute(params, runner)


__all__ = [
    "FIXELCFESTATS_METADATA",
    "FixelcfestatsColumnParamsDict",
    "FixelcfestatsColumnParamsDictTagged",
    "FixelcfestatsConfigParamsDict",
    "FixelcfestatsConfigParamsDictTagged",
    "FixelcfestatsOutputs",
    "FixelcfestatsParamsDict",
    "FixelcfestatsParamsDictTagged",
    "FixelcfestatsVariousFileParamsDict",
    "FixelcfestatsVariousFileParamsDictTagged",
    "FixelcfestatsVariousStringParamsDict",
    "FixelcfestatsVariousStringParamsDictTagged",
    "fixelcfestats",
    "fixelcfestats_column",
    "fixelcfestats_config",
    "fixelcfestats_execute",
    "fixelcfestats_params",
    "fixelcfestats_various_file",
    "fixelcfestats_various_string",
]
