Skip to content

Commit

Permalink
Merge pull request #219 from oesteban/enh/RefactorAnatomical
Browse files Browse the repository at this point in the history
[ENH] Large refactoring of anatomical workflow
  • Loading branch information
oesteban committed Oct 20, 2016
2 parents ec5b88a + 5807c2c commit cf8aa39
Show file tree
Hide file tree
Showing 18 changed files with 1,015 additions and 186 deletions.
12 changes: 12 additions & 0 deletions .pylintrc
@@ -1,2 +1,14 @@
[pre-commit-hook]
limit=8.1


[MESSAGES CONTROL]
# Disable the following PyLint messages:
# W0621: Redefining name %r from outer scope (line %s)
# W0622: Redefining built-in %r
disable-msg=W0621,W0622


[FORMAT]
# Maximum number of characters on a single line.
max-line-length=99
6 changes: 3 additions & 3 deletions circle.yml
Expand Up @@ -20,9 +20,9 @@ dependencies:
# Create scratch folder and force group permissions
- mkdir -p $SCRATCH && sudo setfacl -d -m group:ubuntu:rwx $SCRATCH && sudo setfacl -m group:ubuntu:rwx $SCRATCH
- if [[ ! -d ~/data/ds003_downsampled ]]; then wget --retry-connrefused --waitretry=5 --read-timeout=20 --timeout=15 -t 0 -q -O ds003_downsampled.tar.gz "${DS003_URL}" && tar xzf ds003_downsampled.tar.gz -C ~/data/; fi
- pip install "niworkflows>=0.0.3a11"
- pip install "niworkflows>=0.0.3a14"
override:
- python -c "from niworkflows import data as nwd; nwd.get_mni_template(); nwd.get_ds003_downsampled(); nwd.get_brainweb_1mm_normal()"
- python -c "from niworkflows import data as nwd; nwd.get_mni_icbm152_nlin_asym_09c(); nwd.get_ds003_downsampled(); nwd.get_brainweb_1mm_normal()"
- if [[ -e ~/docker/image.tar ]]; then docker load -i ~/docker/image.tar; fi
- docker build -f docker/Dockerfile_py35 -t mriqc:py35 .
- docker build -f docker/Dockerfile_py27 -t mriqc:py27 .
Expand All @@ -35,7 +35,7 @@ test:
timeout: 2600
- docker run -i -v /etc/localtime:/etc/localtime:ro -v ~/.cache/stanford-crn:/root/.cache/stanford-crn -v ~/data:/data:ro -v $SCRATCH/func:/scratch -w /scratch mriqc:py35 /data/ds003_downsampled out/ participant -d func -w work/ --nthreads ${FUNC_NPROCS} --testing
- docker run -i -v /etc/localtime:/etc/localtime:ro -v ~/data:/data:ro -v $SCRATCH/func:/scratch -w /scratch mriqc:py35 /data/ds003_downsampled out/ group -d func -w work/
- docker run -i -v /etc/localtime:/etc/localtime:ro -v ~/.cache/stanford-crn:/root/.cache/stanford-crn -v ~/data:/data:ro -v $SCRATCH/anat:/scratch -w /scratch mriqc:py35 /data/ds003_downsampled out/ participant -d anat -w work/ --nthreads ${ANAT_NPROCS} --testing --ants-nthreads ${ANTS_NTHREADS}:
- docker run -i -v /etc/localtime:/etc/localtime:ro -v ~/.cache/stanford-crn:/root/.cache/stanford-crn -v ~/data:/data:ro -v $SCRATCH/anat:/scratch -w /scratch mriqc:py35 /data/ds003_downsampled out/ participant -d anat -w work/ --nthreads ${ANAT_NPROCS} --testing --ants-nthreads ${ANTS_NTHREADS} --verbose-reports :
timeout: 2600
- docker run -i -v /etc/localtime:/etc/localtime:ro -v ~/data:/data:ro -v $SCRATCH/anat:/scratch -w /scratch mriqc:py27 /data/ds003_downsampled out/ group -d anat -w work/

Expand Down
7 changes: 7 additions & 0 deletions mriqc/data/__init__.py
@@ -0,0 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
from __future__ import absolute_import, division, print_function, unicode_literals

from .config import Template, IndividualTemplate
42 changes: 42 additions & 0 deletions mriqc/data/config.py
@@ -0,0 +1,42 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Utilities: Jinja2 templates
"""
from __future__ import absolute_import, division, print_function, unicode_literals

from io import open # pylint: disable=W0622
import jinja2
from pkg_resources import resource_filename as pkgrf


class Template(object):
"""
Utility class for generating a config file from a jinja template.
https://github.com/oesteban/endofday/blob/f2e79c625d648ef45b08cc1f11fd0bd84342d604/endofday/core/template.py
"""
def __init__(self, template_str):
self.template_str = template_str
self.env = jinja2.Environment(
loader=jinja2.FileSystemLoader(searchpath='/'),
trim_blocks=True, lstrip_blocks=True)

def compile(self, configs):
"""Generates a string with the replacements"""
template = self.env.get_template(self.template_str)
return template.render(configs)

def generate_conf(self, configs, path):
"""Saves the oucome after replacement on the template to file"""
output = self.compile(configs)
with open(path, 'w+') as output_file:
output_file.write(output)


class IndividualTemplate(Template):
"""Specific template for the individual report"""

def __init__(self):
super(IndividualTemplate, self).__init__(pkgrf('mriqc', 'data/reports/individual.html'))

0 comments on commit cf8aa39

Please sign in to comment.