AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Bids

skill-k-dense-ai-scientific-agent-skills-bids · by K-Dense-AI

>

No reviews yet
0 installs
16 views
0.0% view→install

Install

$ agentstack add skill-k-dense-ai-scientific-agent-skills-bids

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-k-dense-ai-scientific-agent-skills-bids)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
1mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Bids? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Brain Imaging Data Structure (BIDS)

Overview

The Brain Imaging Data Structure (BIDS) is a community standard for organizing and describing neuroscience and biomedical research datasets. It defines a consistent file naming convention, directory hierarchy, and metadata schema so that datasets are immediately understandable by humans and software tools alike. BIDS is governed by the BIDS Specification (currently v1.11.x) and is maintained by the community via the BIDS-Standard GitHub organization.

While BIDS originated for MRI, it has grown well beyond neuroimaging. The specification now covers 11 modalities spanning imaging, electrophysiology, and behavioral data:

  • Imaging: MRI (structural, functional, diffusion, fieldmaps, perfusion/ASL), PET, microscopy
  • Electrophysiology: EEG, MEG, iEEG (intracranial EEG), EMG
  • Other: NIRS (near-infrared spectroscopy), motion capture, behavioral data (without imaging), MR spectroscopy

Active BEPs are extending BIDS further — notably BEP032 (microelectrode electrophysiology) will add support for extracellular recordings including Neuropixels probes, bringing BIDS to a prevalent methodology in animal neuroscience research (see also the neuropixels-analysis skill).

Adoption is required or strongly encouraged by major data repositories (OpenNeuro, DANDI), leading journals (NeuroImage, Human Brain Mapping, Scientific Data), and funding agencies (NIH, ERC).

The Python ecosystem for BIDS centers on PyBIDS (pybids) for querying and indexing BIDS datasets, and the bids-validator (Deno-based, available as PyPI package bids-validator-deno or via Deno directly) for compliance checking. Conversion from DICOM is typically done with HeuDiConv, dcm2bids, or BIDScoin.

When to Use This Skill

Apply this skill when:

  • Organizing raw neuroscience data (imaging, electrophysiology, behavioral) into BIDS-compliant directory structures
  • Querying an existing BIDS dataset to find specific files by subject, session, task, run, or modality
  • Validating a dataset against the BIDS specification before sharing or submission
  • Converting DICOM data from scanners into BIDS format
  • Writing or editing JSON sidecar metadata files
  • Creating BIDS-compliant derivatives (preprocessed data, analysis outputs)
  • Setting up a dataset_description.json for a new dataset
  • Working with BIDS entities (subject, session, task, acquisition, run, etc.)
  • Configuring .bidsignore to exclude files from validation
  • Preparing data for upload to OpenNeuro, DANDI, or other BIDS-aware repositories

Installation

# Core BIDS querying library
uv pip install pybids

# BIDS validator (Deno-based, installed via PyPI wrapper)
uv pip install bids-validator-deno
# Alternative: install directly via Deno
# deno install -g -A npm:bids-validator

# DICOM-to-BIDS converters (install as needed)
uv pip install heudiconv       # HeuDiConv - heuristic-based DICOM conversion
uv pip install dcm2bids        # dcm2bids - config-file-based conversion
# BIDScoin: uv pip install bidscoin

# Useful companions
uv pip install nibabel          # NIfTI/other neuroimaging file I/O
uv pip install pydicom          # DICOM file reading (used by converters)

Core Workflows

1. BIDS Directory Structure

A minimal BIDS dataset follows this layout:

my_dataset/
  dataset_description.json      # Required: name, BIDSVersion, etc.
  participants.tsv              # Recommended: subject-level phenotypic data
  participants.json             # Recommended: column descriptions
  README                        # Recommended: dataset documentation
  CHANGES                       # Recommended: version history
  .bidsignore                   # Optional: patterns to exclude from validation
  sub-01/
    anat/
      sub-01_T1w.nii.gz
      sub-01_T1w.json           # Sidecar metadata
    func/
      sub-01_task-rest_bold.nii.gz
      sub-01_task-rest_bold.json
      sub-01_task-rest_events.tsv     # Event timing for task fMRI
      sub-01_task-rest_events.json
    dwi/
      sub-01_dwi.nii.gz
      sub-01_dwi.json
      sub-01_dwi.bvec
      sub-01_dwi.bval
    fmap/
      sub-01_phasediff.nii.gz
      sub-01_phasediff.json
      sub-01_magnitude1.nii.gz
    perf/
      sub-01_asl.nii.gz
      sub-01_asl.json
  sub-01/
    ses-pre/
      anat/
        sub-01_ses-pre_T1w.nii.gz
      func/
        sub-01_ses-pre_task-nback_bold.nii.gz
    ses-post/
      ...

