根据脑成像数据结构(BIDS)转换和组织原始MRI数据集

bidscoin的Python项目详细描述


bidscoin

a bids converter toolkit

pypi versionpypi-python version

bidscoin是一个用户友好的开放源码的python工具包,它将(coins)源代码级(raw)神经成像数据集转换为(nifti)nifti。rel="nofollow">json/tsv按照脑成像数据结构组织的数据集,也就是a.k.a.bids标准。bidscoin使用直接映射方法来识别原始源数据并将其转换为bids数据,而不是依赖于复杂或不明确的编程逻辑来识别成像模式。可用于将源数据映射到投标的信息源是:

  1. mri头文件中的信息(dicom、par/rec或.7格式;例如seriesdescription)
  2. 来自NIFTI标题的信息(例如图像维度)
  3. 文件结构中的信息(文件和/或目录名,例如文件数)
< Buff行情>

注意:目前,DICOM支持(选项1)已经完全实现,但对选项2和3的支持计划在未来的版本中进行。

映射信息以键值对的形式存储在人们可读的、广泛支持的yaml文件中。nifti-和json文件是用dcm2nix生成的。此外,用户还可以提供自定义编写的插件函数,例如使用附加信息源或解析演示日志文件。

因为所有的映射信息都可以用图形用户界面编辑,bidscoin不需要编程知识即可使用。

有关bidscoin安装和要求的信息,请参见安装指南。

bidscoin工作流

所需的源数据结构

bidscoin将获取您的(原始)源数据以及具有键值映射的yaml文件。(字典)信息作为输入,并返回bids文件夹作为输出。源数据输入文件夹应按照/sub identifier/[ses identifier]/seriesfolder/dicomfile结构组织。此数据组织是用户从(西门子)扫描仪在dccn上接收数据的方式(nb:theses identifier子文件夹是可选的,可以省略)。

  • 如果您的数据还没有以这种方式组织,您可以使用方便的命令行实用程序将无序或dicomdir排序的dicom文件移动到具有dicom系列文件夹的组织中。命名为[seriesNumber]-[seriesDescription]。系列文件夹包含单个数据类型,通常在一次运行中获取。

  • 另一个有助于组织源数据的命令行实用程序是rawmapper.py。此实用程序可以显示数据集中所有感兴趣dicom字段值的概述(映射),还可以使用这些字段重命名源数据子文件夹(这很方便,例如,如果您在scanner控制台和yo上手动将主题标识符作为[附加信息]输入你想用这些来重命名你的主题文件夹。

< Buff行情>

如果这些实用程序不能满足您的需要,请查看以下工具

将源数据添加到出价中

有了一个有组织的源数据文件夹,实际的数据集到bids的转换由(1a)bidsmapper.py,(1b)bidseditor.pyd(2)命令行工具。bidsmapper生成源数据集中不同类型数据类型的映射,使用bidseditor可以编辑此映射,bidscoiner执行实际工作,将源数据转换为bids。默认情况下(但请参见下面bidsmapper的-i选项),步骤1a自动启动步骤1b,因此在最简单的形式下,将原始源数据转换为bids所需做的只是运行两个简单的命令,例如:

bidsmapper.py sourcefolder bidsfolder
bidscoiner.py sourcefolder bidsfolder

步骤1a:运行bidsmapper
usage: bidsmapper.py [-h] [-b BIDSMAP] [-t TEMPLATE] [-n SUBPREFIX]
                     [-m SESPREFIX] [-i {0,1,2}] [-v]
                     sourcefolder bidsfolder

Creates a bidsmap.yaml YAML file in the bidsfolder/code/bidscoin that maps the information
from all raw source data to the BIDS labels. You can check and edit the bidsmap file with
the bidseditor (but also with any text-editor) before passing it to the bidscoiner
N.B.: Institute users may want to use a site-customized template bidsmap (see the
--template option). The bidsmap_dccn template from the Donders Institute can serve as
an example (or may even mostly work for other institutes out of the box).

positional arguments:
  sourcefolder          The source folder containing the raw data in
                        sub-#/ses-#/run format (or specify --subprefix and
                        --sesprefix for different prefixes)
  bidsfolder            The destination folder with the (future) bids data and
                        the bidsfolder/code/bidscoin/bidsmap.yaml output file

