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

Update #9

Merged
merged 9 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ jobs:
name: Build and publish Python distribution to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- uses: actions/setup-node@v4
- name: Run flake8
run: |
python -mpip install flake8
flake8 .
- name: Build a binary wheel and a source tarball
run: |
python -mpip install wheel
Expand Down
26 changes: 17 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
.. image:: https://github.com/German-BioImaging/omero-autotag/workflows/PyPI/badge.svg
:target: https://github.com/German-BioImaging/omero-autotag/actions

.. image:: https://badge.fury.io/py/omero-autotag.svg
:target: https://badge.fury.io/py/omero-autotag


OMERO.autotag
================
=============

OMERO.autotag is a plugin for `OMERO.web <https://github.com/ome/omero-web>`_ that automates the application of tags to images based on the
original filename, path, and extensions of the images.

Expand All @@ -12,9 +20,9 @@ As Python 2 has now reached end-of-life, OMERO 5.6 now
requires Python 3. With release 3.1.0 of autotag, the following are now required. To use autotag on older OMERO systems (running Python 2),
please use versions older than 3.1.0.

* Python 3.5 or later
* Python 3.8 or later
* omero-web 5.6 or later
* django 1.11 or later
* django 4.2 or later

User Documentation
==================
Expand Down Expand Up @@ -122,14 +130,14 @@ Harvard Medical School, then later extended by DPWR
Consulting Ltd.

These plugins were developed originally with the
support of [Micron Advanced Bioimaging Unit](https://micronoxford.com/)
support of `Micron Advanced Bioimaging Unit <https://micronoxford.com/>`_
funded by the Wellcome Trust Strategic Award 091911,
and [Open Microscopy](https://www.openmicroscopy.org/).
and `Open Microscopy <https://www.openmicroscopy.org/>`_.

Continued development was supported by [The Laboratory
of Systems Pharmacology, Harvard Medical School](https://hits.harvard.edu/the-program/laboratory-of-systems-pharmacology/research-program/) and
[Research Computing, Harvard Medical School](https://it.hms.harvard.edu/our-services/research-computing).
Continued development was supported by `The Laboratory
of Systems Pharmacology, Harvard Medical School <https://hits.harvard.edu/the-program/laboratory-of-systems-pharmacology/research-program/>`_ and
`Research Computing, Harvard Medical School <https://it.hms.harvard.edu/our-services/research-computing>`_.

Continued development was sponsored by
[Micron Advanced Bioimaging Unit](https://micronoxford.com/)
`Micron Advanced Bioimaging Unit <https://micronoxford.com/>`_
funded by the Wellcome Trust Strategic Award 107457.
25 changes: 13 additions & 12 deletions omero_autotag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,48 @@
from omero.rtypes import rlong


def createTagAnnotationsLinks(conn, additions=[], removals=[]):
def create_tag_annotations_links(conn, additions=[], removals=[]):
"""
Links or unlinks existing Images with existing Tag annotations

@param additions: List of tags to add to images
@param additions: List of tags to remove from images
"""

newLinks = []
new_links = []
# Create a list of links to apply
for addition in additions:
link = omero.model.ImageAnnotationLinkI()
link.parent = omero.model.ImageI(addition[0], False)
link.child = omero.model.TagAnnotationI(addition[1], False)
newLinks.append(link)
new_links.append(link)

# Apply the links
failed = 0
savedLinks = []
saved_links = []
svc = conn.getUpdateService()
try:
# will fail if any of the links already exist
savedLinks = conn.getUpdateService().saveAndReturnArray(
newLinks, conn.SERVICE_OPTS
saved_links = svc.saveAndReturnArray(
new_links, conn.SERVICE_OPTS
)
except omero.ValidationException:
# This will occur if the user has modified the tag landscape outside
# of the auto-tagger while using the auto-tagger. Not likely to often
# happen, but very possible.

for link in newLinks:
for link in new_links:
try:
savedLinks.append(
conn.getUpdateService().saveAndReturnObject(link, conn.SERVICE_OPTS)
saved_links.append(
svc.saveAndReturnObject(link, conn.SERVICE_OPTS)
)
except omero.ValidationException:
failed += 1

if len(removals) > 0:
# Get existing links belonging to current user (all at once to save
# on queries)
allImageIds, allTagIds = list(zip(*removals))
all_image_ids, all_tag_ids = list(zip(*removals))

params = omero.sys.Parameters()
params.theFilter = omero.sys.Filter()
Expand All @@ -52,8 +53,8 @@ def createTagAnnotationsLinks(conn, additions=[], removals=[]):
# tags, otherwise we'd have to get them individually.
links = conn.getAnnotationLinks(
"Image",
parent_ids=list(allImageIds),
ann_ids=list(allTagIds),
parent_ids=list(all_image_ids),
ann_ids=list(all_tag_ids),
params=params,
)

Expand Down
12 changes: 6 additions & 6 deletions omero_autotag/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import omero
from omero.rtypes import rstring, unwrap
from omeroweb.webclient import tree
from .utils import createTagAnnotationsLinks
from .utils import create_tag_annotations_links

logger = logging.getLogger(__name__)

Expand All @@ -30,19 +30,19 @@ def process_update(request, conn=None, **kwargs):
removals = []

for image in images:
image_id = image["imageId"]
iid = image["imageId"]

additions.extend(
[(int(image_id), int(addition),) for addition in image["additions"]]
[(int(iid), int(addition),) for addition in image["additions"]]
)

removals.extend(
[(int(image_id), int(removal),) for removal in image["removals"]]
[(int(iid), int(removal),) for removal in image["removals"]]
)

# TODO Interface for createTagAnnotationsLinks is a bit nasty, but go
# TODO Interface for create_tag_annotations_links is a bit nasty, but go
# along with it for now
createTagAnnotationsLinks(conn, additions, removals)
create_tag_annotations_links(conn, additions, removals)

return HttpResponse("")

Expand Down
33 changes: 17 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,23 @@ def run(self):
description=DESCRIPTION,
long_description=read_file("README.rst"),
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: JavaScript",
"Programming Language :: Python :: 3",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Internet :: WWW/HTTP :: WSGI",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Software Development :: Libraries :: " "Application Frameworks",
"Topic :: Text Processing :: Markup :: HTML",
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU Affero General Public License v3',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: JavaScript',
'Programming Language :: Python :: 3',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Internet :: WWW/HTTP :: WSGI',
'Topic :: Scientific/Engineering :: Visualization',
'Topic :: Software Development :: Libraries :: '
'Application Frameworks',
'Topic :: Text Processing :: Markup :: HTML'
],
author=AUTHOR,
author_email="dpwrussell@gmail.com",
Expand Down