File size: 10,891 Bytes
55f9952
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
"""
This module contains information about datasets used in the project.

The datasets are defined as dataset dataclasses.
Each dataset dataclass contains information about the dataset, such as the dataset name, the phases and annotations provided in the source dataset.
It also contains information about how to translate source labels and masks into UMIE format.
"""
from dataclasses import dataclass, field

from config import labels, masks


@dataclass
class MaskColor:
    """A class for storing information about how to recolor a given mask from the source color to the target color."""

    source_color: int
    target_color: int


@dataclass
class DatasetArgs:
    """This class represents required configuration information about each dataset."""

    dataset_uid: str  # unique identifier for the dataset in UMIE
    dataset_name: str  # name of the dataset in UMIE
    phases: dict[
        str, str
    ]  # phase_id is used for encoding the phase in umie img name, phase_name is used for naming the folder
    labels: dict[str, list[dict[str, float]]] = field(
        default_factory=dict
    )  # we allow many-to-many label translations, some labels have multiple RadLex codes
    masks: dict[str, MaskColor] = field(
        default_factory=dict
    )  # mask name and MaskColor object specifying how to recolor the mask


kits23 = DatasetArgs(
    dataset_uid="00",
    dataset_name="kits23",
    phases={"0": "CT"},  # arterial or nephrogenic CT phase (no way to distinguish them in the dataset easily)
    labels={
        "normal": [{labels.NormalityDecriptor.radlex_name: 1}],
        "angiomyolipoma": [{labels.Angiomyolipoma.radlex_name: 1}, {labels.Neoplasm.radlex_name: 1}],
        "chromophobe_rcc": [
            {labels.ChromophobeAdenocarcinoma.radlex_name: 1},
            {labels.RenalAdenocarcinoma.radlex_name: 1},
            {labels.Adenocarcinoma.radlex_name: 1},
            {labels.Neoplasm.radlex_name: 1},
        ],
        "clear_cell_papillary": [
            {labels.ClearCellAdenocarcinoma.radlex_name: 1},
            {labels.PapillaryRenalAdenocarcinoma.radlex_name: 1},
            {labels.RenalAdenocarcinoma.radlex_name: 1},
            {labels.Adenocarcinoma.radlex_name: 1},
            {labels.Neoplasm.radlex_name: 1},
        ],
        "clear_cell_rcc": [
            {labels.ClearCellAdenocarcinoma.radlex_name: 1},
            {labels.RenalAdenocarcinoma.radlex_name: 1},
            {labels.Adenocarcinoma.radlex_name: 1},
            {labels.Neoplasm.radlex_name: 1},
        ],
        "mest": [{labels.Neoplasm.radlex_name: 1}],
        "multilocular_cystic_rcc": [
            {labels.MultilocularCysticRenalTumor.radlex_name: 1},
            {labels.RenalAdenocarcinoma.radlex_name: 1},
            {labels.Adenocarcinoma.radlex_name: 1},
            {labels.Neoplasm.radlex_name: 1},
        ],
        "oncocytoma": [{labels.Oncocytoma.radlex_name: 1}, {labels.Neoplasm.radlex_name: 1}],
        "papillary_rcc": [
            {labels.PapillaryRenalAdenocarcinoma.radlex_name: 1},
            {labels.RenalAdenocarcinoma.radlex_name: 1},
            {labels.Adenocarcinoma.radlex_name: 1},
            {labels.Neoplasm.radlex_name: 1},
        ],
        "rcc_unclassified": [
            {labels.RenalAdenocarcinoma.radlex_name: 1},
            {labels.Adenocarcinoma.radlex_name: 1},
            {labels.Neoplasm.radlex_name: 1},
        ],
        "spindle_cell_neoplasm": [{labels.Neoplasm.radlex_name: 1}],
        "urothelial": [{labels.Neoplasm.radlex_name: 1}],
        "wilms": [{labels.WilmsTumor.radlex_name: 1}, {labels.Neoplasm.radlex_name: 1}],
    },
    masks={
        masks.Kidney.radlex_name: MaskColor(source_color=1, target_color=masks.Kidney.color),
        masks.Neoplasm.radlex_name: MaskColor(source_color=2, target_color=masks.Neoplasm.color),
        masks.RenalCyst.radlex_name: MaskColor(source_color=3, target_color=masks.RenalCyst.color),
    },
)