optional arguments:
  -h, --help            show this help message and exit
  -b BIDSMAP, --bidsmap BIDSMAP
                        The bidsmap YAML-file with the study heuristics. If
                        the bidsmap filename is relative (i.e. no "/" in the
                        name) then it is assumed to be located in
                        bidsfolder/code/bidscoin. Default: bidsmap.yaml
  -t TEMPLATE, --template TEMPLATE
                        The bidsmap template with the default heuristics (this
                        could be provided by your institute). If the bidsmap
                        filename is relative (i.e. no "/" in the name) then it
                        is assumed to be located in bidsfolder/code/bidscoin.
                        Default: bidsmap_template.yaml
  -n SUBPREFIX, --subprefix SUBPREFIX
                        The prefix common for all the source subject-folders.
                        Default: 'sub-'
  -m SESPREFIX, --sesprefix SESPREFIX
                        The prefix common for all the source session-folders.
                        Default: 'ses-'
  -i {0,1,2}, --interactive {0,1,2}
                        {0}: The sourcefolder is scanned for different kinds
                        of scans without any user interaction. {1}: The
                        sourcefolder is scanned for different kinds of scans
                        and, when finished, the resulting bidsmap is opened
                        using the bidseditor. {2}: As {1}, except that already
                        during scanning the user is asked for help if a new
                        and unknown run is encountered. This option is most
                        useful when re-running the bidsmapper (e.g. when the
                        scan protocol was changed since last running the
                        bidsmapper). Default: 1
  -v, --version         Show the BIDS and BIDScoin version

examples:
  bidsmapper.py /project/foo/raw /project/foo/bids
  bidsmapper.py /project/foo/raw /project/foo/bids -t bidsmap_dccn

bidsmapper将扫描sourcefolder以查找不同的运行(扫描类型),为每次运行创建到bids输出名称(也称为"bidsmap")的映射。默认情况下(但请参见上面的-i选项),完成后,bidsmapper将自动启动步骤1b,如下一节所述(但步骤1b也可以通过直接运行bidseditor单独运行)。

< Buff行情>

提示:使用-t bidsmap_dccn选项,看看它是否适合您。如果没有,请考虑使用文本编辑器打开它,并根据需要进行调整。

步骤1b:运行bidseditor
usage: bidseditor.py [-h] [-s SOURCEFOLDER] [-b BIDSMAP] [-t TEMPLATE]
                     [-n SUBPREFIX] [-m SESPREFIX]
                     bidsfolder

This tool launches a graphical user interface for editing the bidsmap.yaml file
that is e.g. produced by the bidsmapper or by this bidseditor itself. The user can
fill in or change the BIDS labels for entries that are unidentified or sub-optimal,
such that meaningful BIDS output names will be generated from these labels. The saved
bidsmap.yaml output file can be used for converting the source data to BIDS using
the bidscoiner.

positional arguments:
  bidsfolder            The destination folder with the (future) bids data

optional arguments:
  -h, --help            show this help message and exit
  -s SOURCEFOLDER, --sourcefolder SOURCEFOLDER
                        The source folder containing the raw data. If empty,
                        it is derived from the bidsmap provenance information
  -b BIDSMAP, --bidsmap BIDSMAP
                        The bidsmap YAML-file with the study heuristics. If
                        the bidsmap filename is relative (i.e. no "/" in the
                        name) then it is assumed to be located in
                        bidsfolder/code/bidscoin. Default: bidsmap.yaml
  -t TEMPLATE, --template TEMPLATE
                        The bidsmap template with the default heuristics (this
                        could be provided by your institute). If the bidsmap
                        filename is relative (i.e. no "/" in the name) then it
                        is assumed to be located in bidsfolder/code/bidscoin.
                        Default: bidsmap_template.yaml
  -n SUBPREFIX, --subprefix SUBPREFIX
                        The prefix common for all the source subject-folders.
                        Default: 'sub-'
  -m SESPREFIX, --sesprefix SESPREFIX
                        The prefix common for all the source session-folders.
                        Default: 'ses-'

