Skip to content

Commit

Permalink
add compatibility with windows
Browse files Browse the repository at this point in the history
  • Loading branch information
maigva committed Aug 24, 2023
1 parent 2239af8 commit 1c69def
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
37 changes: 27 additions & 10 deletions xnat2mids/conversion/dicom_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import json
import pydicom
import shutil

import platform
sistema = platform.system()
# def sitk_dicom2mifti(dicom_path):
# reader = sitk.ImageSeriesReader()
# dicom_names = reader.GetGDCMSeriesFileNames(dicom_path.parent)
Expand Down Expand Up @@ -33,12 +34,21 @@ def dicom2niix(folder_json, str_options):
folder_nifti = folder_json.parent.parent.joinpath("LOCAL_NIFTI", "files")
folder_nifti.mkdir(parents=True, exist_ok=True)
print(f"dcm2niix {str_options} -o {folder_nifti} {folder_json}")
subprocess.call(
f"dcm2niix {str_options} -o {folder_nifti} {folder_json}",
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT
)
if sistema == "Linux":
subprocess.call(
f"dcm2niix {str_options} -o {folder_nifti} {folder_json}",
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT
)
else:
print(f"dcm2niix.exe {str_options} -o {folder_nifti} {folder_json}")
subprocess.call(
f"dcm2niix.exe {str_options} -o {folder_nifti} {folder_json}",
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT
)
if len(list(folder_nifti.iterdir())) == 0:
# folder_nifti.parent.unlink(missing_ok=True)
return folder_nifti
Expand All @@ -62,8 +72,16 @@ def dicom2png(folder_json, str_options):
folder_png.parent.mkdir(parents=True, exist_ok=True)
sitk_img = sitk.ReadImage(dcm_file)
sitk.WriteImage(sitk_img, folder_png)
subprocess.call(
f"dcm2niix {str_options} -b o -o {folder_png.parent} {dcm_files[0].parent}",
if sistema == "Linux":
subprocess.call(
f"dcm2niix {str_options} -b o -o {folder_png.parent} {dcm_files[0].parent}",
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT
)
else:
subprocess.call(
f"dcm2niix.exe {str_options} -b o -o {folder_png.parent} {dcm_files[0].parent}",
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT
Expand All @@ -90,4 +108,3 @@ def add_dicom_metadata(
sort_keys=True)
with json_filepath.open('w') as dicom_file:
dicom_file.write(string_json)

4 changes: 2 additions & 2 deletions xnat2mids/mids_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pandas.errors import EmptyDataError

adquisition_date_pattern = r"(?P<year>\d+)-(?P<month>\d+)-(?P<day>\d+)T(?P<hour>\d+):(?P<minutes>\d+):(?P<seconds>\d+).(?P<ms>\d+)"
subses_pattern = r"[A-z]+(?P<prefix_sub>\d*)?(_S)(?P<suffix_sub>\d+)/[A-z]+\-?[A-z]*(?P<prefix_ses>\d*)?(_E)(?P<suffix_ses>\d+)"
subses_pattern = r"[A-z]+(?P<prefix_sub>\d*)?(_S)(?P<suffix_sub>\d+)(\\|/)[A-z]+\-?[A-z]*(?P<prefix_ses>\d*)?(_E)(?P<suffix_ses>\d+)"
prostate_pattern = r"(?:(?:(?:diff?|dwi)(?:\W|_)(?:.*)(?:b\d+))|dif 2000)|(?:adc|Apparent)|prop|blade|fse|tse|^ax T2$"

aquisition_date_pattern_comp = re.compile(adquisition_date_pattern)
Expand Down Expand Up @@ -107,7 +107,7 @@ def create_directory_mids_v1(xnat_data_path, mids_data_path, body_part, debug_le
if "_E" not in sessions_xnat_path.name: continue



print(sessions_xnat_path)
findings = re.search(subses_pattern, str(sessions_xnat_path), re.X)
#print('subject,', findings.group('prefix_sub'), findings.group('suffix_sub'))
#print('session,', findings.group('prefix_ses'), findings.group('suffix_ses'))
Expand Down

0 comments on commit 1c69def

Please sign in to comment.