diff --git a/DESCRIPTION b/DESCRIPTION index 343d39f0..ab5690aa 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: Spectre Type: Package -Title: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry data. -Version: 0.4.5 +Title: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry and imaging data. +Version: 0.5.0 Author: Thomas Ashhurst, Felix Marsh-Wakefield, Givanna Putri Maintainer: Thomas Ashhurst Description: A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry data. @@ -36,7 +36,17 @@ Imports: ggraph, stringr, rsvd, - irlba + irlba, + gridExtra, + raster, + tiff, + rgeos, + tidyr, + sp, + sf, + stars, + qs, + exactextractr Suggests: RoxygenNote: 7.1.1 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 00eef526..40c617ba 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,17 +5,26 @@ export(create.dt) export(create.stats) export(create.sumtable) export(do.add.cols) +export(do.add.masks) +export(do.add.percell) export(do.aggregate) export(do.align) export(do.asinh) +export(do.calculate.area) export(do.clip) +export(do.create.outlines) export(do.combine.cols) export(do.embed.columns) +export(do.extract) +export(do.extract.cell.dat) export(do.filter) +export(do.filter.percell) +export(do.label.from.polygon) export(do.list.summary) export(do.list.switch) export(do.logicle) export(do.merge.files) +export(do.pull.data) export(do.reorder) export(do.rescale) export(do.stats) @@ -27,12 +36,14 @@ export(make.colour.plot) export(make.multi.plot) export(make.network.plot) export(make.pheatmap) +export(make.spatial.plot) export(make.volcano.plot) export(package.check) export(package.install) export(package.load) export(prep.cytonorm) export(read.files) +export(read.spatial.files) export(run.align) export(run.chronoclust) export(run.cytonorm) @@ -44,10 +55,12 @@ export(run.pca) export(run.phenograph) export(run.prepare.chronoclust) export(run.ruv) +export(run.spatial.analysis) export(run.tsne) export(run.umap) export(train.cytonorm) export(train.knn.classifier) export(write.files) +export(write.hdf5) export(write.sumtables) import(data.table) diff --git a/R/create.dt.R b/R/create.dt.R index 32f5f39e..c13c1cfb 100755 --- a/R/create.dt.R +++ b/R/create.dt.R @@ -7,8 +7,7 @@ #' #' @usage create.dt(dat, from) #' -#' @author -#' Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} #' #' @references \url{https://github.com/ImmuneDynamics/Spectre}. #' diff --git a/R/create.stats.R b/R/create.stats.R index 8f4c0145..364eee9e 100755 --- a/R/create.stats.R +++ b/R/create.stats.R @@ -11,6 +11,10 @@ #' @param pairwise.test DEFAULT = 'wilcox.test'. Currently the only option #' @param corrections DEFAULT = 'fdr' (false discovery rate). Currently the only option #' +#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' #' @import data.table #' #' @export diff --git a/R/create.sumtable.R b/R/create.sumtable.R index 84e6df29..35ff3ed2 100755 --- a/R/create.sumtable.R +++ b/R/create.sumtable.R @@ -26,10 +26,9 @@ #' use.cols = names(dat)[c(11:19)], #' counts = counts) #' -#' @author -#' Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} #' -#' @references \url{https://sydneycytometry.org.au/spectre}. +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. #' #' @export diff --git a/R/demo.asinh.R b/R/demo.asinh.R index aff50b17..8c3babb1 100755 --- a/R/demo.asinh.R +++ b/R/demo.asinh.R @@ -8,9 +8,9 @@ #' #' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} #' -#' @source Thomas M Ashhurst. +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. #' -#' @references \url{https://sydneycytometry.org.au/spectre}. +#' @source Thomas M Ashhurst. #' #' @examples #' demo.asinh diff --git a/R/demo.batches.1.R b/R/demo.batches.1.R index 94fab8d4..e92f37a5 100755 --- a/R/demo.batches.1.R +++ b/R/demo.batches.1.R @@ -10,7 +10,7 @@ #' #' @source Thomas M Ashhurst. #' -#' @references \url{https://sydneycytometry.org.au/spectre}. +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. #' #' @examples #' demo.batches.1 diff --git a/R/demo.clustered.R b/R/demo.clustered.R index d5ba3243..4ead503d 100755 --- a/R/demo.clustered.R +++ b/R/demo.clustered.R @@ -10,8 +10,8 @@ #' #' @source Thomas M Ashhurst. #' -#' @references \url{https://sydneycytometry.org.au/spectre}. -#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' #' @examples #' demo.clustered #' diff --git a/R/demo.exp.R b/R/demo.exp.R index 0266b5d3..75d0a776 100755 --- a/R/demo.exp.R +++ b/R/demo.exp.R @@ -10,8 +10,8 @@ #' #' @source Thomas M Ashhurst. #' -#' @references \url{https://sydneycytometry.org.au/spectre}. -#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' #' @examples #' demo.exp #' diff --git a/R/demo.spatial.R b/R/demo.spatial.R new file mode 100755 index 00000000..59e63aac --- /dev/null +++ b/R/demo.spatial.R @@ -0,0 +1,18 @@ +#' demo.spatial - Demo spatial dataset consisting of 6x regions of interest, acquired using Imaging Mass Cytometry (IMC) +#' +#' @docType data +#' +#' @usage demo.spatial +#' +#' @format An R object (list) containing 6x ROIs, each consisting of raster stacks, masks, and extracted cellular data in a data.table +#' +#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' +#' @source Thomas M Ashhurst. +#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' +#' @examples +#' demo.spatial +#' +"demo.spatial" diff --git a/R/demo.start.R b/R/demo.start.R index b0723d42..0359e4cb 100755 --- a/R/demo.start.R +++ b/R/demo.start.R @@ -10,8 +10,8 @@ #' #' @source Thomas M Ashhurst. #' -#' @references \url{https://sydneycytometry.org.au/spectre}. -#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' #' @examples #' demo.start #' diff --git a/R/demo.sum.R b/R/demo.sum.R index 53d76068..435f0f53 100755 --- a/R/demo.sum.R +++ b/R/demo.sum.R @@ -10,8 +10,8 @@ #' #' @source Thomas M Ashhurst. #' -#' @references \url{https://sydneycytometry.org.au/spectre}. -#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' #' @examples #' demo.sum #' diff --git a/R/do.add.cols.R b/R/do.add.cols.R index 62426f80..b691addc 100755 --- a/R/do.add.cols.R +++ b/R/do.add.cols.R @@ -13,8 +13,8 @@ #' #' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} #' -#' @references \url{https://sydneycytometry.org.au/spectre}. -#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' #' @examples #' add.dt <- data.table('Files' = unique(Spectre::demo.asinh$FileName), #' 'SampleNumber' = c(1:12)) diff --git a/R/do.add.masks.R b/R/do.add.masks.R new file mode 100644 index 00000000..b6b469be --- /dev/null +++ b/R/do.add.masks.R @@ -0,0 +1,129 @@ +#' do.add.masks +#' +#' @param spatial.dat NO DEFAULT. Spatial data list. +#' @param mask.loc NO DEFAULT. Directory of mask files. +#' @param masks NO DEFAULT. Vector of mask file names +#' @param mask.label DEFAULT = "cell_mask" +#' @param mask.ext DEFAULT = "_mask.tif" (will also recognise the '.tiff' file type) +#' @param correct.extent DEFAULT = TRUE +#' @param flip.y DEFAULT = TRUE +#' @param value.modifier DEFAULT = 65535 +#' @param array DEFAULT = FALSE +#' +#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' +#' @import data.table +#' +#' @export + +do.add.masks <- function(spatial.dat, + mask.loc, + masks, + + mask.label = "cell.mask", + mask.ext = "_mask.tif", + + correct.extent = TRUE, + flip.y = TRUE, + value.modifier = 65535, + array = FALSE + ){ + + ### Require + + require('raster') + require('hdf5r') + require('HDF5Array') + + ### Setup + + message(paste0('Adding masks to ', mask.label)) + + spat.names <- names(spatial.dat) + spat.names + + mask.names <- gsub(mask.ext, "", masks) + mask.names + + mask.check <- (spat.names == mask.names) + mask.check + + if(all(mask.check) == FALSE){ + stop('Error -- list of ROIs does not match the list of masks') + } + + ### Read in mask files + + setwd(mask.loc) + + for(i in spat.names){ + # i <- spat.names[[1]] + + message(paste0(" -- processing ", i)) + + if(grepl('.h5', mask.ext)){ + file.ext <- '.h5' + } else { + file.ext <- 'other' + } + + ## If HDF5 files + + if(file.ext == '.h5'){ + + message(" ... reading HDF5 file") + + # h5closeAll() + # h5ls(paste0(i, mask.ext)) + + mask.img <- h5read(paste0(i, mask.ext), name = 'exported_data') + mask.img <- array(as.numeric(mask.img), dim(mask.img)) + mask.img <- matrix(mask.img, nrow = dim(mask.img)[3], ncol = dim(mask.img)[2]) + mask.img <- raster(mask.img) + + } else { + + ## If NOT HDF5 files + + if(array == FALSE){ + mask.img <- readTIFF(paste0(i, mask.ext)) + mask.img <- raster(mask.img) + } + + if(array == TRUE){ + + message(" ... reading array") + + mask.img <- raster(paste0(i, mask.ext)) + } + + } + + ## Correct extent + + if(correct.extent == TRUE){ + message(" ... correcting extent") + extent(mask.img) <- c(0, dim(mask.img)[2], 0,dim(mask.img)[1]) # Y axis - X axis + } + + ## Flip Y + + if(flip.y == TRUE){ + message(" ... flipping Y") + mask.img <- flip(mask.img, 'y') + } + + ## Finalise + + raster::values(mask.img) <- raster::values(mask.img) * value.modifier + names(mask.img) <- mask.label + spatial.dat[[i]]$MASKS[[mask.label]]$maskraster <- mask.img + + } + + message("Returning spatial data object with added masks") + return(spatial.dat) +} + diff --git a/R/do.add.percell.R b/R/do.add.percell.R new file mode 100755 index 00000000..7d10158c --- /dev/null +++ b/R/do.add.percell.R @@ -0,0 +1,29 @@ +#' do.add.percell +#' +#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' +#' @import data.table +#' +#' @export + +do.add.percell <- function(spatial.dat, + percell.dat, + roi.col, + name = "per.cell"){ + + ### Setup + message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.") + + ### Loop + + for(i in names(spatial.dat)){ + # i <- "20171228_spleen315_500x500_editedforFAS_s1_p9_r2_a2_ac" + temp <- percell.dat[percell.dat[[roi.col]] == i,] + spatial.dat[[i]]$CPDATA[[name]] <- temp + } + + return(spatial.dat) + +} diff --git a/R/do.aggregate.R b/R/do.aggregate.R index 30748db2..670361cf 100755 --- a/R/do.aggregate.R +++ b/R/do.aggregate.R @@ -21,6 +21,9 @@ #' plot.title = "Pheatmap", #' sample.col = "Population", #' plot.cols = names(exp)[c(2:10)]) +#' @author Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. #' #' @import data.table #' diff --git a/R/do.calculate.area.R b/R/do.calculate.area.R new file mode 100644 index 00000000..b2a3d775 --- /dev/null +++ b/R/do.calculate.area.R @@ -0,0 +1,72 @@ +#' do.calculate.area +#' +#' @param dat NO DEFAULT. Spatial data list +#' @param region DEFAULT = NULL. Name of the region mask, if present. +#' +#' @import data.table +#' +#' @export + +do.calculate.area <- function(dat, + region = NULL){ + + ### Setup + + # dat <- spatial.dat + # region <- 'regions' + + ### Preparation + + roi.names <- names(dat) + + ### Processing + + area.list <- list() + + for(i in roi.names){ + + # i <- roi.names[[1]] + + ## If region masks are present + + if(!is.null(region)){ + + poly.names <- dat[[i]]$MASKS[[region]]$polygons@data + + areas <- area(dat[[i]]$MASKS[[region]]$polygons) + areas <- sqrt(areas) + areas <- as.data.table(t(areas)) + + names(areas) <- as.character(poly.names[[1]]) + + # total.area <- sqrt(dim(dat[[i]]$RASTERS[[1]])[1] * dim(dat[[i]]$RASTERS[[1]])[2]) + # total.area <- as.data.table(total.area) + # names(total.area) <- 'Total' + # areas <- cbind(areas, total.area) + area.list[[i]] <- areas + + } + + ## If region masks are NOT present + if(is.null(region)){ + + total.area <- sqrt(dim(dat[[i]]$RASTERS[[1]])[1] * dim(dat[[i]]$RASTERS[[1]])[2]) + total.area <- as.data.table(total.area) + + names(total.area) <- 'Total' + area.list[[i]] <- total.area + + } + } + + area.list + + area.res <- rbindlist(area.list, fill = TRUE) + area.res <- cbind(roi.names, area.res) + names(area.res)[1] <- "ROI" + + ### Return + + return(area.res) + +} \ No newline at end of file diff --git a/R/do.create.outlines.R b/R/do.create.outlines.R new file mode 100644 index 00000000..1ae39cfc --- /dev/null +++ b/R/do.create.outlines.R @@ -0,0 +1,113 @@ +#' do.create.outlines +#' +#' @param spatial.dat NO DEFAULT. Spatial data list +#' @param mask.name NO DEFAULT. Name of the mask to create outlines for +#' @param method DEFAULT = 'stars'. Can be 'stars' or 'raster' +#' +#' @import data.table +#' +#' @export + +do.create.outlines <- function(spatial.dat, + mask.name, + method = 'stars' # 'stars' 'raster' +){ + + ### Setup + + #message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.") + + require(raster) + require(tiff) + require(rgeos) + require(tidyr) + require(ggplot2) + require(dplyr) + + # polygons.name <- paste0(mask.name, "_polygons") + # outlines.name <- paste0(mask.name, "_outlines") + # centroids.name <- paste0(mask.name, "_centroids") + + ### Slow or fast version + + if(method == 'stars'){ + message(paste0("Creating polygons, outlines, and centroids using 'stars' method.")) + } + + if(method == 'raster'){ + message(paste0("Creating polygons, outlines, and centroids using standard method -- this step may take some time, please be patient")) + } + + if(method == 'gdal'){ + message("GDAL version not currently supportedb -- reverting to stars method") + # if(length(Sys.which("gdal_polygonize.py")) > 1){ + # message(paste0("Creating polygons, outlines, and centroids using GDAL -- this step may take some time, please be patient")) + # } + } + + ### Run + + for(i in names(spatial.dat)){ + # i <- names(spatial.dat)[[1]] + start.time <- Sys.time() + + mask <- spatial.dat[[i]]$MASKS[[mask.name]]$maskraster + + message(paste0("Processing masks for ROI ", i)) + + ## rasterToPolygons method + if(method == 'raster'){ + polygon <- rasterToPolygons(mask, dissolve=TRUE) # This is the long step + spatial.dat[[i]]$MASKS[[mask.name]][["polygons"]] <- polygon + message("... polygons complete") + } + + ## stars method + if(method == 'stars'){ + + require(stars) + require(sf) + require(sp) + + names(mask) <- "TEMP_MASK" + + stars.mask <- stars::st_as_stars(mask) + + sf::st_crs(stars.mask) <- 4326 + + res <- sf::st_as_sf(stars.mask, # requires the sf, sp, raster and stars packages + as_points = FALSE, + merge = TRUE) #, + #na.rm = TRUE) + #group = TRUE) # TRUE crashes, FALSE does not + + res$TEMP_MASK + + res <- res %>% + group_by(TEMP_MASK) %>% + summarise(geometry = sf::st_union(geometry)) %>% + ungroup() + + polygon <- sf::as_Spatial(res) + + names(polygon) <- mask.name + crs(polygon) <- NA + + spatial.dat[[i]]$MASKS[[mask.name]][["polygons"]] <- polygon + message("... polygons complete") + } + + ### Create outlines + outline <- fortify(polygon) + spatial.dat[[i]]$MASKS[[mask.name]][["outlines"]] <- outline + message("... outlines complete") + + ### Create centroids + centroids <- gCentroid(polygon,byid=TRUE) + spatial.dat[[i]]$MASKS[[mask.name]][["centroids"]] <- centroids + message("... centroids complete") + } + + message("Returning spatial data") + return(spatial.dat) +} diff --git a/R/do.extract.R b/R/do.extract.R new file mode 100644 index 00000000..a78e5a92 --- /dev/null +++ b/R/do.extract.R @@ -0,0 +1,136 @@ +#' do.extract +#' +#' @param dat NO DEFAULT. Spatial data list +#' @param mask NO DEFAULT. Name of mask to use for cell data extraction +#' @param name DEFAULT = 'CellData'. Name of the extracted cell dataset. +#' @param fun DEFAULT = 'mean'. Summarisation function. +#' +#' @import data.table +#' +#' @export + +do.extract <- function(dat, # spatial.data object + mask, # name of the mask being summarised + name = "CellData", + fun = "mean" # type of marker summarisation (mean, median etc) +){ + + #message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.") + + require('rgeos') + require('sp') + require('rgdal') + require('exactextractr') + require('data.table') + + ### Demo data + + # spatial.dat <- demo.spatial + # str(spatial.dat, 3) + # + # for(i in names(spatial.dat)){ + # spatial.dat[[i]]$DATA <- NULL + # } + # + # str(spatial.dat, 3) + # + # dat <- spatial.dat + # mask <- "cell.mask" + # name = "CellData" + # fun = "mean" + # + # str(dat, 4) + + ### Loop for each ROI + + rois <- names(spatial.dat) + + for(roi in rois){ + # roi <- rois[[1]] + message(paste0("Processing ", roi)) + + roi.stack <- spatial.dat[[roi]]$RASTERS + roi.poly <- spatial.dat[[roi]]$MASKS[[mask]]$polygons + + raster.names <- names(roi.stack) + ply.df <- as.data.frame(roi.poly) + ply.df + + ply.centroids <- gCentroid(roi.poly,byid=TRUE) + ply.centroids.df <- as.data.frame(ply.centroids) + ply.centroids.df # mask number, with X and Y coordinates + + ply.centroids.df <- cbind(ply.centroids.df, as.data.frame(area(roi.poly))) + names(ply.centroids.df)[3] <- "Area" + + ## RASTERS + + for(i in raster.names){ + # i <- raster.names[[1]] + message(paste0("... ", i)) + temp.dat <- roi.stack[[i]] + + ## Slower method + + # extracted.dat <- raster::extract(x = temp.dat, y = roi.poly, df = TRUE) # this is the time consuming step + # extracted.dat.res <- aggregate(. ~ID, data = extracted.dat, FUN = fun) + # # #colnames(extracted.dat.res)[2] <- i # should we be removing .tiff here? If we do should be the same in the other read.spatial function, to ensure matching consistency + # + # ply.centroids.df <- cbind(ply.centroids.df, extracted.dat.res[2]) ## doing this would remove the necessity to calculate centroids within the 'make.spatial.plot' function + + ## FAST method + + ## Faster options + + # vx <- velox(temp.dat) + # res <- vx$extract(sp=roi.poly, fun=mean) # 3293 polygons #3294? + + res <- exactextractr::exact_extract(temp.dat, st_as_sf(roi.poly), fun=fun) + res <- as.data.table(res) + + names(res) <- i + ply.centroids.df <- cbind(ply.centroids.df, res) ## doing this would remove the necessity to calculate centroids within the 'make.spatial.plot' function + } + + ID <- c(1:nrow(ply.centroids.df)) + roi.dat <- cbind(ID, ply.centroids.df) + roi.dat <- as.data.table(roi.dat) + + ## OTHER MASK POLYGONS + + other.polys <- names(spatial.dat[[roi]]$MASKS) + other.polys <- other.polys[!other.polys %in% mask] + + cols <- c("x", "y", "ID") + + roi.dat.xyid <- roi.dat[,..cols] + names(roi.dat.xyid) <- c('Longitude', 'Latitude', 'Names') + roi.dat.xyid + + Longitude <- roi.dat.xyid$Longitude + Latitude <- roi.dat.xyid$Latitude + coordinates(roi.dat.xyid) <- ~ Longitude + Latitude + + if(length(other.polys) != 0){ + for(i in c(1:(length(other.polys)))){ + # i <- 1 + ply.name <- other.polys[[i]] + + message(paste0("... occurance in ", ply.name)) + + ply <- spatial.dat[[roi]]$MASKS[[ply.name]]$polygons + + proj4string(roi.dat.xyid) <- proj4string(ply) + + over.res <- over(roi.dat.xyid, ply) + over.res <- as.data.table(over.res) + roi.dat <- cbind(roi.dat, over.res) + } + } + + spatial.dat[[roi]]$DATA[[name]] <- roi.dat + } + + ### Return new spatial.dat object + return(spatial.dat) +} diff --git a/R/do.extract.cell.dat.R b/R/do.extract.cell.dat.R new file mode 100755 index 00000000..0953c80d --- /dev/null +++ b/R/do.extract.cell.dat.R @@ -0,0 +1,31 @@ +#' do.extract.cell.dat +#' +#' @import data.table +#' +#' @export + +do.extract.cell.dat <- function(spatial.dat, + target.dat){ + + ### Setup + message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.") + + ### Extract + + dat.list <- list() + + for(i in names(spatial.dat)){ + roi.dat <- spatial.dat[[i]]$CPDATA[[target.dat]] + nme.vec <- rep(i, nrow(roi.dat)) + + roi.dat <- cbind("ROI" = nme.vec, roi.dat) + dat.list[[i]] <- roi.dat + } + + dat.dt <- rbindlist(dat.list, fill = TRUE) + return(dat.dt) +} + + + + diff --git a/R/do.filter.percell.R b/R/do.filter.percell.R new file mode 100755 index 00000000..57f9aa1b --- /dev/null +++ b/R/do.filter.percell.R @@ -0,0 +1,59 @@ +#' do.filter.percell +#' +#' @import data.table +#' +#' @export + +do.filter.percell <- function(spatial.dat, + per.cell, + to, + filter.by, + id.col = "ObjectNumber", + x.col = "Location_Center_X", + y.col = "Location_Center_Y", + simplify.cp.colname = TRUE, + value.modifier = 65535){ + + ### Setup + message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.") + + ### Loop + + for(i in names(spatial.dat)){ + # i <- "20171228_spleen315_500x500_editedforFAS_s1_p9_r2_a2_ac" + temp <- spatial.dat[[i]]$CPDATA[[per.cell]] + temp.filtered <- temp[,grepl( filter.by , names(temp)),with = FALSE] + temp.filtered <- temp.filtered * value.modifier + temp.filtered <- cbind(ID = temp[[id.col]],x = temp[[x.col]], y = temp[[y.col]], temp.filtered) + + if(simplify.cp.colname == TRUE){ + measr <- temp.filtered[,c(1:3),with = FALSE] + chnls <- temp.filtered[,c(4:length(names(temp.filtered))),with = FALSE] + + names(chnls) <- sub('.*\\_c', '', names(chnls)) + temp.names <- names(chnls) + + for(b in c(1:length(temp.names))){ + a <- temp.names[[b]] + if(nchar(a) == 1){ + a <- paste0("0", a) + } + temp.names[[b]] <- a + } + + names(chnls) <- temp.names + neworder <- sort(names(chnls)) + chnls <- setcolorder(chnls, neworder) + + temp.filtered <- cbind(measr, chnls) + } + + spatial.dat[[i]]$CPDATA[[to]] <- temp.filtered + } + + ### Return + return(spatial.dat) + +} + + diff --git a/R/do.label.from.polygon.R b/R/do.label.from.polygon.R new file mode 100755 index 00000000..1306f7fb --- /dev/null +++ b/R/do.label.from.polygon.R @@ -0,0 +1,94 @@ +#' do.label.from.polygon +#' +#' @import data.table +#' +#' @export + +do.label.from.polygon <- function(spatial.dat, + cell.dat, + mask, + labels, + + name = "Label", + id.col = 'ID', + roi.col = 'ROI'#, + #x.col = 'x', + #y.col = 'y' +){ + + ### + + # spatial.dat <- spatial.dat + # cell.dat <- cell.dat + # mask <- 'obj_mask' + # + # name = "Label" + # labels <- c("HTC", "CTL", "Background", "Hepatocyte", "cDC", "CD11bpos", "Other immune", "Macrophages") + # + # id.col = 'ID' + # roi.col = 'ROI' + # x.col = 'x' + # y.col = 'y' + + TEMP_LABEL_PLACEHOLDER1 <- labels + TEMP_LABEL_PLACEHOLDER1 <- as.data.table(TEMP_LABEL_PLACEHOLDER1) + + ### + rois <- names(spatial.dat) + + start.dat.list <- list() + dat.list <- list() + mask.list <- list() + + unq.labels <- list() + res.list <- list() + + ### + + for(i in rois){ + unq.labels[[i]] <- unique(as.data.frame(spatial.dat[[i]]$MASKS[[mask]]$polygons)) + rm(i) + } + + all.labs <- unique(rbindlist(unq.labels, fill = TRUE)) + all.labs <- all.labs[order(all.labs)] + + all.labs <- cbind(all.labs, TEMP_LABEL_PLACEHOLDER1) + all.labs + + for(i in rois){ + # i <- rois[[8]] + dat.list[[i]] <- cell.dat[cell.dat[[roi.col]] == i,] + coordinates(dat.list[[i]]) <- ~ x + y + + mask.list[[i]] <- spatial.dat[[i]]$MASKS[[mask]]$polygons + proj4string(dat.list[[i]]) <- proj4string(mask.list[[i]]) + + res <- over(dat.list[[i]], mask.list[[i]]) + res.list[[i]] <- res[[1]] + } + + ### + + res.dt <- unlist(res.list) + res.dt <- as.data.table(res.dt) + res.dt + + if(nrow(cell.dat) != nrow(res.dt)){ + stop("Result dt rows are inconsistent with starting dt rows") + } + + res.dt <- do.embed.columns(res.dt, "res.dt", all.labs, 'obj_mask') + res.dt + + res.dt$res.dt <- NULL + names(res.dt)[length(names(res.dt))] <- name + res.dt + + return.dat <- cbind(cell.dat, res.dt) + + ### + return(return.dat) +} + + diff --git a/R/do.pull.data.R b/R/do.pull.data.R new file mode 100644 index 00000000..f894cf22 --- /dev/null +++ b/R/do.pull.data.R @@ -0,0 +1,36 @@ +#' do.pull.data +#' +#' @param spatial.dat NO DEFAULT. Spatial data list. +#' @param target.dat NO DEFAULT. Dataset to pull. +#' +#' @import data.table +#' +#' @export + +do.pull.data <- function(spatial.dat, + target.dat){ + + ### Setup + #message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.") + + require(data.table) + + ### Extract + + dat.list <- list() + + for(i in names(spatial.dat)){ + roi.dat <- spatial.dat[[i]]$DATA[[target.dat]] + nme.vec <- rep(i, nrow(roi.dat)) + + roi.dat <- cbind("ROI" = nme.vec, roi.dat) + dat.list[[i]] <- roi.dat + } + + dat.dt <- rbindlist(dat.list, fill = TRUE) + return(dat.dt) +} + + + + diff --git a/R/make.spatial.plot.R b/R/make.spatial.plot.R new file mode 100644 index 00000000..161eb684 --- /dev/null +++ b/R/make.spatial.plot.R @@ -0,0 +1,355 @@ +#' make.spatial.plot +#' +#' @param spatial.dat NO DEFAULT.A spatial data list +#' @param image.roi NO DEFAULT.The name of the ROI to plot +#' @param image.channel NO DEFAULT.Name of the channel to plot +#' @param mask.outlines DEFAULT = NULL. Name of the mask for outlines +#' @param cell.dat DEFAULT = NULL. Character name for the cellular dataset in the spatial data list, or a data.table object. +#' @param cell.col DEFAULT = NULL. Name of cellular dataset to colour points by +#' @param image.y.flip DEFAULT = TRUE. Flips the Y-axis orientation. +#' @param image.mask.size DEFAULT = 0.1 +#' @param image.mask.colour DEFAULT = "gold" +#' @param image.min.threshold DEFAULT = 0.00. Lower threshold for plot signal. Values below this target will be clipped. +#' @param image.max.threshold DEFAULT = 0.99. Upper threshold for plot signal. Values above this target will be clipped. +#' @param image.blank DEFAULT = FALSE. Will blank the plot image. +#' @param cell.x DEFAULT = "x". Column name for the 'x' coordinate in data.table +#' @param cell.y DEFAULT = "y". Column name for the 'y' coordinate in data.table +#' @param cell.col.type DEFAULT= "numeric". Can be 'factor'. +#' @param cell.colours = DEFAULT = "spectral". +#' @param cell.col.min.threshold = DEFAULT = 0.01. Values below this target will be clipped. +#' @param cell.col.max.threshold = DEFAULT = 0.995. Values above this target will be clipped. +#' @param title DEFAULT = paste0(image.roi) +#' @param dot.size DEFAULT = 1 +#' @param dot.alpha DEFAULT = 1 +#' @param align.xy.by DEFAULT = cell.dat +#' @param align.col.by DEFAULT = cell.dat +#' @param save.to.disk DEFAULT = TRUE +#' @param path DEFAULT = getwd(). Path for saving image files +#' @param plot.width DEFAULT = 9 +#' @param plot.height DEFAULT = 7 +#' @param blank.axis DEFAULT = FALSE +#' +#' @import data.table +#' +#' @export + +make.spatial.plot <- function(spatial.dat, # spatial data object + image.roi, # name of ROI + image.channel, # name of channel + + ## Options for adding cell outlines + mask.outlines = NULL, # character -- the outlines in spatial.dat object + + ## Options for adding cellular data + cell.dat = NULL, # can be character (if it's data within spatial.dat) or a data.table + cell.col = NULL, # column for colouration + + ## Other settings (with defaults) + image.y.flip = TRUE, + image.mask.size = 0.1, + image.mask.colour = "gold", + image.min.threshold = 0.00, + image.max.threshold = 0.99, + image.blank = FALSE, + + cell.x = "x", + cell.y = "y", + cell.col.type = "numeric", + cell.colours = "spectral", + cell.col.min.threshold = 0.01, + cell.col.max.threshold = 0.995, + + title = paste0(image.roi), + dot.size = 1, + dot.alpha = 1, + align.xy.by = cell.dat, # choose a data frame to set absolute limits for X/Y/colour + align.col.by = cell.dat, + save.to.disk = TRUE, + path = getwd(), + plot.width = 9, + plot.height = 7, + blank.axis = FALSE) +{ + + ### TESTING + # library(raster) + # library(data.table) + # library(tiff) + # library(ggplot2) + # + # spatial.dat = spatial.dat + # + # spatial.dat$meta.data + # + # roi = "20171228_spleen315_500x500_editedforFAS_s1_p9_r2_a2_ac" + # roi.marker = "CD20_Dy161" + + # cell.dat <- spatial.dat$cell.dat.means.filtered + # cell.dat <- cell.dat[cell.dat[["ImageName"]] == "20171228_spleen315_500x500_editedforFAS_s1_p9_r2_a2_ac_ilastik_s2_Probabilities_mask.tiff",] + # cell.dat = cell.dat + # cell.x = "X" + # cell.y = "Y" + # cell.colour = 'CD20' + # + # add.outlines = TRUE + # flip.y.axis = TRUE + + ### Check that necessary packages are installed + if(!is.element('Spectre', installed.packages()[,1])) stop('Spectre is required but not installed') + if(!is.element('ggplot2', installed.packages()[,1])) stop('ggplot2 is required but not installed') + if(!is.element('scales', installed.packages()[,1])) stop('scales is required but not installed') + if(!is.element('colorRamps', installed.packages()[,1])) stop('colorRamps is required but not installed') + if(!is.element('ggthemes', installed.packages()[,1])) stop('ggthemes is required but not installed') + if(!is.element('RColorBrewer', installed.packages()[,1])) stop('RColorBrewer is required but not installed') + if(!is.element('raster', installed.packages()[,1])) stop('raster is required but not installed') + if(!is.element('rgeos', installed.packages()[,1])) stop('rgeos is required but not installed') + + ### Require packages + require(Spectre) + require(ggplot2) + require(scales) + require(colorRamps) + require(ggthemes) + require(RColorBrewer) + require(raster) + require(rgeos) + + ### Compatability conversions + + roi <- image.roi + roi.marker <- image.channel + + #cell.dat + cell.colour <- cell.col + + add.outlines <- image.outlines <- mask.outlines + flip.y.axis <- image.y.flip + + cell.colour.type <- cell.col.type + + raster.mask.size <- image.mask.size + raster.mask.colour <- image.mask.colour + raster.min.threshold <- image.min.threshold + raster.max.threshold <- image.max.threshold + + col.min.threshold <- cell.col.min.threshold + col.max.threshold <- cell.col.max.threshold + + colours <- cell.colours + + ### Colour setup + + # Jet + if(colours == "jet"){ + colour.scheme <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) + } + + # Spectral + if(colours == "spectral"){ + spectral.list <- colorRampPalette(brewer.pal(11,"Spectral"))(50) + spectral.list <- rev(spectral.list) + colour.scheme <- colorRampPalette(c(spectral.list)) + } + + # Viridis + if(colours == "viridis"){ + colour.scheme <- colorRampPalette(c(viridis_pal(option = "viridis")(50))) + } + + # Inferno + if(colours == "inferno"){ + colour.scheme <- colorRampPalette(c(viridis_pal(option = "inferno")(50))) + } + + #Magma + if(colours == "magma"){ + colour.scheme <- colorRampPalette(c(viridis_pal(option = "magma")(50))) + } + + ### cell.dat setup + + if(!is.null(cell.dat)){ + + if(is.character(cell.dat) == TRUE){ + temp <- spatial.dat[[roi]]$DATA[[cell.dat]] + cell.dat <- temp + } + + + if(cell.colour.type == "numeric"){ + + # Dot point colouration + if(is.null(align.col.by) == TRUE){ + ColrMin <- quantile(cell.dat[[cell.colour]], probs = c(col.min.threshold)) + ColrMax <- quantile(cell.dat[[cell.colour]], probs = c(col.max.threshold)) + } + + if(is.null(align.col.by) == FALSE){ + ColrMin <- quantile(align.col.by[[cell.colour]], probs = c(col.min.threshold)) + ColrMax <- quantile(align.col.by[[cell.colour]], probs = c(col.max.threshold)) + } + + } + + } + + + ### Preparat the raster data + + ## Image prep + + raster.image <- spatial.dat[[roi]]$RASTERS[[roi.marker]] + + tiff.p <- rasterToPoints(raster.image) + tiff.df <- data.frame(tiff.p) + raster.label <- names(tiff.df)[3] + colnames(tiff.df) <- c("x_axis", "y_axis", raster.label) + + ## Create cell outlines + if(!is.null(mask.outlines)){ + outline <- spatial.dat[[roi]]$MASKS[[mask.outlines]]$outlines + centroids <- spatial.dat[[roi]]$MASKS[[mask.outlines]]$centroids + + centroid.xmin <- centroids@bbox[1] + centroid.xmax <- centroids@bbox[3] + + centroid.ymin <- centroids@bbox[2] + centroid.ymax <- centroids@bbox[4] + } + + ## Flip y-axis values + + # if(flip.y.axis == TRUE){ + # dat <- invert.y.axis(dat, y.axis) + # } + + ## Normalise XY for cell centroids + plot.normalize <- function(dat, min, max){ + return(((dat- min(dat)) / (max(dat)-min(dat))) * (max - min) + min) + } + + # if(!is.null(cell.dat)){ + # # X AXIS + # cell.dat[[cell.x]] <- plot.normalize(cell.dat[[cell.x]], min = centroid.xmin, max = centroid.xmax) + # + # # Y AXIS + # cell.dat[[cell.y]] <- plot.normalize(cell.dat[[cell.y]], min = centroid.ymin, max = centroid.ymax) + # + # } + + ## Raster colour limits + + RastMin <- quantile(tiff.df[[3]], probs = c(raster.min.threshold)) + RastMax <- quantile(tiff.df[[3]], probs = c(raster.max.threshold)) + + ############################################### + ### Add a check to see if centroids line up ### + ############################################### + + ### Generate and show coloured plot + + if(image.blank == FALSE){ + p <- ggplot(data=tiff.df, aes(x=tiff.df[[1]], y=tiff.df[[2]])) + + + ## Plot the raster (IMC image) + geom_raster(aes(fill=tiff.df[[3]])) + + scale_fill_gradient(raster.label, + low = "black", + high = "white", + limits=c(RastMin,RastMax), + oob=squish) + } + + if(image.blank == TRUE){ + p <- ggplot(data=tiff.df, aes(x=tiff.df[[1]], y=tiff.df[[2]])) + + + ## Plot the raster (IMC image) + geom_raster(aes(fill=tiff.df[[3]])) + + scale_fill_gradient(raster.label, + low = "black", + high = "black", + limits=c(RastMin,RastMax), + oob=squish) + } + + + + ### Plot the cell mask boundaries + + if(!is.null(image.outlines)){ + p <- p + geom_path(aes(x = long, y = lat, group = group), + data = outline, + size = raster.mask.size, + col = raster.mask.colour) + } + + ## Plot the cellular data + + if(!is.null(cell.dat)){ + if(cell.colour.type == "numeric"){ + p <- p + geom_point(data=cell.dat, + aes(x=cell.dat[[cell.x]], y=cell.dat[[cell.y]], color = cell.dat[[cell.colour]]), #as.numeric(as.character(col)) + size = dot.size, #dot.size + alpha = dot.alpha # shape = 1 + ) + + + scale_color_gradientn(colours = colour.scheme(50), + limits = (c(ColrMin,ColrMax)), + oob=squish, + name = cell.colour) + } + + if(cell.colour.type != "numeric"){ + p <- p + geom_point(data=cell.dat, + aes(x=cell.dat[[cell.x]], y=cell.dat[[cell.y]], color = as.factor(cell.dat[[cell.colour]])), #as.numeric(as.character(col)) + size = dot.size, #dot.size + alpha = dot.alpha # shape = 1 + ) + + + scale_colour_discrete(name = cell.colour) + } + + } + + ## Setup some themes + p <- p + theme_bw() + + coord_equal() + + xlab(cell.x)+ + ylab(cell.y)+ + ggtitle(title) + + ## More themes + p <- p + theme(panel.background = element_rect(fill = "white", colour = "black", size = 0.5), # change 'colour' to black for informative axis + axis.title.x=element_text(color="Black", face="bold", size=18), + axis.title.y=element_text(color="Black", face="bold", size=18), + legend.text=element_text(size=12), # large = 30 # small = 8 + legend.key.height=unit(1,"cm"), # large = 3 # small = 1.2 + legend.key.width=unit(0.4,"cm"), # large = 1 # small = 0.4 + #legend.title=element_blank(), + plot.title = element_text(color="Black", face="bold", size=16, hjust=0) # size 70 for large, # 18 for small + ) + + if(flip.y.axis == TRUE){ + + p <- p + scale_y_reverse() + + } + + ### Save ggplot to disk if desired + if(save.to.disk == TRUE){ + ggsave(filename = paste0(title, "_ROI_", roi.marker, "_marker_", cell.colour,".png"), + plot = p, + path = path, + width = plot.width, + height = plot.height, + limitsize = FALSE) + } + + print(p) + +} + + + + + diff --git a/R/read.spatial.files.R b/R/read.spatial.files.R new file mode 100644 index 00000000..5e5d53c8 --- /dev/null +++ b/R/read.spatial.files.R @@ -0,0 +1,157 @@ +#' Read TIFF files into R and and create spatial data object +#' +#' @usage read.spatial.files() +#' +#' @param rois vector of ROI names (directory names) +#' @param roi.loc working directory for ROIs +#' @param multi.tiff Default FALSE. Currently we don't support reading in multipage TIFF files +#' @param correct.extent Correct extent so that the minimum is 0,0. Default TRUE +#' @param flip.y Flip the data arrangement for the y-axis. Default TRUE +#' @param value.modifier Data modifier based on image processing. Default 65535 +#' @param ext Default = ".tif" (which will recognise '.tiff' files as well) +#' +#' @return Returns a spatial data object. +#' +#' @examples +#' +#' @import data.table +#' +#' @export + +read.spatial.files <- function(rois, + roi.loc = getwd(), + multi.tiff = FALSE, + correct.extent = TRUE, + flip.y = TRUE, + value.modifier = 65535, + ext = ".tif"){ + + ### Packages + + require('raster') + + ### Checks + + if(multi.tiff == TRUE){ + if(length(grep(".tif", rois)) != length(rois)){ + stop("It appears that your list of ROIs are not TIFF stack files, and might be directories full of single TIFFs (i.e. one TIFF per channel. If this is correct, please use 'multi.tiff = FALSE'") + } + } + + ### Setup + + # message("This is a developmental Spectre-spatial function that is still in testing phase with limited documentation. We recommend only using this function if you know what you are doing.") + ROI.list <- list() + spatial.dat <- list() + setwd(roi.loc) + + ### Loop for ROIs -- one TIFF per ROI (i.e. tiff stack) + + if(multi.tiff == TRUE){ + message("Multi.tiff is not currently supported") + # + # setwd(roi.loc) + # ROI.list <- list() + # + # for(i in rois){ + # # i <- rois[[1]] + # message(paste0("Reading TIFF file for ", i)) + # + # temp <- readTIFF(i, all = TRUE) + # str(temp) + # + # temp <- raster(temp[[1]]) + # + # raster.stack <- stack(active.roi) + # + # + # + # + # + # raster.stack <- stack(active.roi) + # ROI.list[[i]]$rasters <- raster.stack + # } + } + + ### Loop for ROIs -- one FOLDER per ROI + + if(multi.tiff == FALSE){ + for(i in rois){ + # i <- rois[[1]] + message(paste0("Reading TIFF files for ", i)) + + setwd(roi.loc) + setwd(i) + tiffs <- list.files(pattern = ext) + + ## TIFF loop + active.roi <- list() + + for(a in tiffs){ + # a <- tiffs[[7]] + + active.roi[[a]] <- readTIFF(a) + + if('matrix' %in% class(active.roi[[a]])){ + + message(" -- ", a, " - single band in TIFF") + active.roi[[a]] <- raster(active.roi[[a]]) + + } + + + if(class(active.roi[[a]]) != 'matrix'){ + if('array' %in% class(active.roi[[a]])){ + + message(" -- ", a, " - merging multiple bands in TIFF ") + + active.roi[[a]] <- raster(a) + + nbands <- active.roi[[a]]@file@nbands + # nbands + + band.list <- list() + + for(u in c(1:nbands)){ + band.list[[u]] <- values(raster(a, band = u)) + } + + band.res <- band.list[[1]] + + for(u in c(2:nbands)){ + band.res <- band.res + band.list[[u]] + } + + values(active.roi[[a]]) <- band.res + + } + } + + if(correct.extent == TRUE){ + message(" ...correcting extent") + extent(active.roi[[a]]) <- c(0, dim(active.roi[[a]])[2], 0,dim(active.roi[[a]])[1]) # Y axis - X axis + } + + if(flip.y == TRUE){ + message(" ...flipping y-axis orientation") + active.roi[[a]] <- flip(active.roi[[a]], 'y') + } + + raster::values(active.roi[[a]]) <- raster::values(active.roi[[a]]) * value.modifier + + for(n in c(1:length(names(active.roi)))){ + names(active.roi)[n] <- gsub(ext, "", names(active.roi)[n]) + } + } + + raster.stack <- stack(active.roi) + ROI.list[[i]]$RASTERS <- raster.stack + } + } + + + ### Return + message("Spatial data object construction complete") + return(ROI.list) + +} diff --git a/R/run.spatial.analysis.R b/R/run.spatial.analysis.R new file mode 100644 index 00000000..6b23d3ca --- /dev/null +++ b/R/run.spatial.analysis.R @@ -0,0 +1,369 @@ +#' run.spatial.analysis +#' +#' @param dat NO DEFAULT. Data.table +#' @param sample.col NO DEFAULT. Column that denotes 'samples' +#' @param pop.col NO DEFAULT. Column that denotes 'samples' +#' @param annot.cols DEFAULT = NULL. Annotation columns. +#' @param region.col DEFAULT = NULL. Create a 'total' by default, and add specific ones if requested here +#' @param area.table DEFAULT = NULL. Calculate 'total' automatically +#' @param adj.dist DEFAULT = 20 +#' @param x.col DEFAULT = 'x' +#' @param y.col DEFAULT = 'y' +#' @param distribution DEFAULT = TRUE +#' @param composition DEFAULT = TRUE +#' @param counts DEFAULT = TRUE +#' @param counts.per.area DEFAULT = TRUE +#' @param distance DEFAULT = TRUE +#' @param adjacency DEFAULT = TRUE +#' @param func DEFAULT = 'mean' +#' +#' @import data.table +#' +#' @export + +# run.spatial.analysis + +run.spatial.analysis <- function(dat, + sample.col, + pop.col, + + annot.cols = NULL, + region.col = NULL, # Create a 'total' by default, and add specific ones if requested here + area.table = NULL, # calculate 'total' automatically + + adj.dist = 20, + + x.col = 'x', + y.col = 'y', + + distribution = TRUE, + composition = TRUE, + counts = TRUE, + counts.per.area = TRUE, + distance = TRUE, + adjacency = TRUE, + + func = 'mean'){ + + ### Test data + + # dat <- cell.dat + # sample.col <- "ROI" + # pop.col <- "Annotated metacluster" + # region.col <- "Annotated region" + # + # area.table <- area.table + # adj.dist = 20 + # + # annot.cols = 'Group' + # + # distribution = TRUE + # composition = TRUE + # counts = TRUE + # counts.per.area = TRUE + # distance = TRUE + # adjacency = TRUE + # + # x.col = 'x' + # y.col = 'y' + # + # func = 'mean' + + ### Function for NAs + + # ###################### NA to 0 ################### + do.rmv.na = function(dat) { + # either of the following for loops + + # by name : + for (j in names(dat)) + set(dat,which(is.na(dat[[j]])),j,0) + + # or by number (slightly faster than by name) : + # for (j in seq_len(ncol(dat))) + # set(dat,which(is.na(dat[[j]])),j,0) + } + # ################################################ + + ### Setup + + pops <- unique(dat[[pop.col]]) + samples <- unique(dat[[sample.col]]) + regions <- unique(dat[[region.col]]) + + setorderv(dat, sample.col) + setorderv(dat, pop.col) + + ### Loop PER SAMPLE + + all.counts <- list() + + for(i in samples){ + # i <- samples[[1]] + + message('Processing ', i) + + ### Setup + + ## Subset sample data + samp.dat <- dat[dat[[sample.col]] == i,] + + ## Sample front matter + samp.front <- samp.dat[1,c(sample.col, annot.cols), with = FALSE] + + ## Preparation + samp.counts <- as.data.table(regions) + names(samp.counts)[1] <- "REGION" + + ## Loop for each population across regions + + reg.res <- as.data.table(pops) + names(reg.res)[1] <- "POPULATIONS" + + for(a in regions){ + # a <- regions[[1]] + + reg.dat <- samp.dat[samp.dat[[region.col]] == a,] + counts <- reg.dat[, .(count = .N), by = pop.col] + names(counts)[1] <- "POPULATIONS" + names(counts)[2] <- a + + reg.res <- do.add.cols(reg.res, "POPULATIONS", counts, "POPULATIONS", show.status = FALSE) + do.rmv.na(reg.res) + } + + ### DISTRIBUTION -- Type A -- for each cell type, where is it located (row proportions) + + if(distribution == TRUE){ + + message(' -- Calculating distribution') + + a.res <- data.table() + + for(o in c(1:nrow(reg.res))){ + # o <- 1 + nme <- reg.res[o,1] + + rw.ttl <- sum(reg.res[o,-1]) + res <- reg.res[o,-1]/rw.ttl + res <- res*100 + + a.res <- rbind(a.res, cbind(nme, res)) + + rm(o) + rm(nme) + rm(rw.ttl) + rm(res) + } + + do.rmv.na(a.res) + a.res.long <- melt(setDT(a.res), id.vars = c("POPULATIONS"), variable.name = "REGION") + a.res.long + + a.res.long.new <- data.table() + a.res.long.new$measure <- paste0("Percent of cell type in region -- ", "Distribution of ", a.res.long$POPULATIONS, " in ", a.res.long$REGION) + + a.res.long.new$counts <- a.res.long$value + + a.res.long.new <- dcast(melt(a.res.long.new, id.vars = "measure"), variable ~ measure) + + a.res.long.new$variable <- NULL + + # a.res.long.new$variable <- i + # names(a.res.long.new)[1] <- sample.col + + } + + + ### COMPOSITION -- Type B -- for each region, what cells are in it (column proportions) + + if(composition == TRUE){ + + message(' -- Calculating composition') + + b.res <- as.data.table(reg.res[,1]) + + for(o in c(2:length(names(reg.res)))){ + # o <- 2 + nme <- names(reg.res)[o] + + col.ttl <- sum(reg.res[,..o]) + res <- reg.res[,..o]/col.ttl + res <- res*100 + + b.res <- cbind(b.res, res) + + rm(o) + rm(nme) + rm(col.ttl) + rm(res) + } + + do.rmv.na(b.res) + b.res.long <- melt(setDT(b.res), id.vars = c("POPULATIONS"), variable.name = "REGION") + b.res.long + + b.res.long.new <- data.table() + b.res.long.new$measure <- paste0("Percent of total cells in region -- ", "Composition of ", b.res.long$REGION, " - ", b.res.long$POPULATIONS) + b.res.long.new$counts <- b.res.long$value + b.res.long.new + + b.res.long.new <- dcast(melt(b.res.long.new, id.vars = "measure"), variable ~ measure) + + b.res.long.new$variable <- NULL + + #b.res.long.new$variable <- i + #names(b.res.long.new)[1] <- sample.col + } + + ### COUNTS + + message(' -- Calculating cell counts') + + reg.res.long <- melt(setDT(reg.res), id.vars = c("POPULATIONS"), variable.name = "REGION") + reg.res.long + + reg.res.long.new <- data.table() + reg.res.long.new$measure <- paste0("Cells per region -- ", "Cell counts in ", reg.res.long$REGION, " - ", reg.res.long$POPULATIONS) + reg.res.long.new$counts <- reg.res.long$value + + reg.res.long.new <- dcast(melt(reg.res.long.new, id.vars = "measure"), variable ~ measure) + reg.res.long.new$variable <- NULL + + # reg.res.long.new$variable <- i + # names(reg.res.long.new)[1] <- sample.col + + ### COUNTS / AREA + + message(' -- Calculating counts/area') + + reg.res.by.area <- reg.res + + for(u in regions){ + # u <- regions[[1]] + + ar <- area.table[area.table[[sample.col]] == i, u, with = FALSE] + ar <- ar[[1]] + ar <- as.numeric(ar) + + reg.res.by.area[[u]] <- reg.res.by.area[[u]] / ar * 10000 # per 100 um^2 + } + + reg.res.area.long <- melt(setDT(reg.res.by.area), id.vars = c("POPULATIONS"), variable.name = "REGION") + reg.res.area.long + + reg.res.area.long.new <- data.table() + reg.res.area.long.new$measure <- paste0("Cells per 100 sqr. pixels of ", reg.res.area.long$REGION, " -- ", reg.res.area.long$POPULATIONS) + reg.res.area.long.new$counts <- reg.res.area.long$value + + reg.res.area.long.new <- dcast(melt(reg.res.area.long.new, id.vars = "measure"), variable ~ measure) + reg.res.area.long.new$variable <- NULL + + ### DISTANCE and ADJACENCY + + message(' -- Calculating distance and adjacency') + + dist.res.list <- data.table() + adj.res.list <- data.table() + + for(u in regions){ + # u <- regions[[1]] + + message(" ", paste0('Region: ', u)) + + reg.temp <- do.filter(samp.dat, region.col, u) + reg.pops <- unique(reg.temp[[pop.col]]) + + combs <- gtools::permutations(n = length(reg.pops), r = 2, v = reg.pops, repeats.allowed = TRUE) + combs # x, y + + comb.dist.list <- list() + comb.adj.list <- list() + + for(a in c(1:nrow(combs))){ + # a <- 1 + # a <- 7 + + ## Start + + cell.a <- combs[a,1] + cell.b <- combs[a,2] + + nme <- paste0(cell.a, " to ", cell.b) + message(" ---- ", paste0(cell.a, " to ", cell.b)) + + ## Setup + + pop.temp <- do.filter(reg.temp, pop.col, c(cell.a, cell.b)) + cell.types <- pop.temp[[pop.col]] + + pop.temp <- pop.temp[,c(x.col, y.col),with = FALSE] + + A <- pop.temp[which(cell.types == cell.a),] + B <- pop.temp[which(cell.types == cell.b),] + + ## Calculate distance and adjacency + + res <- proxy::dist(as.data.frame(A), as.data.frame(B)) # https://stackoverflow.com/questions/48117286/distance-between-two-sets-of-points + + # Same cell types + if(cell.a == cell.b){ + # res <- res[lower.tri(res, diag = FALSE)] + diag(res) <- NA + } + + comb.dist.list[[nme]] <- sum(rowMeans(res, na.rm = TRUE), na.rm = TRUE) / nrow(res) # Average of all rows -- distance # Same result as mean(res) + comb.adj.list[[nme]] <- sum(res < adj.dist, na.rm = TRUE) / nrow(res) # Average for all rows -- number of neighbours + + } + + comb.dist <- as.data.table(comb.dist.list) + comb.adj <- as.data.table(comb.adj.list) + + names(comb.dist) <- paste0('Av. Distance', ' within ', u, ' -- ', names(comb.dist)) + names(comb.adj) <- paste0('Av. Neighbours under ', adj.dist, 'pixles in ', u, ' -- ', names(comb.adj)) + + as.matrix(names(comb.dist)) + as.matrix(names(comb.adj)) + + # names(comb.dist) <- paste0(names(comb.dist), " in ", u) + # comb.adj + + dist.res.list <- cbind(dist.res.list, comb.dist) + adj.res.list <- cbind(adj.res.list, comb.adj) + + } + + + ### WRAP UP for sample + + sample.all <- cbind(samp.front, + reg.res.long.new, + reg.res.area.long.new, + a.res.long.new, + b.res.long.new, + dist.res.list, + adj.res.list) + + all.counts[[i]] <- sample.all + + # all.counts <- rbind(all.counts, cbind(reg.res.long.new, + # reg.res.area.long.new, + # a.res.long.new, + # b.res.long.new)) + + rm(reg.res.long.new) + rm(reg.res.area.long.new) + rm(a.res.long.new) + rm(b.res.long.new) + rm(comb.dist) + rm(comb.adj) + rm(sample.all) + } + + ### Wrap up + + final <- rbindlist(all.counts, fill = TRUE) + return(final) + +} diff --git a/R/write.hdf5.R b/R/write.hdf5.R new file mode 100644 index 00000000..2a18a9a2 --- /dev/null +++ b/R/write.hdf5.R @@ -0,0 +1,372 @@ +#' write.hdf5 +#' +#' @param dat NO DEFAULT. Spatial data list +#' @param channels DEFAULT = NULL. Channels to include. If NULL, all channels included. +#' @param merge.channels DEFAULT = NULL. Channels to use to create an additional 'merged' channel. +#' @param q.max DEFAULT = 0.99 +#' @param flip.y DEFAULT = TRUE +#' @param random.crop.x DEFAULT = NULL +#' @param random.crop.y DEFAULT = NULL +#' @param random.crop.x.seed DEFAULT = 42 +#' @param random.crop.y.seed DEFAULT = 21 +#' @param print.spatial.plot DEFAULT = TRUE +#' @param chunk.size DEFAULT = NULL +#' @param compression DEFAULT = 0 +#' @param plots DEFAULT = FALSE +#' +#' @author +#' Thomas M Ashhurst, \email{thomas.ashhurst@@sydney.edu.au} +#' +#' @references \url{https://github.com/ImmuneDynamics/Spectre}. +#' +#' @import data.table +#' +#' @export + +# run.spatial.analysis + +write.hdf5 <- function(dat, # SpectreMAP object + channels = NULL, + merge.channels = NULL, + q.max = 0.99, + flip.y = TRUE, + random.crop.x = NULL, + random.crop.y = NULL, + random.crop.x.seed = 42, + random.crop.y.seed = 21, + print.spatial.plot = TRUE, + chunk.size = NULL, + compression = 0, + plots = FALSE + ){ + + ### Packages + + require('Spectre') + require('data.table') + require('raster') + require('rhdf5') + require('HDF5Array') + + ### Testing + + # dat <- spatial.dat + # channels = names(spatial.dat[[1]]$RASTERS)[c(13:25)] + # q.max = 0.99 + # flip.y = TRUE + # random.crop.x = 300 + # random.crop.y = 300 + # random.crop.x.seed = 42 + # random.crop.y.seed = 21 + # print.spatial.plot = TRUE + # compression = 0 + + ### Setup + + message('Writing HDF5 files to disk...') + message('...') + + ### Loop + + for(i in names(dat)){ + # i <- names(dat)[1] + + gc() + + roi.dat <- list() + roi.dat[[i]]<- dat[[i]] + + message('Starting ', i) + + ## Flip Y + + if(isTRUE(flip.y)){ + message(" -- flipping y-axis") + roi.dat[[i]]$RASTERS <- raster::flip(roi.dat[[i]]$RASTERS, direction='y') + } + + ## Filtering to clip very bright pixels + + message(" -- clipping bright pixels") + + for(a in channels){ + # a <- for.ilastik[1] + + max(roi.dat[[i]]$RASTERS[[a]]@data@values) + + q <- quantile(roi.dat[[i]]$RASTERS[[a]]@data@values, q.max) + + raster::values(roi.dat[[i]]$RASTERS[[a]])[roi.dat[[i]]$RASTERS[[a]]@data@values > q] <- q + + max(roi.dat[[i]]$RASTERS[[a]]@data@values) + + if(max(raster::values(roi.dat[[i]]$RASTERS[[a]])) > q){ + stop('Upper threshold clipping did not work') + } + + if(max(roi.dat[[i]]$RASTERS[[a]]@data@values) > q){ + stop('Upper threshold clipping did not work') + } + } + + ## Cropping + + if(!is.null(random.crop.x)){ + if(!is.null(random.crop.y)){ + + ## Dimensions + + message(" -- setup cropping") + + xmin <- extent(roi.dat[[i]]$RASTERS)[1] + xmax <- extent(roi.dat[[i]]$RASTERS)[2] + ymin <- extent(roi.dat[[i]]$RASTERS)[3] + ymax <- extent(roi.dat[[i]]$RASTERS)[4] + + ## New X + + x.length <- xmax - xmin + x.mid <- xmax - random.crop.x + + if(x.mid < xmin){ + x.mid <- xmin + } + + set.seed(random.crop.x.seed) + new.xmin <- runif(1, xmin, x.mid) + new.xmin <- ceiling(new.xmin) + + new.xmax <- new.xmin + random.crop.x + + if(new.xmax > xmax){ + new.xmax <- xmax + } + + ## New Y + + y.length <- ymax - ymin + y.mid <- ymax - random.crop.y + + if(y.mid < ymin){ + y.mid <- ymin + } + + set.seed(random.crop.y.seed) + new.ymin <- runif(1, ymin, y.mid) + new.ymin <- ceiling(new.ymin) + + new.ymax <- new.ymin + random.crop.y + + if(new.ymax > ymax){ + new.ymax <- ymax + } + + ## Crop + + message(" -- calculate new extent") + e <- extent(new.xmin, new.xmax, new.ymin, new.ymax) + + gc() + message(" -- cropping ROI") + roi.dat[[i]]$RASTERS <- crop(roi.dat[[i]]$RASTERS, e) + + ## Clean up + + rm(xmin) + rm(xmax) + rm(ymin) + rm(ymax) + rm(e) + + gc() + } + } + + ## Adjust + + message(" -- adjusting data") + + rws <- roi.dat[[i]]$RASTERS@nrows # rows = y-axis + cls <- roi.dat[[i]]$RASTERS@ncols # cols = x-axis + + temp <- raster::values(roi.dat[[i]]$RASTERS) + temp <- as.data.table(temp) + temp <- temp[,..channels] + + if(!is.null(merge.channels)){ + + # sapply(temp[,..merge.channels], max, na.rm = TRUE) + # colSums(temp[,..merge.channels]) + # rw.tbl <- temp[,..merge.channels] + + rw.tbl <- do.rescale(temp, merge.channels, new.min = 0, new.max = 10) + + # rw.tbl <- do.rescale(temp, merge.channels, new.min = 0, new.max = max(temp[,..merge.channels])) + rw.tbl <- rw.tbl[,names(rw.tbl)[grepl('_rescaled', names(rw.tbl))], with = FALSE] + + for(u in names(rw.tbl)){ + # u <- names(rw.tbl)[[5]] + + # rw.tbl[[u]][rw.tbl[[u]] > quantile(rw.tbl[[u]], 0.95)] <- quantile(rw.tbl[[u]], 0.95) + over.one <- rw.tbl[[u]][rw.tbl[[u]] > 0] + rw.tbl[[u]][rw.tbl[[u]] <= quantile(over.one, 0.05)] <- 0 + } + + # sapply(rw.tbl, max, na.rm = TRUE) + # rw.sms <- rowMeans(rw.tbl) + + rw.sms <- rowSums(rw.tbl) + # rw.sms[rw.sms > length(merge.channels)] <- length(merge.channels) + # rw.sms[rw.sms > quantile(rw.sms, 0.95)] <- quantile(rw.sms, 0.95) + + + + # rw.tbl <- temp[,..merge.channels] + # rw.tbl <- do.zscore(rw.tbl, merge.channels, replace = TRUE) + # + # for(u in names(rw.tbl)){ + # # u <- names(rw.tbl)[[5]] + # rw.tbl[[u]][rw.tbl[[u]] > quantile(rw.tbl[[u]], 0.95)] <- quantile(rw.tbl[[u]], 0.95) + # rw.tbl[[u]][rw.tbl[[u]] <= quantile(rw.tbl[[u]], 0.05)] <- quantile(rw.tbl[[u]], 0.05) + # } + + # rw.sms <- rowSums(rw.tbl) + rw.sms[rw.sms > quantile(rw.sms, 0.95)] <- quantile(rw.sms, 0.95) + rw.sms[rw.sms <= quantile(rw.sms, 0.05)] <- 0 + + temp$Merged <- rw.sms + temp <- temp[,c('Merged', channels), with = FALSE] + } + + lgth <- length(names(temp)) + temp <- as.vector(as.matrix(temp)) + + ## Array + + message(" -- creating array") + + AR <- array(data = temp, dim = c(cls, rws, lgth, 1)) + AR <- aperm(AR, c(3,1,2,4)) + + rm(temp) + gc() + + dim(AR)[1] # layers (channels) + dim(AR)[2] # rows (y-axis) + dim(AR)[3] # columns (x-axis) + dim(AR)[4] # 1 (z-axis, required for easy reading by Ilastik) + + ## Write HDF5 + + # h5closeAll() + + message(" -- writing HDF5 file") + + if(!is.null(random.crop.x)){ + if(!is.null(random.crop.y)){ + + if(!paste0(i, "_crop.h5") %in% list.files(getwd())){ + file.remove(paste0(i, "_crop.h5")) + } + + h5createFile(paste0(i, "_crop.h5")) + h5createDataset(paste0(i, "_crop.h5"), + "stacked_channels", + dim(AR), + storage.mode = "integer", + chunk = c(1, dim(AR)[2],dim(AR)[3], 1), + level = compression + ) + h5write(AR, file=paste0(i, "_crop.h5"), + name="stacked_channels") + h5ls(paste0(i, "_crop.h5")) + + + } + + } else { + + if(!paste0(i, ".h5") %in% list.files(getwd())){ + file.remove(paste0(i, ".h5")) + } + + h5createFile(paste0(i, ".h5")) + h5createDataset(paste0(i, ".h5"), + "stacked_channels", + dim(AR), + maxdims = dim(AR), + storage.mode = "integer", + chunk = c(1, dim(AR)[2],dim(AR)[3], 1), + level = compression + ) + h5write(AR, file=paste0(i, ".h5"), + name="stacked_channels") + h5ls(paste0(i, ".h5")) + } + + + ## Plots + + if(isTRUE(plots)){ + + message(" -- creating plots") + + if(!is.null(random.crop.x)){ + if(!is.null(random.crop.y)){ + + dir.create('HDF5 cropped plots') + dir.create(paste0('HDF5 cropped plots/', i)) + + for(a in channels){ + make.spatial.plot(roi.dat, + image.roi = i, + image.channel = a, + image.min.threshold = 0, + image.max.threshold = 1, + image.y.flip = FALSE, + path = paste0('HDF5 cropped plots/', i) + ) + } + } + + } else { + + dir.create('HDF5 plots') + dir.create(paste0('HDF5 plots/', i)) + + for(a in channels){ + make.spatial.plot(roi.dat, + image.roi = i, + image.channel = a, + image.min.threshold = 0, + image.max.threshold = 1, + image.y.flip = FALSE, + path = paste0('HDF5 plots/', i) + ) + } + } + + } + + + ## Message + if(!is.null(random.crop.x)){ + if(!is.null(random.crop.y)){ + + message(' -- cropped HDF5 file for ', i, ' complete') + message(' ') + + } + } else { + message(' -- HDF5 file for ', i, ' complete') + message(' ') + } + + rm(roi.dat) + rm(AR) + gc() + } + + gc() + +} diff --git a/README.md b/README.md index 0c6759c8..84c7d405 100755 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ # Spectre -A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry data. +A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry and imaging data. ### Current version -`v0.4.5` +`v0.5.0` ### About -Spectre is an R package that enables comprehensive end-to-end integration and analysis of high-dimensional cytometry data from different batches or experiments. Spectre streamlines the analytical stages of raw data pre-processing, batch alignment, data integration, clustering, dimensionality reduction, visualisation and population labelling, as well as quantitative and statistical analysis. To manage large cytometry datasets, Spectre was built on the data.table framework – this simple table-like structure allows for fast and easy processing of large datasets in R. Critically, the design of Spectre allows for a simple, clear, and modular design of analysis workflows, that can be utilised by data and laboratory scientists. Recently we have extended the functionality of Spectre to support the analysis of Imaging Mass Cytometry (IMC) and scRNAseq data. For more information, please see our pre-print: [Integration, exploration, and analysis of high-dimensional single-cell cytometry data using Spectre. (2020). TM Ashhurst\*, F Marsh-Wakefield\*, GH Putri\*, AG Spiteri, D Shinko, ... bioRxiv](https://www.biorxiv.org/content/10.1101/2020.10.22.349563v1.abstract). +Spectre is an R package that enables comprehensive end-to-end integration and analysis of high-dimensional cytometry data from different batches or experiments. Spectre streamlines the analytical stages of raw data pre-processing, batch alignment, data integration, clustering, dimensionality reduction, visualisation and population labelling, as well as quantitative and statistical analysis. To manage large cytometry datasets, Spectre was built on the data.table framework – this simple table-like structure allows for fast and easy processing of large datasets in R. Critically, the design of Spectre allows for a simple, clear, and modular design of analysis workflows, that can be utilised by data and laboratory scientists. Recently we have extended the functionality of Spectre to support the analysis of Imaging Mass Cytometry (IMC) and scRNAseq data. For more information, please see our paper: [Ashhurst TM, Marsh-Wakefield F, Putri GH et al. (2021). Cytometry A. DOI: 10.1002/cyto.a.24350](https://doi.org/10.1002/cyto.a.24350). -Spectre was developed by [Thomas Ashhurst](https://tomashhurst.github.io/), [Felix Marsh-Wakefield](https://scholar.google.com/citations?user=6PaVkisAAAAJ&hl=en), and [Givanna Putri](https://scholar.google.com/citations?user=S-sNLPIAAAAJ&hl=en). +Spectre was developed by [Thomas Ashhurst](https://immunedynamics.github.io/thomas-ashhurst/), [Felix Marsh-Wakefield](https://immunedynamics.github.io/felix-marsh-wakefield/), and [Givanna Putri](https://immunedynamics.github.io/givanna-putri/). -### Protocols and vignettes +### Instructions and protocols Usage instructions and protocols are available from [https://immunedynamics.github.io/spectre](https://immunedynamics.github.io/spectre). ### Citation -If you use Spectre in your work, please consider citing [Ashhurst TM, Marsh-Wakefield F, Putri GH et al. (2020). bioRxiv. 2020.10.22.349563](https://www.biorxiv.org/content/10.1101/2020.10.22.349563v1.abstract). To continue providing open-source tools such as Spectre, it helps us if we can demonstrate that our efforts are contributing to analysis efforts in the community. Please also consider citing the authors of the individual packages or tools (e.g. CytoNorm, FlowSOM, tSNE, UMAP, etc) that are critical elements of your analysis work. +If you use Spectre in your work, please consider citing [Ashhurst TM, Marsh-Wakefield F, Putri GH et al. (2021). Cytometry A. DOI: 10.1002/cyto.a.24350](https://doi.org/10.1002/cyto.a.24350). To continue providing open-source tools such as Spectre, it helps us if we can demonstrate that our efforts are contributing to analysis efforts in the community. Please also consider citing the authors of the individual packages or tools (e.g. CytoNorm, FlowSOM, tSNE, UMAP, etc) that are critical elements of your analysis work. ### Installing Spectre Detailed installation instructions are available from [https://immunedynamics.github.io/spectre](https://immunedynamics.github.io/spectre). Briefly, install and load the 'devtools' library. @@ -51,18 +51,11 @@ If the package is sucessfully installed, you can load the library using: library("Spectre") ``` -Subsequently, there are a few packages from Bioconductor that you should install, which won't be installed by default when you install Spectre. +Subsequently, there are a few packages from Bioconductor that you should install, which won't be installed by default when you install Spectre. You can install these using the `package.install()` function. ``` -## Install BiocManager to download packages from Bioconductor -if (!requireNamespace("BiocManager", quietly = TRUE)) - install.packages("BiocManager") - ## Download additional BioConductor packages -if(!require('flowCore')) {BiocManager::install('flowCore')} -if(!require('Biobase')) {BiocManager::install('Biobase')} -if(!require('flowViz')) {BiocManager::install('flowViz')} -if(!require('FlowSOM')) {BiocManager::install('FlowSOM')} +Spectre::package.install() ``` You can then check for whether all of the packages for Spectre have been loaded correctly using the following commands diff --git a/data/demo.spatial.RData b/data/demo.spatial.RData new file mode 100755 index 00000000..4f83fbd8 Binary files /dev/null and b/data/demo.spatial.RData differ diff --git a/man/create.stats.Rd b/man/create.stats.Rd index e3f58c1d..8419b6fb 100755 --- a/man/create.stats.Rd +++ b/man/create.stats.Rd @@ -35,3 +35,9 @@ create.stats( \description{ This function performs statistical analysis and generates an output data.table } +\references{ +\url{https://github.com/ImmuneDynamics/Spectre}. +} +\author{ +Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} +} diff --git a/man/create.sumtable.Rd b/man/create.sumtable.Rd index ae28d14a..859659c2 100755 --- a/man/create.sumtable.Rd +++ b/man/create.sumtable.Rd @@ -43,7 +43,7 @@ sum.dat <- create.sumtable(dat = dat, } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/demo.asinh.Rd b/man/demo.asinh.Rd index 252b55e6..30b0cc78 100755 --- a/man/demo.asinh.Rd +++ b/man/demo.asinh.Rd @@ -21,7 +21,7 @@ demo.asinh } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/demo.batches.1.Rd b/man/demo.batches.1.Rd index c05834ff..8d4c8ccf 100755 --- a/man/demo.batches.1.Rd +++ b/man/demo.batches.1.Rd @@ -21,7 +21,7 @@ demo.batches.1 } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/demo.clustered.Rd b/man/demo.clustered.Rd index 0afeed46..460c5b55 100755 --- a/man/demo.clustered.Rd +++ b/man/demo.clustered.Rd @@ -21,7 +21,7 @@ demo.clustered } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/demo.exp.Rd b/man/demo.exp.Rd index 54d62ca4..35c472cc 100755 --- a/man/demo.exp.Rd +++ b/man/demo.exp.Rd @@ -21,7 +21,7 @@ demo.exp } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/demo.spatial.Rd b/man/demo.spatial.Rd new file mode 100644 index 00000000..c5f21da3 --- /dev/null +++ b/man/demo.spatial.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/demo.spatial.R +\docType{data} +\name{demo.spatial} +\alias{demo.spatial} +\title{demo.spatial - Demo spatial dataset consisting of 6x regions of interest, acquired using Imaging Mass Cytometry (IMC)} +\format{ +An R object (list) containing 6x ROIs, each consisting of raster stacks, masks, and extracted cellular data in a data.table +} +\source{ +Thomas M Ashhurst. +} +\usage{ +demo.spatial +} +\description{ +demo.spatial - Demo spatial dataset consisting of 6x regions of interest, acquired using Imaging Mass Cytometry (IMC) +} +\examples{ +demo.spatial + +} +\references{ +\url{https://github.com/ImmuneDynamics/Spectre}. +} +\author{ +Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} +} +\keyword{datasets} diff --git a/man/demo.start.Rd b/man/demo.start.Rd index 48d70437..309fa64e 100755 --- a/man/demo.start.Rd +++ b/man/demo.start.Rd @@ -21,7 +21,7 @@ demo.start } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/demo.sum.Rd b/man/demo.sum.Rd index f6f6e130..6b4ba696 100755 --- a/man/demo.sum.Rd +++ b/man/demo.sum.Rd @@ -21,7 +21,7 @@ demo.sum } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/do.add.cols.Rd b/man/do.add.cols.Rd index cc87e66e..62e0b6a2 100755 --- a/man/do.add.cols.Rd +++ b/man/do.add.cols.Rd @@ -36,7 +36,7 @@ cell.dat <- do.add.cols(dat = Spectre::demo.asinh, } \references{ -\url{https://sydneycytometry.org.au/spectre}. +\url{https://github.com/ImmuneDynamics/Spectre}. } \author{ Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} diff --git a/man/do.add.masks.Rd b/man/do.add.masks.Rd new file mode 100644 index 00000000..f4110490 --- /dev/null +++ b/man/do.add.masks.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.add.masks.R +\name{do.add.masks} +\alias{do.add.masks} +\title{do.add.masks} +\usage{ +do.add.masks( + spatial.dat, + mask.loc, + masks, + mask.label = "cell.mask", + mask.ext = "_mask.tif", + correct.extent = TRUE, + flip.y = TRUE, + value.modifier = 65535, + array = FALSE +) +} +\arguments{ +\item{spatial.dat}{NO DEFAULT. Spatial data list.} + +\item{mask.loc}{NO DEFAULT. Directory of mask files.} + +\item{masks}{NO DEFAULT. Vector of mask file names} + +\item{mask.label}{DEFAULT = "cell_mask"} + +\item{mask.ext}{DEFAULT = "_mask.tif" (will also recognise the '.tiff' file type)} + +\item{correct.extent}{DEFAULT = TRUE} + +\item{flip.y}{DEFAULT = TRUE} + +\item{value.modifier}{DEFAULT = 65535} + +\item{array}{DEFAULT = FALSE} +} +\description{ +do.add.masks +} +\references{ +\url{https://github.com/ImmuneDynamics/Spectre}. +} +\author{ +Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} +} diff --git a/man/do.add.percell.Rd b/man/do.add.percell.Rd new file mode 100644 index 00000000..89f07c84 --- /dev/null +++ b/man/do.add.percell.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.add.percell.R +\name{do.add.percell} +\alias{do.add.percell} +\title{do.add.percell} +\usage{ +do.add.percell(spatial.dat, percell.dat, roi.col, name = "per.cell") +} +\description{ +do.add.percell +} +\references{ +\url{https://github.com/ImmuneDynamics/Spectre}. +} +\author{ +Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} +} diff --git a/man/do.aggregate.Rd b/man/do.aggregate.Rd index 4aad928f..f63a6fe3 100644 --- a/man/do.aggregate.Rd +++ b/man/do.aggregate.Rd @@ -34,5 +34,10 @@ Spectre::make.pheatmap(dat = exp, plot.title = "Pheatmap", sample.col = "Population", plot.cols = names(exp)[c(2:10)]) - +} +\references{ +\url{https://github.com/ImmuneDynamics/Spectre}. +} +\author{ +Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} } diff --git a/man/do.calculate.area.Rd b/man/do.calculate.area.Rd new file mode 100644 index 00000000..89eee351 --- /dev/null +++ b/man/do.calculate.area.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.calculate.area.R +\name{do.calculate.area} +\alias{do.calculate.area} +\title{do.calculate.area} +\usage{ +do.calculate.area(dat, region = NULL) +} +\arguments{ +\item{dat}{NO DEFAULT. Spatial data list} + +\item{region}{DEFAULT = NULL. Name of the region mask, if present.} +} +\description{ +do.calculate.area +} diff --git a/man/do.create.outlines.Rd b/man/do.create.outlines.Rd new file mode 100644 index 00000000..e5e60152 --- /dev/null +++ b/man/do.create.outlines.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.create.outlines.R +\name{do.create.outlines} +\alias{do.create.outlines} +\title{do.create.outlines} +\usage{ +do.create.outlines(spatial.dat, mask.name, method = "stars") +} +\arguments{ +\item{spatial.dat}{NO DEFAULT. Spatial data list} + +\item{mask.name}{NO DEFAULT. Name of the mask to create outlines for} + +\item{method}{DEFAULT = 'stars'. Can be 'stars' or 'raster'} +} +\description{ +do.create.outlines +} diff --git a/man/do.extract.Rd b/man/do.extract.Rd new file mode 100644 index 00000000..533e070b --- /dev/null +++ b/man/do.extract.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.extract.R +\name{do.extract} +\alias{do.extract} +\title{do.extract} +\usage{ +do.extract(dat, mask, name = "CellData", fun = "mean") +} +\arguments{ +\item{dat}{NO DEFAULT. Spatial data list} + +\item{mask}{NO DEFAULT. Name of mask to use for cell data extraction} + +\item{name}{DEFAULT = 'CellData'. Name of the extracted cell dataset.} + +\item{fun}{DEFAULT = 'mean'. Summarisation function.} +} +\description{ +do.extract +} diff --git a/man/do.extract.cell.dat.Rd b/man/do.extract.cell.dat.Rd new file mode 100644 index 00000000..49936ac1 --- /dev/null +++ b/man/do.extract.cell.dat.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.extract.cell.dat.R +\name{do.extract.cell.dat} +\alias{do.extract.cell.dat} +\title{do.extract.cell.dat} +\usage{ +do.extract.cell.dat(spatial.dat, target.dat) +} +\description{ +do.extract.cell.dat +} diff --git a/man/do.filter.percell.Rd b/man/do.filter.percell.Rd new file mode 100644 index 00000000..5141956c --- /dev/null +++ b/man/do.filter.percell.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.filter.percell.R +\name{do.filter.percell} +\alias{do.filter.percell} +\title{do.filter.percell} +\usage{ +do.filter.percell( + spatial.dat, + per.cell, + to, + filter.by, + id.col = "ObjectNumber", + x.col = "Location_Center_X", + y.col = "Location_Center_Y", + simplify.cp.colname = TRUE, + value.modifier = 65535 +) +} +\description{ +do.filter.percell +} diff --git a/man/do.label.from.polygon.Rd b/man/do.label.from.polygon.Rd new file mode 100644 index 00000000..a2eafa14 --- /dev/null +++ b/man/do.label.from.polygon.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.label.from.polygon.R +\name{do.label.from.polygon} +\alias{do.label.from.polygon} +\title{do.label.from.polygon} +\usage{ +do.label.from.polygon( + spatial.dat, + cell.dat, + mask, + labels, + name = "Label", + id.col = "ID", + roi.col = "ROI" +) +} +\description{ +do.label.from.polygon +} diff --git a/man/do.pull.data.Rd b/man/do.pull.data.Rd new file mode 100644 index 00000000..bb9fe14d --- /dev/null +++ b/man/do.pull.data.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/do.pull.data.R +\name{do.pull.data} +\alias{do.pull.data} +\title{do.pull.data} +\usage{ +do.pull.data(spatial.dat, target.dat) +} +\arguments{ +\item{spatial.dat}{NO DEFAULT. Spatial data list.} + +\item{target.dat}{NO DEFAULT. Dataset to pull.} +} +\description{ +do.pull.data +} diff --git a/man/make.spatial.plot.Rd b/man/make.spatial.plot.Rd new file mode 100644 index 00000000..96f97153 --- /dev/null +++ b/man/make.spatial.plot.Rd @@ -0,0 +1,97 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/make.spatial.plot.R +\name{make.spatial.plot} +\alias{make.spatial.plot} +\title{make.spatial.plot} +\usage{ +make.spatial.plot( + spatial.dat, + image.roi, + image.channel, + mask.outlines = NULL, + cell.dat = NULL, + cell.col = NULL, + image.y.flip = TRUE, + image.mask.size = 0.1, + image.mask.colour = "gold", + image.min.threshold = 0, + image.max.threshold = 0.99, + image.blank = FALSE, + cell.x = "x", + cell.y = "y", + cell.col.type = "numeric", + cell.colours = "spectral", + cell.col.min.threshold = 0.01, + cell.col.max.threshold = 0.995, + title = paste0(image.roi), + dot.size = 1, + dot.alpha = 1, + align.xy.by = cell.dat, + align.col.by = cell.dat, + save.to.disk = TRUE, + path = getwd(), + plot.width = 9, + plot.height = 7, + blank.axis = FALSE +) +} +\arguments{ +\item{spatial.dat}{NO DEFAULT.A spatial data list} + +\item{image.roi}{NO DEFAULT.The name of the ROI to plot} + +\item{image.channel}{NO DEFAULT.Name of the channel to plot} + +\item{mask.outlines}{DEFAULT = NULL. Name of the mask for outlines} + +\item{cell.dat}{DEFAULT = NULL. Character name for the cellular dataset in the spatial data list, or a data.table object.} + +\item{cell.col}{DEFAULT = NULL. Name of cellular dataset to colour points by} + +\item{image.y.flip}{DEFAULT = TRUE. Flips the Y-axis orientation.} + +\item{image.mask.size}{DEFAULT = 0.1} + +\item{image.mask.colour}{DEFAULT = "gold"} + +\item{image.min.threshold}{DEFAULT = 0.00. Lower threshold for plot signal. Values below this target will be clipped.} + +\item{image.max.threshold}{DEFAULT = 0.99. Upper threshold for plot signal. Values above this target will be clipped.} + +\item{image.blank}{DEFAULT = FALSE. Will blank the plot image.} + +\item{cell.x}{DEFAULT = "x". Column name for the 'x' coordinate in data.table} + +\item{cell.y}{DEFAULT = "y". Column name for the 'y' coordinate in data.table} + +\item{cell.col.type}{DEFAULT= "numeric". Can be 'factor'.} + +\item{cell.colours}{= DEFAULT = "spectral".} + +\item{cell.col.min.threshold}{= DEFAULT = 0.01. Values below this target will be clipped.} + +\item{cell.col.max.threshold}{= DEFAULT = 0.995. Values above this target will be clipped.} + +\item{title}{DEFAULT = paste0(image.roi)} + +\item{dot.size}{DEFAULT = 1} + +\item{dot.alpha}{DEFAULT = 1} + +\item{align.xy.by}{DEFAULT = cell.dat} + +\item{align.col.by}{DEFAULT = cell.dat} + +\item{save.to.disk}{DEFAULT = TRUE} + +\item{path}{DEFAULT = getwd(). Path for saving image files} + +\item{plot.width}{DEFAULT = 9} + +\item{plot.height}{DEFAULT = 7} + +\item{blank.axis}{DEFAULT = FALSE} +} +\description{ +make.spatial.plot +} diff --git a/man/read.spatial.files.Rd b/man/read.spatial.files.Rd new file mode 100644 index 00000000..7c3162cd --- /dev/null +++ b/man/read.spatial.files.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read.spatial.files.R +\name{read.spatial.files} +\alias{read.spatial.files} +\title{Read TIFF files into R and and create spatial data object} +\usage{ +read.spatial.files() +} +\arguments{ +\item{rois}{vector of ROI names (directory names)} + +\item{roi.loc}{working directory for ROIs} + +\item{multi.tiff}{Default FALSE. Currently we don't support reading in multipage TIFF files} + +\item{correct.extent}{Correct extent so that the minimum is 0,0. Default TRUE} + +\item{flip.y}{Flip the data arrangement for the y-axis. Default TRUE} + +\item{value.modifier}{Data modifier based on image processing. Default 65535} + +\item{ext}{Default = ".tif" (which will recognise '.tiff' files as well)} +} +\value{ +Returns a spatial data object. +} +\description{ +Read TIFF files into R and and create spatial data object +} +\examples{ + +} diff --git a/man/run.spatial.analysis.Rd b/man/run.spatial.analysis.Rd new file mode 100644 index 00000000..897c259a --- /dev/null +++ b/man/run.spatial.analysis.Rd @@ -0,0 +1,61 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/run.spatial.analysis.R +\name{run.spatial.analysis} +\alias{run.spatial.analysis} +\title{run.spatial.analysis} +\usage{ +run.spatial.analysis( + dat, + sample.col, + pop.col, + annot.cols = NULL, + region.col = NULL, + area.table = NULL, + adj.dist = 20, + x.col = "x", + y.col = "y", + distribution = TRUE, + composition = TRUE, + counts = TRUE, + counts.per.area = TRUE, + distance = TRUE, + adjacency = TRUE, + func = "mean" +) +} +\arguments{ +\item{dat}{NO DEFAULT. Data.table} + +\item{sample.col}{NO DEFAULT. Column that denotes 'samples'} + +\item{pop.col}{NO DEFAULT. Column that denotes 'samples'} + +\item{annot.cols}{DEFAULT = NULL. Annotation columns.} + +\item{region.col}{DEFAULT = NULL. Create a 'total' by default, and add specific ones if requested here} + +\item{area.table}{DEFAULT = NULL. Calculate 'total' automatically} + +\item{adj.dist}{DEFAULT = 20} + +\item{x.col}{DEFAULT = 'x'} + +\item{y.col}{DEFAULT = 'y'} + +\item{distribution}{DEFAULT = TRUE} + +\item{composition}{DEFAULT = TRUE} + +\item{counts}{DEFAULT = TRUE} + +\item{counts.per.area}{DEFAULT = TRUE} + +\item{distance}{DEFAULT = TRUE} + +\item{adjacency}{DEFAULT = TRUE} + +\item{func}{DEFAULT = 'mean'} +} +\description{ +run.spatial.analysis +} diff --git a/man/write.hdf5.Rd b/man/write.hdf5.Rd new file mode 100644 index 00000000..0d32bc19 --- /dev/null +++ b/man/write.hdf5.Rd @@ -0,0 +1,58 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/write.hdf5.R +\name{write.hdf5} +\alias{write.hdf5} +\title{write.hdf5} +\usage{ +write.hdf5( + dat, + channels = NULL, + merge.channels = NULL, + q.max = 0.99, + flip.y = TRUE, + random.crop.x = NULL, + random.crop.y = NULL, + random.crop.x.seed = 42, + random.crop.y.seed = 21, + print.spatial.plot = TRUE, + chunk.size = NULL, + compression = 0, + plots = FALSE +) +} +\arguments{ +\item{dat}{NO DEFAULT. Spatial data list} + +\item{channels}{DEFAULT = NULL. Channels to include. If NULL, all channels included.} + +\item{merge.channels}{DEFAULT = NULL. Channels to use to create an additional 'merged' channel.} + +\item{q.max}{DEFAULT = 0.99} + +\item{flip.y}{DEFAULT = TRUE} + +\item{random.crop.x}{DEFAULT = NULL} + +\item{random.crop.y}{DEFAULT = NULL} + +\item{random.crop.x.seed}{DEFAULT = 42} + +\item{random.crop.y.seed}{DEFAULT = 21} + +\item{print.spatial.plot}{DEFAULT = TRUE} + +\item{chunk.size}{DEFAULT = NULL} + +\item{compression}{DEFAULT = 0} + +\item{plots}{DEFAULT = FALSE} +} +\description{ +write.hdf5 +} +\references{ +\url{https://github.com/ImmuneDynamics/Spectre}. +} +\author{ +Thomas M Ashhurst, \email{thomas.ashhurst@sydney.edu.au} +} diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/140Ce_Ce140.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/140Ce_Ce140.tiff new file mode 100644 index 00000000..684840e9 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/140Ce_Ce140.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/80ArAr_ArAr80.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..5a62a1c4 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CD11b_Sm149.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CD11b_Sm149.tiff new file mode 100644 index 00000000..f7a33a91 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CD11b_Sm149.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CD20_Dy161.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CD20_Dy161.tiff new file mode 100644 index 00000000..a2de50f4 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CD20_Dy161.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CD3_Er170.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CD3_Er170.tiff new file mode 100644 index 00000000..202bc952 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CD3_Er170.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CD45_Sm152.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CD45_Sm152.tiff new file mode 100644 index 00000000..507a358f Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CD45_Sm152.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CD4_Gd156.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CD4_Gd156.tiff new file mode 100644 index 00000000..f2e0c4bf Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CD4_Gd156.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CD68_Tb159.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CD68_Tb159.tiff new file mode 100644 index 00000000..6cbd60e6 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CD68_Tb159.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CD8a_Dy162.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CD8a_Dy162.tiff new file mode 100644 index 00000000..bfd3af45 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CD8a_Dy162.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/CollagenI_Tm169.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/CollagenI_Tm169.tiff new file mode 100644 index 00000000..0bcc338b Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/CollagenI_Tm169.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/DNA1_Ir191.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/DNA1_Ir191.tiff new file mode 100644 index 00000000..f8085bd9 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/DNA1_Ir191.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/DNA3_Ir193.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/DNA3_Ir193.tiff new file mode 100644 index 00000000..e9d2af16 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/DNA3_Ir193.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/HistoneH3_Yb176.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..9640523a Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/VIM_Nd143.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/VIM_Nd143.tiff new file mode 100644 index 00000000..6e093dfb Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/VIM_Nd143.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI002/alphaSMA_Pr141.tiff b/segmentation/Ilastik multicut/ROIs/ROI002/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..2d356e42 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI002/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/140Ce_Ce140.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/140Ce_Ce140.tiff new file mode 100644 index 00000000..1d0dbafe Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/140Ce_Ce140.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/80ArAr_ArAr80.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..7a1c3f05 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CD11b_Sm149.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CD11b_Sm149.tiff new file mode 100644 index 00000000..1db62a27 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CD11b_Sm149.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CD20_Dy161.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CD20_Dy161.tiff new file mode 100644 index 00000000..35469bfc Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CD20_Dy161.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CD3_Er170.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CD3_Er170.tiff new file mode 100644 index 00000000..ef13aa36 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CD3_Er170.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CD45_Sm152.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CD45_Sm152.tiff new file mode 100644 index 00000000..2f47cef6 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CD45_Sm152.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CD4_Gd156.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CD4_Gd156.tiff new file mode 100644 index 00000000..6ad14cac Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CD4_Gd156.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CD68_Tb159.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CD68_Tb159.tiff new file mode 100644 index 00000000..f1f1e795 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CD68_Tb159.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CD8a_Dy162.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CD8a_Dy162.tiff new file mode 100644 index 00000000..a8c769d5 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CD8a_Dy162.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/CollagenI_Tm169.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/CollagenI_Tm169.tiff new file mode 100644 index 00000000..fd61881b Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/CollagenI_Tm169.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/DNA1_Ir191.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/DNA1_Ir191.tiff new file mode 100644 index 00000000..859ff093 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/DNA1_Ir191.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/DNA3_Ir193.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/DNA3_Ir193.tiff new file mode 100644 index 00000000..25fa398d Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/DNA3_Ir193.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_CD11b_Sm149_marker_.png b/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_CD11b_Sm149_marker_.png new file mode 100755 index 00000000..934489de Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_CD11b_Sm149_marker_.png differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_CD20_Dy161_marker_.png b/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_CD20_Dy161_marker_.png new file mode 100755 index 00000000..6c469ac4 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_CD20_Dy161_marker_.png differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_alphaSMA_Pr141_marker_.png b/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_alphaSMA_Pr141_marker_.png new file mode 100755 index 00000000..65fe6999 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/HDF5 plots/ROI002/ROI002_ROI_alphaSMA_Pr141_marker_.png differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/HistoneH3_Yb176.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..a652bea8 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/ROI002.h5 b/segmentation/Ilastik multicut/ROIs/ROI004/ROI002.h5 new file mode 100755 index 00000000..a190c07c Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/ROI002.h5 differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/VIM_Nd143.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/VIM_Nd143.tiff new file mode 100644 index 00000000..cc4ca50d Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/VIM_Nd143.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI004/alphaSMA_Pr141.tiff b/segmentation/Ilastik multicut/ROIs/ROI004/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..4c1585d2 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI004/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/140Ce_Ce140.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/140Ce_Ce140.tiff new file mode 100644 index 00000000..9bbaf2ee Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/140Ce_Ce140.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/80ArAr_ArAr80.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..d5a8234e Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CD11b_Sm149.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CD11b_Sm149.tiff new file mode 100644 index 00000000..0206b0ca Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CD11b_Sm149.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CD20_Dy161.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CD20_Dy161.tiff new file mode 100644 index 00000000..05e84982 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CD20_Dy161.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CD3_Er170.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CD3_Er170.tiff new file mode 100644 index 00000000..7d570b90 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CD3_Er170.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CD45_Sm152.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CD45_Sm152.tiff new file mode 100644 index 00000000..3af8521b Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CD45_Sm152.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CD4_Gd156.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CD4_Gd156.tiff new file mode 100644 index 00000000..78aea8b8 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CD4_Gd156.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CD68_Tb159.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CD68_Tb159.tiff new file mode 100644 index 00000000..06ec3bb5 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CD68_Tb159.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CD8a_Dy162.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CD8a_Dy162.tiff new file mode 100644 index 00000000..6befc86c Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CD8a_Dy162.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/CollagenI_Tm169.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/CollagenI_Tm169.tiff new file mode 100644 index 00000000..dd25f6bc Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/CollagenI_Tm169.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/DNA1_Ir191.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/DNA1_Ir191.tiff new file mode 100644 index 00000000..9f5c27e3 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/DNA1_Ir191.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/DNA3_Ir193.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/DNA3_Ir193.tiff new file mode 100644 index 00000000..2b0ea24a Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/DNA3_Ir193.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/HistoneH3_Yb176.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..6efca7b3 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/VIM_Nd143.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/VIM_Nd143.tiff new file mode 100644 index 00000000..b579ae60 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/VIM_Nd143.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI006/alphaSMA_Pr141.tiff b/segmentation/Ilastik multicut/ROIs/ROI006/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..6ea763fd Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI006/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/140Ce_Ce140.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/140Ce_Ce140.tiff new file mode 100644 index 00000000..0b30f306 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/140Ce_Ce140.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/80ArAr_ArAr80.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..020a24e1 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CD11b_Sm149.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CD11b_Sm149.tiff new file mode 100644 index 00000000..0510fb14 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CD11b_Sm149.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CD20_Dy161.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CD20_Dy161.tiff new file mode 100644 index 00000000..1720af2f Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CD20_Dy161.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CD3_Er170.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CD3_Er170.tiff new file mode 100644 index 00000000..b66950fb Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CD3_Er170.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CD45_Sm152.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CD45_Sm152.tiff new file mode 100644 index 00000000..790420c5 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CD45_Sm152.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CD4_Gd156.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CD4_Gd156.tiff new file mode 100644 index 00000000..5e41cf43 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CD4_Gd156.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CD68_Tb159.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CD68_Tb159.tiff new file mode 100644 index 00000000..acff9aec Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CD68_Tb159.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CD8a_Dy162.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CD8a_Dy162.tiff new file mode 100644 index 00000000..cca91724 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CD8a_Dy162.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/CollagenI_Tm169.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/CollagenI_Tm169.tiff new file mode 100644 index 00000000..632e05e1 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/CollagenI_Tm169.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/DNA1_Ir191.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/DNA1_Ir191.tiff new file mode 100644 index 00000000..eac01c08 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/DNA1_Ir191.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/DNA3_Ir193.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/DNA3_Ir193.tiff new file mode 100644 index 00000000..847d98d5 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/DNA3_Ir193.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/HistoneH3_Yb176.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..e91ca165 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/VIM_Nd143.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/VIM_Nd143.tiff new file mode 100644 index 00000000..18567b73 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/VIM_Nd143.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI008/alphaSMA_Pr141.tiff b/segmentation/Ilastik multicut/ROIs/ROI008/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..50531e26 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI008/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/140Ce_Ce140.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/140Ce_Ce140.tiff new file mode 100644 index 00000000..0007e2c5 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/140Ce_Ce140.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/80ArAr_ArAr80.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..3509fb2f Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CD11b_Sm149.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CD11b_Sm149.tiff new file mode 100644 index 00000000..f95aece9 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CD11b_Sm149.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CD20_Dy161.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CD20_Dy161.tiff new file mode 100644 index 00000000..b2a04d3c Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CD20_Dy161.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CD3_Er170.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CD3_Er170.tiff new file mode 100644 index 00000000..10b0d00f Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CD3_Er170.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CD45_Sm152.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CD45_Sm152.tiff new file mode 100644 index 00000000..4f73a358 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CD45_Sm152.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CD4_Gd156.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CD4_Gd156.tiff new file mode 100644 index 00000000..f7757d39 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CD4_Gd156.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CD68_Tb159.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CD68_Tb159.tiff new file mode 100644 index 00000000..2327d822 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CD68_Tb159.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CD8a_Dy162.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CD8a_Dy162.tiff new file mode 100644 index 00000000..607a39e7 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CD8a_Dy162.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/CollagenI_Tm169.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/CollagenI_Tm169.tiff new file mode 100644 index 00000000..59dfc405 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/CollagenI_Tm169.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/DNA1_Ir191.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/DNA1_Ir191.tiff new file mode 100644 index 00000000..c850f763 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/DNA1_Ir191.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/DNA3_Ir193.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/DNA3_Ir193.tiff new file mode 100644 index 00000000..df23a8a3 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/DNA3_Ir193.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/HistoneH3_Yb176.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..6345bce2 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/VIM_Nd143.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/VIM_Nd143.tiff new file mode 100644 index 00000000..9ce1e843 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/VIM_Nd143.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI010/alphaSMA_Pr141.tiff b/segmentation/Ilastik multicut/ROIs/ROI010/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..140ce1e3 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI010/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/140Ce_Ce140.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/140Ce_Ce140.tiff new file mode 100644 index 00000000..a8ffe092 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/140Ce_Ce140.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/80ArAr_ArAr80.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..c9e45ba5 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CD11b_Sm149.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CD11b_Sm149.tiff new file mode 100644 index 00000000..446e3bcd Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CD11b_Sm149.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CD20_Dy161.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CD20_Dy161.tiff new file mode 100644 index 00000000..04d8cf98 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CD20_Dy161.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CD3_Er170.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CD3_Er170.tiff new file mode 100644 index 00000000..b40a2b3b Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CD3_Er170.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CD45_Sm152.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CD45_Sm152.tiff new file mode 100644 index 00000000..f644cb88 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CD45_Sm152.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CD4_Gd156.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CD4_Gd156.tiff new file mode 100644 index 00000000..2144ec83 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CD4_Gd156.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CD68_Tb159.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CD68_Tb159.tiff new file mode 100644 index 00000000..6241ba58 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CD68_Tb159.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CD8a_Dy162.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CD8a_Dy162.tiff new file mode 100644 index 00000000..707553fc Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CD8a_Dy162.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/CollagenI_Tm169.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/CollagenI_Tm169.tiff new file mode 100644 index 00000000..db708c21 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/CollagenI_Tm169.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/DNA1_Ir191.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/DNA1_Ir191.tiff new file mode 100644 index 00000000..006cfed4 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/DNA1_Ir191.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/DNA3_Ir193.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/DNA3_Ir193.tiff new file mode 100644 index 00000000..44767a7d Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/DNA3_Ir193.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/HistoneH3_Yb176.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..0bf38bf2 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/VIM_Nd143.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/VIM_Nd143.tiff new file mode 100644 index 00000000..0f06decb Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/VIM_Nd143.tiff differ diff --git a/segmentation/Ilastik multicut/ROIs/ROI012/alphaSMA_Pr141.tiff b/segmentation/Ilastik multicut/ROIs/ROI012/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..3fbfcf83 Binary files /dev/null and b/segmentation/Ilastik multicut/ROIs/ROI012/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Ilastik multicut/Segmentation - process TIFFs.R b/segmentation/Ilastik multicut/Segmentation - process TIFFs.R new file mode 100644 index 00000000..7f111a81 --- /dev/null +++ b/segmentation/Ilastik multicut/Segmentation - process TIFFs.R @@ -0,0 +1,106 @@ +################################################################################### +### Segmentation 1 - process TIFFs +################################################################################### + + ### Load packages + + library(Spectre) + + package.check(type = 'spatial') + package.load(type = 'spatial') + + ### Set PrimaryDirectory + + dirname(rstudioapi::getActiveDocumentContext()$path) # Finds the directory where this script is located + setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # Sets the working directory to where the script is located + getwd() + PrimaryDirectory <- getwd() + PrimaryDirectory + + ### Set InputDirectory + + setwd(PrimaryDirectory) + setwd("ROIs/") + InputDirectory <- getwd() + InputDirectory + + ### Create directory for Ilastik HDF5 files + + setwd(PrimaryDirectory) + dir.create("masks") + setwd("masks") + MaskDirectory <- getwd() + MaskDirectory + + ### Create directory for CROPPED Ilastik HDF5 files + + setwd(PrimaryDirectory) + dir.create("cropped") + setwd("cropped") + CroppedDirectory <- getwd() + CroppedDirectory + +################################################################################### +### Check ROIs and TIFFs +################################################################################### + + ### Initialise the spatial data object with channel TIFF files + + setwd(InputDirectory) + + rois <- list.dirs(full.names = FALSE, recursive = FALSE) + as.matrix(rois) + + tiff.list <- list() + + for(i in rois){ + setwd(InputDirectory) + setwd(i) + tiff.list[[i]] <- list.files(getwd()) + } + + t(as.data.frame(tiff.list)) + +################################################################################### +### Read in TIFF files and create spatial objects +################################################################################### + + setwd(InputDirectory) + + spatial.dat <- read.spatial.files(rois = rois, roi.loc = getwd()) + + str(spatial.dat, 3) + spatial.dat[[1]]$RASTERS + +################################################################################### +### Create HDF5 files for mask creation +################################################################################### + + nms <- names(spatial.dat[[1]]$RASTERS) + + as.matrix(nms) + for.ilastik <- nms[c(3:15)] + as.matrix(for.ilastik) + + as.matrix(for.ilastik) + merge.channels <- for.ilastik[c(2:8)] + as.matrix(merge.channels) + + ## Whole ROIs for Ilastik + + setwd(MaskDirectory) + write.hdf5(dat = spatial.dat, + channels = for.ilastik, + merge.channels = merge.channels, + plots = FALSE) + + ## Cropped ROIs to train Ilastik + + setwd(CroppedDirectory) + write.hdf5(dat = spatial.dat, + channels = for.ilastik, + merge.channels = merge.channels, + random.crop.x = 350, + random.crop.y = 300, + plots = FALSE) + diff --git a/segmentation/Ilastik multicut/multicut_1_pixel.ilp b/segmentation/Ilastik multicut/multicut_1_pixel.ilp new file mode 100755 index 00000000..a7681187 Binary files /dev/null and b/segmentation/Ilastik multicut/multicut_1_pixel.ilp differ diff --git a/segmentation/Ilastik multicut/multicut_2_segment.ilp b/segmentation/Ilastik multicut/multicut_2_segment.ilp new file mode 100755 index 00000000..32b1e5a9 Binary files /dev/null and b/segmentation/Ilastik multicut/multicut_2_segment.ilp differ diff --git a/segmentation/Ilastik multicut/multicut_3_cellClassification.ilp b/segmentation/Ilastik multicut/multicut_3_cellClassification.ilp new file mode 100755 index 00000000..c380e406 Binary files /dev/null and b/segmentation/Ilastik multicut/multicut_3_cellClassification.ilp differ diff --git a/segmentation/Ilastik multicut/multicut_4_regionClassification.ilp b/segmentation/Ilastik multicut/multicut_4_regionClassification.ilp new file mode 100755 index 00000000..dd48c9dd Binary files /dev/null and b/segmentation/Ilastik multicut/multicut_4_regionClassification.ilp differ diff --git a/segmentation/Simple nuclear/BasicSegmentation_MAC.cpproj b/segmentation/Simple nuclear/BasicSegmentation_MAC.cpproj new file mode 100644 index 00000000..92806064 Binary files /dev/null and b/segmentation/Simple nuclear/BasicSegmentation_MAC.cpproj differ diff --git a/segmentation/Simple nuclear/BasicSegmentation_WINDOWS.cpproj b/segmentation/Simple nuclear/BasicSegmentation_WINDOWS.cpproj new file mode 100644 index 00000000..3a9d3e59 Binary files /dev/null and b/segmentation/Simple nuclear/BasicSegmentation_WINDOWS.cpproj differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/127I_I127.tiff b/segmentation/Simple nuclear/ROIs/ROI002/127I_I127.tiff new file mode 100755 index 00000000..9788e5e5 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/127I_I127.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/131Xe_Xe131.tiff b/segmentation/Simple nuclear/ROIs/ROI002/131Xe_Xe131.tiff new file mode 100755 index 00000000..bb830f62 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/131Xe_Xe131.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/134Xe_Xe134.tiff b/segmentation/Simple nuclear/ROIs/ROI002/134Xe_Xe134.tiff new file mode 100755 index 00000000..a8041f27 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/134Xe_Xe134.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/138Ba_Ba138.tiff b/segmentation/Simple nuclear/ROIs/ROI002/138Ba_Ba138.tiff new file mode 100755 index 00000000..f82e2792 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/138Ba_Ba138.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/140Ce_Ce140.tiff b/segmentation/Simple nuclear/ROIs/ROI002/140Ce_Ce140.tiff new file mode 100644 index 00000000..684840e9 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/140Ce_Ce140.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/188Os_Os188.tiff b/segmentation/Simple nuclear/ROIs/ROI002/188Os_Os188.tiff new file mode 100755 index 00000000..46ae9153 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/188Os_Os188.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/190BCKG_BCKG190.tiff b/segmentation/Simple nuclear/ROIs/ROI002/190BCKG_BCKG190.tiff new file mode 100755 index 00000000..17aed6d0 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/190BCKG_BCKG190.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/202Hg_Hg202.tiff b/segmentation/Simple nuclear/ROIs/ROI002/202Hg_Hg202.tiff new file mode 100755 index 00000000..79693b98 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/202Hg_Hg202.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/208Pb_Pb208.tiff b/segmentation/Simple nuclear/ROIs/ROI002/208Pb_Pb208.tiff new file mode 100755 index 00000000..d6cbaea8 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/208Pb_Pb208.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/209Bi_Bi209.tiff b/segmentation/Simple nuclear/ROIs/ROI002/209Bi_Bi209.tiff new file mode 100755 index 00000000..8a6055f8 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/209Bi_Bi209.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/80ArAr_ArAr80.tiff b/segmentation/Simple nuclear/ROIs/ROI002/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..5a62a1c4 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/89Y_Y89.tiff b/segmentation/Simple nuclear/ROIs/ROI002/89Y_Y89.tiff new file mode 100755 index 00000000..b3c4da41 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/89Y_Y89.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CD11b_Sm149.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CD11b_Sm149.tiff new file mode 100644 index 00000000..f7a33a91 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CD11b_Sm149.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CD20_Dy161.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CD20_Dy161.tiff new file mode 100644 index 00000000..a2de50f4 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CD20_Dy161.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CD3_Er170.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CD3_Er170.tiff new file mode 100644 index 00000000..202bc952 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CD3_Er170.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CD45_Sm152.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CD45_Sm152.tiff new file mode 100644 index 00000000..507a358f Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CD45_Sm152.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CD4_Gd156.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CD4_Gd156.tiff new file mode 100644 index 00000000..f2e0c4bf Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CD4_Gd156.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CD68_Tb159.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CD68_Tb159.tiff new file mode 100644 index 00000000..6cbd60e6 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CD68_Tb159.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CD8a_Dy162.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CD8a_Dy162.tiff new file mode 100644 index 00000000..bfd3af45 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CD8a_Dy162.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/CollagenI_Tm169.tiff b/segmentation/Simple nuclear/ROIs/ROI002/CollagenI_Tm169.tiff new file mode 100644 index 00000000..0bcc338b Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/CollagenI_Tm169.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/DNA1_Ir191.tiff b/segmentation/Simple nuclear/ROIs/ROI002/DNA1_Ir191.tiff new file mode 100644 index 00000000..f8085bd9 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/DNA1_Ir191.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/DNA3_Ir193.tiff b/segmentation/Simple nuclear/ROIs/ROI002/DNA3_Ir193.tiff new file mode 100644 index 00000000..e9d2af16 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/DNA3_Ir193.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/HistoneH3_Yb176.tiff b/segmentation/Simple nuclear/ROIs/ROI002/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..9640523a Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/VIM_Nd143.tiff b/segmentation/Simple nuclear/ROIs/ROI002/VIM_Nd143.tiff new file mode 100644 index 00000000..6e093dfb Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/VIM_Nd143.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI002/alphaSMA_Pr141.tiff b/segmentation/Simple nuclear/ROIs/ROI002/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..2d356e42 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI002/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/140Ce_Ce140.tiff b/segmentation/Simple nuclear/ROIs/ROI004/140Ce_Ce140.tiff new file mode 100644 index 00000000..1d0dbafe Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/140Ce_Ce140.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/80ArAr_ArAr80.tiff b/segmentation/Simple nuclear/ROIs/ROI004/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..7a1c3f05 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CD11b_Sm149.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CD11b_Sm149.tiff new file mode 100644 index 00000000..1db62a27 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CD11b_Sm149.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CD20_Dy161.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CD20_Dy161.tiff new file mode 100644 index 00000000..35469bfc Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CD20_Dy161.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CD3_Er170.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CD3_Er170.tiff new file mode 100644 index 00000000..ef13aa36 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CD3_Er170.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CD45_Sm152.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CD45_Sm152.tiff new file mode 100644 index 00000000..2f47cef6 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CD45_Sm152.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CD4_Gd156.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CD4_Gd156.tiff new file mode 100644 index 00000000..6ad14cac Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CD4_Gd156.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CD68_Tb159.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CD68_Tb159.tiff new file mode 100644 index 00000000..f1f1e795 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CD68_Tb159.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CD8a_Dy162.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CD8a_Dy162.tiff new file mode 100644 index 00000000..a8c769d5 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CD8a_Dy162.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/CollagenI_Tm169.tiff b/segmentation/Simple nuclear/ROIs/ROI004/CollagenI_Tm169.tiff new file mode 100644 index 00000000..fd61881b Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/CollagenI_Tm169.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/DNA1_Ir191.tiff b/segmentation/Simple nuclear/ROIs/ROI004/DNA1_Ir191.tiff new file mode 100644 index 00000000..859ff093 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/DNA1_Ir191.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/DNA3_Ir193.tiff b/segmentation/Simple nuclear/ROIs/ROI004/DNA3_Ir193.tiff new file mode 100644 index 00000000..25fa398d Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/DNA3_Ir193.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/HistoneH3_Yb176.tiff b/segmentation/Simple nuclear/ROIs/ROI004/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..a652bea8 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/VIM_Nd143.tiff b/segmentation/Simple nuclear/ROIs/ROI004/VIM_Nd143.tiff new file mode 100644 index 00000000..cc4ca50d Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/VIM_Nd143.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI004/alphaSMA_Pr141.tiff b/segmentation/Simple nuclear/ROIs/ROI004/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..4c1585d2 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI004/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/140Ce_Ce140.tiff b/segmentation/Simple nuclear/ROIs/ROI006/140Ce_Ce140.tiff new file mode 100644 index 00000000..9bbaf2ee Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/140Ce_Ce140.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/80ArAr_ArAr80.tiff b/segmentation/Simple nuclear/ROIs/ROI006/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..d5a8234e Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CD11b_Sm149.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CD11b_Sm149.tiff new file mode 100644 index 00000000..0206b0ca Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CD11b_Sm149.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CD20_Dy161.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CD20_Dy161.tiff new file mode 100644 index 00000000..05e84982 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CD20_Dy161.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CD3_Er170.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CD3_Er170.tiff new file mode 100644 index 00000000..7d570b90 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CD3_Er170.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CD45_Sm152.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CD45_Sm152.tiff new file mode 100644 index 00000000..3af8521b Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CD45_Sm152.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CD4_Gd156.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CD4_Gd156.tiff new file mode 100644 index 00000000..78aea8b8 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CD4_Gd156.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CD68_Tb159.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CD68_Tb159.tiff new file mode 100644 index 00000000..06ec3bb5 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CD68_Tb159.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CD8a_Dy162.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CD8a_Dy162.tiff new file mode 100644 index 00000000..6befc86c Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CD8a_Dy162.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/CollagenI_Tm169.tiff b/segmentation/Simple nuclear/ROIs/ROI006/CollagenI_Tm169.tiff new file mode 100644 index 00000000..dd25f6bc Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/CollagenI_Tm169.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/DNA1_Ir191.tiff b/segmentation/Simple nuclear/ROIs/ROI006/DNA1_Ir191.tiff new file mode 100644 index 00000000..9f5c27e3 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/DNA1_Ir191.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/DNA3_Ir193.tiff b/segmentation/Simple nuclear/ROIs/ROI006/DNA3_Ir193.tiff new file mode 100644 index 00000000..2b0ea24a Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/DNA3_Ir193.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/HistoneH3_Yb176.tiff b/segmentation/Simple nuclear/ROIs/ROI006/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..6efca7b3 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/VIM_Nd143.tiff b/segmentation/Simple nuclear/ROIs/ROI006/VIM_Nd143.tiff new file mode 100644 index 00000000..b579ae60 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/VIM_Nd143.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI006/alphaSMA_Pr141.tiff b/segmentation/Simple nuclear/ROIs/ROI006/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..6ea763fd Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI006/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/140Ce_Ce140.tiff b/segmentation/Simple nuclear/ROIs/ROI008/140Ce_Ce140.tiff new file mode 100644 index 00000000..0b30f306 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/140Ce_Ce140.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/80ArAr_ArAr80.tiff b/segmentation/Simple nuclear/ROIs/ROI008/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..020a24e1 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CD11b_Sm149.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CD11b_Sm149.tiff new file mode 100644 index 00000000..0510fb14 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CD11b_Sm149.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CD20_Dy161.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CD20_Dy161.tiff new file mode 100644 index 00000000..1720af2f Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CD20_Dy161.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CD3_Er170.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CD3_Er170.tiff new file mode 100644 index 00000000..b66950fb Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CD3_Er170.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CD45_Sm152.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CD45_Sm152.tiff new file mode 100644 index 00000000..790420c5 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CD45_Sm152.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CD4_Gd156.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CD4_Gd156.tiff new file mode 100644 index 00000000..5e41cf43 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CD4_Gd156.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CD68_Tb159.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CD68_Tb159.tiff new file mode 100644 index 00000000..acff9aec Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CD68_Tb159.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CD8a_Dy162.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CD8a_Dy162.tiff new file mode 100644 index 00000000..cca91724 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CD8a_Dy162.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/CollagenI_Tm169.tiff b/segmentation/Simple nuclear/ROIs/ROI008/CollagenI_Tm169.tiff new file mode 100644 index 00000000..632e05e1 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/CollagenI_Tm169.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/DNA1_Ir191.tiff b/segmentation/Simple nuclear/ROIs/ROI008/DNA1_Ir191.tiff new file mode 100644 index 00000000..eac01c08 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/DNA1_Ir191.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/DNA3_Ir193.tiff b/segmentation/Simple nuclear/ROIs/ROI008/DNA3_Ir193.tiff new file mode 100644 index 00000000..847d98d5 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/DNA3_Ir193.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/HistoneH3_Yb176.tiff b/segmentation/Simple nuclear/ROIs/ROI008/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..e91ca165 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/VIM_Nd143.tiff b/segmentation/Simple nuclear/ROIs/ROI008/VIM_Nd143.tiff new file mode 100644 index 00000000..18567b73 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/VIM_Nd143.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI008/alphaSMA_Pr141.tiff b/segmentation/Simple nuclear/ROIs/ROI008/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..50531e26 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI008/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/140Ce_Ce140.tiff b/segmentation/Simple nuclear/ROIs/ROI010/140Ce_Ce140.tiff new file mode 100644 index 00000000..0007e2c5 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/140Ce_Ce140.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/80ArAr_ArAr80.tiff b/segmentation/Simple nuclear/ROIs/ROI010/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..3509fb2f Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CD11b_Sm149.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CD11b_Sm149.tiff new file mode 100644 index 00000000..f95aece9 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CD11b_Sm149.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CD20_Dy161.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CD20_Dy161.tiff new file mode 100644 index 00000000..b2a04d3c Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CD20_Dy161.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CD3_Er170.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CD3_Er170.tiff new file mode 100644 index 00000000..10b0d00f Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CD3_Er170.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CD45_Sm152.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CD45_Sm152.tiff new file mode 100644 index 00000000..4f73a358 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CD45_Sm152.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CD4_Gd156.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CD4_Gd156.tiff new file mode 100644 index 00000000..f7757d39 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CD4_Gd156.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CD68_Tb159.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CD68_Tb159.tiff new file mode 100644 index 00000000..2327d822 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CD68_Tb159.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CD8a_Dy162.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CD8a_Dy162.tiff new file mode 100644 index 00000000..607a39e7 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CD8a_Dy162.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/CollagenI_Tm169.tiff b/segmentation/Simple nuclear/ROIs/ROI010/CollagenI_Tm169.tiff new file mode 100644 index 00000000..59dfc405 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/CollagenI_Tm169.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/DNA1_Ir191.tiff b/segmentation/Simple nuclear/ROIs/ROI010/DNA1_Ir191.tiff new file mode 100644 index 00000000..c850f763 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/DNA1_Ir191.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/DNA3_Ir193.tiff b/segmentation/Simple nuclear/ROIs/ROI010/DNA3_Ir193.tiff new file mode 100644 index 00000000..df23a8a3 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/DNA3_Ir193.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/HistoneH3_Yb176.tiff b/segmentation/Simple nuclear/ROIs/ROI010/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..6345bce2 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/VIM_Nd143.tiff b/segmentation/Simple nuclear/ROIs/ROI010/VIM_Nd143.tiff new file mode 100644 index 00000000..9ce1e843 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/VIM_Nd143.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI010/alphaSMA_Pr141.tiff b/segmentation/Simple nuclear/ROIs/ROI010/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..140ce1e3 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI010/alphaSMA_Pr141.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/140Ce_Ce140.tiff b/segmentation/Simple nuclear/ROIs/ROI012/140Ce_Ce140.tiff new file mode 100644 index 00000000..a8ffe092 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/140Ce_Ce140.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/80ArAr_ArAr80.tiff b/segmentation/Simple nuclear/ROIs/ROI012/80ArAr_ArAr80.tiff new file mode 100644 index 00000000..c9e45ba5 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/80ArAr_ArAr80.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CD11b_Sm149.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CD11b_Sm149.tiff new file mode 100644 index 00000000..446e3bcd Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CD11b_Sm149.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CD20_Dy161.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CD20_Dy161.tiff new file mode 100644 index 00000000..04d8cf98 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CD20_Dy161.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CD3_Er170.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CD3_Er170.tiff new file mode 100644 index 00000000..b40a2b3b Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CD3_Er170.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CD45_Sm152.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CD45_Sm152.tiff new file mode 100644 index 00000000..f644cb88 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CD45_Sm152.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CD4_Gd156.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CD4_Gd156.tiff new file mode 100644 index 00000000..2144ec83 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CD4_Gd156.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CD68_Tb159.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CD68_Tb159.tiff new file mode 100644 index 00000000..6241ba58 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CD68_Tb159.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CD8a_Dy162.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CD8a_Dy162.tiff new file mode 100644 index 00000000..707553fc Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CD8a_Dy162.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/CollagenI_Tm169.tiff b/segmentation/Simple nuclear/ROIs/ROI012/CollagenI_Tm169.tiff new file mode 100644 index 00000000..db708c21 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/CollagenI_Tm169.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/DNA1_Ir191.tiff b/segmentation/Simple nuclear/ROIs/ROI012/DNA1_Ir191.tiff new file mode 100644 index 00000000..006cfed4 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/DNA1_Ir191.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/DNA3_Ir193.tiff b/segmentation/Simple nuclear/ROIs/ROI012/DNA3_Ir193.tiff new file mode 100644 index 00000000..44767a7d Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/DNA3_Ir193.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/HistoneH3_Yb176.tiff b/segmentation/Simple nuclear/ROIs/ROI012/HistoneH3_Yb176.tiff new file mode 100644 index 00000000..0bf38bf2 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/HistoneH3_Yb176.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/VIM_Nd143.tiff b/segmentation/Simple nuclear/ROIs/ROI012/VIM_Nd143.tiff new file mode 100644 index 00000000..0f06decb Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/VIM_Nd143.tiff differ diff --git a/segmentation/Simple nuclear/ROIs/ROI012/alphaSMA_Pr141.tiff b/segmentation/Simple nuclear/ROIs/ROI012/alphaSMA_Pr141.tiff new file mode 100644 index 00000000..3fbfcf83 Binary files /dev/null and b/segmentation/Simple nuclear/ROIs/ROI012/alphaSMA_Pr141.tiff differ diff --git a/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 1 - add masks.R b/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 1 - add masks.R new file mode 100644 index 00000000..6d80d115 --- /dev/null +++ b/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 1 - add masks.R @@ -0,0 +1,301 @@ +################################################################################### +### Spectre: spatial 1 - add masks and extract cellular data +################################################################################### + +### Load libraries + +library('Spectre') + +Spectre::package.check(type = 'spatial') +Spectre::package.load(type = 'spatial') + +### Set PrimaryDirectory + +dirname(rstudioapi::getActiveDocumentContext()$path) # Finds the directory where this script is located +setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # Sets the working directory to where the script is located +getwd() +PrimaryDirectory <- getwd() +PrimaryDirectory + +### Set InputDirectory (ROI TIFFs) + +setwd(PrimaryDirectory) +setwd("data/ROIs/") +InputDirectory <- getwd() +InputDirectory + +### Set MaskDirectory (ROI mask TIFFs) + +setwd(PrimaryDirectory) +setwd("data/masks/") +MaskDirectory <- getwd() +MaskDirectory + +### Create output directory + +setwd(PrimaryDirectory) +dir.create("Output 1 - add masks") +setwd("Output 1 - add masks") +OutputDirectory <- getwd() +OutputDirectory + +################################################################################### +### Check ROIs and TIFFs +################################################################################### + +### Initialise the spatial data object with channel TIFF files + +setwd(InputDirectory) + +rois <- list.dirs(full.names = FALSE, recursive = FALSE) +as.matrix(rois) + +tiff.list <- list() + +### Check channel names + +for(i in rois){ + setwd(InputDirectory) + setwd(i) + tiff.list[[i]] <- list.files(getwd()) +} + +t(as.data.frame(tiff.list)) + +################################################################################### +### Read in TIFF files and create spatial objects +################################################################################### + +### Read in ROI channel TIFFs + +setwd(InputDirectory) +spatial.dat <- read.spatial.files(rois = rois, roi.loc = getwd()) + +### Check results + +str(spatial.dat, 3) +spatial.dat[[1]]$RASTERS + +################################################################################### +### Read in masks files +################################################################################### + + ### Define cell mask extension for different mask types + + setwd(MaskDirectory) + + all.masks <- list.files(pattern = '.tif') + as.matrix(all.masks) + + ### Import CELL masks + + as.matrix(all.masks) + cell.mask.ext <- '_ilastik_s2_Object Identities.tif' + + cell.masks <- list.files(pattern = cell.mask.ext) + as.matrix(cell.masks) + + spatial.dat <- do.add.masks(spatial.dat = spatial.dat, + mask.loc = getwd(), + masks = cell.masks, + mask.label = 'cell.mask', + mask.ext = cell.mask.ext) + + str(spatial.dat, 3) + + spatial.dat[[1]]$RASTERS + spatial.dat[[1]]$MASKS + + ### Import CELL TYPE masks + + as.matrix(all.masks) + cell.type.ext <- '_ilastik_s2_Object Predictions.tif' + + cell.types <- list.files(pattern = cell.type.ext) + as.matrix(cell.types) + + spatial.dat <- do.add.masks(spatial.dat = spatial.dat, + mask.loc = getwd(), + masks = cell.types, + mask.label = 'cell.type', + mask.ext = cell.type.ext) + + str(spatial.dat, 3) + + spatial.dat[[1]]$RASTERS + spatial.dat[[1]]$MASKS + + ### Import REGION masks + + as.matrix(all.masks) + region.ext <- '_ilastik_s2_Simple Segmentation.tif' + + regions <- list.files(pattern = region.ext) + as.matrix(regions) + + spatial.dat <- do.add.masks(spatial.dat = spatial.dat, + mask.loc = getwd(), + masks = regions, + mask.label = 'region', + mask.ext = region.ext) + + str(spatial.dat, 3) + + spatial.dat[[1]]$RASTERS + spatial.dat[[1]]$MASKS + +################################################################################### +### Generate polygons and outlines +################################################################################### + +### Generate polygons and outlines + +spatial.dat <- do.create.outlines(spatial.dat, 'cell.mask') +spatial.dat <- do.create.outlines(spatial.dat, 'cell.type') +spatial.dat <- do.create.outlines(spatial.dat, 'region') + +### Checks + +str(spatial.dat, 3) + +spatial.dat[[1]]$RASTERS +spatial.dat[[1]]$MASKS + +################################################################################### +### Mask QC plots +################################################################################### + +### Mask plots + +setwd(OutputDirectory) +dir.create('Plots - cell masks') +setwd('Plots - cell masks') + +base <- 'DNA1_Ir191' +mask <- 'cell.mask' + +for(i in names(spatial.dat)){ + make.spatial.plot(spatial.dat = spatial.dat, + image.roi = i, + image.channel = base, + mask.outlines = 'cell.mask') +} + +################################################################################### +### Extract 'per cell' data +################################################################################### + +### Extract cellular data for each cell mask + +spatial.dat <- do.extract(spatial.dat, 'cell.mask') +str(spatial.dat, 3) + +################################################################################### +### Save spatial data object as qs file +################################################################################### + +### Output + +setwd(OutputDirectory) +dir.create('QS file') +setwd('QS file') + +qsave(spatial.dat, "spatial.dat.qs") + +################################################################################### +### Write FCS files +################################################################################### + +### Pull cellular data + +cell.dat <- do.pull.data(spatial.dat, 'CellData') +cell.dat + +as.matrix(names(cell.dat)) +cellular.cols <- names(cell.dat)[c(6:20)] +cellular.cols + +### Arcsinh transformation + +cell.dat <- do.asinh(cell.dat, cellular.cols, cofactor = 1) + +### Invert y axis + +all.neg <- function(test) -1*abs(test) + +y_invert <- cell.dat[['y']] +y_invert <- all.neg(y_invert) +cell.dat[['y_invert']] <- y_invert + +cell.dat + +### Write FCS files + +setwd(OutputDirectory) +dir.create('FCS files') +setwd('FCS files') + +write.files(cell.dat, 'spatial_all', write.csv = FALSE, write.fcs = TRUE) +write.files(cell.dat, 'spatial', divide.by = 'ROI', write.csv = FALSE, write.fcs = TRUE) + +################################################################################### +### Further plots +################################################################################### + +### Plot settings + +as.matrix(names(spatial.dat)) + +plot.rois <- c("ROI002", "ROI004") +plot.rois + +as.matrix(names(spatial.dat[[1]]$RASTERS)) +exp.plot <- names(spatial.dat[[1]]$RASTERS)[1:15] +exp.plot + +as.matrix(names(spatial.dat[[1]]$DATA$CellData)) +factor.plot <- names(spatial.dat[[1]]$DATA$CellData)[20:21] +factor.plot + +### Expression data point plots + +setwd(OutputDirectory) +dir.create('Plots - expression') +setwd('Plots - expression') + +for(i in plot.rois){ + for(a in exp.plot){ + make.spatial.plot(spatial.dat = spatial.dat, + image.roi = i, + image.channel = a, + mask.outlines = 'cell.mask') + } +} + +### Data point plots + +setwd(OutputDirectory) +dir.create('Plots - data point expression') +setwd('Plots - data point expression') + +for(i in plot.rois){ + for(a in exp.plot){ + make.spatial.plot(spatial.dat = spatial.dat, + image.roi = i, + image.channel = a, + mask.outlines = 'cell.mask', + cell.dat = 'CellData', + cell.col = a) + } + + for(a in factor.plot){ + make.spatial.plot(spatial.dat = spatial.dat, + image.roi = i, + image.channel = base, + mask.outlines = 'cell.mask', + cell.dat = 'CellData', + cell.col = a, + cell.col.type = 'factor') + } +} + diff --git a/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 2 - cellular analysis.R b/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 2 - cellular analysis.R new file mode 100644 index 00000000..ced70d91 --- /dev/null +++ b/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 2 - cellular analysis.R @@ -0,0 +1,301 @@ +################################################################################### +### Spectre: spatial 2 - cellular analysis +################################################################################### + + ### Load libraries + + library('Spectre') + + Spectre::package.check(type = 'spatial') + Spectre::package.load(type = 'spatial') + + ### Set PrimaryDirectory + + dirname(rstudioapi::getActiveDocumentContext()$path) # Finds the directory where this script is located + setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # Sets the working directory to where the script is located + getwd() + PrimaryDirectory <- getwd() + PrimaryDirectory + + ### Set InputDirectory + + setwd(PrimaryDirectory) + setwd("Output 1 - add masks") + InputDirectory <- getwd() + InputDirectory + + ### Set metadata directory + + setwd(PrimaryDirectory) + setwd("metadata") + MetaDirectory <- getwd() + MetaDirectory + + ### Create output directory + + setwd(PrimaryDirectory) + dir.create("Output 2 - cellular analysis") + setwd("Output 2 - cellular analysis") + OutputDirectory <- getwd() + OutputDirectory + +################################################################################### +### Read in spatial data object +################################################################################### + + ### Read in spatial data object + + setwd(InputDirectory) + setwd("QS file/") + + list.files(getwd(), '.qs') + + spatial.dat <- qread('spatial.dat.qs') + str(spatial.dat, 3) + + spatial.dat[[1]]$DATA$CellData + + ### Metadata + + setwd(MetaDirectory) + + sample.meta <- fread("ROIs and samples.csv") + sample.meta + +################################################################################### +### Extract cellular data from images using masks and add annotations +################################################################################### + + setwd(OutputDirectory) + + ### Pull cellular data into a separate data.table + + cell.dat <- do.pull.data(spatial.dat, 'CellData') + cell.dat + + ### Add sample metadata + + cell.dat <- do.add.cols(cell.dat, base.col = 'ROI', add.dat = sample.meta, add.by = 'ROI') + cell.dat + + ### Annotate the 'cell.type' masks + + make.spatial.plot(spatial.dat, + image.roi = 'ROI002', + image.channel = 'DNA1_Ir191', + cell.dat = 'CellData', + cell.col = 'cell.type', + cell.col.type = 'factor') + + + as.matrix(unique(cell.dat$cell.type)) + + cell.type.annot <- list('Cell' = c('65534'), + 'Non-cell' = c('65535') + ) + + cell.type.annot <- do.list.switch(cell.type.annot) + names(cell.type.annot) <- c('Values', 'Annotated cell type') + cell.type.annot + + cell.dat <- do.add.cols(cell.dat, 'cell.type', cell.type.annot, 'Values') + cell.dat + + ### Annotate the 'cell.type' masks + + make.spatial.plot(spatial.dat, + image.roi = 'ROI002', + image.channel = 'DNA1_Ir191', + cell.dat = 'CellData', + cell.col = 'region', + cell.col.type = 'factor') + + as.matrix(unique(cell.dat$region)) + + region.annot <- list('Background' = c('65533'), + 'Red pulp' = c('65534'), + 'White pulp' = c('65535') + ) + + region.annot <- do.list.switch(region.annot) + names(region.annot) <- c('Values', 'Annotated region') + region.annot + + cell.dat <- do.add.cols(cell.dat, 'region', region.annot, 'Values') + cell.dat + +################################################################################### +### Filtering +################################################################################### + + ### Filter + + as.matrix(unique(cell.dat$`Annotated cell type`)) + + cell.dat <- cell.dat[cell.dat[['Annotated cell type']] != 'Non-cell',] + cell.dat + +################################################################################### +### Setup columns +################################################################################### + + ### Select 'cellular' columns and perform arcsinh transformation + + as.matrix(names(cell.dat)) + + cellular.cols <- names(cell.dat)[c(8:20)] + as.matrix(cellular.cols) + + ### Define key columns + + as.matrix(names(cell.dat)) + + roi.col <- 'ROI' + sample.col <- 'Sample' + group.col <- 'Group' + batch.col <- 'Batch' + + ### Asinh transformation + + cell.dat <- do.asinh(cell.dat, cellular.cols, cofactor = 1) + cell.dat + + cellular.cols <- paste0(cellular.cols, "_asinh") + as.matrix(cellular.cols) + + ### Re-scaling + + cell.dat <- do.rescale(cell.dat, cellular.cols) + cell.dat + + cellular.cols <- paste0(cellular.cols, "_rescaled") + as.matrix(cellular.cols) + + ### Define clustering cols + + as.matrix(names(cell.dat)) + + cluster.cols <- names(cell.dat)[c(41:47)] + as.matrix(cluster.cols) + +################################################################################### +### Clustering and dimensionality reduction +################################################################################### + + setwd(OutputDirectory) + + ### Run FlowSOM + + cell.dat <- run.flowsom(cell.dat, cluster.cols, meta.k = 15) + cell.dat + + ### Run DR + + cell.dat <- run.fitsne(cell.dat, cluster.cols, perplexity = 200) + cell.dat + + ### Individual plots + + make.colour.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', roi.col, 'factor') + make.colour.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', sample.col, 'factor') + make.colour.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', group.col, 'factor') + make.colour.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', batch.col, 'factor') + + make.colour.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', 'Annotated cell type', 'factor', add.label = TRUE) + make.colour.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', 'FlowSOM_metacluster', 'factor', add.label = TRUE) + + ### Multi plots + + make.multi.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', plot.by = cellular.cols, figure.title = 'Cellular cols') + make.multi.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', plot.by = cluster.cols, col.type = 'factor', figure.title = 'Clustering cols') + + make.multi.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', 'Annotated cell type', 'ROI', col.type = 'factor', figure.title = 'FlowSOM_metacluster by ROI') + make.multi.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', 'FlowSOM_metacluster', 'ROI', col.type = 'factor', figure.title = 'FlowSOM_metacluster by ROI') + + ### Expression heatmap + + exp <- do.aggregate(cell.dat, cellular.cols, 'FlowSOM_metacluster', 'mean') + make.pheatmap(exp, 'FlowSOM_metacluster', cellular.cols) + rm(exp) + +################################################################################### +### Annotate clusters +################################################################################### + + ### Cluster annotations + + cluster.annots <- list('T cells' = c(12,14,15), + 'B cells' = c(1,10,5,9)) + + cluster.annots <- do.list.switch(cluster.annots) + names(cluster.annots) <- c('Values', 'Annotated metacluster') + cluster.annots + + ### Add annotations, fill in NAs + + cell.dat <- do.add.cols(cell.dat, 'FlowSOM_metacluster', cluster.annots, 'Values') + cell.dat[['Annotated metacluster']][is.na(cell.dat[['Annotated metacluster']])] <- 'Other' + cell.dat + + ### Extra plots + + make.colour.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', 'Annotated metacluster', 'factor', add.label = TRUE) + make.multi.plot(cell.dat, 'FItSNE_X', 'FItSNE_Y', 'Annotated metacluster', 'ROI', col.type = 'factor', figure.title = 'Annotated metacluster by ROI') + +################################################################################### +### Save data +################################################################################### + + setwd(OutputDirectory) + + ### data.table + + fwrite(cell.dat, 'cell.dat.csv') + + ### FCS files + + setwd(OutputDirectory) + dir.create('FCS') + setwd('FCS') + + write.files(cell.dat, file.prefix = 'IMC_All', write.csv = FALSE, write.fcs = TRUE) + write.files(cell.dat, file.prefix = 'IMC_', divide.by = sample.col, write.csv = FALSE, write.fcs = TRUE) + +################################################################################### +### Spatial plotting of cluster data +################################################################################### + + ### Clusters + + setwd(OutputDirectory) + dir.create('Clusters') + setwd('Clusters') + + for(i in unique(cell.dat$ROI)){ + temp <- cell.dat[cell.dat[['ROI']] == i,] + make.spatial.plot(spatial.dat, i, 'DNA1_Ir191', mask.outlines = 'cell.mask', temp, cell.col = 'Annotated metacluster', cell.col.type = 'factor') + } + + ### Cell type + + setwd(OutputDirectory) + dir.create('Annotated') + setwd('Annotated') + + for(i in unique(cell.dat$ROI)){ + temp <- cell.dat[cell.dat[['ROI']] == i,] + make.spatial.plot(spatial.dat, i, 'DNA1_Ir191', mask.outlines = 'cell.mask', temp, cell.col = 'Annotated cell type', cell.col.type = 'factor') + } + + + ### Regions + + setwd(OutputDirectory) + dir.create('Regions') + setwd('Regions') + + for(i in unique(cell.dat$ROI)){ + temp <- cell.dat[cell.dat[['ROI']] == i,] + make.spatial.plot(spatial.dat, i, 'DNA1_Ir191', mask.outlines = 'cell.mask', temp, cell.col = 'Annotated region', cell.col.type = 'factor') + } + \ No newline at end of file diff --git a/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 3 - cluster annotation and spatial analysis.R b/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 3 - cluster annotation and spatial analysis.R new file mode 100644 index 00000000..db14589e --- /dev/null +++ b/worked_examples/Spatial_workflows/Advanced spatial workflow/Advanced spatial 3 - cluster annotation and spatial analysis.R @@ -0,0 +1,187 @@ +################################################################################### +### Spectre: spatial 3 - spatial analysis +################################################################################### + + ### Load libraries + + library('Spectre') + + Spectre::package.check(type = 'spatial') + Spectre::package.load(type = 'spatial') + + ### Set PrimaryDirectory + + dirname(rstudioapi::getActiveDocumentContext()$path) # Finds the directory where this script is located + setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # Sets the working directory to where the script is located + getwd() + PrimaryDirectory <- getwd() + PrimaryDirectory + + ### Set InputDirectory + + setwd(PrimaryDirectory) + setwd("Output 2 - cellular analysis/") + InputDirectory <- getwd() + InputDirectory + + ### Create output directory + + setwd(PrimaryDirectory) + dir.create("Output 3 - spatial analysis") + setwd("Output 3 - spatial analysis") + OutputDirectory <- getwd() + +################################################################################### +### Read in data +################################################################################### + + ### Read in data.table + + setwd(InputDirectory) + list.files(getwd(), '.csv') + + cell.dat <- fread("cell.dat.csv") + cell.dat + + ### Read in spatial data + + setwd(PrimaryDirectory) + setwd("Output 1 - add masks/QS file/") + + list.files(getwd(), '.qs') + + spatial.dat <- qread('spatial.dat.qs') + + ### Read in data.table + + area.totals <- do.calculate.area(spatial.dat) + area.totals + + area.table <- do.calculate.area(spatial.dat, region = 'region') + area.table + + as.matrix(unique(cell.dat[,c('region', 'Annotated region'),with = FALSE])) + + names(area.table) <- c('ROI', 'Background', 'Red pulp', 'White pulp') + area.table + + +################################################################################### +### Spatial analysis +################################################################################### + + setwd(OutputDirectory) + + ### Define columns + + as.matrix(names(cell.dat)) + + roi.col <- 'ROI' + sample.col <- 'Sample' + group.col <- 'Group' + batch.col <- 'Batch' + + pop.col <- 'Annotated metacluster' + region.col <- 'Annotated region' + + ### Some checks + + as.matrix(unique(cell.dat[[roi.col]])) + as.matrix(unique(cell.dat[[group.col]])) + as.matrix(unique(cell.dat[[region.col]])) + area.table + + as.matrix(unique(cell.dat[[pop.col]])) + + ### Run area analysis on the DATA.TABLE + + reg.dat <- run.spatial.analysis(dat = cell.dat, + sample.col = roi.col, + pop.col = pop.col, + annot.cols = group.col, + region.col = region.col, + area.table = area.table) ## Also calculate on total by default + + reg.dat[,c(1:10)] + + ### Save regional analysis data + + setwd(OutputDirectory) + fwrite(reg.dat, 'reg.dat.csv') + +################################################################################### +### Plotting etc +################################################################################### + + setwd(OutputDirectory) + + ### Plotting preferences + + as.matrix(names(reg.dat)) + + as.matrix(names(reg.dat)[c(1:10)]) + to.plot <- names(reg.dat)[c(3:ncol(reg.dat))] + to.plot + + ### Pheatmap + + reg.dat.z <- do.zscore(reg.dat, use.cols = to.plot, replace = TRUE) + reg.dat.z + + reg.dat.z <- reg.dat.z[,colSums(is.na(reg.dat.z))