examples:
  bidseditor.py /project/foo/bids
  bidseditor.py /project/foo/bids -t bidsmap_dccn.yaml
  bidseditor.py /project/foo/bids -b my/custom/bidsmap.yaml

Here are a few tips & tricks:
-----------------------------

DICOM Attributes
  An (DICOM) attribute label can also be a list, in which case the BIDS labels / mapping
  are applies if a (DICOM) attribute value is in this list. If the attribute value is
  empty it is not used to identify the run. Wildcards can also be given, either as a single
  '*', or enclosed by '*'. Examples:
       SequenceName: '*'
       SequenceName: '*epfid*'
       SequenceName: ['epfid2d1rs', 'fm2d2r']
       SequenceName: ['*epfid*', 'fm2d2r']
   NB: Editing the DICOM attributes is normally not necessary and adviced against

Dynamic BIDS labels
  The BIDS labels can be static, in which case the label is just a normal string, or dynamic,
  when the string is enclosed with pointy brackets like `<attribute name>` or
  `<<argument1><argument2>>`. In case of single pointy brackets the label will be replaced
  during bidsmapper, bidseditor and bidscoiner runtime by the value of the (DICOM) attribute
  with that name. In case of double pointy brackets, the label will be updated for each
  subject/session during bidscoiner runtime. For instance, then the `run` label `<<1>>` in
  the bids name will be replaced with `1` or increased to `2` if a file with runindex `1`
  already exists in that directory.

Fieldmaps: suffix
  Select 'magnitude1' if you have 'magnitude1' and 'magnitude2' data in one series-folder
  (this is what Siemens does) -- the bidscoiner will automatically pick up the 'magnitude2'
  data during runtime. The same holds for 'phase1' and 'phase2' data. See the BIDS
  specification for more details on fieldmap suffixes

Fieldmaps: IntendedFor
  You can use the `IntendedFor` field to indicate for which runs (DICOM series) a fieldmap
  was intended. The dynamic label of the `IntendedFor` field can be a list of string patterns
  that is used to include all runs in a session that have that string pattern in their BIDS
  file name. Example: use `<<task>>` to include all functional runs or `<<Stop*Go><Reward>>`
  to include "Stop1Go"-, "Stop2Go"- and "Reward"-runs.
  NB: The fieldmap might not be used at all if this field is left empty!

Manual editing / inspection of the bidsmap
  You can of course also directly edit or inspect the `bidsmap.yaml` file yourself with any
  text editor. For instance to merge a set of runs that by adding a wildcard to a DICOM
  attribute in one run item and then remove the other runs in the set. See ./docs/bidsmap.md
  and ./heuristics/bidsmap_dccn.yaml for more information.

如下图所示,bidseditor的主窗口打开,其中有一个bids map选项卡,其中包含一个input samples列表,该列表唯一表示源文件夹中存在的所有不同文件,以及相关的bids output namebids输出名中的路径显示为红色,如果模式不是bids标准的一部分,则在转换为bids时将忽略运行时删除灰色,否则将显示为绿色。双击sample(dicom)文件名将打开一个带有完整标题i的检查窗口信息(双击示例文件名可在整个图形用户界面中工作)。

bidseditor主窗口

用户可以单击每个列表项的编辑按钮,打开一个新的编辑窗口,如下所示。在此界面中,右标模态(下拉菜单)和后缀标签(下拉菜单)可以正确设置,然后可以编辑关联的标标签(双击黑色项)。结果,新的bids输出名将显示在底部的文本字段中。这就是bids输出数据的样子,如果一切正常,用户可以将此映射存储到bidsmap并通过单击ok按钮返回主窗口。

bidseditor编辑窗口

最后,如果主窗口中的所有bids输出名称都正常,用户可以单击保存按钮并继续运行bidscoiner工具。

