Communitygithub.com

脑成像数据结构(BIDS)

BIDS 是一个社区标准,用于组织和描述神经科学与生物医学研究数据集。它定义了统一的文件命名、目录层次结构和元数据模式,使数据集易于人类和软件工具理解。

脑成像数据结构(BIDS) 是什么?

本技能提供了关于脑成像数据结构(BIDS)的全面指南,该标准是全球神经科学社区广泛采用的规范,用于组织成像、电生理学和行为学数据。它涵盖了11种模态,包括MRI、PET、EEG、MEG和iEEG,并介绍了如何通过PyBIDS进行数据查询、使用bids-validator进行合规性验证,以及利用HeuDiConv、dcm2bids或BIDScoin从DICOM数据转换为BIDS格式。该技能详细解释了核心工作流程,例如构建BIDS目录结构、创建dataset_description.json、处理事件文件、管理参与者TSV文件以及处理衍生数据。此外,它还提供针对常见问题的解决方案(如验证失败、时序错误和元数据缺失)以及最佳实践,包括早期频繁验证、利用元数据继承和使用scans.tsv记录运行级元数据。该技能还涵盖了BIDS扩展提案(BEP)生态系统和相关的工具生态,如fMRIPrep、MRIQC和TemplateFlow。通过将本技能集成到AI代理中,用户可在如OpenNeuro和DANDI等BIDS感知平台上无缝组织、验证和共享神经科学数据集。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/bids

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

脑成像数据结构(BIDS) 是做什么的?

概述

脑成像数据结构(BIDS)是一种社区标准,用于组织和描述神经科学与生物医学研究数据集。它定义了统一一致的文件命名约定、目录层次结构和元数据模式,使得数据集能够被人类和软件工具即时理解。BIDS 由 BIDS 规范(当前为 v1.11.x)管理,并由社区通过 BIDS-Standard GitHub 组织维护。

虽然 BIDS 最初用于 MRI,但其范围已远远超出神经影像学。该规范现涵盖 11 种模态,包括影像、电生理学和行为数据:

  • 影像:MRI(结构、功能、弥散、场图、灌注/ASL)、PET、显微成像
  • 电生理学:EEG、MEG、iEEG(颅内 EEG)、EMG
  • 其他:NIRS(近红外光谱)、动作捕捉、行为数据(不含影像)、MR 波谱

活跃的 BEP(BIDS 扩展提案)正在进一步扩展 BIDS——值得注意的 BEP032(微电极电生理学)将增加对包括 Neuropixels 探针在内的细胞外记录的支持,将 BIDS 引入动物神经科学研究中流行的方法学领域(也可参见 neuropixels-analysis 技能)。

主要数据存储库(OpenNeuro、DANDI)、领先期刊(NeuroImage、Human Brain Mapping、Scientific Data)以及资助机构(NIH、ERC)要求或强烈推荐采用 BIDS。

BIDS 的 Python 生态系统主要围绕用于查询和索引 BIDS 数据集的 PyBIDS (pybids),以及用于合规性检查的 bids-validator(基于 Deno,可作为 PyPI 包 bids-validator-deno 或直接通过 Deno 使用)。从 DICOM 进行转换通常使用 HeuDiConv、dcm2bids 或 BIDScoin。

何时使用此技能

在以下情况应用此技能:

  • 将原始神经科学数据(影像、电生理学、行为)组织成 BIDS 兼容的目录结构
  • 查询现有 BIDS 数据集以根据受试者、会话、任务、运行或模态查找特定文件
  • 在共享或提交前根据 BIDS 规范验证数据集
  • 将扫描仪的 DICOM 数据转换为 BIDS 格式
  • 编写或编辑 JSON 侧车元数据文件
  • 创建符合 BIDS 的衍生数据(预处理后的数据、分析输出)
  • 为新数据集设置 dataset_description.json
  • 处理 BIDS 实体(受试者、会话、任务、采集、运行等)
  • 配置 .bidsignore 以从验证中排除文件
  • 准备数据上传到 OpenNeuro、DANDI 或其他支持 BIDS 的存储库

安装

# 核心 BIDS 查询库
uv pip install pybids

