Skip to content

Commit 24c667a

Browse files
authored
Merge pull request #26 from poldracklab/enh/revise-workflow
ENH: Setup a smoke test on CircleCI + minor improvements to CLI
2 parents cdf5276 + 363a84c commit 24c667a

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

.circleci/config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ jobs:
118118
paths:
119119
- /tmp/docker
120120

121+
- restore_cache:
122+
keys:
123+
- templateflow-v1-{{ .Branch }}-{{ epoch }}
124+
- templateflow-v1-{{ .Branch }}-
125+
- templateflow-v1-master-
126+
- templateflow-v1-
127+
paths:
128+
- /tmp/templateflow
129+
- run:
130+
name: Run on example dataset
131+
no_output_timeout: 60m
132+
command: |
133+
mkdir -p /tmp/templateflow /tmp/workdir
134+
docker run -u $( id -u ) --rm -it -v /tmp/templateflow:/home/nirodents/.cache/templateflow \
135+
-v $PWD/nirodents/data:/data -v /tmp/workdir:/work -w /work nirodents:latest \
136+
artsBrainExtraction /data/15_1_T2_Quick_RAS.nii.gz --sloppy
137+
- save_cache:
138+
key: templateflow-v1-{{ .Branch }}-{{ epoch }}
139+
paths:
140+
- /tmp/templateflow
141+
- store_artifacts:
142+
path: /tmp/workdir
143+
destination: interim
121144
workflows:
122145
version: 2
123146
build_test_deploy:

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.circleci/
2+
.maint/
3+
docs/
4+
.gitignore
5+
.mailmap
6+
.travis.yml

