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

import typing
import pathlib
from styxdefs import *

CIFTI_CROSS_CORRELATION_METADATA = Metadata(
    id="05c0db0d9a53210f00f60734da04cd0863715c7a.boutiques",
    name="cifti-cross-correlation",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiCrossCorrelationParameters = typing.TypedDict('CiftiCrossCorrelationParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-cross-correlation"]],
    "cifti_a": InputPathType,
    "cifti_b": InputPathType,
    "cifti_out": str,
    "opt_weights_weight_file": typing.NotRequired[str | None],
    "opt_fisher_z": bool,
    "opt_mem_limit_limit_gb": typing.NotRequired[float | None],
})
CiftiCrossCorrelationParametersTagged = typing.TypedDict('CiftiCrossCorrelationParametersTagged', {
    "@type": typing.Literal["workbench/cifti-cross-correlation"],
    "cifti_a": InputPathType,
    "cifti_b": InputPathType,
    "cifti_out": str,
    "opt_weights_weight_file": typing.NotRequired[str | None],
    "opt_fisher_z": bool,
    "opt_mem_limit_limit_gb": typing.NotRequired[float | None],
})


class CiftiCrossCorrelationOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiCrossCorrelationParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    cifti_out: OutputPathType
    """output cifti file"""


def cifti_cross_correlation_params(
    cifti_a: InputPathType,
    cifti_b: InputPathType,
    cifti_out: str,
    opt_weights_weight_file: str | None = None,
    opt_fisher_z: bool = False,
    opt_mem_limit_limit_gb: float | None = None,
) -> CiftiCrossCorrelationParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti_a: first input cifti file.
        cifti_b: second input cifti file.
        cifti_out: output cifti file.
        opt_weights_weight_file: specify column weights: text file containing\
            one weight per column.
        opt_fisher_z: apply fisher small z transform (ie, artanh) to\
            correlation.
        opt_mem_limit_limit_gb: restrict memory usage: memory limit in\
            gigabytes.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-cross-correlation",
        "cifti_a": cifti_a,
        "cifti_b": cifti_b,
        "cifti_out": cifti_out,
        "opt_fisher_z": opt_fisher_z,
    }
    if opt_weights_weight_file is not None:
        params["opt_weights_weight_file"] = opt_weights_weight_file
    if opt_mem_limit_limit_gb is not None:
        params["opt_mem_limit_limit_gb"] = opt_mem_limit_limit_gb
    return params


def cifti_cross_correlation_cargs(
    params: CiftiCrossCorrelationParameters,
    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("wb_command")
    cargs.append("-cifti-cross-correlation")
    cargs.append(execution.input_file(params.get("cifti_a", None)))
    cargs.append(execution.input_file(params.get("cifti_b", None)))
    cargs.append(params.get("cifti_out", None))
    if params.get("opt_weights_weight_file", None) is not None:
        cargs.extend([
            "-weights",
            params.get("opt_weights_weight_file", None)
        ])
    if params.get("opt_fisher_z", False):
        cargs.append("-fisher-z")
    if params.get("opt_mem_limit_limit_gb", None) is not None:
        cargs.extend([
            "-mem-limit",
            str(params.get("opt_mem_limit_limit_gb", None))
        ])
    return cargs


def cifti_cross_correlation_outputs(
    params: CiftiCrossCorrelationParameters,
    execution: Execution,
) -> CiftiCrossCorrelationOutputs:
    """
    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 = CiftiCrossCorrelationOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(params.get("cifti_out", None)),
    )
    return ret


def cifti_cross_correlation_execute(
    params: CiftiCrossCorrelationParameters,
    runner: Runner | None = None,
) -> CiftiCrossCorrelationOutputs:
    """
    cifti-cross-correlation
    
    Correlate a cifti file with another cifti file.
    
    Correlates every row in <cifti-a> with every row in <cifti-b>. The mapping
    along columns in <cifti-b> becomes the mapping along rows in the output.
    
    When using the -fisher-z option, the output is NOT a Z-score, it is
    artanh(r), to do further math on this output, consider using -cifti-math.
    
    Restricting the memory usage will make it calculate the output in chunks, by
    reading through <cifti-b> multiple times.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiCrossCorrelationOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_CROSS_CORRELATION_METADATA)
    params = execution.params(params)
    cargs = cifti_cross_correlation_cargs(params, execution)
    ret = cifti_cross_correlation_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_cross_correlation(
    cifti_a: InputPathType,
    cifti_b: InputPathType,
    cifti_out: str,
    opt_weights_weight_file: str | None = None,
    opt_fisher_z: bool = False,
    opt_mem_limit_limit_gb: float | None = None,
    runner: Runner | None = None,
) -> CiftiCrossCorrelationOutputs:
    """
    cifti-cross-correlation
    
    Correlate a cifti file with another cifti file.
    
    Correlates every row in <cifti-a> with every row in <cifti-b>. The mapping
    along columns in <cifti-b> becomes the mapping along rows in the output.
    
    When using the -fisher-z option, the output is NOT a Z-score, it is
    artanh(r), to do further math on this output, consider using -cifti-math.
    
    Restricting the memory usage will make it calculate the output in chunks, by
    reading through <cifti-b> multiple times.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        cifti_a: first input cifti file.
        cifti_b: second input cifti file.
        cifti_out: output cifti file.
        opt_weights_weight_file: specify column weights: text file containing\
            one weight per column.
        opt_fisher_z: apply fisher small z transform (ie, artanh) to\
            correlation.
        opt_mem_limit_limit_gb: restrict memory usage: memory limit in\
            gigabytes.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiCrossCorrelationOutputs`).
    """
    params = cifti_cross_correlation_params(
        cifti_a=cifti_a,
        cifti_b=cifti_b,
        cifti_out=cifti_out,
        opt_weights_weight_file=opt_weights_weight_file,
        opt_fisher_z=opt_fisher_z,
        opt_mem_limit_limit_gb=opt_mem_limit_limit_gb,
    )
    return cifti_cross_correlation_execute(params, runner)


__all__ = [
    "CIFTI_CROSS_CORRELATION_METADATA",
    "CiftiCrossCorrelationOutputs",
    "cifti_cross_correlation",
    "cifti_cross_correlation_execute",
    "cifti_cross_correlation_params",
]
