Skip to content

Commit

Permalink
Release v0.9.4-2
Browse files Browse the repository at this point in the history
  • Loading branch information
lucalianas committed May 5, 2022
2 parents ca407c1 + 37f7aff commit 051e1e3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion promort/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.4
0.9.4-2
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,19 @@ def _get_core_bounds(self, core: Dict) -> Dict:
except IndexError:
raise InvalidPolygonError()

def _group_nearest_cores(self, cores, height_tolerance=0.01):
def _group_nearest_cores(self, cores):
cores_map, sorted_y_coords = self._get_sorted_cores_map(cores)
cores_groups = list()
tolerance = sorted_y_coords[-1][1] * height_tolerance
current_group = cores_map[sorted_y_coords[0]]
cg_max_y = sorted_y_coords[0][1]
for i, yc in enumerate(sorted_y_coords[1:]):
if yc[0] <= sorted_y_coords[i][1] + tolerance:
if yc[0] <= cg_max_y:
current_group.extend(cores_map[yc])
cg_max_y = max([cg_max_y, yc[1]])
else:
cores_groups.append(current_group)
current_group = cores_map[yc]
cg_max_y = yc[1]
cores_groups.append(current_group)
return cores_groups

Expand Down
13 changes: 11 additions & 2 deletions promort/reviews_manager/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from django.contrib.auth.models import User
from predictions_manager.models import Provenance

from rest_framework import serializers

Expand Down Expand Up @@ -280,6 +281,7 @@ class PredictionReviewSerializer(serializers.ModelSerializer):
slug_field='username',
queryset=User.objects.all()
)
model = serializers.SerializerMethodField()
started = serializers.SerializerMethodField()
completed = serializers.SerializerMethodField()
annotation_type = serializers.SerializerMethodField()
Expand All @@ -288,9 +290,16 @@ class PredictionReviewSerializer(serializers.ModelSerializer):
class Meta:
model = PredictionReview

fields = ('id', 'label', 'annotation_type', 'prediction', 'slide', 'reviewer',
fields = ('id', 'label', 'annotation_type', 'prediction', 'slide', 'reviewer', 'model',
'creation_date', 'start_date', 'completion_date', 'started', 'completed')
read_only_fields = ('id', 'creation_date', 'started', 'completed', 'annotation_type')
read_only_fields = ('id', 'creation_date', 'started', 'completed', 'annotation_type', 'model')

@staticmethod
def get_model(obj):
try:
return Provenance.objects.filter(prediction=obj.prediction).first().model
except AttributeError:
return None

@staticmethod
def get_started(obj):
Expand Down
30 changes: 21 additions & 9 deletions promort/rois_manager/management/commands/extract_focus_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ def add_arguments(self, parser):
help='path of the output folder for the extracted JSON objects')
parser.add_argument('--limit-bounds', dest='limit_bounds', action='store_true',
help='extract ROIs considering only the non-empty slide region')

def _load_rois_annotation_steps(self):
steps = ROIsAnnotationStep.objects.filter(completion_date__isnull=False)
parser.add_argument('--reviewer', dest='reviewer', type=str,
help='filter review steps by reviewer username')
parser.add_argument('--tissue-type', dest='tissue_type', type=str,
choices=['TUMOR', 'NORMAL'], help='filter focus regions by tissue type')

def _load_rois_annotation_steps(self, reviewer=None):
if reviewer is not None:
logger.info(f'Filtering by reviewer: {reviewer}')
steps = ROIsAnnotationStep.objects.filter(completion_date__isnull=False,
rois_annotation__reviewer__username=reviewer)
else:
steps = ROIsAnnotationStep.objects.filter(completion_date__isnull=False)
return steps

def _get_slide_bounds(self, slide):
Expand Down Expand Up @@ -112,8 +121,11 @@ def _dump_details(self, details, out_folder):
writer.writeheader()
writer.writerows(details)

def _dump_focus_regions(self, step, out_folder, limit_bounds):
focus_regions = step.focus_regions
def _dump_focus_regions(self, step, out_folder, limit_bounds, tissue_type=None):
if tissue_type is None:
focus_regions = step.focus_regions
else:
focus_regions = [fr for fr in step.focus_regions if fr.tissue_status == tissue_type]
slide = step.slide
logger.info('Loading info for slide %s', slide.id)
if not limit_bounds:
Expand All @@ -135,13 +147,13 @@ def _dump_focus_regions(self, step, out_folder, limit_bounds):
focus_regions_details.append(frd)
self._dump_details(focus_regions_details, out_path)

def _export_data(self, out_folder, limit_bounds=False):
steps = self._load_rois_annotation_steps()
def _export_data(self, out_folder, limit_bounds=False, reviewer=None, tissue_type=None):
steps = self._load_rois_annotation_steps(reviewer)
logger.info('Loaded %d ROIs Annotation Steps', len(steps))
for s in steps:
self._dump_focus_regions(s, out_folder, limit_bounds)
self._dump_focus_regions(s, out_folder, limit_bounds, tissue_type)

def handle(self, *args, **opts):
logger.info('=== Starting export job ===')
self._export_data(opts['out_folder'], opts['limit_bounds'])
self._export_data(opts['out_folder'], opts['limit_bounds'], opts['reviewer'], opts['tissue_type'])
logger.info('=== Export completed ===')
3 changes: 3 additions & 0 deletions promort/static_src/templates/worklist/pending_reviews.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ <h1>WORKLIST - Pending annotations</h1>
<strong>Review ID:</strong> {{ annotation.extended_label }}
</p>
<p><strong>Review Type:</strong> {{ annotation.annotation_type }}</p>
<p ng-show="wlc.isPredictionReview(annotation)">
<strong>Model:</strong> {{ annotation.model }}
</p>
<p ng-show="!wlc.isQuestionnaireRequest(annotation) && !wlc.isPredictionReview(annotation)">
<strong>Slides count:</strong> {{ annotation.steps_count | number:0 }}
</p>
Expand Down

0 comments on commit 051e1e3

Please sign in to comment.