Skip to content

Commit

Permalink
fix doc, dockers and add skip_dcm2niix
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbore committed Jul 27, 2023
1 parent 22a9851 commit 821ec41
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion containers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN apt-get -y install wget build-essential cmake git pigz \
RUN pip3 install dcm2bids

# Install dcm2niix from github
ENV DCM2NIIX_VERSION="v1.0.20201102"
ENV DCM2NIIX_VERSION="v1.0.20230411"

WORKDIR /usr/local/src
RUN git clone https://github.com/rordenlab/dcm2niix.git
Expand Down
5 changes: 5 additions & 0 deletions dcm2bids/cli/dcm2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def _build_arg_parser():
help="Overwrite previous temporary dcm2niix "
"output if it exists.")

p.add_argument("--skip_dcm2niix",
action="store_true",
help="Skip dcm2niix conversion. "
"Option -d should contains NIFTI and json files.")

p.add_argument("--clobber",
action="store_true",
help="Overwrite output if it exists.")
Expand Down
3 changes: 3 additions & 0 deletions dcm2bids/dcm2bids_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(
session=DEFAULT.session,
clobber=DEFAULT.clobber,
force_dcm2niix=DEFAULT.force_dcm2niix,
skip_dcm2niix=DEFAULT.skip_dcm2niix,
log_level=DEFAULT.logLevel,
**_
):
Expand All @@ -54,6 +55,7 @@ def __init__(
self.bids_validate = bids_validate
self.auto_extract_entities = auto_extract_entities
self.force_dcm2niix = force_dcm2niix
self.skip_dcm2niix = skip_dcm2niix
self.logLevel = log_level
self.logger = logging.getLogger(__name__)

Expand All @@ -77,6 +79,7 @@ def run(self):
self.dicom_dirs,
self.bids_dir,
self.participant,
self.skip_dcm2niix,
self.config.get("dcm2niixOptions", DEFAULT.dcm2niixOptions),
)

Expand Down
26 changes: 20 additions & 6 deletions dcm2bids/dcm2niix_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Dcm2niixGen(object):
dicom_dirs (list): A list of folder with dicoms to convert
bids_dir (str): A path to the root BIDS directory
participant: Optional Participant object
skip_dcm2niix: Optional if input only NIFTI and JSON files
options (str): Optional arguments for dcm2niix
Properties:
Expand All @@ -29,6 +30,7 @@ def __init__(
dicom_dirs,
bids_dir,
participant=None,
skip_dcm2niix=DEFAULT.skip_dcm2niix,
options=DEFAULT.dcm2niixOptions,
helper=False
):
Expand All @@ -37,6 +39,7 @@ def __init__(
self.dicom_dirs = dicom_dirs
self.bids_dir = bids_dir
self.participant = participant
self.skip_dcm2niix = skip_dcm2niix
self.options = options
self.helper = helper

Expand Down Expand Up @@ -96,15 +99,26 @@ def run(self, force=False, helper=False):
def execute(self):
""" Execute dcm2niix for each directory in dicom_dirs
"""
for dicomDir in self.dicom_dirs:
cmd = ['dcm2niix', *shlex.split(self.options),
'-o', self.output_dir, dicomDir]
if not self.skip_dcm2niix:
for dicomDir in self.dicom_dirs:
cmd = ['dcm2niix', *shlex.split(self.options),
'-o', self.output_dir, dicomDir]
output = run_shell_command(cmd)

try:
output = output.decode()
except Exception:
pass

self.logger.debug(f"\n{output}")
self.logger.info("Check log file for dcm2niix output\n")
else:
cmd = ['cp', '-r', dicomDir, self.output_dir]
output = run_shell_command(cmd)

try:
output = output.decode()
except Exception:
pass

self.logger.debug(f"\n{output}")
self.logger.info("Check log file for dcm2niix output\n")

self.logger.info("Not running dcm2niix\n")
1 change: 1 addition & 0 deletions dcm2bids/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DEFAULT(object):

# dcm2niix.py
dcm2niixOptions = "-b y -ba y -z y -f '%3s_%f_%p_%t'"
skip_dcm2niix = False

# sidecar.py
auto_extractors = {'SeriesDescription': ["task-(?P<task>[a-zA-Z0-9]+)"],
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/create-config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
},
{
"id": "task-rest",
"id": "task_rest",
"datatype": "func",
"suffix": "bold",
"custom_entities": "task-rest",
Expand Down

0 comments on commit 821ec41

Please sign in to comment.