Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

populate metadata links file ann #152

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions omero/import_scripts/Populate_Metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,34 @@
"""


def get_original_file(conn, object_type, object_id, file_ann_id=None):
def link_file_ann(conn, object_type, object_id, file_ann_id):
"""Link File Annotation to the Object, if not already linked."""
file_ann = conn.getObject("Annotation", file_ann_id)
if file_ann is None:
sys.stderr.write("Error: File Annotation not found: %s.\n"
% file_ann_id)
sys.exit(1)
omero_object = get_object(conn, object_type, object_id)
# Check for existing links
links = list(conn.getAnnotationLinks(object_type, parent_ids=[object_id],
ann_ids=[file_ann_id]))
if len(links) == 0:
omero_object.linkAnnotation(file_ann)


def get_object(conn, object_type, object_id):
if object_type not in OBJECT_TYPES:
sys.stderr.write("Error: Invalid object type: %s.\n" % object_type)
sys.exit(1)
omero_object = conn.getObject(object_type, int(object_id))
if omero_object is None:
sys.stderr.write("Error: %s does not exist.\n" % object_type)
sys.exit(1)
return omero_object


def get_original_file(conn, object_type, object_id, file_ann_id=None):
omero_object = get_object(conn, object_type, object_id)
file_ann = None

for ann in omero_object.listAnnotations():
Expand All @@ -85,10 +105,11 @@ def get_original_file(conn, object_type, object_id, file_ann_id=None):
def populate_metadata(client, conn, script_params):
object_ids = script_params["IDs"]
object_id = object_ids[0]
data_type = script_params["Data_Type"]
file_ann_id = None
if "File_Annotation" in script_params:
file_ann_id = int(script_params["File_Annotation"])
data_type = script_params["Data_Type"]
link_file_ann(conn, data_type, object_id, file_ann_id)
original_file = get_original_file(
conn, data_type, object_id, file_ann_id)
provider = DownloadingOriginalFileProvider(conn)
Expand Down