Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
Major update
Browse files Browse the repository at this point in the history
  • Loading branch information
lukassnoek committed Mar 19, 2018
1 parent cd4d2ac commit 347d547
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 246 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,4 @@ ENV/
OLD/
.DS_Store

bidsconverter/data/PIOP2
bidsconverter/data/Upgrade
bidsify/data/test_data
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deploy:
secure: U8Bfe8mXUSp5HYzGsyJfLuVzu+uEt6hid6AQb+HafJMHhhmoiX4cL8IH1xYaT/ZDXR02IO5bpQpjLLvKizDCXrfEgM/YTWhi1lldVh8O6cdP0gBeNfYNQz0qmbWhJFGzN+ad4VXBXrCVIPtF88mmowzRr6P0vLHW8GudSPInJKl6ofUwJDkOOFL6tqAiSLTIlwQQtvKTMqxCAQ3U+kliznpbbjFJSCjf29IQ/tUqzflbKmVdpr5nXCwVONNnydnY8fFK9Vrhl2UchFKjE5KbfoYxFs9udhlgxZMoKSDmTcvhhjwZ7HN8WPABxvY+IvrDi+CUjFDKBKZhSan0fQBfc8aMN0YVE2/TtEJXwsA9g4c3/BkcoF532mc7e2dzExQwOh/xS/iLPhn0qtf+VQn7po7iXwSMbpPIqEOYbgpaWXzgo0Pf5O5Q0pKzuXpcN4femZ1hEtTZ9f13LHuyjLPN9GAZjQmdUGbIkPFY/bbu6ssbkcgKZTABODln68LOnLDQGqpog5bYQ9Myr5mLhF3duLjnoZIcuReyQ7Ed8Z7bcNeiu7t4PAWbgm2DJ3VrUkzq24iUvGedwh3Eqr4eQnedrk2Bn3+rqVv00FjX9elmR7S3TJ4l4jPkfg8R48tDan6wGqhu3s2S97MSmgi+/gWDAEpTBHaHc5DuZ4TcJXTb3To=
on:
tags: true
repo: lukassnoek/BidsConverter
repo: spinoza-rec/bidsify

env:
global:
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ CHANGELOG

Version 0.3.0 (upcoming)
-------------
Version 0.3.0 of BidsConverter will be the first release after the major refactor.
Version 0.3.0 of bidsify will be the first release after the major refactor.
It contains the following (major) changes:

- ENH: accepts both json and yaml config files
- ENH: major refactoring of package structure (now based on `shablona <https://github.com/uwescience/shablona>`_)
- ENH: writes out a (default) dataset_description.json and participants.tsv file
- ENH: option to run BidsConverter in a docker image!
- ENH: option to run ``bidsify`` in a docker image!

Versions < 0.3.0
----------------
Expand Down
39 changes: 20 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
BidsConverter - converts your (raw) data to the BIDS-format
``bidsify``bidsify - converts your (raw) data to the BIDS-format
=============================================================
.. _BIDS: http://bids.neuroimaging.io/
.. _here: http://www.jsoneditoronline.org/?id=f175c0dc8f147229da869000d52af71c
.. image:: https://coveralls.io/repos/github/lukassnoek/BidsConverter/badge.svg?branch=refactor
:target: https://coveralls.io/github/lukassnoek/BidsConverter?branch=refactor
.. image:: https://coveralls.io/repos/github/lukassnoek/bidsify/badge.svg?branch=refactor
:target: https://coveralls.io/github/lukassnoek/bidsify?branch=refactor
.. image:: https://travis-ci.org/lukassnoek/BidsConverter.svg?branch=refactor
:target: https://travis-ci.org/lukassnoek/BidsConverter
.. image:: https://travis-ci.org/lukassnoek/bidsify.svg?branch=refactor
:target: https://travis-ci.org/lukassnoek/bidsify
.. image:: https://ci.appveyor.com/api/projects/status/g3y6ds5d0f2fhxer/branch/refactor?svg=true
:target: https://ci.appveyor.com/project/lukassnoek/bidsconverter
:target: https://ci.appveyor.com/project/lukassnoek/bidsify
.. image:: https://img.shields.io/badge/python-2.7-blue.svg
:target: https://www.python.org/download/releases/2.7
Expand All @@ -26,14 +26,14 @@ your files such that it fits the BIDS naming scheme and conforms
to file-formats specified by BIDS. This tool has been used to
successfully convert datasets for preprocessing using `fmriprep <http://fmriprep.readthedocs.io/en/latest/>`_.
BidsConverter is still very much in development, so there are probably still some bugs for data
``Bidsify`` is still very much in development, so there are probably still some bugs for data
that differs from our standard format (at the Spinoza Centre in Amsterdam) and the API might change
in the future. If you encounter any issues, please submit an issue or (better yet), submit a pull-request
with your proposed solution!

