Skip to content

Commit e651b4b

Browse files
committed
Allow users to set work-dir when using bidsmapper (GitHub issue #276)
1 parent ca101cc commit e651b4b

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

bidscoin/bidscoiner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from bidscoin.plugins import EventsParser
2626

2727

28-
def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force: bool=False, bidsmap: str= 'bidsmap.yaml', cluster: str= '') -> None:
28+
def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force: bool=False, bidsmap: str= 'bidsmap.yaml', cluster: str= '', workdir: str='') -> None:
2929
"""
3030
Main function that processes all the subjects and session in the sourcefolder and uses the
3131
bidsmap.yaml file in bidsfolder/code/bidscoin to cast the data into the BIDS folder.
@@ -36,7 +36,7 @@ def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force:
3636
:param force: If True, participant will be processed, regardless of existing folders in the bidsfolder. Otherwise, existing folders will be skipped
3737
:param bidsmap: The name of the bidsmap YAML-file. If the bidsmap pathname is just the base name (i.e. no "/" in the name) then it is assumed to be located in the current directory or in bidsfolder/code/bidscoin
3838
:param cluster: Use the DRMAA library to submit the bidscoiner jobs to a high-performance compute (HPC) cluster with DRMAA native specifications for submitting bidscoiner jobs to the HPC cluster. See cli/_bidscoiner() for default
39-
:return: Nothing
39+
:param workdir: Working directory for temporary unpacking of zipped or DICOMDIR data. Defaults to the system temporary folder if not specified
4040
"""
4141

4242
# Input checking & defaults
@@ -263,7 +263,7 @@ def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force:
263263
for session in sessions:
264264

265265
# Unpack the data in a temporary folder if it is tarballed/zipped and/or contains a DICOMDIR file
266-
sesfolders, unpacked = unpack(session, bidsmap.options.get('unzip',''))
266+
sesfolders, unpacked = unpack(session, bidsmap.options.get('unzip',''), workdir)
267267
for sesfolder in sesfolders:
268268

269269
# Run the bidscoiner plugins

bidscoin/bidsmapper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_, uptodate, versionmessage = check_version()
2525

2626

27-
def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str, plugins: list, subprefix: str, sesprefix: str, unzip: str, store: bool=False, automated: bool=False, force: bool=False, no_update: bool=False) -> BidsMap:
27+
def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str, plugins: list, subprefix: str, sesprefix: str, unzip: str, store: bool=False, automated: bool=False, force: bool=False, no_update: bool=False, workdir: str='') -> BidsMap:
2828
"""
2929
Main function that processes all the subjects and session in the sourcefolder and that generates a fully filled-in bidsmap.yaml
3030
file in bidsfolder/code/bidscoin. Folders in sourcefolder are assumed to contain a single dataset.
@@ -39,8 +39,9 @@ def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str,
3939
:param unzip: Wildcard pattern to select tar/zip-files in the session folder. Leave empty to use the bidsmap value
4040
:param store: If True, the provenance samples will be stored
4141
:param automated: The bidseditor will not be launched if True
42-
:param no_update: Do not update any sub-/ses-prefixes in or prepend the sourcefolder name to the <<filepath:regex>> expression
4342
:param force: If True, the previous bidsmap and logfiles will be deleted
43+
:param no_update: Do not update any sub-/ses-prefixes in or prepend the sourcefolder name to the <<filepath:regex>> expression
44+
:param workdir: Working directory for temporary unpacking of zipped or DICOMDIR data. Defaults to the system temporary folder if not specified
4445
:return: The new bidsmap
4546
"""
4647

@@ -118,7 +119,7 @@ def bidsmapper(sourcefolder: str, bidsfolder: str, bidsmap: str, template: str,
118119

119120
# Unpack the data in a temporary folder if it is tarballed/zipped and/or contains a DICOMDIR file
120121
LOGGER.info(f"Mapping: {session} (subject {n}/{len(subjects)})")
121-
sesfolders, unpacked = unpack(session, unzip)
122+
sesfolders, unpacked = unpack(session, unzip, workdir)
122123
for sesfolder in sesfolders:
123124
if store:
124125
bidsmap_new.store = {'source': sesfolder.parent.parent.parent.parent if unpacked else rawfolder.parent,

bidscoin/cli/_bidscoiner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ def get_parser():
3434
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is just the base name (i.e. no "/" in the name) then it is assumed to be located in the current directory or in bidsfolder/code/bidscoin. Default: bidsmap.yaml', metavar='NAME', default='bidsmap.yaml')
3535
parser.add_argument('-f','--force', help='Process all subjects, regardless of existing subject folders in the bidsfolder. Otherwise these subject folders will be skipped', action='store_true')
3636
parser.add_argument('-c','--cluster', help='Use the DRMAA library to submit the bidscoiner jobs to a high-performance compute (HPC) cluster. You can add an opaque DRMAA argument with native specifications for your HPC resource manager (NB: Use quotes and include at least one space character to prevent premature parsing -- see examples)', metavar='SPECS', nargs='?', const='-l walltime=00:30:00,mem=4gb', type=str)
37+
parser.add_argument('-w','--workdir', help='Optional working directory for temporary unpacking of zipped or DICOMDIR data. Defaults to the system temporary folder if not specified', default='')
3738

3839
return parser

bidscoin/cli/_bidsmapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def get_parser() -> argparse.ArgumentParser:
4444
parser.add_argument('-s','--store', help='Store newly discovered data samples in the bidsfolder/code/provenance folder (useful for editing e.g. zipped or DICOMDIR datasets)', action='store_true')
4545
parser.add_argument('-a','--automated', help='Save the automatically generated bidsmap to disk and without interactively tweaking it with the bidseditor', action='store_true')
4646
parser.add_argument('-f','--force', help='Discard the previously saved bidsmap and log file, instead of reusing them (use this option for a fresh start)', action='store_true')
47+
parser.add_argument('-w','--workdir', help='Optional working directory for temporary unpacking of zipped or DICOMDIR data. Defaults to the system temporary folder if not specified', default='')
4748
parser.add_argument('--no-update', help="Do not update any sub-/ses-prefixes in or prepend the sourcefolder name to the <<filepath:regex>> expression that extracts the subject/session labels. This is normally done to make the extraction more robust, but could cause problems for certain use cases", action='store_true')
4849

4950
return parser

0 commit comments

Comments
 (0)