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

Plate well labels #543

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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: 12 additions & 0 deletions omero_figure/omeroutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ def get_timestamps(conn, image):
if t in timemap:
time_list.append(timemap[t])
return time_list


def get_wellsample_index(conn, wellsample_id):
params = ParametersI()
params.addId(wellsample_id)
query = """select index(wellSamples) from Well well
left outer join well.wellSamples as wellSamples
where wellSamples.id = :id
"""
qs = conn.getQueryService()
rsp = qs.projection(query, params, conn.SERVICE_OPTS)
return rsp[0][0].val
4 changes: 4 additions & 0 deletions omero_figure/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
# Use query ?image=1&image=2
re_path(r'^timestamps/$', views.timestamps, name='figure_timestamps'),

# Get parents (e.g. Plate, Well, WellSample) for images
# Use query ?image=1&image=2
re_path(r'^parents/$', views.parents, name='figure_parents'),

# Get Z scale for images
# Use query ?image=1&image=2
re_path(r'^z_scale/$', views.z_scale, name='figure_z_scale'),
Expand Down
34 changes: 33 additions & 1 deletion omero_figure/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import json
import time

from omeroweb.webclient.show import paths_to_object

from omeroweb.webgateway.marshal import imageMarshal
from omeroweb.webgateway.views import _get_prepared_image
from omeroweb.webclient.views import run_script
Expand All @@ -40,7 +42,7 @@
from io import BytesIO

from omeroweb.webclient.decorators import login_required
from .omeroutils import get_timestamps
from .omeroutils import get_timestamps, get_wellsample_index

from . import utils
import logging
Expand Down Expand Up @@ -160,6 +162,36 @@ def timestamps(request, conn=None, **kwargs):
return JsonResponse(data)


@login_required()
def parents(request, conn=None, **kwargs):

image_ids = request.GET.getlist('image')
try:
image_ids = [int(iid) for iid in image_ids]
except ValueError:
return Http404("Invalid 'image' id")

parents = {}
for img_id in image_ids:
img_parents = {}
for img_path in paths_to_object(conn, image_id=img_id):
for item in img_path:
o_type = item["type"]
del item["type"]
img_parents[o_type] = item
if o_type == "wellsample":
item["index"] = get_wellsample_index(conn, item["id"])
continue
obj = conn.getObject(o_type, item["id"])
if o_type == "well":
item["label"] = obj.getWellPos()
else:
item["name"] = obj.getName()
parents[img_id] = img_parents

return JsonResponse({"parents": parents})


@login_required()
def z_scale(request, conn=None, **kwargs):

Expand Down
27 changes: 27 additions & 0 deletions src/js/models/panel_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@
} else if (format === "name") {
text = this.get('datasetName') ? this.get('datasetName') : "No/Many Datasets";
}
} else {
// screen, plate, well, (name or id)
text = "" + this.get(property)?.[format] ?? "Not Found";
}
return text;
},
Expand Down Expand Up @@ -1025,6 +1028,30 @@
}
},

addLabelsFromPlatesWellsFields: function(label_data) {

// TODO: could ignore image IDs if Plate/Well/Field loaded already
var image_ids = this.map(function(s){return s.get('imageId')});
image_ids = "image=" + image_ids.join("&image=");
var url = BASE_WEBFIGURE_URL + "parents/?" + image_ids;
console.log('url', url);
$.getJSON(url, function(data){
console.log(data);
// {screen: {id:3, name:abc}, plate: {id:1, name:foo}, well:{id:2, name:A1}}
const parents = data.parents;

// Add parents to each panel, then add label
this.forEach(function(p){
var iid = p.get('imageId');
if (parents[iid]) {
p.set(parents[iid]);
}
console.log("Adding label..", label_data);
p.add_labels([label_data]);
});
}.bind(this));
},

createLabelsFromTags: function(options) {
// Loads Tags for selected images and creates labels
var image_ids = this.map(function(s){return s.get('imageId')})
Expand Down
5 changes: 3 additions & 2 deletions src/js/views/panel_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,12 @@
format = prop_nf[1] ? prop_nf[1] : "index";
precision = param_dict["precision"] !== undefined ? param_dict["precision"] : 0; // decimal places default to 0
label_value = self.model.get_time_label_text(format, param_dict["offset"], precision);
} else if (['image', 'dataset'].includes(prop_nf[0])){
} else if (['image', 'dataset', 'screen', 'plate', 'well', 'wellsample'].includes(prop_nf[0])){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add acquisition to the list of accepted objects? It's already part of the parent in the JSON response.

And/or the alias run with a ternary condition inside the if:
prop_nf[0] = prop_nf[0] == "run" ? "acquisition" : prop_nf[0]

format = prop_nf[1] ? prop_nf[1] : "name";
label_value = self.model.get_name_label_text(prop_nf[0], format);
console.log("render_label label_value", label_value, prop_nf);
//Escape the underscore for markdown
label_value = label_value.replaceAll("_", "\\_");
label_value = ("" + label_value).replaceAll("_", "\\_");
} else if (['x', 'y', 'z', 'width', 'height', 'w', 'h', 'rotation', 'rot'].includes(prop_nf[0])){
format = prop_nf[1] ? prop_nf[1] : "pixel";
precision = param_dict["precision"] !== undefined ? param_dict["precision"] : 2; // decimal places default to 2
Expand Down
12 changes: 12 additions & 0 deletions src/js/views/right_panel_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,18 @@
return false;
}

// If we need SPW info and we don't have it, load...
if (label_text.includes('[plate.name]') || label_text.includes('well.name') || label_text.includes('field.index')) {
// Load Plate Name for images...
console.log("label_text", label_text);
selected.addLabelsFromPlatesWellsFields({
text: label_text,
position: position,
size: font_size,
color: color});
return false;
}

if (label_text == '[tags]') {
// Load Tags for this image and create labels

Expand Down
2 changes: 2 additions & 0 deletions src/templates/labels_form_inner_template.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<li><a href="#" data-label="[well.label] Field#[field.index]">Well & Fieild</a></li>
Mispell of Field

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also [field.index] is not functional.
Either needs to be changed to [wellsample.index] or could be given an alias in the JS (similar to the comment on run/acquisition)

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<li role="presentation" class="divider"></li>
<li><a href="#" data-label="[image.name]">Image Name</a></li>
<li><a href="#" data-label="[dataset.name]">Dataset Name</a></li>
<li><a href="#" data-label="[well.label] Field#[field.index]">Well & Fieild</a></li>
<li><a href="#" data-label="[plate.name]">Plate Name</a></li>
<li title="Create labels from active Channels on the selected panel">
<a href="#" data-label="[channels labels]">Channels (separate labels)</a>
</li>
Expand Down