omero.util.metadata_mapannotations module

Utilities for manipulating map-annotations used as metadata

class util.metadata_mapannotations.CanonicalMapAnnotation(ma, primary_keys=None)[source]

Bases: object

A canonical representation of a map-annotation for metadata use This is based around the idea of a primary key derived from the combination of the namespace with 1+ keys-value pairs. A null namespace is treated as an empty string (‘’), but still forms part of the primary key.

Parameters:
  • ma – The omero.model.MapAnnotation object

  • primary_keys – Keys from key-value pairs that will be used to form the primary key.

add_parent(parenttype, parentid)[source]

Add a parent descriptor Parameter types are important because they are used in a set

Parameters:
  • parenttype – An OMERO type string

  • parentid – An OMERO object ID (integer)

get_mapann()[source]

Update and return an omero.model.MapAnnotation with merged/combined fields

get_parents()[source]
merge(other)[source]

Adds any key/value pairs from other that aren’t in self Adds parents from other Does not update primary key

merge_parents(other)[source]
process_keypairs(kvpairs, primary_keys)[source]
class util.metadata_mapannotations.MapAnnotationManager(combine=0)[source]

Bases: object

Handles creation and de-duplication of MapAnnotations

MA_APPEND = 0
MA_NEW = 2
MA_OLD = 1
add(cma)[source]

Adds a CanonicalMapAnnotation to the managed list.

Returns any CanonicalMapAnnotation that are no longer required, this may be cma or it may be a previously added annotation. The idea is that this can be used to de-duplicate existing OMERO MapAnnotations by calling add() on all MapAnnotations and deleting those which are returned

If MapAnnotations are combined the parents of the unwanted MapAnnotations are appended to the one that is kept by the manager.

Parameters:

cma – A CanonicalMapAnnotation

add_from_namespace_query(session, ns, primary_keys)[source]

Fetches all map-annotations with the given namespace This will only work if there are no duplicates, otherwise an exception will be thrown

WARNING: You should probably only use this in MA_APPEND mode since the parents of existing annotations aren’t fetched (requires a query for each parent type) WARNING: This may be resource intensive TODO: Use omero.utils.populate_metadata._QueryContext for batch queries

Parameters:
  • session – An OMERO session

  • ns – The namespace

  • primary_keys – Primary keys

get_map_annotations()[source]
exception util.metadata_mapannotations.MapAnnotationPrimaryKeyException(message)[source]

Bases: Exception