Features
--------
So far, BidsConverter is able to do the following:
So far, ``bidsify`` is able to do the following:

- Rename raw files to the format specified by BIDS (using the information in the config.json)
- Convert raw Philips PAR/REC files and DICOM files (experimental; not fully tested) to nifti.gz format
Expand All @@ -52,7 +52,7 @@ It does not support (yet):

The config.json file
--------------------
The BidsConverter only needs a ``config.json`` file, which contains
``bidsify`` only needs a ``config.json`` file, which contains
information that is used to rename and convert the raw files. An
example of a complete ``config.json`` file can be found here_.

Expand All @@ -74,6 +74,7 @@ is the `"options"` section. An example of this section could be:
"subject_stem": "sub",
"out_dir": "bids_converted",
"spinoza_data": 0
}
}
No options *need* to be set explicitly as they all have sensible defaults.
Expand All @@ -92,8 +93,8 @@ Note: when the `"spinoza_data"` attribute is set to 1 (True), some default metad
~~~~~~~~~~
The BIDS-format specifies the naming and format of several types of MRI(-related) filetypes.
These filetypes have specific suffixes, which are appended to the filenames in the renaming
process handled by the BidsConverter. The `"mappings"` section in the config is meant to
tell the BidsConverter what filetype can be identified by which "key". Thus, the mappings
process handled by ``bidsify``. The `"mappings"` section in the config is meant to
tell ``bidsify`` what filetype can be identified by which "key". Thus, the mappings
section consists of `"filetype": "identifier"` pairs. Basically, if BIDS requires a
specific suffix for a filetype, you need to specify that here. For example, a standard
dataset with several BOLD-fMRI files, a T1, and physiological recordings could have
Expand Down Expand Up @@ -247,7 +248,7 @@ The config-file should, in that case, look like:
}
The BidsConverter will then create four files (assuming that they can be "found" using their corresponding "ids"):
``bidsify`` will then create four files (assuming that they can be "found" using their corresponding "ids"):

- ``sub-001_task-nback_run-1_acq-sequential_bold.nii.gz``
- ``sub-001_task-nback_run-2_acq-sequential_bold.nii.gz``
Expand Down Expand Up @@ -334,9 +335,9 @@ datatype section. For example, to do so for the previous examples:
}
Usage of BidsConverter
Usage of ``bidsify``
----------------------
After installing the BidsConverter (see next section), the command ``convert2bids``
After installing ``bidsify`` (see next section), the command ``bidsify``
should be available in your terminal. It takes two (named) arguments:

- -d ("directory"): path to the directory with the raw data that you want to convert
Expand All @@ -346,7 +347,7 @@ If no arguments are given, the "directory" is assumed to be the current working
and the config-file is assumed to be named "config.json" and to be located in the current
working directory.

Importantly, BidsConverter assumes that the directory with raw data is organized as follows
Importantly, ``bidsify`` assumes that the directory with raw data is organized as follows
(for the simple case of one BOLD run and one T1):

- sub-01
Expand Down Expand Up @@ -386,22 +387,22 @@ a session-directory. **Note**: the session directory **must** be named "ses-<som
Also, instead of separate \*.PAR and \*.REC files, you can also have a single or multiple DICOM
files instead. (DICOM conversion has, however, not been thoroughly tested ...)

