Skip to content

Commit f2df371

Browse files
authored
Merge pull request #109 from oesteban/enh/smriprep-fasttrack
ENH: Port the new *anatomical fast-track* from *fMRIPrep*
2 parents 634d89a + 347b40e commit f2df371

File tree

6 files changed

+49
-52
lines changed

6 files changed

+49
-52
lines changed

.circleci/config.yml

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ jobs:
126126
steps:
127127
- restore_cache:
128128
keys:
129-
- data-v2-{{ .Revision }}
130-
- data-v2-
129+
- data-thp-v1-{{ .Revision }}
130+
- data-thp-v1-
131131
- run:
132132
name: Get test data from THP002
133133
command: |
@@ -151,6 +151,14 @@ jobs:
151151
else
152152
echo "FreeSurfer derivatives of THP002 were cached"
153153
fi
154+
- save_cache:
155+
key: data-thp-v1-{{ .Revision }}-{{ epoch }}
156+
paths:
157+
- /tmp/data/THP002
158+
- restore_cache:
159+
keys:
160+
- data-ds001771-v1-{{ .Revision }}
161+
- data-ds001771-v1-
154162
- run:
155163
name: Get test data (ds001771)
156164
command: |
@@ -163,17 +171,20 @@ jobs:
163171
echo "Dataset ds001771_sub-36 was cached"
164172
fi
165173
- run:
166-
name: Get FreeSurfer derivatives for ds001771_sub-36
174+
name: Get anatomical derivatives for ds001771
167175
command: |
168-
if [[ ! -d /tmp/data/ds001771/derivatives/freesurfer-6.0.1 ]]; then
176+
if [[ ! -d /tmp/data/ds001771/derivatives ]]; then
169177
mkdir -p /tmp/data/ds001771/derivatives
170178
wget --retry-connrefused --waitretry=5 --read-timeout=20 --timeout=15 -t 0 -q \
171-
-O ds001771_sub-36_derivatives_freesurfer.tar.gz "https://files.osf.io/v1/resources/8k95s/providers/osfstorage/5e21e74fedceab00ad82e047"
172-
tar xvzf ds001771_sub-36_derivatives_freesurfer.tar.gz -C /tmp/data/ds001771/derivatives
173-
mv /tmp/data/ds001771/derivatives/freesurfer /tmp/data/ds001771/derivatives/freesurfer-6.0.1
179+
-O ds001771-derivs.tar.gz "https://files.osf.io/v1/resources/8k95s/providers/osfstorage/5eb251fba2199500215d1dc3"
180+
tar xvzf ds001771-derivs.tar.gz -C /tmp/data/ds001771/
174181
else
175-
echo "FreeSurfer derivatives of ds001771 were cached"
182+
echo "Anatomical derivatives of ds001771 were cached"
176183
fi
184+
- save_cache:
185+
key: data-ds001771-v1-{{ .Revision }}-{{ epoch }}
186+
paths:
187+
- /tmp/data/ds001771
177188
- run:
178189
name: Store FreeSurfer license file
179190
command: |
@@ -192,10 +203,6 @@ jobs:
192203
paths:
193204
- fslicense
194205
- config/nipype.cfg
195-
- save_cache:
196-
key: data-v2-{{ .Revision }}-{{ epoch }}
197-
paths:
198-
- /tmp/data
199206

