Skip to content

Commit

Permalink
feat: updated focus regions clinical data extraction tool
Browse files Browse the repository at this point in the history
  • Loading branch information
lucalianas committed Aug 31, 2023
1 parent d655e20 commit b8da7a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ def _dump_row(self, focus_region_annotation, csv_writer):
'hypernephroid_pattern': focus_region_annotation.hypernephroid_pattern,
'mucinous': focus_region_annotation.mucinous,
'comedo_necrosis': focus_region_annotation.comedo_necrosis,
'total_gleason_4_area': focus_region_annotation.get_total_gleason_4_area(),
'gleason_4_percentage': focus_region_annotation.get_gleason_4_percentage()
'total_gleason_3_area': focus_region_annotation.get_total_gleason_area("G3"),
'total_gleason_4_area': focus_region_annotation.get_total_gleason_area("G4"),
'total_gleason_5_area': focus_region_annotation.get_total_gleason_area("G5"),
'gleason_3_percentage': focus_region_annotation.get_gleason_percentage("G3"),
'gleason_4_percentage': focus_region_annotation.get_gleason_percentage("G4"),
'gleason_5_percentage': focus_region_annotation.get_gleason_percentage("G5")
}
)

Expand All @@ -96,7 +100,8 @@ def _export_data(self, out_file, page_size):
'focus_region_id', 'focus_region_label', 'core_id', 'core_label', 'action_start_time',
'action_complete_time', 'creation_date', 'perineural_involvement', 'intraductal_carcinoma',
'ductal_carcinoma', 'poorly_formed_glands', 'cribriform_pattern', 'small_cell_signet_ring',
'hypernephroid_pattern', 'mucinous', 'comedo_necrosis', 'total_gleason_4_area', 'gleason_4_percentage']
'hypernephroid_pattern', 'mucinous', 'comedo_necrosis', 'total_gleason_3_area', 'gleason_3_percentage',
'total_gleason_4_area', 'gleason_4_percentage', 'total_gleason_5_area', 'gleason_5_percentage']
with open(out_file, 'w') as ofile:
writer = DictWriter(ofile, delimiter=',', fieldnames=header)
writer.writeheader()
Expand Down
15 changes: 14 additions & 1 deletion promort/clinical_annotations_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,27 @@ def get_gleason_elements(self):
return gleason_elements_map

def get_gleason_4_elements(self):
return self.get_gleason_elements()["G4"]
return self.get_gleason_elements().get("G4", [])

def get_total_gleason_area(self, gleason_pattern):
gleason_area = 0
for g in self.get_gleason_elements().get(gleason_pattern, []):
gleason_area += g.area
return gleason_area

def get_total_gleason_4_area(self):
g4_area = 0
for g4 in self.get_gleason_4_elements():
g4_area += g4.area
return g4_area

def get_gleason_percentage(self, gleason_pattern):
gleason_area = self.get_total_gleason_area(gleason_pattern)
try:
return (gleason_area / self.focus_region.area) * 100.0
except ZeroDivisionError:
return -1

def get_gleason_4_percentage(self):
g4_area = self.get_total_gleason_4_area()
try:
Expand Down

0 comments on commit b8da7a3

Please sign in to comment.