Skip to content

Commit

Permalink
Merge pull request #8 from NFDI4BIOIMAGE/dev
Browse files Browse the repository at this point in the history
Support for multiple images
  • Loading branch information
MicheleBortol authored Sep 6, 2024
2 parents cdde8bb + 2141f2e commit b47ce48
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .omeroci/app-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env bash
source /infra/utils
set -e
set +u
cd $TARGET
# add the app to omero.web.apps
value=$(get_app_name)
# Configuration commands

su - omero-web -c "env OMERODIR=$OMERODIR /opt/omero/web/venv3/bin/omero config set omero.web.apps '[\"$value\"]'"
su - omero-web -c "env OMERODIR=$OMERODIR /opt/omero/web/venv3/bin/omero config set omero.web.omero_vitessce.serveraddress '"http://localhost:4080"'"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Only files attached to the dataset/image are available in the form.

The following fields are available:
- `Config file name` (required, "VitessceConfig-YYYY.MM.DD_HHMMSS.json"): Name of the config file to attach, a ".json" extension is added if missing.
- `Image` (required): OMERO Image to view.
- `Images` (required): OMERO Image(s) to view, assumes the same pixel size for all images.
- `Segmentation` (optional, `None`): Label image to overlay on the image, pixel values correspond to cell identities.
- `Cell identities` (optional, `None`): `.csv` file with at least 2 columns: `Cell id column` and `Label column` defined in the 2 fields below.
- `Cell id column` (optional, "cell_id"): Name of the `Cell id column` used in `Cell identities`, `Expression`, `Embeddings`.
Expand Down
14 changes: 8 additions & 6 deletions omero_vitessce/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class ConfigForm(forms.Form):

config_file_name_help = "Name of the config file to use, \
a '.json' extension is added if missing."
image_help = "OMERO Image to view."
images_help = "OMERO Image(s) to view, assumes identical pixel size."
segmentation_help = "Label image to overlay on the image, \
pixel values correspond to cell identities."
pixel values should correspond to cell identities."
cell_identities_help = ".csv file with at least 2 columns: \
Cell id column and Label column defined in the 2 fields below."
cell_id_help = "Name of the Cell id column used in \
Expand Down Expand Up @@ -60,19 +60,21 @@ def __init__(self, file_names, file_urls,
self.text_choices, self.image_choices = self.prepare_choices(
file_names, file_urls, img_names, img_urls)

# Configuration file fields
filename = self.make_config_file_name()

self.fields["config_file_name"] = forms.CharField(
empty_value=filename, strip=True,
min_length=1, max_length=40, required=False,
help_text=ConfigForm.config_file_name_help)

# images field
# No empty default, we alway want an image in the config
self.fields["image"] = forms.ChoiceField(
self.fields["images"] = forms.MultipleChoiceField(
choices=self.image_choices[1:], required=True,
help_text=ConfigForm.image_help)
help_text=ConfigForm.images_help)

# Cell data
# Cell data fields
self.fields["segmentation"] = forms.ChoiceField(
choices=self.image_choices, required=False,
help_text=ConfigForm.segmentation_help)
Expand Down Expand Up @@ -109,7 +111,7 @@ def __init__(self, file_names, file_urls,
min_length=1, max_length=20, required=False,
help_text=ConfigForm.embeddings_y_help)

# Molecule data
# Molecule data fields
self.fields["molecules"] = forms.ChoiceField(
choices=self.text_choices, required=False,
help_text=ConfigForm.molecules_help)
Expand Down
2 changes: 1 addition & 1 deletion omero_vitessce/omero_vitessce_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def str_not_empty(o):

OMEROVITESSCE_SETTINGS_MAPPINGS = {
'omero.web.omero_vitessce.serveraddress': ['SERVER_ADDRESS',
'"http://localhost:4080"',
'""',
str_not_empty, None]
}

Expand Down
6 changes: 3 additions & 3 deletions omero_vitessce/templates/omero_vitessce/vitessce_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
Images</th>
</tr>
<tr>
<th><div class="tooltip">{{ form.image.label_tag }}
<span class="tooltiptext">{{ form.image.help_text }}</span>
<th><div class="tooltip">{{ form.images.label_tag }}
<span class="tooltiptext">{{ form.images.help_text }}</span>
</div></th>
<th style="text-align:left;">{{ form.image }}</th>
<th style="text-align:left;">{{ form.images }}</th>
<tr style="height:30px">
<th colspan="2" style="text-align:center;vertical-align:bottom">
Cell Data</th>
Expand Down
17 changes: 15 additions & 2 deletions omero_vitessce/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from omero.util.temp_files import create_path

from .forms import ConfigForm
from . import omero_vitessce_settings

from vitessce import VitessceConfig, OmeZarrWrapper, MultiImageWrapper
Expand Down Expand Up @@ -149,14 +150,26 @@ def create_config(config_args, obj_type, obj_id, conn):
the results from the form are used as args.
"""

# If an attachment/image is deleted/moved between the Vitessce right tab
# plugin is loaded and the form is submitted then it will not be found
# and will not be present in the cleaned_data -> None
file_names, file_urls, img_files, img_urls = get_files_images(
obj_type, obj_id, conn)
config_args = ConfigForm(data=config_args, file_names=file_names,
file_urls=file_urls, img_names=img_files,
img_urls=img_urls)
config_args = config_args.cleaned_data

description, name = get_details(obj_type, obj_id, conn)

vc = VitessceConfig(schema_version="1.0.16",
name=name, description=description)
vc_dataset = vc.add_dataset()

img_url = config_args.get("image")
images = [OmeZarrWrapper(img_url=img_url, name="Image")]
images = []
img_urls = config_args.get("images")
for n, img_url in enumerate(img_urls):
images.append(OmeZarrWrapper(img_url=img_url, name=f"Image {n}"))

sp = vc.add_view(Vt.SPATIAL, dataset=vc_dataset)
lc = vc.add_view(Vt.LAYER_CONTROLLER, dataset=vc_dataset)
Expand Down
3 changes: 2 additions & 1 deletion omero_vitessce/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def vitessce_panel(request, obj_type, obj_id, conn=None, **kwargs):
if OMERO_WEB_ZARR:
files, urls, img_files, img_urls = get_files_images(
obj_type, obj_id, conn)
form = ConfigForm(files, urls, img_files, img_urls)
form = ConfigForm(file_names=files, file_urls=urls,
img_names=img_files, img_urls=img_urls)
context["form"] = form
else:
context["form"] = None
Expand Down

0 comments on commit b47ce48

Please sign in to comment.