mediml 0.9.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- MEDiml/MEDscan.py +1696 -0
- MEDiml/__init__.py +21 -0
- MEDiml/biomarkers/BatchExtractor.py +806 -0
- MEDiml/biomarkers/BatchExtractorTexturalFilters.py +840 -0
- MEDiml/biomarkers/__init__.py +16 -0
- MEDiml/biomarkers/diagnostics.py +125 -0
- MEDiml/biomarkers/get_oriented_bound_box.py +158 -0
- MEDiml/biomarkers/glcm.py +1602 -0
- MEDiml/biomarkers/gldzm.py +523 -0
- MEDiml/biomarkers/glrlm.py +1315 -0
- MEDiml/biomarkers/glszm.py +555 -0
- MEDiml/biomarkers/int_vol_hist.py +527 -0
- MEDiml/biomarkers/intensity_histogram.py +615 -0
- MEDiml/biomarkers/local_intensity.py +89 -0
- MEDiml/biomarkers/morph.py +1756 -0
- MEDiml/biomarkers/ngldm.py +780 -0
- MEDiml/biomarkers/ngtdm.py +414 -0
- MEDiml/biomarkers/stats.py +373 -0
- MEDiml/biomarkers/utils.py +389 -0
- MEDiml/filters/TexturalFilter.py +299 -0
- MEDiml/filters/__init__.py +9 -0
- MEDiml/filters/apply_filter.py +134 -0
- MEDiml/filters/gabor.py +215 -0
- MEDiml/filters/laws.py +283 -0
- MEDiml/filters/log.py +147 -0
- MEDiml/filters/mean.py +121 -0
- MEDiml/filters/textural_filters_kernels.py +1738 -0
- MEDiml/filters/utils.py +107 -0
- MEDiml/filters/wavelet.py +237 -0
- MEDiml/learning/DataCleaner.py +198 -0
- MEDiml/learning/DesignExperiment.py +480 -0
- MEDiml/learning/FSR.py +667 -0
- MEDiml/learning/Normalization.py +112 -0
- MEDiml/learning/RadiomicsLearner.py +714 -0
- MEDiml/learning/Results.py +2237 -0
- MEDiml/learning/Stats.py +694 -0
- MEDiml/learning/__init__.py +10 -0
- MEDiml/learning/cleaning_utils.py +107 -0
- MEDiml/learning/ml_utils.py +1015 -0
- MEDiml/processing/__init__.py +6 -0
- MEDiml/processing/compute_suv_map.py +121 -0
- MEDiml/processing/discretisation.py +149 -0
- MEDiml/processing/interpolation.py +275 -0
- MEDiml/processing/resegmentation.py +66 -0
- MEDiml/processing/segmentation.py +912 -0
- MEDiml/utils/__init__.py +25 -0
- MEDiml/utils/batch_patients.py +45 -0
- MEDiml/utils/create_radiomics_table.py +131 -0
- MEDiml/utils/data_frame_export.py +42 -0
- MEDiml/utils/find_process_names.py +16 -0
- MEDiml/utils/get_file_paths.py +34 -0
- MEDiml/utils/get_full_rad_names.py +21 -0
- MEDiml/utils/get_institutions_from_ids.py +16 -0
- MEDiml/utils/get_patient_id_from_scan_name.py +22 -0
- MEDiml/utils/get_patient_names.py +26 -0
- MEDiml/utils/get_radiomic_names.py +27 -0
- MEDiml/utils/get_scan_name_from_rad_name.py +22 -0
- MEDiml/utils/image_reader_SITK.py +37 -0
- MEDiml/utils/image_volume_obj.py +22 -0
- MEDiml/utils/imref.py +340 -0
- MEDiml/utils/initialize_features_names.py +62 -0
- MEDiml/utils/inpolygon.py +159 -0
- MEDiml/utils/interp3.py +43 -0
- MEDiml/utils/json_utils.py +78 -0
- MEDiml/utils/mode.py +31 -0
- MEDiml/utils/parse_contour_string.py +58 -0
- MEDiml/utils/save_MEDscan.py +30 -0
- MEDiml/utils/strfind.py +32 -0
- MEDiml/utils/textureTools.py +188 -0
- MEDiml/utils/texture_features_names.py +115 -0
- MEDiml/utils/write_radiomics_csv.py +47 -0
- MEDiml/wrangling/DataManager.py +1724 -0
- MEDiml/wrangling/ProcessDICOM.py +512 -0
- MEDiml/wrangling/__init__.py +3 -0
- mediml-0.9.9.dist-info/LICENSE.md +674 -0
- mediml-0.9.9.dist-info/METADATA +232 -0
- mediml-0.9.9.dist-info/RECORD +78 -0
- mediml-0.9.9.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from neuroCombat import neuroCombat
|
|
4
|
+
|
|
5
|
+
from ..utils.get_institutions_from_ids import get_institutions_from_ids
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Normalization:
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
method: str = 'combat',
|
|
12
|
+
variable_table: pd.DataFrame = None,
|
|
13
|
+
covariates_df: pd.DataFrame = None,
|
|
14
|
+
institutions: list = None
|
|
15
|
+
) -> None:
|
|
16
|
+
"""
|
|
17
|
+
Constructor of the Normalization class.
|
|
18
|
+
"""
|
|
19
|
+
self.method = method
|
|
20
|
+
self.variable_table = variable_table
|
|
21
|
+
self.covariates_df = covariates_df
|
|
22
|
+
self.institutions = institutions
|
|
23
|
+
|
|
24
|
+
def apply_combat(
|
|
25
|
+
self,
|
|
26
|
+
variable_table: pd.DataFrame,
|
|
27
|
+
covariate_df: pd.DataFrame = None,
|
|
28
|
+
institutions: list = None
|
|
29
|
+
) -> pd.DataFrame:
|
|
30
|
+
"""
|
|
31
|
+
Applys ComBat Normalization method to the data.
|
|
32
|
+
More details :ref:`this link <https://github.com/Jfortin1/ComBatHarmonization/tree/master/Python>`.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
variable_table (pd.DataFrame): pandas data frame on which Combat harmonization will be applied.
|
|
36
|
+
This table is of size N X F (Observations X Features) and has the IDs as index.
|
|
37
|
+
Requirements for this table
|
|
38
|
+
|
|
39
|
+
- Does not contain NaNs.
|
|
40
|
+
- No feature has 0 variance.
|
|
41
|
+
- All variables are continuous (For example: Radiomics variables).
|
|
42
|
+
covariate_df (pd.DataFrame, optional): N X M pandas data frame, where N must equal the number of
|
|
43
|
+
observations in variable_table. M is the number of covariates to include in the algorithm.
|
|
44
|
+
institutions (list, optional): List of size n_observations X 1 with the different institutions.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
pd.DataFrame: variable_table after Combat harmonization.
|
|
48
|
+
"""
|
|
49
|
+
# Initializing the class attributes from the arguments
|
|
50
|
+
if variable_table is None:
|
|
51
|
+
if self.variable_table is None:
|
|
52
|
+
raise ValueError('variable_table must be given.')
|
|
53
|
+
else:
|
|
54
|
+
self.variable_table = variable_table
|
|
55
|
+
if covariate_df is not None:
|
|
56
|
+
self.covariates_df = covariate_df
|
|
57
|
+
if institutions:
|
|
58
|
+
self.institutions = institutions
|
|
59
|
+
|
|
60
|
+
# Intializing the institutions if not given
|
|
61
|
+
if self.institutions is None:
|
|
62
|
+
patient_ids = pd.Series(self.variable_table.index)
|
|
63
|
+
self.institutions = get_institutions_from_ids(patient_ids)
|
|
64
|
+
all_institutions = self.institutions.unique()
|
|
65
|
+
for n in range(all_institutions.size):
|
|
66
|
+
self.institutions[self.institutions == all_institutions[n]] = n+1
|
|
67
|
+
self.institutions = self.institutions.to_numpy(dtype=int)
|
|
68
|
+
self.institutions = np.reshape(self.institutions, (-1, 1))
|
|
69
|
+
|
|
70
|
+
# No harmonization will be applied if there is only one institution
|
|
71
|
+
if np.unique(self.institutions).size < 2:
|
|
72
|
+
return self.variable_table
|
|
73
|
+
|
|
74
|
+
# Initializing the covariates if not given
|
|
75
|
+
if self.covariates_df is not None:
|
|
76
|
+
self.covariates_df['institution'] = self.institutions
|
|
77
|
+
else:
|
|
78
|
+
# the covars matrix is only a row with the institution
|
|
79
|
+
self.covariates_df = pd.DataFrame(
|
|
80
|
+
self.institutions,
|
|
81
|
+
columns=['institution'],
|
|
82
|
+
index=self.variable_table.index.values
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Apply combat
|
|
86
|
+
n_features = self.variable_table.shape[1]
|
|
87
|
+
batch_col = 'institution'
|
|
88
|
+
if n_features == 1:
|
|
89
|
+
# combat does not work with a single feature so a temporary one is added,
|
|
90
|
+
# then removed later (this has no effect on the algorithm).
|
|
91
|
+
self.variable_table['temp'] = pd.Series(
|
|
92
|
+
np.ones(self.variable_table.shape[0]),
|
|
93
|
+
index=self.variable_table.index
|
|
94
|
+
)
|
|
95
|
+
data_combat = neuroCombat(
|
|
96
|
+
self.variable_table.transpose(),
|
|
97
|
+
self.covariates_df,
|
|
98
|
+
batch_col
|
|
99
|
+
)
|
|
100
|
+
self.variable_table = pd.DataFrame(self.variable_table.drop('temp', axis=1))
|
|
101
|
+
vt_combat = pd.DataFrame(data_combat[:][0].transpose())
|
|
102
|
+
else:
|
|
103
|
+
data_combat = neuroCombat(
|
|
104
|
+
self.variable_table.transpose(),
|
|
105
|
+
self.covariates_df,
|
|
106
|
+
batch_col
|
|
107
|
+
)
|
|
108
|
+
vt_combat = pd.DataFrame(data_combat['data']).transpose()
|
|
109
|
+
|
|
110
|
+
self.variable_table[:] = vt_combat.values
|
|
111
|
+
|
|
112
|
+
return self.variable_table
|