200207
THP002:
201208
machine:
@@ -222,7 +229,7 @@ jobs:
222229
at: /tmp
223230
- restore_cache:
224231
keys:
225-
- data-v2-{{ .Revision }}
232+
- data-thp-v1-{{ .Revision }}
226233
- restore_cache:
227234
keys:
228235
- build-v1-{{ .Branch }}-{{ epoch }}
@@ -329,7 +336,7 @@ jobs:
329336
at: /tmp
330337
- restore_cache:
331338
keys:
332-
- data-v2-{{ .Revision }}
339+
- data-ds001771-v1-{{ .Revision }}
333340
- restore_cache:
334341
keys:
335342
- build-v1-{{ .Branch }}-{{ epoch }}
@@ -347,41 +354,11 @@ jobs:
347354
command: |
348355
docker pull localhost:5000/dmriprep
349356
docker tag localhost:5000/dmriprep nipreps/dmriprep:latest
350-
- restore_cache:
351-
keys:
352-
- ds001771-anat-v00-{{ .Branch }}-{{ .Revision }}
353-
- ds001771-anat-v00-{{ .Branch }}
354-
- ds001771-anat-v00-master
355-
- ds001771-anat-v00-
356-
- run:
357-
name: Run anatomical workflow on ds001771
358-
no_output_timeout: 2h
359-
command: |
360-
mkdir -p /tmp/ds001771/{work,derivatives}
361-
docker run -e FS_LICENSE=$FS_LICENSE --rm \
362-
-v /tmp/data/ds001771:/data \
363-
-v /tmp/ds001771/derivatives:/out \
364-
-v /tmp/fslicense/license.txt:/tmp/fslicense/license.txt:ro \
365-
-v /tmp/config/nipype.cfg:/home/dmriprep/.nipype/nipype.cfg \
366-
-v /tmp/ds001771/work:/work \
367-
--user $(id -u):$(id -g) \
368-
nipreps/dmriprep:latest /data /out participant -vv \
369-
--fs-subjects-dir /data/derivatives/freesurfer-6.0.1 --sloppy --anat-only \
370-
--notrack --skip-bids-validation -w /work --omp-nthreads 2 --nprocs 2
371-
- run:
372-
name: Clean-up after anatomical run
373-
command: |
374-
rm -rf /tmp/ds001771/work/dmriprep_wf/fsdir*
375-
rm -rf /tmp/ds001771/work/reportlets
376-
when: on_success
377-
- save_cache:
378-
key: ds001771-anat-v00-{{ .Branch }}-{{ .Revision }}-{{ epoch }}
379-
paths:
380-
- /tmp/ds001771/work
381357
- run:
382358
name: Run full diffusion workflow on ds001771
383359
no_output_timeout: 2h
384360
command: |
361+
mkdir -p /tmp/ds001771/work /tmp/ds001771/derivatives
385362
docker run -e FS_LICENSE=$FS_LICENSE --rm \
386363
-v /tmp/data/ds001771:/data \
387364
-v /tmp/ds001771/derivatives:/out \
@@ -390,8 +367,10 @@ jobs:
390367
-v /tmp/ds001771/work:/work \
391368
--user $(id -u):$(id -g) \
392369
nipreps/dmriprep:latest /data /out participant -vv \
393-
--fs-subjects-dir /data/derivatives/freesurfer-6.0.1 --sloppy \
394-
--notrack --skip-bids-validation -w /work --omp-nthreads 2 --nprocs 2
370+
-w /work --omp-nthreads 2 --nprocs 2 \
371+
--notrack --skip-bids-validation --sloppy \
372+
--fs-subjects-dir /data/derivatives/freesurfer-6.0.1 \
373+
--anat-derivatives /data/derivatives/smriprep-0.6.0
395374
- store_artifacts:
396375
path: /tmp/ds001771/derivatives/dmriprep
397376
- run:

dmriprep/cli/parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def _bids_filter(value):
114114
"{<suffix>:{<entity>:<filter>,...},...} "
115115
"(https://github.com/bids-standard/pybids/blob/master/bids/layout/config/bids.json)",
116116
)
117+
g_bids.add_argument(
118+
"--anat-derivatives", action='store', metavar="PATH", type=PathExists,
119+
help="Reuse the anatomical derivatives from another fMRIPrep run or calculated "
120+
"with an alternative processing tool (NOT RECOMMENDED)."
121+
)
117122

118123
g_perfm = parser.add_argument_group("Options to handle performance")
119124
g_perfm.add_argument(

dmriprep/cli/run.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ def main():
101101
config.loggers.workflow.log(
102102
25,
103103
"Works derived from this dMRIPrep execution should "
104-
"include the following boilerplate:\n\n%s",
105-
(
106-
config.execution.output_dir / "dmriprep" / "logs" / "CITATION.md"
107-
).read_text(),
104+
"include the following boilerplate: "
105+
f"{config.execution.output_dir / 'dmriprep' / 'logs' / 'CITATION.md'}."
108106
)
109107

110108
if config.workflow.run_reconall:

dmriprep/config/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ def init(cls):
324324
class execution(_Config):
325325
"""Configure run-level settings."""
326326

327+
anat_derivatives = None
328+
"""A path where anatomical derivatives are found to fast-track *sMRIPrep*."""
327329
bids_dir = None
328330
"""An existing path to the dataset, which must be BIDS-compliant."""
329331
bids_description_hash = None
@@ -371,6 +373,7 @@ class execution(_Config):
371373
_layout = None
372374

373375
_paths = (
376+
"anat_derivatives",
374377
"bids_dir",
375378
"fs_license_file",
376379
"fs_subjects_dir",

dmriprep/workflows/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,22 @@ def init_single_subject_wf(subject_id):
194194
desc="about", keep_dtype=True),
195195
name="ds_report_about", run_without_submitting=True)
196196

197+
anat_derivatives = config.execution.anat_derivatives
198+
if anat_derivatives:
199+
from smriprep.utils.bids import collect_derivatives
200+
std_spaces = spaces.get_spaces(nonstandard=False, dim=(3,))
201+
anat_derivatives = collect_derivatives(
202+
anat_derivatives.absolute(),
203+
subject_id,
204+
std_spaces,
205+
config.workflow.run_reconall,
206+
)
207+
197208
# Preprocessing of T1w (includes registration to MNI)
198209
anat_preproc_wf = init_anat_preproc_wf(
199210
bids_root=str(config.execution.bids_dir),
200211
debug=config.execution.debug is True,
212+
existing_derivatives=anat_derivatives,
201213
freesurfer=config.workflow.run_reconall,
202214
hires=config.workflow.hires,
203215
longitudinal=config.workflow.longitudinal,

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ install_requires =
2626
nipype ~= 1.4
2727
niworkflows >=1.2.0rc4,<1.3
2828
numpy
29-
pybids >=0.9.4
29+
pybids >=0.10.2
3030
pyyaml
3131
sdcflows >= 1.2.3
3232
smriprep >=0.6.0rc4,<0.7

0 commit comments

Comments
 (0)