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.
Files changed (78) hide show
  1. MEDiml/MEDscan.py +1696 -0
  2. MEDiml/__init__.py +21 -0
  3. MEDiml/biomarkers/BatchExtractor.py +806 -0
  4. MEDiml/biomarkers/BatchExtractorTexturalFilters.py +840 -0
  5. MEDiml/biomarkers/__init__.py +16 -0
  6. MEDiml/biomarkers/diagnostics.py +125 -0
  7. MEDiml/biomarkers/get_oriented_bound_box.py +158 -0
  8. MEDiml/biomarkers/glcm.py +1602 -0
  9. MEDiml/biomarkers/gldzm.py +523 -0
  10. MEDiml/biomarkers/glrlm.py +1315 -0
  11. MEDiml/biomarkers/glszm.py +555 -0
  12. MEDiml/biomarkers/int_vol_hist.py +527 -0
  13. MEDiml/biomarkers/intensity_histogram.py +615 -0
  14. MEDiml/biomarkers/local_intensity.py +89 -0
  15. MEDiml/biomarkers/morph.py +1756 -0
  16. MEDiml/biomarkers/ngldm.py +780 -0
  17. MEDiml/biomarkers/ngtdm.py +414 -0
  18. MEDiml/biomarkers/stats.py +373 -0
  19. MEDiml/biomarkers/utils.py +389 -0
  20. MEDiml/filters/TexturalFilter.py +299 -0
  21. MEDiml/filters/__init__.py +9 -0
  22. MEDiml/filters/apply_filter.py +134 -0
  23. MEDiml/filters/gabor.py +215 -0
  24. MEDiml/filters/laws.py +283 -0
  25. MEDiml/filters/log.py +147 -0
  26. MEDiml/filters/mean.py +121 -0
  27. MEDiml/filters/textural_filters_kernels.py +1738 -0
  28. MEDiml/filters/utils.py +107 -0
  29. MEDiml/filters/wavelet.py +237 -0
  30. MEDiml/learning/DataCleaner.py +198 -0
  31. MEDiml/learning/DesignExperiment.py +480 -0
  32. MEDiml/learning/FSR.py +667 -0
  33. MEDiml/learning/Normalization.py +112 -0
  34. MEDiml/learning/RadiomicsLearner.py +714 -0
  35. MEDiml/learning/Results.py +2237 -0
  36. MEDiml/learning/Stats.py +694 -0
  37. MEDiml/learning/__init__.py +10 -0
  38. MEDiml/learning/cleaning_utils.py +107 -0
  39. MEDiml/learning/ml_utils.py +1015 -0
  40. MEDiml/processing/__init__.py +6 -0
  41. MEDiml/processing/compute_suv_map.py +121 -0
  42. MEDiml/processing/discretisation.py +149 -0
  43. MEDiml/processing/interpolation.py +275 -0
  44. MEDiml/processing/resegmentation.py +66 -0
  45. MEDiml/processing/segmentation.py +912 -0
  46. MEDiml/utils/__init__.py +25 -0
  47. MEDiml/utils/batch_patients.py +45 -0
  48. MEDiml/utils/create_radiomics_table.py +131 -0
  49. MEDiml/utils/data_frame_export.py +42 -0
  50. MEDiml/utils/find_process_names.py +16 -0
  51. MEDiml/utils/get_file_paths.py +34 -0
  52. MEDiml/utils/get_full_rad_names.py +21 -0
  53. MEDiml/utils/get_institutions_from_ids.py +16 -0
  54. MEDiml/utils/get_patient_id_from_scan_name.py +22 -0
  55. MEDiml/utils/get_patient_names.py +26 -0
  56. MEDiml/utils/get_radiomic_names.py +27 -0
  57. MEDiml/utils/get_scan_name_from_rad_name.py +22 -0
  58. MEDiml/utils/image_reader_SITK.py +37 -0
  59. MEDiml/utils/image_volume_obj.py +22 -0
  60. MEDiml/utils/imref.py +340 -0
  61. MEDiml/utils/initialize_features_names.py +62 -0
  62. MEDiml/utils/inpolygon.py +159 -0
  63. MEDiml/utils/interp3.py +43 -0
  64. MEDiml/utils/json_utils.py +78 -0
  65. MEDiml/utils/mode.py +31 -0
  66. MEDiml/utils/parse_contour_string.py +58 -0
  67. MEDiml/utils/save_MEDscan.py +30 -0
  68. MEDiml/utils/strfind.py +32 -0
  69. MEDiml/utils/textureTools.py +188 -0
  70. MEDiml/utils/texture_features_names.py +115 -0
  71. MEDiml/utils/write_radiomics_csv.py +47 -0
  72. MEDiml/wrangling/DataManager.py +1724 -0
  73. MEDiml/wrangling/ProcessDICOM.py +512 -0
  74. MEDiml/wrangling/__init__.py +3 -0
  75. mediml-0.9.9.dist-info/LICENSE.md +674 -0
  76. mediml-0.9.9.dist-info/METADATA +232 -0
  77. mediml-0.9.9.dist-info/RECORD +78 -0
  78. 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