├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── 2D_point_pattern.R ├── 3D_viusalization.R ├── HSVencoding.R ├── Image_resolution_switch.R ├── Mask_functions.R ├── QC.R ├── RegionNeighbours.R ├── Rigid_transformation.R ├── RunNMF.R ├── Spatial_genes.R ├── Staffli.R ├── Visualization.R ├── Visualization_utilities.R ├── crop_utilities.R ├── facet_grid_SC.R ├── generics.R ├── image_processing.R ├── image_processing_utilities.R ├── manual_annotation.R ├── pre_processing.R ├── process_from_table.R └── utilities.R ├── README.md ├── STutility.Rproj ├── inst ├── CITATION └── extdata │ ├── counts │ ├── BC1.csv │ ├── BC2.csv │ ├── BC3.csv │ ├── BC4.csv │ ├── Hippo1.jpg │ ├── Hippo1.tsv.gz │ ├── Hippo2.jpg │ ├── Hippo2.tsv.gz │ ├── Hippo3.jpg │ ├── Hippo3.tsv.gz │ ├── Hippo4.jpg │ ├── Hippo4.tsv.gz │ ├── Hippo5.jpg │ ├── Hippo5.tsv.gz │ ├── Hippo6.jpg │ ├── Hippo6.tsv.gz │ ├── Hippo7.jpg │ ├── Hippo7.tsv.gz │ ├── Hippo8.jpg │ ├── Hippo8.tsv.gz │ ├── MOB1.jpg │ ├── MOB1.tsv │ ├── MOB2.jpg │ ├── MOB2.tsv │ ├── MOB3.jpg │ ├── MOB3.tsv │ ├── MOB4.jpg │ ├── MOB4.tsv │ ├── alignment_table_Hippo1.tsv.gz │ ├── alignment_table_Hippo2.tsv.gz │ ├── alignment_table_Hippo3.tsv.gz │ ├── alignment_table_Hippo4.tsv.gz │ ├── alignment_table_Hippo5.tsv.gz │ ├── alignment_table_Hippo6.tsv.gz │ ├── alignment_table_Hippo7.tsv.gz │ ├── alignment_table_Hippo8.tsv.gz │ ├── alignment_table_MOB1.tsv │ ├── alignment_table_MOB2.tsv │ ├── alignment_table_MOB3.tsv │ └── alignment_table_MOB4.tsv │ ├── metaData.csv │ ├── metaData_mmBrain.csv │ └── mouse_genes.tsv.gz └── man ├── AlignImages.Rd ├── ColorBlender.Rd ├── ConvertGeneNames.Rd ├── CorSpatialDims.Rd ├── CorSpatialGenes.Rd ├── Create3DStack.Rd ├── CreateStaffliObject.Rd ├── Create_annotation.Rd ├── CropImages.Rd ├── CustomFacetWrap.Rd ├── DimOverlay.Rd ├── DimPlot3D.Rd ├── EdgeMask.Rd ├── FactorGeneLoadingPlot.Rd ├── FeatureOverlay.Rd ├── FeaturePlot3D.Rd ├── FilterObjects.Rd ├── GetCoords.Rd ├── GetCropWindows.Rd ├── GetSpatNet.Rd ├── GetStaffli.Rd ├── HSVOverlay.Rd ├── HSVPlot.Rd ├── HSVPlot3D.Rd ├── ImagePlot.Rd ├── InputFromTable.Rd ├── LoadImages.Rd ├── ManualAlignImages.Rd ├── ManualAnnotation.Rd ├── MaskImages.Rd ├── MergeSTData.Rd ├── Merger.Rd ├── RegionNeighbours.Rd ├── RunNMF.Rd ├── ST.DimPlot.Rd ├── ST.FeaturePlot.Rd ├── ST.ImagePlot.Rd ├── ST.rgbDimPlot.Rd ├── STPlot.Rd ├── STutility-package.Rd ├── SetQuantile.Rd ├── SmoothPlot.Rd ├── Staffli-class.Rd ├── Staffli-get-methods.Rd ├── Staffli-set-methods.Rd ├── SubsetSTData.Rd ├── SummarizeAssocFeatures.Rd ├── SwitchResolution.Rd ├── Warp.Rd ├── WarpImages.Rd ├── add.margins.Rd ├── apply.transform.Rd ├── combine.tr.Rd ├── create.array.from.feature.vals.Rd ├── create.cols.from.array.Rd ├── cscale.Rd ├── dark_theme.Rd ├── draw_scalebar.Rd ├── facet_wrap_custom.Rd ├── feature.scaler.Rd ├── find.optimal.transform.Rd ├── g_legend.Rd ├── generate.map.affine.Rd ├── generate.map.rot.Rd ├── get.edges.Rd ├── get.edges.Seurat.Rd ├── get.edges.Staffli.Rd ├── getExtension.Rd ├── grid.from.staffli.Rd ├── ica_init.Rd ├── icpmat.Rd ├── iminfo.Rd ├── interpolate_2D_data.Rd ├── labelRGB.Rd ├── make.plot.Rd ├── mirror.Rd ├── names.Rd ├── obtain.array.coords.Rd ├── palette.select.Rd ├── parse.spot.file.Rd ├── plot.Rd ├── prep.sb.Rd ├── qc.scatter.Rd ├── qcGenes.Rd ├── qcSamples.Rd ├── qcSpots.Rd ├── rasterize_scatter.Rd ├── rasterlists.Rd ├── rigid.refl.Rd ├── rigid.rot.Rd ├── rigid.stretch.Rd ├── rigid.transf.Rd ├── rigid.transl.Rd ├── rnmf.Rd ├── rotate.Rd ├── samplenames.Rd ├── scale_override.Rd ├── scaled.imdims.Rd ├── scatter_HE.Rd ├── show.Rd ├── sleepy.Rd ├── slic.Rd ├── spatial_dim_plot.Rd ├── spatial_feature_plot.Rd ├── spatial_hsv_plot.Rd ├── st.load.matrix.Rd ├── stretch.Rd └── translate.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^doc$ 4 | ^Meta$ 5 | vignettes/vignette.Rmd 6 | vignettes/manual_annotation.Rmd 7 | vignettes/mouse_olfactory_buld.R 8 | vignettes/MultiCCA_vignette.Rmd 9 | R/Visualization_leaflet.R 10 | R/SeededNMF.R 11 | vignettes/vignette.Rmd 12 | .Rhistory 13 | saved/* 14 | R_tmp/ 15 | seeded_NMF.rmd -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | inst/doc 2 | doc 3 | .Rproj.user 4 | .gitignore 5 | .RData 6 | .Rhistory 7 | .DS_Store 8 | inst/.DS_Store 9 | inst/extdata/.DS_Store 10 | #inst/extdata/counts/* 11 | vignettes/MultiCCA_vignette.Rmd 12 | saved/* 13 | inst/rmarkdown 14 | vignettes/vignette_cache/ 15 | R/CMYK.R 16 | R/Visualization_leaflet.R 17 | R/SeededNMF.R 18 | R_tmp 19 | seeded_NMF.Rmd 20 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: STutility 2 | Type: Package 3 | Title: Analysis and visualization of Spatial Transcriptomics data 4 | Version: 1.1.1 5 | Authors@R: 6 | c(person( 7 | "Ludvig", "Larsson", 8 | email = "ludvig.larsson@scilifelab.se", 9 | role = c("aut", "cre") 10 | ), 11 | person( 12 | "Joseph", "Bergenstraahle", 13 | role = c("aut") 14 | )) 15 | Description: STutility collects useful tools for Spatial Transcriptomics data analysis within R. 16 | The package is built on top of popular Seurat R package, which is a toolkit for analysis and exploration of single cell RNA sequencing data (scRNAseq). 17 | STutility adds image functionallity to the Seurat workflow, allowing RNAseq data to be put in a spatial tissue context. 18 | Tutorials for data transformation, QC, analysis and visualization can be found on our website: https://ludvigla.github.io/STUtility_web_site/. 19 | License: MIT + file LICENSE 20 | Encoding: UTF-8 21 | Depends: 22 | Seurat (>= 3.0.0), 23 | ggplot2 (>= 3.2.0) 24 | Imports: 25 | methods, 26 | cowplot, 27 | dplyr, 28 | purrr, 29 | zeallot, 30 | magrittr, 31 | jsonlite, 32 | igraph (>= 1.2.4), 33 | plotly (>= 4.9.0), 34 | Matrix (>= 1.2), 35 | imager (>= 0.41), 36 | shiny (>= 1.3.0), 37 | raster (>= 3.0), 38 | magick (>= 2.0), 39 | scales (>= 1.0.0), 40 | data.table (>= 1.12.2), 41 | reshape2 (>= 1.4.3), 42 | patchwork, 43 | shinyjs 44 | Suggests: 45 | knitr, 46 | rmarkdown, 47 | reticulate, 48 | sp (>= 1.3), 49 | spData (>= 0.3.2), 50 | dbscan (>= 1.1), 51 | RColorBrewer, 52 | ggiraph (>= 0.6), 53 | viridis (>= 0.5.0), 54 | Morpho (>= 2.7), 55 | Rvcg (>= 0.18), 56 | tibble, 57 | ica (>= 1.0), 58 | irlba (>= 2.3.3), 59 | akima (>= 0.6), 60 | spdep (>= 1.1), 61 | spatstat.explore, 62 | spatstat.model, 63 | NNLM 64 | VignetteBuilder: knitr 65 | RoxygenNote: 7.2.3 66 | Collate: 67 | '2D_point_pattern.R' 68 | '3D_viusalization.R' 69 | 'HSVencoding.R' 70 | 'Image_resolution_switch.R' 71 | 'Mask_functions.R' 72 | 'QC.R' 73 | 'RegionNeighbours.R' 74 | 'Rigid_transformation.R' 75 | 'generics.R' 76 | 'Staffli.R' 77 | 'RunNMF.R' 78 | 'Spatial_genes.R' 79 | 'Visualization_utilities.R' 80 | 'Visualization.R' 81 | 'crop_utilities.R' 82 | 'facet_grid_SC.R' 83 | 'image_processing_utilities.R' 84 | 'image_processing.R' 85 | 'manual_annotation.R' 86 | 'pre_processing.R' 87 | 'process_from_table.R' 88 | 'utilities.R' 89 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2019 2 | COPYRIGHT HOLDER: Joseph Bergsntråhle 3 | 4 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(AlignImages,Seurat) 4 | S3method(AlignImages,Staffli) 5 | S3method(CropImages,Seurat) 6 | S3method(CropImages,Staffli) 7 | S3method(LoadImages,Seurat) 8 | S3method(LoadImages,Staffli) 9 | S3method(ManualAlignImages,Seurat) 10 | S3method(ManualAlignImages,Staffli) 11 | S3method(MaskImages,Seurat) 12 | S3method(MaskImages,Staffli) 13 | S3method(WarpImages,Seurat) 14 | S3method(WarpImages,Staffli) 15 | export(AlignImages) 16 | export(ConvertGeneNames) 17 | export(CorSpatialGenes) 18 | export(Create3DStack) 19 | export(CreateStaffliObject) 20 | export(CropImages) 21 | export(DimOverlay) 22 | export(DimPlot3D) 23 | export(EdgeMask) 24 | export(FactorGeneLoadingPlot) 25 | export(FeatureOverlay) 26 | export(FeaturePlot3D) 27 | export(GetCoords) 28 | export(GetCropWindows) 29 | export(GetSpatNet) 30 | export(GetStaffli) 31 | export(HSVOverlay) 32 | export(HSVPlot) 33 | export(HSVPlot3D) 34 | export(ImagePlot) 35 | export(InputFromTable) 36 | export(LoadImages) 37 | export(ManualAlignImages) 38 | export(ManualAnnotation) 39 | export(MaskImages) 40 | export(MergeSTData) 41 | export(RegionNeighbours) 42 | export(RunNMF) 43 | export(ST.DimPlot) 44 | export(ST.FeaturePlot) 45 | export(ST.ImagePlot) 46 | export(ST.rgbDimPlot) 47 | export(STPlot) 48 | export(SubsetSTData) 49 | export(SummarizeAssocFeatures) 50 | export(SwitchResolution) 51 | export(WarpImages) 52 | export(combine.tr) 53 | export(iminfo) 54 | export(labelRGB) 55 | export(palette.select) 56 | export(rasterlists) 57 | export(samplenames) 58 | export(scaled.imdims) 59 | exportClasses(Staffli) 60 | exportMethods("[") 61 | exportMethods("[<-") 62 | exportMethods("[[") 63 | exportMethods("[[<-") 64 | exportMethods(iminfo) 65 | exportMethods(names) 66 | exportMethods(plot) 67 | exportMethods(rasterlists) 68 | exportMethods(samplenames) 69 | exportMethods(scaled.imdims) 70 | exportMethods(show) 71 | import(Matrix) 72 | importFrom(Matrix,bdiag) 73 | importFrom(Matrix,colSums) 74 | importFrom(Seurat,"DefaultAssay<-") 75 | importFrom(Seurat,"Idents<-") 76 | importFrom(Seurat,CreateDimReducObject) 77 | importFrom(Seurat,CreateSeuratObject) 78 | importFrom(Seurat,DarkTheme) 79 | importFrom(Seurat,DefaultAssay) 80 | importFrom(Seurat,Embeddings) 81 | importFrom(Seurat,FetchData) 82 | importFrom(Seurat,GetAssayData) 83 | importFrom(Seurat,Idents) 84 | importFrom(Seurat,Key) 85 | importFrom(Seurat,Reductions) 86 | importFrom(Seurat,RenameCells) 87 | importFrom(Seurat,VariableFeatures) 88 | importFrom(Seurat,WhichCells) 89 | importFrom(cowplot,plot_grid) 90 | importFrom(data.table,as.data.table) 91 | importFrom(data.table,fread) 92 | importFrom(dplyr,group_by) 93 | importFrom(dplyr,mutate) 94 | importFrom(dplyr,select) 95 | importFrom(dplyr,summarize) 96 | importFrom(dplyr,ungroup) 97 | importFrom(ggplot2,aes) 98 | importFrom(ggplot2,aes_) 99 | importFrom(ggplot2,aes_string) 100 | importFrom(ggplot2,annotate) 101 | importFrom(ggplot2,annotation_custom) 102 | importFrom(ggplot2,as_labeller) 103 | importFrom(ggplot2,coord_fixed) 104 | importFrom(ggplot2,coord_flip) 105 | importFrom(ggplot2,element_blank) 106 | importFrom(ggplot2,element_rect) 107 | importFrom(ggplot2,element_text) 108 | importFrom(ggplot2,facet_wrap) 109 | importFrom(ggplot2,geom_bar) 110 | importFrom(ggplot2,geom_point) 111 | importFrom(ggplot2,geom_segment) 112 | importFrom(ggplot2,geom_text) 113 | importFrom(ggplot2,ggplot) 114 | importFrom(ggplot2,ggplot_build) 115 | importFrom(ggplot2,ggplot_gtable) 116 | importFrom(ggplot2,ggproto) 117 | importFrom(ggplot2,ggproto_parent) 118 | importFrom(ggplot2,ggtitle) 119 | importFrom(ggplot2,guide_legend) 120 | importFrom(ggplot2,guides) 121 | importFrom(ggplot2,labs) 122 | importFrom(ggplot2,scale_color_gradient2) 123 | importFrom(ggplot2,scale_color_gradientn) 124 | importFrom(ggplot2,scale_color_manual) 125 | importFrom(ggplot2,scale_fill_gradient2) 126 | importFrom(ggplot2,scale_fill_gradientn) 127 | importFrom(ggplot2,scale_fill_manual) 128 | importFrom(ggplot2,scale_size) 129 | importFrom(ggplot2,scale_x_continuous) 130 | importFrom(ggplot2,scale_y_continuous) 131 | importFrom(ggplot2,sym) 132 | importFrom(ggplot2,theme) 133 | importFrom(ggplot2,theme_bw) 134 | importFrom(ggplot2,theme_minimal) 135 | importFrom(ggplot2,theme_void) 136 | importFrom(ggplot2,vars) 137 | importFrom(grDevices,as.raster) 138 | importFrom(grDevices,col2rgb) 139 | importFrom(grDevices,colorRamp) 140 | importFrom(grDevices,densCols) 141 | importFrom(grDevices,dev.off) 142 | importFrom(grDevices,hcl) 143 | importFrom(grDevices,hsv) 144 | importFrom(grDevices,png) 145 | importFrom(grDevices,rgb) 146 | importFrom(grid,rasterGrob) 147 | importFrom(grid,unit) 148 | importFrom(igraph,graph_from_data_frame) 149 | importFrom(imager,HSVtoRGB) 150 | importFrom(imager,LabtosRGB) 151 | importFrom(imager,RGBtoHSV) 152 | importFrom(imager,add) 153 | importFrom(imager,as.cimg) 154 | importFrom(imager,as.pixset) 155 | importFrom(imager,blur_anisotropic) 156 | importFrom(imager,enorm) 157 | importFrom(imager,grayscale) 158 | importFrom(imager,imappend) 159 | importFrom(imager,imgradient) 160 | importFrom(imager,imlist) 161 | importFrom(imager,imsplit) 162 | importFrom(imager,imsub) 163 | importFrom(imager,imwarp) 164 | importFrom(imager,isoblur) 165 | importFrom(imager,magick2cimg) 166 | importFrom(imager,map_il) 167 | importFrom(imager,medianblur) 168 | importFrom(imager,nPix) 169 | importFrom(imager,sRGBtoLab) 170 | importFrom(imager,spectrum) 171 | importFrom(imager,split_connected) 172 | importFrom(imager,threshold) 173 | importFrom(jsonlite,read_json) 174 | importFrom(magick,geometry_area) 175 | importFrom(magick,geometry_size_pixels) 176 | importFrom(magick,image_annotate) 177 | importFrom(magick,image_append) 178 | importFrom(magick,image_border) 179 | importFrom(magick,image_composite) 180 | importFrom(magick,image_crop) 181 | importFrom(magick,image_info) 182 | importFrom(magick,image_read) 183 | importFrom(magick,image_scale) 184 | importFrom(magrittr,"%>%") 185 | importFrom(parallel,detectCores) 186 | importFrom(plotly,add_markers) 187 | importFrom(plotly,ggplotly) 188 | importFrom(plotly,layout) 189 | importFrom(plotly,plot_ly) 190 | importFrom(purrr,map) 191 | importFrom(purrr,map_dbl) 192 | importFrom(purrr,modify_at) 193 | importFrom(raster,coordinates) 194 | importFrom(raster,raster) 195 | importFrom(scales,rescale) 196 | importFrom(shiny,HTML) 197 | importFrom(shiny,actionButton) 198 | importFrom(shiny,checkboxInput) 199 | importFrom(shiny,column) 200 | importFrom(shiny,debounce) 201 | importFrom(shiny,eventReactive) 202 | importFrom(shiny,fluidPage) 203 | importFrom(shiny,fluidRow) 204 | importFrom(shiny,h4) 205 | importFrom(shiny,headerPanel) 206 | importFrom(shiny,hr) 207 | importFrom(shiny,mainPanel) 208 | importFrom(shiny,modalDialog) 209 | importFrom(shiny,numericInput) 210 | importFrom(shiny,observe) 211 | importFrom(shiny,observeEvent) 212 | importFrom(shiny,pageWithSidebar) 213 | importFrom(shiny,plotOutput) 214 | importFrom(shiny,radioButtons) 215 | importFrom(shiny,reactive) 216 | importFrom(shiny,reactiveValues) 217 | importFrom(shiny,renderPlot) 218 | importFrom(shiny,runApp) 219 | importFrom(shiny,selectInput) 220 | importFrom(shiny,showModal) 221 | importFrom(shiny,sidebarPanel) 222 | importFrom(shiny,sliderInput) 223 | importFrom(shiny,stopApp) 224 | importFrom(shiny,strong) 225 | importFrom(shiny,submitButton) 226 | importFrom(shiny,textInput) 227 | importFrom(shiny,withProgress) 228 | importFrom(shinyjs,reset) 229 | importFrom(shinyjs,useShinyjs) 230 | importFrom(stats,cor) 231 | importFrom(stats,dist) 232 | importFrom(stats,kmeans) 233 | importFrom(stats,median) 234 | importFrom(stats,na.omit) 235 | importFrom(stats,quantile) 236 | importFrom(stats,reorder) 237 | importFrom(stats,runif) 238 | importFrom(stats,setNames) 239 | importFrom(utils,packageVersion) 240 | importFrom(zeallot,"%<-%") 241 | -------------------------------------------------------------------------------- /R/2D_point_pattern.R: -------------------------------------------------------------------------------- 1 | 2 | #' Function used to generate a 2D set of points from an HE image 3 | #' 4 | #' The defualt segmentation uses the HE image as input and defines any pixel with an intensity value 5 | #' below a threshold to be a point. The number of points can be downsampeld to limit the maximum number. 6 | #' 7 | #' @param object Staffli object 8 | #' @param type Sets the image type to run segmentation on 9 | #' @param sample.index Integer value specifying the index of the sample to be analyzed 10 | #' @param limit Sets the intensity threshold in the interval [0, 1] 11 | #' @param maxnum Integer value specifying the maximum number of points 12 | #' @param edges Extracts the coordinates of the edges instead 13 | #' @param custom.edge.detector Custom function used to detect edges 14 | #' @importFrom imager grayscale 15 | 16 | scatter_HE <- function ( 17 | object, 18 | type = "masked.masks", 19 | sample.index = NULL, 20 | limit = 0.5, 21 | maxnum = 5e4, 22 | edges = FALSE, 23 | custom.edge.detector = NULL 24 | ){ 25 | sample.index <- sample.index %||% 1 26 | 27 | if (!type %in% rasterlists(object)) stop(paste0(type, " images not found in Staffli object"), call. = FALSE) 28 | 29 | if (edges) { 30 | bw.image <- get.edges(object, sample.index, type = type) 31 | xyset = which(bw.image > limit, arr.ind = TRUE) 32 | } else { 33 | if (is.null(custom.edge.detector)) { 34 | im <- as.cimg(object[type][[sample.index]]) 35 | bw.image <- im %>% as.cimg() %>% grayscale()#im[, , 1, 1] %>% as.cimg() 36 | if (type %in% c("processed.masks", "masked.masks")) { 37 | xyset = which(bw.image > limit*255, arr.ind = TRUE) 38 | } else { 39 | bw.image <- 255 - bw.image 40 | seg <- bw.image > 0.5*255 41 | xyset = which(seg, arr.ind = TRUE) 42 | } 43 | } else { 44 | im <- as.cimg(object[type][[sample.index]]) 45 | if (class(custom.edge.detector) != "function") stop("Provided custom edge detector is not a function") 46 | seg <- custom.edge.detector(im) 47 | if (!"pixset" %in% class(seg)) stop("Provided custom edge detector did not return a pixset object") 48 | xyset = which(seg, arr.ind = TRUE) 49 | } 50 | } 51 | set.seed(1) 52 | if (maxnum < nrow(xyset)) { 53 | xyset <- xyset[sample(1:nrow(xyset), size = maxnum, replace = FALSE), ] 54 | } 55 | xyset <- xyset[, 1:2] %>% as.data.frame() %>% setNames(nm = c("x", "y")) 56 | return(xyset) 57 | } 58 | 59 | 60 | #' Creates 2D point patterns for a set of images 61 | #' 62 | #' @param object Staffli object 63 | #' 64 | #' @inheritParams scatter_HE 65 | 66 | grid.from.staffli <- function ( 67 | object, 68 | type, 69 | limit = 0.3, 70 | maxnum = 1e3, 71 | edges = FALSE, 72 | custom.edge.detector = NULL 73 | ) { 74 | l <- setNames(lapply(1:length(names(object)), function(sample.index) { 75 | scatter <- scatter_HE(object = object, sample.index = sample.index, maxnum = maxnum, limit = limit, type = type, edges = edges, custom.edge.detector = custom.edge.detector) 76 | if (type %in% c("processed", "processed.masks")) { 77 | xy.names <- c("warped_x", "warped_y") 78 | } else { 79 | xy.names <- c("pixel_x", "pixel_y") 80 | } 81 | coords <- subset(object[[]], sample == sample.index)[, xy.names] 82 | dims.raw <- object@dims[[sample.index]][2:3] %>% as.numeric() 83 | dims.scaled <- scaled.imdims(object)[[sample.index]] 84 | sf.xy <- dims.raw[2]/dims.scaled[1] 85 | coords <- coords/sf.xy 86 | return(list(scatter = scatter, coords = coords)) 87 | }), nm = names(object)) 88 | } 89 | 90 | -------------------------------------------------------------------------------- /R/Image_resolution_switch.R: -------------------------------------------------------------------------------- 1 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | # Switch resolution 3 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | 5 | #' Function used to reload images in different quality and apply image transformations 6 | #' 7 | #' If you want to use histological images in your analyses the recommendation is to 8 | #' load them in low resolution (default 400 pixels width) and apply any transformations 9 | #' that you want, e.g. masking and alignment. Then, whenever you need to increase the 10 | #' resolution of your images you can use this function to reload higher resolution 11 | #' versions of the same images and apply the same transformations. 12 | #' 13 | #' Masking and alignment has been optimized for small images and will be significanlty slower 14 | #' for images of higher resolution. For this reson we recommend users to use this function 15 | #' instead. 16 | #' 17 | #' @param object Seurat object 18 | #' @param xdim Sets the pixel width for scaling, e.g. 400 (maximum allowed width is 2000 pixels) 19 | #' @param reference.index Set reference image used for image alignment. This should be the same the reference.index 20 | #' used for \code{\link{AlignImages}} or \code{\link{ManualAlignImages}}. 21 | #' @param verbose Print messages 22 | #' 23 | #' @importFrom magick image_read image_scale image_info 24 | #' @importFrom imager as.cimg magick2cimg imsub 25 | #' @importFrom grDevices as.raster 26 | #' 27 | #' @export 28 | #' 29 | #' @examples 30 | #' \dontrun{ 31 | #' # Create Seurat object, load, mask and align images at low resolution 32 | #' se <- InputFromTable(infoTable) %>% 33 | #' LoadImages() %>% 34 | #' MaskImages() %>% 35 | #' AlignImages() 36 | #' 37 | #' # Reload images and apply transformations to higher resolution images, e.g. 2000 pixels width 38 | #' se <- SwitchResolution(se, 2000) 39 | #' } 40 | #' 41 | 42 | SwitchResolution <- function ( 43 | object, 44 | xdim, 45 | reference.index = 1, 46 | verbose = FALSE 47 | ) { 48 | 49 | # Check if masked images are available 50 | if (!"masked" %in% rasterlists(object)) stop(paste0("Masked images are not present in Seurat object"), call. = FALSE) 51 | st.object <- GetStaffli(object) 52 | 53 | if (all(!c("masked", "processed") %in% rasterlists(st.object))) stop("No image transformations have been executed. Aborting ...", call. = FALSE) 54 | 55 | # Load images 56 | if (xdim > 2000) stop("Maximum size allowed is 2000px width. Set a lower number for xdim.", call. = FALSE) 57 | if (class(xdim) != "numeric") stop("xdim must be a numeric value.", call. = FALSE) 58 | old.xdim <- st.object@xdim 59 | st.object@xdim <- xdim 60 | high.res.images <- setNames(lapply(seq_along(names(st.object)), function(i) { 61 | x <- st.object@imgs[i] 62 | im <- image_read(path = x) 63 | 64 | # Check if image has been cropped 65 | ds <- st.object@dims[[i]] 66 | if ("cropped" %in% colnames(ds)) { 67 | if (ds$cropped) { 68 | crop.geom <- paste0(ds$max_x - ds$min_x, "x", ds$max_y - ds$min_y, "+", ds$min_x, "+", ds$min_y) 69 | im <- image_crop(im, geometry = crop.geom) 70 | } 71 | } 72 | 73 | im <- im %>% image_scale(paste0(xdim)) 74 | if (verbose) cat(paste0("Loaded section ", i, " image at ", paste0(image_info(im)$width), "x", image_info(im)$height), "resolution ... \n") 75 | 76 | as.raster(im) 77 | }), nm = names(st.object)) 78 | 79 | # Blow up masks 80 | masked.masks <- st.object["masked.masks"] 81 | masked.masks <- setNames(lapply(seq_along(masked.masks), function(n) { 82 | msk <- masked.masks[[n]] 83 | msk <- image_read(msk) %>% image_scale(paste0(xdim)) 84 | msk <- msk %>% as.raster() 85 | 86 | # Check if dimensions match 87 | im <- high.res.images[[n]] 88 | diff <- nrow(msk) - nrow(im) 89 | 90 | if (diff > 0) { 91 | for (i in 1:diff) { 92 | msk <- msk[-nrow(msk), ] 93 | } 94 | } else if (diff < 0) { 95 | for (j in 1:abs(diff)) { 96 | msk <- rbind(as.matrix(msk), rep("#000000ff", ncol(msk))) %>% as.raster() 97 | } 98 | } 99 | 100 | if (verbose) cat(paste0("Scaled section ", n, " image mask to ", paste0(ncol(msk)), "x", nrow(msk)), "resolution ... \n") 101 | return(msk) 102 | }), nm = names(st.object)) 103 | 104 | # Apply masks to higher resolution images 105 | masked <- setNames(lapply(seq_along(high.res.images), function(i) { 106 | im <- high.res.images[[i]] %>% as.cimg() 107 | msk <- masked.masks[[i]] %>% as.cimg() 108 | msked.im <- im*msk 109 | msked.im <- as.raster(msked.im) 110 | msked.im[msked.im == "#000000"] <- "#FFFFFF" 111 | if (verbose) cat(paste0("Finished masking section ", i, " image ... \n")) 112 | return(msked.im) 113 | }), nm = names(st.object)) 114 | 115 | # Transform images if processed images are available 116 | if ("processed" %in% rasterlists(st.object)) { 117 | transforms <- st.object@transformations 118 | processed.images <- masked 119 | processed.masks <- st.object["processed.masks"] 120 | mref <- processed.images[[reference.index]] 121 | for (i in seq_along(transforms)) { 122 | s <- unique(st.object@meta.data$sample)[i] 123 | # Obtain scale factors 124 | dims.raw <- as.numeric(st.object@dims[[i]][2:3]) 125 | dims.scaled <- dim(high.res.images[[i]]) 126 | sf.xy <- dims.raw[1]/dims.scaled[2] 127 | 128 | # Define warp functions 129 | m <- masked[[i]] %>% as.cimg() 130 | tr <- transforms[[i]] 131 | s <- xdim/old.xdim 132 | tr <- matrix(c(1, 1, 1, 1, 1, 1, s, s, 1), ncol = 3)*tr 133 | map.affine.backward <- generate.map.affine(tr) 134 | map.affine.forward <- generate.map.affine(tr, forward = TRUE) 135 | 136 | if (verbose) cat(paste0("Warping image for section ", i, " ... \n")) 137 | imat <- Warp(m, map.affine.backward) 138 | select_rows <- min(nrow(imat), nrow(mref)); select_cols <- min(ncol(imat), ncol(mref)) 139 | imat <- imat[1:select_rows, 1:select_cols] %>% as.cimg() 140 | 141 | if (verbose) cat(paste0("Scaling processed mask for section ", i, " image ... \n")) 142 | imat.msk <- image_read(processed.masks[[i]]) %>% image_scale(paste0(xdim)) %>% magick2cimg()*255 143 | 144 | diff <- ncol(imat.msk) - ncol(imat) 145 | 146 | if (diff > 0) { 147 | imat.msk <- imsub(imat.msk, y <= ncol(imat)) 148 | } else if (diff < 0) { 149 | imat.msk <- as.array(imat.msk) 150 | empty_msk <- array(dim = c(dim(imat.msk)[1], ncol(imat.msk) + abs(diff), dim(imat.msk)[3:4])) 151 | for (j in 1:dim(imat.msk)[4]) { 152 | empty_msk[, , 1, j] <- cbind(imat.msk[, , 1, j], matrix(rep(0, nrow(imat.msk)*abs(diff)), ncol = abs(diff))) 153 | } 154 | imat.msk <- as.cimg(empty_msk) 155 | } 156 | 157 | if (verbose) cat(paste0("Cleaning up background ... \n")) 158 | imat.masked <- imat*threshold(imat.msk, thr = 1) 159 | imat.masked <- imat.masked + (!threshold(imat.msk, thr = 1))*255 160 | imat.masked[imat.masked > 255] <- 255 161 | 162 | if (verbose) cat(paste0("Sample ", i, " image processing complete. \n\n")) 163 | processed.images[[i]] <- imat.masked %>% as.raster() 164 | processed.masks[[i]] <- imat.msk %>% as.raster() 165 | } 166 | st.object@rasterlists$processed <- processed.images 167 | st.object@rasterlists$processed.masks <- processed.masks 168 | } 169 | 170 | # Save values 171 | st.object@rasterlists$raw <- high.res.images 172 | st.object@rasterlists$masked <- masked 173 | st.object@rasterlists$masked.masks <- masked.masks 174 | 175 | object@tools$Staffli <- st.object 176 | 177 | return(object) 178 | } 179 | 180 | -------------------------------------------------------------------------------- /R/Mask_functions.R: -------------------------------------------------------------------------------- 1 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | # Mask Images 3 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | 5 | #' Masking function t 6 | #' 7 | #' This function takes an image of class \code{cimg} as input and returns 8 | #' an image of class \code{pixset}. The method is typically suitable for images 9 | #' with little background debris. Not suitable for 'Visium' images with fiducials. 10 | #' 11 | #' @param im An image of class \code{cimg} 12 | #' 13 | #' @importFrom imager imgradient enorm isoblur threshold as.cimg as.pixset 14 | #' 15 | #' @export 16 | #' 17 | 18 | EdgeMask <- function ( 19 | im 20 | ) { 21 | im <- im %>% imgradient("xy") %>% enorm() %>% isoblur(2) 22 | im <- im^0.1 23 | im <- threshold(im) 24 | im <- im[, , , 1] %>% as.cimg() %>% as.pixset() 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /R/QC.R: -------------------------------------------------------------------------------- 1 | #' @import Matrix 2 | "_PACKAGE" 3 | 4 | #' Quality metrics for spots 5 | #' 6 | #' @param exprMat expression matrix with spots in columns and genes in rows 7 | #' @param delim delimiter for expression matrix headers 8 | #' @return data.frame with x, y coordinates and quality metrics 9 | 10 | qcSpots <- function( 11 | exprMat, 12 | delim = "x" 13 | ) { 14 | qc.table <- GetCoords(colnames(exprMat), delim) 15 | qc.table <- cbind(qc.table, data.frame(nCount_RNA = colSums(exprMat), 16 | nFeature_RNA = apply(exprMat, 2, function(x) sum(x > 0)))) 17 | qc.table$nCount_per_nFeature_RNA <- qc.table$nCount_RNA/qc.table$nFeature_RNA 18 | return(qc.table) 19 | } 20 | 21 | 22 | #' Quality metrics for genes 23 | #' 24 | #' @param object expression matrix with spots in columns and genes in rows or Seurat object 25 | #' @param delim delimiter 26 | #' @param labels character vector with labels corresponding to dataset IDs in merged expression matrix [optional] 27 | #' @return data.frame with gene names and quality metrics 28 | 29 | qcGenes <- function( 30 | object, 31 | delim = "x", 32 | labels = NULL 33 | ) { 34 | stopifnot(class(object) %in% c("matrix", "data.frame", "Seurat")) 35 | 36 | if (class(object) == "Seurat") { 37 | coords <- GetCoords(colnames(object), delim) 38 | exprMat <- GetAssayData(object = object, slot = 'counts') 39 | exprMat <- exprMat[rownames(object), colnames(object)] 40 | } else { 41 | coords <- GetCoords(colnames(object), delim) 42 | exprMat <- object 43 | } 44 | 45 | qc.table <- data.frame(gene = rownames(object)) 46 | if ("sample" %in% colnames(coords)) { 47 | samples <- unique(coords$sample) 48 | for (i in seq_along(samples)) { 49 | qc.table[, ifelse(!is.null(labels), labels[i], samples[i])] <- rowSums(exprMat[, coords$sample == samples[i]]) 50 | } 51 | } else { 52 | qc.table[, "count"] <- rowSums(exprMat) 53 | } 54 | return(qc.table) 55 | } 56 | 57 | 58 | #' Quality metrics for samples 59 | #' 60 | #' @param object expression matrix with spots in columns and genes in rows or Seurat object 61 | #' @param delim delimiter 62 | #' @param labels character vector with labels corresponding to dataset IDs in merged expression matrix [optional] 63 | #' 64 | #' @importFrom magrittr %>% 65 | #' @importFrom dplyr summarize group_by 66 | #' 67 | #' @return data.frame with quality metrics per sample 68 | 69 | qcSamples <- function( 70 | object, 71 | delim = "x", 72 | labels = NULL 73 | ) { 74 | stopifnot(class(object) %in% c("matrix", "data.frame", "Seurat")) 75 | 76 | if (class(object) == "Seurat") { 77 | exprMat <- GetAssayData(object = object, slot = 'counts') 78 | exprMat <- exprMat[rownames(object), colnames(object)] 79 | } else { 80 | exprMat <- object 81 | } 82 | 83 | qc.table <- qcSpots(exprMat, delim) 84 | summarize_fkn <- function(grouped_df) { 85 | grouped_df %>% summarize(avg.nCount_RNA = round(mean(nCount_RNA), digits = 2), 86 | max.nCount_RNA = max(nCount_RNA), 87 | min.nCount_RNA = min(nCount_RNA), 88 | avg.nFeature_RNA = round(mean(nFeature_RNA), digits = 2), 89 | max.nFeature_RNA = max(nFeature_RNA), 90 | min.nFeature_RNA = min(nFeature_RNA)) %>% as.data.frame() 91 | } 92 | if ("sample" %in% colnames(qc.table)) { 93 | qc.table <- qc.table %>% 94 | group_by(sample) %>% 95 | summarize_fkn 96 | } else { 97 | qc.table <- qc.table %>% 98 | summarize_fkn 99 | } 100 | return(qc.table) 101 | } 102 | 103 | #' function(x, y, ...) used to plot the contents of each panel of the display in pairs function 104 | #' 105 | #' @param x x coordinate 106 | #' @param y y coordinate 107 | #' 108 | #' @importFrom grDevices densCols 109 | #' 110 | #' @return panel for pairs function 111 | #' @keywords internal 112 | 113 | qc.scatter <- function(x,y){ 114 | dns <- densCols(x,y); 115 | points(x,y, col=dns, pch=".", panel.first=grid()); 116 | abline(a=0, b=1, col="brown") 117 | } 118 | 119 | 120 | -------------------------------------------------------------------------------- /R/RegionNeighbours.R: -------------------------------------------------------------------------------- 1 | #' Autodetect region neighbours 2 | #' 3 | #' This function allows you to automatically identify neighbours of a selected region. 4 | #' 5 | #' One way of using method this is to find spots surrounding a certain cluster. First, you need to make sure 6 | #' the identity of the Seurat object is set to the meta.data column that you want to use, so for example 7 | #' `se <- SetIdent(se, value = "seurat_clusters")` if you want to use the default seurat clusters. 8 | #' Then you select the label that defined the region of interest using the `id` parameter, so for example 9 | #' `ìd = "1"` will use cluster 1 as the region. If you set the `keep.idents` parameter to TRUE, the cluster ids 10 | #' of the neighbouring spots will be kept in the result, otherwise they will be returned as one single goup. 11 | #' You can also activate the `keep.within.id` parameter to include all spots of the selected region in the output, 12 | #' otherwise only the spots along the region border will be kept. 13 | #' 14 | #' @param object Seurat object. 15 | #' @param id Group label used to define region, e.g. a cluster id. The region will be selected using the 16 | #' active identity (see `Idents`). 17 | #' @param column.key Sets the name of the column in the meta.data slot where the output is stored. [default: 'nbs_'] 18 | #' @param keep.idents If set to TRUE, the identities of the neighbours are kept in the output, otherwise all 19 | #' neighbours will be named 'nbs_id' where id is the group label defined by the aprameter `ìd` [default: FALSE] 20 | #' @param keep.within.id If set to TRUE, all id spots are kept, otherwise only the spots with outside neighbours are kept 21 | #' @param verbose Print messages 22 | #' 23 | #' @importFrom Seurat Idents 24 | #' 25 | #' @export 26 | #' 27 | #' @examples 28 | #' \dontrun{ 29 | #' # Cluster data, find neighbours to cluster 10 and then plot the results 30 | #' se <- FindNeighbours(se) %>% FindClusters() 31 | #' se <- RegionNeighbours(se, id = 10) 32 | #' ST.FeaturePlot(se, features = "nbs_10") 33 | #' 34 | #' # Find neighbours to cluster 10 and keep all id spots 35 | #' se <- RegionNeighbours(se, id = 10) 36 | #' ST.FeaturePlot(se, features = "nbs_10", keep.within.id = TRUE) 37 | #' } 38 | #' 39 | RegionNeighbours <- function ( 40 | object, 41 | id, 42 | column.key = "nbs_", 43 | keep.idents = FALSE, 44 | keep.within.id = FALSE, 45 | verbose = FALSE 46 | ) { 47 | 48 | if (verbose) cat("Creating Connected Netork using KNN ... \n") 49 | spatnet <- GetSpatNet(object) 50 | spatnet <- do.call(rbind, lapply(seq_along(spatnet), function(i) { 51 | spnet <- spatnet[[i]] 52 | spnet$sample <- paste0(i) 53 | return(spnet) 54 | })) 55 | 56 | spatnet$label_from <- Idents(object)[spatnet$from] %>% as.character() 57 | spatnet$label_to <- Idents(object)[spatnet$to] %>% as.character() 58 | spatnet <- subset(spatnet, label_from == paste0(id)) 59 | if (verbose) cat(paste0("Found ", nrow(spatnet), " neighbours for id ", id, " ... \n")) 60 | 61 | if (!keep.within.id) { 62 | if (verbose) cat("Excluding neighbours from the same group ... \n") 63 | spatnet <- subset(spatnet, label_from != label_to) 64 | if (verbose) cat(paste0(nrow(spatnet), " neighbours left ... \n")) 65 | } 66 | 67 | column.key <- paste0(column.key, id) 68 | column.value <- setNames(rep(NA, ncol(object)), nm = colnames(object)) 69 | column.value[unique(union(spatnet$from, spatnet$to))] <- Idents(object)[unique(union(spatnet$from, spatnet$to))] %>% as.character() 70 | if (keep.idents) { 71 | if (verbose) cat("Naming neighbours to id_nb_to* ... \n") 72 | column.value[column.value != paste0(id) & !is.na(column.value)] <- paste0(column.value[column.value != paste0(id) & !is.na(column.value)], "_nb_to_", id) 73 | } else { 74 | if (verbose) cat(paste0("Naming all neighbours ", paste0("nbs_", id), " ... \n")) 75 | column.value[column.value != paste0(id) & !is.na(column.value)] <- paste0("nbs_", id) 76 | } 77 | 78 | if (verbose) cat(paste0("Saving neighbour ids to column '", column.key, "' ... \n")) 79 | object@meta.data[, column.key] <- column.value 80 | if (verbose) cat(paste0("Finished. \n\n")) 81 | return(object) 82 | } 83 | -------------------------------------------------------------------------------- /R/crop_utilities.R: -------------------------------------------------------------------------------- 1 | #' Get crop geometries 2 | #' 3 | #' This function can be used to define "crop windows" based on sets 4 | #' of target spots. 5 | #' 6 | #' @param object A Seurat object created with STutility 7 | #' @param group.by A meta.data column to group the spots by. Only character 8 | #' vector or factors are allowed. Selects "labels" by default. 9 | #' @param groups.to.keep Provide a caharcter vector of groups to keep. 10 | #' @param symmetric Make crop window square. This will mkae it easier to align images in dowstream processing steps. 11 | #' @param keep.all.spots Keep all spots within selected crop windows and not just the spots 12 | #' belonging to the predefined groups. All spots that are present in multiple crop windows will be removed. 13 | #' @param xy_padding Increase the crop area in all directions. Given in pixels. 14 | #' @return A list of "crop geometries" to be used with \code{\link{CropImages}}) 15 | #' 16 | #' @export 17 | 18 | GetCropWindows <- function ( 19 | object, 20 | group.by = NULL, 21 | groups.to.keep = NULL, 22 | symmetric = TRUE, 23 | keep.all.spots = FALSE, 24 | xy_padding = 50 25 | ) { 26 | 27 | # Check to see if Staffli object is present 28 | .check_seurat_object(object) 29 | st.object <- object@tools$Staffli 30 | 31 | # Check group.by 32 | group.by <- group.by %||% "labels" 33 | group.by.keep <- group.by 34 | if (!group.by %in% colnames(object@meta.data)) stop("group.by is not available in the Seurat object meta.data slot. ", call. = FALSE) 35 | group.by <- object@meta.data[, group.by] 36 | if (!class(group.by) %in% c("character", "factor")) stop(paste0("Invalid group.by column of class ", class(group.by)), call. = FALSE) 37 | group.by <- as.character(group.by) 38 | #if (length(unique(group.by)) == 1) stop("Only one group provided.") 39 | 40 | coords <- data.frame(st.object@meta.data[, c("pixel_x", "pixel_y")], Var = group.by, section = st.object@meta.data$sample) 41 | 42 | # Reduce groups 43 | if (!is.null(groups.to.keep)) { 44 | coords <- subset(coords, Var %in% groups.to.keep) 45 | } 46 | 47 | # Get groups 48 | if (!is.null(groups.to.keep)) { 49 | grps <- groups.to.keep 50 | } else { 51 | if (is.null(group.by)) { 52 | grps <- setdiff(unique(coords$Var), "Default") 53 | } else { 54 | grps <- unique(coords$Var) 55 | } 56 | } 57 | 58 | crop.geoms.all.sections <- Reduce(c, lapply(unique(coords$section), function(sid) { 59 | coords.subset <- subset(coords, section %in% sid) 60 | crop.geoms <- lapply(grps, function(grp) { 61 | coords.subset.grp <- subset(coords.subset, Var %in% grp) 62 | if (nrow(coords.subset.grp) == 0) return(NULL) 63 | minxy <- apply(coords.subset.grp[, c("pixel_x", "pixel_y")], 2, range) 64 | minxy[1, ] <- minxy[1, ] - xy_padding 65 | minxy[2, ] <- minxy[2, ] + xy_padding 66 | minxy <- round(minxy) 67 | wh <- apply(minxy, 2, diff) 68 | if (symmetric) { 69 | wh <- rep(max(wh), 2) 70 | mid.points <- apply(minxy, 2, mean) 71 | minxy <- matrix(c(mid.points[1] - max(wh)/2, 72 | mid.points[1] + max(wh)/2, 73 | mid.points[2] - max(wh)/2, 74 | mid.points[2] + max(wh)/2), ncol = 2) 75 | geom <- setNames(data.frame(paste0(wh[1], "x", wh[2], "+", minxy[1, 1], "+", minxy[1, 2]), grp, group.by.keep, keep.all.spots), nm = c("geom", "group", "group.by", "all.spots")) 76 | } else { 77 | geom <- setNames(data.frame(paste0(wh[1], "x", wh[2], "+", minxy[1, 1], "+", minxy[1, 2]), grp, group.by.keep, keep.all.spots), nm = c("geom", "group", "group.by", "all.spots")) 78 | } 79 | }) 80 | crop.geoms <- crop.geoms[!sapply(crop.geoms, is.null)] 81 | names(crop.geoms) <- rep(sid, length(crop.geoms)) 82 | return(crop.geoms) 83 | })) 84 | 85 | return(crop.geoms.all.sections) 86 | 87 | } 88 | -------------------------------------------------------------------------------- /R/facet_grid_SC.R: -------------------------------------------------------------------------------- 1 | #' Function used to override scales in facets of a ggplot object 2 | #' 3 | #' @param which Index of facet 4 | #' @param scale Object of class "Scale" used to override (e.g. \code{scale_x_continuous()}) 5 | 6 | scale_override <- function ( 7 | which, 8 | scale 9 | ) { 10 | if(!is.numeric(which) || (length(which) != 1) || (which %% 1 != 0)) { 11 | stop("which must be an integer of length 1") 12 | } 13 | 14 | if(is.null(scale$aesthetics) || !any(c("x", "y") %in% scale$aesthetics)) { 15 | stop("scale must be an x or y position scale") 16 | } 17 | 18 | structure(list(which = which, scale = scale), class = "scale_override") 19 | } 20 | 21 | #' Custom ggproto object for facet wrap 22 | #' 23 | #' @importFrom ggplot2 ggproto ggproto_parent 24 | 25 | CustomFacetWrap <- ggproto ( 26 | "CustomFacetWrap", FacetWrap, 27 | init_scales = function(self, layout, x_scale = NULL, y_scale = NULL, params) { 28 | # make the initial x, y scales list 29 | scales <- ggproto_parent(FacetWrap, self)$init_scales(layout, x_scale, y_scale, params) 30 | 31 | if(is.null(params$scale_overrides)) return(scales) 32 | 33 | max_scale_x <- length(scales$x) 34 | max_scale_y <- length(scales$y) 35 | 36 | # ... do some modification of the scales$x and scales$y here based on params$scale_overrides 37 | for(scale_override in params$scale_overrides) { 38 | which <- scale_override$which 39 | scale <- scale_override$scale 40 | 41 | if("x" %in% scale$aesthetics) { 42 | if(!is.null(scales$x)) { 43 | if(which < 0 || which > max_scale_x) stop("Invalid index of x scale: ", which) 44 | scales$x[[which]] <- scale$clone() 45 | } 46 | } else if("y" %in% scale$aesthetics) { 47 | if(!is.null(scales$y)) { 48 | if(which < 0 || which > max_scale_y) stop("Invalid index of y scale: ", which) 49 | scales$y[[which]] <- scale$clone() 50 | } 51 | } else { 52 | stop("Invalid scale") 53 | } 54 | } 55 | 56 | # return scales 57 | scales 58 | } 59 | ) 60 | 61 | #' Custom facet wrap function 62 | #' 63 | #' @param ... Parameters which can be passed to \code{facet_wrap} 64 | #' @param scale_overrides List of "scale_override" objects 65 | #' 66 | #' @importFrom ggplot2 facet_wrap ggproto 67 | 68 | facet_wrap_custom <- function ( 69 | ..., 70 | scale_overrides = NULL 71 | ) { 72 | # take advantage of the sanitizing that happens in facet_wrap 73 | facet_super <- facet_wrap(...) 74 | 75 | # sanitize scale overrides 76 | if(inherits(scale_overrides, "scale_override")) { 77 | scale_overrides <- list(scale_overrides) 78 | } else if(!is.list(scale_overrides) || 79 | !all(vapply(scale_overrides, inherits, "scale_override", FUN.VALUE = logical(1)))) { 80 | stop("scale_overrides must be a scale_override object or a list of scale_override objects") 81 | } 82 | 83 | facet_super$params$scale_overrides <- scale_overrides 84 | 85 | ggproto(NULL, CustomFacetWrap, 86 | shrink = facet_super$shrink, 87 | params = facet_super$params 88 | ) 89 | } 90 | -------------------------------------------------------------------------------- /R/pre_processing.R: -------------------------------------------------------------------------------- 1 | #' @import Matrix 2 | "_PACKAGE" 3 | 4 | #' load count files 5 | #' 6 | #' @param path Path to count files 7 | #' @param delim Delimiter used in gene count matrix file 8 | #' @param row.names set column as row.names 9 | #' @param visium Load 10x visium output files 10 | #' 11 | #' @importFrom data.table fread 12 | #' 13 | #' @keywords internal 14 | 15 | st.load.matrix = function ( 16 | path, 17 | delim = "\t", 18 | row.names = 1, 19 | visium = F 20 | ) { 21 | stopifnot(file.exists(path)) 22 | x = c() 23 | if(visium == F){ #Original ST loading 24 | tmp = suppressWarnings({try({x = data.frame(fread(input = path, integer64 = "character", sep = delim), row.names = row.names, check.names = FALSE)})}) 25 | } else { #10X Visium loading 26 | suff <- getExtension(path) 27 | if (dir.exists(path) & suff == basename(path)) { 28 | tmp = try({x = Seurat::Read10X(data.dir = path)}) 29 | } else { 30 | tmp = try({x = Seurat::Read10X_h5(filename = path)}) 31 | } 32 | } 33 | if(inherits(tmp, 'try-error')) { 34 | stop("Failed to read data.") 35 | } else { 36 | return(as(as.matrix(x), "dgCMatrix")) 37 | } 38 | } 39 | 40 | #' Merge expression matrices 41 | #' 42 | #' @description This function takes a list of expression matrices as input with ST spots in columns 43 | #' and genes in rows. All expression matrices will be merged into one matrix where all genes that are 44 | #' present in any of the expression matrices will be included. If a there are no counts available for 45 | #' a gene in one or more of the expression matrices, the counts for that gene will be set to 0 in those 46 | #' expression matrices. By default, a unique number will be prefixed to the headers of each expression 47 | #' matrix. 48 | #' @param exp.list list of expression matrices 49 | #' @param delim delimiter used to separate coordinates in expression matrix headers 50 | #' @param labels labels to use as suffix for the headers of each expression matrix 51 | #' @param sparse.matrix.fmt return mergedexpression matrix in dgCMatrix format to save memory 52 | #' 53 | #' @return merged expression matrix 54 | 55 | Merger <- function( 56 | exp.list, 57 | delim = "x", 58 | labels = NULL, 59 | sparse.matrix.fmt = F 60 | ) { 61 | 62 | # Check labels 63 | if (!is.null(labels)) { 64 | stopifnot(length(labels) == length(ls) & class(labels) == "character") 65 | } 66 | 67 | # List all genes 68 | genes <- Reduce(union, lapply(exp.list, rownames)) 69 | 70 | matrix.list <- lapply(seq_along(exp.list), function(i) { 71 | count <- exp.list[[i]] 72 | nspots <- ncol(count) 73 | curgenes <- rownames(count) 74 | m <- matrix(0, nrow=length(genes), ncol=nspots) 75 | rownames(m) <- genes 76 | m[curgenes,] <- count 77 | colnames(m) <- paste(ifelse(!is.null(labels), labels[i], i), colnames(count), sep = delim) 78 | 79 | # Save in sparse format? 80 | if (sparse.matrix.fmt) { 81 | m <- as(m, "dgCMatrix") 82 | } 83 | return(m) 84 | }) 85 | return(do.call(cbind, matrix.list)) 86 | } 87 | 88 | #' Obtain file extension 89 | #' 90 | #' @param file Path to file 91 | #' 92 | getExtension <- function ( 93 | file 94 | ){ 95 | ex <- strsplit(basename(file), split = "\\.")[[1]] 96 | if (ex[length(ex)] == "gz") suff <- paste(ex[length(ex) - 1], ex[length(ex)], sep = ".") else suff <- ex[length(ex)] 97 | return(suff) 98 | } 99 | -------------------------------------------------------------------------------- /R/utilities.R: -------------------------------------------------------------------------------- 1 | #' Extract table of x, y coordinates from ST count matrix headers 2 | #' 3 | #' @param spotnames x, y coordinates separated by delimiter (default "x") 4 | #' @param delim delimiter 5 | #' @return data.frame with x, y coordinates and optionally a sample column 6 | #' @export 7 | 8 | GetCoords <- function( 9 | spotnames, 10 | delim = "x" 11 | ) { 12 | stopifnot(class(spotnames) == "character") 13 | if (sum(duplicated(spotnames)) > 0) { 14 | stop("Duplicate names are not allowed ...") 15 | } 16 | coords <- do.call(rbind, strsplit(spotnames, split = delim)) 17 | if (ncol(coords) == 3) { 18 | coords <- setNames(data.frame(coords, stringsAsFactors = F), nm = c("x", "y", "sample")) 19 | } else if (ncol(coords) == 2) { 20 | coords <- setNames(data.frame(coords, stringsAsFactors = F), nm = c("x", "y")) 21 | } else { 22 | stop("Invalid spotnames ...") 23 | } 24 | coords$x <- as.numeric(coords$x) 25 | coords$y <- as.numeric(coords$y) 26 | rownames(coords) <- spotnames 27 | return(coords) 28 | } 29 | 30 | 31 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | # Internal 33 | #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | 35 | # Set a default value if an object is null 36 | # 37 | # @param lhs An object to set if it's null 38 | # @param rhs The value to provide if x is null 39 | # 40 | # @return rhs if lhs is null, else lhs 41 | # 42 | # @author Hadley Wickham 43 | # @references https://adv-r.hadley.nz/functions.html#missing-arguments 44 | # 45 | `%||%` <- function(lhs, rhs) { 46 | if (!is.null(x = lhs)) { 47 | return(lhs) 48 | } else { 49 | return(rhs) 50 | } 51 | } 52 | 53 | 54 | #' Get the names of objects within a Seurat object that are of a certain class 55 | #' 56 | #' @param object A Seurat object 57 | #' @param classes.keep A vector of names of classes to get 58 | #' 59 | #' @return A vector with the names of objects within the Seurat object that are of class \code{classes.keep} 60 | 61 | FilterObjects <- function(object, classes.keep = c('Assay', 'DimReduc')) { 62 | slots <- na.omit(object = Filter( 63 | f = function(x) { 64 | return(class(x = slot(object = object, name = x)) == 'list') 65 | }, 66 | x = slotNames(x = object) 67 | )) 68 | slots <- grep(pattern = 'tools', x = slots, value = TRUE, invert = TRUE) 69 | slots <- grep(pattern = 'misc', x = slots, value = TRUE, invert = TRUE) 70 | slots.objects <- unlist( 71 | x = lapply( 72 | X = slots, 73 | FUN = function(x) { 74 | return(names(x = slot(object = object, name = x))) 75 | } 76 | ), 77 | use.names = FALSE 78 | ) 79 | object.classes <- sapply( 80 | X = slots.objects, 81 | FUN = function(i) { 82 | return(class(x = object[[i]])) 83 | } 84 | ) 85 | object.classes <- object.classes[object.classes %in% classes.keep] 86 | return(names(x = object.classes)) 87 | } 88 | 89 | #' Palette selection 90 | #' 91 | #' @param palette Palette choice for plotting spatial expression histology heatmap 92 | #' @keywords internal 93 | #' 94 | #' @export 95 | #' 96 | 97 | palette.select <- function(palette, info = F) { 98 | if (!requireNamespace("RColorBrewer")) install.packages("RColorBrewer") 99 | if (!requireNamespace("viridis")) install.packages("viridis") 100 | palettes <- list( 101 | Reds = RColorBrewer::brewer.pal(n = 9, name = "Reds"), 102 | LgBu = c("grey", "lightblue", "blue"), 103 | GnRd = c("green", "black", "red"), 104 | BuRd = c("blue", "black", "red"), 105 | GrRd = c("lightgray", "mistyrose", "red", "dark red"), 106 | magma = viridis::magma(9), 107 | GnBu = rev(RColorBrewer::brewer.pal(9,"GnBu")), 108 | the.cols = c(rgb(255,255,217, maxColorValue=255), 109 | rgb(65,182,196, maxColorValue=255), 110 | rgb(8, 29, 88, maxColorValue=255)), 111 | offwhite.to.black = c(rgb(220,220,220, maxColorValue=255), 112 | rgb(0, 0, 0, maxColorValue=255)), 113 | viridis = viridis::viridis(9), 114 | cividis = viridis::cividis(9), 115 | plasma = viridis::plasma(9), 116 | heat = c("dark blue", "cyan", "yellow", "red"), 117 | Spectral = rev(RColorBrewer::brewer.pal(11,"Spectral")), 118 | RdBu = rev(RColorBrewer::brewer.pal(11,"RdBu")), 119 | MaYl = c("#FF00FF", "black", "#FFFF00"), 120 | RdYlBu = rev(RColorBrewer::brewer.pal(n = 11, name = "RdYlBu")) 121 | ) 122 | if (info) { 123 | return(data.frame(palette = names(palettes), category = c("seq", "seq", "seq", "seq", "seq", "seq", "seq", "seq", "seq", "seq", "seq", "seq", "div", "div", "div", "div", "div"), 124 | stringsAsFactors = F)) 125 | } 126 | if (!palette %in% names(palettes)) { 127 | stop("Invalid palette name: ", palette, call. = FALSE) 128 | } 129 | return(palettes[[palette]]) 130 | } 131 | 132 | #' Convert gene names 133 | #' 134 | #' @param exprMat expression matrix 135 | #' @param annotation data.frame with one id.column containing the current gene ids and a matching replace 136 | #' column containing the new gene ids 137 | #' @param id.column character vector of unique gene ids of the same type as in the Seurat object 138 | #' @param replace.column character vector of unique gene ids to replace the old ids 139 | #' 140 | #' @return A Seurat object with covnerted gene ids 141 | #' @export 142 | ConvertGeneNames <- function ( 143 | exprMat, 144 | annotation, 145 | id.column, 146 | replace.column 147 | ) { 148 | 149 | if (!id.column %in% colnames(annotation) | !replace.column %in% colnames(annotation)) stop(paste0(id.column, " and ", replace.column, " must be present in the annotation table"), call. = F) 150 | if (sum(duplicated(annotation[, id.column])) > 0 | sum(duplicated(annotation[, id.column])) > 0) stop("Duplicated ids are not allowed", call. = F) 151 | 152 | rownames(annotation) <- annotation[, id.column] 153 | rownames(exprMat) <- annotation[rownames(exprMat), ]$gene_name 154 | return(exprMat) 155 | } 156 | 157 | 158 | #' Check if a Seurat object has been processed with STutility 159 | #' 160 | #' @param object A Seurat object 161 | #' @param message An error message 162 | #' 163 | .check_seurat_object <- function ( 164 | object, 165 | message = "This Seurat object does not appear to have been processed with STutility." 166 | ) { 167 | if (!"Staffli" %in% names(object@tools)) stop("This Seurat object does not appear to have been processed with STutility.") 168 | } 169 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STUtility 2 | 3 | ## STUtility becomes `semla` 4 | 5 | STUtility will no longer be maintained and instead you can use our new R package 6 | `semla` which is available at https://github.com/ludvigla/semla. 7 | 8 | ## Installation 9 | 10 | To install STUtility from github (currently only option), you need to have devtools installed: 11 | 12 | ``` 13 | install.packages("remotes") 14 | ``` 15 | 16 | Finally, install STUtility: 17 | 18 | ``` 19 | remotes::install_github( 20 | "jbergenstrahle/STUtility" 21 | ) 22 | ``` 23 | 24 | ### Install STUtility in an anaconda environment (Mac OS) 25 | 26 | From the terminal 27 | 28 | ``` 29 | conda create -n R4.0 30 | conda activate R4.0 31 | conda install -c conda-forge r-essentials r-base r-devtools r-spdep r-hdf5r 32 | conda install -c bioconda r-fftwtools 33 | ``` 34 | 35 | From R 36 | 37 | ``` 38 | devtools::install_github( 39 | "jbergenstrahle/STUtility" 40 | ) 41 | ``` 42 | 43 | ## How to use the package 44 | 45 | Please see https://ludvigla.github.io/STUtility_web_site/ for online documentation and tutorials in how to use the package 46 | -------------------------------------------------------------------------------- /STutility.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citEntry(entry = "article", 2 | title = "Seamless integration of image and molecular analysis for spatial transcriptomics workflows", 3 | author = personList( as.person("Joseph Bergenstråhle"), 4 | as.person("Ludvig Larsson")), 5 | year = 2020, 6 | journal = "BMC Genomics", 7 | url = "https://github.com/jbergenstrahle/STUtility", 8 | textVersion = paste("Joseph Bergenstråhle and Ludvig Larsson et al (2020):", 9 | "Seamless integration of image and molecular analysis for spatial transcriptomics workflows.", 10 | "BMC Genomics")) 11 | -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo1.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo1.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo1.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo2.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo2.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo2.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo3.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo3.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo3.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo4.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo4.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo4.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo5.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo5.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo5.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo6.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo6.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo6.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo7.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo7.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo7.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo8.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/Hippo8.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/Hippo8.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/MOB1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/MOB1.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/MOB2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/MOB2.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/MOB3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/MOB3.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/MOB4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/MOB4.jpg -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo1.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo1.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo2.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo2.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo3.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo3.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo4.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo4.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo5.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo5.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo6.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo6.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo7.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo7.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/counts/alignment_table_Hippo8.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/counts/alignment_table_Hippo8.tsv.gz -------------------------------------------------------------------------------- /inst/extdata/metaData.csv: -------------------------------------------------------------------------------- 1 | samples;type;z;individual;spotfiles;imgs 2 | /Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB1.tsv;Mouse;100;1;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/alignment_table_MOB1.tsv;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB1.jpg 3 | /Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB2.tsv;Mouse;120;1;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/alignment_table_MOB2.tsv;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB2.jpg 4 | /Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB3.tsv;Mouse;130;2;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/alignment_table_MOB3.tsv;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB3.jpg 5 | /Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB4.tsv;Mouse;140;2;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/alignment_table_MOB4.tsv;/Users/ludviglarsson/anaconda2/envs/R36/lib/R/library/STutility/extdata/counts/MOB4.jpg 6 | -------------------------------------------------------------------------------- /inst/extdata/metaData_mmBrain.csv: -------------------------------------------------------------------------------- 1 | samples;type;spotfiles;imgs 2 | ~/STUtility/inst/extdata/counts/Hippo1.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo1.tsv.gz;~/STUtility/inst/extdata/counts/Hippo1.jpg 3 | ~/STUtility/inst/extdata/counts/Hippo2.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo2.tsv.gz;~/STUtility/inst/extdata/counts/Hippo2.jpg 4 | ~/STUtility/inst/extdata/counts/Hippo3.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo3.tsv.gz;~/STUtility/inst/extdata/counts/Hippo3.jpg 5 | ~/STUtility/inst/extdata/counts/Hippo4.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo4.tsv.gz;~/STUtility/inst/extdata/counts/Hippo4.jpg 6 | ~/STUtility/inst/extdata/counts/Hippo5.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo5.tsv.gz;~/STUtility/inst/extdata/counts/Hippo5.jpg 7 | ~/STUtility/inst/extdata/counts/Hippo6.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo6.tsv.gz;~/STUtility/inst/extdata/counts/Hippo6.jpg 8 | ~/STUtility/inst/extdata/counts/Hippo7.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo7.tsv.gz;~/STUtility/inst/extdata/counts/Hippo7.jpg 9 | ~/STUtility/inst/extdata/counts/Hippo8.tsv.gz;Mouse;~/STUtility/inst/extdata/counts/alignment_table_Hippo8.tsv.gz;~/STUtility/inst/extdata/counts/Hippo8.jpg 10 | -------------------------------------------------------------------------------- /inst/extdata/mouse_genes.tsv.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbergenstrahle/STUtility/9a8f421499e58b13340ee386db07b0eba923c88c/inst/extdata/mouse_genes.tsv.gz -------------------------------------------------------------------------------- /man/AlignImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/image_processing.R 3 | \name{AlignImages} 4 | \alias{AlignImages} 5 | \alias{AlignImages.Staffli} 6 | \alias{AlignImages.Seurat} 7 | \title{Automatic alignment of HE stained tissue images} 8 | \usage{ 9 | AlignImages( 10 | object, 11 | indices = NULL, 12 | reference.index = NULL, 13 | use.masked = FALSE, 14 | verbose = FALSE 15 | ) 16 | 17 | \method{AlignImages}{Staffli}( 18 | object, 19 | indices = NULL, 20 | reference.index = NULL, 21 | use.masked = FALSE, 22 | verbose = FALSE 23 | ) 24 | 25 | \method{AlignImages}{Seurat}( 26 | object, 27 | indices = NULL, 28 | reference.index = NULL, 29 | use.masked = FALSE, 30 | verbose = FALSE 31 | ) 32 | } 33 | \arguments{ 34 | \item{object}{A Seurat object} 35 | 36 | \item{indices}{Integer: sample indices of images to align with reference} 37 | 38 | \item{reference.index}{Integer: sample index of referece image} 39 | 40 | \item{use.masked}{Setting this to TRUE will ignore any "processed" images available in the object and 41 | apply the alignment from scratch.} 42 | 43 | \item{verbose}{Print messages} 44 | } 45 | \value{ 46 | A Staffli object 47 | 48 | A Seurat object 49 | } 50 | \description{ 51 | Image alignment or image registration consists in finding a rigid tranformation 52 | function that remaps pixels between two images so that two images are aligned. 53 | AlignImages allows you to align all images to a reference (any image present in the Seurat object) 54 | which simplifies the interpretation of spatial heatmaps and can be useful for creating 3D 55 | models. The transformation function is learned using the ICP (Iterative Closest Point) on two point 56 | sets which defines the edges of the tissues in the HE images. Note that this alignment works best 57 | for tissue sections that are intact, i.e. not cropped or folded. Also, because the method only used 58 | the edges of the tissue for alignment, you might end up with strange results if the tissue 59 | shape is symmetrical. 60 | } 61 | \examples{ 62 | \dontrun{ 63 | # Create a new Staffli object, mask, align and plot images 64 | st.obj <- CreateStaffliObject(imgs, meta.data) 65 | st.obj <- LoadImages(st.obj, verbose = TRUE) \%>\% MaskImages() \%>\% AlignImages() 66 | plot(st.obj) 67 | } 68 | \dontrun{ 69 | # Load, mask, align and plot images 70 | se <- LoadImages(se, verbose = TRUE) \%>\% MaskImages() \%>\% AlignImages() 71 | ImagePlot(se) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /man/ColorBlender.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{ColorBlender} 4 | \alias{ColorBlender} 5 | \title{Squeeze 2 or 3 column feature data into the unit cube and converts into RGB space} 6 | \usage{ 7 | ColorBlender(data, channels.use = NULL) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame containing feature values and coordinates} 11 | 12 | \item{channels.use}{Select channels to use for blending. Default is red, green and blue but the order can be shuffled. 13 | For 2 features, the default is red and green. (options: "red", "green" and "blue")} 14 | } 15 | \description{ 16 | Squeeze 2 or 3 column feature data into the unit cube and converts into RGB space 17 | } 18 | -------------------------------------------------------------------------------- /man/ConvertGeneNames.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{ConvertGeneNames} 4 | \alias{ConvertGeneNames} 5 | \title{Convert gene names} 6 | \usage{ 7 | ConvertGeneNames(exprMat, annotation, id.column, replace.column) 8 | } 9 | \arguments{ 10 | \item{exprMat}{expression matrix} 11 | 12 | \item{annotation}{data.frame with one id.column containing the current gene ids and a matching replace 13 | column containing the new gene ids} 14 | 15 | \item{id.column}{character vector of unique gene ids of the same type as in the Seurat object} 16 | 17 | \item{replace.column}{character vector of unique gene ids to replace the old ids} 18 | } 19 | \value{ 20 | A Seurat object with covnerted gene ids 21 | } 22 | \description{ 23 | Convert gene names 24 | } 25 | -------------------------------------------------------------------------------- /man/CorSpatialDims.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Spatial_genes.R 3 | \name{CorSpatialDims} 4 | \alias{CorSpatialDims} 5 | \title{Find dims with high spatial autocorrelation} 6 | \usage{ 7 | CorSpatialDims( 8 | object, 9 | dims = NULL, 10 | reduction = "pca", 11 | nNeighbours = NULL, 12 | maxdist = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{object}{Seurat object} 17 | 18 | \item{dims}{dims to rank by spatial autocorrelation. If no dims are provided, the 19 | all dims will be used} 20 | 21 | \item{reduction}{dimensionality reduction object to pull data from} 22 | 23 | \item{nNeighbours}{Number of neighbours to find for each spot, For Visium data, this parameter is set to 24 | 6 because of the spots are arranged in a hexagonal pattern and should have maximum 6 neighbors.} 25 | 26 | \item{maxdist}{Maximum allowed distance to define neighbouring spots [default: 1.5]. If not provided, a 27 | maximum distance is automatically selected depending on the platform. For Visium data, this maximum distance 28 | is set to 150 microns.} 29 | } 30 | \value{ 31 | data.frame with gene names and correlation scores 32 | } 33 | \description{ 34 | This function can be used to find dims with spatial structure in ST datasets. 35 | A more detailed decription of the algorithm is outlined in the Details section below. 36 | } 37 | \details{ 38 | overview of method: 39 | \itemize{ 40 | \item{Build a connection network from the array x,y coordinates for each sample. For a 'Visium' array, this would typically be 6 neighbours 41 | because of the hexagonal structure of spots.} 42 | \item{Combine connection networks from multiple samples} 43 | \item{Compute the lag vector for each feature} 44 | \item{Compute the correlation between the lag vector and the original vector} 45 | } 46 | The connection network is build by defining edges between each spot and its `nNeighborurs` closest 47 | neighbours that are within a maximum distance defined by `maxdist`. This is to make sure that spots 48 | along the tissue edges or holes have the correct number of neighbours. A connection network is built for 49 | each section separately but they are then combined into one large connection network so that the 50 | autocorrelation can be computed for the whole dataset. 51 | 52 | Now that we have a neighbour group defined for 53 | each spot, we can calculate the lag vector for each feature. The lag vector of a features is essentially 54 | the summed expression of that feature in the neighbour groups, computed for all spots and can be thought 55 | of as a "smoothing" estimate. 56 | 57 | If we consider a spot A and its neighbours nbA, a feature with high spatial 58 | corelation should have similar expression levels in both groups. We can therefore compute the a 59 | correlation score between the lag vector and the "normal" expression vector to get an estimate of 60 | the spatial autocorrelation. 61 | } 62 | -------------------------------------------------------------------------------- /man/CorSpatialGenes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Spatial_genes.R 3 | \name{CorSpatialGenes} 4 | \alias{CorSpatialGenes} 5 | \title{Find genes with high spatial autocorrelation} 6 | \usage{ 7 | CorSpatialGenes( 8 | object, 9 | assay = NULL, 10 | slot = "scale.data", 11 | features = NULL, 12 | nNeighbours = NULL, 13 | maxdist = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{Seurat object} 18 | 19 | \item{assay}{Name of assay the function is being run on} 20 | 21 | \item{slot}{Slot to use as input [default: 'scale.data']} 22 | 23 | \item{features}{Features to rank by spatial autocorrelation. If no features are provided, the 24 | features are selected using the `VariableFeatures` function in Seurat, meaning that the top variable genes 25 | will be used.} 26 | 27 | \item{nNeighbours}{Number of neighbours to find for each spot, For Visium data, this parameter is set to 28 | 6 because of the spots are arranged in a hexagonal pattern and should have maximum 6 neighbors.} 29 | 30 | \item{maxdist}{Maximum allowed distance to define neighbouring spots [default: 1.5]. If not provided, a 31 | maximum distance is automatically selected depending on the platform. For Visium data, this maximum distance 32 | is set to 150 microns.} 33 | } 34 | \value{ 35 | data.frame with gene names and correlation scores 36 | } 37 | \description{ 38 | This function can be used to find genes with spatial structure in ST datasets. 39 | A more detailed decription of the algorithm is outlined in the Details section below. 40 | } 41 | \details{ 42 | overview of method: 43 | \itemize{ 44 | \item{Build a connection network from the array x,y coordinates for each sample. For a 'Visium' array, this would typically be 6 neighbours 45 | because of the hexagonal structure of spots.} 46 | \item{Combine connection networks from multiple samples} 47 | \item{Compute the lag vector for each feature} 48 | \item{Compute the correlation between the lag vector and the original vector} 49 | } 50 | The connection network is build by defining edges between each spot and its `nNeighborurs` closest 51 | neighbours that are within a maximum distance defined by `maxdist`. This is to make sure that spots 52 | along the tissue edges or holes have the correct number of neighbours. A connection network is built for 53 | each section separately but they are then combined into one large connection network so that the 54 | autocorrelation can be computed for the whole dataset. 55 | 56 | Now that we have a neighbour group defined for 57 | each spot, we can calculate the lag vector for each feature. The lag vector of a features is essentially 58 | the summed expression of that feature in the neighbour groups, computed for all spots and can be thought 59 | of as a "smoothing" estimate. 60 | 61 | If we consider a spot A and its neighbours nbA, a feature with high spatial 62 | corelation should have similar expression levels in both groups. We can therefore compute the a 63 | correlation score between the lag vector and the "normal" expression vector to get an estimate of 64 | the spatial autocorrelation. 65 | } 66 | -------------------------------------------------------------------------------- /man/Create3DStack.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3D_viusalization.R 3 | \name{Create3DStack} 4 | \alias{Create3DStack} 5 | \title{Creates a stack of point patterns with aligned data and stores it in a 6 | `Staffli` object.} 7 | \usage{ 8 | Create3DStack(object, limit = 0.4, maxnum = 50000, nx = 200, verbose = TRUE) 9 | } 10 | \arguments{ 11 | \item{object}{Seurat object} 12 | 13 | \item{limit}{Cut-off threshold for segmentation of points. Has to be a value between 0-1.} 14 | 15 | \item{maxnum}{Maximum number of points to store for each section [default: 5e5]. If you are analyzing many samples 16 | you will have to decrease this number.} 17 | 18 | \item{nx}{Number of cells to interpolate over across the x axis} 19 | 20 | \item{verbose}{Print messages} 21 | } 22 | \value{ 23 | Seurat object 24 | } 25 | \description{ 26 | Creates a stack of point patterns with aligned data and stores it in a 27 | `Staffli` object. 28 | } 29 | -------------------------------------------------------------------------------- /man/CreateStaffliObject.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{CreateStaffliObject} 4 | \alias{CreateStaffliObject} 5 | \title{Create a Staffli object} 6 | \usage{ 7 | CreateStaffliObject(imgs = NULL, meta.data, xdim = 400, platforms = NULL) 8 | } 9 | \arguments{ 10 | \item{imgs}{Character vector specifying paths to images in jpg or png format.} 11 | 12 | \item{meta.data}{Spot-level metadata to add to the Staffli object. Should be a data.frame with 13 | required fields 'x' and 'y' which specifies the ST array coorindates and a column calles 'sample' 14 | which maps spots to a certain image.} 15 | 16 | \item{xdim}{Specifies the width of the scaled images in pixels [default: 400 pixels]} 17 | 18 | \item{platforms}{Specify the platforms used to generate the ST data [options: 'Visium', '2k', '1k']} 19 | } 20 | \description{ 21 | Create a Staffli object from set of images and associated spot coordinates. 22 | } 23 | -------------------------------------------------------------------------------- /man/Create_annotation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/manual_annotation.R 3 | \name{Create_annotation} 4 | \alias{Create_annotation} 5 | \title{Create an annotation} 6 | \usage{ 7 | Create_annotation(object, type, sampleNr, res) 8 | } 9 | \arguments{ 10 | \item{object}{Seurat object} 11 | 12 | \item{type}{Image type, e.g. "raw" or "masked"} 13 | 14 | \item{sampleNr}{Selected section/sample number} 15 | 16 | \item{res}{Image resolution} 17 | } 18 | \description{ 19 | Create an annotation 20 | } 21 | -------------------------------------------------------------------------------- /man/CropImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/image_processing.R 3 | \name{CropImages} 4 | \alias{CropImages} 5 | \alias{CropImages.Staffli} 6 | \alias{CropImages.Seurat} 7 | \title{Manual cropping of images} 8 | \usage{ 9 | CropImages( 10 | object, 11 | crop.geometry.list, 12 | xdim = NULL, 13 | time.resolve = FALSE, 14 | verbose = FALSE, 15 | ... 16 | ) 17 | 18 | \method{CropImages}{Staffli}( 19 | object, 20 | crop.geometry.list, 21 | xdim = NULL, 22 | time.resolve = FALSE, 23 | verbose = FALSE, 24 | ... 25 | ) 26 | 27 | \method{CropImages}{Seurat}( 28 | object, 29 | crop.geometry.list, 30 | xdim = NULL, 31 | time.resolve = FALSE, 32 | verbose = FALSE, 33 | ... 34 | ) 35 | } 36 | \arguments{ 37 | \item{object}{Seurat object} 38 | 39 | \item{crop.geometry.list}{List of crop windows. Each element of the list should be named by a section number that 40 | the cropping should be applied to, e.g. "1", "2", "3", etc. The crop window is defined by a string speficying the 41 | size of the output window and the offset in pixels; "_width_x_height_+_offsetx_+_offsety_". Note that the cropping 42 | will be applied to the original HE images, i.e. the images that were loaded when running `LoadImages`. See details 43 | below for more information.} 44 | 45 | \item{xdim}{Maximum width of cropped window} 46 | 47 | \item{time.resolve}{Activate to stop R from loading raw images into memory} 48 | 49 | \item{verbose}{Print messages} 50 | 51 | \item{...}{Additional parameters} 52 | } 53 | \value{ 54 | A Staffli object 55 | 56 | A Seurat object 57 | } 58 | \description{ 59 | Takes a predefined list of crop windows and cuts each image 60 | } 61 | \details{ 62 | Let's say that you want to crop out a smaller piece of secttion 1 that should be 500x500 pixels 63 | and should be offset by 400 pixels along the x axis and 400 pixels along the y axis. The y axis 64 | starts from the top of the image so the offset will essentially determine the top left corner 65 | of the output cropped image. To do this, you can set `crop.geometry.list = list("1" = "500x500+400+400")`. 66 | If `xdim` is not specified, the function will collect the predefined `xdim` that was set when 67 | running `LoadImages`. The `xdim` value determines the maximum allowed width of the cropped image, 68 | so if you for example set a large crop window from the original image, e.g. "2000x2000+1000+1000" 69 | the output image will still be downscaled to a width of `xdim` to keep the output image in low 70 | resolution. 71 | } 72 | \examples{ 73 | \dontrun{ 74 | # Load images 75 | st.object <- GetStaffli(se) 76 | 77 | # Crop section 1 to a size of 500x500 pixels offset by (500, 500) pixels from the top left corner 78 | st.object<- CropImages(st.object, crop.geometry.list = list("1" = "500x500+500+500")) 79 | } 80 | \dontrun{ 81 | # Load images 82 | se <- LoadImages(se) 83 | 84 | # Crop section 1 to a size of 500x500 pixels offset by (500, 500) pixels from the top left corner 85 | se <- CropImages(se, crop.geometry.list = list("1" = "500x500+500+500")) 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /man/CustomFacetWrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/facet_grid_SC.R 3 | \docType{data} 4 | \name{CustomFacetWrap} 5 | \alias{CustomFacetWrap} 6 | \title{Custom ggproto object for facet wrap} 7 | \format{ 8 | An object of class \code{CustomFacetWrap} (inherits from \code{FacetWrap}, \code{Facet}, \code{ggproto}, \code{gg}) of length 2. 9 | } 10 | \usage{ 11 | CustomFacetWrap 12 | } 13 | \description{ 14 | Custom ggproto object for facet wrap 15 | } 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/DimPlot3D.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3D_viusalization.R 3 | \name{DimPlot3D} 4 | \alias{DimPlot3D} 5 | \title{Plots a selected dimensionality reduction vector in 3D} 6 | \usage{ 7 | DimPlot3D( 8 | object, 9 | spots = NULL, 10 | dims = 1, 11 | reduction = NULL, 12 | mode = c("cloud", "spots"), 13 | pts.downsample = 5e+05, 14 | zcoords = NULL, 15 | min.cutoff = NA, 16 | max.cutoff = NA, 17 | blend = FALSE, 18 | pt.size = NULL, 19 | pt.alpha = 1, 20 | cols = c("navyblue", "cyan", "yellow", "red", "dark red"), 21 | add.alpha = FALSE, 22 | add.margins = 0, 23 | channels.use = NULL, 24 | scene = "scene1", 25 | return.data = FALSE, 26 | dark.theme = FALSE, 27 | verbose = FALSE 28 | ) 29 | } 30 | \arguments{ 31 | \item{object}{Seurat object} 32 | 33 | \item{spots}{Subset spots to plot} 34 | 35 | \item{dims}{Dimensions to plot [default: 1]. Only one dimension can be plotted at the time unless the blend option is 36 | activated, in which case you can plot 2 or three dimensions at the time.} 37 | 38 | \item{reduction}{Reduction object to pull data from [e.g. 'umap', 'pca', 'ica', 'NMF', ...]} 39 | 40 | \item{mode}{Select mode to display the 3D stack in. The default 'cloud' option will use the stacked point patterns as a scaffold for the 3D 41 | visualization whereas the 'spots' options will use the spot coordinates instead.} 42 | 43 | \item{pts.downsample}{Downsample the point cloud to this number [default: 5e5].} 44 | 45 | \item{zcoords}{Vector of z coordinates with the same length as the number of sections in the dataset [default: 1:number_of_sections]} 46 | 47 | \item{min.cutoff, max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 48 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 49 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 50 | 51 | \item{blend}{Scale and blend expression values to visualize coexpression of two dims (this options will override other coloring parameters). 52 | See 'Blending values' below for a more thourough description.} 53 | 54 | \item{pt.size}{Sets the size of points in the 3D plot} 55 | 56 | \item{pt.alpha}{Sets the opacity of the points. Only active if `add.alpha = FALSE`} 57 | 58 | \item{cols}{Colors used to create a colorscale} 59 | 60 | \item{add.alpha}{Adds opacity to points scaled by feature values. See opacity section for more details.} 61 | 62 | \item{add.margins}{Add margins along z axis to push sections closer to each other} 63 | 64 | \item{channels.use}{Color channels to use for blending. Has to be a character vector of length 2 or 3 with "red", "green" and "blue" 65 | color names specified [default: c("red", "green", "blue)]} 66 | 67 | \item{scene}{Give the scene a name to allow for multiple subplots} 68 | 69 | \item{return.data}{return the data.frame with x,y coordinates and interpolated values 70 | instead of plotting} 71 | 72 | \item{dark.theme}{Draws the plot with a dark theme} 73 | 74 | \item{verbose}{Print messages} 75 | } 76 | \description{ 77 | This function is similar to the ST.DimPlot but works for 3D stacked data. First, you need to mask and align the tissue sections in your 78 | Seurat object and run the \code{Create3DStack} function to create the 3D stack from the aligned images. 79 | } 80 | \section{Blending values}{ 81 | 82 | The blend option can be useful if you wish to visualize multiple dimensionality reduction simultaneuosly and works for two or three value vectors. 83 | Each of the selected vectors are rescaled from 0 to 1 and are used as RGB color channels to produce mixed color for each 84 | spot. This can be particularly useful when looking at overlapping value vectors. For example, if you are looking at two overlapping value vectors 85 | "A" and "B" and use the blend option, the "A" values will be encoded in the "red" channel and the "B" values in the "green" channel. If a spot is 86 | purely "A" the color will be red and if it is purely "B" it will green. Any mixture of "A" and "B" will produce a color between red and green 87 | where a 50/50 mixture gives yellow color. 88 | } 89 | 90 | \section{distance between tissue sections}{ 91 | 92 | The distance between adjacent tissue sections is by default set to 1 with the z axis ranging from 0 to the number of sections. You can control the 93 | distances manually by converting the z coordinates using the `zcoords`. The range of the z axis can be controlled to either force the sections 94 | closer to each other or adding distance between them. This can be done using the `add.margins` option which accepts a numeric value that will 95 | stretch out the z axis range. For example, if you have 6 sections and `add.margins = 20`, the z axis will range from [-20, 26] and therefore 96 | push the sections closer to each other. 97 | } 98 | 99 | \section{opacity}{ 100 | 101 | Sometimes it can be useful to add some opacity to the points to make it easier to look at 3D structures. If `pt.alpha` is specified, the same opacity 102 | will be applied to all points. If `add.alpha` is active, the opacity will be scaled with the feature values, meaning that the points with the lowest 103 | feature values will be transparent. `add.alpha` does not work for blended values. 104 | } 105 | 106 | -------------------------------------------------------------------------------- /man/EdgeMask.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Mask_functions.R 3 | \name{EdgeMask} 4 | \alias{EdgeMask} 5 | \title{Masking function t} 6 | \usage{ 7 | EdgeMask(im) 8 | } 9 | \arguments{ 10 | \item{im}{An image of class \code{cimg}} 11 | } 12 | \description{ 13 | This function takes an image of class \code{cimg} as input and returns 14 | an image of class \code{pixset}. The method is typically suitable for images 15 | with little background debris. Not suitable for 'Visium' images with fiducials. 16 | } 17 | -------------------------------------------------------------------------------- /man/FactorGeneLoadingPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RunNMF.R 3 | \name{FactorGeneLoadingPlot} 4 | \alias{FactorGeneLoadingPlot} 5 | \title{Plot a bar chart with gene loadings} 6 | \usage{ 7 | FactorGeneLoadingPlot(object, factor = 1, topn = 20, dark.theme = FALSE) 8 | } 9 | \arguments{ 10 | \item{object}{Seurat object} 11 | 12 | \item{factor}{Factor to plot gene loadings for [default: 1]} 13 | 14 | \item{topn}{Top genes to show [default: 20]} 15 | 16 | \item{dark.theme}{Use a dark theme for the plot} 17 | } 18 | \description{ 19 | This function takes a `Seurat`object as input with a 'NMF' reduction slot 20 | and plots a bar chart of gene weights (loadings) for the top most driving genes. 21 | } 22 | -------------------------------------------------------------------------------- /man/FeaturePlot3D.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3D_viusalization.R 3 | \name{FeaturePlot3D} 4 | \alias{FeaturePlot3D} 5 | \title{Plots the values of a selected feature in 3D} 6 | \usage{ 7 | FeaturePlot3D( 8 | object, 9 | spots = NULL, 10 | features, 11 | mode = c("cloud", "spots"), 12 | pts.downsample = 5e+05, 13 | zcoords = NULL, 14 | slot = "data", 15 | min.cutoff = NA, 16 | max.cutoff = NA, 17 | blend = FALSE, 18 | pt.size = NULL, 19 | pt.alpha = 1, 20 | cols = c("navyblue", "cyan", "yellow", "red", "dark red"), 21 | add.alpha = FALSE, 22 | add.margins = 0, 23 | channels.use = NULL, 24 | scene = "scene1", 25 | return.data = FALSE, 26 | dark.theme = FALSE, 27 | verbose = FALSE 28 | ) 29 | } 30 | \arguments{ 31 | \item{object}{Seurat object} 32 | 33 | \item{spots}{Subset spots to plot} 34 | 35 | \item{features}{Features to plot} 36 | 37 | \item{mode}{Select mode to display the 3D stack in. The default 'cloud' option will use the stacked point patterns as a scaffold for the 3D 38 | visualization whereas the 'spots' options will use the spot coordinates instead.} 39 | 40 | \item{pts.downsample}{Downsample the point cloud to this number [default: 5e5].} 41 | 42 | \item{zcoords}{Vector of z coordinates with the same length as the number of sections in the dataset [default: 1:number_of_sections]} 43 | 44 | \item{slot}{Which slot to pull the data from? [default: 'data']} 45 | 46 | \item{min.cutoff, max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 47 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 48 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 49 | 50 | \item{blend}{Scale and blend expression values to visualize coexpression of two features (this options will override other coloring parameters). 51 | See 'Blending values' below for a more thourough description.} 52 | 53 | \item{pt.size}{Sets the size of points in the 3D plot} 54 | 55 | \item{pt.alpha}{Sets the opacity of the points. Only active if `add.alpha = FALSE`} 56 | 57 | \item{cols}{Colors used to create a colorscale} 58 | 59 | \item{add.alpha}{Adds opacity to points scaled by feature values. See opacity section for more details.} 60 | 61 | \item{add.margins}{Add margins along z axis to push sections closer to each other} 62 | 63 | \item{channels.use}{Color channels to use for blending. Has to be a character vector of length 2 or 3 with "red", "green" and "blue" 64 | color names specified [default: c("red", "green", "blue)]} 65 | 66 | \item{scene}{Give the scene a name to allow for multiple subplots} 67 | 68 | \item{return.data}{return the data.frame with x,y coordinates and interpolated values 69 | instead of plotting} 70 | 71 | \item{dark.theme}{Draws the plot with a dark theme} 72 | 73 | \item{verbose}{Print messages} 74 | } 75 | \description{ 76 | This function is similar to the ST.FeaturePlot but works for 3D stacked data. First, you need to mask and align the tissue sections in your 77 | Seurat object and run the \code{Create3DStack} function to create the 3D stack from the aligned images. 78 | } 79 | \section{Blending values}{ 80 | 81 | The blend option can be useful if you wish to visualize multiple feature vectors simultaneuosly and works for two or three value vectors. 82 | Each of the selected vectors are rescaled from 0 to 1 and are used as RGB color channels to produce mixed color for each 83 | spot. This can be particularly useful when looking at overlapping value vectors. For example, if you are looking at two overlapping value vectors 84 | "A" and "B" and use the blend option, the "A" values will be encoded in the "red" channel and the "B" values in the "green" channel. If a spot is 85 | purely "A" the color will be red and if it is purely "B" it will green. Any mixture of "A" and "B" will produce a color between red and green 86 | where a 50/50 mixture gives yellow color. 87 | } 88 | 89 | \section{distance between tissue sections}{ 90 | 91 | The distance between adjacent tissue sections is by default set to 1 with the z axis ranging from 0 to the number of sections. You can control the 92 | distances manually by converting the z coordinates using the `zcoords`. The range of the z axis can be controlled to either force the sections 93 | closer to each other or adding distance between them. This can be done using the `add.margins` option which accepts a numeric value that will 94 | stretch out the z axis range. For example, if you have 6 sections and `add.margins = 20`, the z axis will range from [-20, 26] and therefore 95 | push the sections closer to each other. 96 | } 97 | 98 | \section{opacity}{ 99 | 100 | Sometimes it can be useful to add some opacity to the points to make it easier to look at 3D structures. If `pt.alpha` is specified, the same opacity 101 | will be applied to all points. If `add.alpha` is active, the opacity will be scaled with the feature values, meaning that the points with the lowest 102 | feature values will be transparent. `add.alpha` does not work for blended values. 103 | } 104 | 105 | -------------------------------------------------------------------------------- /man/FilterObjects.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{FilterObjects} 4 | \alias{FilterObjects} 5 | \title{Get the names of objects within a Seurat object that are of a certain class} 6 | \usage{ 7 | FilterObjects(object, classes.keep = c("Assay", "DimReduc")) 8 | } 9 | \arguments{ 10 | \item{object}{A Seurat object} 11 | 12 | \item{classes.keep}{A vector of names of classes to get} 13 | } 14 | \value{ 15 | A vector with the names of objects within the Seurat object that are of class \code{classes.keep} 16 | } 17 | \description{ 18 | Get the names of objects within a Seurat object that are of a certain class 19 | } 20 | -------------------------------------------------------------------------------- /man/GetCoords.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{GetCoords} 4 | \alias{GetCoords} 5 | \title{Extract table of x, y coordinates from ST count matrix headers} 6 | \usage{ 7 | GetCoords(spotnames, delim = "x") 8 | } 9 | \arguments{ 10 | \item{spotnames}{x, y coordinates separated by delimiter (default "x")} 11 | 12 | \item{delim}{delimiter} 13 | } 14 | \value{ 15 | data.frame with x, y coordinates and optionally a sample column 16 | } 17 | \description{ 18 | Extract table of x, y coordinates from ST count matrix headers 19 | } 20 | -------------------------------------------------------------------------------- /man/GetCropWindows.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/crop_utilities.R 3 | \name{GetCropWindows} 4 | \alias{GetCropWindows} 5 | \title{Get crop geometries} 6 | \usage{ 7 | GetCropWindows( 8 | object, 9 | group.by = NULL, 10 | groups.to.keep = NULL, 11 | symmetric = TRUE, 12 | keep.all.spots = FALSE, 13 | xy_padding = 50 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{A Seurat object created with STutility} 18 | 19 | \item{group.by}{A meta.data column to group the spots by. Only character 20 | vector or factors are allowed. Selects "labels" by default.} 21 | 22 | \item{groups.to.keep}{Provide a caharcter vector of groups to keep.} 23 | 24 | \item{symmetric}{Make crop window square. This will mkae it easier to align images in dowstream processing steps.} 25 | 26 | \item{keep.all.spots}{Keep all spots within selected crop windows and not just the spots 27 | belonging to the predefined groups. All spots that are present in multiple crop windows will be removed.} 28 | 29 | \item{xy_padding}{Increase the crop area in all directions. Given in pixels.} 30 | } 31 | \value{ 32 | A list of "crop geometries" to be used with \code{\link{CropImages}}) 33 | } 34 | \description{ 35 | This function can be used to define "crop windows" based on sets 36 | of target spots. 37 | } 38 | -------------------------------------------------------------------------------- /man/GetSpatNet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Spatial_genes.R 3 | \name{GetSpatNet} 4 | \alias{GetSpatNet} 5 | \title{Create Spatial Networks} 6 | \usage{ 7 | GetSpatNet(object, nNeighbours = NULL, maxdist = NULL, minK = 0) 8 | } 9 | \arguments{ 10 | \item{object}{Seurat object} 11 | 12 | \item{nNeighbours}{Number of nearest neighbours to calculate for each spot. The default 13 | number of neighbours is 6 for the 'Visium' platform and 4 for the '1k' and '2k' platforms.} 14 | 15 | \item{maxdist}{Distance cut-off for nearest neighbours to consider. The default is 1.5 for the 16 | 'Visium' and '2k' platforms and 2 for the '1k' platform.} 17 | 18 | \item{minK}{Minimum nearest neigbhours if maxdist is not provided [default: 0]} 19 | } 20 | \description{ 21 | Create spatial networks based on spot center to center distances from a Seurat object. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | spatial.networks <- GetSpatNet(se) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /man/GetStaffli.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/Staffli.R 3 | \docType{methods} 4 | \name{GetStaffli} 5 | \alias{GetStaffli} 6 | \alias{GetStaffli,Seurat-method} 7 | \alias{GetStaffli,Seurat,Seurat-method} 8 | \title{Extracts Staffli from Seurat object} 9 | \usage{ 10 | GetStaffli(object) 11 | 12 | GetStaffli(object) 13 | 14 | \S4method{GetStaffli}{Seurat}(object) 15 | } 16 | \arguments{ 17 | \item{object}{A Seurat object} 18 | } 19 | \description{ 20 | Extracts Staffli from Seurat object 21 | 22 | Method used to extract a Staffli object from the tools slot of a 23 | Seurat object 24 | } 25 | -------------------------------------------------------------------------------- /man/HSVOverlay.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HSVencoding.R 3 | \name{HSVOverlay} 4 | \alias{HSVOverlay} 5 | \title{Overlay HSV encoded features on HE images} 6 | \usage{ 7 | HSVOverlay( 8 | object, 9 | features, 10 | sampleids = 1, 11 | rescale = TRUE, 12 | spots = NULL, 13 | ncols.features = NULL, 14 | ncols.samples = NULL, 15 | type = NULL, 16 | min.cutoff = NA, 17 | max.cutoff = NA, 18 | slot = "data", 19 | pt.size = 2, 20 | pt.alpha = 1, 21 | add.alpha = FALSE, 22 | palette = NULL, 23 | cols = NULL, 24 | split.hsv = FALSE, 25 | dark.theme = FALSE, 26 | sample.label = TRUE, 27 | show.sb = TRUE, 28 | verbose = FALSE, 29 | ... 30 | ) 31 | } 32 | \arguments{ 33 | \item{object}{Seurat object} 34 | 35 | \item{features}{\itemize{ 36 | \item An \code{Assay} feature (e.g. a gene name - "MS4A1") 37 | \item A column name from meta.data (e.g. mitochondrial percentage - "percent.mito") 38 | }} 39 | 40 | \item{sampleids}{Names of samples to plot} 41 | 42 | \item{rescale}{Rescale each feature column separately from 0 to 1 range. If set to FALSE, all feature columns 43 | will be scaled together from 0 to 1 and preserve the relative differencies} 44 | 45 | \item{spots}{Character vector with spot IDs to plot [default: all spots]} 46 | 47 | \item{ncols.features}{Number of columns passed to \code{\link{FeatureOverlay}}. For example, 48 | if you are plotting 4 features, `ncols.features = 2` will arrange the \code{\link{FeatureOverlay}} 49 | plots into a 2x2 grid [default: `length(features)`]. (see \emph{Arrange plots*} for a detailed description)} 50 | 51 | \item{ncols.samples}{Number of columns in the layout grid for the samples. For example, 52 | if you are plotting 4 samples, `ncols.samples = 2` will arrange the plots obtained 53 | from \code{\link{FeatureOverlay}} plots into a 2x2 grid [default: `1`]. 54 | (see \emph{Arrange plots*} for a detailed description)} 55 | 56 | \item{type}{Image type to plot on. Here you can specify any of the images available in your Seurat object. To get this list you can 57 | run the \code{\link{rasterlists}} function on your Seurat object. If the type is not specified, the images will be prioritized in the following 58 | order if they are available; "processed", "masked" and "raw".} 59 | 60 | \item{min.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 61 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 62 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 63 | 64 | \item{max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 65 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 66 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 67 | 68 | \item{slot}{Which slot to pull expression data from? [dafault: 'data']} 69 | 70 | \item{pt.size}{Point size of each ST spot [default: 1]} 71 | 72 | \item{pt.alpha}{Opacity of each ST spot [default: 1]} 73 | 74 | \item{add.alpha}{Scale spot opacity by selected feature. Higher values get more opaque while lower values make spots transparent.} 75 | 76 | \item{palette}{Color palette used for spatial heatmap (see \code{palette.select(info = T)} for available options). 77 | Disabled if a color vector is provided (see \code{cols} below).} 78 | 79 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 80 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 81 | option.} 82 | 83 | \item{split.hsv}{Should the HSV colored features be split into separate plots? [default: FALSE]} 84 | 85 | \item{dark.theme}{Switches color of scalebar to 'white'} 86 | 87 | \item{sample.label}{Should the sample label be included in the image? [default: TRUE]} 88 | 89 | \item{show.sb}{Should a scalebar be drawn? [default: TRUE]} 90 | 91 | \item{verbose}{Print messages} 92 | 93 | \item{...}{Parameters passed to DimOverlay} 94 | } 95 | \description{ 96 | Graphs the selected features as a HSVplot on a 2D grid of spots overlaid on top of an HE images. 97 | Only numerical features are accepted, e.g. genes or dimensionality reduction output vectors. If you 98 | want to draw dimentionality reduction vectors you need to specify the whole names of the vectors, e.g. 99 | `features = c("factor_1", "factor_2")` for the two first NMF factors. 100 | } 101 | \details{ 102 | NOTE that this function draws sample 1 as default, but can take multiple samples as well using the `sampleids argument`. 103 | 104 | It is typically difficult to explore details in the HE image when diplaying multiple samples side by side, 105 | so we recommend to draw the plots for one sample at the time. If you have higher resolution images, 106 | it could also take significant time to draw the plots. 107 | } 108 | \section{Arrange plots}{ 109 | 110 | 111 | The `ncols.features` argument will determine how each subplot called using 112 | \code{\link{DimOverlay}} is arranged and will by default put all dims in 1 row, i.e. 113 | `ncols.features = length(features)`. The `ncols.samples` argument will determine how these subplots 114 | are arranged and will by default use 1 column, meaning that each subplot is put in its own row. 115 | The output layout matrix would then have the dimensions `length(samples)xlength(features)` 116 | 117 | 118 | 119 | The `ncols.features` argument will determine how each subplot is arranged and will by default put all features in 1 row, i.e. 120 | `ncols.features = length(features)`. The `ncols.samples` argument will determine how these subplots 121 | are arranged and will by default use 1 column, meaning that each subplot is put in its own row. 122 | The output layout matrix would then have the dimensions `length(samples)xlength(features)` 123 | } 124 | 125 | \section{Splitting categorical features}{ 126 | 127 | If you are plotting a categorical feature, e.g.cluster labels, you have the option to split each label into facets using \code{split.labels=TRUE}. 128 | This is very useful if you have many different labels which can make it difficult to distinguish the different colors. 129 | } 130 | 131 | \examples{ 132 | \dontrun{ 133 | # Load images 134 | se <- se \%>\% SCTransfrom() \%>\% LoadImages() \%>\% RunNMF() 135 | 136 | # Overlay first two NMF factors on the first two tissue sections 137 | HSVPlot(se, features = c("factor_1", "factor_2"), sampleids = 1:2) 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /man/HSVPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HSVencoding.R 3 | \name{HSVPlot} 4 | \alias{HSVPlot} 5 | \title{HSV encoded plots} 6 | \usage{ 7 | HSVPlot( 8 | object, 9 | features, 10 | ncol = NULL, 11 | plot.type = "spots", 12 | split.hsv = FALSE, 13 | rescale = TRUE, 14 | indices = NULL, 15 | spots = NULL, 16 | min.cutoff = NA, 17 | max.cutoff = NA, 18 | slot = "data", 19 | pt.size = 1, 20 | pt.alpha = 1, 21 | pt.border = FALSE, 22 | add.alpha = FALSE, 23 | sigma = 2, 24 | highlight.edges = FALSE, 25 | cols = NULL, 26 | dark.theme = TRUE, 27 | grid.ncol = NULL, 28 | theme = theme_void(), 29 | scale.res = 1, 30 | verbose = FALSE, 31 | ... 32 | ) 33 | } 34 | \arguments{ 35 | \item{object}{Seurat object} 36 | 37 | \item{features}{\itemize{ 38 | \item An \code{Assay} feature (e.g. a gene name - "MS4A1") 39 | \item A column name from meta.data (e.g. mitochondrial percentage - "percent.mito") 40 | }} 41 | 42 | \item{ncol}{Number of columns to arrange the samples into. This can for example be useful to adjust if you want to visualize the samples 43 | in just in one row or one column.} 44 | 45 | \item{plot.type}{Select one of 'spots' or 'smooth' [default: 'spots']} 46 | 47 | \item{split.hsv}{Should the HSV colored features be split into separate plots? [default: FALSE]} 48 | 49 | \item{rescale}{Rescale each feature column separately from 0 to 1 range. If set to FALSE, all feature columns 50 | will be scaled together from 0 to 1 and preserve the relative differencies} 51 | 52 | \item{indices}{Numeric vector specifying sample indices to include in plot. Default is to show all samples.} 53 | 54 | \item{spots}{Vector of spots to plot (default is all spots)} 55 | 56 | \item{min.cutoff, max.cutoff}{Vector of minimum and maximum cutoff values for each feature, 57 | may specify quantile in the form of 'q##' where '##' is the quantile (eg, 'q1', 'q10')} 58 | 59 | \item{slot}{Which slot to pull expression data from?} 60 | 61 | \item{pt.size}{Adjust point size for plotting} 62 | 63 | \item{pt.alpha}{Adjust opacity of spots.} 64 | 65 | \item{pt.border}{Should a border be drawn around the spots? [default: TRUE]} 66 | 67 | \item{add.alpha}{Adds opacity to spots scaled by feature values. This will disable the pt.alpha parameter} 68 | 69 | \item{sigma}{Smoothing bandwidth; only active if \code{plot.type = 'smooth'}. A single positive number, a numeric vector of length 2, or a function that selects the bandwidth automatically [default: 2]. 70 | See \code{\link{density.ppp}} function from the \code{\link{spatstat.core}} package for more details.} 71 | 72 | \item{highlight.edges}{Highlights the edges of the tissue. Only active if \code{plot.type = 'smooth'} and if the images have been masked.} 73 | 74 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 75 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 76 | option.} 77 | 78 | \item{dark.theme}{Use a dark theme for plotting} 79 | 80 | \item{grid.ncol}{Number of columns for display when combining plots} 81 | 82 | \item{theme}{Add a custom theme to the output ggplot object} 83 | 84 | \item{scale.res}{Integer value setting the resolution of the output raster image. E.g. scale.res = 2 will double the 85 | resolution of the output but will also take longer to render. Only active if plot.type is set to 'smooth'.} 86 | 87 | \item{verbose}{Print messages} 88 | 89 | \item{...}{Extra parameters passed on to \code{\link{STPlot}}} 90 | } 91 | \value{ 92 | A ggplot object 93 | } 94 | \description{ 95 | Using an HSV encoding of feature values, this functions can be used to color 96 | code expression profiles of multiple features and visualize spatially. 97 | } 98 | \details{ 99 | Using RGB encoding, we can show up to 3 features at the same time in the 100 | "red", "green" and "blue" color channels. Whenever two or three features overlap, 101 | the color will be a mix of the three channels, e.g. 50% green and 50% red will give a yellow color. 102 | This strategy is very effective when looking at features values with significant 103 | overlap but is limited to show maximum three features. 104 | 105 | If we want to show more than three features in the same plot, this 106 | function provides a strategy to do this as long as the overlap between features 107 | is relatively low. First, a color is assigned to each of N features by cutting 108 | the hue (H) into N values with an even interval. The feature values (e.g. gene expression) 109 | are then scaled to a 0-1 range which is encoded in the Value channel (V). 110 | For each spot, the color with the highest V is selected meaning that only the 111 | feature with the highest value will be shown in the plot. This strategy works well 112 | for features with no or very little overlap but gets cluttered when to many 113 | features are included. 114 | 115 | This visualization method should be used only on carefully selected features and you should be 116 | aware that color representation of quantitative data can be very misleading. It should only be 117 | usde to assess qualitative aspects of the data, for example if you wish to know where 5 "non-overlapping" 118 | features are expressed spatially. You should therefore investigate beforehand if the features of interest 119 | overlap or, otherwise the results can become very confusing. 120 | } 121 | \section{scaling of features}{ 122 | 123 | All features are by default scaled independently to a 0 to 1 range which means that the relative 124 | differencies between the feature expression levels is not preserved. This is because some features 125 | can still be very distinct for a region of interest even though their magnitude of expression is low. 126 | If you want to preserve the relative differencies you can set `rescale = FALSE`. 127 | } 128 | 129 | -------------------------------------------------------------------------------- /man/HSVPlot3D.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3D_viusalization.R 3 | \name{HSVPlot3D} 4 | \alias{HSVPlot3D} 5 | \title{Plots the values of a feature in 3D} 6 | \usage{ 7 | HSVPlot3D( 8 | object, 9 | features, 10 | mode = c("cloud", "spots"), 11 | zcoords = NULL, 12 | spots = NULL, 13 | min.cutoff = NA, 14 | max.cutoff = NA, 15 | slot = "data", 16 | blend = FALSE, 17 | pt.size = NULL, 18 | pt.alpha = 1, 19 | cols = NULL, 20 | add.alpha = FALSE, 21 | add.margins = 0, 22 | channels.use = NULL, 23 | scene = "scene1", 24 | return.data = FALSE, 25 | dark.theme = TRUE, 26 | rescale = TRUE, 27 | verbose = FALSE 28 | ) 29 | } 30 | \arguments{ 31 | \item{object}{Seurat object} 32 | 33 | \item{features}{\itemize{ 34 | \item An \code{Assay} feature (e.g. a gene name - "MS4A1") 35 | \item A column name from meta.data (e.g. mitochondrial percentage - "percent.mito") 36 | \item A column name from dimensionality reduction output (e.g. principal component 1 - "PC_1") 37 | }} 38 | 39 | \item{mode}{Select mode to display the 3D stack in. The default 'cloud' option will use the stacked point patterns as a scaffold for the 3D 40 | visualization whereas the 'spots' options will use the spot coordinates instead.} 41 | 42 | \item{zcoords}{Vector of z coordinates with the same length as the number of sections in the dataset [default: 1:#sections]} 43 | 44 | \item{spots}{Vector of spots to plot (default is all spots)} 45 | 46 | \item{min.cutoff, max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 47 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 48 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 49 | 50 | \item{slot}{Which slot to pull the data from? [default: 'data']} 51 | 52 | \item{blend}{Scale and blend expression values to visualize coexpression of two features (this options will override other coloring parameters). 53 | See 'Blending values' below for a more thourough description.} 54 | 55 | \item{pt.size}{Sets the size of points in the 3D plot} 56 | 57 | \item{pt.alpha}{Sets the opacity of the points} 58 | 59 | \item{cols}{Character vector of colors with equal length to the number of features. These colors will override 60 | the selection of HSV colors and can therefore not be encoded in the same way. Instead of tuning the saturation/value 61 | parameters we can add an alpha channel, making spots with values close to zero completely transparent. This has to 62 | be activated by setting `add.alpha = TRUE`} 63 | 64 | \item{add.alpha}{Adds opacity to colors.} 65 | 66 | \item{add.margins}{Add margins along z axis to push sections closer to each other} 67 | 68 | \item{channels.use}{Color channels to use for blending. Has to be a character vector of length 2 or 3 with "red", "green" and "blue" 69 | color names specified [default: c("red", "green", "blue)]} 70 | 71 | \item{scene}{Give the scene a name to allow for multiple subplots} 72 | 73 | \item{return.data}{return the data.frame with x,y coordinates and interpolated values 74 | instead of plotting} 75 | 76 | \item{dark.theme}{Draws the plot with a dark theme} 77 | 78 | \item{rescale}{Rescale each feature column separately from 0 to 1 range. If set to FALSE, all feature columns 79 | will be scaled together from 0 to 1 and preserve the relative differencies} 80 | 81 | \item{verbose}{Print messages} 82 | } 83 | \description{ 84 | Plots the values of a feature in 3D 85 | } 86 | -------------------------------------------------------------------------------- /man/ImagePlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing.R 3 | \name{ImagePlot} 4 | \alias{ImagePlot} 5 | \title{Function used to plot HE images obtained with \code{\link{LoadImages}}} 6 | \usage{ 7 | ImagePlot( 8 | object, 9 | indices = NULL, 10 | type = NULL, 11 | method = "raster", 12 | ncols = NULL, 13 | annotate = TRUE, 14 | darken = FALSE, 15 | fix.axes = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{object}{Seurat object} 20 | 21 | \item{indices}{Image indices to select} 22 | 23 | \item{type}{Specify which image to display [options: "raw", "masked" or "processed"]} 24 | 25 | \item{method}{Specify display method (raster or viewer).} 26 | 27 | \item{ncols}{Number of columns in output grid of images} 28 | 29 | \item{annotate}{Will put a unique id in the top left corner} 30 | 31 | \item{darken}{Switches the background to black} 32 | 33 | \item{fix.axes}{Fix axes limits to be the same as section 1} 34 | } 35 | \description{ 36 | Function used to plot HE images obtained with \code{\link{LoadImages}} 37 | } 38 | -------------------------------------------------------------------------------- /man/LoadImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/image_processing.R 3 | \name{LoadImages} 4 | \alias{LoadImages} 5 | \alias{LoadImages.Staffli} 6 | \alias{LoadImages.Seurat} 7 | \title{Function used to read HE images in jpeg or png format} 8 | \usage{ 9 | LoadImages( 10 | object, 11 | image.paths = NULL, 12 | xdim = 400, 13 | crop.to.fiducials = FALSE, 14 | crop.scale.factors = c(9, 10, 10, 8), 15 | verbose = TRUE, 16 | time.resolve = FALSE 17 | ) 18 | 19 | \method{LoadImages}{Staffli}( 20 | object, 21 | image.paths = NULL, 22 | xdim = 400, 23 | crop.to.fiducials = FALSE, 24 | crop.scale.factors = c(9, 10, 10, 8), 25 | verbose = TRUE, 26 | time.resolve = TRUE 27 | ) 28 | 29 | \method{LoadImages}{Seurat}( 30 | object, 31 | image.paths = NULL, 32 | xdim = 400, 33 | crop.to.fiducials = FALSE, 34 | crop.scale.factors = c(9, 10, 10, 8), 35 | verbose = TRUE, 36 | time.resolve = TRUE 37 | ) 38 | } 39 | \arguments{ 40 | \item{object}{Seurat or Staffli object} 41 | 42 | \item{image.paths}{Paths to HE images. This is only required if image paths are missing in the Seurat object.} 43 | 44 | \item{xdim}{Sets the pixel width for scaling, e.g. 400 (maximum allowed width is 2000 pixels)} 45 | 46 | \item{crop.to.fiducials}{Set to TRUE if you want to crop out background from the images outside the fiducials.} 47 | 48 | \item{crop.scale.factors}{Numeric vector of length 4 providing a scaling factor for each side of the image. 49 | The scaling factors define the number of spot widths away from the capture area to include in the cropped 50 | image if `crop.to.fiducials` is set to TRUE. The default values are c(9, 10, 10, 8) which corresponds to 51 | left, top, right and bottom.} 52 | 53 | \item{verbose}{Print messages} 54 | 55 | \item{time.resolve}{Activate to stop R from loading raw images into memory} 56 | } 57 | \value{ 58 | A Staffli object 59 | 60 | A Seurat object 61 | } 62 | \description{ 63 | Function used to read HE images in jpeg or png format 64 | } 65 | \examples{ 66 | \dontrun{ 67 | # Create a new Staffli object and plot images 68 | st.obj <- CreateStaffliObject(imgs, meta.data) 69 | st.obj <- LoadImages(st.obj, verbose = TRUE) 70 | plot(st.obj) 71 | } 72 | 73 | \dontrun{ 74 | # Load images into a Seurat object and plot images 75 | se <- LoadImages(se, verbose = TRUE) 76 | ImagePlot(se) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /man/ManualAlignImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/image_processing.R 3 | \name{ManualAlignImages} 4 | \alias{ManualAlignImages} 5 | \alias{ManualAlignImages.Staffli} 6 | \alias{ManualAlignImages.Seurat} 7 | \title{Manual alignment of images} 8 | \usage{ 9 | ManualAlignImages( 10 | object, 11 | type = NULL, 12 | reference.index = 1, 13 | edges = TRUE, 14 | verbose = FALSE, 15 | limit = 0.3, 16 | maxnum = 1000, 17 | fix.axes = FALSE, 18 | custom.edge.detector = NULL 19 | ) 20 | 21 | \method{ManualAlignImages}{Staffli}( 22 | object, 23 | type = "masked.masks", 24 | reference.index = 1, 25 | edges = TRUE, 26 | verbose = FALSE, 27 | limit = 0.3, 28 | maxnum = 1000, 29 | fix.axes = FALSE, 30 | custom.edge.detector = NULL 31 | ) 32 | 33 | \method{ManualAlignImages}{Seurat}( 34 | object, 35 | type = "masked.masks", 36 | reference.index = 1, 37 | edges = TRUE, 38 | verbose = FALSE, 39 | limit = 0.3, 40 | maxnum = 1000, 41 | fix.axes = FALSE, 42 | custom.edge.detector = NULL 43 | ) 44 | } 45 | \arguments{ 46 | \item{object}{Seurat object} 47 | 48 | \item{type}{Image type to use as input for alignment [default: 'masked.masks']} 49 | 50 | \item{reference.index}{Specifies reference sample image for alignment [default: 1]} 51 | 52 | \item{edges}{Uses the tissue edges for alignment} 53 | 54 | \item{verbose}{Print messages} 55 | 56 | \item{limit}{Pixel intensity limit for thresholding} 57 | 58 | \item{maxnum}{Maximum number of points to display in the app} 59 | 60 | \item{fix.axes}{Fix axes of images} 61 | 62 | \item{custom.edge.detector}{Custom function used to detect edges in tissue image. If a function is provided, the 63 | edges option will be overridden.} 64 | } 65 | \value{ 66 | A Staffli object 67 | 68 | A Seurat object 69 | } 70 | \description{ 71 | Creates an interactive shiny application to align images manually 72 | } 73 | \examples{ 74 | \dontrun{ 75 | # Create a new Staffli object, mask, align and plot images (will start an interactive shiny session) 76 | st.obj <- CreateStaffliObject(imgs, meta.data) 77 | st.obj <- LoadImages(st.obj, verbose = TRUE) \%>\% MaskImages() \%>\% ManualAlignImages() 78 | plot(st.obj) 79 | } 80 | \dontrun{ 81 | # Load, mask, align and plot images (will start an interactive shiny session) 82 | se <- LoadImages(se, verbose = TRUE) \%>\% MaskImages() \%>\% ManualAlignImages() 83 | ImagePlot(se) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /man/ManualAnnotation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/manual_annotation.R 3 | \name{ManualAnnotation} 4 | \alias{ManualAnnotation} 5 | \title{Manual annotation tool via shiny 6 | This function takes a seurat object with stored image locations and opens up the manual selection tool in the default browser} 7 | \usage{ 8 | ManualAnnotation(object, type = NULL, res = 1000, verbose = FALSE) 9 | } 10 | \arguments{ 11 | \item{object}{Seurat object} 12 | 13 | \item{type}{Input image type, e.g. "masked" or "raw"} 14 | 15 | \item{res}{Tissue HE image width in pixels} 16 | 17 | \item{verbose}{Print messages} 18 | } 19 | \description{ 20 | Manual annotation tool via shiny 21 | This function takes a seurat object with stored image locations and opens up the manual selection tool in the default browser 22 | } 23 | -------------------------------------------------------------------------------- /man/MaskImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/image_processing.R 3 | \name{MaskImages} 4 | \alias{MaskImages} 5 | \alias{MaskImages.Staffli} 6 | \alias{MaskImages.Seurat} 7 | \title{Image masking} 8 | \usage{ 9 | MaskImages( 10 | object, 11 | thresholding = FALSE, 12 | iso.blur = 2, 13 | channels.use = NULL, 14 | compactness = 1, 15 | add.contrast = NULL, 16 | verbose = FALSE, 17 | custom.msk.fkn = NULL 18 | ) 19 | 20 | \method{MaskImages}{Staffli}( 21 | object, 22 | thresholding = TRUE, 23 | iso.blur = 2, 24 | channels.use = NULL, 25 | compactness = 1, 26 | add.contrast = NULL, 27 | verbose = FALSE, 28 | custom.msk.fkn = NULL 29 | ) 30 | 31 | \method{MaskImages}{Seurat}( 32 | object, 33 | thresholding = TRUE, 34 | iso.blur = 2, 35 | channels.use = NULL, 36 | compactness = 1, 37 | add.contrast = NULL, 38 | verbose = FALSE, 39 | custom.msk.fkn = NULL 40 | ) 41 | } 42 | \arguments{ 43 | \item{object}{Seurat or Staffli object o pre-procesing step [default: TRUE]} 44 | 45 | \item{thresholding}{Applies thresholding step} 46 | 47 | \item{iso.blur}{Sets the level of smoothing in the pre-procesing step [default: 2]} 48 | 49 | \item{channels.use}{Select channel to use for masking [default: 1 for '1k' and '2k' platforms and 1:3 for 'Visium' platform]} 50 | 51 | \item{compactness}{Scales the number of super-pixels [default: 1]} 52 | 53 | \item{add.contrast}{Add contrast to pre-procesing step [default: TRUE platforms and 1:3 for FALSE for 'Visium' platform]} 54 | 55 | \item{verbose}{Print messages} 56 | 57 | \item{custom.msk.fkn}{Custom masking function that takes an image of class "cimg" as input and returns a mask 58 | of class "pixset" outlining the tissue area.} 59 | } 60 | \value{ 61 | A Seurat or Staffli object with masked HE images 62 | 63 | A Staffli object 64 | 65 | A Seurat object 66 | } 67 | \description{ 68 | Masks the background of a tissue section in HE images 69 | } 70 | \details{ 71 | The masking method provided uses the SLIC method; Simple Linear Iterative Clustering (for more info, see 72 | \url{https://www.r-bloggers.com/superpixels-in-imager/}). This algorithm generates superpixels by 73 | clustering pixels based on their color similarity and proximity in the image plane. 74 | Before running the SLIC method on the HE images we have noticed that some pre-processing can improve the 75 | masking significantly. 76 | First of all, a thresholding is applied to the image using a variant of Otsu's method (see \code{\link[imager]{threshold}}. 77 | Thereafter, you can select which color channels to use for the masking. it can be beneficial to remove 1 or two color channels from the image 78 | using \code{channels.use}. Specifying \code{channels.use = 1} will keep only the first channel before running SLIC. 79 | The next step is to apply some blurring efect on the image to "smooth" out speckles in the image. This 80 | "smoothing" effect can be adjusted with \code{iso.blur}, where a higher \code{iso.blur} leads to more smoothing. 81 | The compactness will adjust the number of superpixels to compute. If you double this number you will get twice 82 | as many superpixels. This can sometimes be helpful to get a finer sensitivity of the masking. 83 | } 84 | \section{Custom mask function}{ 85 | 86 | The `custom.msk.function` gives you the option to use your own masking function specifically designed for your 87 | images. The custom function has to take a "cimg" class image as input and return an object of class "pxset". 88 | } 89 | 90 | \section{Troubleshooting}{ 91 | 92 | Masking HE images is a non trivial problem as the tissue morphology comes in many different shapes and 93 | colors. The default masking algorithm can fail or perform poorly for a number of different reasons and 94 | below is a couple of examples of common problems. 95 | \itemize{ 96 | \item{ 97 | Bubbles and dirt - If you have air bubbles or other no tissue residue in you images, there is a risk that 98 | this will be picked up as tissue by the `MaskImages` function. The function uses the spotfile coordinates 99 | to define what region is outside or inside tissue, but if these are not provided, any part of the image 100 | picked up by the masking algorithm will be interpreted as relevant. If there is no way around this, you 101 | can mask the images manually using an image editing software before loading them into your Seurat object. 102 | } 103 | \item{ 104 | Tissue gets masked instead of background - If this happens, it probably means that your pixel coordinates provided 105 | in the spotfiles do not match the HE images provided. For example, if you've run the ST spot detector on a set of 106 | HE images, you have to provide these exact HE images when running `InputFromTable` or otherwise the pixel coordinates 107 | will be incorrect. 108 | } 109 | \item{ 110 | Parts of tissue gets masked - The masking algorithm relies on differencies in color intensity to segment out the tissue 111 | area. A common problem is that parts of your tissue is more similar to the background than the rest of the tissue, whcih 112 | typically happens for cell sparse tissue regions such as adipose tisse or connective tissue. If this happens you can try 113 | out different settings for the `thresholding`, `ìso.blur`, `channels.use`, `compactness` or `add.contrast` options or you might have to 114 | write your own masking function and pass it using the `custom.msk.fkn` option. 115 | } 116 | } 117 | } 118 | 119 | \examples{ 120 | \dontrun{ 121 | # Create a new Staffli object, mask and plot images 122 | st.obj <- CreateStaffliObject(imgs, meta.data) 123 | st.obj <- LoadImages(st.obj, verbose = TRUE) \%>\% MaskImages() 124 | plot(st.obj) 125 | } 126 | 127 | \dontrun{ 128 | # Load images into a Seurat objectm, mask and plot images 129 | se <- LoadImages(se, verbose = TRUE) \%>\% MaskImages() 130 | ImagePlot(se) 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /man/MergeSTData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{MergeSTData} 4 | \alias{MergeSTData} 5 | \title{Merge two or more Seurat objects containing Staffli image data} 6 | \usage{ 7 | MergeSTData( 8 | x = NULL, 9 | y = NULL, 10 | add.spot.ids = NULL, 11 | merge.data = TRUE, 12 | project = "SeuratProject", 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{x}{Seurat object} 18 | 19 | \item{y}{Seurat object (or list of multiple Seurat obejcts)} 20 | 21 | \item{add.spot.ids}{A character vector of length(x = c(x, y)). Appends the corresponding 22 | values to the start of each objects' spot names.} 23 | 24 | \item{merge.data}{Merge the data slots instead of just merging the counts (which requires renormalization). 25 | This is recommended if the same normalization approach was applied to all objects.} 26 | 27 | \item{project}{Sets the project name for the Seurat object.} 28 | 29 | \item{...}{Arguments passed to other methods} 30 | } 31 | \description{ 32 | Merges Seurat objects containing Spatial Transcriptomics data while 33 | making sure that the images and spot coordinates are correctly structures. 34 | If you use the default \code{\link{merge}} function you will not be able 35 | to use any of the STUtility visualization methods on the output object. 36 | } 37 | -------------------------------------------------------------------------------- /man/Merger.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pre_processing.R 3 | \name{Merger} 4 | \alias{Merger} 5 | \title{Merge expression matrices} 6 | \usage{ 7 | Merger(exp.list, delim = "x", labels = NULL, sparse.matrix.fmt = F) 8 | } 9 | \arguments{ 10 | \item{exp.list}{list of expression matrices} 11 | 12 | \item{delim}{delimiter used to separate coordinates in expression matrix headers} 13 | 14 | \item{labels}{labels to use as suffix for the headers of each expression matrix} 15 | 16 | \item{sparse.matrix.fmt}{return mergedexpression matrix in dgCMatrix format to save memory} 17 | } 18 | \value{ 19 | merged expression matrix 20 | } 21 | \description{ 22 | This function takes a list of expression matrices as input with ST spots in columns 23 | and genes in rows. All expression matrices will be merged into one matrix where all genes that are 24 | present in any of the expression matrices will be included. If a there are no counts available for 25 | a gene in one or more of the expression matrices, the counts for that gene will be set to 0 in those 26 | expression matrices. By default, a unique number will be prefixed to the headers of each expression 27 | matrix. 28 | } 29 | -------------------------------------------------------------------------------- /man/RegionNeighbours.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RegionNeighbours.R 3 | \name{RegionNeighbours} 4 | \alias{RegionNeighbours} 5 | \title{Autodetect region neighbours} 6 | \usage{ 7 | RegionNeighbours( 8 | object, 9 | id, 10 | column.key = "nbs_", 11 | keep.idents = FALSE, 12 | keep.within.id = FALSE, 13 | verbose = FALSE 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{Seurat object.} 18 | 19 | \item{id}{Group label used to define region, e.g. a cluster id. The region will be selected using the 20 | active identity (see `Idents`).} 21 | 22 | \item{column.key}{Sets the name of the column in the meta.data slot where the output is stored. [default: 'nbs_']} 23 | 24 | \item{keep.idents}{If set to TRUE, the identities of the neighbours are kept in the output, otherwise all 25 | neighbours will be named 'nbs_id' where id is the group label defined by the aprameter `ìd` [default: FALSE]} 26 | 27 | \item{keep.within.id}{If set to TRUE, all id spots are kept, otherwise only the spots with outside neighbours are kept} 28 | 29 | \item{verbose}{Print messages} 30 | } 31 | \description{ 32 | This function allows you to automatically identify neighbours of a selected region. 33 | } 34 | \details{ 35 | One way of using method this is to find spots surrounding a certain cluster. First, you need to make sure 36 | the identity of the Seurat object is set to the meta.data column that you want to use, so for example 37 | `se <- SetIdent(se, value = "seurat_clusters")` if you want to use the default seurat clusters. 38 | Then you select the label that defined the region of interest using the `id` parameter, so for example 39 | `ìd = "1"` will use cluster 1 as the region. If you set the `keep.idents` parameter to TRUE, the cluster ids 40 | of the neighbouring spots will be kept in the result, otherwise they will be returned as one single goup. 41 | You can also activate the `keep.within.id` parameter to include all spots of the selected region in the output, 42 | otherwise only the spots along the region border will be kept. 43 | } 44 | \examples{ 45 | \dontrun{ 46 | # Cluster data, find neighbours to cluster 10 and then plot the results 47 | se <- FindNeighbours(se) \%>\% FindClusters() 48 | se <- RegionNeighbours(se, id = 10) 49 | ST.FeaturePlot(se, features = "nbs_10") 50 | 51 | # Find neighbours to cluster 10 and keep all id spots 52 | se <- RegionNeighbours(se, id = 10) 53 | ST.FeaturePlot(se, features = "nbs_10", keep.within.id = TRUE) 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /man/RunNMF.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RunNMF.R 3 | \name{RunNMF} 4 | \alias{RunNMF} 5 | \title{Run Non-negative Matrix Factorization} 6 | \usage{ 7 | RunNMF( 8 | object, 9 | assay = NULL, 10 | slot = "scale.data", 11 | features = NULL, 12 | nfactors = 20, 13 | rescale = TRUE, 14 | reduction.name = "NMF", 15 | reduction.key = "factor_", 16 | n.cores = NULL, 17 | order.by.spcor = FALSE, 18 | sort.spcor.by.var = FALSE, 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{object}{Seurat object} 24 | 25 | \item{assay}{Assay Name of Assay NMF is being run on} 26 | 27 | \item{slot}{Slot to pull data from.} 28 | 29 | \item{features}{Features to compute the NMF for. Note that these features must be present in the 30 | slot used to compute the NMF. By default, the `features` is set to `VariableFeatures(object)` 31 | to include the most variable features selected in the normalization step.} 32 | 33 | \item{nfactors}{Total Number of factors to compute and store (20 by default)} 34 | 35 | \item{rescale}{Rescale data to make sure that values of the input matrix are non-n} 36 | 37 | \item{reduction.name}{Dimensional reduction name, "NMF" by default} 38 | 39 | \item{reduction.key}{Dimensional reduction key, specifies the prefix of the factor ids, e.g. 40 | "factor_1", "factor_2", etc.} 41 | 42 | \item{n.cores}{Number of threads to use in computation} 43 | 44 | \item{order.by.spcor}{Order factors by spatial correlation} 45 | 46 | \item{sort.spcor.by.var}{Sort factors by decreasing variance} 47 | 48 | \item{...}{Additional parameters} 49 | } 50 | \description{ 51 | Decompose an expression matrix A with non-negative elements into matrices WxH, also with 52 | non-negative elements. W is the feature loading matrix (features x factors) and H is the 53 | low dimensional embedding of the spots (factors x spots). 54 | } 55 | -------------------------------------------------------------------------------- /man/ST.ImagePlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization.R 3 | \name{ST.ImagePlot} 4 | \alias{ST.ImagePlot} 5 | \title{Graphs ST spots colored by continuous variable, e.g. dimensional reduction vector} 6 | \usage{ 7 | ST.ImagePlot( 8 | data, 9 | data.type, 10 | variable, 11 | image, 12 | dims, 13 | pt.size = 2, 14 | pt.alpha = 1, 15 | pt.border = FALSE, 16 | add.alpha = FALSE, 17 | palette = "MaYl", 18 | cols = NULL, 19 | ncol = NULL, 20 | spot.colors = NULL, 21 | center.zero = TRUE, 22 | plot.title = NULL, 23 | dark.theme = FALSE, 24 | pixels.per.um = NULL, 25 | limits = NULL, 26 | label.by = NULL, 27 | ... 28 | ) 29 | } 30 | \arguments{ 31 | \item{data}{Object of class 'data.frame' containing at least (x, y) coordinates, a "sample" vector with labels for each sample 32 | and one column with the feature values. Can also include an additional column for shapes.} 33 | 34 | \item{data.type}{String specifying the class of the features in data to be plotted} 35 | 36 | \item{variable}{Name of feature column} 37 | 38 | \item{image}{Image of class "raster" to use as background for plotting} 39 | 40 | \item{dims}{List of dimensions for original images. This list has to contain one element for each sample and each element 41 | should be a vector of length 2 specifying the dimensions of the original HE image.} 42 | 43 | \item{pt.size}{Point size of each ST spot [default: 1]} 44 | 45 | \item{pt.alpha}{Opacity of each ST spot [default: 1]} 46 | 47 | \item{pt.border}{Should a border be drawn around the spots? [default: TRUE]} 48 | 49 | \item{add.alpha}{Scale spot opacity by selected feature. Higher values get more opaque while lower values make spots transparent.} 50 | 51 | \item{palette}{Color palette used for spatial heatmap (see \code{palette.select(info = T)} for available options). 52 | Disabled if a color vector is provided (see \code{cols} below).} 53 | 54 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 55 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 56 | option.} 57 | 58 | \item{ncol}{Number of columns to arrange the samples into. This can for example be useful to adjust if you want to visualize the samples 59 | in just in one row or one column.} 60 | 61 | \item{spot.colors}{Character vector with color names that overrides default coloring with ggplot2} 62 | 63 | \item{center.zero}{Specifies whther or not the colorscale should be centered around 0. For some values, such as Principal Component vectors, 64 | the distribution of values is centered at 0 and in that case it can be appropriate to use a divergent colorscale with a predefined value for 0. 65 | If this parameter is set to TRUE, the ggplot2 function \code{scale_color_gradient2} will be used to control the coloring instead of 66 | \code{scale_color_gradientn}. If center.zero is set to FALSE, the colorscale will simply map the values in equally spaced intervals which could skew 67 | the interpretaion of the output plot.} 68 | 69 | \item{plot.title}{String specifying the title of the plot} 70 | 71 | \item{dark.theme}{Switches color of scalebar to 'white'} 72 | 73 | \item{pixels.per.um}{Defines the number of pixels per micrometer to draw the scale bar} 74 | 75 | \item{limits}{Sets the limits of the colorbar} 76 | 77 | \item{label.by}{Feature to relabel facets by. By default, facets are given a unique section number ranging grom 1 to the number of sections 78 | available in the `Staffli` object. If you want to relabel these facets you can pass the name of a column that keeps the labels that you 79 | want to use. For example, if you wish to rename the facets to use labels defined by a charcater vector in column "section_id" in your 80 | meta.data slot, you can pass `label.by = "section_id"` to relabel the facets. Only works for categorical group variables with where the 81 | number of groups is less than or equal to the number of tissue sections in your Staffli object.} 82 | 83 | \item{...}{Parameters passed to geom_point()} 84 | } 85 | \description{ 86 | Graphs ST spots colored by continuous variable, e.g. dimensional reduction vector 87 | } 88 | -------------------------------------------------------------------------------- /man/ST.rgbDimPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{ST.rgbDimPlot} 4 | \alias{ST.rgbDimPlot} 5 | \title{Store rgb values after ST.Dimplot 6 | OBS! could be merged with ST.Dimplot?} 7 | \usage{ 8 | ST.rgbDimPlot(plotObj) 9 | } 10 | \arguments{ 11 | \item{plotObj}{A ST.DimPlot output object} 12 | } 13 | \description{ 14 | Store rgb values after ST.Dimplot 15 | OBS! could be merged with ST.Dimplot? 16 | } 17 | -------------------------------------------------------------------------------- /man/STPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization.R 3 | \name{STPlot} 4 | \alias{STPlot} 5 | \title{Graphs ST spots colored by continuous or categorical features} 6 | \usage{ 7 | STPlot( 8 | data, 9 | data.type = NULL, 10 | variable, 11 | pt.size = 1, 12 | pt.alpha = 1, 13 | pt.border = FALSE, 14 | palette = "MaYl", 15 | cols = NULL, 16 | ncol = NULL, 17 | spot.colors = NULL, 18 | center.zero = TRUE, 19 | center.tissue = FALSE, 20 | plot.title = NULL, 21 | dims = NULL, 22 | split.labels = FALSE, 23 | pxum = NULL, 24 | sb.size = 2.5, 25 | dark.theme = FALSE, 26 | limits = NULL, 27 | label.by = NULL, 28 | ... 29 | ) 30 | } 31 | \arguments{ 32 | \item{data}{Object of class 'data.frame' containing at least (x, y) coordinates, a "sample" vector with labels for each sample 33 | and one column with the feature values. Can also include an additional column for shapes.} 34 | 35 | \item{data.type}{String specifying the class of the features in data to be plotted} 36 | 37 | \item{variable}{Name of feature column} 38 | 39 | \item{pt.size}{Point size of each ST spot [default: 1]} 40 | 41 | \item{pt.alpha}{Opacity of each ST spot [default: 1]} 42 | 43 | \item{pt.border}{Should a border be drawn around the spots? [default: TRUE]} 44 | 45 | \item{palette}{Color palette used for spatial heatmap (see \code{palette.select(info = T)} for available options). 46 | Disabled if a color vector is provided (see \code{cols} below).} 47 | 48 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 49 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 50 | option.} 51 | 52 | \item{ncol}{Number of columns to arrange the samples into. This can for example be useful to adjust if you want to visualize the samples 53 | in just in one row or one column.} 54 | 55 | \item{spot.colors}{Character vector with color names that overrides default coloring with ggplot2} 56 | 57 | \item{center.zero}{Specifies whther or not the colorscale should be centered around 0. For some values, such as Principal Component vectors, 58 | the distribution of values is centered at 0 and in that case it can be appropriate to use a divergent colorscale with a predefined value for 0. 59 | If this parameter is set to TRUE, the ggplot2 function \code{scale_color_gradient2} will be used to control the coloring instead of 60 | \code{scale_color_gradientn}. If center.zero is set to FALSE, the colorscale will simply map the values in equally spaced intervals which could skew 61 | the interpretaion of the output plot.} 62 | 63 | \item{center.tissue}{Adjust coordinates so that the center of the tissue is in the middle of the array along the y-axis. This can be useful if your 64 | samples have been placed in very different parts of the capture area and you want to center the plots in the middle. This is however unnecessary if 65 | you have already aligned the sample data (see \code{\link{AlignImages}}, \code{\link{WarpImages}} and \code{\link{ManualAlignImages}})} 66 | 67 | \item{plot.title}{String specifying the title of the plot} 68 | 69 | \item{dims}{List of dimensions for x and y scales. If you have mixed datasets from different arrays (platforms) with different resolution, 70 | this list of dimensions will be used to specify the limits along the x- and y-axis of the array for each sample.} 71 | 72 | \item{split.labels}{Only works if the features are specified by character vectors. 73 | The plot will be split into one plot for each group label, highlighting the labelled spots.} 74 | 75 | \item{pxum}{A data.frame object with columns for 'x', 'xend', 'y' and 'sample' 76 | used for facetted plots.} 77 | 78 | \item{sb.size}{Defines the size of the scalebar} 79 | 80 | \item{dark.theme}{Switches color of scalebar to 'white'} 81 | 82 | \item{limits}{Sets the range of the colorbar values} 83 | 84 | \item{label.by}{Feature to relabel facets by. By default, facets are given a unique section number ranging grom 1 to the number of sections 85 | available in the `Staffli` object. If you want to relabel these facets you can pass the name of a column that keeps the labels that you 86 | want to use. For example, if you wish to rename the facets to use labels defined by a charcater vector in column "section_id" in your 87 | meta.data slot, you can pass `label.by = "section_id"` to relabel the facets. Only works for categorical group variables with where the 88 | number of groups is less than or equal to the number of tissue sections in your Staffli object.} 89 | 90 | \item{...}{Parameters passed to geom_point()} 91 | } 92 | \description{ 93 | Graphs ST spots colored by continuous or categorical features 94 | } 95 | -------------------------------------------------------------------------------- /man/STutility-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/QC.R, R/manual_annotation.R, 3 | % R/pre_processing.R, R/process_from_table.R 4 | \docType{package} 5 | \name{STutility-package} 6 | \alias{STutility} 7 | \alias{STutility-package} 8 | \title{STutility: Analysis and visualization of Spatial Transcriptomics data} 9 | \description{ 10 | STutility collects useful tools for Spatial Transcriptomics data analysis within R. The package is built on top of popular Seurat R package, which is a toolkit for analysis and exploration of single cell RNA sequencing data (scRNAseq). STutility adds image functionallity to the Seurat workflow, allowing RNAseq data to be put in a spatial tissue context. Tutorials for data transformation, QC, analysis and visualization can be found on our website: https://ludvigla.github.io/STUtility_web_site/. 11 | 12 | STutility collects useful tools for Spatial Transcriptomics data analysis within R. The package is built on top of popular Seurat R package, which is a toolkit for analysis and exploration of single cell RNA sequencing data (scRNAseq). STutility adds image functionallity to the Seurat workflow, allowing RNAseq data to be put in a spatial tissue context. Tutorials for data transformation, QC, analysis and visualization can be found on our website: https://ludvigla.github.io/STUtility_web_site/. 13 | 14 | STutility collects useful tools for Spatial Transcriptomics data analysis within R. The package is built on top of popular Seurat R package, which is a toolkit for analysis and exploration of single cell RNA sequencing data (scRNAseq). STutility adds image functionallity to the Seurat workflow, allowing RNAseq data to be put in a spatial tissue context. Tutorials for data transformation, QC, analysis and visualization can be found on our website: https://ludvigla.github.io/STUtility_web_site/. 15 | 16 | STutility collects useful tools for Spatial Transcriptomics data analysis within R. The package is built on top of popular Seurat R package, which is a toolkit for analysis and exploration of single cell RNA sequencing data (scRNAseq). STutility adds image functionallity to the Seurat workflow, allowing RNAseq data to be put in a spatial tissue context. Tutorials for data transformation, QC, analysis and visualization can be found on our website: https://ludvigla.github.io/STUtility_web_site/. 17 | } 18 | \author{ 19 | \strong{Maintainer}: Ludvig Larsson \email{ludvig.larsson@scilifelab.se} 20 | 21 | Authors: 22 | \itemize{ 23 | \item Joseph Bergenstraahle 24 | } 25 | 26 | 27 | \strong{Maintainer}: Ludvig Larsson \email{ludvig.larsson@scilifelab.se} 28 | 29 | Authors: 30 | \itemize{ 31 | \item Joseph Bergenstraahle 32 | } 33 | 34 | 35 | \strong{Maintainer}: Ludvig Larsson \email{ludvig.larsson@scilifelab.se} 36 | 37 | Authors: 38 | \itemize{ 39 | \item Joseph Bergenstraahle 40 | } 41 | 42 | 43 | \strong{Maintainer}: Ludvig Larsson \email{ludvig.larsson@scilifelab.se} 44 | 45 | Authors: 46 | \itemize{ 47 | \item Joseph Bergenstraahle 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /man/SetQuantile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{SetQuantile} 4 | \alias{SetQuantile} 5 | \title{Find the quantile of a data} 6 | \usage{ 7 | SetQuantile(cutoff, data) 8 | } 9 | \arguments{ 10 | \item{cutoff}{The cutoff to turn into a quantile} 11 | 12 | \item{data}{The data to find the quantile of} 13 | } 14 | \value{ 15 | The numerical representation of the quantile 16 | } 17 | \description{ 18 | Converts a quantile in character form to a number regarding some data 19 | String form for a quantile is represented as a number prefixed with 'q' 20 | For example, 10th quantile is 'q10' while 2nd quantile is 'q2' 21 | } 22 | \details{ 23 | Will only take a quantile of non-zero data values 24 | } 25 | \references{ 26 | \url{https://github.com/satijalab/seurat/blob/master/R/visualization.R} 27 | } 28 | -------------------------------------------------------------------------------- /man/SmoothPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization.R 3 | \name{SmoothPlot} 4 | \alias{SmoothPlot} 5 | \title{Graphs a smooth interpolation heatmap colored by continuous variable, e.g. dimensional reduction vector} 6 | \usage{ 7 | SmoothPlot( 8 | st.object, 9 | data, 10 | image.type, 11 | data.type = NULL, 12 | variable, 13 | palette = "MaYl", 14 | cols = NULL, 15 | ncol = NULL, 16 | center.zero = TRUE, 17 | dark.theme = FALSE, 18 | highlight.edges = TRUE, 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{st.object}{A Staffli object} 24 | 25 | \item{data}{Object of class 'data.frame' containing at least (x, y) coordinates, a "sample" vector with labels for each sample 26 | and one column with the feature values. Can also include an additional column for shapes.} 27 | 28 | \item{image.type}{Specifies the image is "processed", otherwise NULL} 29 | 30 | \item{data.type}{String specifying the class of the features in data to be plotted} 31 | 32 | \item{variable}{Name of feature column} 33 | 34 | \item{palette}{Color palette used for spatial heatmap (see \code{palette.select(info = T)} for available options). 35 | Disabled if a color vector is provided (see \code{cols} below).} 36 | 37 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 38 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 39 | option.} 40 | 41 | \item{ncol}{Number of columns to arrange the samples into. This can for example be useful to adjust if you want to visualize the samples 42 | in just in one row or one column.} 43 | 44 | \item{center.zero}{Specifies whther or not the colorscale should be centered around 0. For some values, such as Principal Component vectors, 45 | the distribution of values is centered at 0 and in that case it can be appropriate to use a divergent colorscale with a predefined value for 0. 46 | If this parameter is set to TRUE, the ggplot2 function \code{scale_color_gradient2} will be used to control the coloring instead of 47 | \code{scale_color_gradientn}. If center.zero is set to FALSE, the colorscale will simply map the values in equally spaced intervals which could skew 48 | the interpretaion of the output plot.} 49 | 50 | \item{dark.theme}{Switches color of scalebar to 'white'} 51 | 52 | \item{highlight.edges}{Should edges be highlighted? [default: TRUE]} 53 | 54 | \item{...}{Parameters passed to geom_point()} 55 | } 56 | \description{ 57 | Graphs a smooth interpolation heatmap colored by continuous variable, e.g. dimensional reduction vector 58 | } 59 | -------------------------------------------------------------------------------- /man/Staffli-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \docType{class} 4 | \name{Staffli-class} 5 | \alias{Staffli-class} 6 | \alias{Staffli} 7 | \title{The Staffli Class} 8 | \description{ 9 | The Staffli object is a representation of images for Spatial Transcriptomics experiments 10 | that contains lists of scaled images in raster format and coordinates for the corresponding 11 | spots that can be used to map expression data onto the images. 12 | } 13 | \section{Slots}{ 14 | 15 | \describe{ 16 | \item{\code{imgs}}{A character vector of paths to the raw HE images.} 17 | 18 | \item{\code{rasterlists}}{A list of lists containing images in 'raster' format} 19 | 20 | \item{\code{scatter.data}}{Data.frame holding x, y, z coordinates for 3D interpolation and visualization} 21 | 22 | \item{\code{transformations}}{A list of 3x3 transformation matrices used to transform (x,y)-coordinates 23 | of an aligned image to a reference image.} 24 | 25 | \item{\code{meta.data}}{Contains meta-information about each spot, starting with regular (x,y)-coordinates 26 | found in the headers of gene-count matrices obtained with the ST method. The meta.data 27 | can also contain (adj_x, adj_y)-coordinates which are defined in the same grid but adjusted using the 28 | ST spot detector and (pixel_x, pixel_y)-coordinates which are defined in the coordinate system of the 29 | original image. Finally, a "sample" column is used to group the spots by image (capture area).} 30 | 31 | \item{\code{xdim}}{The width of the scaled images in pixels.} 32 | 33 | \item{\code{limits}}{Specifies the limits of the array (e.g. limits = c(100, 100) means that the array 34 | is a 100 spots wide and a 100 spots high)} 35 | 36 | \item{\code{dims}}{List of numerical vectors specifying the dimensions of the original images.} 37 | 38 | \item{\code{platforms}}{Specify the platform used to generate the ST data [options: 'Visium', '2k', '1k']} 39 | 40 | \item{\code{samplenames}}{Character specifying the samplenames.} 41 | 42 | \item{\code{pixels.per.um}}{Numeric vector specifying the number of pixels per micron} 43 | 44 | \item{\code{version}}{Package version.} 45 | }} 46 | 47 | -------------------------------------------------------------------------------- /man/Staffli-get-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{[[,Staffli,ANY,ANY-method} 4 | \alias{[[,Staffli,ANY,ANY-method} 5 | \alias{`[[`,Staffli,Staffli-method} 6 | \alias{[,Staffli,ANY,ANY,ANY-method} 7 | \alias{`[`,Staffli,Staffli-method} 8 | \title{Method used to get meta data from a Staffli object} 9 | \usage{ 10 | \S4method{[[}{Staffli,ANY,ANY}(x, i, j, drop = F) 11 | 12 | \S4method{[}{Staffli,ANY,ANY,ANY}(x, i) 13 | } 14 | \arguments{ 15 | \item{x}{Staffli bject from which to get image from.} 16 | 17 | \item{i}{index for image to get.} 18 | 19 | \item{j}{column indices specifying elements to extract.} 20 | 21 | \item{drop}{If TRUE the result is coerced to the lowest possible dimension. 22 | This only works for extracting elements, not for the replacement.} 23 | } 24 | \description{ 25 | Method used to get meta data from a Staffli object 26 | 27 | Method used to get list of scaled images 28 | from selected type 29 | } 30 | -------------------------------------------------------------------------------- /man/Staffli-set-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{[[<-,Staffli,ANY,ANY-method} 4 | \alias{[[<-,Staffli,ANY,ANY-method} 5 | \alias{`[[<-`,Staffli,Staffli-method} 6 | \alias{[<-,Staffli,ANY,ANY,ANY-method} 7 | \alias{`[<-`,Staffli,Staffli-method} 8 | \title{Method used to set meta data in a Staffli object} 9 | \usage{ 10 | \S4method{[[}{Staffli,ANY,ANY}(x, i, j, ...) <- value 11 | 12 | \S4method{[}{Staffli,ANY,ANY,ANY}(x, i, j, ...) <- value 13 | } 14 | \arguments{ 15 | \item{x}{Staffli object in which to replace image.} 16 | 17 | \item{i}{index for image to replace.} 18 | 19 | \item{j}{column indices specifying elements to replace.} 20 | 21 | \item{...}{additional parameters} 22 | 23 | \item{value}{Data to add to meta data data.frame.} 24 | } 25 | \description{ 26 | Method used to set meta data in a Staffli object 27 | 28 | Method used to set list of scaled images 29 | of selected type 30 | } 31 | -------------------------------------------------------------------------------- /man/SubsetSTData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{SubsetSTData} 4 | \alias{SubsetSTData} 5 | \title{Subset a Seurat object containing Staffli image data} 6 | \usage{ 7 | SubsetSTData( 8 | object, 9 | expression, 10 | spots = NULL, 11 | features = NULL, 12 | idents = NULL, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{A Seurat object containing Staffli data} 18 | 19 | \item{expression}{Logical expression indicating features/variables to keep} 20 | 21 | \item{spots}{A vector of spots to keep} 22 | 23 | \item{features}{A vector of features to keep} 24 | 25 | \item{idents}{A vector of identity classes to keep} 26 | 27 | \item{...}{Extra parameters passed to WhichCells, such as slot, invert, or downsample} 28 | } 29 | \description{ 30 | Subsets a Seurat object containing Spatial Transcriptomics data while 31 | making sure that the images and the spot coordinates are subsetted correctly. 32 | If you use the default \code{\link{subset}} function there is a risk that images 33 | are kept in the output Seurat object which will make the STUtility functions 34 | crash. 35 | } 36 | \examples{ 37 | \dontrun{ 38 | # Subset using meta data to keep spots with more than 1000 unique genes 39 | se.subset <- SubsetSTData(se, expression = nFeature_RNA >= 1000) 40 | 41 | # Subset by a predefined set of spots 42 | se.subset <- SubsetSTData(se, spots = keep.spots) 43 | 44 | # Subset by a predefined set of features 45 | se.subset <- SubsetSTData(se, features = keep.features) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /man/SummarizeAssocFeatures.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RunNMF.R 3 | \name{SummarizeAssocFeatures} 4 | \alias{SummarizeAssocFeatures} 5 | \title{Summarize features associated with cselected factors} 6 | \usage{ 7 | SummarizeAssocFeatures( 8 | object, 9 | dims = NULL, 10 | features.return = 10, 11 | features.use = NULL 12 | ) 13 | } 14 | \arguments{ 15 | \item{object}{Seurat object} 16 | 17 | \item{dims}{Factors to use} 18 | 19 | \item{features.return}{Number of features to return per factor} 20 | 21 | \item{features.use}{Select features (genes) to subset the data on} 22 | } 23 | \description{ 24 | Extracts the top driving features per factor and returns 25 | } 26 | -------------------------------------------------------------------------------- /man/SwitchResolution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Image_resolution_switch.R 3 | \name{SwitchResolution} 4 | \alias{SwitchResolution} 5 | \title{Function used to reload images in different quality and apply image transformations} 6 | \usage{ 7 | SwitchResolution(object, xdim, reference.index = 1, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{object}{Seurat object} 11 | 12 | \item{xdim}{Sets the pixel width for scaling, e.g. 400 (maximum allowed width is 2000 pixels)} 13 | 14 | \item{reference.index}{Set reference image used for image alignment. This should be the same the reference.index 15 | used for \code{\link{AlignImages}} or \code{\link{ManualAlignImages}}.} 16 | 17 | \item{verbose}{Print messages} 18 | } 19 | \description{ 20 | If you want to use histological images in your analyses the recommendation is to 21 | load them in low resolution (default 400 pixels width) and apply any transformations 22 | that you want, e.g. masking and alignment. Then, whenever you need to increase the 23 | resolution of your images you can use this function to reload higher resolution 24 | versions of the same images and apply the same transformations. 25 | } 26 | \details{ 27 | Masking and alignment has been optimized for small images and will be significanlty slower 28 | for images of higher resolution. For this reson we recommend users to use this function 29 | instead. 30 | } 31 | \examples{ 32 | \dontrun{ 33 | # Create Seurat object, load, mask and align images at low resolution 34 | se <- InputFromTable(infoTable) \%>\% 35 | LoadImages() \%>\% 36 | MaskImages() \%>\% 37 | AlignImages() 38 | 39 | # Reload images and apply transformations to higher resolution images, e.g. 2000 pixels width 40 | se <- SwitchResolution(se, 2000) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/Warp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{Warp} 4 | \alias{Warp} 5 | \title{Apply warping of x, y coordinates using a affine transformation function} 6 | \usage{ 7 | Warp(im, map.rot, mask = FALSE) 8 | } 9 | \arguments{ 10 | \item{im}{Raster image} 11 | 12 | \item{map.rot}{Affine transformation function, see \code{\link{generate.map.rot}}} 13 | 14 | \item{mask}{Returns image as a mask} 15 | } 16 | \description{ 17 | Apply warping of x, y coordinates using a affine transformation function 18 | } 19 | -------------------------------------------------------------------------------- /man/WarpImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/image_processing.R 3 | \name{WarpImages} 4 | \alias{WarpImages} 5 | \alias{WarpImages.Staffli} 6 | \alias{WarpImages.Seurat} 7 | \title{Warps images using various transformations} 8 | \usage{ 9 | WarpImages(object, transforms, verbose) 10 | 11 | \method{WarpImages}{Staffli}(object, transforms, verbose = FALSE) 12 | 13 | \method{WarpImages}{Seurat}(object, transforms, verbose = FALSE) 14 | } 15 | \arguments{ 16 | \item{object}{Seurat object} 17 | 18 | \item{transforms}{List of arguments passed to warp function. The available options are 19 | "angle" [numeric], "mirror.x" [logical], "mirror.y" [logical], "shift.x" [numeric]and "shift.y" [numeric].} 20 | 21 | \item{verbose}{Print messages} 22 | } 23 | \value{ 24 | Seurat object with processed imaged 25 | 26 | A Staffli object 27 | 28 | A Seurat object 29 | } 30 | \description{ 31 | This function can be used to apply rigid transformations on masked images including; 32 | rotations, reflections and translations. See details below for more information. 33 | } 34 | \details{ 35 | The transformations are controlled by specifying verious rigid transformations 36 | for each sample using the transforms variable. The transforms variable should be a 37 | named list of lists with one element for each sample that you want to apply a transformation 38 | on. For example, if you want to rotate sample 1 90 degrees clockwise and reflect sample 2 39 | along its x axis you can pass `transforms <- list("1" = list("angle" = 90), "2" = list("mirror.x" = TRUE))`. 40 | When multiple transformations are passed, they are applied in the following order; 41 | rotation -> reflection -> translation. 42 | } 43 | \examples{ 44 | \dontrun{ 45 | # Create a new Staffli object, mask, warp and plot images 46 | st.obj <- CreateStaffliObject(imgs, meta.data) 47 | transforms <- list("2" = list("mirror.y" = TRUE)) 48 | st.obj <- LoadImages(st.obj, verbose = TRUE) \%>\% MaskImages() \%>\% WarpImages(transforms) 49 | plot(st.obj) 50 | } 51 | \dontrun{ 52 | # Load, mask, warp and plot images in a Seurat object 53 | # Mirror y axis in sample '2' and rotate sample '3' 10 degrees 54 | transforms <- list("2" = list("mirror.y" = TRUE), "3" = list("angle" = 10)) 55 | se <- LoadImages(se, verbose = TRUE) \%>\% MaskImages() \%>\% WarpImages(transforms) 56 | ImagePlot(se) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /man/add.margins.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{add.margins} 4 | \alias{add.margins} 5 | \title{Function used to add whitespace to image} 6 | \usage{ 7 | add.margins(rst) 8 | } 9 | \arguments{ 10 | \item{rst}{Raster image} 11 | } 12 | \description{ 13 | This function adds whitespace to a raster image and forces the height/width 14 | to be equal to the image diagonal. This way you can ensure that no part of the tissue 15 | is cropped after a rotation transformation 16 | } 17 | -------------------------------------------------------------------------------- /man/apply.transform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R, 3 | % R/image_processing_utilities.R 4 | \name{apply.transform} 5 | \alias{apply.transform} 6 | \title{Apply rigid transformation to a set of points} 7 | \usage{ 8 | apply.transform(map, set) 9 | 10 | apply.transform(map, set) 11 | } 12 | \arguments{ 13 | \item{map}{List containing transformation matrices} 14 | 15 | \item{set}{Matrix of x, y coordinates to be transformed} 16 | } 17 | \value{ 18 | Matrix of transformed x, y coordinates 19 | 20 | Matrix of transformed x, y coordinates 21 | } 22 | \description{ 23 | Takes a list obtained with \code{\link{find.optimal.transform}} and 24 | a matrix of x, y coordinates and returns the transformed x, y coordinates 25 | 26 | Takes a list of obtained with \code{\link{find.optimal.transform}} and 27 | a matrix of x, y coordinates and returns the transformed x, y coordinates 28 | } 29 | -------------------------------------------------------------------------------- /man/combine.tr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{combine.tr} 4 | \alias{combine.tr} 5 | \title{Combines rigid tranformation matrices} 6 | \usage{ 7 | combine.tr(center.cur, center.new, alpha, mirror.x = FALSE, mirror.y = FALSE) 8 | } 9 | \arguments{ 10 | \item{center.cur}{(x, y) image pixel coordinates specifying the current center of the tissue (stored in slot "tools" as "centers")} 11 | 12 | \item{center.new}{(x, y) image pixel coordinates specifying the new center (image center)} 13 | 14 | \item{alpha}{Rotation angle} 15 | 16 | \item{mirror.x}{Logical: mirrors x or y axis if set to TRUE} 17 | 18 | \item{mirror.y}{Logical: mirrors x or y axis if set to TRUE} 19 | } 20 | \description{ 21 | Combines rigid tranformation matrices in the following order: 22 | translation of points to origin (0, 0) -> reflection of points 23 | -> rotation by alpha degrees and translation of points to new center 24 | } 25 | \examples{ 26 | \dontrun{ 27 | library(imager) 28 | library(tidyverse) 29 | im <- load.image("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Aster_Tataricus.JPG/1024px-Aster_Tataricus.JPG") 30 | d <- sRGBtoLab(im) \%>\% as.data.frame(wide="c")\%>\% 31 | dplyr::select(-x,-y) 32 | 33 | km <- kmeans(d, 2) 34 | 35 | # Run a segmentation to extract flower 36 | seg <- as.cimg(abs(km$cluster - 2), dim = c(dim(im)[1:2], 1, 1)) 37 | plot(seg); highlight(seg == 1) 38 | 39 | # Detect edges 40 | dx <- imgradient(seg, "x") 41 | dy <- imgradient(seg, "y") 42 | grad.mag <- sqrt(dx^2 + dy^2) 43 | plot(grad.mag) 44 | 45 | # Extract points at edges 46 | edges.px <- which(grad.mag > max(grad.mag[, , 1, 1])/2, arr.ind = TRUE) 47 | points(edges.px, col = "green", cex = 0.1) 48 | 49 | # Apply transformations to point set 50 | tr1 <- combine.tr(center.cur = apply(edges.px[, 1:2], 2, mean), 51 | center.new = c(1200, 1200), alpha = 90) 52 | tr2 <- combine.tr(center.cur = apply(edges.px[, 1:2], 2, mean), 53 | center.new = c(500, 1200), mirror.x = T, alpha = 30) 54 | tr3 <- combine.tr(center.cur = apply(edges.px[, 1:2], 2, mean), 55 | center.new = c(1200, 500), mirror.y = T, alpha = 270) 56 | plot(edges.px, xlim = c(0, 1700), ylim = c(0, 1700), cex = 0.1) 57 | points(t(tr1\%*\%t(edges.px[, 1:3])), cex = 0.1, col = "red") 58 | points(t(tr2\%*\%t(edges.px[, 1:3])), cex = 0.1, col = "yellow") 59 | points(t(tr3\%*\%t(edges.px[, 1:3])), cex = 0.1, col = "blue") 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /man/create.array.from.feature.vals.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HSVencoding.R 3 | \name{create.array.from.feature.vals} 4 | \alias{create.array.from.feature.vals} 5 | \title{Creates an array of dimensions number_of_spots*3*number_of_features} 6 | \usage{ 7 | create.array.from.feature.vals( 8 | data, 9 | features, 10 | hue_breaks, 11 | cols, 12 | dark.theme, 13 | verbose 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{data.frame with feature values} 18 | 19 | \item{features}{feature names} 20 | 21 | \item{hue_breaks}{Hue values (same length as features)} 22 | 23 | \item{cols}{Custom colors} 24 | 25 | \item{dark.theme}{Used to select what channel the feature values should be encoded in} 26 | 27 | \item{verbose}{Print messages} 28 | } 29 | \description{ 30 | For each feature, a matrix is stored with nSpots number of rows and 31 | with the HSV color channels as columns. If dark.theme is set to TRUE, 32 | the V channel will be reserved for feature values and the S channel will 33 | be set to 1, otherwise the S channel will be resevred for feature values 34 | and the V channel will be set to 1. 35 | } 36 | -------------------------------------------------------------------------------- /man/create.cols.from.array.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HSVencoding.R 3 | \name{create.cols.from.array} 4 | \alias{create.cols.from.array} 5 | \title{Creates HSV colors from an array} 6 | \usage{ 7 | create.cols.from.array( 8 | data, 9 | d, 10 | features, 11 | cols, 12 | split.hsv, 13 | dark.theme, 14 | add.alpha 15 | ) 16 | } 17 | \arguments{ 18 | \item{data}{data.frame with feature values} 19 | 20 | \item{d}{array created with \code{create.array.from.vals} function} 21 | 22 | \item{features}{Feature names} 23 | 24 | \item{cols}{Custom colors} 25 | 26 | \item{split.hsv}{Should the features be plotted separately?} 27 | 28 | \item{dark.theme}{Used to select what channel the feature values should be encoded in} 29 | 30 | \item{add.alpha}{Adds opacity to the output colors, defined by the scaled feature values} 31 | } 32 | \description{ 33 | If split.hsv = FALSE, the feature with the highest value in a spot will define the 34 | color for that spot. The intensity of the color will depend on if dark.theme is active and 35 | the magnitude of the feature value in that spot. 36 | } 37 | -------------------------------------------------------------------------------- /man/cscale.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3D_viusalization.R 3 | \name{cscale} 4 | \alias{cscale} 5 | \title{Create a plotly compatible colorscale} 6 | \usage{ 7 | cscale(cols) 8 | } 9 | \arguments{ 10 | \item{cols}{Vector of colors} 11 | } 12 | \description{ 13 | Create a plotly compatible colorscale 14 | } 15 | -------------------------------------------------------------------------------- /man/dark_theme.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{dark_theme} 4 | \alias{dark_theme} 5 | \title{Generates a dark theme for STPlot} 6 | \usage{ 7 | dark_theme() 8 | } 9 | \description{ 10 | Generates a dark theme for STPlot 11 | } 12 | -------------------------------------------------------------------------------- /man/draw_scalebar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{draw_scalebar} 4 | \alias{draw_scalebar} 5 | \title{Draws a scalebar for ST plots} 6 | \usage{ 7 | draw_scalebar( 8 | p, 9 | x = NULL, 10 | xend = NULL, 11 | y = NULL, 12 | pxum = NULL, 13 | sb.size = 2.5, 14 | dark.theme = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{p}{An object of class 'ggplot'} 19 | 20 | \item{x, xend}{The start and positions of the scalebar along the x axis.} 21 | 22 | \item{y}{The position of the scalebar along the y axis.} 23 | 24 | \item{pxum}{A data.frame object with columns for 'x', 'xend', 'y' and 'sample' 25 | used for facetted plots.} 26 | 27 | \item{sb.size}{Size of scalebar} 28 | 29 | \item{dark.theme}{Switches color of scalebar to 'white'} 30 | } 31 | \value{ 32 | An object of class 'ggplot' with a scalebar drawn on top of it 33 | } 34 | \description{ 35 | Takes a ggplot object as input together with some additional parameters 36 | specifying the position and widht of a scalebar representing the actual 37 | width of corresponding 500um in the plot. The actual width of the scale 38 | bar is determined by the x, xend parameters and has to be calulated 39 | separately. To do this, you can use the pixels.per.um slot of the 40 | `Staffli` object. 41 | } 42 | -------------------------------------------------------------------------------- /man/facet_wrap_custom.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/facet_grid_SC.R 3 | \name{facet_wrap_custom} 4 | \alias{facet_wrap_custom} 5 | \title{Custom facet wrap function} 6 | \usage{ 7 | facet_wrap_custom(..., scale_overrides = NULL) 8 | } 9 | \arguments{ 10 | \item{...}{Parameters which can be passed to \code{facet_wrap}} 11 | 12 | \item{scale_overrides}{List of "scale_override" objects} 13 | } 14 | \description{ 15 | Custom facet wrap function 16 | } 17 | -------------------------------------------------------------------------------- /man/feature.scaler.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{feature.scaler} 4 | \alias{feature.scaler} 5 | \title{Function used to scale numerical features} 6 | \usage{ 7 | feature.scaler(data, features, min.cutoff, max.cutoff) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame containing x, y coordinates and columns with numerical features} 11 | 12 | \item{features}{feature names} 13 | 14 | \item{min.cutoff, max.cutoff}{Vector of minimum and maximum cutoff values for each feature, 15 | may specify quantile in the form of 'q##' where '##' is the quantile (eg, 'q1', 'q10')} 16 | } 17 | \description{ 18 | Function used to scale numerical features 19 | } 20 | -------------------------------------------------------------------------------- /man/find.optimal.transform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{find.optimal.transform} 4 | \alias{find.optimal.transform} 5 | \title{Finds optimal transform based on RMSE} 6 | \usage{ 7 | find.optimal.transform(set1, set2, xdim, ydim) 8 | } 9 | \arguments{ 10 | \item{set1, set2}{Point set from image to be aligned with reference and point set from reference image} 11 | 12 | \item{xdim, ydim}{Width and height of image} 13 | } 14 | \value{ 15 | list with the list of tranformation matrices, reflection coordinates and rmse score 16 | for the optimal transformation 17 | } 18 | \description{ 19 | Tests different types of reflection settings and return the optimal solution 20 | based on RMSE between the transformed points and thre reference set 21 | } 22 | -------------------------------------------------------------------------------- /man/g_legend.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{g_legend} 4 | \alias{g_legend} 5 | \title{Create legend} 6 | \usage{ 7 | g_legend( 8 | data, 9 | data.type = "numeric", 10 | variable, 11 | center.zero, 12 | cols, 13 | val.limits, 14 | dark.theme = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{data}{data.frame with values that should be mapped onto colorscale} 19 | 20 | \item{data.type}{input data type, e.g. "factor", "numeric", "character", ...} 21 | 22 | \item{variable}{character string specifying tha name of the column (variable) containing values} 23 | 24 | \item{center.zero}{Specifies whether or not the colorscale should be centered at zero} 25 | 26 | \item{cols}{Character vector with color ids to be used in colorscale} 27 | 28 | \item{val.limits}{Specifies the limits for values in colorscale} 29 | 30 | \item{dark.theme}{Should a dark theme be used?} 31 | } 32 | \description{ 33 | Creates a colorscale legend for a dataset in grob format 34 | } 35 | -------------------------------------------------------------------------------- /man/generate.map.affine.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{generate.map.affine} 4 | \alias{generate.map.affine} 5 | \title{Generate a map function} 6 | \usage{ 7 | generate.map.affine(tr, forward = FALSE) 8 | } 9 | \arguments{ 10 | \item{tr}{results obtained with \code{\link{find.optimal.transform}}} 11 | 12 | \item{forward}{Should the forward transformation be computed?} 13 | } 14 | \value{ 15 | A transformation function that takes x and y coordinates as input and outputs a 16 | list of warped x, y coordinates 17 | } 18 | \description{ 19 | Given two sets of points (2D) this function will create a rigid transformation 20 | function that minimized the rmse of the two points sets. Because we use the backward 21 | transformation function for image warping, we need to compute the forward transformation 22 | function for pixel coordinate warping. If set1 is (x, y) and set2 is the target (x', y') 23 | point set, we want to find the backward transformation function M(x', y') -> (x, y). 24 | The forward transformation will be the inverse of M, i.e. M^-1(x, y) -> (x', y'). 25 | The iterative closest point algorithm used to find the best rigid transformation function 26 | may not find the best solution if the image is reflected. For this reason we calculate 27 | the transofmration function for all different combinations of reflections and select the 28 | function with the lowest rmse between the aligned set and reference set. 29 | } 30 | -------------------------------------------------------------------------------- /man/generate.map.rot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{generate.map.rot} 4 | \alias{generate.map.rot} 5 | \title{Create transformation function} 6 | \usage{ 7 | generate.map.rot(tr, forward = FALSE) 8 | } 9 | \arguments{ 10 | \item{tr}{Forward transformation matrix} 11 | 12 | \item{forward}{Logical: sets algorithm to 'forwar', otherwise 'backward'} 13 | } 14 | \description{ 15 | Creates a function that takes x,y values as input and applies a transformation 16 | } 17 | -------------------------------------------------------------------------------- /man/get.edges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R 3 | \name{get.edges} 4 | \alias{get.edges} 5 | \title{Obtain edges of binary mask stores in masked.masks list} 6 | \usage{ 7 | get.edges(object, index = 1, verbose = FALSE, type = "masked.masks") 8 | } 9 | \arguments{ 10 | \item{object}{Seurat object} 11 | 12 | \item{index}{Sample index} 13 | 14 | \item{verbose}{Print messages} 15 | 16 | \item{type}{image type to run edge detection on [default: 'masked.masks']} 17 | } 18 | \description{ 19 | Obtain edges of binary mask stores in masked.masks list 20 | } 21 | -------------------------------------------------------------------------------- /man/get.edges.Seurat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{get.edges.Seurat} 4 | \alias{get.edges.Seurat} 5 | \title{Finds edges of a mask and returns a set of x,y coordinates 6 | aligned along the edges} 7 | \usage{ 8 | \method{get.edges}{Seurat}(object, index = 1, verbose = FALSE, type = "masked.masks") 9 | } 10 | \arguments{ 11 | \item{object}{Seurat object} 12 | 13 | \item{index}{Sample index} 14 | 15 | \item{verbose}{Print messages} 16 | 17 | \item{type}{image type to run edge detection on [default: 'masked.masks']} 18 | } 19 | \value{ 20 | A list of data.frames with edge coordinates 21 | } 22 | \description{ 23 | Finds edges of a mask and returns a set of x,y coordinates 24 | aligned along the edges 25 | } 26 | \examples{ 27 | \dontrun{ 28 | # Mask, align and plot edges for image 2 from a Seurat object 29 | edges <- LoadImages(se, verbose = TRUE) \%>\% MaskImages() \%>\% get.edges(index = 2) 30 | plot(as.raster(edges) \%>\% as.cimg()) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /man/get.edges.Staffli.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{get.edges.Staffli} 4 | \alias{get.edges.Staffli} 5 | \title{Finds edges of a mask and returns a set of x,y coordinates 6 | aligned along the edges} 7 | \usage{ 8 | \method{get.edges}{Staffli}(object, index = 1, verbose = FALSE, type = "masked.masks") 9 | } 10 | \arguments{ 11 | \item{object}{Seurat object} 12 | 13 | \item{index}{Sample index} 14 | 15 | \item{verbose}{Print messages} 16 | 17 | \item{type}{image type to run edge detection on [default: 'masked.masks']} 18 | } 19 | \value{ 20 | A list of data.frames with edge coordinates 21 | } 22 | \description{ 23 | Finds edges of a mask and returns a set of x,y coordinates 24 | aligned along the edges 25 | } 26 | \examples{ 27 | \dontrun{ 28 | # Create a new Staffli object, mask, align and plot edges for image 2 29 | st.obj <- CreateStaffliObject(imgs, meta.data) 30 | edges <- LoadImages(st.obj, verbose = TRUE) \%>\% MaskImages() \%>\% get.edges(index = 2) 31 | plot(as.raster(edges) \%>\% as.cimg()) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /man/getExtension.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pre_processing.R 3 | \name{getExtension} 4 | \alias{getExtension} 5 | \title{Obtain file extension} 6 | \usage{ 7 | getExtension(file) 8 | } 9 | \arguments{ 10 | \item{file}{Path to file} 11 | } 12 | \description{ 13 | Obtain file extension 14 | } 15 | -------------------------------------------------------------------------------- /man/grid.from.staffli.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/2D_point_pattern.R 3 | \name{grid.from.staffli} 4 | \alias{grid.from.staffli} 5 | \title{Creates 2D point patterns for a set of images} 6 | \usage{ 7 | grid.from.staffli( 8 | object, 9 | type, 10 | limit = 0.3, 11 | maxnum = 1000, 12 | edges = FALSE, 13 | custom.edge.detector = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{Staffli object} 18 | 19 | \item{type}{Sets the image type to run segmentation on} 20 | 21 | \item{limit}{Sets the intensity threshold in the interval [0, 1]} 22 | 23 | \item{maxnum}{Integer value specifying the maximum number of points} 24 | 25 | \item{edges}{Extracts the coordinates of the edges instead} 26 | 27 | \item{custom.edge.detector}{Custom function used to detect edges} 28 | } 29 | \description{ 30 | Creates 2D point patterns for a set of images 31 | } 32 | -------------------------------------------------------------------------------- /man/ica_init.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RunNMF.R 3 | \name{ica_init} 4 | \alias{ica_init} 5 | \title{Initiate NMF using ICA} 6 | \usage{ 7 | ica_init(A, k, ica.fast = F) 8 | } 9 | \arguments{ 10 | \item{A}{input matrix} 11 | 12 | \item{k}{number of components to compute} 13 | 14 | \item{ica.fast}{Should a fast implementation of ICA be used?} 15 | } 16 | \description{ 17 | Initiate NMF using ICA 18 | } 19 | -------------------------------------------------------------------------------- /man/icpmat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{icpmat} 4 | \alias{icpmat} 5 | \title{Match two point sets using iterative closest point search} 6 | \usage{ 7 | icpmat( 8 | set1, 9 | set2, 10 | iterations, 11 | mindist = 1e+15, 12 | type = c("rigid", "similarity", "affine"), 13 | threads = 1 14 | ) 15 | } 16 | \arguments{ 17 | \item{set1, set2}{Point set from image to be aligned with reference and point set from reference image} 18 | 19 | \item{iterations}{Number of iterations} 20 | 21 | \item{mindist}{Minimum distance that definces valid points} 22 | 23 | \item{type}{Select type of transform to be applied} 24 | 25 | \item{threads}{number of trheads to use} 26 | } 27 | \value{ 28 | list with transformed x, y coordinates and list of transformation matrices 29 | } 30 | \description{ 31 | Match two point sets using iterative closest point search 32 | } 33 | -------------------------------------------------------------------------------- /man/iminfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/Staffli.R 3 | \docType{methods} 4 | \name{iminfo} 5 | \alias{iminfo} 6 | \alias{iminfo,Staffli-method} 7 | \alias{iminfo,Staffli,Staffli-method} 8 | \title{Extracts a list of image info from a Staffli object} 9 | \usage{ 10 | iminfo(object) 11 | 12 | iminfo(object) 13 | 14 | \S4method{iminfo}{Staffli}(object) 15 | } 16 | \arguments{ 17 | \item{object}{A Staffli object} 18 | } 19 | \description{ 20 | Extracts a list of image info from a Staffli object 21 | 22 | Method for extracting the HE image dimensions from a 'Staffli' object 23 | } 24 | -------------------------------------------------------------------------------- /man/interpolate_2D_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3D_viusalization.R 3 | \name{interpolate_2D_data} 4 | \alias{interpolate_2D_data} 5 | \title{Interpolate value across point pattern} 6 | \usage{ 7 | interpolate_2D_data(data, section.input, nx, ny, xy.range) 8 | } 9 | \arguments{ 10 | \item{data}{data.frame object with spot coordinates and a 'value' column with numeric data} 11 | 12 | \item{section.input}{data.frame object with x,y coordinates for a point pattern to interpolate values over} 13 | 14 | \item{nx, ny}{Dimensions of grid} 15 | 16 | \item{xy.range}{Range of x,y coordinates to interpolate over} 17 | } 18 | \value{ 19 | data.frame object with point pattern and interpolated values 20 | } 21 | \description{ 22 | Takes a data.frame with spot coordinates and a 'value' column as input 23 | and interpolates the 'value' across a grid defined by the dimensions nx, ny 24 | and finally assigns the interpolated values to points associated with each grid cell. 25 | } 26 | -------------------------------------------------------------------------------- /man/labelRGB.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{labelRGB} 4 | \alias{labelRGB} 5 | \title{Select spots by rgb values after ST.DimPlot} 6 | \usage{ 7 | labelRGB( 8 | object, 9 | dimPlot, 10 | label1 = "label1", 11 | label2 = NULL, 12 | red1 = c(0, 255), 13 | green1 = c(0, 255), 14 | blue1 = c(0, 255), 15 | red2 = c(0, 255), 16 | green2 = c(0, 255), 17 | blue2 = c(0, 255) 18 | ) 19 | } 20 | \arguments{ 21 | \item{object}{A Seurat object} 22 | 23 | \item{dimPlot}{A 'ggplot' object created with \code{ST.DimPlot}} 24 | 25 | \item{label1, label2}{Optional names of the 1st and 2nd groups of capture-spots} 26 | 27 | \item{red1}{Red 1 limits} 28 | 29 | \item{green1}{Green 1 limits} 30 | 31 | \item{blue1}{Blue 1 limits} 32 | 33 | \item{red2}{Red 2 limits} 34 | 35 | \item{green2}{Green 2 limits} 36 | 37 | \item{blue2}{Blue 2 limits} 38 | } 39 | \description{ 40 | Select spots by rgb values after ST.DimPlot 41 | } 42 | -------------------------------------------------------------------------------- /man/make.plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/manual_annotation.R 3 | \name{make.plot} 4 | \alias{make.plot} 5 | \title{Used for the manual annotation tool, returns plot and coordinate IDs for selected sample} 6 | \usage{ 7 | make.plot(object, sampleNr, spotAlpha, Labels, SpotSize, res, ann) 8 | } 9 | \arguments{ 10 | \item{object}{Seurat object} 11 | 12 | \item{sampleNr}{Sample to be plotted} 13 | 14 | \item{spotAlpha}{geom_point opacity} 15 | 16 | \item{Labels}{labels included in the input seurat object} 17 | 18 | \item{SpotSize}{geom_point size} 19 | 20 | \item{res}{resolution of the image} 21 | } 22 | \description{ 23 | Used for the manual annotation tool, returns plot and coordinate IDs for selected sample 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/mirror.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{mirror} 4 | \alias{mirror} 5 | \title{Creates a transformation matrix that mirrors an object 6 | in 2D along either the x axis or y axis around its 7 | center of mass} 8 | \usage{ 9 | mirror(mirror.x = FALSE, mirror.y = FALSE, center.cur) 10 | } 11 | \arguments{ 12 | \item{mirror.x, mirror.y}{Logical specifying whether or not an 13 | object should be reflected} 14 | 15 | \item{center.cur}{Coordinates of the current center of mass} 16 | } 17 | \description{ 18 | Creates a transformation matrix that mirrors an object 19 | in 2D along either the x axis or y axis around its 20 | center of mass 21 | } 22 | -------------------------------------------------------------------------------- /man/names.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{names,Staffli-method} 4 | \alias{names,Staffli-method} 5 | \alias{names,Staffli,Staffli-method} 6 | \title{Method used to get samplenames from a Staffli object} 7 | \usage{ 8 | \S4method{names}{Staffli}(x) 9 | } 10 | \arguments{ 11 | \item{x}{object to get names from.} 12 | } 13 | \description{ 14 | Method used to get samplenames from a Staffli object 15 | } 16 | -------------------------------------------------------------------------------- /man/obtain.array.coords.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{obtain.array.coords} 4 | \alias{obtain.array.coords} 5 | \title{Obtain array coordinates} 6 | \usage{ 7 | obtain.array.coords(st.object, data, image.type, spots) 8 | } 9 | \arguments{ 10 | \item{st.object}{A Staffli object} 11 | 12 | \item{data}{Data.frame with array coordinates} 13 | 14 | \item{image.type}{One of "raw", "masked" or "processed"} 15 | 16 | \item{spots}{Spots to subset data on} 17 | } 18 | \description{ 19 | Obtain array coordinates 20 | } 21 | -------------------------------------------------------------------------------- /man/palette.select.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{palette.select} 4 | \alias{palette.select} 5 | \title{Palette selection} 6 | \usage{ 7 | palette.select(palette, info = F) 8 | } 9 | \arguments{ 10 | \item{palette}{Palette choice for plotting spatial expression histology heatmap} 11 | } 12 | \description{ 13 | Palette selection 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/parse.spot.file.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/process_from_table.R 3 | \name{parse.spot.file} 4 | \alias{parse.spot.file} 5 | \title{load count files} 6 | \usage{ 7 | parse.spot.file(path, delim = "\\t") 8 | } 9 | \arguments{ 10 | \item{path}{Path to spot files} 11 | 12 | \item{delim}{delimiter} 13 | 14 | \item{suffix}{add suffix to path} 15 | 16 | \item{row.names}{set column as row.names} 17 | } 18 | \description{ 19 | load count files 20 | } 21 | \keyword{Parse} 22 | \keyword{ST} 23 | \keyword{detector} 24 | \keyword{from} 25 | \keyword{internal} 26 | \keyword{output} 27 | \keyword{spot} 28 | \keyword{the} 29 | \keyword{tool} 30 | -------------------------------------------------------------------------------- /man/plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{plot,Staffli,missing-method} 4 | \alias{plot,Staffli,missing-method} 5 | \alias{plot,Staffli,Staffli-method} 6 | \title{Plot method for Staffli objects} 7 | \usage{ 8 | \S4method{plot}{Staffli,missing}(x, y = NULL, type = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{x}{object to use for plotting.} 12 | 13 | \item{y}{missing} 14 | 15 | \item{type}{type of images to use as background for plot, e.g. "raw", "masked"} 16 | 17 | \item{...}{additional parameters passed to \code{points}} 18 | } 19 | \description{ 20 | Plot method for Staffli objects 21 | } 22 | -------------------------------------------------------------------------------- /man/prep.sb.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization_utilities.R 3 | \name{prep.sb} 4 | \alias{prep.sb} 5 | \title{Prep scalebar} 6 | \usage{ 7 | prep.sb( 8 | st.object, 9 | data, 10 | data.type, 11 | indices, 12 | split.labels, 13 | features, 14 | dims, 15 | show.sb 16 | ) 17 | } 18 | \arguments{ 19 | \item{st.object}{An object of class 'Staffli'} 20 | 21 | \item{data}{data.frame for plotting} 22 | 23 | \item{data.type}{String specifying the class of the variable used for splitting} 24 | 25 | \item{indices}{Integer vector specifying sample indices to include in the plot} 26 | 27 | \item{split.labels}{Split plots} 28 | 29 | \item{features}{Features included in data} 30 | 31 | \item{dims}{List of image dimensions} 32 | 33 | \item{show.sb}{Return NULL if FALSE} 34 | } 35 | \value{ 36 | A data.frame containing positions of a scale bar used for plotting 37 | } 38 | \description{ 39 | Prep scalebar 40 | } 41 | -------------------------------------------------------------------------------- /man/qc.scatter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/QC.R 3 | \name{qc.scatter} 4 | \alias{qc.scatter} 5 | \title{function(x, y, ...) used to plot the contents of each panel of the display in pairs function} 6 | \usage{ 7 | qc.scatter(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{x coordinate} 11 | 12 | \item{y}{y coordinate} 13 | } 14 | \value{ 15 | panel for pairs function 16 | } 17 | \description{ 18 | function(x, y, ...) used to plot the contents of each panel of the display in pairs function 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/qcGenes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/QC.R 3 | \name{qcGenes} 4 | \alias{qcGenes} 5 | \title{Quality metrics for genes} 6 | \usage{ 7 | qcGenes(object, delim = "x", labels = NULL) 8 | } 9 | \arguments{ 10 | \item{object}{expression matrix with spots in columns and genes in rows or Seurat object} 11 | 12 | \item{delim}{delimiter} 13 | 14 | \item{labels}{character vector with labels corresponding to dataset IDs in merged expression matrix [optional]} 15 | } 16 | \value{ 17 | data.frame with gene names and quality metrics 18 | } 19 | \description{ 20 | Quality metrics for genes 21 | } 22 | -------------------------------------------------------------------------------- /man/qcSamples.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/QC.R 3 | \name{qcSamples} 4 | \alias{qcSamples} 5 | \title{Quality metrics for samples} 6 | \usage{ 7 | qcSamples(object, delim = "x", labels = NULL) 8 | } 9 | \arguments{ 10 | \item{object}{expression matrix with spots in columns and genes in rows or Seurat object} 11 | 12 | \item{delim}{delimiter} 13 | 14 | \item{labels}{character vector with labels corresponding to dataset IDs in merged expression matrix [optional]} 15 | } 16 | \value{ 17 | data.frame with quality metrics per sample 18 | } 19 | \description{ 20 | Quality metrics for samples 21 | } 22 | -------------------------------------------------------------------------------- /man/qcSpots.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/QC.R 3 | \name{qcSpots} 4 | \alias{qcSpots} 5 | \title{Quality metrics for spots} 6 | \usage{ 7 | qcSpots(exprMat, delim = "x") 8 | } 9 | \arguments{ 10 | \item{exprMat}{expression matrix with spots in columns and genes in rows} 11 | 12 | \item{delim}{delimiter for expression matrix headers} 13 | } 14 | \value{ 15 | data.frame with x, y coordinates and quality metrics 16 | } 17 | \description{ 18 | Quality metrics for spots 19 | } 20 | -------------------------------------------------------------------------------- /man/rasterize_scatter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3D_viusalization.R 3 | \name{rasterize_scatter} 4 | \alias{rasterize_scatter} 5 | \title{Assign points to a grid} 6 | \usage{ 7 | rasterize_scatter(scatter, r, nx) 8 | } 9 | \arguments{ 10 | \item{scatter}{data.frame with x,y coordinates for a point pattern} 11 | 12 | \item{r}{A 'raster' object} 13 | 14 | \item{nx}{Number of cells to interpolate over across the x axis} 15 | } 16 | \value{ 17 | data.frame object with point pattern and associated grid.cell number 18 | } 19 | \description{ 20 | takes a point pattern and a raster object as input and 21 | assigns each point to a cell of the raster object. 22 | } 23 | -------------------------------------------------------------------------------- /man/rasterlists.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/Staffli.R 3 | \docType{methods} 4 | \name{rasterlists} 5 | \alias{rasterlists} 6 | \alias{rasterlists,Staffli-method} 7 | \alias{rasterlists,Staffli,Staffli-method} 8 | \alias{rasterlists,Seurat-method} 9 | \alias{rasterlists,Seurat,Seurat-method} 10 | \title{Extracts available image types from Seurat or Staffli objects} 11 | \usage{ 12 | rasterlists(object) 13 | 14 | rasterlists(object) 15 | 16 | \S4method{rasterlists}{Staffli}(object) 17 | 18 | \S4method{rasterlists}{Seurat}(object) 19 | } 20 | \arguments{ 21 | \item{object}{A Staffli or Seurat object} 22 | } 23 | \description{ 24 | Extracts available image types from Seurat or Staffli objects 25 | 26 | Method to extract the available image types from a Staffli object 27 | } 28 | -------------------------------------------------------------------------------- /man/rigid.refl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{rigid.refl} 4 | \alias{rigid.refl} 5 | \title{Creates a transformation matrix for reflection} 6 | \usage{ 7 | rigid.refl(mirror.x, mirror.y) 8 | } 9 | \arguments{ 10 | \item{mirror.x, mirror.y}{Logical: mirrors x or y axis if set to TRUE} 11 | } 12 | \description{ 13 | Creates a transformation matrix for reflection where mirror.x will reflect the 14 | points along the x axis and mirror.y will reflect thepoints along the y axis. 15 | Points are assumed to be centered at (0, 0) 16 | } 17 | -------------------------------------------------------------------------------- /man/rigid.rot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{rigid.rot} 4 | \alias{rigid.rot} 5 | \title{Creates a transformation matrix for rotation} 6 | \usage{ 7 | rigid.rot(alpha = 0, forward = TRUE) 8 | } 9 | \arguments{ 10 | \item{alpha}{rotation angle} 11 | 12 | \item{forward}{should the rotation be done in forward direction?} 13 | } 14 | \description{ 15 | Creates a transformation matrix for clockwise rotation by 'alpha' degrees 16 | } 17 | -------------------------------------------------------------------------------- /man/rigid.stretch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{rigid.stretch} 4 | \alias{rigid.stretch} 5 | \title{Creates a transformation matrix for stretching} 6 | \usage{ 7 | rigid.stretch(r) 8 | } 9 | \arguments{ 10 | \item{r}{stretching factor} 11 | } 12 | \description{ 13 | Creates a transformation matrix for stretching by a factor of r 14 | along the x axis. 15 | } 16 | -------------------------------------------------------------------------------- /man/rigid.transf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{rigid.transf} 4 | \alias{rigid.transf} 5 | \title{Creates a transformation matrix for rotation and translation} 6 | \usage{ 7 | rigid.transf(h = 0, k = 0, alpha = 0) 8 | } 9 | \arguments{ 10 | \item{h}{Numeric: offset along x axis} 11 | 12 | \item{k}{Numeric: offset along y axis} 13 | 14 | \item{alpha}{rotation angle} 15 | } 16 | \description{ 17 | Creates a transformation matrix for clockwise rotation by 'alpha' degrees 18 | followed by a translation with an offset of (h, k). Points are assumed to be 19 | centered at (0, 0). 20 | } 21 | -------------------------------------------------------------------------------- /man/rigid.transl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{rigid.transl} 4 | \alias{rigid.transl} 5 | \title{Creates a transformation matrix for translation with an offset of (h, k)} 6 | \usage{ 7 | rigid.transl(h = 0, k = 0) 8 | } 9 | \arguments{ 10 | \item{h}{Numeric: offset along x axis} 11 | 12 | \item{k}{Numeric: offset along y axis} 13 | } 14 | \description{ 15 | Creates a transformation matrix for translation with an offset of (h, k) 16 | } 17 | -------------------------------------------------------------------------------- /man/rnmf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RunNMF.R 3 | \name{rnmf} 4 | \alias{rnmf} 5 | \title{Run NMF with ica init} 6 | \usage{ 7 | rnmf( 8 | A, 9 | k, 10 | alpha = 0, 11 | init = "ica", 12 | n.cores = 1, 13 | loss = "mse", 14 | max.iter = 500, 15 | ica.fast = F 16 | ) 17 | } 18 | \arguments{ 19 | \item{A}{Expression matrix} 20 | 21 | \item{k}{= Number of factors} 22 | 23 | \item{alpha}{Alpha parameter value} 24 | 25 | \item{init}{Method to initiate NMF by} 26 | 27 | \item{n.cores}{Number of threads to run} 28 | 29 | \item{loss}{Loss method} 30 | 31 | \item{max.iter}{Maximum number of iterations for NMF} 32 | 33 | \item{ica.fast}{Should fast ica be run?} 34 | } 35 | \description{ 36 | Run NMF with ica init 37 | } 38 | -------------------------------------------------------------------------------- /man/rotate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{rotate} 4 | \alias{rotate} 5 | \title{Creates a transformation matrix that rotates an object 6 | in 2D around it's center of mass} 7 | \usage{ 8 | rotate(angle, center.cur) 9 | } 10 | \arguments{ 11 | \item{angle}{Angle given in degrees used for rotation} 12 | 13 | \item{center.cur}{Coordinates of the current center of mass} 14 | } 15 | \description{ 16 | Creates a transformation matrix that rotates an object 17 | in 2D around it's center of mass 18 | } 19 | -------------------------------------------------------------------------------- /man/samplenames.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/Staffli.R 3 | \docType{methods} 4 | \name{samplenames} 5 | \alias{samplenames} 6 | \alias{samplenames,Staffli-method} 7 | \alias{samplenames,Staffli,Staffli-method} 8 | \alias{samplenames,Seurat-method} 9 | \alias{samplenames,Seurat,Seurat-method} 10 | \title{Extracts available samplenames from Seurat or Staffli objects} 11 | \usage{ 12 | samplenames(object) 13 | 14 | samplenames(object) 15 | 16 | \S4method{samplenames}{Staffli}(object) 17 | 18 | \S4method{samplenames}{Seurat}(object) 19 | } 20 | \arguments{ 21 | \item{object}{A Staffli object} 22 | } 23 | \description{ 24 | Extracts available samplenames from Seurat or Staffli objects 25 | 26 | Method used to get samplenames from a Staffli or Seurat object processed using STutility 27 | } 28 | -------------------------------------------------------------------------------- /man/scale_override.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/facet_grid_SC.R 3 | \name{scale_override} 4 | \alias{scale_override} 5 | \title{Function used to override scales in facets of a ggplot object} 6 | \usage{ 7 | scale_override(which, scale) 8 | } 9 | \arguments{ 10 | \item{which}{Index of facet} 11 | 12 | \item{scale}{Object of class "Scale" used to override (e.g. \code{scale_x_continuous()})} 13 | } 14 | \description{ 15 | Function used to override scales in facets of a ggplot object 16 | } 17 | -------------------------------------------------------------------------------- /man/scaled.imdims.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/Staffli.R 3 | \docType{methods} 4 | \name{scaled.imdims} 5 | \alias{scaled.imdims} 6 | \alias{scaled.imdims,Staffli-method} 7 | \alias{scaled.imdims,Staffli,Staffli-method} 8 | \title{Extracts scaled dimensions of images in Staffli object} 9 | \usage{ 10 | scaled.imdims(object, type = "raw") 11 | 12 | scaled.imdims(object, type = "raw") 13 | 14 | \S4method{scaled.imdims}{Staffli}(object, type = "raw") 15 | } 16 | \arguments{ 17 | \item{object}{A Staffli object} 18 | 19 | \item{type}{Image type [choices: 'raw', 'masked', 'processed']} 20 | } 21 | \description{ 22 | Extracts scaled dimensions of images in Staffli object 23 | 24 | Method for extracting the scaled HE image dimensions from a 'Staffli' object 25 | } 26 | -------------------------------------------------------------------------------- /man/scatter_HE.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/2D_point_pattern.R 3 | \name{scatter_HE} 4 | \alias{scatter_HE} 5 | \title{Function used to generate a 2D set of points from an HE image} 6 | \usage{ 7 | scatter_HE( 8 | object, 9 | type = "masked.masks", 10 | sample.index = NULL, 11 | limit = 0.5, 12 | maxnum = 50000, 13 | edges = FALSE, 14 | custom.edge.detector = NULL 15 | ) 16 | } 17 | \arguments{ 18 | \item{object}{Staffli object} 19 | 20 | \item{type}{Sets the image type to run segmentation on} 21 | 22 | \item{sample.index}{Integer value specifying the index of the sample to be analyzed} 23 | 24 | \item{limit}{Sets the intensity threshold in the interval [0, 1]} 25 | 26 | \item{maxnum}{Integer value specifying the maximum number of points} 27 | 28 | \item{edges}{Extracts the coordinates of the edges instead} 29 | 30 | \item{custom.edge.detector}{Custom function used to detect edges} 31 | } 32 | \description{ 33 | The defualt segmentation uses the HE image as input and defines any pixel with an intensity value 34 | below a threshold to be a point. The number of points can be downsampeld to limit the maximum number. 35 | } 36 | -------------------------------------------------------------------------------- /man/show.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Staffli.R 3 | \name{show,Staffli-method} 4 | \alias{show,Staffli-method} 5 | \alias{show,Staffli,Staffli-method} 6 | \title{Show method for Staffli objects} 7 | \usage{ 8 | \S4method{show}{Staffli}(object) 9 | } 10 | \arguments{ 11 | \item{object}{object to print preselected attributes for} 12 | } 13 | \description{ 14 | Show method for Staffli objects 15 | } 16 | -------------------------------------------------------------------------------- /man/sleepy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{sleepy} 4 | \alias{sleepy} 5 | \title{Function to perform system sleep if user having memory issues during image loading} 6 | \usage{ 7 | sleepy(x) 8 | } 9 | \arguments{ 10 | \item{x}{time to sleep} 11 | } 12 | \description{ 13 | Function to perform system sleep if user having memory issues during image loading 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/slic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image_processing_utilities.R 3 | \name{slic} 4 | \alias{slic} 5 | \title{SLIC algorithm} 6 | \usage{ 7 | slic(im, nS, compactness = 1, ...) 8 | } 9 | \arguments{ 10 | \item{im}{Image of class "cimg"} 11 | 12 | \item{nS}{Number of superpixels to return} 13 | 14 | \item{compactness}{Controls scaling ratio for pixel values} 15 | 16 | \item{...}{Parameters passed to kmeans} 17 | } 18 | \description{ 19 | Converts image into SLIC superpixels 20 | } 21 | -------------------------------------------------------------------------------- /man/spatial_dim_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization.R 3 | \name{spatial_dim_plot} 4 | \alias{spatial_dim_plot} 5 | \title{Dimensional reduction plot on ST coordinates on top of HE image} 6 | \usage{ 7 | spatial_dim_plot( 8 | object, 9 | dims = 1:2, 10 | sample.index = 1, 11 | spots = NULL, 12 | type = NULL, 13 | min.cutoff = NA, 14 | max.cutoff = NA, 15 | blend = FALSE, 16 | pt.size = 1, 17 | pt.alpha = 1, 18 | pt.border = FALSE, 19 | add.alpha = FALSE, 20 | reduction = NULL, 21 | palette = "MaYl", 22 | cols = NULL, 23 | grid.ncol = NULL, 24 | center.zero = TRUE, 25 | channels.use = NULL, 26 | verbose = FALSE, 27 | dark.theme = FALSE, 28 | show.sb = TRUE, 29 | value.scale = c("samplewise", "all"), 30 | label.by = NULL, 31 | ... 32 | ) 33 | } 34 | \arguments{ 35 | \item{object}{Seurat object} 36 | 37 | \item{dims}{List of dimensions for original images. This list has to contain one element for each sample and each element 38 | should be a vector of length 2 specifying the dimensions of the original HE image.} 39 | 40 | \item{sample.index}{Index specifying the sample that you want to use for plotting} 41 | 42 | \item{spots}{Character vector with spot IDs to plot [default: all spots]} 43 | 44 | \item{type}{Image type to plot on. Here you can specify any of the images available in your Seurat object. To get this list you can 45 | run the \code{\link{rasterlists}} function on your Seurat object. If the type is not specified, the images will be prioritized in the following 46 | order if they are available; "processed", "masked" and "raw".} 47 | 48 | \item{min.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 49 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 50 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 51 | 52 | \item{max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 53 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 54 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 55 | 56 | \item{blend}{Scale and blend expression values to visualize coexpression of two features (this options will override other coloring parameters). 57 | See 'Blending values' below for a more thourough description.} 58 | 59 | \item{pt.size}{Point size of each ST spot [default: 1]} 60 | 61 | \item{pt.alpha}{Opacity of each ST spot [default: 1]} 62 | 63 | \item{pt.border}{Should a border be drawn around the spots? [default: TRUE]} 64 | 65 | \item{add.alpha}{Scale spot opacity by selected feature. Higher values get more opaque while lower values make spots transparent.} 66 | 67 | \item{reduction}{Which dimensionality reduction to use. If not specified, first searches for "umap", then "tsne", then "pca"} 68 | 69 | \item{palette}{Color palette used for spatial heatmap (see \code{palette.select(info = T)} for available options). 70 | Disabled if a color vector is provided (see \code{cols} below).} 71 | 72 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 73 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 74 | option.} 75 | 76 | \item{grid.ncol}{Number of columns for display when combining plots. This option will only have an effect on the sample level structure.} 77 | 78 | \item{center.zero}{Specifies whther or not the colorscale should be centered around 0. For some values, such as Principal Component vectors, 79 | the distribution of values is centered at 0 and in that case it can be appropriate to use a divergent colorscale with a predefined value for 0. 80 | If this parameter is set to TRUE, the ggplot2 function \code{scale_color_gradient2} will be used to control the coloring instead of 81 | \code{scale_color_gradientn}. If center.zero is set to FALSE, the colorscale will simply map the values in equally spaced intervals which could skew 82 | the interpretaion of the output plot.} 83 | 84 | \item{channels.use}{Color channels to use for blending. Has to be a character vector of length 2 or 3 with "red", "green" and "blue" 85 | color names specified [default: c("red", "green", "blue)]} 86 | 87 | \item{verbose}{Print messages} 88 | 89 | \item{dark.theme}{Switches color of scalebar to 'white'} 90 | 91 | \item{show.sb}{Should the size bar be displayed? [default: TRUE]} 92 | 93 | \item{value.scale}{Defines how the feature values should be mapped to the colorbar. If `value.scale = "samplewise"`, each feature will be 94 | scaled independently and if `value.scale = "all"` the features will all have the same value reange.} 95 | 96 | \item{label.by}{Feature to relabel facets by. By default, facets are given a unique section number ranging grom 1 to the number of sections 97 | available in the `Staffli` object. If you want to relabel these facets you can pass the name of a column that keeps the labels that you 98 | want to use. For example, if you wish to rename the facets to use labels defined by a charcater vector in column "section_id" in your 99 | meta.data slot, you can pass `label.by = "section_id"` to relabel the facets. Only works for categorical group variables with where the 100 | number of groups is less than or equal to the number of tissue sections in your Staffli object.} 101 | 102 | \item{...}{Extra parameters passed on to \code{\link{ST.ImagePlot}}} 103 | } 104 | \value{ 105 | A ggplot object 106 | } 107 | \description{ 108 | Dimensional reduction plot on ST coordinates on top of HE image 109 | } 110 | -------------------------------------------------------------------------------- /man/spatial_feature_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Visualization.R 3 | \name{spatial_feature_plot} 4 | \alias{spatial_feature_plot} 5 | \title{Visualize 'features' on one selected HE image} 6 | \usage{ 7 | spatial_feature_plot( 8 | object, 9 | features, 10 | sample.index = 1, 11 | spots = NULL, 12 | type = NULL, 13 | min.cutoff = NA, 14 | max.cutoff = NA, 15 | slot = "data", 16 | blend = FALSE, 17 | pt.size = 2, 18 | pt.alpha = 1, 19 | pt.border = FALSE, 20 | add.alpha = FALSE, 21 | palette = NULL, 22 | cols = NULL, 23 | spot.colors = NULL, 24 | ncol = NULL, 25 | grid.ncol = NULL, 26 | center.zero = FALSE, 27 | channels.use = NULL, 28 | verbose = FALSE, 29 | dark.theme = FALSE, 30 | show.sb = TRUE, 31 | value.scale = c("samplewise", "all"), 32 | label.by = NULL, 33 | ... 34 | ) 35 | } 36 | \arguments{ 37 | \item{object}{Seurat object} 38 | 39 | \item{features}{\itemize{ 40 | \item An \code{Assay} feature (e.g. a gene name - "MS4A1") 41 | \item A column name from meta.data (e.g. mitochondrial percentage - "percent.mito") 42 | }} 43 | 44 | \item{sample.index}{Index specifying the sample that you want to use for plotting} 45 | 46 | \item{spots}{Character vector with spot IDs to plot [default: all spots]} 47 | 48 | \item{type}{Image type to plot on. Here you can specify any of the images available in your Seurat object. To get this list you can 49 | run the \code{\link{rasterlists}} function on your Seurat object. If the type is not specified, the images will be prioritized in the following 50 | order if they are available; "processed", "masked" and "raw".} 51 | 52 | \item{min.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 53 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 54 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 55 | 56 | \item{max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 57 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 58 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 59 | 60 | \item{slot}{Which slot to pull expression data from? [dafault: 'data']} 61 | 62 | \item{blend}{Scale and blend expression values to visualize coexpression of two features (this options will override other coloring parameters). 63 | See 'Blending values' below for a more thourough description.} 64 | 65 | \item{pt.size}{Point size of each ST spot [default: 1]} 66 | 67 | \item{pt.alpha}{Opacity of each ST spot [default: 1]} 68 | 69 | \item{pt.border}{Should a border be drawn around the spots? [default: TRUE]} 70 | 71 | \item{add.alpha}{Scale spot opacity by selected feature. Higher values get more opaque while lower values make spots transparent.} 72 | 73 | \item{palette}{Color palette used for spatial heatmap (see \code{palette.select(info = T)} for available options). 74 | Disabled if a color vector is provided (see \code{cols} below).} 75 | 76 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 77 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 78 | option.} 79 | 80 | \item{spot.colors}{Character vector with color names that overrides default coloring with ggplot2} 81 | 82 | \item{ncol}{Number of columns to arrange the samples into. This can for example be useful to adjust if you want to visualize the samples 83 | in just in one row or one column.} 84 | 85 | \item{grid.ncol}{Number of columns for display when combining plots. This option will only have an effect on the sample level structure.} 86 | 87 | \item{center.zero}{Specifies whther or not the colorscale should be centered around 0. For some values, such as Principal Component vectors, 88 | the distribution of values is centered at 0 and in that case it can be appropriate to use a divergent colorscale with a predefined value for 0. 89 | If this parameter is set to TRUE, the ggplot2 function \code{scale_color_gradient2} will be used to control the coloring instead of 90 | \code{scale_color_gradientn}. If center.zero is set to FALSE, the colorscale will simply map the values in equally spaced intervals which could skew 91 | the interpretaion of the output plot.} 92 | 93 | \item{channels.use}{Color channels to use for blending. Has to be a character vector of length 2 or 3 with "red", "green" and "blue" 94 | color names specified [default: c("red", "green", "blue)]} 95 | 96 | \item{verbose}{Print messages} 97 | 98 | \item{dark.theme}{Switches color of scalebar to 'white'} 99 | 100 | \item{show.sb}{Should the size bar be displayed? [default: TRUE]} 101 | 102 | \item{value.scale}{Defines how the feature values should be mapped to the colorbar. If `value.scale = "samplewise"`, each feature will be 103 | scaled independently and if `value.scale = "all"` the features will all have the same value reange.} 104 | 105 | \item{label.by}{Feature to relabel facets by. By default, facets are given a unique section number ranging grom 1 to the number of sections 106 | available in the `Staffli` object. If you want to relabel these facets you can pass the name of a column that keeps the labels that you 107 | want to use. For example, if you wish to rename the facets to use labels defined by a charcater vector in column "section_id" in your 108 | meta.data slot, you can pass `label.by = "section_id"` to relabel the facets. Only works for categorical group variables with where the 109 | number of groups is less than or equal to the number of tissue sections in your Staffli object.} 110 | 111 | \item{...}{Extra parameters passed on to \code{\link{ST.ImagePlot}}} 112 | } 113 | \value{ 114 | A ggplot object 115 | } 116 | \description{ 117 | Colors spots on an an ST array grid according to a 'feature' 118 | (i.e. gene expression (raw counts or scaled) and features available in the meta data slot). 119 | NOTE that this function only draws a plot for one sample at the time. 120 | } 121 | -------------------------------------------------------------------------------- /man/spatial_hsv_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HSVencoding.R 3 | \name{spatial_hsv_plot} 4 | \alias{spatial_hsv_plot} 5 | \title{Overlay HSVplot on one selected HE image} 6 | \usage{ 7 | spatial_hsv_plot( 8 | object, 9 | features, 10 | split.hsv = FALSE, 11 | sample.index = 1, 12 | rescale = TRUE, 13 | spots = NULL, 14 | type = NULL, 15 | min.cutoff = NA, 16 | max.cutoff = NA, 17 | slot = "data", 18 | pt.size = 2, 19 | pt.alpha = 1, 20 | pt.border = FALSE, 21 | add.alpha = FALSE, 22 | palette = NULL, 23 | cols = NULL, 24 | grid.ncol = NULL, 25 | dark.theme = FALSE, 26 | sample.label = TRUE, 27 | show.sb = TRUE, 28 | value.scale = c("samplewise", "all"), 29 | verbose = FALSE, 30 | ... 31 | ) 32 | } 33 | \arguments{ 34 | \item{object}{Seurat object} 35 | 36 | \item{features}{\itemize{ 37 | \item An \code{Assay} feature (e.g. a gene name - "MS4A1") 38 | \item A column name from meta.data (e.g. mitochondrial percentage - "percent.mito") 39 | }} 40 | 41 | \item{split.hsv}{Should the HSV colored features be split into separate plots? [default: FALSE]} 42 | 43 | \item{sample.index}{Index specifying the sample that you want to use for plotting} 44 | 45 | \item{rescale}{Rescale each feature column separately from 0 to 1 range. If set to FALSE, all feature columns 46 | will be scaled together from 0 to 1 and preserve the relative differencies} 47 | 48 | \item{spots}{Character vector with spot IDs to plot [default: all spots]} 49 | 50 | \item{type}{Image type to plot on. Here you can specify any of the images available in your Seurat object. To get this list you can 51 | run the \code{\link{rasterlists}} function on your Seurat object. If the type is not specified, the images will be prioritized in the following 52 | order if they are available; "processed", "masked" and "raw".} 53 | 54 | \item{min.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 55 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 56 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 57 | 58 | \item{max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' 59 | is the quantile (eg, 'q1', 'q10'). This can be useful if you have outlier values that skew the colorscale in the plot. For example, if you specify 60 | 'q1', you will trim of values below the 1st percentile. [default: no cuttoffs]} 61 | 62 | \item{slot}{Which slot to pull expression data from? [dafault: 'data']} 63 | 64 | \item{pt.size}{Point size of each ST spot [default: 1]} 65 | 66 | \item{pt.alpha}{Opacity of each ST spot [default: 1]} 67 | 68 | \item{pt.border}{Should a border be drawn around the spots? [default: TRUE]} 69 | 70 | \item{add.alpha}{Scale spot opacity by selected feature. Higher values get more opaque while lower values make spots transparent.} 71 | 72 | \item{palette}{Color palette used for spatial heatmap (see \code{palette.select(info = T)} for available options). 73 | Disabled if a color vector is provided (see \code{cols} below).} 74 | 75 | \item{cols}{A vector of colors to use for colorscale, e.g. \code{cols = c("blue", "white", "red")} will 76 | create a gradient color scale going from blue to white to red. This options will deactivate the \code{palette} 77 | option.} 78 | 79 | \item{grid.ncol}{Number of columns for display when combining plots. This option will only have an effect on the sample level structure.} 80 | 81 | \item{dark.theme}{Switches color of scalebar to 'white'} 82 | 83 | \item{sample.label}{Should the sample label be included in the image? [default: TRUE]} 84 | 85 | \item{show.sb}{Should a scalebar be drawn? [default: TRUE]} 86 | 87 | \item{value.scale}{Defines how the dimensionality reduction values should be mapped to the colorbar. `value.scale = "samplewise"` will 88 | scale each feature independantly while `value.scale = "all"` will use the same value range for all vectors} 89 | 90 | \item{verbose}{Print messages} 91 | 92 | \item{...}{Extra parameters passed on to \code{\link{ST.ImagePlot}}} 93 | } 94 | \value{ 95 | A ggplot object 96 | } 97 | \description{ 98 | Colors spots on an an ST array grid according to a 'feature' 99 | (i.e. gene expression (raw counts or scaled) and features available in the meta data slot). 100 | NOTE that this function only draws a plot for one sample at the time. 101 | } 102 | -------------------------------------------------------------------------------- /man/st.load.matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pre_processing.R 3 | \name{st.load.matrix} 4 | \alias{st.load.matrix} 5 | \title{load count files} 6 | \usage{ 7 | st.load.matrix(path, delim = "\\t", row.names = 1, visium = F) 8 | } 9 | \arguments{ 10 | \item{path}{Path to count files} 11 | 12 | \item{delim}{Delimiter used in gene count matrix file} 13 | 14 | \item{row.names}{set column as row.names} 15 | 16 | \item{visium}{Load 10x visium output files} 17 | } 18 | \description{ 19 | load count files 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/stretch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{stretch} 4 | \alias{stretch} 5 | \title{Stretch along angle} 6 | \usage{ 7 | stretch(r, alpha, center.cur) 8 | } 9 | \arguments{ 10 | \item{r}{stretching factor} 11 | 12 | \item{alpha}{angle} 13 | 14 | \item{center.cur}{Coordinates of the current center of mass} 15 | } 16 | \description{ 17 | Creates a transformation matrix that stretches an object 18 | along a specific axis 19 | } 20 | -------------------------------------------------------------------------------- /man/translate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Rigid_transformation.R 3 | \name{translate} 4 | \alias{translate} 5 | \title{Creates a transformation matrix that translates an object 6 | in 2D} 7 | \usage{ 8 | translate(translate.x, translate.y) 9 | } 10 | \arguments{ 11 | \item{translate.x, translate.y}{translation of x, y coordinates} 12 | } 13 | \description{ 14 | Creates a transformation matrix that translates an object 15 | in 2D 16 | } 17 | --------------------------------------------------------------------------------