Neuroglancer Annotation Manager

This page lists the classes and methods used to administer the annotations that are entered by either an anatomist via Neuroglancer, or by the cell detector process.


This module is responsible for the saving and restoring of the three different annotations.

  1. Saving annotations - when the user clicks ‘Save annotations’ in Neuroglancer:

  1. All data from the active layer gets sent to one of the three tables:

    • Marked cells

    • Polygon sequences

    • Structure COM

2. Data also gets sent to the annotations_point_archive table. This table has a unique constraint. When the same data gets sent to the database, it updates it instead of creating new useless inserts. This is done by Django’s built-in bulk_create method with the ‘ignore_conficts’ flag set to true. It also finds an existing archive, or creates a new archive and uses that key for the FK_archive_set_ID. The constraint is on these columns:

  • Session ID (FK_session_id)

  • x Decimal(8,2) - formerly a float

  • y Decimal(8,2) - formerly a float

  • z Decimal(8,2) - formerly a float

  1. Restoring annotations

1. This occurs when the user checks one and only one checkbox on the archive page. After selecting a checkbox, the user chooses the ‘Restore the selected archive’ option from the dropdown menu. Once the user clicks ‘Go’, these events take place:

  1. Get requested archive (set of points in the annotations_points_archive table)

  2. Mark session inactive that is in the archive

  3. Create a new active session and add it to either marked_cell, polygon_sequence or structureCOM

class neuroglancer.annotation_manager.AnnotationManager(neuroglancerModel)

This class handles the management of annotations into the three tables:

  1. MarkedCells

  2. StructureCOM

  3. PolygonSequence

add_com(annotationi: Annotation, annotation_session: AnnotationSession)

Helper method to add a COM to the bulk manager.

Parameters
  • annotationi – A COM annotation

  • annotation_session – session object

add_polygons(annotationi: Annotation, annotation_session: AnnotationSession)

Helper method to add a polygon to the bulk manager.

Parameters
  • annotationi – A polygon annotation

  • annotation_session – session object

add_volumes(annotationi: Annotation, annotation_session: AnnotationSession)

Helper method to add a volume to the bulk manager.

Parameters
  • annotationi – A COM annotation

  • annotation_session – session object

archive_and_insert_annotations()

The main function that updates the database with annotations in the current_layer attribute. This function loops each annotation in the current layer and inserts data into the bulk manager. At the end of the loop, all data is in the bulk manager and it gets inserted. We also save the session to update the updated column.

archive_annotations(annotation_session: AnnotationSession)

Move the existing annotations into the archive. First, we get the existing rows and then we insert those into the archive table. This is a background task.

Parameters

annotation_session – annotation session object

create_marked_cell(annotationi: Annotation, annotation_session: AnnotationSession, cell_type, source) MarkedCell

Helper method to create a MarkedCell object.

Parameters
  • annotationi – A COM annotation

  • annotation_session – session object

  • cell_type – the cell type object of the marked cell

  • source – the MARKED/UNMARKED source

Returns

MarkedCell object

create_new_archive(annotation_session)

Helper method to create a new session

Parameters

annotation_session – session object

create_new_session(brain_region: BrainRegion, annotation_type: str)

Helper method to create a new annotation_session

Parameters
  • brain_region – brain region object AKA structure

  • annotation_type – either marked cell or polygon or COM

get_archive(annotation_session)

Gets either the existing archive or creates a new one.

Parameters

annotation_session – session object

get_session(brain_region, annotation_type)

Gets either the existing session or creates a new one. We first try by trying to get the exact UrlModel (AKA, neuroglancer state). If that doesn’t succeed, we try without the state ID

Parameters
  • brain_region – brain region object AKA structure

  • annotation_type – either marked cell or polygon or COM

is_structure_com(annotationi: Annotation)

Determines if a point annotation is a structure COM. A point annotation is a COM if the description corresponds to a structure existing in the database.

Parameters

(Annotation) (annotationi) – the annotation object

Return boolean

True or False

set_current_layer(state_layer)
set the current layer attribute from a layer component of neuroglancer json state.

The incoming neuroglancer json state is parsed by a custom class named AnnotationLayer that groups points according to it’s membership to a polygon seqence or volume

Parameters

(dict) (state_layer) – neuroglancer json state component of an annotation layer in dictionary form