coronahack = DatasetArgs(
    dataset_uid="01",
    dataset_name="coronahack",
    phases={"0": "Xray"},
    labels={
        "Normal": [{labels.NormalityDecriptor.radlex_name: 1}],
        "PneumoniaBacteria": [{labels.Pneumonia.radlex_name: 1}],
        "PneumoniaVirus": [
            {labels.PneumoniaViral.radlex_name: 1},
            {labels.ViralInfection.radlex_name: 1},
            {labels.Pneumonia.radlex_name: 1},
        ],
    },
)

alzheimers = DatasetArgs(
    dataset_uid="02",
    dataset_name="alzheimers",
    phases={"0": "MRI"},
    labels={
        "MildDemented": [{labels.Dementia.radlex_name: round(2 / 3, 2)}],
        "ModerateDemented": [{labels.Dementia.radlex_name: 1}],
        "NonDemented": [{labels.NormalityDecriptor.radlex_name: 1}],
        "VeryMildDemented": [{labels.Dementia.radlex_name: round(1 / 3, 2)}],
        "mildDem": [{labels.Dementia.radlex_name: round(2 / 3, 2)}],
        "moderateDem": [{labels.Dementia.radlex_name: 1}],
        "nonDem": [{labels.NormalityDecriptor.radlex_name: 1}],
        "verymildDem": [{labels.Dementia.radlex_name: round(1 / 3, 2)}],
    },
)

brain_tumor_classification = DatasetArgs(
    dataset_uid="03",
    dataset_name="brain_tumor_classification",
    phases={
        "0": "T1_weighted_postCM"
    },  # occasionally T2_weighted! (but no way to distinguish them in the dataset easily)
    labels={
        "no_tumor": [{labels.NormalityDecriptor.radlex_name: 1}],
        "glioma_tumor": [{labels.Glioma.radlex_name: 1}],
        "meningioma_tumor": [{labels.Meningioma.radlex_name: 1}],
        "pituitary_tumor": [{labels.Pituitary.radlex_name: 1}],
    },
)

covid19_detection = DatasetArgs(
    dataset_uid="04",
    dataset_name="covid19_detection",
    phases={"0": "Xray"},
    labels={
        "Normal": [{labels.NormalityDecriptor.radlex_name: 1}],
        "BacterialPneumonia": [{labels.Pneumonia.radlex_name: 1}],
        "ViralPneumonia": [
            {labels.PneumoniaViral.radlex_name: 1},
            {labels.Pneumonia.radlex_name: 1},
            {labels.ViralInfection.radlex_name: 1},
        ],
        "COVID-19": [
            {labels.PneumoniaViral.radlex_name: 1},
            {labels.Pneumonia.radlex_name: 1},
            {labels.ViralInfection.radlex_name: 1},
        ],
    },
)

finding_and_measuring_lungs = DatasetArgs(
    dataset_uid="05",
    dataset_name="finding_and_measuring_lungs",
    phases={"0": "CT"},
    masks={masks.Lung.radlex_name: MaskColor(source_color=255, target_color=masks.Lung.color)},
)

brain_with_intracranial_hemorrhage = DatasetArgs(
    dataset_uid="06",
    dataset_name="brain_with_intracranial_hemorrhage",
    phases={"0": "Bone", "1": "Brain"},
    labels={
        "brain_hemorrhage": [{labels.Hemorrhage.radlex_name: 1}],
        "normal": [{labels.NormalityDecriptor.radlex_name: 1}],
    },
    masks={masks.Hemorrhage.radlex_name: MaskColor(source_color=255, target_color=masks.Hemorrhage.color)},
)

lits = DatasetArgs(
    dataset_uid="07",
    dataset_name="lits",
    phases={"0": "CT"},
    labels={
        "Neoplasm": [{labels.Neoplasm.radlex_name: 1}],
        "NormalityDescriptor": [{labels.NormalityDecriptor.radlex_name: 1}],
    },
    masks={
        masks.Liver.radlex_name: MaskColor(source_color=150, target_color=masks.Liver.color),
        masks.Neoplasm.radlex_name: MaskColor(source_color=145, target_color=masks.Neoplasm.color),
    },
)