nirodents/cli/brainextraction.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,40 @@ def get_parser():
1414
ANTs-based Rodents ToolS (ARTs) package.\
1515
""", formatter_class=ArgumentDefaultsHelpFormatter)
1616

17+
parser.add_argument("input_image", action="store", type=Path,
18+
help="The target image for brain extraction.")
1719
parser.add_argument("--version", action="version",
1820
version="artsBrainExtraction v{}".format(__version__))
19-
parser.add_argument("-i", "--input-image", action="store", type=Path,
20-
help="The target image for brain extraction.")
2121
parser.add_argument("--template", action="store", choices=("WHS", ), default="WHS",
2222
help="The TemplateFlow ID of the reference template.")
2323
parser.add_argument("--omp-nthreads", action="store", type=int, default=cpu_count(),
2424
help="Number of CPUs available for multithreading processes.")
2525
parser.add_argument("--nprocs", action="store", type=int, default=cpu_count(),
2626
help="Number of processes that can be run in parallel.")
27-
parser.add_argument("--debug", action="store", type=int, default=0, choices=[0,1],
28-
help="Boolean to run debug mode.")
27+
parser.add_argument(
28+
"-m",
29+
"--mri-scheme",
30+
action="store",
31+
type=str,
32+
default="T2w",
33+
choices=("T2w", "T1w"),
34+
help="select a particular MRI scheme"
35+
)
36+
parser.add_argument(
37+
"-w",
38+
"--work-dir",
39+
action="store",
40+
type=Path,
41+
default=Path("work").absolute(),
42+
help="path where intermediate results should be stored",
43+
)
44+
parser.add_argument(
45+
"--sloppy",
46+
dest="debug",
47+
action="store_true",
48+
default=False,
49+
help="Use low-quality tools for speed - TESTING ONLY",
50+
)
2951
return parser
3052

3153

@@ -36,17 +58,20 @@ def main():
3658
opts = get_parser().parse_args()
3759
be = init_rodent_brain_extraction_wf(
3860
in_template=opts.template,
61+
bids_suffix=opts.mri_scheme,
3962
omp_nthreads=opts.omp_nthreads,
40-
debug=opts.debug
63+
debug=opts.debug,
4164
)
65+
be.base_dir = opts.work_dir
4266
be.inputs.inputnode.in_files = opts.input_image
4367
nipype_plugin = {"plugin": "Linear"}
4468
if opts.nprocs > 1:
4569
nipype_plugin["plugin"] = "MultiProc"
4670
nipype_plugin["plugin_args"] = {
4771
"nproc": opts.nprocs,
72+
"raise_insufficient": False,
73+
"maxtasksperchild": 1,
4874
}
49-
print('input image: ', opts.input_image)
5075
be.run(**nipype_plugin)
5176

5277

nirodents/workflows/brainextraction.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ def init_rodent_brain_extraction_wf(
3737
final_normalization_quality='precise',
3838
in_template='WHS',
3939
init_normalization_quality='3stage',
40-
modality='T2w',
4140
mem_gb=3.0,
4241
name='rodent_brain_extraction_wf',
4342
omp_nthreads=None,
44-
tpl_suffix='T2star',
4543
template_spec=None,
4644
use_float=True,
4745
):
@@ -63,7 +61,7 @@ def init_rodent_brain_extraction_wf(
6361
name='inputnode')
6462

6563
# Find images in templateFlow
66-
tpl_target_path = get_template(in_template, resolution=debug + 1, suffix=tpl_suffix)
64+
tpl_target_path = get_template(in_template, resolution=debug + 1, suffix="T2star" if bids_suffix == "T2w" else "T1w")
6765
tpl_regmask_path = get_template(in_template, resolution=debug + 1, atlas='v3', desc='brain', suffix='mask')
6866
if tpl_regmask_path:
6967
inputnode.inputs.in_mask = str(tpl_regmask_path)
@@ -125,7 +123,7 @@ def init_rodent_brain_extraction_wf(
125123
interpolation='Linear', invert_transform_flags=True), name='warp_mask')
126124

127125
# Set up initial spatial normalization
128-
init_settings_file = f'data/brainextraction_{init_normalization_quality}_{modality}.json'
126+
init_settings_file = f'data/brainextraction_{init_normalization_quality}_{bids_suffix}.json'
129127
init_norm = pe.Node(Registration(from_file=pkgr_fn(
130128
'nirodents', init_settings_file)),
131129
name='init_norm',
@@ -161,7 +159,7 @@ def init_rodent_brain_extraction_wf(
161159
skullstrip_tpl.inputs.in_file = tpl_target_path
162160

163161
# Normalise skull-stripped image to brain template
164-
final_settings_file = f'data/brainextraction_{final_normalization_quality}_{modality}.json'
162+
final_settings_file = f'data/brainextraction_{final_normalization_quality}_{bids_suffix}.json'
165163
final_norm = pe.Node(Registration(from_file=pkgr_fn(
166164
'nirodents', final_settings_file)),
167165
name='final_norm',
@@ -192,7 +190,7 @@ def init_rodent_brain_extraction_wf(
192190

193191
sinker = pe.Node(DataSink(), name='sinker')
194192

195-
if modality.lower() == 't2w':
193+
if bids_suffix.lower() == 't2w':
196194
wf.connect([
197195
# resampling, truncation, initial N4, and creation of laplacian
198196
(inputnode, trunc, [('in_files', 'op1')]),
@@ -271,7 +269,7 @@ def init_rodent_brain_extraction_wf(
271269
])
272270
return wf
273271

274-
elif modality == 'mp2rage':
272+
elif bids_suffix == 't1w':
275273
wf.connect([
276274
# resampling and creation of laplacians
277275
(inputnode, res_target, [('in_files', 'in_file')]),

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ install_requires =
2323
attrs
2424
nibabel >= 3.0.1
2525
nipype @ git+https://github.com/nipy/nipype.git@master
26-
niworkflows @ git+https://github.com/oesteban/niworkflows.git@6d2286268d09215045161e534d0bf84dc34f38fc
26+
niworkflows @ git+https://github.com/oesteban/niworkflows.git@0f7e42971cf119925b72042db607c9be3f19144a
2727
templateflow ~= 0.6
2828
test_requires =
2929
coverage < 5

0 commit comments

Comments
 (0)