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

Always update pixels #8

Merged
merged 5 commits into from
Sep 25, 2023
Merged
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
28 changes: 18 additions & 10 deletions src/omero_mkngff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from omero.cli import BaseControl, Parser
from omero.sys import ParametersI

SUFFIX = "mkngff"
HELP = """Plugin to swap OMERO filesets with NGFF

CLI plugin used to swap an existing OMERO fileset with
Expand Down Expand Up @@ -105,12 +106,6 @@
values (nextval('seq_filesetentry'), {DETAILS2},
new_fileset, new_file, i-1, 'unknown');

if info[i][2] = 'METADATA.ome.xml' then
update pixels set path = trim(trailing '/' from info[i][1]), name = info[i][2]
from (select id from image where image.fileset = old_fileset) as subquery
where pixels.image = subquery.id;
end if;

end loop;

update image set fileset = new_fileset where fileset = old_fileset;
Expand Down Expand Up @@ -197,7 +192,7 @@ def sql(self, args: Namespace) -> None:
self.ctx.die(401, f"Symlink target does not exist: {args.symlink_target}")
return

# create *_converted/path/to/zarr directory containing symlink to data
# create *_SUFFIX/path/to/zarr directory containing symlink to data
if args.symlink_repo:
prefix_dir = os.path.join(args.symlink_repo, prefix)
self.ctx.err(f"Checking for prefix_dir {prefix_dir}")
Expand All @@ -206,7 +201,7 @@ def sql(self, args: Namespace) -> None:
symlink_container = f"{symlink_path.parent}"
if symlink_container.startswith("/"):
symlink_container = symlink_container[1:] # remove "/" from start
symlink_dir = os.path.join(f"{prefix_dir}_converted", symlink_container)
symlink_dir = f"{prefix_dir}_{SUFFIX}"
self.ctx.err(f"Creating dir at {symlink_dir}")
os.makedirs(symlink_dir, exist_ok=True)

Expand All @@ -218,21 +213,34 @@ def sql(self, args: Namespace) -> None:
os.symlink(args.symlink_target, symlink_source, target_is_directory)

rows = []
# Need a file to set path/name on pixels table BioFormats uses for setId()
setid_target = None
for row_path, row_name, row_mime in self.walk(symlink_path):
# remove common path to shorten
row_path = str(row_path).replace(f"{symlink_path.parent}", "")
if str(row_path).startswith("/"):
row_path = str(row_path)[1:] # remove "/" from start
row_full_path = f"{prefix_path}/{prefix_name}_{SUFFIX}/{row_path}"
# pick the first .zattrs file we find, then update to ome.xml if we find it
if setid_target is None and row_name == ".zattrs" or row_name == "METADATA.ome.xml":
setid_target = [row_full_path, row_name]
rows.append(
ROW.format(
PATH=f"{prefix_path}/{prefix_name}_converted/{row_path}/",
PATH=f"{row_full_path}/",
NAME=row_name,
MIME=row_mime,
)
)

# Add a command to update the Pixels table with path/name using old Fileset ID *before* new Fileset is created
fpath = setid_target[0]
fname = setid_target[1]
self.ctx.out(f"UPDATE pixels SET name = '{fname}', path = '{fpath}' where image in (select id from Image where fileset = {args.fileset_id});")

self.ctx.out(
TEMPLATE.format(
OLD_FILESET=args.fileset_id,
PREFIX=f"{prefix_path}/{prefix_name}_converted/",
PREFIX=f"{prefix_path}/{prefix_name}_{SUFFIX}/",
ROWS=",\n".join(rows),
REPO=self.get_uuid(args),
UUID=args.secret,
Expand Down