brain_tumor_detection = DatasetArgs(
    dataset_uid="08",
    dataset_name="brain_tumor_detection",
    phases={"0": "MRI"},
    labels={
        "Y": [{labels.NormalityDecriptor.radlex_name: 1}],
        "N": [{labels.Neoplasm.radlex_name: 1}],
    },
)

knee_osteoarthritis = DatasetArgs(
    dataset_uid="09",
    dataset_name="knee_osteoarthritis",
    phases={"0": "CT"},
    labels={
        "0": [{labels.NormalityDecriptor.radlex_name: 1}],
        "1": [{labels.Osteoarthritis.radlex_name: round(0.25, 2)}],
        "2": [{labels.Osteoarthritis.radlex_name: round(0.5, 2)}],
        "3": [{labels.Osteoarthritis.radlex_name: round(0.75, 2)}],
        "4": [{labels.Osteoarthritis.radlex_name: 1}],
    },
)

brain_tumor_progression = DatasetArgs(
    dataset_uid="10",
    dataset_name="brain_tumor_progression",
    phases={
        "0": "T1post",
        "1": "dT1",
        "2": "T1prereg",
        "3": "FLAIRreg",
        "4": "ADCreg",
        "5": "sRCBVreg",
        "6": "nRCBVreg",
        "7": "nCBFreg",
        "8": "T2reg",
    },  # masks based on T1 weighed
    labels={},
    masks={masks.Neoplasm.radlex_name: MaskColor(source_color=255, target_color=masks.Neoplasm.color)},
)


chest_xray14 = DatasetArgs(
    dataset_uid="11",
    dataset_name="chest_xray14",
    phases={"0": "Xray"},
    labels={
        "No Finding": [{labels.NormalityDecriptor.radlex_name: 1}],
        "Atelectasis": [{labels.Atelectasis.radlex_name: 1}],
        "Cardiomegaly": [{labels.BoxlikeHeart.radlex_name: 1}],
        "Effusion": [{labels.PleuralEffusion.radlex_name: 1}],
        "Infiltration": [{labels.Consolidation.radlex_name: 1}],
        "Mass": [{labels.Lesion.radlex_name: 1}, {labels.Mass.radlex_name: 1}],
        "Nodule": [{labels.Lesion.radlex_name: 1}],
        "Pneumonia": [{labels.Pneumonia.radlex_name: 1}],
        "Pneumothorax": [{labels.Pneumothorax.radlex_name: 1}],
        "Consolidation": [{labels.Consolidation.radlex_name: 1}],
        "Edema": [{labels.PulmonaryEdema.radlex_name: 1}],
        "Emphysema": [{labels.Emphysema.radlex_name: 1}],
        "Fibrosis": [{labels.Fibrosis.radlex_name: 1}],
        "Pleural_Thickening": [{labels.Thickening.radlex_name: 1}],
        "Hernia": [{labels.Hernia.radlex_name: 1}],
    },
)

coca = DatasetArgs(
    dataset_uid="12",
    dataset_name="coca",
    phases={"0": "CT"},
    masks={masks.CalciumScore.radlex_name: MaskColor(source_color=20, target_color=masks.CalciumScore.color)},
)

brain_met_share = DatasetArgs(
    dataset_uid="13",
    dataset_name="brain_met_share",
    phases={
        "0": "T1_weighted_preCM_spin-echo_pre-contrast",
        "1": "T1_weighted_postCM",  # This one was used to generate the masks
        "2": "T1_gradient_echo_postCM",  # using an IR-prepped FSPGR sequence
        "3": "T2_FLAIR_postCM",
    },
    masks={masks.Metastasis.radlex_name: MaskColor(source_color=255, target_color=masks.Metastasis.color)},
)

cmmd = DatasetArgs(
    dataset_uid="18",
    dataset_name="cmmd",
    phases={"0": "MG"},
    labels={
        "calcification": [{labels.Calcification.radlex_name: 1}],
        "mass": [{labels.Mass.radlex_name: 1}, {labels.Lesion.radlex_name: 1}],
        "both": [{labels.Calcification.radlex_name: 1}, {labels.Mass.radlex_name: 1}, {labels.Lesion.radlex_name: 1}],
        "Benign": [{labels.Benign.radlex_name: 1}],
        "Malignant": [{labels.Malignant.radlex_name: 1}],
    },
)
all_datasets = [obj for name, obj in globals().items() if isinstance(obj, DatasetArgs)]