# BIDS 验证器(基于 Deno,通过 PyPI 包装器安装)
uv pip install bids-validator-deno
# 替代方案:直接通过 Deno 安装
# deno install -g -A npm:bids-validator

# DICOM 转 BIDS 转换器(根据需要安装)
uv pip install heudiconv       # HeuDiConv - 基于启发式规则的 DICOM 转换
uv pip install dcm2bids        # dcm2bids - 基于配置文件的转换
# BIDScoin: uv pip install bidscoin

# 有用的辅助工具
uv pip install nibabel          # NIfTI/其他神经影像文件 I/O
uv pip install pydicom          # DICOM 文件读取(供转换器使用)

核心工作流程

references/core_workflows.md 文档中记录了两大工作流程,每个都附带现成的代码示例:

  1. BIDS 目录结构 — 所需的布局以及每种模态应放置的位置。
  2. dataset_description.json — 必需的字段以及如何生成它。
  3. 使用 PyBIDS 查询 — BIDSLayout、实体过滤器、侧车元数据及其自动继承,以及根据实体构建路径。
  4. 验证 — 通过 PyPI 包装器(推荐)、直接通过 Deno、传统的 Node 验证器以及使用 .bidsignore 排除文件。
  5. 实体和文件命名 — 实体顺序和命名语法。
  6. DICOM 到 BIDS 转换 — HeuDiConv(包括一键式 ReproIn 路径以及侦察→启发式→转换序列)和 dcm2bids(基于配置文件)。
  7. 元数据侧车 — 每种模态的必需和推荐的 JSON 字段。
  8. 事件文件 — 任务 fMRI 事件时序和列约定。
  9. 参与者文件 — participants.tsv 及其数据字典。
  10. 衍生数据 — 衍生数据的布局及其 dataset_description.json。
  11. 高级 PyBIDS — 索引缓存、包含衍生数据、混淆回归变量以及 DataFrame 输出。
  12. BIDS-Apps — 标准调用模式以及 fMRIPrep、MRIQC 和 QSIPrep。

及早并频繁验证:PyBIDS 在索引数据集时会验证结构,因此索引失败通常意味着命名或元数据问题,而不是代码错误。

参考资料

本技能包含详细的参考文档:

使用以下命令更新模式和 BEP:python scripts/update_schema.py

常见问题及解决方案

1. 验证器报告“不是 BIDS 数据集”

原因:根目录缺少 dataset_description.json。 修复:创建文件,至少包含 {"Name": "...", "BIDSVersion": "1.10.0"}。

2. 受试者不一致警告

原因:并非所有受试者都拥有相同的文件集(某些缺失会话、运行等)。 修复:这是警告,而非错误。如果是有意为之,请使用 --ignoreSubjectConsistency。在 participants.tsv 或 scans.tsv 中记录缺失数据。

3. 缺少 SliceTiming

原因:dcm2niix 无法从 DICOM 标头中提取切片时序。 修复:根据扫描协议确定切片顺序,并手动添加到 JSON 侧车中。常见模式:升序、降序、隔行扫描(奇数优先或偶数优先)。

4. 相位编码方向混淆

原因:轴标签(i/j/k 与 x/y/z 与 LR/AP/SI)令人困惑。 修复:在 BIDS 中,使用 NIfTI 图像轴:i=第一轴,j=第二轴,k=第三轴。- 表示负方向。对于标准的轴向采集:j 通常为前后方向。请验证采集协议。

5. PyBIDS 在大型数据集上很慢

原因:每次调用 BIDSLayout() 时都会进行完整的文件系统索引。 修复:使用 database_path 将索引缓存到 SQLite 文件:

layout = BIDSLayout("/data", database_path="/data/.pybids_cache.db")

6. PyBIDS 找不到衍生数据

原因:衍生数据目录缺少其自身的 dataset_description.json。 修复:每个衍生数据目录必须包含 dataset_description.json,并带有 "DatasetType": "derivative"。

7. 事件文件时序错误

原因:onset 时间相对于错误的参考点(例如,触发时间 vs 第一个卷)。 修复:起始时间必须相对于该运行采集的第一个卷,以秒为单位。如果丢弃了虚拟扫描,请考虑它们。

