Command-line Interface#
The TRX toolkit provides a unified command-line interface trx as well as individual standalone commands for backward compatibility. All commands become available on your PATH after installing trx-python.
Each command supports --help for full options.
Unified CLI: trx#
The recommended way to use TRX commands is through the unified trx CLI:
trx --help # Show all available commands
trx <command> --help # Show help for a specific command
Available subcommands:
trx concatenate- Concatenate multiple tractogramstrx convert- Convert between tractography formatstrx convert-dsi- Fix DSI-Studio TRK filestrx generate- Generate TRX from raw data filestrx manipulate-dtype- Change array data typestrx compare- Simple tractogram comparisontrx validate- Validate and clean TRX filestrx verify-header- Check header compatibilitytrx visualize- Visualize tractogram overlap
Standalone Commands#
For backward compatibility, standalone commands are also available:
trx_concatenate_tractograms#
Concatenate multiple tractograms into a single output.
Supports
trk,tck,vtk,fib,dpy, andtrxinputs.Flags:
--delete-dpv,--delete-dps,--delete-groupsto drop mismatched metadata;--referencefor formats needing an anatomy reference;-fto overwrite.
# Using unified CLI
trx concatenate in1.trk in2.trk merged.trx
# Using standalone command
trx_concatenate_tractograms in1.trk in2.trk merged.trx
trx_convert_dsi_studio#
Convert a DSI Studio .trk with accompanying .nii.gz reference into a cleaned .trk or TRX.
# Using unified CLI
trx convert-dsi input.trk reference.nii.gz cleaned.trk
# Using standalone command
trx_convert_dsi_studio input.trk reference.nii.gz cleaned.trk
trx_convert_tractogram#
General-purpose converter between trk, tck, vtk, fib, dpy, and trx.
Flags:
--referencefor formats needing a NIfTI,--positions-dtype,--offsets-dtype,-fto overwrite.
# Using unified CLI
trx convert input.trk output.trx --positions-dtype float32 --offsets-dtype uint64
# Using standalone command
trx_convert_tractogram input.trk output.trx --positions-dtype float32 --offsets-dtype uint64
trx_generate_from_scratch#
Build a TRX file from raw NumPy arrays or CSV streamline coordinates.
Flags:
--positions,--offsets,--positions-dtype,--offsets-dtype, spatial options (--space,--origin), and metadata loaders for dpv/dps/groups/dpg.
# Using unified CLI
trx generate fa.nii.gz output.trx --positions positions.npy --offsets offsets.npy
# Using standalone command
trx_generate_from_scratch fa.nii.gz output.trx --positions positions.npy --offsets offsets.npy
trx_manipulate_datatype#
Rewrite TRX datasets with new dtypes for positions/offsets/dpv/dps/dpg/groups.
Accepts per-field dtype arguments and overwrites with
-f.
# Using unified CLI
trx manipulate-dtype input.trx output.trx --positions-dtype float16 --dpv color,uint8
# Using standalone command
trx_manipulate_datatype input.trx output.trx --positions-dtype float16 --dpv color,uint8
trx_simple_compare#
Compare two tractograms for quick difference checks.
# Using unified CLI
trx compare first.trk second.trk
# Using standalone command
trx_simple_compare first.trk second.trk
trx_validate#
Validate a TRX file for consistency and remove invalid streamlines.
# Using unified CLI
trx validate data.trx --out cleaned.trx
# Using standalone command
trx_validate data.trx --out cleaned.trx
trx_verify_header_compatibility#
Check whether tractogram headers are compatible for operations such as concatenation.
# Using unified CLI
trx verify-header file1.trk file2.trk
# Using standalone command
trx_verify_header_compatibility file1.trk file2.trk
trx_visualize_overlap#
Visualize streamline overlap between tractograms (requires visualization dependencies).
# Using unified CLI
trx visualize tractogram.trk reference.nii.gz
# Using standalone command
trx_visualize_overlap tractogram.trk reference.nii.gz
Notes#
Test datasets for examples can be fetched with
python -m trx.fetcherhelpers:fetch_data(get_testing_files_dict())downloads to$TRX_HOME(default~/.tee_ar_ex).All commands print detailed usage with
--help.The unified
trxCLI uses Typer for beautiful terminal output with colors and rich formatting.