Key points:

  • Every NIfTI file should have a corresponding .json sidecar
  • File names encode entities: sub-[_ses-][_task-][_acq-][_run-]_.
  • Entity order in filenames is fixed by the specification
  • Only dataset_description.json is strictly required at the root level

2. Creating dataset_description.json

import json

dataset_description = {
    "Name": "My Neuroimaging Study",
    "BIDSVersion": "1.10.0",
    "DatasetType": "raw",
    "License": "CC0",
    "Authors": ["First Author", "Second Author"],
    "Acknowledgements": "Funded by NIH R01-MH123456",
    "HowToAcknowledge": "Please cite: Author et al. (2025) Journal Name.",
    "Funding": ["NIH R01-MH123456", "NSF BCS-7654321"],
    "ReferencesAndLinks": ["https://doi.org/10.xxxx/xxxxx"],
    "DatasetDOI": "10.18112/openneuro.ds000001.v1.0.0",
    "GeneratedBy": [
        {
            "Name": "HeuDiConv",
            "Version": "1.3.1",
            "CodeURL": "https://github.com/nipy/heudiconv"
        }
    ]
}

with open("dataset_description.json", "w") as f:
    json.dump(dataset_description, f, indent=4)

For derivatives, set "DatasetType": "derivative" and add "GeneratedBy" listing the pipeline:

deriv_description = {
    "Name": "fMRIPrep - fMRI PREProcessing",
    "BIDSVersion": "1.10.0",
    "DatasetType": "derivative",
    "GeneratedBy": [
        {
            "Name": "fMRIPrep",
            "Version": "24.1.0",
            "CodeURL": "https://github.com/nipreps/fmriprep"
        }
    ]
}

3. Querying BIDS Datasets with PyBIDS

from bids import BIDSLayout

# Index a BIDS dataset (validates structure on load)
layout = BIDSLayout("/path/to/bids_dataset")

# Basic queries
subjects = layout.get_subjects()          # ['01', '02', '03', ...]
sessions = layout.get_sessions()          # ['pre', 'post'] or []
tasks = layout.get_tasks()                # ['rest', 'nback']
runs = layout.get_runs()                  # [1, 2] or []

# Find specific files
bold_files = layout.get(
    suffix="bold",
    extension=".nii.gz",
    return_type="filename"
)

# Filter by subject, task, session
nback_sub01 = layout.get(
    subject="01",
    task="nback",
    suffix="bold",
    extension=".nii.gz",
    return_type="filename"
)

# Get metadata from JSON sidecars (automatic inheritance)
metadata = layout.get_metadata("/path/to/sub-01/func/sub-01_task-rest_bold.nii.gz")
tr = metadata["RepetitionTime"]

# Get all entities for a file
entities = layout.get_entities()

# Build a path from entities using BIDSLayout
bids_file = layout.get(subject="01", suffix="T1w", extension=".nii.gz")[0]
print(bids_file.path)
print(bids_file.get_entities())

Key points:

  • BIDSLayout indexes the entire dataset on initialization; for large datasets use database_path to cache the index
  • Metadata inheritance: a JSON sidecar at a higher level (e.g., root or subject) is inherited by all files below unless overridden
  • Use return_type="filename" for paths, return_type="object" (default) for BIDSFile objects

4. Validating BIDS Datasets

Using bids-validator via PyPI (recommended)

The bids-validator-deno PyPI package bundles the Deno-based validator as a standalone CLI:

# Install
uv pip install bids-validator-deno

# Validate a dataset
bids-validator /path/to/bids_dataset

