ome / omero-mapr

An OMERO.web app allowing to browse the data through attributes linked to the image
https://pypi.org/project/omero-mapr/
GNU Affero General Public License v3.0
5 stars 12 forks source link

Selected values can have custom transformations #47

Closed manics closed 1 year ago

manics commented 5 years ago

omero.web.mapr.metadata_kv_substitutions is a dict of Keys:Value-transformations that allows values in a map-annotation to be post-processed using custom HTML, e.g. to convert an identifier into a hyperlink

For example:

omero config set -- omero.web.mapr.metadata_kv_substitutions '[{
    "namespace": "idr.openmicroscopy.org/study/info",
    "key": "PubMed ID",
    "value": "<a href=\"https://www.ncbi.nlm.nih.gov/pubmed/{{value}}\">{{value}}</a>"
}]'

will convert a key-value pair PubMed ID:28775673 to PubMed ID:<a href="https://www.ncbi.nlm.nih.gov/pubmed/28775673">28775673</a>

omero config set -- omero.web.mapr.metadata_kv_substitutions '[{
    "namespace": "idr.openmicroscopy.org/study/info",
    "key": "Study Type",
    "value": "<span style=\"color:red;\"> !!! <a href=\"https://www.google.com/search?q={{value}}\" target=\"_blank\">{{value}}</a> !!! </span>"
}]'

will convert all values with Key Study Type to a Google link, surrounded by red !!!: Screen Shot 2019-05-15 at 18 43 55

--exclude

manics commented 5 years ago

I've just pushed some commits so the new key-value substitutions only apply to the specified namespace instead of all matching keys. Note Organism is still automatically linked since this is the behaviour of the existing mapr code, but I can also fix that to be consistent so idr.openmicroscopy.org/study/info Organism would not be linked.

sbesson commented 5 years ago

Thanks for the last commits. The namespace configuration was going to one of my questions.

This proposal tries to address the can we render values for specific keys within a give namespace as hyperlinks using some mapping. I can certainly see lots of use cases especially for the top-level study annotations.

Seeing how it could be configured, this made me wonder whether there are more mapr functionalities that we would like to re-use without going through the whole process of creating top-level menus? In other terms, are we trying to define a lighter omero.web.mapr.config elements? As a next step, I can certainly see us testing this using various metadata fields pointing to third-party resources. In no particular order: publication and data identifiers but also more generically any of our terms mapped to existing ontologies (Taxon, Study Type, Imaging Method, SNOMED codes...)

manics commented 5 years ago

One of the problems at the moment is that the mapr metadata panel modifies the HTML created by the webclient, whereas ideally mapr would hook into the webclient metadata panel and generate the required HTML from the KV-pairs stored as a JSON structure.

I'm not completely sure how the mapr value URLs for primary categories such as as Gene/ensemble-URLs are created but it looks like there's some magic searching of key-names containing URL within the same map-annotation.

In contrast this PR only adds the ability to transform a value and the URL template is defined statically in the mapr-config, instead of in a key-value URL entry.

I can see the argument for both adding this new behaviour to the existing primary categories to avoid requiring both the Gene ID and Gene URL (less work), but there's also a case for keeping it since the URL could include an ontology release version.

will-moore commented 5 years ago

It looks like it could be useful to have this functionality in the webclient itself, but it looks like the only way to do that is to implement it there AND here (since mapr right panel replaces webclient). So probably not worth it.

manics commented 5 years ago

It's not completely straightforward, but I think it'd be feasible to get some of the mapr features into the webclient, and enable the mapr-only transformations by allowing apps to extend webclient OME.linkify_element method. Could be worth investigating in future.

manics commented 5 years ago

Note Organism is still automatically linked since this is the behaviour of the existing mapr code, but I can also fix that to be consistent so idr.openmicroscopy.org/study/info Organism would not be linked.

Turned out it wasn't a simple fix so I've opened https://github.com/ome/omero-mapr/issues/48

The last few commits ensure the value of the key-value pair is HTML safe (since mapr modifies the displayed value in javascript the standard django filters are bypassed)

manics commented 5 years ago

Since right_plugin.general.js.html involves an additional conditional it's easier to review with whitespace ignored https://github.com/ome/omero-mapr/pull/47/files?w=1#diff-69e46b64428a744487786a148428dd70

manics commented 5 years ago

Testing locally:

$ omero config get omero.web.mapr.metadata_kv_substitutions
[{"namespace": "mapr-custom-ns", "key": "abc", "value": "<span style=\"color:green;\"> ~~~ <a href=\"https://www.google.com/search?q={{value}}\" target=\"_blank\">{{value}}</a> ~~~ </span>"}, {"namespace": "mapr-custom-ns", "value": "<span style=\"color:red;\">!!! {{value}} !!!</span>", "key": "123"}]
$ omero obj get MapAnnotation:1074
description=
id=1074
mapValue=(abc,</script><script>alert('test')</script>),(123,<>"'!&;?)
name=
ns=mapr-custom-ns
version=5
Screen Shot 2019-05-17 at 14 34 51
sbesson commented 1 year ago

Closing as this has moved out-of-sync