Skip to content

Commit

Permalink
Merge pull request #4 from NFDI4BIOIMAGE/dev
Browse files Browse the repository at this point in the history
Options for genrating configuration files.
  • Loading branch information
MicheleBortol authored Aug 20, 2024
2 parents 92d588f + 1d9b1e7 commit a224704
Show file tree
Hide file tree
Showing 79 changed files with 367 additions and 138 deletions.
51 changes: 39 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,62 @@ The plugin can be used with:
- `Open with` `->` `Vitessce` on the left side panel.

#### Right-hand-side panel:
- **Prexisting config files**:
![Right-Config](https://github.com/user-attachments/assets/b8fea5f0-1d8f-4578-a577-8744d32dcaa5)
Clicking the link will open a new tab with the viewer displaying the selected configuration.
- **Autogenerating config file**:
![Right-Auto](https://github.com/user-attachments/assets/8dfa22cc-dbb5-493d-b837-d609a11a1346)
Clicking the button will autogenerate a config file and attach it to the dataset/image, and the viewer displaying the autogenerated configuration.
- **Prexisting config files**:

Clicking the link will open a new tab with the viewer displaying the selected configuration.
![Link-List-image](https://github.com/user-attachments/assets/b95c77a3-77c5-4221-83f2-c9c460a83f2e)


- **Autogenerating config file**:

The form allows the user to automatically generate a config file with the selected parameters. After clicking the `Generate Config` button
a config file is generated and attached to the dataset/image. The viewer displaying the autogenerated configuration will open in a new tab.
![Form-image](https://github.com/user-attachments/assets/5c81aba3-adfd-465c-86f0-9e03506ec3ea)

#### Open-with:
Right click on a `dataset` or an `images` in the left-panel and select `open-with` -> `Vitessce`.
This will open the vitessce viewer in a new tab using the first configuration file attachement.
![Openwith-image](https://github.com/user-attachments/assets/f75cc27c-4cd3-4a19-ae20-7d8f0a47aa87)

### Viewer window
After using a The Vitessce viewer is opened in a new tab:
![image](https://github.com/user-attachments/assets/77de517e-67e4-42d6-a2b6-2a3a6a11dc7e)
After autogenerating or selecting a config file, the Vitessce viewer is opened in a new tab:
![Viewer GIF](https://github.com/user-attachments/assets/719a3093-2a6a-480d-afc9-522b4873310e)



### Config files
The omero-vitessce plugin considers all files with the `.json.txt` extension attached to the image or dataset as config files for the viewer.
The omero-vitessce plugin considers all files with the `.json` extension attached to the image or dataset as config files for the viewer.
The config files should follow the vitessce view-config-json format: http://vitessce.io/docs/view-config-json/

#### Autogenerated config files
Config files can be autogenerated for:
- `images`: A spatial view and a layer controller view are setup for the image.
- `datasets`: All images in the dataset are bundled togheter and a spatial view and a layer controller are setup.
- `images`
- `datasets`

Assumes that the images are in the OME-NGFF format v0.4 and that [omero-web-zarr](https://github.com/ome/omero-web-zarr) is
available to serve the images.
The attachements must be in `.csv` format and the column with the cell identifiers should be consistent across attachements.
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, OME-NGFF images only.
`Segmentation` (optional, `None`): Segmentation to overlay on the image, OME-NGFF images only.
`Cell identities` (optional, `None`): `.csv` file with at least 2 columns: `Cell id column` and `Label column` defined in the 2 fileds below.
`Cell id column` (optional, "cell_id"): Name of the `Cell id column` used in `Cell identities`, `Expression`, `Embeddings`.
`Label column` (optional, "label"): Name of the `Label` used in `Cell identities`.
`Expression` (optional, `None`): `.csv` file with the `Cell id column` all other columns are considered as expression values and should be numerical.
`Embeddings` (optional, `None`): `.csv` file with the `Cell id column` and the `Embedding x` and `Embedding y` columns defined in the 2 fileds below.
`Embedding x` (optional, "UMAP_1"): Name of the `Embedding x` used in `Embeddings`.
`Embedding y` (optional, "UMAP_2"): Name of the `Embedding y` used in `Embeddings`.
`Histograms` (required , `True`): Add 3 plots showing: The number of transcripts per cell, the number of cells in each set, gene expression in each set.
`Heatmap` (required , `True`): Adds an heatmap.

The `Expression` and `Cell identities` files are required to show the histograms.
The `Embeddings` file is necessary to show the cells in a scatterplot.

#### Custom config files
Custom config files should have a `.json.txt` extension and added as attachements to a dataset or an image.
Custom config files should have a `.json` extension and added as attachements to a dataset or an image.
The configuration files does not need to refer to the dataset / image it is attached to and can refer to other images.

For how to create a custom config file see:
Expand All @@ -101,6 +127,7 @@ Development
## Sources

The main sources are:
- omero-vitessce from Will Moore: https://github.com/will-moore/omero-vitessce
- cookiecutter-omero-webapp: https://github.com/ome/cookiecutter-omero-webapp
- `react_webapp` from omero-web-apps-examples: https://github.com/ome/omero-web-apps-examples/tree/master/react-webapp
- Vitessce python package used for generating config files http://python-docs.vitessce.io/
Expand Down
90 changes: 90 additions & 0 deletions omero_vitessce/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import datetime

from django import forms


class ConfigForm(forms.Form):
""" Form used to collect the parameters used to
automatically generate a config file for Vitessce
"""

default_cell_id_col = "cell_id"
default_label_col = "label"
default_embedding_x_col = "UMAP_1"
default_embedding_y_col = "UMAP_2"

def __init__(self, file_names, file_urls,
img_names, img_urls, *args, **kwargs):
super(ConfigForm, self).__init__(*args, **kwargs)

self.text_choices, self.image_choices = self.prepare_choices(
file_names, file_urls, img_names, img_urls)

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)

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

self.fields["segmentation"] = forms.ChoiceField(
choices=self.image_choices, required=False)

self.fields["cell identities"] = forms.ChoiceField(
choices=self.text_choices, required=False)

self.fields["cell id column"] = forms.CharField(
empty_value=ConfigForm.default_cell_id_col, strip=True,
min_length=1, max_length=20, required=False)

self.fields["label column"] = forms.CharField(
empty_value=ConfigForm.default_label_col, strip=True,
min_length=1, max_length=20, required=False)

self.fields["expression"] = forms.ChoiceField(
choices=self.text_choices, required=False)

self.fields["embeddings"] = forms.ChoiceField(
choices=self.text_choices, required=False)

self.fields["embedding x"] = forms.CharField(
empty_value=ConfigForm.default_embedding_x_col, strip=True,
min_length=1, max_length=20, required=False)

self.fields["embedding y"] = forms.CharField(
empty_value=ConfigForm.default_embedding_y_col, strip=True,
min_length=1, max_length=20, required=False)

self.fields["histograms"] = forms.BooleanField(initial=True,
required=False)
self.fields["heatmap"] = forms.BooleanField(initial=True,
required=False)

# Set default values for CharField fields
self.fields["config file name"].initial = filename
self.fields["cell id column"].initial = ConfigForm.default_cell_id_col
self.fields["label column"].initial = ConfigForm.default_label_col
self.fields["embedding x"].initial = ConfigForm.default_embedding_x_col
self.fields["embedding y"].initial = ConfigForm.default_embedding_y_col

def make_config_file_name(self):
""" Creates the default config file name with a timestamp:
VitessceConfig-yyyy.mm.dd_hhmmss.json
"""
ts = datetime.datetime.now().strftime("%Y.%m.%d_%H%M%S")
filename = "VitessceConfig-" + ts + ".json"
return filename

def prepare_choices(self, file_names, file_urls, img_names, img_urls):
""" Makes the lists of images and attached files for the form
"""
self.text_choices = [i for i in zip(file_urls, file_names)]
self.image_choices = [i for i in zip(img_urls, img_names)]

self.text_choices.insert(0, ('', '---'))
self.image_choices.insert(0, ('', '---'))

return self.text_choices, self.image_choices
2 changes: 2 additions & 0 deletions omero_vitessce/static/js/113.7e38aec5.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions omero_vitessce/static/js/113.7e38aec5.chunk.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions omero_vitessce/static/js/160.cd6c2778.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions omero_vitessce/static/js/160.cd6c2778.chunk.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit a224704

Please sign in to comment.