# Ignore specific warnings/errors
bids-validator /path/to/bids_dataset --ignoreNiftiHeaders --ignoreSubjectConsistency
Using bids-validator via Deno directly

If Deno is already available, you can install or run the validator without PyPI:

# Install globally via Deno
deno install -g -A npm:bids-validator

# Or run without installing
deno run -A npm:bids-validator /path/to/bids_dataset
Legacy Node.js validator

The older Node.js-based validator (npm install -g bids-validator) is deprecated in favor of the Deno-based version. The Deno version is the reference implementation for BIDS Specification v1.9+.

Using .bidsignore

Create .bidsignore at the dataset root to exclude files from validation (gitignore syntax):

# Exclude sourcedata and extra files
sourcedata/
extra_data/
*.log
*_sbref.nii.gz
**/.DS_Store

5. BIDS Entities and File Naming

The authoritative, machine-readable source of truth for entities, their ordering, allowed suffixes, and all filename rules is the BIDS Schema — a structured YAML/JSON representation of the specification. A JSON export is shipped with this skill at references/bids_schema.json. The schema is defined in the bids-specification src/schema/ directory and published at https://bids-specification.readthedocs.io/en/stable/schema.json. BEP-specific schema previews are available at https://github.com/bids-standard/bids-schema/tree/main/BEPs.

Run scripts/update_schema.py to refresh the schema and BEPs list from upstream (no dependencies beyond stdlib).

The tables below are a convenient summary; when in doubt, consult the schema.

BIDS filenames are built from ordered key-value entity pairs:

| Entity | Key | Example | Required for | |--------|-----|---------|--------------| | Subject | sub- | sub-01 | All files | | Session | ses- | ses-pre | Multi-session studies | | Task | task- | task-rest | func (bold, cbv, phase), eeg, meg | | Acquisition | acq- | acq-highres | Distinguishing acquisition parameters | | Contrast enhancing agent | ce- | ce-gadolinium | Contrast-enhanced images | | Reconstruction | rec- | rec-magnitude | Reconstruction variants | | Direction | dir- | dir-AP | Fieldmaps, DWI, phase-encoding | | Run | run- | run-01 | Multiple identical acquisitions | | Echo | echo- | echo-1 | Multi-echo sequences | | Part | part- | part-mag | Magnitude/phase splits | | Space | space- | space-MNI152NLin2009cAsym | Derivatives in template space | | Description | desc- | desc-preproc | Derivatives only |

Entity ordering in filenames is fixed by the spec (defined in rules.entities in bids_schema.json). See references/bids_specification.md for the complete numbered ordering table. A common subset: sub-[_ses-][_task-][_acq-][_ce-][_rec-][_dir-][_run-][_echo-][_part-][_space-][_desc-]_.

Common suffixes by datatype:

| Datatype | Suffixes | |----------|----------| | anat | T1w, T2w, FLAIR, T2star, T1map, T2map, defacemask | | func | bold, cbv, sbref, events, physio, stim | | dwi | dwi, sbref | | fmap | phasediff, phase1, phase2, magnitude1, magnitude2, fieldmap, epi | | perf | asl, m0scan, aslcontext | | eeg | eeg, channels, electrodes, events | | meg | meg, channels, coordsystem, events | | ieeg | ieeg, channels, electrodes, coordsystem, events | | pet | pet, blood |

6. DICOM to BIDS Conversion

HeuDiConv

HeuDiConv is the most flexible DICOM-to-BIDS converter. It supports three usage modes — from fully automatic to fully custom — and handles duplicates, provenance tracking, and sourcedata archiving out of the box.

Mode 1: ReproIn (turnkey, recommended for new studies)

If scanner protocol names follow the ReproIn naming convention, conversion is fully automatic — no heuristic file to write:

# Turnkey conversion: HeuDiConv maps ReproIn protocol names to BIDS automatically
heudiconv --files dicom/001 -o /path/to/bids -f reproin --bids --minmeta

ReproIn protocol names encode BIDS entities directly:

  • anat-T1wsub-XX/anat/sub-XX_T1w.nii.gz
  • func-bold_task-restsub-XX/func/sub-XX_task-rest_bold.nii.gz
  • dwi_dir-APsub-XX/dwi/sub-XX_dir-AP_dwi.nii.gz
  • fmap_dir-PAsub-XX/fmap/sub-XX_dir-PA_epi.nii.gz

