knitr::opts_chunk$set(echo = TRUE) knitr::opts_knit$set(root.dir = file.path("..", "extdata"))
library(S4Vectors) library(SingleCellExperiment) library(cytomapper)
Here, a subset of single-cell data, corresponding to 100 images from the full dataset is downloaded.
# Download the zipped folder image and unzip it url.cells <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/f1e3b8dc-56be-4172-bbc4-3a6f9de97563/file_downloaded") download.file(url.cells, destfile = "CellSubset.zip") unzip("CellSubset.zip") file.remove("CellSubset.zip") # Read-in the data cells <- read.csv("CellSubset.csv", stringsAsFactors = FALSE) # Order the dataset by ImageNumber and ObjectNumber cells <- cells[order(cells$ImageNumber, cells$ObjectNumber), ]
# Download the zipped folder image and unzip it url.image <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/0b236273-d21b-4566-84a2-f1c56324a900/file_downloaded") download.file(url.image, destfile = "Image.zip") unzip("Image.zip") file.remove("Image.zip") # Read-in the data image <- read.csv("All_Image.csv", stringsAsFactors = FALSE)
# Download the zipped folder image and unzip it url.celltypes <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/59e8da72-5bfe-4289-b95b-28348a6e1222/file_downloaded") download.file(url.celltypes, destfile = "CellTypes.zip") unzip("CellTypes.zip") file.remove("CellTypes.zip") # Read-in the data celltypes <- read.csv("CellTypes.csv", stringsAsFactors = FALSE)
# Download the zipped folder image and unzip it url.donors <- ("https://data.mendeley.com/public-files/datasets/cydmwsfztj/files/9074990e-1b93-4c79-8c49-1db01a66398b/file_downloaded") download.file(url.donors, destfile = "Donors.zip") unzip("Donors.zip") file.remove("Donors.zip") # Read-in the data donors <- read.csv("Donors.csv", stringsAsFactors = FALSE)
cell.metadata <- DataFrame(ImageNumber = cells$ImageNumber, CellNumber = cells$ObjectNumber, Pos_X = cells$Location_Center_X, Pos_Y = cells$Location_Center_Y, ParentIslet = cells$Parent_Islets, ClosestIslet = cells$Parent_ExpandedIslets, Area = cells$AreaShape_Area, NbNeighbours = cells$Neighbors_NumberOfNeighbors_3)
image.metadata <- DataFrame(ImageNumber = image$ImageNumber, ImageFullName = image$FileName_CleanStack, slide = image$Metadata_Slide, width = image$Width_CleanStack, height = image$Height_CleanStack)
cell.metadata <- merge(cell.metadata, image.metadata, by="ImageNumber")
This information is used by cytomapper
to match single-cell data with images and masks
cell.metadata$ImageName <- sub("_a0_full_clean.tiff", "", cell.metadata$ImageFullName)
# Add cell ids to cell metadata (format: "ImageName_CellNumber") cell.metadata$id <- paste(cell.metadata$ImageName, cell.metadata$CellNumber, sep="_") # Merge cell metadata and cell type information cell.metadata <- merge(cell.metadata, celltypes[, c("id", "CellCat", "CellType")], by="id")
cell.metadata <- merge(cell.metadata, donors, by="slide")
# Rows are ordered by ImageNumber and CellNumber cell.metadata <- cell.metadata[order(cell.metadata$ImageNumber, cell.metadata$CellNumber), ] # Cell ids are used as row names rownames(cell.metadata) <- cell.metadata$id
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)
# Match panel and stack slice information panel <- panel[panel$full == 1,] panel <- panel[match(channel.mass[,1], panel$MetalTag),] # Add short protein names as panel rownames rownames(panel) <- panel$shortname
Here, we import the mean intensity per cell
cur_counts <- cells[, grepl("Intensity_MeanIntensity_CleanStack", colnames(cells))]
channelNumber <- as.numeric(sub("^.*_c", "", colnames(cur_counts))) cur_counts <- cur_counts[, order(channelNumber, decreasing = FALSE)]
sce <- SingleCellExperiment(assays = list(counts = t(as.matrix(cur_counts))))
exprs = asinh-transformed counts
assay(sce, "exprs") <- asinh(counts(sce)/1)
rownames(sce) <- rownames(panel) colnames(sce) <- rownames(cell.metadata)
colData(sce) <- cell.metadata rowData(sce) <- panel sce
saveRDS(sce, "pancreas_sce.rds")
file.remove("All_Image.csv", "CellSubset.csv", "CellTypes.csv", "Donors.csv", "panel.csv", "ChannelMass.csv")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.