Skip to content

Commit

Permalink
prepare now uses relative paths (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmartins authored Aug 8, 2023
1 parent 3ba94d0 commit a13e385
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 40 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def read(fname):
packages=['', 'omero.plugins'],
package_dir={"": "src"},
name="omero-cli-transfer",
version='0.7.0',
version='0.7.1',
maintainer="Erick Ratamero",
maintainer_email="[email protected]",
description=("A set of utilities for exporting a transfer"
Expand Down
22 changes: 14 additions & 8 deletions src/generate_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,17 @@ def create_objects(folder, filelist):
if not filelist:
for path, subdirs, files in os.walk(folder):
for f in files:
img_files.append(os.path.abspath(os.path.join(path, f)))
img_files.append(os.path.relpath(
os.path.join(path, f), folder))
targets = copy.deepcopy(img_files)
for img in img_files:
if img not in (targets):
continue
cmd = ["omero", 'import', '-f', img, "\n"]
img_path = os.path.join(os.getcwd(), folder, img)
cmd = ["omero", 'import', '-f', img_path, "\n"]
res = cli.popen(cmd, stdout=PIPE, stderr=DEVNULL)
std = res.communicate()
files = parse_files_import(std[0].decode('UTF-8'))
files = parse_files_import(std[0].decode('UTF-8'), folder)
if len(files) > 1:
for f in files:
targets.remove(f)
Expand All @@ -498,9 +500,9 @@ def create_objects(folder, filelist):
counter_imgs = 1
counter_pls = 1
for target in targets:
target = str(Path(target).absolute())
print(f"Processing file {target}")
res = run_showinf(target, cli)
target_full = os.path.join(os.getcwd(), folder, target)
print(f"Processing file {target_full}")
res = run_showinf(target_full, cli)
imgs, pls, anns = parse_showinf(res,
counter_imgs, counter_pls, target)
images.extend(imgs)
Expand All @@ -519,11 +521,15 @@ def run_showinf(target, cli):
return std[0].decode('UTF-8')


def parse_files_import(text):
def parse_files_import(text, folder):
lines = text.split("\n")
targets = [line for line in lines if not line.startswith("#")
and len(line) > 0]
return targets
clean_targets = []
for target in targets:
clean = os.path.relpath(target, folder)
clean_targets.append(clean)
return clean_targets


def parse_showinf(text, counter_imgs, counter_plates, target):
Expand Down
112 changes: 81 additions & 31 deletions test/data/prepare/transfer.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,84 @@
<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">
<Plate ID="Plate:1" Name="Plate Name 0">
<Well Column="0" ID="Well:0_0_0_0" Row="0" Color="255" ExternalDescription="External Description" ExternalIdentifier="External Identifier" Type="Transfection: done">
<WellSample ID="WellSample:0_0_0_0_0_0" Index="0" PositionX="0.0" PositionY="1.0" Timepoint="2006-05-04T18:13:51">
<ImageRef ID="Image:2" />
</WellSample>
</Well>
<AnnotationRef ID="Annotation:-166540319990038501817496698575818747072" />
</Plate>
<Image ID="Image:1" Name="test_pyramid.tiff">
<Pixels DimensionOrder="XYCZT" ID="Pixels:1" SizeC="1" SizeT="1" SizeX="16" SizeY="16" SizeZ="1" Type="uint8">
<MetadataOnly />
</Pixels>
<AnnotationRef ID="Annotation:-86643574848290778120287886298910882783" />
</Image>
<Image ID="Image:2" Name="default-plate">
<Pixels DimensionOrder="XYZCT" ID="Pixels:2" SizeC="1" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" Type="uint8">
<MetadataOnly />
</Pixels>
<AnnotationRef ID="Annotation:-134337008044623056588408027657468159176" />
</Image>
<StructuredAnnotations>
<CommentAnnotation ID="Annotation:-86643574848290778120287886298910882783" Namespace="Image:1">
<Value>/mnt/c/Users/erick/Documents/GitHub/omero-cli-transfer/test/data/prepare/test_pyramid.ome.tif</Value>
</CommentAnnotation>
<CommentAnnotation ID="Annotation:-134337008044623056588408027657468159176" Namespace="Image:2">
<Value>/mnt/c/Users/erick/Documents/GitHub/omero-cli-transfer/test/data/prepare/default-plate&amp;plates=1.fake</Value>
</CommentAnnotation>
<CommentAnnotation ID="Annotation:-166540319990038501817496698575818747072" Namespace="Plate:1">
<Value>/mnt/c/Users/erick/Documents/GitHub/omero-cli-transfer/test/data/prepare/default-plate&amp;plates=1.fake</Value>
</CommentAnnotation>
</StructuredAnnotations>
<Plate ID="Plate:1" Name="Plate Name 0">
<Well ID="Well:0_0_0_0" Column="0" Row="0" ExternalDescription="External Description" ExternalIdentifier="External Identifier" Type="Transfection: done" Color="255">
<WellSample ID="WellSample:0_0_0_0_0_0" PositionX="0.0" PositionXUnit="reference frame" PositionY="1.0" PositionYUnit="reference frame" Timepoint="2006-05-04T18:13:51" Index="0">
<ImageRef ID="Image:1"/>
</WellSample>
</Well>
<AnnotationRef ID="Annotation:-302109755386744031474663137255099440619"/>
</Plate>
<Image ID="Image:1" Name="default-plate">
<Pixels ID="Pixels:1" DimensionOrder="XYZCT" Type="uint8" SizeX="512" SizeY="512" SizeZ="1" SizeC="1" SizeT="1">
<MetadataOnly/>
</Pixels>
<AnnotationRef ID="Annotation:-55040966795353415047517454760603713654"/>
<AnnotationRef ID="Annotation:-60189972287065119682949125532632336000"/>
</Image>
<Image ID="Image:2" Name="test_pyramid.tiff">
<Pixels ID="Pixels:2" DimensionOrder="XYCZT" Type="uint8" SizeX="16" SizeY="16" SizeZ="1" SizeC="1" SizeT="1">
<MetadataOnly/>
</Pixels>
<AnnotationRef ID="Annotation:-124740294806861926766131915590778711100"/>
<AnnotationRef ID="Annotation:-235134109673596436144013343504048608878"/>
</Image>
<Image ID="Image:3" Name="vsi-ets-test-jpg2k.vsi [001 C405, C488]">
<Pixels ID="Pixels:3" DimensionOrder="XYCZT" Type="uint16" SizeX="1645" SizeY="1682" SizeZ="11" SizeC="2" SizeT="1">
<MetadataOnly/>
</Pixels>
<AnnotationRef ID="Annotation:-259343186022718704856275667016466761689"/>
<AnnotationRef ID="Annotation:-224780865139240311027116801634970628041"/>
</Image>
<Image ID="Image:4" Name="vsi-ets-test-jpg2k.vsi [macro image]">
<Pixels ID="Pixels:4" DimensionOrder="XYCZT" Type="uint8" SizeX="501" SizeY="512" SizeZ="1" SizeC="3" SizeT="1">
<MetadataOnly/>
</Pixels>
<AnnotationRef ID="Annotation:-63003149123325712739521864873102528314"/>
<AnnotationRef ID="Annotation:-180673318620852740990473970358731429779"/>
</Image>
<StructuredAnnotations>
<CommentAnnotation ID="Annotation:-55040966795353415047517454760603713654" Namespace="Image:1">
<Value>default-plate&amp;plates=1.fake</Value>
</CommentAnnotation>
<MapAnnotation ID="Annotation:-60189972287065119682949125532632336000" Namespace="openmicroscopy.org/cli/transfer/prepare">
<Value>
<M K="software">omero-cli-transfer</M>
<M K="version">0.6.0</M>
<M K="packing_timestamp">08/08/2023, 13:51:49</M>
</Value>
</MapAnnotation>
<CommentAnnotation ID="Annotation:-302109755386744031474663137255099440619" Namespace="Plate:1">
<Value>default-plate&amp;plates=1.fake</Value>
</CommentAnnotation>
<CommentAnnotation ID="Annotation:-124740294806861926766131915590778711100" Namespace="Image:2">
<Value>test_pyramid.ome.tif</Value>
</CommentAnnotation>
<MapAnnotation ID="Annotation:-235134109673596436144013343504048608878" Namespace="openmicroscopy.org/cli/transfer/prepare">
<Value>
<M K="software">omero-cli-transfer</M>
<M K="version">0.6.0</M>
<M K="packing_timestamp">08/08/2023, 13:51:51</M>
</Value>
</MapAnnotation>
<CommentAnnotation ID="Annotation:-259343186022718704856275667016466761689" Namespace="Image:3">
<Value>vsi-ets-test-jpg2k.vsi</Value>
</CommentAnnotation>
<MapAnnotation ID="Annotation:-224780865139240311027116801634970628041" Namespace="openmicroscopy.org/cli/transfer/prepare">
<Value>
<M K="software">omero-cli-transfer</M>
<M K="version">0.6.0</M>
<M K="packing_timestamp">08/08/2023, 13:51:53</M>
</Value>
</MapAnnotation>
<CommentAnnotation ID="Annotation:-63003149123325712739521864873102528314" Namespace="Image:4">
<Value>vsi-ets-test-jpg2k.vsi</Value>
</CommentAnnotation>
<MapAnnotation ID="Annotation:-180673318620852740990473970358731429779" Namespace="openmicroscopy.org/cli/transfer/prepare">
<Value>
<M K="software">omero-cli-transfer</M>
<M K="version">0.6.0</M>
<M K="packing_timestamp">08/08/2023, 13:51:53</M>
</Value>
</MapAnnotation>
</StructuredAnnotations>
</OME>

0 comments on commit a13e385

Please sign in to comment.