Skip to content

Commit 3e02eca

Browse files
authored
Merge pull request #343 from cni-md/master
Reproin fix for Philips
2 parents d9f9864 + 9196e89 commit 3e02eca

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

heudiconv/heuristics/reproin.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
Sequence names on the scanner must follow this specification to avoid manual
2929
conversion/handling:
3030
31-
[PREFIX:]<seqtype[-label]>[_ses-<SESID>][_task-<TASKID>][_acq-<ACQLABEL>][_run-<RUNID>][_dir-<DIR>][<more BIDS>][__<custom>]
31+
[PREFIX:][WIP ]<seqtype[-label]>[_ses-<SESID>][_task-<TASKID>][_acq-<ACQLABEL>][_run-<RUNID>][_dir-<DIR>][<more BIDS>][__<custom>]
3232
3333
where
3434
[PREFIX:] - leading capital letters followed by : are stripped/ignored
35+
[WIP ] - prefix is stripped/ignored (added by Philips for patch sequences)
3536
<...> - value to be entered
3637
[...] - optional -- might be nearly mandatory for some modalities (e.g.,
3738
run for functional) and very optional for others
@@ -104,6 +105,16 @@
104105
105106
Although we still support "-" and "+" used within SESID and TASKID, their use is
106107
not recommended, thus not listed here
108+
109+
## Scanner specifics
110+
111+
We perform following actions regardless of the type of scanner, but applied
112+
generally to accommodate limitations imposed by different manufacturers/models:
113+
114+
### Philips
115+
116+
- We replace all ( with { and ) with } to be able e.g. to specify session {date}
117+
- "WIP " prefix unconditionally added by the scanner is stripped
107118
"""
108119

109120
import os
@@ -426,16 +437,15 @@ def ls(study_session, seqinfo):
426437
# So we just need subdir and file_suffix!
427438
def infotodict(seqinfo):
428439
"""Heuristic evaluator for determining which runs belong where
429-
430-
allowed template fields - follow python string module:
431-
440+
441+
allowed template fields - follow python string module:
442+
432443
item: index within category
433444
subject: participant id
434445
seqitem: run number during scanning
435446
subindex: sub index within group
436447
session: scan index for longitudinal acq
437448
"""
438-
439449
seqinfo = fix_seqinfo(seqinfo)
440450
lgr.info("Processing %d seqinfo entries", len(seqinfo))
441451
and_dicom = ('dicom', 'nii.gz')
@@ -841,6 +851,7 @@ def parse_series_spec(series_spec):
841851
# https://github.com/ReproNim/reproin/issues/14
842852
# where PU: prefix is added by the scanner
843853
series_spec = re.sub("^[A-Z]*:", "", series_spec)
854+
series_spec = re.sub("^WIP ", "", series_spec) # remove Philips WIP prefix
844855

845856
# Remove possible suffix we don't care about after __
846857
series_spec = series_spec.split('__', 1)[0]
@@ -888,7 +899,9 @@ def split2(s):
888899

889900
# sanitize values, which must not have _ and - is undesirable ATM as well
890901
# TODO: BIDSv2.0 -- allows "-" so replace with it instead
891-
value = str(value).replace('_', 'X').replace('-', 'X')
902+
value = str(value) \
903+
.replace('_', 'X').replace('-', 'X') \
904+
.replace('(', '{').replace(')', '}') # for Philips
892905

893906
if key in ['ses', 'run', 'task', 'acq']:
894907
# those we care about explicitly

heudiconv/heuristics/test_reproin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def test_parse_series_spec():
166166
assert \
167167
pdpn(" PREFIX:bids_func_ses+_task-boo_run+ ") == \
168168
pdpn("PREFIX:bids_func_ses+_task-boo_run+") == \
169+
pdpn("WIP func_ses+_task-boo_run+") == \
169170
pdpn("bids_func_ses+_run+_task-boo") == \
170171
{
171172
'seqtype': 'func',
@@ -202,3 +203,9 @@ def test_parse_series_spec():
202203
'acq': 'MPRAGE',
203204
'seqtype_label': 'T1w'
204205
}
206+
207+
# Check for currently used {date}, which should also should get adjusted
208+
# from (date) since Philips does not allow for {}
209+
assert pdpn("func_ses-{date}") == \
210+
pdpn("func_ses-(date)") == \
211+
{'seqtype': 'func', 'session': '{date}'}

0 commit comments

Comments
 (0)