Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrosss committed Sep 6, 2021
0 parents commit 9802975
Show file tree
Hide file tree
Showing 11 changed files with 1,205 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[bumpversion]
current_version = 1.0.0
commit = True
tag = True
tag_name = {new_version}

[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:src/d2b_dcm2niix.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
min_python_version = 3.8.1
40 changes: 40 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Code Style

on: [push, pull_request]

jobs:
build:
name: "Lint Code Base"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry==1.1.8
BLACK_VERSION=$(poetry show black | grep version | rev | cut -d " " -f 1 | rev)
FLAKE8_VERSION=$(poetry show flake8 | grep version | rev | cut -d " " -f 1 | rev)
pip install "black==${BLACK_VERSION}" "flake8==${FLAKE8_VERSION}"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --max-complexity=10 --max-line-length=88 --statistics
- name: Check with black
run: |
black . --check --diff
- name: Run GitHub super-linter
uses: docker://github/super-linter:v3
env:
VALIDATE_ALL_CODEBASE: true
VALIDATE_YAML: true
VALIDATE_JSON: true
VALIDATE_MD: true
VALIDATE_BASH: true
VALIDATE_DOCKER: true
VALIDATE_GO: true
VALIDATE_ENV: true
26 changes: 26 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish to PyPI

on:
release:
types:
- created

jobs:
wheels:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry==1.1.8
- name: Build and Publish
run: |
poetry config pypi-token.pypi "$PYPI_TOKEN"
poetry publish --build
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/type-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Type Check

on: [push, pull_request]

jobs:
build:
name: "Type Check Code Base"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Set up Python 3.8"
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: "Install Dependencies"
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install --no-interaction --no-dev
- name: "Set up Node.js"
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: "Install Pyright"
run: |
npm install -g pyright
- name: "Type Check with Pyright"
run: |
pyright src
147 changes: 147 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
tmp*


# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# End of https://www.toptal.com/developers/gitignore/api/python
57 changes: 57 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
default_language_version:
python: python3.8
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-docstring-first
- id: check-json
- id: check-toml
- id: check-vcs-permalinks
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: 21.5b2
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: ["flake8-typing-imports==1.10.1"]
args:
- "--max-complexity=10"
- "--max-line-length=88"
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.5.0
hooks:
- id: reorder-python-imports
args: [--py3-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.19.0
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.8.0
hooks:
- id: python-check-blanket-noqa
- id: python-use-type-annotations
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.812
# hooks:
# - id: mypy
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# d2b-dcm2niix

Dcm2niix plugin for the d2b package

[![PyPI Version](https://img.shields.io/pypi/v/d2b-dcm2niix.svg)](https://pypi.org/project/d2b-dcm2niix/)

## Installation

```bash
pip install d2b-dcm2niix
```

## Usage

After installation the `d2b run` command should have additional `dcm2niix`-specific flags:

```text
$ d2b run --help
usage: d2b run [-h] -c CONFIG_FILE -p PARTICIPANT -o OUT_DIR [-s SESSION] [-l {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--no-dcm2niix | --dcm2niix | --force-dcm2niix] in_dir [in_dir ...]
Organize data in the BIDS format
positional arguments:
in_dir Directory(ies) containing files to organize
required arguments:
-c CONFIG_FILE, --config CONFIG_FILE
JSON configuration file (see example/config.json)
-p PARTICIPANT, --participant PARTICIPANT
Participant ID
-o OUT_DIR, --out-dir OUT_DIR
Output BIDS directory
--no-dcm2niix Don't run dcm2niix on the input directories. (This is the default)
--dcm2niix Run dcm2niix on each of the input directories before organization code executes. dcm2niix execution will be skipped for directories for which converted results from a previous run are found.
--force-dcm2niix Run dcm2niix on each of the input directories before organization code executes. Previous dcm2niix results will be overwritten
optional arguments:
-s SESSION, --session SESSION
Session ID
-l {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
Set logging level
```

Specifically, the following new (mutually exclusive) options are available:

- `--no-dcm2niix`: This is the default behaviour (i.e. the behaviour of the `d2b run` command if none of the dcm2niix flags are set)

- `--dcm2niix`: This will try to run `dcm2niix` on (copies of) each of the input directories prior to proceeding with BIDS-ification. **NOTE:** If any NIfTI files are found from a previous `d2b run --dcm2niix ...` run, then dcm2niix will not be invoked on that (copy of that) specific input directory.

- `--force-dcm2niix`: This will run `dcm2niix` on (copies of) each of the input directories _always_, regardless of files from previous `d2b run` runs.

Also, there should be a new subcommand `d2b dcm2niix` available:

```text
$ d2b dcm2niix --help
usage: d2b dcm2niix [-h] in_dir [in_dir ...] out_dir
Run dcm2niix with the options used by d2b
positional arguments:
in_dir DICOM directory(ies)
out_dir Output BIDS directory
optional arguments:
-h, --help show this help message and exit
```

This command is the equivalent of `dcm2bids`'s `dcm2bids_helper` command. In particular it's serves as a way to run dcm2niix in the exact same way that `d2b run --[force-]dcm2niix` would run the command (i.e. potentially useful to see what the resulting sidecars/filenames would look like).
Loading

0 comments on commit 9802975

Please sign in to comment.