Skip to content

Commit

Permalink
Release 0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lucalianas committed Dec 6, 2021
2 parents 4da72ea + c36d9b6 commit 63702e1
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 106 deletions.
2 changes: 1 addition & 1 deletion promort/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0
0.9.1
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ def _dump_data(self, page_size, csv_writer):

def _dump_row(self, core_annotation, csv_writer):
try:
creation_start_date = core_annotation.creation_start_date.strftime('%Y-%m-%d %H:%M:%S')
action_start_time = core_annotation.action_start_time.strftime('%Y-%m-%d %H:%M:%S')
except AttributeError:
creation_start_date = None
action_start_time = None
try:
action_complete_time = core_annotation.action_complete_time.strftime('%Y-%m-%d %H:%M:%S')
except AttributeError:
action_complete_time = None
csv_writer.writerow(
{
'case_id': core_annotation.core.slice.slide.case.id,
Expand All @@ -69,7 +73,8 @@ def _dump_row(self, core_annotation, csv_writer):
'reviewer': core_annotation.author.username,
'core_id': core_annotation.core.id,
'core_label': core_annotation.core.label,
'creation_start_date': creation_start_date,
'action_start_time': action_start_time,
'action_complete_time': action_complete_time,
'creation_date': core_annotation.creation_date.strftime('%Y-%m-%d %H:%M:%S'),
'primary_gleason': core_annotation.primary_gleason,
'secondary_gleason': core_annotation.secondary_gleason,
Expand All @@ -79,8 +84,8 @@ def _dump_row(self, core_annotation, csv_writer):

def _export_data(self, out_file, page_size):
header = ['case_id', 'slide_id', 'rois_review_step_id', 'clinical_review_step_id', 'reviewer',
'core_id', 'core_label', 'creation_start_date', 'creation_date', 'primary_gleason',
'secondary_gleason', 'gleason_group_who_16']
'core_id', 'core_label', 'action_start_time', 'action_complete_time', 'creation_date',
'primary_gleason', 'secondary_gleason', 'gleason_group_who_16']
with open(out_file, 'w') as ofile:
writer = DictWriter(ofile, delimiter=',', fieldnames=header)
writer.writeheader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ def _dump_data(self, page_size, csv_writer):

def _dump_row(self, focus_region_annotation, csv_writer):
try:
creation_start_date = focus_region_annotation.creation_start_date.strftime('%Y-%m-%d %H:%M:%S')
action_start_time = focus_region_annotation.action_start_time.strftime('%Y-%m-%d %H:%M:%S')
except AttributeError:
creation_start_date = None
action_start_time = None
try:
action_complete_time = focus_region_annotation.action_complete_time.strftime('%Y-%m-%d %H:%M:%S')
except AttributeError:
action_complete_time = None
csv_writer.writerow(
{
'case_id': focus_region_annotation.focus_region.core.slice.slide.case.id,
Expand All @@ -70,7 +74,8 @@ def _dump_row(self, focus_region_annotation, csv_writer):
'focus_region_label': focus_region_annotation.focus_region.label,
'core_id': focus_region_annotation.focus_region.core.id,
'core_label': focus_region_annotation.focus_region.core.label,
'creation_start_date': creation_start_date,
'action_start_time': action_start_time,
'action_complete_time': action_complete_time,
'creation_date': focus_region_annotation.creation_date.strftime('%Y-%m-%d %H:%M:%S'),
'perineural_involvement': focus_region_annotation.perineural_involvement,
'intraductal_carcinoma': focus_region_annotation.intraductal_carcinoma,
Expand All @@ -88,10 +93,10 @@ def _dump_row(self, focus_region_annotation, csv_writer):

def _export_data(self, out_file, page_size):
header = ['case_id', 'slide_id', 'rois_review_step_id', 'clinical_review_step_id', 'reviewer',
'focus_region_id', 'focus_region_label', 'core_id', 'core_label', 'creation_start_date',
'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']
'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']
with open(out_file, 'w') as ofile:
writer = DictWriter(ofile, delimiter=',', fieldnames=header)
writer.writeheader()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Copyright (c) 2021, CRS4
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from django.core.management.base import BaseCommand
from django.core.paginator import Paginator
from clinical_annotations_manager.models import GleasonElement

from csv import DictWriter

import logging

logger = logging.getLogger('promort_commands')


class Command(BaseCommand):
help = """
Export existing Gleason items data to CSV.
No ROIs are exported, only metadata; to export ROIs use the extract_gleason_elements command.
"""

def add_arguments(self, parser):
parser.add_argument('--output_file', dest='output', type=str, required=True,
help='path of the output CSV file')
parser.add_argument('--page_size', dest='page_size', type=int, default=0,
help='the number of records retrieved for each page (this will enable pagination)')

def _dump_row(self, gleason_element, csv_writer):
try:
creation_start_date = gleason_element.creation_start_date.strftime('%Y-%m-%d %H:%M:%S')
except AttributeError:
creation_start_date = None
fr_ann = gleason_element.focus_region_annotation
csv_writer.writerow(
{
'case_id': fr_ann.focus_region.core.slice.slide.case.id,
'slide_id': fr_ann.focus_region.core.slice.slide.id,
'rois_review_step_id': fr_ann.annotation_step.rois_review_step.label,
'clinical_review_step_id': fr_ann.annotation_step.label,
'reviewer': fr_ann.author.username,
'focus_region_id': fr_ann.focus_region.id,
'focus_region_label': fr_ann.focus_region.label,
'core_id': fr_ann.focus_region.core.id,
'core_label': fr_ann.focus_region.core.label,
'gleason_element_id': gleason_element.id,
'gleason_type': gleason_element.gleason_type,
'creation_start_date': creation_start_date,
'creation_date': gleason_element.creation_date.strftime('%Y-%m-%d %H:%M:%S')
}
)

def _dump_data(self, page_size, csv_writer):
if page_size > 0:
logger.info('Pagination enabled (%d records for page)', page_size)
ge_qs = GleasonElement.objects.get_queryset().order_by('creation_date')
paginator = Paginator(ge_qs, page_size)
for x in paginator.page_range:
logger.info(f'-- page {x} --')
page = paginator.page(x)
for ge in page.object_list:
self._dump_row(ge, csv_writer)
else:
logger.info('Loading full batch')
gleason_elements = GleasonElement.objects.all()
for ge in gleason_elements:
self._dump_row(ge, csv_writer)

def _export_data(self, out_file, page_size):
header = ['case_id', 'slide_id', 'rois_review_step_id', 'clinical_review_step_id', 'reviewer', 'focus_region_id',
'focus_region_label', 'core_id', 'core_label', 'gleason_element_id', 'gleason_type',
'creation_start_date', 'creation_date']
with open(out_file, 'w') as ofile:
writer = DictWriter(ofile, delimiter=',', fieldnames=header)
writer.writeheader()
self._dump_data(page_size, writer)

def handle(self, *args, **opts):
logger.info('=== Starting export job ===')
self._export_data(opts['output'], opts['page_size'])
logger.info('=== Data saved to {0} ==='.format(opts['output']))
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ def _dump_data(self, page_size, csv_writer):

def _dump_row(self, slice_annotation, csv_writer):
try:
creation_start_date = slice_annotation.creation_start_date.strftime('%Y-%m-%d %H:%M:%S')
action_start_time = slice_annotation.action_start_time.strftime('%Y-%m-%d %H:%M:%S')
except AttributeError:
creation_start_date = None
action_start_time = None
try:
action_complete_time = slice_annotation.action_complete_time.strftime('%Y-%m-%d %H:%M:%S')
except AttributeError:
action_complete_time = None
csv_writer.writerow(
{
'case_id': slice_annotation.slice.slide.case.id,
Expand All @@ -69,7 +73,8 @@ def _dump_row(self, slice_annotation, csv_writer):
'reviewer': slice_annotation.author.username,
'slice_id': slice_annotation.slice.id,
'slice_label': slice_annotation.slice.label,
'creation_start_date': creation_start_date,
'action_start_time': action_start_time,
'action_complete_time': action_complete_time,
'creation_date': slice_annotation.creation_date.strftime('%Y-%m-%d %H:%M:%S'),
'high_grade_pin': slice_annotation.high_grade_pin,
'pah': slice_annotation.pah,
Expand All @@ -83,8 +88,8 @@ def _dump_row(self, slice_annotation, csv_writer):

def _export_data(self, out_file, page_size):
header = ['case_id', 'slide_id', 'rois_review_step_id', 'clinical_review_step_id', 'reviewer',
'slice_id', 'slice_label', 'creation_start_date', 'creation_date', 'high_grade_pin', 'pah',
'chronic_inflammation', 'acute_inflammation', 'periglandular_inflammation',
'slice_id', 'slice_label', 'action_start_time', 'action_complete_time', 'creation_date',
'high_grade_pin', 'pah', 'chronic_inflammation', 'acute_inflammation', 'periglandular_inflammation',
'intraglandular_inflammation', 'stromal_inflammation']
with open(out_file, 'w') as ofile:
writer = DictWriter(ofile, delimiter=',', fieldnames=header)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.1.13 on 2021-11-28 15:25

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('clinical_annotations_manager', '0017_auto_20210424_1321'),
]

operations = [
migrations.RenameField(
model_name='coreannotation',
old_name='creation_start_date',
new_name='action_start_time',
),
migrations.RenameField(
model_name='focusregionannotation',
old_name='creation_start_date',
new_name='action_start_time',
),
migrations.RenameField(
model_name='gleasonelement',
old_name='creation_start_date',
new_name='action_start_time',
),
migrations.RenameField(
model_name='sliceannotation',
old_name='creation_start_date',
new_name='action_start_time',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.1.13 on 2021-12-01 09:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('clinical_annotations_manager', '0018_auto_20211128_1525'),
]

operations = [
migrations.AddField(
model_name='coreannotation',
name='action_complete_time',
field=models.DateTimeField(default=None, null=True),
),
migrations.AddField(
model_name='focusregionannotation',
name='action_complete_time',
field=models.DateTimeField(default=None, null=True),
),
migrations.AddField(
model_name='gleasonelement',
name='action_complete_time',
field=models.DateTimeField(default=None, null=True),
),
migrations.AddField(
model_name='sliceannotation',
name='action_complete_time',
field=models.DateTimeField(default=None, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.1.13 on 2021-12-06 10:18

from django.db import migrations


def update_action_complete_time(apps, schema_editor):
GleasonElements = apps.get_model('clinical_annotations_manager', 'GleasonElement')
for g_element in GleasonElements.objects.all():
g_element.action_complete_time = g_element.creation_date
g_element.creation_date = g_element.focus_region_annotation.creation_date
g_element.save()


def reverse_action_complete_time(apps, schema_editor):
GleasonElements = apps.get_model('clinical_annotations_manager', 'GleasonElement')
for g_element in GleasonElements.objects.all():
g_element.creation_date = g_element.action_complete_time
g_element.action_complete_time = None
g_element.save()


class Migration(migrations.Migration):

dependencies = [
('clinical_annotations_manager', '0019_auto_20211201_0933'),
]

operations = [
migrations.RunPython(update_action_complete_time, reverse_action_complete_time),
]
Loading

0 comments on commit 63702e1

Please sign in to comment.