Installing BidsConverter & dependencies
Installing ``bidsify`` & dependencies
---------------------------------------
For now, it can only be installed from Github (no PyPI package yet), either by cloning
this repository directory (and then ``python setup.py install``) or installing it using ``pip``::

$ pip install git+https://github.com/lukassnoek/BidsConverter.git@master
$ pip install git+https://github.com/spinoza-rec/bidsify.git@master

In terms of dependencies: BidsConverter currently only works with the
In terms of dependencies: ``bidsify`` currently only works with the
`dcm2niix <https://github.com/rordenlab/dcm2niix>`_ conversion-software, which
can be installed on Linux-systems using neurodebian::

$ sudo apt install dcm2niix

For other platforms (Mac, Windows), check out the dcm2niix `Github page <https://github.com/rordenlab/dcm2niix/releases>`_.

Apart from dcm2niix, BidsConverter depends on the following Python packages:
Apart from dcm2niix, ``bidsify`` depends on the following Python packages:

- nibabel
- scipy
Expand Down
15 changes: 2 additions & 13 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build: false

clone_folder: c:\projects\BidsConverter
clone_folder: c:\projects\bidsify

environment:
matrix:
Expand All @@ -21,20 +21,9 @@ install:
- git clone https://github.com/rordenlab/dcm2niix c:\projects\dcm2niix
- mkdir c:\projects\dcm2niix\build
- cd c:\projects\dcm2niix\build
#- mkdir build && cd build
#- copy c:\projects\dcm2niix\CMakeLists.txt c:\projects\dcm2niix\build\CMakeLists.txt
#- mkdir c:\projects\dcm2niix\build\SuperBuild
#- xcopy c:\projects\dcm2niix\SuperBuild c:\projects\dcm2niix\build\SuperBuild
- cmake -G "Visual Studio 14 2015 Win64" -DBATCH_VERSION=ON -DUSE_OPENJPEG=ON ..\
- MSBuild c:\projects\dcm2niix\build\dcm2niix.sln
#- copy c:\MinGW\bin\mingw32-make.exe c:\MinGW\bin\make.exe
#- set PATH=C:\MinGW\bin;%PATH%
#- make
- set PATH=c:\projects\dcm2niix\build\bin;%PATH%
#- ps: Install-Product node $env:nodejs_version
#- set CI=true
#- npm install --global npm@latest
#- set PATH=%APPDATA%\npm;%PATH%
- npm install -g bids-validator
- cd c:\projects\BidsConverter
- "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%"
Expand All @@ -49,4 +38,4 @@ install:
test_script:
- mkdir for_test
- cd for_test
- py.test --pyargs bidsconverter --cov-report term-missing --cov=bidsconverter
- py.test --pyargs bidsify --cov-report term-missing --cov=bidsify
2 changes: 1 addition & 1 deletion bidsconverter/__init__.py → bidsify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from __future__ import absolute_import, division, print_function
from .bidsconverter import * # noqa
from .main import * # noqa
File renamed without changes.
17 changes: 17 additions & 0 deletions bidsify/data/default_spinoza_cfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
options:
mri_ext: PAR
debug: False
log_type: ''
n_cores: 1
subject_stem: sub
deface: True
spinoza_data: True

mappings:
bold: _bold
T1w: _T1w
dwi: _dwi
physio: _physio
events: _events
B0: _B0
epi: _epi
File renamed without changes.
File renamed without changes.
31 changes: 13 additions & 18 deletions bidsconverter/bidsconverter.py → bidsify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import warnings
import yaml
import logging
import warnings
import pandas as pd
from copy import copy, deepcopy
from glob import glob
Expand All @@ -19,8 +20,8 @@
_run_cmd)
from .version import __version__

__all__ = ['main', 'bidsify']

__all__ = ['run_cmd', 'bidsify']

