diff --git a/xnat2mids/conversion/dicom_converters.py b/xnat2mids/conversion/dicom_converters.py index 2c9a032..dce1c99 100644 --- a/xnat2mids/conversion/dicom_converters.py +++ b/xnat2mids/conversion/dicom_converters.py @@ -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) @@ -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 @@ -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 @@ -90,4 +108,3 @@ def add_dicom_metadata( sort_keys=True) with json_filepath.open('w') as dicom_file: dicom_file.write(string_json) - diff --git a/xnat2mids/mids_conversion.py b/xnat2mids/mids_conversion.py index 9ae5228..de3ab01 100644 --- a/xnat2mids/mids_conversion.py +++ b/xnat2mids/mids_conversion.py @@ -16,7 +16,7 @@ from pandas.errors import EmptyDataError adquisition_date_pattern = r"(?P\d+)-(?P\d+)-(?P\d+)T(?P\d+):(?P\d+):(?P\d+).(?P\d+)" -subses_pattern = r"[A-z]+(?P\d*)?(_S)(?P\d+)/[A-z]+\-?[A-z]*(?P\d*)?(_E)(?P\d+)" +subses_pattern = r"[A-z]+(?P\d*)?(_S)(?P\d+)(\\|/)[A-z]+\-?[A-z]*(?P\d*)?(_E)(?P\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) @@ -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'))