Skip to content

Commit

Permalink
Add script to fix antibody map annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikl committed Sep 24, 2024
1 parent 72b33ba commit 3e86eee
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions scripts/fix_abmaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import omero
from omero.cli import cli_login
from omero.gateway import BlitzGateway

# This script will add an empty "Antibody Name" key-value pair
# to every MapAnnotation which doesn't have one. Additionally it
# will rename all "Antibody" keys to "Antibody Name"

with cli_login() as c:
conn = BlitzGateway(client_obj=c.get_client())
queryService = conn.getQueryService()
params = omero.sys.Parameters()
query = "select m from MapAnnotation m join m.mapValue mv where m.ns='openmicroscopy.org/mapr/antibody'"
maps = conn.getQueryService().findAllByQuery(query, params)
for i, map in enumerate(maps):
nvs = map.getMapValue()
id = None
names = []
update = False
for nv in nvs:
if nv.name == "Antibody Identifier":
id = nv.value
elif nv.name == "Antibody Name":
names.append(nv.value)
elif nv.name == "Antibody":
nv.name = "Antibody Name"
update = True
names.append(nv.value)
if len(names) == 0:
nvs.append(omero.model.NamedValue("Antibody Name", ""))
map.setMapValue(nvs)
update = True
if update:
conn.getUpdateService().saveAndReturnObject(map)
print(f"{i} - {id}")

0 comments on commit 3e86eee

Please sign in to comment.