DTYPES = ['func', 'anat', 'fmap', 'dwi']
MTYPE_ORDERS = dict(
Expand Down Expand Up @@ -48,8 +49,8 @@
ALLOWED_EXTS.extend([s.upper() for s in ALLOWED_EXTS])


def main():
""" Calls the convert2bids function with cmd line arguments. """
def run_cmd():
""" Calls the bidsify function with cmd line arguments. """

DESC = ("This is a command line tool to convert "
"unstructured data-directories to a BIDS-compatible format")
Expand All @@ -69,7 +70,7 @@ def main():
parser.add_argument('-c', '--config_file',
help='Config-file with img. acq. parameters',
required=False,
default=op.join(os.getcwd(), 'config.json'))
default=op.join(os.getcwd(), 'config.yml'))

parser.add_argument('-v', '--validate',
help='Run bids-validator',
Expand Down Expand Up @@ -125,9 +126,9 @@ def bidsify(cfg, directory, validate):
if not check_executable('dcm2niix'):
msg = """The program 'dcm2niix' was not found on this computer;
install dcm2niix from neurodebian (Linux users) or download dcm2niix
from Github (link) and compile locally (Mac/Windows). BidsConverter
from Github (link) and compile locally (Mac/Windows); bidsify
needs dcm2niix to convert MRI-files to nifti!. Alternatively, use
the BidsConverter Docker image!"""
the bidsify Docker image!"""
print(msg)

if not check_executable('bids-validator') and validate:
Expand Down Expand Up @@ -172,7 +173,7 @@ def bidsify(cfg, directory, validate):


def _process_directory(cdir, out_dir, cfg, is_sess=False):
""" Main workhorse of BidsConverter """
""" Main workhorse of bidsify """

options = cfg['options']
mappings = cfg['mappings']
Expand Down Expand Up @@ -200,8 +201,7 @@ def _process_directory(cdir, out_dir, cfg, is_sess=False):
return None

already_exists = op.isdir(this_out_dir)

if already_exists and not options['overwrite']:
if already_exists:
print('%s already converted - skipping ...' % this_out_dir)
return

Expand Down Expand Up @@ -284,19 +284,14 @@ def _parse_cfg(cfg_file, raw_data_dir):
out_dir = cfg['options']['out_dir']
cfg['options']['out_dir'] = op.join(raw_data_dir, out_dir)

if 'overwrite' not in options:
cfg['options']['overwrite'] = False
else:
cfg['options']['overwrite'] = bool(cfg['options']['overwrite'])

if 'spinoza_data' not in options:
cfg['options']['spinoza_data'] = False

if 'deface' not in options:
cfg['options']['deface'] = False

if cfg['options']['deface'] and 'FSLDIR' not in os.environ.keys():
print("Cannot deface because FSL is not installed ...")
warnings.warn("Cannot deface because FSL is not installed ...")
cfg['options']['deface'] = False

if cfg['options']['deface']:
Expand All @@ -305,7 +300,7 @@ def _parse_cfg(cfg_file, raw_data_dir):
except ImportError:
msg = """To enable defacing, you need to install nipype (pip
install nipype) manually! Setting deface to False for now"""
print(msg)
warnings.warn(msg)
cfg['options']['deface'] = False

# Check which data_types are listed in the config file
Expand All @@ -330,8 +325,8 @@ def _parse_cfg(cfg_file, raw_data_dir):
# Now, extract and set metadata
metadata = dict()

# Always add bidsconverter version
metadata['toplevel'] = dict(BidsConverterVersion=__version__)
# Always add bidsify version
metadata['toplevel'] = dict(BidsifyVersion=__version__)

if 'metadata' in cfg.keys():
metadata['toplevel'].update(cfg['metadata'])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion bidsconverter/version.py → bidsify/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
MINOR = _version_minor
MICRO = _version_micro
VERSION = __version__
PACKAGE_DATA = {'bidsconverter': [op.join('data', '*')]}
PACKAGE_DATA = {'bidsify': [op.join('data', '*')]}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
numpy
nibabel
joblib
pybids
pandas
pyyaml
Loading

0 comments on commit 347d547

Please sign in to comment.