Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 16, 2023
1 parent d6e3c46 commit a97f4d8
Showing 1 changed file with 64 additions and 48 deletions.
112 changes: 64 additions & 48 deletions omeroweb/webclient/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,21 +2077,24 @@ def marshal_annotations(
return annotations, experimenters


def marshal_lineage(conn,
project_ids=None,
dataset_ids=None,
image_ids=None,
screen_ids=None,
plate_ids=None,
run_ids=None,
well_ids=None):

def add_refs(ref_, dataset=None, project=None, well=None,
run=None, plate=None, screen=None):
def marshal_lineage(
conn,
project_ids=None,
dataset_ids=None,
image_ids=None,
screen_ids=None,
plate_ids=None,
run_ids=None,
well_ids=None,
):
def add_refs(
ref_, dataset=None, project=None, well=None, run=None, plate=None, screen=None
):
def _add_refs(obj_type, obj_id):
if obj_id:
all_obj_ids[obj_type].add(obj_id)
lineage_d[obj_type][obj_id].append(ref_)

_add_refs("DatasetI", dataset)
_add_refs("ProjectI", project)
_add_refs("PlateAcquisitionI", run)
Expand All @@ -2114,71 +2117,84 @@ def parse_hql_id(hql_ids):

child_ref_d = defaultdict(dict) # Children references dict
lineage_d, all_obj_ids = {}, {} # Result dictionnaries
for obj_type in ["ImageI", "DatasetI", "ProjectI", "PlateI",
"PlateAcquisitionI", "WellI", "ScreenI"]:
for obj_type in [
"ImageI",
"DatasetI",
"ProjectI",
"PlateI",
"PlateAcquisitionI",
"WellI",
"ScreenI",
]:
lineage_d[obj_type] = defaultdict(list)
all_obj_ids[obj_type] = set(requested[obj_type])

if len(requested[obj_type]) > 0:
for o in conn.getObjects(obj_type[:-1], requested[obj_type]):
details = {"id": o.getId(),
"class": obj_type}
details = {"id": o.getId(), "class": obj_type}
if obj_type not in ["PlateAcquisitionI", "WellI"]:
details["name"] = o.getName()
child_ref_d[obj_type][details["id"]] = details

service_opts = conn.SERVICE_OPTS.copy()
qs = conn.getQueryService()
hql_image = ("select img.id, dset.id, pdl.parent.id, smp.well.id,"
" smp.plateAcquisition.id, plt.id, spl.parent.id"
" from Image img"
" left outer join img.datasetLinks dil"
" left outer join dil.parent dset"
" left outer join img.wellSamples smp"
" left outer join dset.projectLinks pdl"
" left outer join smp.well.plate plt"
" left outer join plt.screenLinks spl"
" where img.id in (:ids)")

hql_wellrun = ("select child_o.id, plt.id, pdl.parent.id"
" from {} child_o"
" join child_o.plate plt"
" left outer join plt.screenLinks pdl"
" where child_o.id in (:ids)")

hql_dsetplate = ("select child_o.id, opl.parent.id FROM {} child_o"
" left outer join child_o.{}Links opl "
" where child_o.id in (:ids)")
hql_image = (
"select img.id, dset.id, pdl.parent.id, smp.well.id,"
" smp.plateAcquisition.id, plt.id, spl.parent.id"
" from Image img"
" left outer join img.datasetLinks dil"
" left outer join dil.parent dset"
" left outer join img.wellSamples smp"
" left outer join dset.projectLinks pdl"
" left outer join smp.well.plate plt"
" left outer join plt.screenLinks spl"
" where img.id in (:ids)"
)

hql_wellrun = (
"select child_o.id, plt.id, pdl.parent.id"
" from {} child_o"
" join child_o.plate plt"
" left outer join plt.screenLinks pdl"
" where child_o.id in (:ids)"
)

hql_dsetplate = (
"select child_o.id, opl.parent.id FROM {} child_o"
" left outer join child_o.{}Links opl "
" where child_o.id in (:ids)"
)

if len(requested["ImageI"]) > 0:
params = omero.sys.ParametersI()
params.addIds(requested["ImageI"])
for (im, ds, pr,
wl, rn, pl, sc) in map(parse_hql_id,
qs.projection(hql_image,
params, service_opts)):
for im, ds, pr, wl, rn, pl, sc in map(
parse_hql_id, qs.projection(hql_image, params, service_opts)
):
ref_ = child_ref_d["ImageI"][im]
add_refs(ref_, ds, pr, wl, rn, pl, sc)

for _type in ["WellI", "PlateAcquisitionI"]:
if len(requested[_type]) > 0:
params = omero.sys.ParametersI()
params.addIds(requested[_type])
for ob, pl, sc in map(parse_hql_id,
qs.projection(hql_wellrun.format(_type[:-1]),
params, service_opts)):
for ob, pl, sc in map(
parse_hql_id,
qs.projection(hql_wellrun.format(_type[:-1]), params, service_opts),
):
ref_ = child_ref_d[_type][ob]
add_refs(ref_, plate=pl, screen=sc)

for _type, parent_type in zip(["PlateI", "DatasetI"],
["screen", "project"]):
for _type, parent_type in zip(["PlateI", "DatasetI"], ["screen", "project"]):
if len(requested[_type]) > 0:
params = omero.sys.ParametersI()
params.addIds(requested[_type])
for ob, p in map(parse_hql_id,
qs.projection(hql_dsetplate.format(_type[:-1],
parent_type),
params, service_opts)):
for ob, p in map(
parse_hql_id,
qs.projection(
hql_dsetplate.format(_type[:-1], parent_type), params, service_opts
),
):
ref_ = child_ref_d[_type][ob]
if _type == "PlateI":
add_refs(ref_, screen=p)
Expand Down

0 comments on commit a97f4d8

Please sign in to comment.