步骤2:运行bidscoiner
usage: bidscoiner.py [-h] [-p PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]] [-f]
                     [-s] [-b BIDSMAP] [-n SUBPREFIX] [-m SESPREFIX] [-v]
                     sourcefolder bidsfolder

Converts ("coins") datasets in the sourcefolder to nifti / json / tsv datasets in the
bidsfolder according to the BIDS standard. Check and edit the bidsmap.yaml file to
your needs using the bidseditor.py tool before running this function. You can run
bidscoiner.py after all data is collected, or whenever new data has been added to the
source folder (presuming the scan protocol hasn't changed).

Provenance information, warnings and error messages are stored in the
bidsfolder/code/bidscoin/bidscoiner.log file.

positional arguments:
  sourcefolder          The source folder containing the raw data in
                        sub-#/[ses-#]/run format (or specify --subprefix and
                        --sesprefix for different prefixes)
  bidsfolder            The destination / output folder with the bids data

optional arguments:
  -h, --help            show this help message and exit
  -p PARTICIPANT_LABEL [PARTICIPANT_LABEL ...], --participant_label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]
                        Space seperated list of selected sub-# names / folders
                        to be processed (the sub- prefix can be removed).
                        Otherwise all subjects in the sourcefolder will be
                        selected
  -f, --force           If this flag is given subjects will be processed,
                        regardless of existing folders in the bidsfolder.
                        Otherwise existing folders will be skipped
  -s, --skip_participants
                        If this flag is given those subjects that are in
                        particpants.tsv will not be processed (also when the
                        --force flag is given). Otherwise the participants.tsv
                        table is ignored
  -b BIDSMAP, --bidsmap BIDSMAP
                        The bidsmap YAML-file with the study heuristics. If
                        the bidsmap filename is relative (i.e. no "/" in the
                        name) then it is assumed to be located in
                        bidsfolder/code/bidscoin. Default: bidsmap.yaml
  -n SUBPREFIX, --subprefix SUBPREFIX
                        The prefix common for all the source subject-folders.
                        Default: 'sub-'
  -m SESPREFIX, --sesprefix SESPREFIX
                        The prefix common for all the source session-folders.
                        Default: 'ses-'
  -v, --version         Show the BIDS and BIDScoin version

examples:
  bidscoiner.py /project/foo/raw /project/foo/bids
  bidscoiner.py -f /project/foo/raw /project/foo/bids -p sub-009 sub-030

完成

