Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Jan 28, 2024
1 parent 7b06554 commit 3c18ddd
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 64 deletions.
2 changes: 1 addition & 1 deletion bidscoin/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def dynamicvalue(self, value, cleanup: bool=True, runtime: bool=False):
return value


def unpack(sesfolder: Path, wildcard: str='', workfolder: Path='', _subprefix: str='') -> Tuple[Set[Path], bool]:
def unpack(sesfolder: Path, wildcard: str='', workfolder: Path='', _subprefix: Union[str,None]='') -> Tuple[Set[Path], bool]:
"""
Unpacks and sorts DICOM files in sourcefolder to a temporary folder if sourcefolder contains a DICOMDIR file or .tar.gz, .gz or .zip files
Expand Down
2 changes: 1 addition & 1 deletion bidscoin/bidscoiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def bidscoiner(rawfolder: str, bidsfolder: str, subjects: list=(), force: bool=F
:param bidsfolder: The name of the BIDS root folder
:param subjects: List of selected subjects / participants (i.e. sub-# names / folders) to be processed (the sub-prefix can be removed). Otherwise, all subjects in the sourcefolder will be selected
:param force: If True, subjects will be processed, regardless of existing folders in the bidsfolder. Otherwise, existing folders will be skipped
:param bidsmapfile: The name of the bidsmap YAML-file. If the bidsmap pathname is relative (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin
:param bidsmapfile: The name of the bidsmap YAML-file. If the bidsmap pathname is just the basename (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin
:param cluster: Use the DRMAA library to submit the bidscoiner jobs to a high-performance compute (HPC) cluster
:param nativespec: DRMAA native specifications for submitting bidscoiner jobs to the HPC cluster. See cli/_bidscoiner() for default
:return: Nothing
Expand Down
2 changes: 1 addition & 1 deletion bidscoin/cli/_bidscoiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_parser():
parser.add_argument('sourcefolder', help='The study root folder containing the raw source data')
parser.add_argument('bidsfolder', help='The destination / output folder with the bids data')
parser.add_argument('-p','--participant_label', help='Space separated list of selected sub-# names / folders to be processed (the sub-prefix can be removed). Otherwise all subjects in the sourcefolder will be selected', nargs='+')
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is relative (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml', default='bidsmap.yaml')
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is just the basename (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml', default='bidsmap.yaml')
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')
parser.add_argument('-c','--cluster', help='Use the DRMAA library to submit the bidscoiner jobs to a high-performance compute (HPC) cluster', action='store_true')
parser.add_argument('-n','--nativespec', help='Opaque DRMAA argument with native specifications for submitting bidscoiner jobs to the HPC cluster. NB: Use quotes and include at least one space character to prevent overearly parsing (default: -l walltime=00:30:00,mem=4gb)', default='-l walltime=00:30:00,mem=4gb')
Expand Down
4 changes: 2 additions & 2 deletions bidscoin/cli/_bidseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_parser() -> argparse.ArgumentParser:
bidseditor myproject/bids -b my/custom/bidsmap.yaml"""))

