knitr::opts_chunk$set(echo = TRUE) knitr::opts_knit$set(root.dir = file.path("..", "extdata"))
library(EBImage) library(cytomapper)
Here, a subset of 100 images from the pancreas IMC dataset is downloaded.
# Download the zipped folder image and unzip it url.images <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/b37054d2-d5d0-4c48-a001-81ff77136f41/file_downloaded") download.file(url.images, destfile = "ImageSubset.zip") unzip("ImageSubset.zip") file.remove("ImageSubset.zip") # Load the images as a CytoImageList object images <- loadImages("./", pattern="_full_clean.tiff") images
# Download the zipped folder image and unzip it url.masks <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/13679a61-e9b4-4820-9f09-a5bbc697647c/file_downloaded") download.file(url.masks, destfile = "Masks.zip") unzip("Masks.zip") file.remove("Masks.zip") # Load the images as a CytoImageList object masks <- loadImages("./", pattern="_full_mask.tiff") masks
# Remove image stacks images.del <- list.files("./", pattern="_full_clean.tiff") file.remove(images.del) # Remove masks masks.del <- list.files("./", pattern="_full_mask.tiff") file.remove(masks.del)
The panel contains antibody-related metadata. The channel-mass file is used to match panel information and image stack slices.
# Import panel url.panel <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/2f9fecfc-b98f-4937-bc38-ae1b959bd74d/file_downloaded") download.file(url.panel, destfile = "panel.csv") panel <- read.csv("panel.csv") # Import channel-mass file url.channelmass <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/704312eb-377c-42e2-8227-44bb9aca0fb3/file_downloaded") download.file(url.channelmass, destfile = "ChannelMass.csv") channel.mass <- read.csv("ChannelMass.csv", header = FALSE)
The masks are 16-bit images and need to be re-scaled. We then convert the mask values to integer.
masks <- scaleImages(masks, (2 ^ 16) - 1)
This information is stored in the metadata columns of the CytoImageList objects and is used by SingleCellMapper to match single cell data, images and mask
mcols(images)$ImageName <- gsub("_a0_full_clean", "", names(images)) mcols(masks)$ImageName <- gsub("_a0_full_mask", "", names(masks))
images
masks <- masks[mcols(masks)$ImageName %in% mcols(images)$ImageName] identical(mcols(masks)$ImageName, mcols(images)$ImageName)
# Match panel and stack slice information panel <- panel[panel$full == 1,] panel <- panel[match(channel.mass[,1], panel$MetalTag),] # Add channel names to the image stacks CytoImageList object channelNames(images) <- panel$shortname
saveRDS(images, "pancreas_images.rds") saveRDS(masks, "pancreas_masks.rds")
file.remove("panel.csv", "ChannelMass.csv")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.