Getting Started

This section will guide you through your first steps with NiWrap, which provides type-safe language bindings for neuroimaging tools generated by the Styx compiler.

Installation

Start by installing the NiWrap package for your preferred language:

pip install niwrap
npm install niwrap
# or
yarn add niwrap
# Install from GitHub
devtools::install_github("styx-api/niwrap-r")

That's it! With this, you're ready to start using neuroimaging tools through NiWrap's bindings.

Your First Command

Let's run a simple brain extraction using FSL's BET tool:

from niwrap import fsl 

# Run brain extraction
result = fsl.bet(
    infile="subject_01/T1.nii.gz",
    outfile="subject_01/brain.nii.gz",
    binary_mask=True
)
import { fsl } from 'niwrap';

// Run brain extraction
const result = await fsl.bet({
    infile: "subject_01/T1.nii.gz",
    outfile: "subject_01/brain.nii.gz",
    binary_mask: true
});
library(niwrap)

# Run brain extraction
result <- fsl$bet(
    infile = "subject_01/T1.nii.gz",
    outfile = "subject_01/brain.nii.gz",
    binary_mask = TRUE
)

This will result into the following command being called:

bet subject_01/T1.nii.gz subject_01/brain.nii.gz -m

Notice how NiWrap automatically translates parameters like binary_mask=True into the appropriate command-line flags that the underlying tools expect.

Using Docker

Don't have FSL installed? No problem. You can run all tools in containers:

from niwrap import fsl
import niwrap

# Enable Docker for all subsequent commands
niwrap.use_docker()

# Now this will run inside an FSL Docker container
result = fsl.bet(
    infile="subject_01/T1.nii.gz",
    outfile="subject_01/brain.nii.gz",
    binary_mask=True
)
import { fsl, useDocker } from 'niwrap';

// Enable Docker for all subsequent commands
useDocker();

// Now this will run inside an FSL Docker container
const result = await fsl.bet({
    infile: "subject_01/T1.nii.gz",
    outfile: "subject_01/brain.nii.gz",
    binary_mask: true
});
library(niwrap)

# Enable Docker for all subsequent commands
niwrap::use_docker()

# Now this will run inside an FSL Docker container
result <- fsl$bet(
    infile = "subject_01/T1.nii.gz",
    outfile = "subject_01/brain.nii.gz",
    binary_mask = TRUE
)

Working with Results

Each command returns a result object containing all output files, making it easy to chain operations:

from niwrap import fsl

# Run brain extraction
bet_result = fsl.bet(
    infile="subject_01/T1.nii.gz",
    binary_mask=True
)

# Use the result in another NiWrap command
fsl.fast(infile=bet_result.outfile)

# Or use with other Python libraries
from nilearn.plotting import plot_anat
plot_anat(bet_result.outfile)
import { fsl } from 'niwrap';

async function processData() {
    // Run brain extraction
    const betResult = await fsl.bet({
        infile: "subject_01/T1.nii.gz",
        binary_mask: true
    });

    // Use the result in another NiWrap command
    await fsl.fast({
        infile: betResult.outfile
    });
}
library(niwrap)

# Run brain extraction
bet_result <- fsl$bet(
    infile = "subject_01/T1.nii.gz",
    binary_mask = TRUE
)

# Use the result in another NiWrap command
fsl$fast(infile = bet_result$outfile)

# Or use with other R packages
library(oro.nifti)
img <- readNIfTI(bet_result$outfile)

tip

NiWrap includes detailed documentation about every command, argument, and output file. You should be able to hover over any of them in your editor to view its documentation.

Discovering Available Tools

To explore what tools are available, use your editor's autocomplete functionality:

from niwrap import fsl

# Type "fsl." and use autocomplete to see available tools
# fsl.bet
# fsl.fast
# fsl.flirt
# ...
import { fsl } from 'niwrap';

// Type "fsl." and use autocomplete to see available tools
// fsl.bet
// fsl.fast
// fsl.flirt
// ...
library(niwrap)

# Type "fsl$" and use autocomplete to see available tools
# fsl$bet
# fsl$fast
# fsl$flirt
# ...

Each tool has type hints and documentation that describe its parameters and outputs.

Next Steps

Now that you've run your first commands, you might want to learn about:

Ready to see more complex examples? Check out the Examples section for real-world usage patterns.