parser.add_argument('bidsfolder', help='The destination folder with the (future) bids data')
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is relative (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml', default='bidsmap.yaml')
parser.add_argument('-t','--template', help=f'The template bidsmap file with the default heuristics (this could be provided by your institute). If the bidsmap filename is relative (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: {bidsmap_template.stem}', default=bidsmap_template)
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is just the basename (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml', default='bidsmap.yaml')
parser.add_argument('-t','--template', help=f'The template bidsmap file with the default heuristics (this could be provided by your institute). If the bidsmap filename is just the basename (i.e. no "/" in the name) then it is assumed to be located in the bidscoin config folder. Default: {bidsmap_template.stem}', default=bidsmap_template)

return parser
4 changes: 2 additions & 2 deletions bidscoin/cli/_bidsmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def get_parser() -> argparse.ArgumentParser:
" bidsmapper myproject/raw myproject/bids -u '*.tar.gz' # Unzip tarball sourcefiles\n ")
parser.add_argument('sourcefolder', help='The study root folder containing the raw source data folders')
parser.add_argument('bidsfolder', help='The destination folder with the (future) bids data and the bidsfolder/code/bidscoin/bidsmap.yaml output file')
parser.add_argument('-b','--bidsmap', help="The study bidsmap file with the mapping heuristics. If the bidsmap filename is relative (i.e. no '/' in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml", default='bidsmap.yaml')
parser.add_argument('-t','--template', help=f"The bidsmap template file with the default heuristics (this could be provided by your institute). If the bidsmap filename is relative (i.e. no '/' in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: {bidsmap_template.stem}", default=bidsmap_template)
parser.add_argument('-b','--bidsmap', help="The study bidsmap file with the mapping heuristics. If the bidsmap filename is just the basename (i.e. no '/' in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml", default='bidsmap.yaml')
parser.add_argument('-t','--template', help=f"The bidsmap template file with the default heuristics (this could be provided by your institute). If the bidsmap filename is just the basename (i.e. no '/' in the name) then it is assumed to be located in the bidscoin config folder. Default: {bidsmap_template.stem}", default=bidsmap_template)
parser.add_argument('-p','--plugins', help='List of plugins to be used. Default: the plugin list of the study/template bidsmap)', nargs='+', default=[])
parser.add_argument('-n','--subprefix', help="The prefix common for all the source subject-folders (e.g. 'Pt' is the subprefix if subject folders are named 'Pt018', 'Pt019', ...). Use '*' when your subject folders do not have a prefix. Default: the value of the study/template bidsmap, e.g. 'sub-'")
parser.add_argument('-m','--sesprefix', help="The prefix common for all the source session-folders (e.g. 'M_' is the subprefix if session folders are named 'M_pre', 'M_post', ..). Use '*' when your session folders do not have a prefix. Default: the value of the study/template bidsmap, e.g. 'ses-'")
Expand Down
2 changes: 1 addition & 1 deletion bidscoin/cli/_bidsparticipants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def get_parser():
parser.add_argument('bidsfolder', help='The destination / output folder with the bids data')
parser.add_argument('-k','--keys', help="Space separated list of the participants.tsv columns. Default: 'session_id' 'age' 'sex' 'size' 'weight'", nargs='+', default=['age', 'sex', 'size', 'weight']) # NB: session_id is default
parser.add_argument('-d','--dryrun', help='Do not save anything, only print the participants info on screen', action='store_true')
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is relative (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml', default='bidsmap.yaml')
parser.add_argument('-b','--bidsmap', help='The study bidsmap file with the mapping heuristics. If the bidsmap filename is just the basename (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin. Default: bidsmap.yaml', default='bidsmap.yaml')

return parser
2 changes: 1 addition & 1 deletion bidscoin/utilities/bidsparticipants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def bidsparticipants(rawfolder: str, bidsfolder: str, keys: list, bidsmapfile: s
:param rawfolder: The root folder-name of the sub/ses/data/file tree containing the source data files
:param bidsfolder: The name of the BIDS root folder
:param keys: The keys that are extracted from the source data when populating the participants.tsv file
:param bidsmapfile: The name of the bidsmap YAML-file. If the bidsmap pathname is relative (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin
:param bidsmapfile: The name of the bidsmap YAML-file. If the bidsmap pathname is just the basename (i.e. no "/" in the name) then it is assumed to be located in bidsfolder/code/bidscoin
:param dryrun: Boolean to just display the participants info
:return: Nothing
"""
Expand Down
5 changes: 3 additions & 2 deletions bidscoin/utilities/dicomsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from typing import List, Set
from importlib.util import find_spec
from typing import Union
if find_spec('bidscoin') is None:
import sys
sys.path.append(str(Path(__file__).parents[2]))
Expand Down Expand Up @@ -134,13 +135,13 @@ def sortsession(sessionfolder: Path, dicomfiles: List[Path], folderscheme: str,
dicomfile.replace(newfilename)


def sortsessions(sourcefolder: Path, subprefix: str='', sesprefix: str='', folderscheme: str='{SeriesNumber:03d}-{SeriesDescription}',
def sortsessions(sourcefolder: Path, subprefix: Union[str,None]='', sesprefix: str='', folderscheme: str='{SeriesNumber:03d}-{SeriesDescription}',
namescheme: str='', pattern: str=r'.*\.(IMA|dcm)$', recursive: bool=True, force: bool=False, dryrun: bool=False) -> Set[Path]:
"""
Wrapper around sortsession() to loop over subjects and sessions and map the session DICOM files
:param sourcefolder: The root folder containing the source [sub/][ses/]dicomfiles or the DICOMDIR file
:param subprefix: The prefix for searching the sub folders in session. Use '' to sort DICOMDIR files directly in sourcefolder
:param subprefix: The prefix for searching the sub folders in session. Use '' to sort DICOMDIR files directly in sourcefolder (None will add DICOMDIR-based sub-/ses-folders
:param sesprefix: The prefix for searching the ses folders in sub folder
:param folderscheme: Optional naming scheme for the sorted (e.g. Series) subfolders. Follows the Python string formatting syntax with DICOM field names in curly bracers with an optional number of digits for numeric fields', default='{SeriesNumber:03d}-{SeriesDescription}'
:param namescheme: Optional naming scheme for renaming the files. Follows the Python string formatting syntax with DICOM field names in curly bracers, e.g. {PatientName}_{SeriesNumber:03d}_{SeriesDescription}_{AcquisitionNumber:05d}_{InstanceNumber:05d}.IMA
Expand Down
2 changes: 1 addition & 1 deletion docs/utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ The bidsparticipants tool is useful for (re-)generating a participants.tsv file
-d, --dryrun Do not save anything, only print the participants info on screen
-b BIDSMAP, --bidsmap BIDSMAP
The study bidsmap file with the mapping heuristics. If the bidsmap filename
is relative (i.e. no "/" in the name) then it is assumed to be located in
is just the basename (i.e. no "/" in the name) then it is assumed to be located in
bidsfolder/code/bidscoin. Default: bidsmap.yaml

examples:
Expand Down
14 changes: 7 additions & 7 deletions docs/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ Step 1a: Running the bidsmapper
-h, --help show this help message and exit
-b BIDSMAP, --bidsmap BIDSMAP
The study bidsmap file with the mapping heuristics. If the bidsmap filename
is relative (i.e. no '/' in the name) then it is assumed to be located in
is just the basename (i.e. no '/' in the name) then it is assumed to be located in
bidsfolder/code/bidscoin. Default: bidsmap.yaml
-t TEMPLATE, --template TEMPLATE
The bidsmap template file with the default heuristics (this could be provided
by your institute). If the bidsmap filename is relative (i.e. no '/' in the
name) then it is assumed to be located in bidsfolder/code/bidscoin. Default:
by your institute). If the bidsmap filename is just the basename (i.e. no '/' in
the name) then it is assumed to be located in the bidscoin config folder. Default:
bidsmap_dccn
-p PLUGINS [PLUGINS ...], --plugins PLUGINS [PLUGINS ...]
List of plugins to be used. Default: the plugin list of the study/template
Expand Down Expand Up @@ -112,12 +112,12 @@ Step 1b: Running the bidseditor
-h, --help show this help message and exit
-b BIDSMAP, --bidsmap BIDSMAP
The study bidsmap file with the mapping heuristics. If the bidsmap filename
is relative (i.e. no "/" in the name) then it is assumed to be located in
is just the basename (i.e. no "/" in the name) then it is assumed to be located in
bidsfolder/code/bidscoin. Default: bidsmap.yaml
-t TEMPLATE, --template TEMPLATE
The template bidsmap file with the default heuristics (this could be provided
by your institute). If the bidsmap filename is relative (i.e. no "/" in the
name) then it is assumed to be located in bidsfolder/code/bidscoin. Default:
by your institute). If the bidsmap filename is just the basename (i.e. no "/" in
the name) then it is assumed to be located in the bidscoin config folder. Default:
bidsmap_dccn

examples:
Expand Down Expand Up @@ -203,7 +203,7 @@ Step 2: Running the bidscoiner
be selected
-b BIDSMAP, --bidsmap BIDSMAP
The study bidsmap file with the mapping heuristics. If the bidsmap filename
is relative (i.e. no "/" in the name) then it is assumed to be located in
is just the basename (i.e. no "/" in the name) then it is assumed to be located in
bidsfolder/code/bidscoin. Default: bidsmap.yaml
-f, --force Process all subjects, regardless of existing subject folders in the
bidsfolder. Otherwise these subject folders will be skipped
Expand Down
Loading

0 comments on commit 3c18ddd

Please sign in to comment.