Skip to content

Commit 3e05353

Browse files
authored
Merge pull request #17 from MEDomicsLab/dev
New version 9.9.10
2 parents 89906f7 + 67c655b commit 3e05353

14 files changed

Lines changed: 505 additions & 639 deletions

MEDiml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
logging.getLogger(__name__).addHandler(stream_handler)
1515

1616
__author__ = "MEDomicsLab consortium"
17-
__version__ = "0.9.9"
17+
__version__ = "0.9.10"
1818
__copyright__ = "Copyright (C) MEDomicsLab consortium"
1919
__license__ = "GNU General Public License 3.0"
2020
__maintainer__ = "MAHDI AIT LHAJ LOUTFI"

MEDiml/wrangling/DataManager.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,7 @@ def __associate_roi_to_image(
432432
Returns:
433433
MEDscan: Returns a MEDscan instance with updated roi attributes.
434434
"""
435-
image_file = Path(image_file)
436-
roi_index = 0
437-
438-
if not path_roi_data:
439-
if not self.paths._path_to_niftis:
440-
raise ValueError("The path to the niftis is not defined")
441-
else:
442-
path_roi_data = self.paths._path_to_niftis
443-
444-
for file in path_roi_data.glob('*.nii.gz'):
445-
_id = image_file.name.split("(")[0] # id is PatientID__ImagingScanName
435+
def load_mask(_id, file, medscan):
446436
# Load the patient's ROI nifti files:
447437
if file.name.startswith(_id) and 'ROI' in file.name.split("."):
448438
roi = nib.load(file)
@@ -452,8 +442,27 @@ def __associate_roi_to_image(
452442
name_set = file.name[file.name.find("_") + 2 : file.name.find("(")]
453443
medscan.data.ROI.update_indexes(key=roi_index, indexes=np.nonzero(roi_data.flatten()))
454444
medscan.data.ROI.update_name_set(key=roi_index, name_set=name_set)
455-
medscan.data.ROI.update_roi_name(key=roi_index, roi_name=roi_name)
445+
medscan.data.ROI.update_roi_name(key=roi_index, roi_name=roi_name)
446+
else:
447+
raise ValueError(f"The ROI file for patient ID: {_id} "
448+
f"was not found in the given path: {file} or was not correctly named.")
449+
450+
image_file = Path(image_file)
451+
roi_index = 0
452+
if not path_roi_data:
453+
if not self.paths._path_to_niftis:
454+
raise ValueError("The path to the niftis is not defined")
455+
else:
456+
path_roi_data = self.paths._path_to_niftis
457+
458+
for file in self.__nifti.stack_path_roi:
459+
_id = image_file.name.split("(")[0] if ("(") in image_file.name else image_file.name # id is PatientID__ImagingScanName
460+
load_mask(_id, file, medscan)
456461
roi_index += 1
462+
else:
463+
_id = image_file.name.split("(")[0] if ("(") in image_file.name else image_file.name # id is PatientID__ImagingScanName
464+
load_mask(_id, path_roi_data, medscan)
465+
457466
return medscan
458467

459468
def __associate_spatialRef(self, nifti_file: Union[Path, str], medscan: MEDscan) -> MEDscan:
@@ -567,7 +576,7 @@ def process_all_niftis(self) -> List[MEDscan]:
567576
medscan = MEDscan()
568577
medscan.patientID = os.path.basename(file).split("_")[0]
569578
medscan.type = os.path.basename(file).split(".")[-3]
570-
medscan.series_description = file.name[file.name.find('__') + 2: file.name.find('(')]
579+
medscan.series_description = file.name[file.name.find('__') + 2: file.name.find('(')] if '__' in file.name else ""
571580
medscan.format = "nifti"
572581
medscan.data.set_orientation(orientation="Axial")
573582
medscan.data.set_patient_position(patient_position="HFS")
@@ -625,6 +634,24 @@ def process_all_niftis(self) -> List[MEDscan]:
625634
if list_instances:
626635
return list_instances
627636

637+
def process_one_nifti(self, path_image: Union[Path, str], path_mask: Union[Path, str]) -> MEDscan:
638+
"""Processes one NIfTI file to create a MEDscan class instance.
639+
640+
Args:
641+
nifti_file (Union[Path, str]): Path to the NIfTI file.
642+
path_data (Union[Path, str]): Path to the data.
643+
644+
Returns:
645+
MEDscan: MEDscan class instance.
646+
"""
647+
medscan = self.__process_one_nifti(path_image, path_mask)
648+
649+
# SAVE MEDscan INSTANCE
650+
if self.save and self.paths._path_save:
651+
save_MEDscan(medscan, self.paths._path_save)
652+
653+
return medscan
654+
628655
def update_from_csv(self, path_csv: Union[str, Path] = None) -> None:
629656
"""Updates the class from a given CSV and summarizes the processed scans again according to it.
630657

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<img src="https://github.com/MEDomicsLab/MEDiml/blob/main/docs/figures/MEDimlLogo150.png?raw=true" style="width:150px;"/>
44

55
[![PyPI - Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10-blue)](https://www.python.org/downloads/release/python-380/)
6-
[![PyPI - version](https://img.shields.io/badge/pypi-v0.9.8-blue)](https://pypi.org/project/medimage-pkg/)
6+
[![PyPI - version](https://img.shields.io/badge/pypi-v0.9.10-blue)](https://pypi.org/project/medimage-pkg/)
77
[![Continuous Integration](https://github.com/MEDomicsLab/MEDiml/actions/workflows/python-app.yml/badge.svg)](https://github.com/MEDomicsLab/MEDiml/actions/workflows/python-app.yml)
88
[![Documentation Status](https://readthedocs.org/projects/mediml/badge/?version=latest)](https://mediml.readthedocs.io/en/latest/?badge=latest)
99
[![License: GPL-3](https://img.shields.io/badge/license-GPLv3-blue)](LICENSE)
10-
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/tutorial/DataManager-Tutorial.ipynb)
10+
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/tutorial/DataManager-Tutorial.ipynb)
1111

1212
</div>
1313

@@ -27,7 +27,7 @@
2727
## 1. Introduction
2828
MEDiml is an open-source Python package that can be used for processing multi-modal medical images (MRI, CT or PET) and for extracting their radiomic features. This package is meant to facilitate the processing of medical images and the subsequent computation of all types of radiomic features while maintaining the reproducibility of analyses. This package has been standardized with the [IBSI](https://theibsi.github.io/) norms.
2929

30-
![MEDiml overview](https://raw.githubusercontent.com/MahdiAll99/MEDimage/main/docs/figures/pakcage-overview.png)
30+
![MEDiml overview](https://raw.githubusercontent.com/MEDomicsLab/MEDiml/main/docs/figures/pakcage-overview.png)
3131

3232

3333
## 2. Installation
@@ -107,14 +107,14 @@ The image biomarker standardization initiative ([IBSI](https://theibsi.github.io
107107
- ### IBSI Chapter 1
108108
[The IBSI chapter 1](https://theibsi.github.io/ibsi1/) is dedicated to the standardization of commonly used radiomic features. It was initiated in September 2016 and reached completion in March 2020. We have created two [jupyter notebooks](https://github.com/MEDomicsLab/MEDiml/tree/main/notebooks/ibsi) for each phase of the chapter and made them available for the users to run the IBSI tests for themselves. The tests can also be explored in interactive Colab notebooks that are directly accessible here:
109109
110-
- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi1p1.ipynb)
111-
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi1p2.ipynb)
110+
- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi1p1.ipynb)
111+
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi1p2.ipynb)
112112

113113
- ### IBSI Chapter 2
114114
[The IBSI chapter 2](https://theibsi.github.io/ibsi2/) was launched in June 2020 and reached completion in February 2024. It is dedicated to the standardization of commonly used imaging filters in radiomic studies. We have created two [jupyter notebooks](https://github.com/MEDomicsLab/MEDiml/tree/main/notebooks/ibsi) for each phase of the chapter and made them available for the users to run the IBSI tests for themselves and validate image filtering and image biomarker calculations from filter response maps. The tests can also be explored in interactive Colab notebooks that are directly accessible here:
115115

116-
- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi2p1.ipynb)
117-
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MahdiAll99/MEDimage/blob/main/notebooks/ibsi/ibsi2p2.ipynb)
116+
- **Phase 1**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi2p1.ipynb)
117+
- **Phase 2**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MEDomicsLab/MEDiml/blob/main/notebooks/ibsi/ibsi2p2.ipynb)
118118

119119
Our team at *UdeS* (a.k.a. Université de Sherbrooke) has already submitted the benchmarked values to the [IBSI uploading website](https://ibsi.radiomics.hevs.ch/).
120120

0 commit comments

Comments
 (0)