7
7
from omeroweb .webclient .decorators import login_required
8
8
9
9
from . import omero_vitessce_settings
10
+ from .forms import ConfigForm
10
11
11
12
from vitessce import VitessceConfig , OmeZarrWrapper , MultiImageWrapper
12
13
from vitessce import ViewType as Vt , FileType as Ft , CoordinationType as Ct
15
16
SERVER = omero_vitessce_settings .SERVER_ADDRESS [1 :- 1 ]
16
17
17
18
19
+ def get_files_images (obj_type , obj_id , conn ):
20
+ """ Gets all the files attached to an object,
21
+ and images if the object is a dataset,
22
+ and returns a list of file names and a list of urls
23
+ for the files and eventually the images
24
+ """
25
+ obj = conn .getObject (obj_type , obj_id )
26
+ file_names = [
27
+ i for i in obj .listAnnotations ()
28
+ if i .OMERO_TYPE ().NAME ==
29
+ "ome.model.annotations.FileAnnotation_name" ]
30
+ file_urls = [i .getId () for i in file_names ]
31
+ file_names = [i .getFileName () for i in file_names ]
32
+ file_urls = [SERVER + "/webclient/annotation/" + str (i ) for i in file_urls ]
33
+
34
+ if obj_type == "dataset" :
35
+ imgs = list (obj .listChildren ())
36
+ img_urls = [build_zarr_image_url (i .getId ()) for i in imgs ]
37
+ img_names = [i .getName () for i in imgs ]
38
+ else :
39
+ img_urls = [build_zarr_image_url (obj_id )]
40
+ img_names = [obj .getName ()]
41
+
42
+ return file_names , file_urls , img_names , img_urls
43
+
44
+
18
45
def build_viewer_url (config_id ):
19
46
""" Generates urls like:
20
47
http://localhost:4080/omero_vitessce/?config=http://localhost:4080/webclient/annotation/999
@@ -47,28 +74,48 @@ def get_attached_configs(obj_type, obj_id, conn):
47
74
return config_files , config_urls
48
75
49
76
50
- def create_dataset_config (dataset_id , conn ):
77
+ def create_dataset_config (dataset_id , config_args ):
51
78
"""
52
79
Generates a Vitessce config for an OMERO dataset and returns it.
53
80
Assumes all images in the dataset are zarr files
54
81
which can be served with omero-web-zarr.
55
82
All images are added to the same view.
56
83
"""
57
- dataset = conn .getObject ("dataset" , dataset_id )
58
- images = [i for i in dataset .listChildren ()]
59
-
60
84
vc = VitessceConfig (schema_version = "1.0.6" )
61
85
vc_dataset = vc .add_dataset ()
62
- wrappers = []
63
- for img in images :
64
- wrapper = OmeZarrWrapper (
65
- img_url = build_zarr_image_url (img .getId ()),
66
- name = img .getName ())
67
- wrappers .append (wrapper )
68
- vc_dataset .add_object (MultiImageWrapper (image_wrappers = wrappers ,
86
+
87
+ img_url = config_args .get ("image" )
88
+
89
+ images = [OmeZarrWrapper (img_url = img_url , name = "Image" )]
90
+
91
+ vc .add_view (Vt .SPATIAL , dataset = vc_dataset , x = 0 , y = 0 , w = 8 , h = 10 )
92
+ vc .add_view (Vt .LAYER_CONTROLLER , dataset = vc_dataset , x = 8 , y = 0 , w = 2 , h = 10 )
93
+
94
+ if config_args .get ("cell identities" ):
95
+ vc_dataset = vc_dataset .add_file (
96
+ url = config_args .get ("cell identities" ),
97
+ file_type = Ft .OBS_SETS_CSV ,
98
+ coordination_values = {"obsType" : "cell" },
99
+ options = {
100
+ "obsIndex" : "cell_id" ,
101
+ "obsSets" : [
102
+ {"name" : "Clustering" , "column" : "graphclust" }]})
103
+ vc .add_view (Vt .OBS_SETS , dataset = vc_dataset , x = 10 , y = 5 , w = 2 , h = 5 )
104
+ if config_args .get ("expression" ):
105
+ vc_dataset = vc_dataset .add_file (
106
+ url = config_args .get ("expression" ),
107
+ file_type = Ft .OBS_FEATURE_MATRIX_CSV )
108
+ vc .add_view (Vt .FEATURE_LIST , dataset = vc_dataset , x = 10 , y = 0 , w = 2 , h = 5 )
109
+ if config_args .get ("segmentation" ):
110
+ segmentation = OmeZarrWrapper (
111
+ img_url = config_args .get ("segmentation" ),
112
+ name = "Segmentation" ,
113
+ is_bitmask = True )
114
+ images .append (segmentation )
115
+
116
+ vc_dataset .add_object (MultiImageWrapper (image_wrappers = images ,
69
117
use_physical_size_scaling = True ))
70
- vc .add_view (Vt .SPATIAL , dataset = vc_dataset , x = 0 , y = 0 , w = 10 , h = 10 )
71
- vc .add_view (Vt .LAYER_CONTROLLER , dataset = vc_dataset , x = 10 , y = 0 , w = 2 , h = 10 )
118
+
72
119
vc .add_coordination_by_dict ({
73
120
Ct .SPATIAL_ZOOM : 2 ,
74
121
Ct .SPATIAL_TARGET_X : 0 ,
@@ -77,7 +124,7 @@ def create_dataset_config(dataset_id, conn):
77
124
return vc
78
125
79
126
80
- def create_image_config (image_id ):
127
+ def create_image_config (image_id , config_args ):
81
128
"""
82
129
Generates a Vitessce config for an OMERO image and returns it.
83
130
Assumes the images is an OME-NGFF v0.4 file
@@ -87,8 +134,10 @@ def create_image_config(image_id):
87
134
vc_dataset = vc .add_dataset ().add_file (
88
135
url = build_zarr_image_url (image_id ),
89
136
file_type = Ft .IMAGE_OME_ZARR )
137
+
90
138
vc .add_view (Vt .SPATIAL , dataset = vc_dataset , x = 0 , y = 0 , w = 10 , h = 10 )
91
139
vc .add_view (Vt .LAYER_CONTROLLER , dataset = vc_dataset , x = 10 , y = 0 , w = 2 , h = 10 )
140
+
92
141
vc .add_coordination_by_dict ({
93
142
Ct .SPATIAL_ZOOM : 2 ,
94
143
Ct .SPATIAL_TARGET_X : 0 ,
@@ -133,6 +182,12 @@ def vitessce_panel(request, obj_type, obj_id, conn=None, **kwargs):
133
182
context = {"json_configs" : dict (zip (config_files , config_urls )),
134
183
"obj_type" : obj_type , "obj_id" : obj_id }
135
184
185
+ if not config_files :
186
+ files , urls , img_files , img_urls = get_files_images (
187
+ obj_type , obj_id , conn )
188
+ form = ConfigForm (files , urls , img_files , img_urls )
189
+ context ["form" ] = form
190
+
136
191
return render (request , "omero_vitessce/vitessce_panel.html" , context )
137
192
138
193
@@ -142,11 +197,12 @@ def generate_config(request, obj_type, obj_id, conn=None, **kwargs):
142
197
write it to a temporarily file and attach it. Then open the
143
198
viewer with the autogenerated config.
144
199
"""
200
+
145
201
obj_id = int (obj_id )
146
202
if obj_type == "image" :
147
- vitessce_config = create_image_config (obj_id )
203
+ vitessce_config = create_image_config (obj_id , request . POST )
148
204
if obj_type == "dataset" :
149
- vitessce_config = create_dataset_config (obj_id , conn )
205
+ vitessce_config = create_dataset_config (obj_id , request . POST )
150
206
151
207
config_id = attach_config (vitessce_config , obj_type , obj_id , conn )
152
208
viewer_url = build_viewer_url (config_id )
0 commit comments