8. TSV 文件验证失败

原因:编码或分隔符问题(空格代替制表符、BOM 字符、Windows 换行符)。 修复:确保制表符分隔的值采用 UTF-8 编码和 Unix 换行符(\n)。对于缺失值,请使用 n/a(而不是 NA、NaN 或空值)。

最佳实践

  1. 及早并频繁验证 — 在每次转换或修改后运行 BIDS 验证器。在错误组合之前修复它们。

  2. 使用元数据继承 — 将共享元数据(例如 TaskName、扫描仪参数)放在顶级侧车文件中,而不是在每个受试者目录中重复。

  3. 保留源数据 — 将原始 DICOM(或其他原始)数据存储在 sourcedata/ 下,以便转换可重现。将 sourcedata/ 添加到 .bidsignore。

  4. 从一开始就使用一致的命名 — 在数据收集之前定义 BIDS 命名方案。使用 ReproIn 命名约定来扫描协议,以实现自动转换。

  5. 记录数据集 — 编写详尽的 README,描述研究设计、采集参数、已知问题以及任何与 BIDS 的偏差。

  6. 使用 scans.tsv 记录运行级元数据 — 记录每次运行的采集时间和质量说明:

filename    acq_time    quality
func/sub-01_task-rest_bold.nii.gz    2025-01-15T10:30:00    good
  1. 版本化数据集 — 使用 CHANGES 记录数据集修改。考虑使用 DataLad 对大型数据集进行完整版本控制。

  2. 去面部解剖图像 — 在共享前从 T1w/T2w 图像中移除面部特征(例如,使用 pydeface、mri_deface 或 afni_refacer)。将去面部版本存储为主要数据,或使用 _defacemask 文件。

  3. 使用 BIDS URI 进行溯源 — 在衍生数据中,使用 BIDS URI 引用源文件:bids::sub-01/anat/sub-01_T1w.nii.gz。

  4. 优先使用社区工具 — 尽可能使用成熟的 BIDS-Apps(fMRIPrep、MRIQC、QSIPrep)而不是自定义流程。它们能正确处理 BIDS I/O 并生成符合 BIDS 的衍生数据。

  5. 研究 bids-examples — bids-examples 存储库是典型 BIDS 数据集的权威集合,涵盖不同的模态和用例(MRI、fMRI、DWI、EEG、MEG、iEEG、PET、ASL、遗传学、衍生数据等)。在构建自己的数据集时将其作为参考,作为 BIDS 工具的测试数据,或了解特定模态应如何组织。每个示例都通过了 BIDS 验证器。

BIDS 扩展提案(BEP)

BEP 是由社区驱动的提案,旨在将 BIDS 扩展到新的模态、衍生数据或元数据。完整列表包含状态、负责人和链接,请参阅 references/beps.yml(从 bids-website 获取)。特定 BEP 的模式预览可在 https://github.com/bids-standard/bids-schema/tree/main/BEPs 查看。

当前 BEP(截至模式更新):