在成功运行bidscoiner.py之后,在完全兼容的bids数据集中转换数据的工作不幸地还没有完全结束,并且,根据数据集的复杂性,可能需要运行其他工具,并且可能需要手动输入元数据(永远不会一切都可以自动化)。例如,您应该更新bids文件夹中的dataset_description.jsonreadme文件的内容,您可能需要提供其他*_scans.tsv*_sessions.tsvparticipants.json文件(请参见//bids.neuroImaging.io/bids_spec.pdf" rel="nofollow">投标规范了解更多信息)。此外,如果您有行为日志文件,您会发现bidscoin还不支持将这些文件转换为符合bids的*\u events.tsv/json文件(鼓励高级用户使用bidscoiner.py插件编写自己的日志文件解析器的可能性。

如果以上所有工作都完成了,您可以(而且应该)运行基于web的bids validator来检查bids数据集中是否存在不一致或丢失的文件(注意:bidsvalidator也以abidsvalidator的形式存在。com/bids standard/bids validator" rel="nofollow">命令行工具)。

< Buff行情>

注意:生成的bids数据集的出处存储在bids/code/bidscoin/bidscoiner.log文件中。此文件对于调试/跟踪bidsmapping问题也非常有用。

选项和插件功能

bidscoin为研究人员提供了编写自定义python函数的可能性,这些函数将在bidsmapper.py和bidscoiner.py运行时执行。要使用此功能,请在bidsmap字典文件中输入模块的名称(默认位置是plugins文件夹;否则必须提供完整路径)以导入插件函数。对于bidsmapper.py,模块中的函数应命名为bidsmapper\u plugin,对于bidscoiner.py,应命名为bidscoiner\u plugin。有关更多详细信息和占位符代码,请参见readme.py

bidscoin功能/todo

  • [X]DICOM源数据
  • []PAR/Rec源数据
  • []P7源数据
  • []NIFTI源数据
  • [X]野外地图
  • [X]多回波数据
  • [X]多线圈数据
  • 宠物数据
  • []刺激/行为日志文件
< Buff行情>

您是否是一个对bids感兴趣的python程序员,对ge和/或philips数据了如指掌?您是否有分析刺激方案演示文稿日志文件的经验?或者你有改进这个工具包或它的文档的想法吗?你碰到虫子了吗?然后,我们强烈建议您在https://github.com/donders-institute/bidscoin rel="nofollow">https://github.com/donders institute/bidscoin上提供反馈或对此项目作出贡献。

Bidscoin教程

本教程专门针对DCCN的研究人员,并使用存储在其中央文件系统中的数据集。但是,对于其他数据集,使用本教程(至少是本教程的一部分)也不难。

  1. 准备。通过执行这些bash命令激活bidscoin环境并在主目录中创建一个教程操场文件夹(另请参见模块帮助bidscoin):

    module add bidscoin  
    source activate /opt/bidscoin  
    cp -r /opt/bidscoin/tutorial ~
    

    新的教程文件夹包含原始源数据文件夹和投标参考参考投标文件夹,即本教程的最终产品。

    让我们从检查这个新的原始数据收集开始:

    • 所有sub-/ses-文件夹的dicom文件是否按系列子文件夹(例如sub-001/ses-01/003-t1mprage/0001.dcm等)组织?如果没有,请使用dicomsort.py
    • 使用rawmapper.py命令打印raw文件夹中fmri系列的"echotime"、"sex"和"acquisitiondate"的dicom值
  2. bids映射。通过运行bidsmapper来扫描原始数据集合中的所有文件夹以查找未知数据bash命令:

    bidsmapper.py raw bids
    
    • 将功能扫描的"任务标签"重命名为更可读的内容,例如"奖励"和"停止"
    • 将搜索模式添加到intendefor字段,以便它选择您的fmri运行(有关详细信息,请参见bidseditorfieldmap部分)
    • 全部完成后,(重新)打开bidsmap.yaml文件并更改选项,以便在bids数据收集中获得非压缩nifti数据(即*.nii,而不是*.nii.gz)。您可以使用文本编辑器,或者更好地运行命令行工具。
  3. 竞价生成。通过运行bidscoiner命令行工具(请注意,输入与bidsmapper相同)将原始数据集合转换为竞价集合:

    bidscoiner.py raw bids
    
    • 检查bids/code/bidscoin/bidscoiner.logbids/code/bidscoin/bidscoiner.errors文件中的任何错误或警告
    • bids/sub-*主题文件夹中的结果与bids参考文件中的结果进行比较。文件名和文件夹名是否相同?还要检查fieldmaps的json sidecar文件。他们有正确的"回声时间"和"意图"字段吗?
    • 如果重新运行bidscoiner.py命令会发生什么?同样的问题又被处理了吗?重新运行"Sub-001"。
    • 检查bids/particients.tsv文件并确定是否正常。
    • 更新dataset_description.jsonreadme文件夹中的文件
    • 最后一步,在~/bids\u教程文件夹中运行投标验证程序。您现在完全准备好共享此数据集了吗?

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java打印元素按ArrayList<String>   java重新启动JSON输出   使用EOL版本Java时存在安全漏洞   java搜索并在vector中列出项目   Java与串口通信   java如何使用keytool运行测试并检查JCE是否缺失或存在?   java如何更改Json格式?   java停止缩放JPanel的背景图像   java递归方法不返回任何内容   facebook sdk中的java UiLifecycleHelper类   java将jfree条形图添加到滚动窗格中   java如何使用ApacheTiles和SpringMVC加载部分页面   javascript如何从安卓 webview读取httpbody?   java@OneToMany映射会自动删除映射的键