Skip to content

Commit

Permalink
Merge pull request #1074 from jiajic/suite_dev
Browse files Browse the repository at this point in the history
fix: xenium focus image loading when not in a subdirectory
  • Loading branch information
jiajic authored Nov 16, 2024
2 parents a816e98 + 4c4f2ca commit 1321982
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions R/convenience_xenium.R
Original file line number Diff line number Diff line change
Expand Up @@ -505,22 +505,36 @@ setMethod(
if (!is.null(load_images)) {
load_images <- lapply(load_images, normalizePath, mustWork = FALSE)
img_focus_path <- normalizePath(img_focus_path, mustWork = FALSE)


# replace shortname
load_images[load_images == "focus"] <- img_focus_path

is_dir <- dir.exists(img_focus_path)
is_focus <- load_images == img_focus_path
is_focus_image <- is_focus & !is_dir
is_focus_dir <- is_focus & is_dir

# handle matches to single focus images instead of a directory
names(load_images)[is_focus_image] <- "dapi"

# [exception] handle focus image dir
is_focus <- load_images == "focus" | load_images == img_focus_path
# split the focus image dir away from other entries
load_images <- load_images[!is_focus]

if (any(is_focus)) {
if (any(is_focus_dir)) {
# split the focus image dir away from other entries
load_images <- load_images[!is_focus_dir]
focus_dir <- img_focus_path
focus_files <- list.files(focus_dir, full.names = TRUE)
focus_files <- focus_files[!dir.exists(focus_files)] # ignore matches to export dir
nbound <- length(focus_files) - 1L
focus_names <- c("dapi", sprintf("bound%d", seq_len(nbound)))
names(focus_files) <- focus_names

# append to rest of entries
load_images <- c(load_images, focus_files)
# ignore matches to export dir (if it is a subdirectory)
focus_files <- focus_files[!dir.exists(focus_files)]
if (length(focus_files) > 0L) {
nbound <- length(focus_files) - 1L
focus_names <- c(
"dapi", sprintf("bound%d", seq_len(nbound))
)
names(focus_files) <- focus_names

# append to rest of entries
load_images <- c(load_images, focus_files)
}
}

# ensure that input is list
Expand Down

0 comments on commit 1321982

Please sign in to comment.