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

import typing
import pathlib
from styxdefs import *
import dataclasses

DMRI_BSET_METADATA = Metadata(
    id="a5ba928b721f328bbae969650915bdc4c218018a.boutiques",
    name="dmri_bset",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class DmriBsetOutputs(typing.NamedTuple):
    """
    Output object returned when calling `dmri_bset(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_dwi_file: OutputPathType
    """Output DWI series"""
    output_b_table_file: OutputPathType | None
    """Output b-value table"""
    output_g_table_file: OutputPathType | None
    """Output gradient table"""


def dmri_bset(
    input_dwi: InputPathType,
    output_dwi: str,
    btol: float | None = 0.05,
    bsort: bool = False,
    bmax: float | None = None,
    input_b_table: InputPathType | None = None,
    input_g_table: InputPathType | None = None,
    output_b_table: str | None = None,
    output_g_table: str | None = None,
    runner: Runner | None = None,
) -> DmriBsetOutputs:
    """
    This tool extracts a subset of volumes, b-values, and gradient directions from a
    diffusion MRI data set.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_dwi: Input DWI series.
        output_dwi: Output DWI series.
        btol: Tolerance around each single b-value (default: 0.05).
        bsort: Reorder output data by b-shell (default: maintain original\
            order).
        bmax: Extract all b-values less than or equal to a maximum.
        input_b_table: Input b-value table (default: input DWI base, .bvals\
            extension).
        input_g_table: Input gradient table (default: input DWI base, .bvecs\
            extension).
        output_b_table: Output b-value table (default: output DWI base, .bvals\
            extension).
        output_g_table: Output gradient table (default: output DWI base, .bvecs\
            extension).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `DmriBsetOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(DMRI_BSET_METADATA)
    cargs = []
    cargs.append("dmri_bset")
    cargs.append(execution.input_file(input_dwi))
    cargs.append(output_dwi)
    cargs.append("[B_VALUES...]")
    if btol is not None:
        cargs.extend([
            "--btol",
            str(btol)
        ])
    if bsort:
        cargs.append("--bsort")
    if bmax is not None:
        cargs.extend([
            "--bmax",
            str(bmax)
        ])
    if input_b_table is not None:
        cargs.extend([
            "--inb",
            execution.input_file(input_b_table)
        ])
    if input_g_table is not None:
        cargs.extend([
            "--ing",
            execution.input_file(input_g_table)
        ])
    if output_b_table is not None:
        cargs.extend([
            "--outb",
            output_b_table
        ])
    if output_g_table is not None:
        cargs.extend([
            "--outg",
            output_g_table
        ])
    ret = DmriBsetOutputs(
        root=execution.output_file("."),
        output_dwi_file=execution.output_file(output_dwi),
        output_b_table_file=execution.output_file(output_b_table) if (output_b_table is not None) else None,
        output_g_table_file=execution.output_file(output_g_table) if (output_g_table is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DMRI_BSET_METADATA",
    "DmriBsetOutputs",
    "dmri_bset",
]
