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

import typing
import pathlib
from styxdefs import *

CONNECTOMESTATS_METADATA = Metadata(
    id="607b512a43f94c7e5deeb72046391536e66cc167.boutiques",
    name="connectomestats",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_ConnectomestatsColumnParamsDictNoTag = typing.TypedDict('_ConnectomestatsColumnParamsDictNoTag', {
    "path": InputPathType,
})
ConnectomestatsColumnParamsDictTagged = typing.TypedDict('ConnectomestatsColumnParamsDictTagged', {
    "@type": typing.Literal["column"],
    "path": InputPathType,
})
ConnectomestatsColumnParamsDict = _ConnectomestatsColumnParamsDictNoTag | ConnectomestatsColumnParamsDictTagged


_ConnectomestatsConfigParamsDictNoTag = typing.TypedDict('_ConnectomestatsConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
ConnectomestatsConfigParamsDictTagged = typing.TypedDict('ConnectomestatsConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
ConnectomestatsConfigParamsDict = _ConnectomestatsConfigParamsDictNoTag | ConnectomestatsConfigParamsDictTagged


_ConnectomestatsParamsDictNoTag = typing.TypedDict('_ConnectomestatsParamsDictNoTag', {
    "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],
    "tfce_dh": typing.NotRequired[float | None],
    "tfce_e": typing.NotRequired[float | None],
    "tfce_h": typing.NotRequired[float | None],
    "variance": typing.NotRequired[InputPathType | None],
    "ftests": typing.NotRequired[InputPathType | None],
    "fonly": bool,
    "column": typing.NotRequired[list[ConnectomestatsColumnParamsDict] | None],
    "threshold": typing.NotRequired[float | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[ConnectomestatsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "algorithm": str,
    "design": InputPathType,
    "contrast": InputPathType,
    "output": str,
})
ConnectomestatsParamsDictTagged = typing.TypedDict('ConnectomestatsParamsDictTagged', {
    "@type": typing.Literal["mrtrix/connectomestats"],
    "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],
    "tfce_dh": typing.NotRequired[float | None],
    "tfce_e": typing.NotRequired[float | None],
    "tfce_h": typing.NotRequired[float | None],
    "variance": typing.NotRequired[InputPathType | None],
    "ftests": typing.NotRequired[InputPathType | None],
    "fonly": bool,
    "column": typing.NotRequired[list[ConnectomestatsColumnParamsDict] | None],
    "threshold": typing.NotRequired[float | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[ConnectomestatsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "algorithm": str,
    "design": InputPathType,
    "contrast": InputPathType,
    "output": str,
})
ConnectomestatsParamsDict = _ConnectomestatsParamsDictNoTag | ConnectomestatsParamsDictTagged


def connectomestats_column(
    path: InputPathType,
) -> ConnectomestatsColumnParamsDictTagged:
    """
    Build parameters.
    
    Args:
        path: add a column to the design matrix corresponding to subject\
            edge-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 connectomestats_column_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ConnectomestatsColumnParamsDict` 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 connectomestats_column_cargs(
    params: ConnectomestatsColumnParamsDict,
    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 connectomestats_config(
    key: str,
    value: str,
) -> ConnectomestatsConfigParamsDictTagged:
    """
    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 connectomestats_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ConnectomestatsConfigParamsDict` 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 connectomestats_config_cargs(
    params: ConnectomestatsConfigParamsDict,
    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


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


def connectomestats_params(
    input_: InputPathType,
    algorithm: str,
    design: InputPathType,
    contrast: InputPathType,
    output: str,
    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,
    tfce_dh: float | None = None,
    tfce_e: float | None = None,
    tfce_h: float | None = None,
    variance: InputPathType | None = None,
    ftests: InputPathType | None = None,
    fonly: bool = False,
    column: list[ConnectomestatsColumnParamsDict] | None = None,
    threshold: float | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[ConnectomestatsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> ConnectomestatsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: a text file listing the file names of the input connectomes.
        algorithm: the algorithm to use in network-based\
            clustering/enhancement. Options are: nbs, tfnbs, none.
        design: the design matrix.
        contrast: the contrast matrix.
        output: the filename prefix for all output.
        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.
        tfce_dh: the height increment used in the tfce integration (default:\
            0.1).
        tfce_e: tfce extent exponent (default: 0.4).
        tfce_h: tfce height exponent (default: 3).
        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\
            edge-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.
        threshold: the t-statistic value to use in threshold-based clustering\
            algorithms.
        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/connectomestats",
        "notest": notest,
        "strong": strong,
        "nonstationarity": nonstationarity,
        "fonly": fonly,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "input": input_,
        "algorithm": algorithm,
        "design": design,
        "contrast": contrast,
        "output": output,
    }
    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 tfce_dh is not None:
        params["tfce_dh"] = tfce_dh
    if tfce_e is not None:
        params["tfce_e"] = tfce_e
    if tfce_h is not None:
        params["tfce_h"] = tfce_h
    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 threshold is not None:
        params["threshold"] = threshold
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def connectomestats_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ConnectomestatsParamsDict` 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("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("tfce_dh", None) is not None:
        if not isinstance(params["tfce_dh"], (float, int)):
            raise StyxValidationError(f'`tfce_dh` has the wrong type: Received `{type(params.get("tfce_dh", None))}` expected `float | None`')
    if params.get("tfce_e", None) is not None:
        if not isinstance(params["tfce_e"], (float, int)):
            raise StyxValidationError(f'`tfce_e` has the wrong type: Received `{type(params.get("tfce_e", None))}` expected `float | None`')
    if params.get("tfce_h", None) is not None:
        if not isinstance(params["tfce_h"], (float, int)):
            raise StyxValidationError(f'`tfce_h` has the wrong type: Received `{type(params.get("tfce_h", None))}` expected `float | None`')
    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[ConnectomestatsColumnParamsDict] | None`')
        for e in params["column"]:
            connectomestats_column_validate(e)
    if params.get("threshold", None) is not None:
        if not isinstance(params["threshold"], (float, int)):
            raise StyxValidationError(f'`threshold` has the wrong type: Received `{type(params.get("threshold", None))}` expected `float | None`')
    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[ConnectomestatsConfigParamsDict] | None`')
        for e in params["config"]:
            connectomestats_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("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("algorithm", None) is None:
        raise StyxValidationError("`algorithm` must not be None")
    if not isinstance(params["algorithm"], str):
        raise StyxValidationError(f'`algorithm` has the wrong type: Received `{type(params.get("algorithm", None))}` expected `str`')
    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("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')


def connectomestats_cargs(
    params: ConnectomestatsParamsDict,
    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("connectomestats")
    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("tfce_dh", None) is not None:
        cargs.extend([
            "-tfce_dh",
            str(params.get("tfce_dh", None))
        ])
    if params.get("tfce_e", None) is not None:
        cargs.extend([
            "-tfce_e",
            str(params.get("tfce_e", None))
        ])
    if params.get("tfce_h", None) is not None:
        cargs.extend([
            "-tfce_h",
            str(params.get("tfce_h", None))
        ])
    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 [connectomestats_column_cargs(s, execution) for s in params.get("column", None)] for a in c])
    if params.get("threshold", None) is not None:
        cargs.extend([
            "-threshold",
            str(params.get("threshold", None))
        ])
    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 [connectomestats_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("input", None)))
    cargs.append(params.get("algorithm", None))
    cargs.append(execution.input_file(params.get("design", None)))
    cargs.append(execution.input_file(params.get("contrast", None)))
    cargs.append(params.get("output", None))
    return cargs


def connectomestats_outputs(
    params: ConnectomestatsParamsDict,
    execution: Execution,
) -> ConnectomestatsOutputs:
    """
    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 = ConnectomestatsOutputs(
        root=execution.output_file("."),
    )
    return ret


def connectomestats_execute(
    params: ConnectomestatsParamsDict,
    runner: Runner | None = None,
) -> ConnectomestatsOutputs:
    """
    connectomestats
    
    Connectome group-wise statistics at the edge level using non-parametric
    permutation testing.
    
    For the TFNBS algorithm, default parameters for statistical enhancement have
    been set based on the work in:
    Vinokur, L.; Zalesky, A.; Raffelt, D.; Smith, R.E. & Connelly, A. A Novel
    Threshold-Free Network-Based Statistics Method: Demonstration using
    Simulated Pathology. OHBM, 2015, 4144;
    and:
    Vinokur, L.; Zalesky, A.; Raffelt, D.; Smith, R.E. & Connelly, A. A novel
    threshold-free network-based statistical method: Demonstration and parameter
    optimisation using in vivo simulated pathology. In Proc ISMRM, 2015, 2846.
    Note however that not only was the optimisation of these parameters not very
    precise, but the outcomes of statistical inference (for both this algorithm
    and the NBS method) can vary markedly for even small changes to enhancement
    parameters. Therefore the specificity of results obtained using either of
    these methods should be interpreted with caution.
    
    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:
    
    * If using the NBS algorithm:
    Zalesky, A.; Fornito, A. & Bullmore, E. T. Network-based statistic:
    Identifying differences in brain networks.
    NeuroImage, 2010, 53, 1197-1207
    
    * If using the TFNBS algorithm:
    Baggio, H.C.; Abos, A.; Segura, B.; Campabadal, A.; Garcia-Diaz, A.; Uribe,
    C.; Compta, Y.; Marti, M.J.; Valldeoriola, F.; Junque, C. Statistical
    inference in brain graphs using threshold-free network-based statistics.HBM,
    2018, 39, 2289-2302
    
    * 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 `ConnectomestatsOutputs`).
    """
    connectomestats_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CONNECTOMESTATS_METADATA)
    params = execution.params(params)
    cargs = connectomestats_cargs(params, execution)
    ret = connectomestats_outputs(params, execution)
    execution.run(cargs)
    return ret


def connectomestats(
    input_: InputPathType,
    algorithm: str,
    design: InputPathType,
    contrast: InputPathType,
    output: str,
    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,
    tfce_dh: float | None = None,
    tfce_e: float | None = None,
    tfce_h: float | None = None,
    variance: InputPathType | None = None,
    ftests: InputPathType | None = None,
    fonly: bool = False,
    column: list[ConnectomestatsColumnParamsDict] | None = None,
    threshold: float | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[ConnectomestatsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> ConnectomestatsOutputs:
    """
    connectomestats
    
    Connectome group-wise statistics at the edge level using non-parametric
    permutation testing.
    
    For the TFNBS algorithm, default parameters for statistical enhancement have
    been set based on the work in:
    Vinokur, L.; Zalesky, A.; Raffelt, D.; Smith, R.E. & Connelly, A. A Novel
    Threshold-Free Network-Based Statistics Method: Demonstration using
    Simulated Pathology. OHBM, 2015, 4144;
    and:
    Vinokur, L.; Zalesky, A.; Raffelt, D.; Smith, R.E. & Connelly, A. A novel
    threshold-free network-based statistical method: Demonstration and parameter
    optimisation using in vivo simulated pathology. In Proc ISMRM, 2015, 2846.
    Note however that not only was the optimisation of these parameters not very
    precise, but the outcomes of statistical inference (for both this algorithm
    and the NBS method) can vary markedly for even small changes to enhancement
    parameters. Therefore the specificity of results obtained using either of
    these methods should be interpreted with caution.
    
    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:
    
    * If using the NBS algorithm:
    Zalesky, A.; Fornito, A. & Bullmore, E. T. Network-based statistic:
    Identifying differences in brain networks.
    NeuroImage, 2010, 53, 1197-1207
    
    * If using the TFNBS algorithm:
    Baggio, H.C.; Abos, A.; Segura, B.; Campabadal, A.; Garcia-Diaz, A.; Uribe,
    C.; Compta, Y.; Marti, M.J.; Valldeoriola, F.; Junque, C. Statistical
    inference in brain graphs using threshold-free network-based statistics.HBM,
    2018, 39, 2289-2302
    
    * 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:
        input_: a text file listing the file names of the input connectomes.
        algorithm: the algorithm to use in network-based\
            clustering/enhancement. Options are: nbs, tfnbs, none.
        design: the design matrix.
        contrast: the contrast matrix.
        output: the filename prefix for all output.
        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.
        tfce_dh: the height increment used in the tfce integration (default:\
            0.1).
        tfce_e: tfce extent exponent (default: 0.4).
        tfce_h: tfce height exponent (default: 3).
        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\
            edge-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.
        threshold: the t-statistic value to use in threshold-based clustering\
            algorithms.
        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 `ConnectomestatsOutputs`).
    """
    params = connectomestats_params(
        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,
        tfce_dh=tfce_dh,
        tfce_e=tfce_e,
        tfce_h=tfce_h,
        variance=variance,
        ftests=ftests,
        fonly=fonly,
        column=column,
        threshold=threshold,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        input_=input_,
        algorithm=algorithm,
        design=design,
        contrast=contrast,
        output=output,
    )
    return connectomestats_execute(params, runner)


__all__ = [
    "CONNECTOMESTATS_METADATA",
    "ConnectomestatsColumnParamsDict",
    "ConnectomestatsColumnParamsDictTagged",
    "ConnectomestatsConfigParamsDict",
    "ConnectomestatsConfigParamsDictTagged",
    "ConnectomestatsOutputs",
    "ConnectomestatsParamsDict",
    "ConnectomestatsParamsDictTagged",
    "connectomestats",
    "connectomestats_column",
    "connectomestats_config",
    "connectomestats_execute",
    "connectomestats_params",
]