Session can be set once on the localizer (e.g., anat-scout_ses-pre) and ReproIn propagates it to all sequences in that Program. Subject ID is extracted from DICOM metadata. Duplicate runs are numbered automatically.

Mode 2: Custom heuristic mapping into ReproIn (for existing data)

If you already have data with non-ReproIn protocol names, you can write a thin heuristic that maps your names into ReproIn conventions, gaining all ReproIn benefits (automatic entity handling, duplicate management, etc.). See https://github.com/repronim/reproin/issues/18 for a HOWTO.

Mode 3: Custom heuristic (full flexibility)

For complex mappings, write a Python heuristic file:

# Step 1: Reconnaissance — discover DICOM series
heudiconv --files dicom/219/itbs/*/*.dcm -o Nifti/ -f convertall -s 219 -c none

# This creates .heudiconv/219/info/dicominfo.tsv — inspect it to understand
# what was acquired and map series to BIDS names.

# Step 2: Write a heuristic file (see references/conversion_tools.md)

# Step 3: Convert
heudiconv --files dicom/219/itbs/*/*.dcm -s 219 -ss itbs \
  -f Nifti/code/heuristic.py -c dcm2niix --bids --minmeta -o Nifti/

See references/conversion_tools.md for complete heuristic file examples.

Key points:

  • HeuDiConv wraps dcm2niix for the actual DICOM-to-NIfTI conversion
  • --minmeta: always use this flag to prevent excess DICOM metadata from overflowing JSON sidecars (can crash fMRIPrep/MRIQC)
  • Duplicate handling: use {item:03d} in templates for auto-numbering when the same protocol is run multiple times; without it, later runs overwrite earlier ones
  • .heudiconv/ directory: created alongside output, stores provenance (heuristic used, dicominfo.tsv, conversion records). Keep it with your data for reproducibility
  • sourcedata/: HeuDiConv archives original DICOMs as .tgz files under sourcedata/ for reproducibility
  • is_motion_corrected filter: use in heuristics to exclude scanner-generated MOCO series (e.g., if not s.is_motion_corrected)
  • Both --files (explicit paths) and -d (template with {subject}, {session} placeholders) are supported for specifying DICOM input
dcm2bids (Configuration-file-based)
# Step 1: Generate helper output to inspect series
dcm2bids_helper -d /path/to/dicom

# Step 2: Create config file (dcm2bids_config.json)
# Step 3: Convert
dcm2bids -d /path/to/dicom -p 01 -c dcm2bids_config.json -o /path/to/bids_output

See references/conversion_tools.md for detailed configuration examples.

7. Metadata Sidecars

Every BIDS data file should have a JSON sidecar with acquisition parameters. Metadata fields follow the inheritance principle: a sidecar at a higher directory level applies to all matching files below.

Inheritance example:

my_dataset/
  task-rest_bold.json           # Applies to ALL rest BOLD files
  sub-01/
    func/
      sub-01_task-rest_bold.json  # Overrides/extends for sub-01 only

Critical metadata fields by modality:

For func (BOLD):

{
    "RepetitionTime": 2.0,
    "TaskName": "rest",
    "PhaseEncodingDirection": "j-",
    "TotalReadoutTime": 0.05,
    "SliceTiming": [0, 0.5, 1.0, 1.5],
    "EffectiveEchoSpacing": 0.00058,
    "EchoTime": 0.03
}

For anat:

{
    "MagneticFieldStrength": 3,
    "Manufacturer": "Siemens",
    "ManufacturersModelName": "Prisma",
    "RepetitionTime": 2.3,
    "EchoTime": 0.00293,
    "FlipAngle": 8
}

For DWI:

{
    "PhaseEncodingDirection": "j-",
    "TotalReadoutTime": 0.05,
    "EchoTime": 0.089,
    "RepetitionTime": 3.4,
    "MultipartID": "dwi_1"
}

Key points:

  • dcm2niix auto-generates most sidecar fields from DICOM he

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.