Skip to content

Commit

Permalink
debugging, new valid_single_image test data
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmartins committed Dec 18, 2023
1 parent 4ee5ffc commit d40703a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 75 deletions.
11 changes: 8 additions & 3 deletions src/generate_omero_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,15 @@ def parse_xml_metadata(ann: XMLAnnotation,
metadata: List[str],
hash: str) -> List[List[str]]:
kv_data = []
print("metadata: ", metadata)
tree = ETree.fromstring(to_xml(ann.value, canonicalize=True))
for el in tree:
if el.tag.rpartition('}')[2] == "CLITransferMetadata":
for el2 in el:
item = el2.tag.rpartition('}')[2]
val = el2.text
if item == "md5" and "md5" in metadata:
kv_data.append(['zip_file_md5', hash])
kv_data.append(['md5', hash])
if item == "origin_image_id" and "img_id" in metadata:
kv_data.append([item, val])
if item == "origin_plate_id" and "plate_id" in metadata:
Expand All @@ -250,8 +251,7 @@ def parse_xml_metadata(ann: XMLAnnotation,
kv_data.append([item, val])
if item == "database_id" and "db_id" in metadata:
kv_data.append([item, val])
else:
kv_data.append([item, val])
print("kv_data: ", kv_data)
return kv_data


Expand Down Expand Up @@ -564,6 +564,7 @@ def link_images(ome: OME, ds_map: dict, img_map: dict, conn: BlitzGateway):
def link_annotations(ome: OME, proj_map: dict, ds_map: dict, img_map: dict,
ann_map: dict, scr_map: dict, pl_map: dict,
conn: BlitzGateway):
print(ann_map)
for proj in ome.projects:
proj_id = proj_map[proj.id]
proj_obj = conn.getObject("Project", proj_id)
Expand All @@ -584,7 +585,9 @@ def link_annotations(ome: OME, proj_map: dict, ds_map: dict, img_map: dict,
img_obj = conn.getObject("Image", img_id)
anns = ome.structured_annotations
for annref in img.annotation_refs:
print("image annref:", annref)
ann = next(filter(lambda x: x.id == annref.id, anns))
print("annotation:", ann)
link_one_annotation(img_obj, ann, ann_map, conn)
except KeyError:
continue
Expand Down Expand Up @@ -627,6 +630,8 @@ def link_one_annotation(obj: IObject, ann: Annotation, ann_map: dict,
ann_obj = conn.getObject("LongAnnotation", ann_id)
elif isinstance(ann, FileAnnotation):
ann_obj = conn.getObject("FileAnnotation", ann_id)
elif isinstance(ann, XMLAnnotation):
ann_obj = conn.getObject("MapAnnotation", ann_id)
else:
ann_obj = None
if ann_obj:
Expand Down
1 change: 1 addition & 0 deletions src/omero_cli_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ def __unpack(self, args):
ln_s, args.skip, self.gateway)
self._delete_all_rois(dest_img_map, self.gateway)
print("Matching source and destination images...")
print(src_img_map, dest_img_map)
img_map = self._make_image_map(src_img_map, dest_img_map, self.gateway)
print("Creating and linking OMERO objects...")
populate_omero(ome, img_map, self.gateway,
Expand Down
Binary file modified test/data/valid_single_image.tar
Binary file not shown.
Binary file modified test/data/valid_single_image.zip
Binary file not shown.
Binary file not shown.
137 changes: 71 additions & 66 deletions test/data/valid_single_image/transfer.xml
Original file line number Diff line number Diff line change
@@ -1,69 +1,74 @@
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
<Image ID="Image:13" Name="combined_result.tiff">
<Description />
<Pixels DimensionOrder="XYZCT" ID="Pixels:13" SizeC="1" SizeT="1" SizeX="1024" SizeY="1024" SizeZ="1" Type="uint16">
<MetadataOnly />
</Pixels>
<ROIRef ID="ROI:34" />
<ROIRef ID="ROI:35" />
<ROIRef ID="ROI:36" />
<AnnotationRef ID="Annotation:45" />
<AnnotationRef ID="Annotation:47" />
<AnnotationRef ID="Annotation:48" />
<AnnotationRef ID="Annotation:-224025024630226983263251575676667039416" />
<AnnotationRef ID="Annotation:-28260204872495984486395250199030049489" />
</Image>
<StructuredAnnotations>
<MapAnnotation ID="Annotation:45" Namespace="openmicroscopy.org/omero/client/mapAnnotation">
<Value>
<M K="species"> </M>
<M K="occupation"> </M>
<M K="first name"> </M>
<M K="surname">this is a test to see if the kv pairs in omero have any length limits. I don't think they do, but I will write something relatively long just so I can double-check whether that is the case or not.</M>
</Value>
</MapAnnotation>
<TagAnnotation ID="Annotation:48">
<Value>simple_tag</Value>
</TagAnnotation>
<MapAnnotation ID="Annotation:-224025024630226983263251575676667039416" Namespace="openmicroscopy.org/cli/transfer">
<Value>
<M K="origin_image_id">13</M>
<M K="packing_timestamp">26/08/2022, 11:01:27</M>
<M K="software">omero-cli-transfer</M>
<M K="version">0.0.0</M>
<M K="origin_hostname">localhost</M>
<M K="md5">TBC</M>
<M K="original_user">root</M>
<M K="original_group">system</M>
<M K="database_id">59149c9d-0ff3-430a-9f1a-1d8093b4a98c</M>
</Value>
</MapAnnotation>
<CommentAnnotation ID="Annotation:-28260204872495984486395250199030049489" Namespace="Image:13">
<Value>root_0/2022-08/26/14-59-42.116/combined_result.tiff</Value>
</CommentAnnotation>
<MapAnnotation ID="Annotation:47" Namespace="jax.org/jax/example/namespace">
<Value>
<M K="species"> </M>
<M K="occupation"> </M>
<M K="first name"> </M>
<M K="surname"> </M>
</Value>
</MapAnnotation>
</StructuredAnnotations>
<ROI ID="ROI:34">
<Union>
<Line ID="Shape:34" FillColor="-256" StrokeColor="-65283" Text="" TheC="0" TheT="0" TheZ="0" X1="321.7500000000001" X2="715.6500000000001" Y1="546.4875000000001" Y2="667.3875" />
</Union>
</ROI>
<ROI ID="ROI:35">
<Union>
<Line ID="Shape:35" FillColor="-256" StrokeColor="-65283" Text="" TheC="0" TheT="0" TheZ="0" X1="453.3750000000001" X2="862.8750000000001" Y1="242.2875000000001" Y2="481.1625000000001" />
</Union>
</ROI>
<ROI ID="ROI:36">
<Union>
<Rectangle ID="Shape:36" FillColor="-256" StrokeColor="-65283" Text="" TheC="0" TheT="0" TheZ="0" Height="154.69825576030746" Width="177.56789185846986" X="136.35047580394115" Y="644.0620035942259" />
</Union>
</ROI>
<Image ID="Image:51" Name="combined_result.tiff">
<Description/>
<Pixels ID="Pixels:51" DimensionOrder="XYZCT" Type="uint16" SizeX="1024" SizeY="1024" SizeZ="1" SizeC="1" SizeT="1">
<MetadataOnly/>
</Pixels>
<ROIRef ID="lsid:51"/>
<ROIRef ID="lsid:52"/>
<ROIRef ID="lsid:53"/>
<AnnotationRef ID="Annotation:51"/>
<AnnotationRef ID="Annotation:52"/>
<AnnotationRef ID="Annotation:53"/>
<AnnotationRef ID="Annotation:5706132577051166458"/>
<AnnotationRef ID="Annotation:5706132577051166459"/>
</Image>
<StructuredAnnotations>
<MapAnnotation ID="Annotation:51" Namespace="openmicroscopy.org/omero/client/mapAnnotation">
<Value>
<M K="species"/>
<M K="occupation"/>
<M K="first name"/>
<M K="surname">this is a test to see if the kv pairs in omero have any length limits. I don't think they do, but I will write something relatively long just so I can double-check whether that is the case or not.</M>
</Value>
</MapAnnotation>
<TagAnnotation ID="Annotation:52">
<Value>simple_tag</Value>
</TagAnnotation>
<MapAnnotation ID="Annotation:53" Namespace="jax.org/jax/example/namespace">
<Value>
<M K="species"/>
<M K="occupation"/>
<M K="first name"/>
<M K="surname"/>
</Value>
</MapAnnotation>
<XMLAnnotation ID="Annotation:5706132577051166458" Namespace="openmicroscopy.org/cli/transfer">
<Value>
<CLITransferMetadata xsi:schemaLocation="https://raw.githubusercontent.com/ome/omero-cli-transfer/main/schemas/preparemetadata.xsd">
<origin_image_id>51</origin_image_id>
<packing_timestamp>18/12/2023, 09:57:59</packing_timestamp>
<software>omero-cli-transfer</software>
<version>0.8.0</version>
<origin_hostname>localhost</origin_hostname>
<md5>TBC</md5>
<original_user>root</original_user>
<original_group>system</original_group>
</CLITransferMetadata>
</Value>
</XMLAnnotation>
<XMLAnnotation ID="Annotation:5706132577051166459" Namespace="openmicroscopy.org/cli/transfer">
<Value>
<CLITransferServerPath xsi:schemaLocation="https://raw.githubusercontent.com/ome/omero-cli-transfer/main/schemas/serverpath.xsd">
<Path>root_0/2023-12/18/14-52-03.548/combined_result.tiff</Path>
</CLITransferServerPath>
</Value>
</XMLAnnotation>
</StructuredAnnotations>
<ROI ID="lsid:51">
<Union>
<Line FillColor="-256" StrokeColor="-65281" StrokeWidth="1.0" Text="" ID="Shape:51" TheZ="0" TheT="0" TheC="0" X1="504.00000000000017" Y1="534.8000000000002" X2="261.8" Y2="284.20000000000005"/>
</Union>
</ROI>
<ROI ID="lsid:52">
<Union>
<Line FillColor="-256" StrokeColor="-65281" StrokeWidth="1.0" Text="" ID="Shape:52" TheZ="0" TheT="0" TheC="0" X1="728.0000000000002" Y1="686.0000000000002" X2="700.0000000000001" Y2="338.80000000000007"/>
</Union>
</ROI>
<ROI ID="lsid:53">
<Union>
<Rectangle FillColor="-256" StrokeColor="-65281" StrokeWidth="1.0" Text="" ID="Shape:53" TheZ="0" TheT="0" TheC="0" X="147.0" Y="791.0000000000002" Width="476.0000000000001" Height="128.80000000000007"/>
</Union>
</ROI>
</OME>

21 changes: 15 additions & 6 deletions test/integration/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ def test_unpack_folder(self, folder_name):
map_ann_ids = ezomero.get_map_annotation_ids(
self.gw, "Image", im_ids[-1])
assert len(map_ann_ids) == 3
provenance = ezomero.get_map_annotation(self.gw, map_ann_ids[-1])
assert len(provenance) == 8
for annid in map_ann_ids:
ann_obj = self.gw.getObject("MapAnnotation", annid)
ann = ezomero.get_map_annotation(self.gw, annid)
if ann_obj.getNs() == "openmicroscopy.org/cli/transfer":
assert len(ann) == 8
assert len(ezomero.get_tag_ids(
self.gw, "Image", im_ids[-1])) == 1
self.delete_all()
Expand All @@ -216,8 +219,11 @@ def test_unpack_folder(self, folder_name):
map_ann_ids = ezomero.get_map_annotation_ids(
self.gw, "Image", im_ids[-1])
assert len(map_ann_ids) == 3
provenance = ezomero.get_map_annotation(self.gw, map_ann_ids[-1])
assert len(provenance) == 1
for annid in map_ann_ids:
ann_obj = self.gw.getObject("MapAnnotation", annid)
ann = ezomero.get_map_annotation(self.gw, annid)
if ann_obj.getNs() == "openmicroscopy.org/cli/transfer":
assert len(ann) == 1
self.delete_all()

self.args = temp_args + ["--metadata", "orig_user", "db_id"]
Expand All @@ -228,8 +234,11 @@ def test_unpack_folder(self, folder_name):
map_ann_ids = ezomero.get_map_annotation_ids(
self.gw, "Image", im_ids[-1])
assert len(map_ann_ids) == 3
provenance = ezomero.get_map_annotation(self.gw, map_ann_ids[-1])
assert len(provenance) == 2
for annid in map_ann_ids:
ann_obj = self.gw.getObject("MapAnnotation", annid)
ann = ezomero.get_map_annotation(self.gw, annid)
if ann_obj.getNs() == "openmicroscopy.org/cli/transfer":
assert len(ann) == 1
self.delete_all()

@pytest.mark.parametrize('package_name', TEST_FILES)
Expand Down

0 comments on commit d40703a

Please sign in to comment.