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

import typing
import pathlib
from styxdefs import *
import dataclasses

DCM2NIIX_METADATA = Metadata(
    id="15ccd57203c6c358b266b58ae05fde04fa3d5414.boutiques",
    name="dcm2niix",
    package="dcm2niix",
    container_image_tag="vnmd/dcm2niix_v1.0.20240202:20241125",
)


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


def dcm2niix_(
    input_dir: InputPathType,
    compression_level: float | None = None,
    adjacent: typing.Literal["y", "n"] | None = None,
    bids: typing.Literal["y", "n", "o"] | None = None,
    bids_anon: typing.Literal["y", "n"] | None = None,
    comment: str | None = None,
    depth: float | None = None,
    export_format: typing.Literal["y", "n", "o", "j", "b"] | None = None,
    filename: str | None = None,
    defaults: typing.Literal["y", "n", "o", "i"] | None = None,
    ignore_derived: typing.Literal["y", "n"] | None = None,
    scaling: typing.Literal["y", "n", "o"] | None = None,
    merge_2d: typing.Literal["n", "y", "0", "1", "2"] | None = None,
    series_number: str | None = None,
    output_dir: str | None = ".",
    philips_scaling: typing.Literal["y", "n"] | None = None,
    search_mode: typing.Literal["y", "l", "n"] | None = None,
    rename: typing.Literal["y", "n"] | None = None,
    single_file: typing.Literal["y", "n"] | None = None,
    update_check: bool = False,
    verbose: typing.Literal["0", "1", "2"] | None = None,
    conflict_behavior: float | None = None,
    crop_3d: typing.Literal["y", "n", "i"] | None = None,
    compression: typing.Literal["y", "o", "i", "n", "3"] | None = None,
    endian: typing.Literal["y", "n", "o"] | None = None,
    progress: typing.Literal["y", "n"] | None = None,
    ignore_trigger: bool = False,
    terse: bool = False,
    xml_: bool = False,
    runner: Runner | None = None,
) -> Dcm2niixOutputs:
    """
    Chris Rorden's dcm2niiX - DICOM to NIfTI converter. Converts DICOM files to
    NIfTI format with optional BIDS sidecar generation.
    
    Author: Chris Rorden
    
    Args:
        input_dir: Input folder containing DICOM files. Will be searched\
            recursively based on depth parameter.
        compression_level: gz compression level (1=fastest..9=smallest).
        adjacent: Adjacent DICOMs (images from same series always in same\
            folder) for faster conversion.
        bids: Generate BIDS sidecar JSON files (o=only: no NIfTI).
        bids_anon: Anonymize BIDS sidecar files by removing personal\
            information.
        comment: Comment stored in NIfTI aux_file (up to 24 characters).
        depth: Directory search depth for DICOM files in sub-folders.
        export_format: Export format: NRRD (y), MGH (o), JSON/JNIfTI (j), or\
            BJNIfTI (b).
        filename: Output filename template (%a=antenna, %b=basename,\
            %c=comments, %d=description, %e=echo number, %f=folder name,\
            %g=accession number, %i=ID of patient, %j=seriesInstanceUID,\
            %k=studyInstanceUID, %m=manufacturer, %n=name of patient,\
            %o=mediaObjectInstanceUID, %p=protocol, %r=instance number, %s=series\
            number, %t=time, %u=acquisition number, %v=vendor, %x=study ID;\
            %z=sequence name).
        defaults: Generate defaults file (o=only: reset and write defaults;\
            i=ignore: reset defaults).
        ignore_derived: Ignore derived, localizer and 2D images.
        scaling: Losslessly scale 16-bit integers (y=scale, n=no but\
            uint16->int16, o=original).
        merge_2d: Merge 2D slices from same series regardless of echo,\
            exposure, etc. (0=no, 1=yes, 2=auto).
        series_number: Only convert specified series CRC number (can be used up\
            to 16 times).
        output_dir: Output directory (omit to save to input folder).
        philips_scaling: Use Philips precise float (not display) scaling.
        search_mode: Search mode (y=show number of DICOMs, l=list DICOMs, n=no).
        rename: Rename instead of convert DICOMs.
        single_file: Single file mode, do not convert other images in folder.
        update_check: Check for newer versions.
        verbose: Verbose output (0=no, 1=yes, 2=logorrheic).
        conflict_behavior: Write behavior for name conflicts (0=skip,\
            1=overwrite, 2=add suffix).
        crop_3d: Crop 3D acquisitions (i=ignore: neither crop nor rotate).
        compression: gz compress images (y=pigz, o=optimal pigz,\
            i=internal:zlib, n=no, 3=no,3D).
        endian: Byte order (y=big-end, n=little-end, o=optimal/native).
        progress: Slicer format progress information.
        ignore_trigger: Disregard values in 0018,1060 and 0020,9153.
        terse: Omit filename post-fixes (can cause overwrites).
        xml_: Output Slicer format features.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Dcm2niixOutputs`).
    """
    if compression_level is not None and not (1 <= compression_level <= 9): 
        raise ValueError(f"'compression_level' must be between 1 <= x <= 9 but was {compression_level}")
    if depth is not None and not (0 <= depth <= 9): 
        raise ValueError(f"'depth' must be between 0 <= x <= 9 but was {depth}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(DCM2NIIX_METADATA)
    cargs = []
    cargs.append("dcm2niix")
    if compression_level is not None:
        cargs.append("-" + str(compression_level))
    if adjacent is not None:
        cargs.extend([
            "-a",
            adjacent
        ])
    if bids is not None:
        cargs.extend([
            "-b",
            bids
        ])
    if bids_anon is not None:
        cargs.extend([
            "-ba",
            bids_anon
        ])
    if comment is not None:
        cargs.extend([
            "-c",
            comment
        ])
    if depth is not None:
        cargs.extend([
            "-d",
            str(depth)
        ])
    if export_format is not None:
        cargs.extend([
            "-e",
            export_format
        ])
    if filename is not None:
        cargs.extend([
            "-f",
            filename
        ])
    if defaults is not None:
        cargs.extend([
            "-g",
            defaults
        ])
    if ignore_derived is not None:
        cargs.extend([
            "-i",
            ignore_derived
        ])
    if scaling is not None:
        cargs.extend([
            "-l",
            scaling
        ])
    if merge_2d is not None:
        cargs.extend([
            "-m",
            merge_2d
        ])
    if series_number is not None:
        cargs.extend([
            "-n",
            series_number
        ])
    if output_dir is not None:
        cargs.extend([
            "-o",
            output_dir
        ])
    if philips_scaling is not None:
        cargs.extend([
            "-p",
            philips_scaling
        ])
    if search_mode is not None:
        cargs.extend([
            "-q",
            search_mode
        ])
    if rename is not None:
        cargs.extend([
            "-r",
            rename
        ])
    if single_file is not None:
        cargs.extend([
            "-s",
            single_file
        ])
    if update_check:
        cargs.append("-u")
    if verbose is not None:
        cargs.extend([
            "-v",
            verbose
        ])
    if conflict_behavior is not None:
        cargs.extend([
            "-w",
            str(conflict_behavior)
        ])
    if crop_3d is not None:
        cargs.extend([
            "-x",
            crop_3d
        ])
    if compression is not None:
        cargs.extend([
            "-z",
            compression
        ])
    if endian is not None:
        cargs.extend([
            "--big-endian",
            endian
        ])
    if progress is not None:
        cargs.extend([
            "--progress",
            progress
        ])
    if ignore_trigger:
        cargs.append("--ignore_trigger_times")
    if terse:
        cargs.append("--terse")
    if xml_:
        cargs.append("--xml")
    cargs.append(execution.input_file(input_dir))
    ret = Dcm2niixOutputs(
        root=execution.output_file("."),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DCM2NIIX_METADATA",
    "Dcm2niixOutputs",
    "dcm2niix_",
]