BEP标题内容状态
004磁敏感加权成像原始正在寻找新负责人
011结构预处理衍生数据衍生有 PR (#518)
012功能预处理衍生数据衍生有 PR (#519),模式已实现
014仿射变换和非线性场扭曲衍生X5 格式开发中
016弥散加权成像衍生数据衍生有 PR (#2211)
017通用 BIDS 连接数据模式衍生开发中
021通用电生理学衍生数据衍生开发中
023PET 预处理衍生数据衍生开发中
024计算机断层扫描原始正在寻找贡献者
026微电极记录原始正在寻找新负责人
028溯源元数据有 PR (#2099)
032微电极电生理学原始有 PR (#2307),预览可用 — 涵盖 Neuropixels 和其他细胞外探针;与 neuropixels-analysis 技能相关
033高级弥散加权成像原始正在寻找贡献者
034计算建模衍生有 PR (#967)
035基于非合规衍生数据的元分析衍生开发中
036表型数据指南原始社区评审中
037无创脑刺激原始开发中
039基于降维的网络原始开发中
040功能性超声原始开发中
041统计模型衍生数据衍生收集反馈中
043BIDS 术语映射元数据收集反馈中
044刺激原始有 PR (#2022),社区评审中
045外围生理记录原始有 PR (#2267)
046弥散纤维束成像衍生开发中
047行为实验的音视频记录原始有 PR (#2231)

相关标准:

  • BIDS-Stats Models:用于定义基于 GLM 的神经影像分析的 JSON 规范
  • BIDS-Derivatives (BEP003):预处理/分析输出的标准(已部分合并到规范中)

相关工具生态系统

工具用途
fMRIPrepfMRI 预处理(生成 BIDS 衍生数据)
MRIQCMRI 质量控制(生成 BIDS 衍生数据)
QSIPrep弥散 MRI 预处理
TemplateFlow具有 BIDS 类命名的神经影像模板和图谱
FitlinsBIDS Stats Models 实现
DataLad大型数据集版本控制,与 BIDS 集成
OpenNeuro免费 BIDS 数据集存储库
DANDI神经生理学数据存档(对某些模态使用 BIDS)
HeuDiConv基于启发式 Python 文件的 DICOM 转 BIDS
dcm2bids基于 JSON 配置的 DICOM 转 BIDS
BIDScoin带 GUI 和 YAML 配置的 DICOM 转 BIDS
nwb2bids将 NWB(无边界神经数据)文件转换为 BIDS
CuBIDSBIDS 数据集整理和协调
bids2tableBIDS 数据集的高效表格索引
bids-examples适用于所有模态的典型 BIDS 数据集的权威集合

文档

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

adaptyv

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

aeon

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

alphagenome

Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.

analytical-method-validation

Plan, execute, and document validation, verification, and transfer of analytical procedures under the governing framework - ICH Q2(R2) and Q14, USP <1220>/<1225>/<1226>, ICH M10 bioanalytical, CLSI EP, or ISO/IEC 17025. Use for HPLC, LC-MS/MS, GC, CE, ICP-MS, dissolution, qNMR, qPCR, NIR, and ligand binding or cell-based assays whenever the question is whether a procedure is fit for its intended purpose. Triggers include

anndata

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

arbor

Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g.

arboreto

Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

autoskill

Observe the user

benchling-integration

Benchling Python SDK and REST API integration for registry entities, inventory, ELN entries, workflows, Benchling Apps, and Data Warehouse queries. Use when automating lab data with benchling-sdk or the v2 API.

bgpt-paper-search

Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone.

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

bioservices

Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use biopython.

bulk-rnaseq

End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g.

cellxgene-census

Query the CZ CELLxGENE Census programmatically for versioned public single-cell and spatial transcriptomics data. Use when you need population-scale cell metadata, gene expression slices, Census summary counts, source H5AD URIs/downloads, embeddings, spatial Census data, or reference atlas comparisons across organisms, tissues, diseases, assays, and cell types. For analyzing your own local single-cell data use scanpy, anndata, or scvi-tools.

cirq

Google quantum computing framework. Use when targeting Google Quantum AI hardware, designing noise-aware circuits, or running quantum characterization experiments. Best for Google hardware, noise modeling, and low-level circuit design. For IBM hardware use qiskit; for quantum ML with autodiff use pennylane; for physics simulations use qutip.

citation-management

Comprehensive citation management for academic research. Search OpenAlex, PubMed, and Google Scholar for papers, extract accurate metadata, validate citations, and generate properly formatted BibTeX entries. This skill should be used when you need to find papers, verify citation information, convert DOIs to BibTeX, or ensure reference accuracy in scientific writing.

clinical-decision-support

Prepare and validate research-only clinical decision-support evaluation, evidence-profile, cohort, survival, biomarker/model, privacy, and governance artifacts. Use for aggregate or synthetic research documentation and traceability—not patient care or live clinical operation.

clinical-reports

Create safety-bounded draft structures and run local deterministic checks for clinical case, diagnostic, trial, safety, and aggregate research reports. Use only with synthetic, de-identified, or aggregate inputs and verified source-fact manifests; every output requires qualified review.

cobrapy

Constraint-based metabolic modeling (COBRA). FBA, FVA, gene knockouts, flux sampling, SBML models, for systems biology and metabolic engineering analysis.

相关技能