├── .Rbuildignore ├── .gitignore ├── CRAN-SUBMISSION ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── cell_type_prediction.R ├── cell_type_prediction_mixed.R ├── checks.R ├── cut_spatial_network.R ├── cut_spatial_network_utils.R ├── disconnect_regions.R ├── export_data_for_viewer.R ├── extdata.R ├── feature_loadings_plot.R ├── file_server.R ├── ftrviewer.R ├── generics.R ├── get_array_rotation.R ├── icp.R ├── load_data.R ├── load_images.R ├── local_G.R ├── mask.R ├── multimodal_object.R ├── neighborhood_analysis.R ├── osddu.R ├── paper.R ├── plot_images.R ├── prepare_for_digital_unroll.R ├── prepare_for_feature_viewer.R ├── radial_distance.R ├── radial_distance_plot.R ├── rigid_transform.R ├── rigid_transform_manual.R ├── scalebar.R ├── semla-package.R ├── semla_to_seurat.R ├── seurat_to_semla.R ├── spatial_autocorrelation.R ├── spatial_neighborhood_stats.R ├── spatial_network.R ├── spatial_utils.R ├── staffli_object.R ├── subset_and_merge.R ├── themes.R ├── tile_images.R ├── transformations_coordinates.R ├── transformations_image.R ├── update_stutilityv1_object.R ├── utils.R ├── visualization_spatial.R ├── visualization_spatial_multicolor.R ├── visualization_spatial_stats.R ├── visualization_spatial_viewer.R └── zzz.R ├── README.md ├── _pkgdown.yml ├── cran-comments.md ├── inst ├── WORDLIST ├── extdata │ ├── mousebrain │ │ ├── filtered_feature_bc_matrix.h5 │ │ ├── se_mbrain │ │ └── spatial │ │ │ ├── scalefactors_json.json │ │ │ ├── tissue_lowres_image.jpg │ │ │ └── tissue_positions_list.csv │ └── mousecolon │ │ ├── filtered_feature_bc_matrix.h5 │ │ ├── galt_spots.csv │ │ ├── se_mcolon │ │ └── spatial │ │ ├── scalefactors_json.json │ │ ├── tissue_lowres_image.jpg │ │ └── tissue_positions_list.csv └── htmlwidgets │ ├── 0c1f69b256da5355cf18806b7cab12c0.jpeg │ ├── ftrviewer.js │ ├── ftrviewer.js.map │ ├── ftrviewer.yaml │ ├── osddu.js │ ├── osddu.js.map │ ├── osddu.yaml │ ├── paper.js │ ├── paper.js.map │ └── paper.yaml ├── man ├── AdjustTissueCoordinates.Rd ├── AnglePlot.Rd ├── CoordAndImageTransform.Rd ├── CoordMirror.Rd ├── CoordTransform.Rd ├── CreateStaffliObject.Rd ├── CutSpatialNetwork.Rd ├── ExportDataForViewer.Rd ├── FeatureViewer.Rd ├── GetCoordinates.Rd ├── GetImageInfo.Rd ├── GetImages.Rd ├── GetScaleFactors.Rd ├── GetStaffli.Rd ├── ImagePlot.Rd ├── ImageTransform.Rd ├── ImageTranslate.Rd ├── LoadAndMergeMatrices.Rd ├── LoadAnnotationCSV.Rd ├── LoadImageInfo.Rd ├── LoadScaleFactors.Rd ├── LoadSpatialCoordinates.Rd ├── MapFeaturesSummary.Rd ├── MapLabelsSummary.Rd ├── MapPointsToReference.Rd ├── ModifyPatchworkTitles.Rd ├── PlotFeatureLoadings.Rd ├── ReadVisiumData.Rd ├── ReplaceImagePaths.Rd ├── Staffli-class.Rd ├── Staffli-methods.Rd ├── ThemeClean.Rd ├── ThemeLegendRight.Rd ├── TileImage.Rd ├── UpdateImageInfo.Rd ├── UpdateSTUtilityV1Object.Rd ├── UpdateSeuratForSemla.Rd ├── UpdateSeuratFromSemla.Rd ├── celltype-prediction-mixed.Rd ├── celltype-prediction.Rd ├── centroid_angles_plot.Rd ├── cor-features.Rd ├── disconnect-regions.Rd ├── export_coordinates.Rd ├── export_graph.Rd ├── figures │ ├── logo.png │ └── sr-logo.png ├── file_server.Rd ├── ftrviewer-shiny.Rd ├── ftrviewer.Rd ├── generate_rigid_transform.Rd ├── get-network.Rd ├── get_array_rotation.Rd ├── icp.Rd ├── kabsch.Rd ├── label-assortativity.Rd ├── load-images.Rd ├── local-G.Rd ├── manual-transform-images.Rd ├── mask-images.Rd ├── mbrain_dataset.Rd ├── mcolon_dataset.Rd ├── merge.Rd ├── multimodal-object.Rd ├── neighborhood-enrichment.Rd ├── osddu-shiny.Rd ├── osddu.Rd ├── paper-shiny.Rd ├── paper.Rd ├── plot.Rd ├── prep_image.Rd ├── radial-distance.Rd ├── region-neighbors.Rd ├── scalebar.Rd ├── semla-package.Rd ├── show.Rd ├── subset.Rd ├── transform-images.Rd ├── visualize-features.Rd ├── visualize-labels.Rd └── visualize-multiple-features.Rd ├── pkgdown ├── extra.css └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── renv.lock ├── semla.Rproj ├── tests ├── spelling.R ├── testthat.R └── testthat │ ├── test-AdjustTissueCoordinates.R │ ├── test-AnglePlot.R │ ├── test-CoordMirror.R │ ├── test-CoordTransform.R │ ├── test-CorSpatialFeatures.R │ ├── test-CreateMultiModalObject.R │ ├── test-DisconnectRegions.R │ ├── test-ExportDataForViewer.R │ ├── test-FeatureLoadingsPlot.R │ ├── test-GetSpatialNetwork.R │ ├── test-ImagePlot.R │ ├── test-LoadAndMergeMatrices.R │ ├── test-LoadImageInfo.R │ ├── test-LoadImages.R │ ├── test-LoadScaleFactors.R │ ├── test-LoadSpatialCoordinates.R │ ├── test-MapFeatures.R │ ├── test-MapFeaturesSummary.R │ ├── test-MapLabels.R │ ├── test-MapLabelsSummary.R │ ├── test-MapMultipleFeatures.R │ ├── test-MaskImages.R │ ├── test-MergeSTData.R │ ├── test-RadialDistance.R │ ├── test-ReadVisiumData.R │ ├── test-RunLabelAssortativityTest.R │ ├── test-RunLocalG.R │ ├── test-RunNNLS.R │ ├── test-RunNeighborhoodEnrichmentTest.R │ ├── test-SubsetSTData.R │ ├── test-UpdateSeuratFromSemla.R │ ├── test-export_graph.R │ ├── test-fileserver.R │ ├── test-ftrviewer.R │ ├── test-icp.R │ ├── test-neighborhood_analysis.R │ ├── test-osddu.R │ ├── test-paper.R │ └── test-themes.R └── vignettes ├── IF_data.Rmd ├── NNMF.Rmd ├── NNMF ├── fea_results_nmf_1 ├── gene_loadings.jpg ├── gene_loadings_sorted ├── multiple_factors.jpg ├── multiple_factors_heatmap.jpg ├── rank_plot.jpg └── spatial_plot.jpg ├── advanced_visualization.Rmd ├── categorical_features.Rmd ├── cell_type_mapping_benchmark.Rmd ├── cell_type_mapping_with_NNLS.rmd ├── compare_cell_type_mapping_NNLS.Rmd ├── compare_cell_type_mapping_NNLS ├── mbrain_cor_bars.jpg ├── mbrain_cor_heatmaps.jpg ├── mbrain_spatial_map_plots.rds ├── mkidney_cor_bars.jpg ├── mkidney_cor_heatmaps.jpg └── mkidney_spatial_map_plots.rds ├── comparison ├── mousebrain │ ├── cell2location │ ├── celltypeprops │ └── stereoscope └── mousekidney │ ├── cell2location │ ├── celltypeprops │ └── stereoscope ├── create_multimodal_object.Rmd ├── create_object.Rmd ├── digital_unrolling.rmd ├── digital_unrolling ├── mBrain.jpg └── mBrain_x_dist.jpg ├── feature_viewer.Rmd ├── getting_started.rmd ├── image_alignment.Rmd ├── images ├── alignment │ ├── aligned_cropped.jpg │ ├── aligned_images.png │ ├── alignment_brain_colon.png │ ├── alignment_start.png │ ├── help_menu.png │ ├── rotated_and_scaled.png │ ├── selected_image.png │ ├── transformed_images_brain_colon.jpg │ └── unique_genes_aligned.jpeg ├── backup │ ├── categorical_features.png │ ├── cut.png │ ├── feature_viewer_start.png │ ├── help_menu.png │ ├── lasso_tool.png │ ├── new_label.png │ ├── numeric_features.png │ ├── wrong.png │ └── zoom_in.png ├── cut.png ├── slide-seq │ ├── DG.jpg │ └── unique_genes.jpg ├── viewer │ ├── categorical_features.png │ ├── feature_viewer_start.png │ ├── help_menu.png │ ├── lasso_tool.png │ ├── new_label.png │ ├── numeric_features.png │ └── zoom_in.png └── wrong.png ├── images_and_coordinates.rmd ├── logo.png ├── mask_images.Rmd ├── numeric_features.Rmd ├── radial_distances.Rmd ├── reference ├── AdjustTissueCoordinates.html ├── AnglePlot-1.png ├── AnglePlot.html ├── CoordAndImageTransform-1.png ├── CoordAndImageTransform-2.png ├── CoordAndImageTransform.html ├── CoordMirror-1.png ├── CoordMirror.html ├── CoordTransform-1.png ├── CoordTransform.html ├── CreateStaffliObject.html ├── CutSpatialNetwork.html ├── FeatureViewer.html ├── GetImages.html ├── GetStaffli.html ├── ImageInfo.html ├── ImagePlot-1.png ├── ImagePlot-2.png ├── ImagePlot-3.png ├── ImagePlot-4.png ├── ImagePlot-5.png ├── ImagePlot-6.png ├── ImagePlot.html ├── ImageTransform.html ├── ImageTranslate.html ├── LoadAndMergeMatrices.html ├── LoadSpatialCoordinates.html ├── MapFeaturesSummary-1.png ├── MapFeaturesSummary-2.png ├── MapFeaturesSummary-3.png ├── MapFeaturesSummary-4.png ├── MapFeaturesSummary.html ├── MapLabelsSummary-1.png ├── MapLabelsSummary.html ├── ReadVisiumData.html ├── Rplot001.png ├── Rplot002.png ├── Rplot003.png ├── Rplot004.png ├── Rplot005.png ├── Rplot006.png ├── Rplot007.png ├── Rplot008.png ├── STUtility2-package.html ├── Staffli-class.html ├── Staffli-get-methods.html ├── Staffli-set-methods.html ├── TileImage.html ├── celltype-prediction.html ├── centroid_angles_plot-1.png ├── centroid_angles_plot.html ├── cor-features.html ├── disconnect-regions-1.png ├── disconnect-regions-2.png ├── disconnect-regions-3.png ├── disconnect-regions-4.png ├── disconnect-regions-5.png ├── disconnect-regions.html ├── export_coordinates.html ├── export_graph.html ├── figures │ ├── logo.png │ └── sr-logo.png ├── file_server.html ├── ftrviewer-shiny.html ├── ftrviewer.html ├── generate_rigid_transform.html ├── get-network.html ├── icp-1.png ├── icp-2.png ├── icp-3.png ├── icp.html ├── index.html ├── kabsch.html ├── label-assortativity.html ├── load-images.html ├── local-G-1.png ├── local-G-2.png ├── local-G-3.png ├── local-G.html ├── manual-transform-images.html ├── mask-images-1.png ├── mask-images-2.png ├── mask-images.html ├── mbrain_dataset.html ├── mcolon_dataset.html ├── merge-1.png ├── merge.html ├── neighborhood-enrichment.html ├── osddu-shiny.html ├── osddu.html ├── paper-shiny.html ├── paper.html ├── prep_image.html ├── radial-distance-1.png ├── radial-distance-2.png ├── radial-distance-3.png ├── radial-distance.html ├── region-neighbors-1.png ├── region-neighbors-2.png ├── region-neighbors-3.png ├── region-neighbors.html ├── show.html ├── subset.html ├── transform-images-1.png ├── transform-images-2.png ├── transform-images-3.png ├── transform-images.html ├── visualize-features-1.png ├── visualize-features-2.png ├── visualize-features-3.png ├── visualize-features-4.png ├── visualize-features-5.png ├── visualize-features-6.png ├── visualize-features.html ├── visualize-labels-1.png ├── visualize-labels-2.png ├── visualize-labels-3.png ├── visualize-labels-4.png ├── visualize-labels-5.png ├── visualize-labels-6.png ├── visualize-labels-7.png ├── visualize-labels-8.png ├── visualize-labels.html ├── visualize-multiple-features-1.png ├── visualize-multiple-features-2.png ├── visualize-multiple-features-3.png └── visualize-multiple-features.html ├── region_neighbors.Rmd ├── semla.Rmd ├── slide-seq.Rmd ├── spatial_autocorrelation.Rmd ├── spatial_statistics_for_labelled_spots.Rmd ├── sr-logo.png ├── subset_and_merge.rmd └── visiumHD.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^renv$ 2 | ^renv\.lock$ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^LICENSE\.md$ 6 | ^vignettes$ 7 | ^notebooks$ 8 | ^srcjs$ 9 | ^_pkgdown\.yml$ 10 | ^docs$ 11 | ^pkgdown$ 12 | ^\.github$ 13 | ^cran-comments\.md$ 14 | ^CRAN-SUBMISSION$ 15 | ^stereoscope$ 16 | ^TODO\.md$ 17 | ^yarn\.lock$ 18 | ^webpack\.config\.js$ 19 | ^package\.json$ 20 | ^images$ 21 | inst/htmlwidgets/paper.js.map 22 | inst/htmlwidgets/osddu.js.map 23 | inst/htmlwidgets/ftrviewer.js.map 24 | .renvignore 25 | Dockerfile 26 | .Rprofile 27 | ^ftrviewer$ 28 | ^osddu$ 29 | ^paper$ 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rprofile 3 | .Rhistory 4 | .RData 5 | .Ruserdata 6 | .renvignore 7 | notebooks/ 8 | presentations/ 9 | package.json 10 | webpack.config.js 11 | yarn.lock 12 | vignettes/mousebrain/ 13 | vignettes/kidney/ 14 | vignettes/bc_visium/ 15 | vignettes/R_objects/ 16 | vignettes/demo_data/ 17 | vignettes/synthetic_spots/ 18 | vignettes/IF_data/ 19 | vignettes/hBrCa_IF 20 | vignettes/10x_data 21 | vignettes/visiumHD 22 | vignettes/compare_cell_type_mapping_NNLS_files/ 23 | vignettes/multimodal_data/ 24 | BC_data/ 25 | demo_data/ 26 | manuscript_items/ 27 | stereoscope/ 28 | renv/ 29 | Dockerfile 30 | TODO.md 31 | tests/testthat/Rplots.pdf 32 | .DS_store 33 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 1.0.0 2 | Date: 2023-04-05 11:31:35 UTC 3 | SHA: 59e8af5ced953859334e6254a43bb0e9f3460376 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2022 2 | COPYRIGHT HOLDER: semla authors 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2022 semla authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/checks.R: -------------------------------------------------------------------------------- 1 | #' Check if a Seurat object has been processed with \code{semla} 2 | #' 3 | #' @param object A Seurat object 4 | #' 5 | #' @importFrom rlang abort 6 | #' @importFrom glue glue 7 | #' 8 | #' @return an error message if conditions are not met 9 | #' 10 | #' @noRd 11 | .check_seurat_object <- function ( 12 | object 13 | ) { 14 | if (!inherits(object, what = "Seurat")) abort(glue("invalid class '{class(object)}'")) 15 | if (!"Staffli" %in% names(object@tools)) abort(c("This Seurat object does not appear to have been processed with semla.", 16 | "x" = "'Staffli' object is missing from tools slot.")) 17 | } 18 | 19 | 20 | #' Check if a Seurat object contains loaded images 21 | #' 22 | #' @param object A Seurat object 23 | #' 24 | #' @importFrom rlang abort 25 | #' @importFrom glue glue 26 | #' 27 | #' @return an error message if conditions are not met 28 | #' 29 | #' @noRd 30 | .check_seurat_images <- function ( 31 | object 32 | ) { 33 | st_object <- GetStaffli(object) 34 | if (!"raw" %in% names(st_object@rasterlists)) abort("Images have not been loaded yet. Did you run 'LoadImages()'?") 35 | } 36 | -------------------------------------------------------------------------------- /R/export_data_for_viewer.R: -------------------------------------------------------------------------------- 1 | #' Export data for FeatureViewer 2 | #' 3 | #' This is a utility function used to export data required for \code{\link{FeatureViewer}}. 4 | #' 5 | #' \code{\link{FeatureViewer}} will automatically attempt to export these files every time it's run. 6 | #' With \code{ExportDataForViewer}, you only have to export the files once and you can provide the output 7 | #' data path for \code{\link{FeatureViewer}} to look for the required files in that directory. 8 | #' 9 | #' @param object A \code{Seurat} object created with \code{semla} 10 | #' @param sampleIDs An integer vector specifying the sampleIDs for the datasets to export. By default, 11 | #' all samples are exported. 12 | #' @param outdir A character vector specifying the path to an existing directory with permission to read 13 | #' and write files. 14 | #' @param nCores Number of cores to use parallel image tiling 15 | #' @param overwrite Overwrite files if they already exists 16 | #' @param verbose Print messages 17 | #' 18 | #' @family feature-viewer-methods 19 | #' 20 | #' @import rlang 21 | #' @import glue 22 | #' @import cli 23 | #' @importFrom parallel detectCores 24 | #' 25 | #' @return A path to the directory where the data is saved 26 | #' 27 | #' @examples 28 | #' 29 | #' library(semla) 30 | #' 31 | #' se_mbrain <- readRDS(system.file("extdata/mousebrain", 32 | #' "se_mbrain", 33 | #' package = "semla")) 34 | #' se_mbrain <- LoadImages(se_mbrain) 35 | #' 36 | #' # Export viewer files to a temporary directory 37 | #' outpath <- ExportDataForViewer(se_mbrain, outdir = tempdir(), nCores = 1, overwrite = TRUE) 38 | #' outpath 39 | #' 40 | #' @export 41 | #' 42 | ExportDataForViewer <- function ( 43 | object, 44 | sampleIDs = NULL, 45 | outdir, 46 | nCores = detectCores() - 1, 47 | overwrite = FALSE, 48 | verbose = TRUE 49 | ) { 50 | 51 | # Check object 52 | .check_seurat_object(object) 53 | 54 | # Check directory 55 | stopifnot(inherits(x = outdir, what = "character"), 56 | length(outdir) == 1) 57 | if (!dir.exists(outdir)) abort(glue("oudir '{outdir}' does not exist")) 58 | if (!file.access(names = outdir, mode = 2) == 0) abort(glue("You do not have permisssion to write to '{outdir}' ")) 59 | 60 | # Check sampleIDs 61 | sampleIDs <- sampleIDs %||% { 62 | GetStaffli(object)@image_info$sampleID |> as.integer() 63 | } 64 | stopifnot(inherits(sampleIDs, what = c("integer", "numeric")), 65 | length(sampleIDs) > 0) 66 | available_sampleIDs <- GetStaffli(object)@image_info$sampleID |> as.integer() 67 | if (!all(sampleIDs %in% available_sampleIDs)) { 68 | abort(glue("Invalid sampleIDs. Possible sampleIDs are: {paste(available_sampleIDs, collapse = ', ')}")) 69 | } 70 | 71 | if (verbose) cli_alert_info("Attempting to tile H&E image(s)") 72 | imgs <- GetStaffli(object)@imgs[sampleIDs] 73 | 74 | for (i in seq_along(imgs)) { 75 | if (!file.exists(imgs[i])) { 76 | abort(glue("{imgs[i]} is not a valid path. Add a valid path to @imgs slot in 'Staffli' object")) 77 | } 78 | dirs <- TileImage(im = image_read(imgs[i]), outpath = outdir, sampleID = sampleIDs[i], overwrite = overwrite, nCores = nCores, verbose = verbose) 79 | datapath <- dirs$datapath 80 | if (verbose) cli_alert(" Exporting Visium coordinates") 81 | export_coordinates(object = object, sampleNumber = sampleIDs[i], outdir = datapath, overwrite = overwrite, verbose = FALSE) 82 | } 83 | 84 | return(datapath) 85 | } 86 | -------------------------------------------------------------------------------- /R/extdata.R: -------------------------------------------------------------------------------- 1 | #' Visium mouse brain dataset 2 | #' 3 | #' A Visium dataset obtained from a coronal tissue section of a mouse brain. 4 | #' \itemize{ 5 | #' \item{\strong{mousebrain/filtered_feature_bc_matrix.h5}:\cr light weight gene expression matrix with 188 genes in hdf5 format filtered to include spots under the tissue} 6 | #' \item{\strong{mousebrain/spatial/tissue_lowres_image.jpg}: \cr H&E image (600x565) pixels} 7 | #' \item{\strong{mousebrain/spatial/tissue_positions_list.csv}: \cr CSV file with spot coordinates} 8 | #' \item{\strong{mousebrain/spatial/scalefactors_json.json}: \cr JSON file with scalefactors} 9 | #' \item{\strong{mousebrain/se_mbrain}: \cr Seurat object stored as an .Rds file with the top 100 most variable features} 10 | #' } 11 | #' 12 | #' @name mbrain_dataset 13 | #' @family datasets 14 | NULL 15 | 16 | #' Visium mouse colon dataset 17 | #' 18 | #' A Visium dataset obtained from a "swiss roll" of a mouse colon 19 | #' \itemize{ 20 | #' \item{\strong{mousecolon/filtered_feature_bc_matrix.h5}:\cr light weight gene expression matrix with 188 genes in hdf5 format filtered to include spots under the tissue} 21 | #' \item{\strong{mousecolon/spatial/tissue_lowres_image.jpg}: \cr H&E image (600x541) pixels} 22 | #' \item{\strong{mousecolon/spatial/tissue_positions_list.csv}: \cr CSV file with spot coordinates} 23 | #' \item{\strong{mousecolon/spatial/scalefactors_json.json}: \cr JSON file with scalefactors} 24 | #' \item{\strong{mousecolon/se_mcolon}: \cr Seurat object stored as an .Rds file with the top 100 most variable features} 25 | #' \item{\strong{mousecolon/galt_spots.csv}: \cr CSV file with GALT spot barcodes} 26 | #' } 27 | #' 28 | #' @references 29 | #' \doi{10.1038/s41467-022-28497-0} 30 | #' 31 | #' @name mcolon_dataset 32 | #' @family datasets 33 | NULL 34 | -------------------------------------------------------------------------------- /R/file_server.R: -------------------------------------------------------------------------------- 1 | #' Host a file server 2 | #' 3 | #' Hosts a file server from a specified directory. See 4 | #' [beakr](https://github.com/MazamaScience/beakr) for more information. 5 | #' 6 | #' @param hostDir A directory to host files from 7 | #' @param host A string with a valid IPv4 or IPv6 address to listen on, 8 | #' Defaults to localhost "127.0.0.1" 9 | #' @param port An integer that indicates the port to listen on. 10 | #' 11 | #' @import rlang 12 | #' @import glue 13 | #' 14 | #' @return A \code{Beakr} class object server defining a server instance 15 | #' 16 | #' @examples 17 | #' \donttest{ 18 | #' 19 | #' # Host files in temporary directory 20 | #' fs <- file_server(hostDir = tempdir()) 21 | #' 22 | #' # Stop server 23 | #' beakr::stopServer(fs) 24 | #' } 25 | #' 26 | #' @export 27 | file_server <- function ( 28 | hostDir, 29 | host = "127.0.0.1", 30 | port = 8080 31 | ) { 32 | 33 | # Normalize path 34 | hostDir <- normalizePath(hostDir, winslash = "/") 35 | 36 | # Check if directory exists 37 | if (!dir.exists(hostDir)) abort(glue("Directory '{hostDir}' does not exist")) 38 | 39 | # Check if beakr is installed 40 | if (!requireNamespace("beakr")) 41 | abort(glue("Package {cli::col_br_magenta('beakr')} is required. Please install it with: \n", 42 | "install.packages('beakr')")) 43 | 44 | # Create a new beakr instance 45 | beakr <- beakr::newBeakr() 46 | 47 | # Start a file server with CORS allowed 48 | fs <- beakr |> 49 | beakr::cors(origin = "*", headers = c("Origin", "X-Requested-With", "Content-Type", "Accept", "Range")) |> 50 | # Host the directory of static files 51 | beakr::serveStaticFiles(urlPath = "/", rootPath = hostDir, verbose = FALSE) |> 52 | # Start the server on selected port 53 | beakr::listen(host = host, port = port, daemon = TRUE) 54 | 55 | return(fs) 56 | } 57 | -------------------------------------------------------------------------------- /R/semla-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | ## usethis namespace: start 5 | ## usethis namespace: end 6 | NULL 7 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | #' @param X List 2 | #' @param FUN Function to apply to list elements 3 | #' @param nCores Number of cores 4 | #' @param ... Other parameters passed to parLapply 5 | #' 6 | #' @importFrom parallel makeCluster parLapply stopCluster 7 | #' 8 | #' @noRd 9 | .winLapply <- function(X, FUN, nCores, ...) { 10 | cl <- makeCluster(nCores) 11 | res <- parLapply(cl, X, FUN, ...) 12 | stopCluster(cl) 13 | return(res) 14 | } 15 | 16 | #' @param X List 17 | #' @param FUN Function to apply to list elements 18 | #' @param nCores Number of cores 19 | #' @param ... Other parameters passed to mclapply 20 | #' 21 | #' @importFrom parallel mclapply 22 | #' 23 | #' @noRd 24 | .unixLapply <- function(X, FUN, nCores, ...) { 25 | res <- mclapply(X, FUN, mc.preschedule = TRUE, ...) 26 | return(res) 27 | } 28 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | #' @importFrom utils packageDescription 2 | #' @importFrom glue glue 3 | #' 4 | .onAttach <- function ( 5 | libname, 6 | pkgname 7 | ) { 8 | pkgVersion <- packageDescription(pkgname, fields = "Version") 9 | msg <- glue("{pkgname} v{pkgVersion}\n\n") 10 | 11 | citation <- glue("\n\nAuthors:", 12 | "\nLudvig Larsson and Lovisa Franzen") 13 | packageStartupMessage(paste0(strwrap(paste0(msg, citation)), collapse = "\n")) 14 | } 15 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | AbCapture 2 | Andersson 3 | Assortativity 4 | BH 5 | Bergenstråhle 6 | Biotechnol 7 | Bivand 8 | CATACAAAGCCGAACC 9 | CTRL 10 | Clu 11 | Colorscale 12 | Colorscales 13 | Commun 14 | CutSpatialNetwork 15 | CytAssist 16 | DOI 17 | DWS 18 | Dann 19 | DeBruine 20 | DeBruines 21 | Debruine 22 | Dentate 23 | DimReducs 24 | Downsample 25 | FEA 26 | FFPE 27 | FeatureViewer 28 | Fettisdagen 29 | Franzén 30 | Fxyd 31 | GALT 32 | Getis 33 | Gi 34 | Github 35 | Hba 36 | Hbb 37 | ICP 38 | IGLC 39 | IPv 40 | Immunofluorescence 41 | Immunoflurescence 42 | JPG 43 | JS 44 | JSON 45 | Kabsch 46 | Karsten 47 | Kleshchevnikov 48 | Letäs 49 | Loupe 50 | Macbook 51 | Machado 52 | MapFeaturesSummary 53 | MazamaScience 54 | Melcher 55 | Morlanes 56 | Muris 57 | NK 58 | NMF 59 | NNLS 60 | NNMF 61 | NaN 62 | ORCID 63 | Ord 64 | PCNA 65 | Parigi 66 | Pre 67 | Pvalb 68 | RCTD 69 | RMSD 70 | ROI 71 | ROIs 72 | RStudio 73 | RcppML 74 | Rds 75 | Renv 76 | Rmd 77 | SCT 78 | SMX 79 | SNN 80 | SRT 81 | STUtility 82 | STereoscope 83 | SciLifeLab 84 | Semmeldagen 85 | Senis 86 | Shmatko 87 | SlideSeq 88 | Staffli 89 | TBD 90 | TIF 91 | TLS 92 | Tabula 93 | Transcriptomics 94 | Triche 95 | UI 96 | UMAP 97 | UMIs 98 | Visium 99 | VisiumV 100 | Zach 101 | al 102 | anterial 103 | artefacts 104 | assortativity 105 | barchart 106 | barcode 107 | barcodes 108 | bc 109 | beakr 110 | bioconductor 111 | blurSeg 112 | bs 113 | bt 114 | celltypeprops 115 | centroid 116 | conda 117 | cran 118 | csv 119 | deconvolution 120 | deconvolve 121 | deconvolved 122 | detectCores 123 | dev 124 | dimred 125 | dn 126 | dotplot 127 | dotplots 128 | downscaled 129 | embeddings 130 | et 131 | expressional 132 | fetchable 133 | fiducials 134 | frac 135 | ftrviewer 136 | fullres 137 | funder 138 | galt 139 | ggplot 140 | github 141 | gyrus 142 | hdf 143 | https 144 | ics 145 | im 146 | imgs 147 | immunofluorescence 148 | io 149 | jpeg 150 | jpg 151 | json 152 | labelled 153 | loadings 154 | longdash 155 | lowres 156 | ludvigla 157 | magentaSeg 158 | magick 159 | mbrain 160 | mcolon 161 | microenvironment 162 | mousebrain 163 | mousecolon 164 | nCellTypes 165 | nCount 166 | nFeature 167 | nSpots 168 | nalysis 169 | nan 170 | nb 171 | ord 172 | osddu 173 | outpath 174 | overrepresented 175 | patially 176 | pearson 177 | plotly 178 | png 179 | poisson 180 | pre 181 | programatically 182 | pxl 183 | qm 184 | regionalization 185 | regionalized 186 | renv 187 | repellant 188 | repo 189 | reproducibility 190 | rescaled 191 | rescaling 192 | sagittal 193 | sampleID 194 | sampleIDs 195 | sc 196 | scRNA 197 | scalebar 198 | scalefactor 199 | scalefactors 200 | scvi 201 | se 202 | spaceranger 203 | spatnet 204 | spotfiles 205 | staffli 206 | stroma 207 | subseted 208 | swiss 209 | tabset 210 | tibble 211 | tibbles 212 | tranforms 213 | transcripto 214 | transcriptomic 215 | transcriptomics 216 | transf 217 | ventricule 218 | xy 219 | zag 220 | zig 221 | µ 222 | σ 223 | -------------------------------------------------------------------------------- /inst/extdata/mousebrain/filtered_feature_bc_matrix.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/inst/extdata/mousebrain/filtered_feature_bc_matrix.h5 -------------------------------------------------------------------------------- /inst/extdata/mousebrain/se_mbrain: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/inst/extdata/mousebrain/se_mbrain -------------------------------------------------------------------------------- /inst/extdata/mousebrain/spatial/scalefactors_json.json: -------------------------------------------------------------------------------- 1 | {"spot_diameter_fullres": 143.31714641818704, "tissue_hires_scalef": 0.1039393, "fiducial_diameter_fullres": 214.97571962728054, "tissue_lowres_scalef": 0.03118179} -------------------------------------------------------------------------------- /inst/extdata/mousebrain/spatial/tissue_lowres_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/inst/extdata/mousebrain/spatial/tissue_lowres_image.jpg -------------------------------------------------------------------------------- /inst/extdata/mousecolon/filtered_feature_bc_matrix.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/inst/extdata/mousecolon/filtered_feature_bc_matrix.h5 -------------------------------------------------------------------------------- /inst/extdata/mousecolon/se_mcolon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/inst/extdata/mousecolon/se_mcolon -------------------------------------------------------------------------------- /inst/extdata/mousecolon/spatial/scalefactors_json.json: -------------------------------------------------------------------------------- 1 | {"spot_diameter_fullres": 67.02201000000001, "tissue_hires_scalef": 0.2019998, "fiducial_diameter_fullres": 108.26633, "tissue_lowres_scalef": 0.060599938} -------------------------------------------------------------------------------- /inst/extdata/mousecolon/spatial/tissue_lowres_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/inst/extdata/mousecolon/spatial/tissue_lowres_image.jpg -------------------------------------------------------------------------------- /inst/htmlwidgets/0c1f69b256da5355cf18806b7cab12c0.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/inst/htmlwidgets/0c1f69b256da5355cf18806b7cab12c0.jpeg -------------------------------------------------------------------------------- /inst/htmlwidgets/ftrviewer.yaml: -------------------------------------------------------------------------------- 1 | # (uncomment to add a dependency) 2 | # dependencies: 3 | # - name: 4 | # version: 5 | # src: 6 | # script: 7 | # stylesheet: 8 | -------------------------------------------------------------------------------- /inst/htmlwidgets/osddu.yaml: -------------------------------------------------------------------------------- 1 | # (uncomment to add a dependency) 2 | # dependencies: 3 | # - name: 4 | # version: 5 | # src: 6 | # script: 7 | # stylesheet: 8 | -------------------------------------------------------------------------------- /inst/htmlwidgets/paper.yaml: -------------------------------------------------------------------------------- 1 | # (uncomment to add a dependency) 2 | # dependencies: 3 | # - name: 4 | # version: 5 | # src: 6 | # script: 7 | # stylesheet: 8 | -------------------------------------------------------------------------------- /man/AdjustTissueCoordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cut_spatial_network_utils.R 3 | \name{AdjustTissueCoordinates} 4 | \alias{AdjustTissueCoordinates} 5 | \title{Adjust tissue coordinates for digital unrolling} 6 | \usage{ 7 | AdjustTissueCoordinates(full_graph, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{full_graph}{A \code{tbl_graph} object generated with \code{\link{CutSpatialNetwork}}} 11 | 12 | \item{verbose}{Print messages} 13 | } 14 | \value{ 15 | A \code{tibble} with "unrolled" tissue coordinates 16 | } 17 | \description{ 18 | This function takes a \code{tbl_graph} object as input generated 19 | with \code{\link{CutSpatialNetwork}} and attempts to calculate 20 | the unrolled tissue coordinates. 21 | } 22 | \details{ 23 | The algorithm is described briefly below: 24 | 25 | First, the end point of the graph are identified. The outermost 26 | end point is assumed to be the starting point and the point at the 27 | center of the roll is assumed to be the end point. 28 | 29 | Then, the algorithm tries to find the geodesic between the 30 | two end points, forming a band of nodes which represents the shortest 31 | path between the starting point and the end point. 32 | 33 | The order of these shortest represents the distances along the x axis 34 | in the new coordinate system and the geodesics to all other nodes are used 35 | as distances on the y axis of the spots in the new coordinate system. 36 | 37 | NB: The graph has to be fully connected. If multiple sub graphs are found, 38 | only the largest graph will be kept. It is crucial that edges has been cut 39 | properly with \code{\link{CutSpatialNetwork}}, otherwise the results will be 40 | inaccurate. See the package website for examples. 41 | } 42 | -------------------------------------------------------------------------------- /man/CoordMirror.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations_coordinates.R 3 | \name{CoordMirror} 4 | \alias{CoordMirror} 5 | \title{Mirror coordinates} 6 | \usage{ 7 | CoordMirror(xy_coords, mirror.x = FALSE, mirror.y = FALSE, center = NULL) 8 | } 9 | \arguments{ 10 | \item{xy_coords}{A \code{matrix}, \code{data.frame} or \code{tbl} object with numeric x, y coordinates.} 11 | 12 | \item{mirror.x, mirror.y}{Logical specifying whether the coordinates should be reflected along 13 | the x-axis, y-axis or both.} 14 | 15 | \item{center}{Optional point (x, y) specifying the center of reflection.} 16 | } 17 | \value{ 18 | A \code{tbl} object with transformed coordinates 19 | } 20 | \description{ 21 | Mirror coordinates 22 | } 23 | \details{ 24 | The coordinate system for \code{xy_coords} should match the dimensions of the 25 | image. In other words, the coordinates should map spots to the tissue section on H&E image. 26 | A 3x3 transformation matrix is constructed by combining the following matrices: 27 | 28 | \itemize{ 29 | \item{\eqn{T(-x, -y)}: Translate coordinates to origin, i.e. (0, 0) becomes the new center \cr\tabular{llc}{ 30 | 1 \tab 0 \tab \eqn{-center_{x}} \cr 31 | 0 \tab 1 \tab \eqn{-center_{y}} \cr 32 | 0 \tab 0 \tab 1 \cr 33 | } 34 | 35 | 36 | } 37 | \item{\eqn{M_{x}}: Reflect coordinates along x-axis\tabular{lll}{ 38 | -1 \tab 0 \tab 0 \cr 39 | 0 \tab 1 \tab 0 \cr 40 | 0 \tab 0 \tab 1 \cr 41 | } 42 | 43 | 44 | } 45 | \item{\eqn{M_{y}}: Reflect coordinates along y-axis \cr\tabular{lll}{ 46 | 1 \tab 0 \tab 0 \cr 47 | 0 \tab -1 \tab 0 \cr 48 | 0 \tab 0 \tab 1 \cr 49 | } 50 | 51 | 52 | } 53 | \item{\eqn{T(x, y)}: Translate coordinates back to center \cr\tabular{llc}{ 54 | 1 \tab 0 \tab \eqn{center_{x}} \cr 55 | 0 \tab 1 \tab \eqn{center_{y}} \cr 56 | 0 \tab 0 \tab 1 \cr 57 | } 58 | 59 | 60 | } 61 | } 62 | 63 | Then, these matrices are combined to form the final transformation matrix: 64 | 65 | \eqn{T_{final} = T(x, y)*M_{y}*M_{x}*T(-x, -y)} 66 | 67 | Which can be used to transform our input coordinates: 68 | 69 | \eqn{xy_{out} = T_{final}*xy_{in}} 70 | } 71 | \examples{ 72 | library(ggplot2) 73 | 74 | # Create a data.frame with x, y coordinates 75 | xy <- data.frame(x = 1:20, y = 1:20) 76 | 77 | # Reflect coordinates along x axis 78 | xy_mx <- CoordMirror(xy, mirror.x = TRUE) |> setNames(nm = c("x", "y")) 79 | 80 | # Reflect along both x, and y axes 81 | xy_mxy <- CoordMirror(xy, mirror.x = TRUE, mirror.y = TRUE) |> setNames(nm = c("x", "y")) 82 | 83 | # Combine all coordinates 84 | xy_all <- do.call(rbind, list(cbind(xy, type = "original", ord = 1:20), 85 | cbind(xy_mx, type = "mirror_x", ord = 1:20), 86 | cbind(xy_mxy, type = "mirror_x_and_y", ord = 1:20))) 87 | xy_all$type <- factor(xy_all$type, levels = c("original", "mirror_x", "mirror_x_and_y")) 88 | 89 | # Now we can see the effects of mirroring 90 | # Mirror x flips the coordinates along the x axis while mirror_x and mirror_y 91 | # effectively inverts the coordinates, thus changing the order of the points 92 | ggplot(xy_all, aes(x, y)) + 93 | geom_point(color = "steelblue", size = 7, alpha = 0.5) + 94 | geom_text(aes(label = ord)) + 95 | facet_grid(~type) + 96 | geom_vline(xintercept = 10.5, linetype = "dashed", color = "red") + 97 | geom_hline(yintercept = 10.5, linetype = "dashed", color = "green") 98 | 99 | } 100 | \seealso{ 101 | Other transforms: 102 | \code{\link{CoordAndImageTransform}()}, 103 | \code{\link{CoordTransform}()}, 104 | \code{\link{ImageTranslate}()}, 105 | \code{\link{RigidTransformImages}()}, 106 | \code{\link{RunAlignment}()} 107 | } 108 | \author{ 109 | Ludvig Larsson 110 | } 111 | \concept{transforms} 112 | -------------------------------------------------------------------------------- /man/CoordTransform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations_coordinates.R 3 | \name{CoordTransform} 4 | \alias{CoordTransform} 5 | \title{Apply transformations to a set of x, y coordinates} 6 | \usage{ 7 | CoordTransform( 8 | xy_coords, 9 | angle = 0, 10 | center = NULL, 11 | xy_offset = c(0, 0), 12 | scalefactor = 1 13 | ) 14 | } 15 | \arguments{ 16 | \item{xy_coords}{A \code{matrix}, \code{data.frame} or \code{tibble} object with numeric x, y coordinates.} 17 | 18 | \item{angle}{Numeric value specifying the degree of rotation. Use negative angles 19 | for counter-clockwise rotation. The value needs to be in the range (-360, 360)} 20 | 21 | \item{center}{Optional point (x, y) specifying the center of rotation.} 22 | 23 | \item{xy_offset}{Optional point (x, y) specifying the translation.} 24 | 25 | \item{scalefactor}{A numeric value specifying a scaling factor between (0, 3)} 26 | } 27 | \value{ 28 | A \code{tbl} object with transformed coordinates 29 | } 30 | \description{ 31 | Apply transformations to a set of x, y coordinates 32 | } 33 | \details{ 34 | The coordinate system for \code{xy_coords} should match the dimensions of the 35 | image. In other words, the coordinates should map spots to the tissue section on H&E image. 36 | Translations and rotations are done by multiplying \code{xy_coords} with the following 37 | transformation matrix \eqn{T_{final}} as described below: 38 | 39 | \itemize{ 40 | \item{\eqn{T(-x, -y)}: Translate coordinates to origin, i.e. (0, 0) becomes the new center \cr\tabular{llc}{ 41 | 1 \tab 0 \tab \eqn{-center_{x}} \cr 42 | 0 \tab 1 \tab \eqn{-center_{y}} \cr 43 | 0 \tab 0 \tab 1 \cr 44 | } 45 | 46 | 47 | } 48 | \item{\eqn{R}: Rotate coordinates around origin \cr\tabular{ccc}{ 49 | \eqn{cos(\alpha)} \tab \eqn{-sin(\alpha)} \tab 0 \cr 50 | \eqn{sin(\alpha)} \tab \eqn{cos(\alpha)} \tab 0 \cr 51 | 0 \tab 0 \tab 1 \cr 52 | } 53 | 54 | 55 | } 56 | \item{\eqn{T(x, y)}: Translate coordinates back to center, or optionally to center + an \code{xy_offset} \cr\tabular{llc}{ 57 | 1 \tab 0 \tab \eqn{center_{x} + offset_{x}} \cr 58 | 0 \tab 1 \tab \eqn{center_{y} + offset_{y}} \cr 59 | 0 \tab 0 \tab 1 \cr 60 | } 61 | 62 | 63 | } 64 | } 65 | 66 | Then, these matrices are combined to form the final transformation matrix: 67 | 68 | \eqn{T_{final} = T(x, y)*R*T(-x, -y)} 69 | 70 | Which can be used to transform our input coordinates: 71 | 72 | \eqn{xy_{out} = T_{final}*xy_{in}} 73 | 74 | The scaling is handled separated after the translations and rotations. 75 | } 76 | \examples{ 77 | # Create a data.frame with x, y coordinates 78 | xy <- data.frame(x = 1:20, y = 1:20) 79 | 80 | # Rotate coordinates 45 degrees clockwise around the center 81 | xy_rotated <- CoordTransform(xy, angle = 45) 82 | plot(xy) 83 | points(xy_rotated, col = "red") 84 | 85 | } 86 | \seealso{ 87 | Other transforms: 88 | \code{\link{CoordAndImageTransform}()}, 89 | \code{\link{CoordMirror}()}, 90 | \code{\link{ImageTranslate}()}, 91 | \code{\link{RigidTransformImages}()}, 92 | \code{\link{RunAlignment}()} 93 | } 94 | \author{ 95 | Ludvig Larsson 96 | } 97 | \concept{transforms} 98 | -------------------------------------------------------------------------------- /man/CreateStaffliObject.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \name{CreateStaffliObject} 4 | \alias{CreateStaffliObject} 5 | \title{Create a Staffli object} 6 | \usage{ 7 | CreateStaffliObject( 8 | imgs = NULL, 9 | meta_data, 10 | image_height = 400, 11 | image_info, 12 | scalefactors 13 | ) 14 | } 15 | \arguments{ 16 | \item{imgs}{Character vector specifying paths to images in JPG, PNG or TIF format} 17 | 18 | \item{meta_data}{Spot-level metadata to add to the \code{Staffli} object. This should be a \code{tbl} with 19 | required columns 'barcode' representing the spot IDs, 'pxl_col_in_fullres' and 'pxl_row_in_fullres' 20 | which specifies the 10x Visium array coordinates and a 'sampleID' column with sample IDs} 21 | 22 | \item{image_height}{Specifies the height of the scaled images in pixels [default: 400 pixels]} 23 | 24 | \item{image_info}{a tibble with image information} 25 | 26 | \item{scalefactors}{a tibble with scalefactors sued to transform coordinates from 27 | the original image space to the downscaled images} 28 | } 29 | \value{ 30 | A \code{Staffli} object 31 | } 32 | \description{ 33 | Create a Staffli object from a set of images and associated spot coordinates 34 | } 35 | \examples{ 36 | 37 | library(semla) 38 | 39 | # Multiple samples 40 | # \%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\% 41 | # Create an object with multiple samples 42 | he_imgs <- c(system.file("extdata/mousebrain", 43 | "spatial/tissue_lowres_image.jpg", 44 | package = "semla"), 45 | system.file("extdata/mousecolon", 46 | "spatial/tissue_lowres_image.jpg", 47 | package = "semla")) 48 | spotfiles <- c(system.file("extdata/mousebrain", 49 | "spatial/tissue_positions_list.csv", 50 | package = "semla"), 51 | system.file("extdata/mousecolon", 52 | "spatial/tissue_positions_list.csv", 53 | package = "semla")) 54 | jsonfiles <- c(system.file("extdata/mousebrain", 55 | "spatial/scalefactors_json.json", 56 | package = "semla"), 57 | system.file("extdata/mousecolon", 58 | "spatial/scalefactors_json.json", 59 | package = "semla")) 60 | 61 | # Read coordinates and select relevant columns 62 | coordinates <- LoadSpatialCoordinates(spotfiles) |> 63 | select(all_of(c("barcode", "x", "y", "pxl_col_in_fullres", "pxl_row_in_fullres", "sampleID"))) 64 | 65 | # Create image_info 66 | image_info <- LoadImageInfo(he_imgs) 67 | 68 | # Read scalefactors 69 | scalefactors <- LoadScaleFactors(jsonfiles) 70 | 71 | # Add additional columns to image_info using scalefactors 72 | image_info <- UpdateImageInfo(image_info, scalefactors) 73 | 74 | # Create Staffli object 75 | staffli_object <- CreateStaffliObject(imgs = he_imgs, 76 | meta_data = coordinates, 77 | image_info = image_info, 78 | scalefactors = scalefactors) 79 | staffli_object 80 | 81 | } 82 | \author{ 83 | Ludvig Larsson 84 | } 85 | -------------------------------------------------------------------------------- /man/CutSpatialNetwork.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cut_spatial_network.R 3 | \name{CutSpatialNetwork} 4 | \alias{CutSpatialNetwork} 5 | \title{Cut spatial networks in folded tissues} 6 | \usage{ 7 | CutSpatialNetwork( 8 | object, 9 | datadir = NULL, 10 | sampleID = 1, 11 | host = "127.0.0.1", 12 | port = 8080L, 13 | container_width = "800px", 14 | container_height = "800px", 15 | overwrite_network_json = TRUE, 16 | verbose = TRUE 17 | ) 18 | } 19 | \arguments{ 20 | \item{object}{A \code{Seurat} object created with \code{semla}} 21 | 22 | \item{datadir}{A directory containing network data and image tiles} 23 | 24 | \item{sampleID}{An integer specifying a tissue section in the \code{Seurat} object} 25 | 26 | \item{host}{A string with a valid IPv4 or IPv6 address to listen on, 27 | Defaults to localhost "127.0.0.1"} 28 | 29 | \item{port}{An integer that indicates the port to listen on.} 30 | 31 | \item{container_width, container_height}{Set height and width of container} 32 | 33 | \item{overwrite_network_json}{Logical specifying if the JSON file 34 | containing the spatial network should be overwritten after completion} 35 | 36 | \item{verbose}{Print messages} 37 | } 38 | \value{ 39 | A \code{tbl_graph} object representing a spatial network 40 | } 41 | \description{ 42 | Opens an interactive viewer where a spatial network is visualized on top 43 | of an H&E image. 44 | } 45 | \details{ 46 | Each spot is connected to adjacent neighbors by edges and 47 | the edges can be cut by holding the SHIFT key while moving the cursor 48 | across them. Cut edges can be mended by holding the CTRL key while moving 49 | the cursor across them. The aim is to cut edges between spots located in separate 50 | layers. The output is a \code{tbl_graph} object representing the spatial network 51 | which can be processed further with \code{\link{AdjustTissueCoordinates}} 52 | to perform "digital unrolling". 53 | } 54 | \section{Examples}{ 55 | 56 | A tutorial can be found on our [package website](https://ludvigla.github.io/semla/). 57 | Got to tutorials -> Digital unrolling 58 | } 59 | 60 | \seealso{ 61 | export_graph 62 | 63 | Other spatial-methods: 64 | \code{\link{CorSpatialFeatures}()}, 65 | \code{\link{DisconnectRegions}()}, 66 | \code{\link{GetSpatialNetwork}()}, 67 | \code{\link{RadialDistance}()}, 68 | \code{\link{RegionNeighbors}()}, 69 | \code{\link{RunLabelAssortativityTest}()}, 70 | \code{\link{RunLocalG}()}, 71 | \code{\link{RunNeighborhoodEnrichmentTest}()} 72 | } 73 | \author{ 74 | Ludvig Larsson 75 | } 76 | \concept{spatial-methods} 77 | -------------------------------------------------------------------------------- /man/ExportDataForViewer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/export_data_for_viewer.R 3 | \name{ExportDataForViewer} 4 | \alias{ExportDataForViewer} 5 | \title{Export data for FeatureViewer} 6 | \usage{ 7 | ExportDataForViewer( 8 | object, 9 | sampleIDs = NULL, 10 | outdir, 11 | nCores = detectCores() - 1, 12 | overwrite = FALSE, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{A \code{Seurat} object created with \code{semla}} 18 | 19 | \item{sampleIDs}{An integer vector specifying the sampleIDs for the datasets to export. By default, 20 | all samples are exported.} 21 | 22 | \item{outdir}{A character vector specifying the path to an existing directory with permission to read 23 | and write files.} 24 | 25 | \item{nCores}{Number of cores to use parallel image tiling} 26 | 27 | \item{overwrite}{Overwrite files if they already exists} 28 | 29 | \item{verbose}{Print messages} 30 | } 31 | \value{ 32 | A path to the directory where the data is saved 33 | } 34 | \description{ 35 | This is a utility function used to export data required for \code{\link{FeatureViewer}}. 36 | } 37 | \details{ 38 | \code{\link{FeatureViewer}} will automatically attempt to export these files every time it's run. 39 | With \code{ExportDataForViewer}, you only have to export the files once and you can provide the output 40 | data path for \code{\link{FeatureViewer}} to look for the required files in that directory. 41 | } 42 | \examples{ 43 | 44 | library(semla) 45 | 46 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 47 | "se_mbrain", 48 | package = "semla")) 49 | se_mbrain <- LoadImages(se_mbrain) 50 | 51 | # Export viewer files to a temporary directory 52 | outpath <- ExportDataForViewer(se_mbrain, outdir = tempdir(), nCores = 1, overwrite = TRUE) 53 | outpath 54 | 55 | } 56 | \seealso{ 57 | Other feature-viewer-methods: 58 | \code{\link{FeatureViewer}()} 59 | } 60 | \concept{feature-viewer-methods} 61 | -------------------------------------------------------------------------------- /man/GetCoordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \docType{methods} 4 | \name{GetCoordinates} 5 | \alias{GetCoordinates} 6 | \alias{GetCoordinates,Staffli-method} 7 | \alias{GetCoordinates,Seurat-method} 8 | \title{Method to extract coordinates} 9 | \usage{ 10 | GetCoordinates(object) 11 | 12 | \S4method{GetCoordinates}{Staffli}(object) 13 | 14 | \S4method{GetCoordinates}{Seurat}(object) 15 | } 16 | \arguments{ 17 | \item{object}{A \code{Staffli} or \code{Seurat} object} 18 | } 19 | \value{ 20 | A \code{tbl} with spot coordinates 21 | } 22 | \description{ 23 | Method to extract coordinates 24 | } 25 | \examples{ 26 | 27 | # Load example data 28 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) |> 29 | LoadImages() 30 | 31 | # Fetch Staffli object 32 | staffli_object <- GetStaffli(se_mbrain) 33 | 34 | # Fetch coordinates from a Staffli object 35 | coordinates <- GetCoordinates(staffli_object) 36 | coordinates 37 | 38 | 39 | # Fetch images from a Seurat object 40 | coordinates <- GetCoordinates(se_mbrain) 41 | coordinates 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/GetImageInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \docType{methods} 4 | \name{GetImageInfo} 5 | \alias{GetImageInfo} 6 | \alias{GetImageInfo,Staffli-method} 7 | \alias{GetImageInfo,Seurat-method} 8 | \title{Method to extract image info} 9 | \usage{ 10 | GetImageInfo(object) 11 | 12 | \S4method{GetImageInfo}{Staffli}(object) 13 | 14 | \S4method{GetImageInfo}{Seurat}(object) 15 | } 16 | \arguments{ 17 | \item{object}{A \code{Staffli} or \code{Seurat} object} 18 | } 19 | \value{ 20 | A \code{tbl} with image information 21 | } 22 | \description{ 23 | Method to extract image info 24 | } 25 | \examples{ 26 | 27 | # Load example data 28 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) |> 29 | LoadImages() 30 | 31 | # Fetch Staffli object 32 | staffli_object <- GetStaffli(se_mbrain) 33 | 34 | # Fetch images from a Staffli object 35 | image_info <- GetImageInfo(staffli_object) 36 | image_info 37 | 38 | 39 | # Fetch images from a Seurat object 40 | image_info <- GetImageInfo(se_mbrain) 41 | image_info 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/GetImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \docType{methods} 4 | \name{GetImages} 5 | \alias{GetImages} 6 | \alias{GetImages,Staffli-method} 7 | \alias{GetImages,Seurat-method} 8 | \title{Method to extract images} 9 | \usage{ 10 | GetImages(object, image_use = c("raw", "transformed")) 11 | 12 | \S4method{GetImages}{Staffli}(object, image_use = c("raw", "transformed")) 13 | 14 | \S4method{GetImages}{Seurat}(object, image_use = c("raw", "transformed")) 15 | } 16 | \arguments{ 17 | \item{object}{A \code{Staffli} or \code{Seurat} object} 18 | 19 | \item{image_use}{A string specifying the image type to get} 20 | } 21 | \value{ 22 | A \code{list} of images in \code{raster} format 23 | } 24 | \description{ 25 | Method to extract images 26 | } 27 | \examples{ 28 | 29 | # Load example data 30 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) |> 31 | LoadImages() 32 | 33 | # Fetch Staffli object 34 | staffli_object <- GetStaffli(se_mbrain) 35 | 36 | # Fetch images from a Staffli object 37 | images <- GetImages(staffli_object) 38 | 39 | 40 | # Fetch images from a Seurat object 41 | images <- GetImages(se_mbrain) 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/GetScaleFactors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \docType{methods} 4 | \name{GetScaleFactors} 5 | \alias{GetScaleFactors} 6 | \alias{GetScaleFactors,Staffli-method} 7 | \alias{GetScaleFactors,Seurat-method} 8 | \title{Method to extract image scale factors} 9 | \usage{ 10 | GetScaleFactors(object) 11 | 12 | \S4method{GetScaleFactors}{Staffli}(object) 13 | 14 | \S4method{GetScaleFactors}{Seurat}(object) 15 | } 16 | \arguments{ 17 | \item{object}{A \code{Staffli} or \code{Seurat} object} 18 | } 19 | \value{ 20 | A \code{tbl} with image scale factors 21 | } 22 | \description{ 23 | Method to extract image scale factors 24 | } 25 | \examples{ 26 | 27 | # Load example data 28 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) |> 29 | LoadImages() 30 | 31 | # Fetch Staffli object 32 | staffli_object <- GetStaffli(se_mbrain) 33 | 34 | # Fetch images from a Staffli object 35 | scalefactors <- GetScaleFactors(staffli_object) 36 | scalefactors 37 | 38 | 39 | # Fetch images from a Seurat object 40 | scalefactors <- GetScaleFactors(se_mbrain) 41 | scalefactors 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/GetStaffli.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \docType{methods} 4 | \name{GetStaffli} 5 | \alias{GetStaffli} 6 | \alias{GetStaffli,Seurat-method} 7 | \title{Method used to extract a \code{Staffli} object from the tools slot of a 8 | \code{Seurat} object} 9 | \usage{ 10 | GetStaffli(object) 11 | 12 | \S4method{GetStaffli}{Seurat}(object) 13 | } 14 | \arguments{ 15 | \item{object}{A \code{Seurat} object} 16 | } 17 | \value{ 18 | A \code{Staffli} object 19 | } 20 | \description{ 21 | Method used to extract a \code{Staffli} object from the tools slot of a 22 | \code{Seurat} object 23 | } 24 | \examples{ 25 | 26 | # Load example data 27 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) |> 28 | LoadImages() 29 | 30 | # Fetch Staffli object from a Seurat object 31 | staffli_object <- GetStaffli(se_mbrain) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/ImageTransform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations_image.R 3 | \name{ImageTransform} 4 | \alias{ImageTransform} 5 | \title{Apply rotations and translations to an image} 6 | \usage{ 7 | ImageTransform(im, angle = 0, xy_offset = c(0, 0), scalefactor = 1) 8 | } 9 | \arguments{ 10 | \item{im}{An image of class \code{magick-image}} 11 | 12 | \item{angle}{An integer value specifying the rotation angle [-360, 360]} 13 | 14 | \item{xy_offset}{A numeric vector of length 2 providing the offsets along 15 | the x- and y-axis given as pixels. These values should not exceed the image dimensions.} 16 | 17 | \item{scalefactor}{A numeric value specifying a scaling factor between [0, 3]} 18 | } 19 | \value{ 20 | An object of class \code{magick-image} 21 | } 22 | \description{ 23 | This function takes an \code{magick-image} object as input and applies translations 24 | defined by the \code{angle} and \code{xy_offset} arguments. The output image dimensions 25 | will remain the same as the input image dimensions, meaning that the transformation might 26 | result in cropping the image. If you don't want this behavior, you should use \code{image_rotate} 27 | from the \code{magick} R package instead. 28 | } 29 | \examples{ 30 | 31 | library(magick) 32 | library(semla) 33 | lowresimagefile <- system.file("extdata/mousebrain/spatial", 34 | "tissue_lowres_image.jpg", 35 | package = "semla") 36 | im <- image_read(lowresimagefile) 37 | 38 | # rotate image 45 degrees clockwise, move image 100 pixels to the right and 100 pixels down 39 | im_transformed <- ImageTransform(im, angle = 45, xy_offset = c(100, 100)) 40 | im_transformed 41 | 42 | # rotate image 45 degrees counter-clockwise, move image 100 pixels to the left and 20 pixels up 43 | im_transformed <- ImageTransform(im, angle = -45, xy_offset = c(-100, 20)) 44 | im_transformed 45 | 46 | # shrink image to helf width/height 47 | im_transformed <- ImageTransform(im, scalefactor = 0.5) 48 | im_transformed 49 | 50 | } 51 | \author{ 52 | Ludvig Larsson 53 | } 54 | \concept{tranforms} 55 | -------------------------------------------------------------------------------- /man/ImageTranslate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations_image.R 3 | \name{ImageTranslate} 4 | \alias{ImageTranslate} 5 | \title{Apply translations} 6 | \usage{ 7 | ImageTranslate(im, xy_offset = NULL) 8 | } 9 | \arguments{ 10 | \item{im}{An image of class \code{magick-image}} 11 | 12 | \item{xy_offset}{A numeric vector of length 2 providing the offsets along 13 | the x- and y-axis given as pixels. These values should not exceed the image dimensions.} 14 | } 15 | \value{ 16 | An object of class \code{magick-image} 17 | } 18 | \description{ 19 | This function takes an \code{magick-image} object as input and applies translations 20 | defined by the \code{xy_offset} argument. The output image dimensions will remain the same 21 | as the input image dimensions, meaning that the transformation might result in cropping 22 | the image. 23 | } 24 | \examples{ 25 | 26 | library(magick) 27 | library(semla) 28 | lowresimagefile <- system.file("extdata/mousebrain/spatial", 29 | "tissue_lowres_image.jpg", 30 | package = "semla") 31 | im <- image_read(lowresimagefile) 32 | 33 | # move image 100 pixels to the right and 100 pixels down 34 | im_transformed <- ImageTranslate(im, xy_offset = c(100, 100)) 35 | im_transformed 36 | 37 | # move image 100 pixels to the left and 20 pixels up 38 | im_transformed <- ImageTranslate(im, xy_offset = c(-100, 20)) 39 | im_transformed 40 | 41 | } 42 | \seealso{ 43 | Other transforms: 44 | \code{\link{CoordAndImageTransform}()}, 45 | \code{\link{CoordMirror}()}, 46 | \code{\link{CoordTransform}()}, 47 | \code{\link{RigidTransformImages}()}, 48 | \code{\link{RunAlignment}()} 49 | } 50 | \author{ 51 | Ludvig Larsson 52 | } 53 | \concept{transforms} 54 | -------------------------------------------------------------------------------- /man/LoadAndMergeMatrices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_data.R 3 | \name{LoadAndMergeMatrices} 4 | \alias{LoadAndMergeMatrices} 5 | \title{Load and merge multiple gene expression matrices} 6 | \usage{ 7 | LoadAndMergeMatrices(samplefiles, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{samplefiles}{Character vector of file/directory paths. Paths should specify \code{.h5} or 11 | \code{.tsv}/\code{.tsv.gz} files. Alternatively, the paths could specify directories including \code{barcodes.tsv}, 12 | \code{features.tsv} and \code{matrix.mtx} files.} 13 | 14 | \item{verbose}{Print messages} 15 | } 16 | \value{ 17 | A sparse matrix of class \code{dgCMatrix} or a list of sparse matrices of class \code{dgCMatrix} 18 | } 19 | \description{ 20 | Gene expression matrices should have features in rows and spots in columns. 21 | } 22 | \details{ 23 | The merging process makes sure that all genes detected are present in the merged output. 24 | This means that if a gene is missing in a certain dataset, the spots in that dataset will 25 | be assigned with 0 expression. 26 | 27 | Spot IDs are renamed to be unique. Usually, the spots are named something similar to: 28 | \code{"ACGCCTGACACGCGCT-1", "TACCGATCCAACACTT-1"}. If a "-N" suffix is missing from 29 | the barcode IDs, it will be added. 30 | 31 | Since spot barcodes are shared across datasets, there is a risk that some of the spot IDs 32 | will be duplicated after merging. To avoid this, the suffix (e.g. "-1") is replaced by 33 | a unique suffix for each loaded matrix: "-1", "-2", "-3", ... 34 | } 35 | \section{IF data}{ 36 | 37 | If the provided h5 files store antibody capture data, \code{LoadAndMergeMatrices} will 38 | return a list of matrices. If multiple samples are loaded, the RNA expression matrices and 39 | antibody capture matrices will be merged and returned as separate elements of the list. 40 | Note that if one or more samples only have RNA expression data, the function will add empty 41 | values for those samples in the merged antibody capture matrix. 42 | } 43 | 44 | \examples{ 45 | 46 | # Load and merge two gene expression matrices 47 | samples <- 48 | c( 49 | system.file( 50 | "extdata/mousebrain", 51 | "filtered_feature_bc_matrix.h5", 52 | package = "semla" 53 | ), 54 | system.file( 55 | "extdata/mousecolon", 56 | "filtered_feature_bc_matrix.h5", 57 | package = "semla" 58 | ) 59 | ) 60 | mergedMatrix <- LoadAndMergeMatrices(samples) 61 | 62 | } 63 | \seealso{ 64 | Other pre-process: 65 | \code{\link{CreateMultiModalObject}()}, 66 | \code{\link{LoadAnnotationCSV}()}, 67 | \code{\link{LoadImageInfo}()}, 68 | \code{\link{LoadImages}()}, 69 | \code{\link{LoadScaleFactors}()}, 70 | \code{\link{LoadSpatialCoordinates}()}, 71 | \code{\link{ReadVisiumData}()}, 72 | \code{\link{UpdateImageInfo}()} 73 | } 74 | \concept{pre-process} 75 | -------------------------------------------------------------------------------- /man/LoadAnnotationCSV.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_data.R 3 | \name{LoadAnnotationCSV} 4 | \alias{LoadAnnotationCSV} 5 | \title{Load annotations from a CSV file} 6 | \usage{ 7 | LoadAnnotationCSV(paths) 8 | } 9 | \arguments{ 10 | \item{paths}{A character vector with paths to CSV files} 11 | } 12 | \value{ 13 | A \code{data.frame} object with barcode IDs and annotations 14 | } 15 | \description{ 16 | Takes a character vector with paths to CSV files and 17 | returns a \code{data.frame}. The resulting \code{data.frame} 18 | can be added to a \code{Seurat} object using the \code{AddMetaData} 19 | function. 20 | } 21 | \details{ 22 | NB: The files need to be loaded in the correct order. For example, 23 | if you have an object with 5 tissue sections, you should provide 24 | 5 \code{paths} in the correct order. 25 | } 26 | \examples{ 27 | 28 | library(semla) 29 | 30 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 31 | se_merged <- MergeSTData(se_mcolon, y = list(se_mcolon, se_mcolon)) 32 | 33 | # Get annotation file(s) 34 | annotation_files <- system.file("extdata/mousecolon", 35 | "galt_spots.csv", 36 | package = "semla") |> rep(3) 37 | 38 | # Load annotations 39 | annotations <- LoadAnnotationCSV(annotation_files) 40 | head(annotations) 41 | 42 | # Edit data.frame if needed 43 | annotations <- annotations |> 44 | rename(test = selection) 45 | 46 | # Add annotations to meta data 47 | se_merged <- AddMetaData(se_merged, metadata = annotations) 48 | 49 | # Plot new categorical variable 50 | MapLabels(se_merged, column_name = "test") 51 | 52 | } 53 | \seealso{ 54 | Other pre-process: 55 | \code{\link{CreateMultiModalObject}()}, 56 | \code{\link{LoadAndMergeMatrices}()}, 57 | \code{\link{LoadImageInfo}()}, 58 | \code{\link{LoadImages}()}, 59 | \code{\link{LoadScaleFactors}()}, 60 | \code{\link{LoadSpatialCoordinates}()}, 61 | \code{\link{ReadVisiumData}()}, 62 | \code{\link{UpdateImageInfo}()} 63 | } 64 | \concept{pre-process} 65 | -------------------------------------------------------------------------------- /man/LoadImageInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_data.R 3 | \name{LoadImageInfo} 4 | \alias{LoadImageInfo} 5 | \title{Load image information} 6 | \usage{ 7 | LoadImageInfo(imgfiles) 8 | } 9 | \arguments{ 10 | \item{imgfiles}{A character vector with file paths. Paths should specify PNG or JPEG files containing 11 | images created with spaceranger. Alternatively, the character vector can contain URLs to images.} 12 | } 13 | \value{ 14 | A \code{tbl} object with image info 15 | } 16 | \description{ 17 | Load image information 18 | } 19 | \examples{ 20 | library(semla) 21 | 22 | imgs <- 23 | Sys.glob(paths = paste0(system.file("extdata", package = "semla"), 24 | "/*/spatial/tissue_lowres_image.jpg")) 25 | image_info <- LoadImageInfo(imgs) 26 | image_info 27 | 28 | } 29 | \seealso{ 30 | Other pre-process: 31 | \code{\link{CreateMultiModalObject}()}, 32 | \code{\link{LoadAndMergeMatrices}()}, 33 | \code{\link{LoadAnnotationCSV}()}, 34 | \code{\link{LoadImages}()}, 35 | \code{\link{LoadScaleFactors}()}, 36 | \code{\link{LoadSpatialCoordinates}()}, 37 | \code{\link{ReadVisiumData}()}, 38 | \code{\link{UpdateImageInfo}()} 39 | } 40 | \concept{pre-process} 41 | -------------------------------------------------------------------------------- /man/LoadScaleFactors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_data.R 3 | \name{LoadScaleFactors} 4 | \alias{LoadScaleFactors} 5 | \title{Load scale factors} 6 | \usage{ 7 | LoadScaleFactors(scalefactorfiles) 8 | } 9 | \arguments{ 10 | \item{scalefactorfiles}{A character vector with file paths. Paths should specify JSON files containing 11 | scale factors created with spaceranger.} 12 | } 13 | \value{ 14 | A \code{tbl} with scale factors 15 | } 16 | \description{ 17 | Load coordinates from \strong{'scalefactors_json.json'} files and merge them into a \code{tibble}. 18 | } 19 | \examples{ 20 | library(semla) 21 | 22 | jsonfiles <- 23 | Sys.glob(paths = paste0(system.file("extdata", package = "semla"), 24 | "/*/spatial/scalefactors_json.json")) 25 | scalefactors <- LoadScaleFactors(jsonfiles) 26 | scalefactors 27 | 28 | } 29 | \seealso{ 30 | Other pre-process: 31 | \code{\link{CreateMultiModalObject}()}, 32 | \code{\link{LoadAndMergeMatrices}()}, 33 | \code{\link{LoadAnnotationCSV}()}, 34 | \code{\link{LoadImageInfo}()}, 35 | \code{\link{LoadImages}()}, 36 | \code{\link{LoadSpatialCoordinates}()}, 37 | \code{\link{ReadVisiumData}()}, 38 | \code{\link{UpdateImageInfo}()} 39 | } 40 | \concept{pre-process} 41 | -------------------------------------------------------------------------------- /man/LoadSpatialCoordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_data.R 3 | \name{LoadSpatialCoordinates} 4 | \alias{LoadSpatialCoordinates} 5 | \title{Load and merge multiple coordinate tables} 6 | \usage{ 7 | LoadSpatialCoordinates( 8 | coordinatefiles, 9 | remove_spots_outside_tissue = TRUE, 10 | verbose = TRUE 11 | ) 12 | } 13 | \arguments{ 14 | \item{coordinatefiles}{Character vector of file paths. Paths should specify \code{.csv} files output by spaceranger} 15 | 16 | \item{remove_spots_outside_tissue}{Should spots outside the tissue be removed?} 17 | 18 | \item{verbose}{Print messages} 19 | } 20 | \value{ 21 | An object of class \code{tbl} containing spot coordinates 22 | } 23 | \description{ 24 | Load coordinates from \strong{'tissue_positions_list.csv'} files and merge them into a \code{tibble}. 25 | } 26 | \details{ 27 | The merging process makes sure that all genes detected are present in the merged output. 28 | This means that if a gene is missing in a certain dataset, the spots in that dataset will 29 | be assigned with 0 expression. 30 | } 31 | \examples{ 32 | 33 | library(semla) 34 | 35 | # Load and merge coordinates from two samples 36 | coordinatefiles <- 37 | c(system.file("extdata/mousebrain/spatial", 38 | "tissue_positions_list.csv", 39 | package = "semla"), 40 | system.file("extdata/mousecolon/spatial", 41 | "tissue_positions_list.csv", 42 | package = "semla")) 43 | coordinates <- LoadSpatialCoordinates(coordinatefiles) 44 | 45 | } 46 | \seealso{ 47 | Other pre-process: 48 | \code{\link{CreateMultiModalObject}()}, 49 | \code{\link{LoadAndMergeMatrices}()}, 50 | \code{\link{LoadAnnotationCSV}()}, 51 | \code{\link{LoadImageInfo}()}, 52 | \code{\link{LoadImages}()}, 53 | \code{\link{LoadScaleFactors}()}, 54 | \code{\link{ReadVisiumData}()}, 55 | \code{\link{UpdateImageInfo}()} 56 | } 57 | \concept{pre-process} 58 | -------------------------------------------------------------------------------- /man/MapPointsToReference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/multimodal_object.R 3 | \name{MapPointsToReference} 4 | \alias{MapPointsToReference} 5 | \title{Map points to nearest reference spots within a distance} 6 | \usage{ 7 | MapPointsToReference( 8 | ref_coords, 9 | map_coords, 10 | distance_max = NULL, 11 | n_neighbors = 100, 12 | verbose = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{ref_coords}{A dataframe containing the reference point coordinates 17 | with the first two columns corresponding to x- and y- pixel coordinates and 18 | coordinate IDs as rownames.} 19 | 20 | \item{map_coords}{A dataframe containing the coordinates of point to map 21 | to the reference, with the first two columns corresponding to x- and y- pixel 22 | coordinates and coordinate IDs as rownames.} 23 | 24 | \item{distance_max}{The maximum distance threshold for considering 25 | a spot as a neighbor (defaults to half the minimum distance between reference points).} 26 | 27 | \item{n_neighbors}{The maximum number of neighbors to consider for 28 | each reference point (defaults to 100).} 29 | 30 | \item{verbose}{Logical indicating whether to print informative messages during 31 | execution. Defaults to TRUE.} 32 | } 33 | \value{ 34 | A dataframe with "map_coord_IDs" indicating the nearest map spot ID 35 | for each point in the reference dataframe. 36 | } 37 | \description{ 38 | This function takes two dataframes containing point coordinates 39 | (pixel column and pixel row) in the first two columns and identifies the nearest 40 | "spot" in the second dataframe for each point in the first dataframe, considering 41 | a maximum distance and a maximum number of neighbors. The coordinate ID needs to 42 | be in the rownames of the input dataframes. 43 | } 44 | -------------------------------------------------------------------------------- /man/ModifyPatchworkTitles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/themes.R 3 | \name{ModifyPatchworkTitles} 4 | \alias{ModifyPatchworkTitles} 5 | \title{Modify patchwork titles} 6 | \usage{ 7 | ModifyPatchworkTitles(p, titles) 8 | } 9 | \arguments{ 10 | \item{p}{A \code{patchwork} object} 11 | 12 | \item{titles}{A character vector matching the number of patches in \code{p}} 13 | } 14 | \value{ 15 | A \code{patchwork} object 16 | } 17 | \description{ 18 | Takes a \code{patchwork} object as input produced with \code{\link{MapFeatures}} 19 | or \code{\link{MapLabels}} and moves the legends to the right side. 20 | } 21 | \examples{ 22 | library(semla) 23 | 24 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 25 | "se_mbrain", 26 | package = "semla")) 27 | 28 | # With MapFeatures 29 | p <- MapFeatures(se_mbrain, c("nFeature_Spatial", "nCount_Spatial")) 30 | ModifyPatchworkTitles(p, titles = c("First", "Second")) 31 | 32 | # With MapLabels 33 | p <- MapLabels(se_mbrain, c("sample_id")) 34 | ModifyPatchworkTitles(p, titles = "My title") 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/ReplaceImagePaths.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \docType{methods} 4 | \name{ReplaceImagePaths} 5 | \alias{ReplaceImagePaths} 6 | \alias{ReplaceImagePaths,Staffli-method} 7 | \alias{ReplaceImagePaths,Seurat-method} 8 | \title{Replace image paths} 9 | \usage{ 10 | ReplaceImagePaths(object, paths) 11 | 12 | \S4method{ReplaceImagePaths}{Staffli}(object, paths) 13 | 14 | \S4method{ReplaceImagePaths}{Seurat}(object, paths) 15 | } 16 | \arguments{ 17 | \item{object}{A \code{Staffli} or \code{Seurat} object} 18 | 19 | \item{paths}{A character vector with image paths} 20 | } 21 | \value{ 22 | A \code{Staffli} or \code{Seurat} object with updated image paths 23 | } 24 | \description{ 25 | Replace image paths 26 | } 27 | -------------------------------------------------------------------------------- /man/Staffli-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \docType{class} 4 | \name{Staffli-class} 5 | \alias{Staffli-class} 6 | \alias{Staffli} 7 | \title{The Staffli Class} 8 | \description{ 9 | The \code{Staffli} object is designed to hold information about the spatial data generated in a 10x 10 | Visium SRT experiment. This includes paths to images, spot coordinates as well as loaded images 11 | in \code{raster} format and additional information about these 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{meta_data}}{A tibble with spot coordinates and additional meta data} 21 | 22 | \item{\code{image_height}}{The height of the scaled images in pixels} 23 | 24 | \item{\code{image_info}}{A tibble with information about the raw images} 25 | 26 | \item{\code{scalefactors}}{A tibble with information about scalefactors used to convert coordinates 27 | between the original image and down-scaled representations such as "tissue_lowres_image.jpg"} 28 | 29 | \item{\code{pixels_per_um}}{Numeric vector specifying the number of pixels in the raw images that 30 | corresponds to 1 micrometer} 31 | 32 | \item{\code{version}}{Package version.} 33 | }} 34 | 35 | \author{ 36 | Ludvig Larsson 37 | } 38 | -------------------------------------------------------------------------------- /man/Staffli-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \name{Staffli-methods} 4 | \alias{Staffli-methods} 5 | \alias{.DollarNames.Staffli} 6 | \alias{$.Staffli} 7 | \title{Staffli Methods} 8 | \usage{ 9 | \method{.DollarNames}{Staffli}(x, pattern = "") 10 | 11 | \method{$}{Staffli}(x, i, ...) 12 | } 13 | \arguments{ 14 | \item{x}{A \code{\link{Staffli}} object} 15 | 16 | \item{pattern}{ A regular expression. Only matching names are 17 | returned. 18 | } 19 | 20 | \item{i}{Name or index of one or more metadata columns} 21 | 22 | \item{...}{Arguments passed to other methods} 23 | } 24 | \value{ 25 | A selected metadata column \code{i} for object \code{x} 26 | } 27 | \description{ 28 | Methods for \code{\link{Staffli}} objects for generics defined in other 29 | packages 30 | } 31 | \section{Functions}{ 32 | \itemize{ 33 | \item \code{.DollarNames(Staffli)}: Auto completion for \code{$} access on a 34 | \code{Staffli} object 35 | 36 | \item \code{$}: Metadata access for \code{Staffli} objects 37 | 38 | }} 39 | \concept{staffli} 40 | -------------------------------------------------------------------------------- /man/ThemeClean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/themes.R 3 | \name{ThemeClean} 4 | \alias{ThemeClean} 5 | \title{Clean theme} 6 | \usage{ 7 | ThemeClean() 8 | } 9 | \value{ 10 | A \code{theme} object 11 | } 12 | \description{ 13 | Removes titles, subtitles and legends from a \code{patchwork} object 14 | } 15 | \examples{ 16 | library(semla) 17 | 18 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 19 | "se_mbrain", 20 | package = "semla")) 21 | 22 | # With MapFeatures 23 | MapFeatures(se_mbrain, c("nFeature_Spatial", "nCount_Spatial")) & 24 | ThemeClean() 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/ThemeLegendRight.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/themes.R 3 | \name{ThemeLegendRight} 4 | \alias{ThemeLegendRight} 5 | \title{Move legend to right side} 6 | \usage{ 7 | ThemeLegendRight() 8 | } 9 | \value{ 10 | A \code{theme} object 11 | } 12 | \description{ 13 | Move the legends in a \code{patchwork} object to the right hand side of the plots 14 | } 15 | \examples{ 16 | library(semla) 17 | 18 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 19 | "se_mbrain", 20 | package = "semla")) 21 | 22 | # With MapFeatures 23 | MapFeatures(se_mbrain, c("nFeature_Spatial", "nCount_Spatial")) & 24 | ThemeLegendRight() 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/TileImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tile_images.R 3 | \name{TileImage} 4 | \alias{TileImage} 5 | \title{Tile an H&E image} 6 | \usage{ 7 | TileImage( 8 | im, 9 | sampleID = 1, 10 | outpath = NULL, 11 | maxZoomLevel = 4, 12 | maxImgWidth = 10000, 13 | nCores = detectCores() - 1, 14 | overwrite = FALSE, 15 | verbose = TRUE 16 | ) 17 | } 18 | \arguments{ 19 | \item{im}{An image of class \code{magick-image}} 20 | 21 | \item{sampleID}{The section number to use. This number will be appended to the output files names} 22 | 23 | \item{outpath}{A string specifying an output directory to save the tiled image in.} 24 | 25 | \item{maxZoomLevel}{Max zoom level} 26 | 27 | \item{maxImgWidth}{Safety threshold to make sure that the zoom level doesn't get too deep.} 28 | 29 | \item{nCores}{Number of cores to use for threading} 30 | 31 | \item{overwrite}{If the the folder '/viewer_data' already exists, it will be overwritten.} 32 | 33 | \item{verbose}{Print messages} 34 | } 35 | \value{ 36 | A character vector with the tile path 37 | } 38 | \description{ 39 | This function takes an image of class \code{magick-image} and create a tile 40 | map. The size of each tile is 256x256 pixels and the number of zoom levels 41 | are determined from the automatically. 42 | } 43 | \examples{ 44 | \donttest{ 45 | 46 | library(magick) 47 | library(shiny) 48 | library(leaflet) 49 | 50 | # Download hires image 51 | he_img <- file.path("https://data.mendeley.com/public-files/datasets/kj3ntnt6vb/files", 52 | "d97fb9ce-eb7d-4c1f-98e0-c17582024a40/file_downloaded") 53 | 54 | # Load H&E image with magick 55 | im <- image_read(he_img) 56 | 57 | # tile image and return path to tiles 58 | tile_res <- TileImage(im, outpath = tempdir(), nCores = 1, overwrite = TRUE) 59 | 60 | # Create a simple viewer with leaflet 61 | ui <- fluidPage( 62 | leafletOutput("map", height = 512, width = 512), 63 | ) 64 | 65 | server <- function(input, output, session) { 66 | addResourcePath("mytiles", tile_res$tilepath) 67 | output$map <- renderLeaflet({ 68 | leaflet(options = leafletOptions(preferCanvas = TRUE)) \%>\% 69 | addTiles(urlTemplate = "/mytiles/{z}/{x}_{y}.jpg", 70 | options = tileOptions(continuousWorld = TRUE, 71 | tileSize = "256", 72 | minZoom = 1, 73 | maxZoom = 3)) 74 | }) 75 | } 76 | if (interactive()) { 77 | shinyApp(ui, server) 78 | } 79 | } 80 | 81 | } 82 | \author{ 83 | Ludvig Larsson 84 | } 85 | -------------------------------------------------------------------------------- /man/UpdateImageInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_data.R 3 | \name{UpdateImageInfo} 4 | \alias{UpdateImageInfo} 5 | \title{Update an \code{image_info} tibble} 6 | \usage{ 7 | UpdateImageInfo(image_info, scalefactors) 8 | } 9 | \arguments{ 10 | \item{image_info}{A \code{tbl} object with image info} 11 | 12 | \item{scalefactors}{A \code{tbl} object with scale factors} 13 | } 14 | \value{ 15 | A \code{tbl} object with image info 16 | } 17 | \description{ 18 | Takes two \code{tbl} objects as input, one with image information produced with 19 | \code{\link{LoadImageInfo}} and one with scale factors produced with 20 | \code{\link{LoadScaleFactors}}. The scale factors are used to calculate the 21 | width and height of the original H&E image which will be added to the output 22 | \code{tbl}. 23 | } 24 | \seealso{ 25 | Other pre-process: 26 | \code{\link{CreateMultiModalObject}()}, 27 | \code{\link{LoadAndMergeMatrices}()}, 28 | \code{\link{LoadAnnotationCSV}()}, 29 | \code{\link{LoadImageInfo}()}, 30 | \code{\link{LoadImages}()}, 31 | \code{\link{LoadScaleFactors}()}, 32 | \code{\link{LoadSpatialCoordinates}()}, 33 | \code{\link{ReadVisiumData}()} 34 | } 35 | \concept{pre-process} 36 | -------------------------------------------------------------------------------- /man/UpdateSTUtilityV1Object.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/update_stutilityv1_object.R 3 | \name{UpdateSTUtilityV1Object} 4 | \alias{UpdateSTUtilityV1Object} 5 | \title{Update an STUtility v1 object to work with \code{semla}} 6 | \usage{ 7 | UpdateSTUtilityV1Object(object, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{object}{A \code{Seurat} object created with \code{STUtility} v1} 11 | 12 | \item{verbose}{Print messages} 13 | } 14 | \value{ 15 | A \code{Seurat} object compatible with \code{semla} 16 | } 17 | \description{ 18 | Some features will no longer be available when updating an \code{STUtility} v1 object. 19 | \code{STUtility} v1 objects do not store information about scaling factors to convert 20 | between pixels and real distances which will set limitations on some of the 21 | visualization methods and spatial functions. To mitigate these issues, you can 22 | either reload the data from the raw space ranger output files or manually add 23 | the missing information stored in the "scalefactors_json.json" files. 24 | } 25 | \details{ 26 | Note that valid image paths need to be available from the \code{STUtility} v1 object. 27 | If not, you can set the paths manually before updating the object: 28 | \code{old_se@tools$Staffli@imgs <- c("path/to/im1.jpg", "path/to/im2.jpg", ...)} 29 | } 30 | \examples{ 31 | 32 | \dontrun{ 33 | se_old_url <- file.path("https://data.mendeley.com/public-files/datasets/kj3ntnt6vb/files", 34 | "8f9d3dee-a026-40f0-be66-2df693f9db66/file_downloaded") 35 | 36 | # Load old STUtility object 37 | se_old <- readRDS(url(se_old_url)) 38 | 39 | # Update imgs slot of Staffli object to a valid path or URL (H&E image) 40 | he_img <- file.path("https://data.mendeley.com/public-files/datasets/kj3ntnt6vb/files", 41 | "d97fb9ce-eb7d-4c1f-98e0-c17582024a40/file_downloaded") 42 | se_old@tools$Staffli@imgs <- he_img 43 | 44 | # Update old STUtility object 45 | se_new <- UpdateSTUtilityV1Object(se_old) 46 | } 47 | 48 | } 49 | \author{ 50 | Ludvig Larsson 51 | } 52 | -------------------------------------------------------------------------------- /man/UpdateSeuratForSemla.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/seurat_to_semla.R 3 | \name{UpdateSeuratForSemla} 4 | \alias{UpdateSeuratForSemla} 5 | \title{Update a Seurat object for compatibility with semla} 6 | \usage{ 7 | UpdateSeuratForSemla( 8 | object, 9 | image_type = c("tissue_lowres", "tissue_hires"), 10 | verbose = TRUE 11 | ) 12 | } 13 | \arguments{ 14 | \item{object}{An object of class \code{Seurat} with Visium data} 15 | 16 | \item{image_type}{One of "tissue_lowres" or "tissue_hires", specifying 17 | what H&E image was loaded into the \code{Seurat} object. Only used for 18 | "VisiumV1" data.} 19 | 20 | \item{verbose}{Print messages} 21 | } 22 | \value{ 23 | A \code{Seurat} object compatible with semla 24 | } 25 | \description{ 26 | In order to make a \code{Seurat} object with \code{semla}, 27 | you can use \code{AddSemlaToSeurat} to add the required 28 | data to the \code{Seurat} object. This assumes that 29 | the \code{Seurat} object contains one or more "VisiumV1" 30 | object(s) in the \code{images} slot. Alternatively, you 31 | can convert a \code{Seurat} object with "SlideSeq" data. 32 | } 33 | \section{VisiumV1}{ 34 | 35 | Note that you need to specify what H&E image was loaded, 36 | one of "tissue_lowres" or "tissue_hires". If this argument 37 | is incorrect, the tissue coordinates will be misplaced. 38 | 39 | Visit the \href{https://ludvigla.github.io/semla/articles/getting_started.html}{getting started} 40 | tutorial on our package website for an example on how to convert a \code{Seurat} object with 41 | VisiumV1 data. 42 | } 43 | 44 | \section{VisiumV2}{ 45 | 46 | Note that you need to specify what H&E image was loaded, 47 | one of "tissue_lowres" or "tissue_hires". If this argument 48 | is incorrect, the tissue coordinates will be misplaced. 49 | 50 | The \href{https://ludvigla.github.io/semla/articles/getting_started.html}{getting started} 51 | tutorial applies also for VisiumV2 assays. If you are working with VisiumHD data however, 52 | we recommend loading the data using \code{semla}'s own functions, as detailed in the 53 | \href{https://ludvigla.github.io/semla/articles/visiumHD.html}{VisiumHD} tutorial. 54 | } 55 | 56 | \section{SlideSeq}{ 57 | 58 | For SlideSeq data, there's no additional H&E image provided. If you convert 59 | a Seurat object containing SlideSeq data, all image related functionality 60 | of \code{semla} will be inaccessible. 61 | } 62 | 63 | \examples{ 64 | \dontrun{ 65 | library(semla) 66 | library(SeuratData) 67 | 68 | # Load example Seurat object with VisiumV1/VisiumV2 data (depends on your Seurat version) 69 | InstallData("stxBrain") 70 | brain <- LoadData("stxBrain", type = "anterior1") 71 | 72 | # Make Seurat object compatible with semla 73 | brain_semla <- UpdateSeuratForSemla(brain) 74 | 75 | # Load example Seurat object with SlideSeq data 76 | InstallData("ssHippo") 77 | slide_seq <- LoadData("ssHippo") 78 | 79 | # Make Seurat object compatible with semla 80 | slide_seq <- UpdateSeuratForSemla(slide_seq) 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /man/UpdateSeuratFromSemla.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/semla_to_seurat.R 3 | \name{UpdateSeuratFromSemla} 4 | \alias{UpdateSeuratFromSemla} 5 | \title{Update a Seurat object created with \code{semla} for compatibility with \code{Seurat}'s spatial functions} 6 | \usage{ 7 | UpdateSeuratFromSemla(object, image_use = "raw", verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{object}{An object of class \code{Seurat} with Visium data, created with \code{semla}} 11 | 12 | \item{image_use}{String specifying image type to use, either "raw" or "transformed"} 13 | 14 | \item{verbose}{Print messages} 15 | } 16 | \value{ 17 | A \code{Seurat} object compatible with with \code{Seurat}'s spatial functions 18 | } 19 | \description{ 20 | Update a Seurat object created with \code{semla} for compatibility with \code{Seurat}'s spatial functions 21 | } 22 | \examples{ 23 | 24 | library(semla) 25 | 26 | # Load example Visium data 27 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 28 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 29 | se_merged <- MergeSTData(se_mbrain, se_mcolon) 30 | 31 | # Update object 32 | se_merged <- UpdateSeuratFromSemla(se_merged) 33 | 34 | # Use Seurat functions 35 | SpatialFeaturePlot(se_merged, features = "Nrgn") 36 | 37 | # Transform images in object 38 | se_merged <- LoadImages(se_merged) 39 | rotation_angle <- get_array_rotation(se_merged, grid_pattern = "hexagonal") 40 | transforms <- rbind(generate_rigid_transform(sampleID = 1L, angle = rotation_angle$`1`), 41 | generate_rigid_transform(sampleID = 2L, angle = 12)) 42 | se_merged <- RigidTransformImages(se_merged, transforms = transforms) 43 | 44 | # Update object 45 | se_raw <- UpdateSeuratFromSemla(se_merged, image_use = "transformed") 46 | se_transformed <- UpdateSeuratFromSemla(se_merged, image_use = "raw") 47 | 48 | # Use Seurat functions 49 | p1 <- SpatialFeaturePlot(se_raw, features = "Nrgn") 50 | p2 <- SpatialFeaturePlot(se_transformed, features = "Nrgn") 51 | p1 | p2 52 | 53 | } 54 | -------------------------------------------------------------------------------- /man/centroid_angles_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/radial_distance_plot.R 3 | \name{centroid_angles_plot} 4 | \alias{centroid_angles_plot} 5 | \title{Draw a centroid angle plot} 6 | \usage{ 7 | centroid_angles_plot(nbreaks = 9, centroid_size = 8) 8 | } 9 | \arguments{ 10 | \item{nbreaks}{Number of intervals to cut the angles into} 11 | 12 | \item{centroid_size}{Size of the centroid spot} 13 | } 14 | \value{ 15 | A \code{ggplot} object 16 | } 17 | \description{ 18 | Draw a centroid angle plot 19 | } 20 | \examples{ 21 | # Draw a plot 22 | centroid_angles_plot(9) 23 | 24 | } 25 | -------------------------------------------------------------------------------- /man/export_coordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prepare_for_feature_viewer.R 3 | \name{export_coordinates} 4 | \alias{export_coordinates} 5 | \title{Export spatial coordinates to a JSON file} 6 | \usage{ 7 | export_coordinates( 8 | object, 9 | sampleNumber = 1L, 10 | outdir, 11 | overwrite = FALSE, 12 | verbose = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{object}{A \code{Seurat} object created with \code{semla}} 17 | 18 | \item{sampleNumber}{An integer specifying a sample ID to export 19 | spatial network for} 20 | 21 | \item{outdir}{Name of a directory to export JSON file to} 22 | 23 | \item{overwrite}{Should an existing coordinate file be overwritten?} 24 | 25 | \item{verbose}{Print messages} 26 | } 27 | \value{ 28 | No return value, writes coordinates to a file 29 | } 30 | \description{ 31 | Utility function to prepare data for \code{\link{FeatureViewer}}. 32 | The exported JSON file should be exported to the same directory as 33 | the H&E image tiles generated with \code{\link{TileImage}} 34 | } 35 | \details{ 36 | Coordinates are located outside the H&E images will not be shown in the viewer. 37 | } 38 | \examples{ 39 | library(semla) 40 | 41 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 42 | "se_mbrain", 43 | package = "semla")) 44 | 45 | export_coordinates(se_mbrain, outdir = tempdir(), overwrite = TRUE) 46 | 47 | } 48 | -------------------------------------------------------------------------------- /man/export_graph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prepare_for_digital_unroll.R 3 | \name{export_graph} 4 | \alias{export_graph} 5 | \title{Export a spatial graph to a JSON file} 6 | \usage{ 7 | export_graph(object, sampleID = 1L, outdir, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{object}{A \code{Seurat} object created with \code{semla}} 11 | 12 | \item{sampleID}{An integer specifying a sample ID to export 13 | spatial network for} 14 | 15 | \item{outdir}{Name of a directory to export JSON file to} 16 | 17 | \item{verbose}{Print messages} 18 | } 19 | \value{ 20 | No return value, writes data to an output directory 21 | } 22 | \description{ 23 | Utility function to prepare data for \code{\link{CutSpatialNetwork}}. 24 | The exported JSON file should be exported to the same directory as 25 | the H&E image tiles generated with \code{\link{TileImage}} 26 | } 27 | \examples{ 28 | 29 | library(semla) 30 | 31 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 32 | 33 | # Export graph as a JSON file to a temporary directory 34 | export_graph(se_mbrain, sampleID = 1L, outdir = tempdir()) 35 | 36 | } 37 | \seealso{ 38 | CutSpatialNetwork 39 | } 40 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/man/figures/logo.png -------------------------------------------------------------------------------- /man/figures/sr-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/man/figures/sr-logo.png -------------------------------------------------------------------------------- /man/file_server.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/file_server.R 3 | \name{file_server} 4 | \alias{file_server} 5 | \title{Host a file server} 6 | \usage{ 7 | file_server(hostDir, host = "127.0.0.1", port = 8080) 8 | } 9 | \arguments{ 10 | \item{hostDir}{A directory to host files from} 11 | 12 | \item{host}{A string with a valid IPv4 or IPv6 address to listen on, 13 | Defaults to localhost "127.0.0.1"} 14 | 15 | \item{port}{An integer that indicates the port to listen on.} 16 | } 17 | \value{ 18 | A \code{Beakr} class object server defining a server instance 19 | } 20 | \description{ 21 | Hosts a file server from a specified directory. See 22 | [beakr](https://github.com/MazamaScience/beakr) for more information. 23 | } 24 | \examples{ 25 | \donttest{ 26 | 27 | # Host files in temporary directory 28 | fs <- file_server(hostDir = tempdir()) 29 | 30 | # Stop server 31 | beakr::stopServer(fs) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/ftrviewer-shiny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ftrviewer.R 3 | \name{ftrviewer-shiny} 4 | \alias{ftrviewer-shiny} 5 | \alias{ftrviewerOutput} 6 | \alias{renderFtrviewer} 7 | \title{Shiny bindings for ftrviewer} 8 | \usage{ 9 | ftrviewerOutput(outputId, width = "100\%", height = "400px") 10 | 11 | renderFtrviewer(expr, env = parent.frame(), quoted = FALSE) 12 | } 13 | \arguments{ 14 | \item{outputId}{output variable to read from} 15 | 16 | \item{width, height}{Must be a valid CSS unit (like \code{'100\%'}, 17 | \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a 18 | string and have \code{'px'} appended.} 19 | 20 | \item{expr}{An expression that generates a ftrviewer} 21 | 22 | \item{env}{The environment in which to evaluate \code{expr}.} 23 | 24 | \item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This 25 | is useful if you want to save an expression in a variable.} 26 | } 27 | \value{ 28 | A \code{shiny.tag.list} output or a \code{shiny.render.function} 29 | function produced to be used in a \code{shiny} app. \code{ftrviewerOutput} 30 | is used in the UI and \code{renderFtrviewer} on the server side. 31 | } 32 | \description{ 33 | Output and render functions for using ftrviewer within Shiny 34 | applications and interactive Rmd documents. 35 | } 36 | -------------------------------------------------------------------------------- /man/ftrviewer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ftrviewer.R 3 | \name{ftrviewer} 4 | \alias{ftrviewer} 5 | \title{Open a feature viewer react application} 6 | \usage{ 7 | ftrviewer( 8 | host = "127.0.0.1", 9 | port = "8080", 10 | sampleID = 1, 11 | values, 12 | opacities, 13 | opacity = 1, 14 | range, 15 | scaleByOpacity = FALSE, 16 | isNumeric = TRUE, 17 | useLasso = FALSE, 18 | levels = character(), 19 | categories = character(), 20 | colors = rev(RColorBrewer::brewer.pal(n = 9, name = "Spectral")), 21 | container_width = 800, 22 | container_height = 800, 23 | spot_size = 0.003, 24 | elementId = NULL 25 | ) 26 | } 27 | \arguments{ 28 | \item{host}{The host address. Defaults to localhost "127.0.0.1"} 29 | 30 | \item{port}{A number for a valid port} 31 | 32 | \item{sampleID}{A section number} 33 | 34 | \item{values}{A vector of numeric or categorical values} 35 | 36 | \item{opacities}{A numeric vector of opacity values} 37 | 38 | \item{opacity}{An integer of length 1 specifying a fixed opacity value} 39 | 40 | \item{range}{A numeric vector of length 2 specifying a range of values (color domain)} 41 | 42 | \item{scaleByOpacity}{A logical specifying if the opacity should be set by 43 | \code{opacities} or \code{opacity}} 44 | 45 | \item{isNumeric}{A logical specifying if the input is numeric or not} 46 | 47 | \item{useLasso}{A logical specifying if the lasso selection tool should be activated} 48 | 49 | \item{levels}{Category levels for coloring of values} 50 | 51 | \item{categories}{A character vector with the categories available} 52 | 53 | \item{colors}{A character vector of colors} 54 | 55 | \item{container_width, container_height}{Container width/height in pixels} 56 | 57 | \item{spot_size}{A numeric value specifying the spot radius} 58 | 59 | \item{elementId}{The id of the viewer element} 60 | } 61 | \value{ 62 | A \code{htmlwidget} to be used in a \code{shiny} application 63 | } 64 | \description{ 65 | This function will open a react application that can 66 | be used to interactively visualize categorical or numeric features 67 | as spatial maps. For the application to run properly, relevant data needs 68 | to be available via a file server. This function is intended to be used 69 | within a shiny app 70 | } 71 | \examples{ 72 | 73 | library(semla) 74 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 75 | se_mbrain <- LoadImages(se_mbrain) 76 | 77 | \dontrun{ 78 | # Export data for viewer 79 | datapath <- ExportDataForViewer(se_mbrain, outdir = tempdir()) 80 | 81 | if (interactive()) { 82 | # Start file server 83 | file_server(datapath) 84 | 85 | # Run feature viewer widget 86 | ftrviewer(values = as.numeric(se_mbrain$nFeature_Spatial), 87 | opacities = rep(1, ncol(se_mbrain)), isNumeric = TRUE, 88 | range = range(se_mbrain$nFeature_Spatial)) 89 | 90 | # Stop file server 91 | beakr::stopAllServers() 92 | } 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /man/generate_rigid_transform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rigid_transform.R 3 | \name{generate_rigid_transform} 4 | \alias{generate_rigid_transform} 5 | \title{Utility function to generate a tibble with image transformations} 6 | \usage{ 7 | generate_rigid_transform( 8 | sampleID = 1, 9 | mirror_x = FALSE, 10 | mirror_y = FALSE, 11 | angle = 0, 12 | tr_x = 0, 13 | tr_y = 0, 14 | scalefactor = 1 15 | ) 16 | } 17 | \arguments{ 18 | \item{sampleID}{An integer specifying a sample ID} 19 | 20 | \item{mirror_x, mirror_y}{Logical specifying if the image and spots should be mirrored 21 | along the x- and/or y-axis} 22 | 23 | \item{angle}{Numeric value specifying the degree of rotation. Use negative angles 24 | for counter-clockwise rotation. The value needs to be in the range (-360, 360)} 25 | 26 | \item{tr_x, tr_y}{Integer values for translations along the x- and y-axis} 27 | 28 | \item{scalefactor}{A numeric value specifying a scaling factor between (0, 3)} 29 | } 30 | \value{ 31 | A \code{tbl} with image transformations 32 | } 33 | \description{ 34 | Utility function to generate a tibble with image transformations 35 | } 36 | \examples{ 37 | 38 | # Flip along x axis and rotate 45 degrees 39 | generate_rigid_transform(sampleID = 1, mirror_x = TRUE, angle = 45) 40 | 41 | # Move image 100 pixels along x and y axes 42 | generate_rigid_transform(sampleID = 1, tr_x = 100, tr_y = 100) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/icp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/icp.R 3 | \name{icp} 4 | \alias{icp} 5 | \title{Iterative Closest Point algorithm ICP} 6 | \usage{ 7 | icp(xy_ref, xy_query, iterations = 100) 8 | } 9 | \arguments{ 10 | \item{xy_ref}{m x 2 numeric matrix of reference points} 11 | 12 | \item{xy_query}{n x 2 numeric matrix of query points} 13 | 14 | \item{iterations}{Number of iterations to run before stopping the ICP} 15 | } 16 | \value{ 17 | A list with the following objects: 18 | 19 | \itemize{ 20 | \item{y_transf: n x 2 matrix of aligned query points} 21 | \item{rot_mat: 2 x 2 rotation matrix} 22 | } 23 | } 24 | \description{ 25 | Aligns two sets of unpaired point sets by applying rotations and translations. 26 | The point sets can be of unequal length. 27 | } 28 | \examples{ 29 | 30 | library(semla) 31 | library(dplyr) 32 | library(ggplot2) 33 | 34 | # Load example mouse brain data 35 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 36 | "se_mbrain", 37 | package = "semla")) 38 | 39 | # Get spatial network 40 | spatnet <- GetSpatialNetwork(se_mbrain) 41 | 42 | # Keep tissue border points 43 | n1 <- spatnet[[1]] |> 44 | filter(nn < 6) 45 | ggplot(n1, aes(x_start, y_start)) + 46 | geom_point() + 47 | scale_y_reverse() 48 | 49 | # get spot coordinates points 50 | xy <- GetStaffli(se_mbrain)@meta_data |> 51 | filter(barcode \%in\% unique(n1$from)) |> 52 | select(pxl_col_in_fullres, pxl_row_in_fullres) |> 53 | setNames(nm = c("x", "y")) |> 54 | bind_cols(type = "set1") 55 | xy_diff <- CoordTransform(xy_coords = xy[, 1:2], 56 | angle = 30, 57 | xy_offset = c(500, 500)) |> 58 | slice_sample(n = nrow(xy) - 100) |> 59 | setNames(nm = c("x", "y")) |> 60 | bind_cols(type = "set2") 61 | xy_orig <- bind_rows(xy, xy_diff) 62 | 63 | # Plot point sets 64 | ggplot(xy_orig, aes(x, y, color = type)) + 65 | geom_point() + 66 | scale_y_reverse() + 67 | labs(title = "Original point sets") 68 | 69 | res <- icp(xy_ref = xy[, 1:2], xy_query = xy_diff[, 1:2]) 70 | 71 | xy_aligned <- xy |> 72 | bind_rows(bind_cols(setNames(res$y_transf|> as_tibble(.name_repair = "minimal"), 73 | nm = c("x", "y")), 74 | type = "set2_aligned")) 75 | 76 | # Plot aligned point sets 77 | ggplot(xy_aligned, aes(x, y, color = type)) + 78 | geom_point() + 79 | scale_y_reverse() + 80 | labs(title = "Aligned point sets") 81 | 82 | # We can obtain the rotation angle in degrees from 83 | # the results 84 | atan2(res$rot_mat[2, 1], res$rot_mat[1, 1])*(180/pi) 85 | 86 | } 87 | -------------------------------------------------------------------------------- /man/kabsch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/icp.R 3 | \name{kabsch} 4 | \alias{kabsch} 5 | \title{Kabsch Algorithm} 6 | \usage{ 7 | kabsch(pm, qm) 8 | } 9 | \arguments{ 10 | \item{pm}{n x 2 matrix of points to align to \code{qm}.} 11 | 12 | \item{qm}{n x 2 matrix of reference points.} 13 | } 14 | \value{ 15 | A list with the rotation matrix "um", the aligned coordinates "qm" 16 | and the target coordinates "pm" 17 | } 18 | \description{ 19 | Aligns two sets of points via rotations and translations. 20 | } 21 | \details{ 22 | Given two sets of points, with one specified as the reference set, 23 | the other set will be rotated so that the RMSD between the two is minimized. 24 | The format of the matrix is that there should be one row for each of 25 | n observations, and the number of columns, d, specifies the dimensionality 26 | of the points. The point sets must be of equal size and with the same 27 | ordering, i.e. point one of the second matrix is mapped to point one of 28 | the reference matrix, point two of the second matrix is mapped to point two 29 | of the reference matrix, and so on. 30 | } 31 | \section{Author}{ 32 | 33 | The original code was written by James Melville. See references for link to 34 | the GitHub gist where the code was taken from. 35 | } 36 | 37 | \references{ 38 | \url{https://gist.github.com/jlmelville/9b4e5d076e719a7541881e8cbf58a895} 39 | \url{https://en.wikipedia.org/wiki/Kabsch_algorithm} 40 | } 41 | -------------------------------------------------------------------------------- /man/label-assortativity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/spatial_neighborhood_stats.R 3 | \name{RunLabelAssortativityTest} 4 | \alias{RunLabelAssortativityTest} 5 | \title{Label Assortativity Analysis} 6 | \usage{ 7 | RunLabelAssortativityTest( 8 | object, 9 | column_name, 10 | n_permutations = 100, 11 | nCores = parallel::detectCores() - 1, 12 | seed = 123, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{A Seurat object} 18 | 19 | \item{column_name}{Column name in metadata corresponding to label ID of the spots.} 20 | 21 | \item{n_permutations}{Integer specifying number of iterations the labels should be randomized 22 | [default: 100]. Recommended to increase the number of permutations to >=100 for more robust 23 | results. A lower number of permutations will result in high standard deviations and thus more 24 | unreliable output} 25 | 26 | \item{nCores}{Number of cores [default: parallel::detectCores() - 1]} 27 | 28 | \item{seed}{A seed to use for reproducibility [default: 123]} 29 | 30 | \item{verbose}{Print messages [default: TRUE]} 31 | } 32 | \value{ 33 | A tibble with scores for each label. 34 | } 35 | \description{ 36 | Performs a network assortativity test for each label, describing whether the spots of that 37 | label displays a clustered or dispersed spatial pattern. 38 | } 39 | \details{ 40 | This analysis is inspired by the Newman's Assortativity measure by looking at the 41 | average degree of spots belonging to the same class or label (specified with \code{column_name}). 42 | The hypothesis that we want to address is that spots of the same label will lie next 43 | to each other in an aggregated fashion, as compared to being randomly dispersed throughout 44 | the tissue. As the average degree within a label may change based on the total number of 45 | observations, we scale it towards the maximum average degree (k) possible in the network (for 46 | Visium, the theoretical max avg k is 6) and the minimum avg k you would expect to see if spots 47 | are randomly dispersed. With the \code{n_permutations} argument, you can specify the number of 48 | iterations for generating a mean of the minimum avg k for each label. 49 | The output of this function is a tibble table with entries for each label corresponding to 50 | the observed avg k (\code{avg_k}), the mean of the randomized avg k (\code{min_avg_k_mean}), the standard 51 | deviation of the randomized avg k (\code{min_avg_k_sd}), and the scaled avg k (\code{avg_k_scaled}), which 52 | has been scaled towards the network max avg k (\code{k_max}) and thus goes from 0 (completely randomly 53 | dispersed) to 1 (fully connected). 54 | } 55 | \examples{ 56 | \donttest{ 57 | library(semla) 58 | 59 | # Read data 60 | se <- readRDS(system.file("extdata/mousebrain", 61 | "se_mbrain", 62 | package = "semla")) 63 | 64 | # Generate clusters 65 | se <- se |> 66 | NormalizeData() |> 67 | ScaleData() |> 68 | FindVariableFeatures() |> 69 | RunPCA() |> 70 | FindNeighbors(reduction = "pca", dims = 1:30) |> 71 | FindClusters() 72 | 73 | # Run Label Assortativity Analysis 74 | res <- RunLabelAssortativityTest(object = se, 75 | column_name = "seurat_clusters", 76 | n_permutations = 100, 77 | nCores = 1) 78 | 79 | res |> arrange(desc(avg_k_scaled)) 80 | } 81 | 82 | } 83 | \seealso{ 84 | Other spatial-methods: 85 | \code{\link{CorSpatialFeatures}()}, 86 | \code{\link{CutSpatialNetwork}()}, 87 | \code{\link{DisconnectRegions}()}, 88 | \code{\link{GetSpatialNetwork}()}, 89 | \code{\link{RadialDistance}()}, 90 | \code{\link{RegionNeighbors}()}, 91 | \code{\link{RunLocalG}()}, 92 | \code{\link{RunNeighborhoodEnrichmentTest}()} 93 | } 94 | \author{ 95 | Lovisa Franzén 96 | } 97 | \concept{spatial-methods} 98 | -------------------------------------------------------------------------------- /man/load-images.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/load_images.R 3 | \name{LoadImages} 4 | \alias{LoadImages} 5 | \alias{LoadImages.default} 6 | \alias{LoadImages.Seurat} 7 | \title{Load images} 8 | \usage{ 9 | LoadImages(object, ...) 10 | 11 | \method{LoadImages}{default}(object, image_height = 400, pad_info = NULL, verbose = TRUE, ...) 12 | 13 | \method{LoadImages}{Seurat}(object, image_height = 400, verbose = TRUE, ...) 14 | } 15 | \arguments{ 16 | \item{object}{An object} 17 | 18 | \item{...}{Arguments passed to other methods} 19 | 20 | \item{image_height}{An integer specifying the height of the down-scaled images} 21 | 22 | \item{pad_info}{A tibble with information about how the image should be padded} 23 | 24 | \item{verbose}{print messages} 25 | } 26 | \value{ 27 | An object with images in \code{raster} format 28 | } 29 | \description{ 30 | Load H&E images (or any other custom images) required for visualization methods in \code{semla}. 31 | } 32 | \section{default method}{ 33 | 34 | If a character vector of image paths are provided, the images will be loaded, 35 | then down-scaled based on \code{image_height} and returned as a list of \code{raster} 36 | objects. Only JPEG and PNG images are supported. 37 | } 38 | 39 | \section{Seurat}{ 40 | 41 | If a Seurat object is provided, the images will be loaded as \code{raster} objects 42 | and stored inside the \code{Staffli} object that is located in the \code{tools} 43 | slot. 44 | } 45 | 46 | \examples{ 47 | 48 | library(semla) 49 | 50 | # Get paths for example images 51 | mousebrain_jpg <- system.file("extdata/mousebrain", 52 | "spatial/tissue_lowres_image.jpg", 53 | package = "semla") 54 | mousecolon_jpg <- system.file("extdata/mousecolon", 55 | "spatial/tissue_lowres_image.jpg", 56 | package = "semla") 57 | 58 | rasters <- LoadImages(c(mousebrain_jpg, mousecolon_jpg)) 59 | 60 | # Save graphical parameters 61 | oldpar <- par(no.readonly = TRUE) 62 | 63 | # plot images 64 | par(mfrow = c(1, 2), mar = c(0, 0, 0, 0)) 65 | for (rst in rasters) { 66 | plot(rst) 67 | } 68 | 69 | # Reset graphical parameters 70 | par(oldpar) 71 | 72 | 73 | library(semla) 74 | 75 | # Load example Visium data 76 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 77 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 78 | se_merged <- MergeSTData(se_mbrain, se_mcolon) 79 | 80 | # Load images 81 | se_merged <- LoadImages(se_merged) 82 | 83 | } 84 | \seealso{ 85 | Other pre-process: 86 | \code{\link{CreateMultiModalObject}()}, 87 | \code{\link{LoadAndMergeMatrices}()}, 88 | \code{\link{LoadAnnotationCSV}()}, 89 | \code{\link{LoadImageInfo}()}, 90 | \code{\link{LoadScaleFactors}()}, 91 | \code{\link{LoadSpatialCoordinates}()}, 92 | \code{\link{ReadVisiumData}()}, 93 | \code{\link{UpdateImageInfo}()} 94 | 95 | Other pre-process: 96 | \code{\link{CreateMultiModalObject}()}, 97 | \code{\link{LoadAndMergeMatrices}()}, 98 | \code{\link{LoadAnnotationCSV}()}, 99 | \code{\link{LoadImageInfo}()}, 100 | \code{\link{LoadScaleFactors}()}, 101 | \code{\link{LoadSpatialCoordinates}()}, 102 | \code{\link{ReadVisiumData}()}, 103 | \code{\link{UpdateImageInfo}()} 104 | } 105 | \concept{pre-process} 106 | -------------------------------------------------------------------------------- /man/mbrain_dataset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/extdata.R 3 | \name{mbrain_dataset} 4 | \alias{mbrain_dataset} 5 | \title{Visium mouse brain dataset} 6 | \description{ 7 | A Visium dataset obtained from a coronal tissue section of a mouse brain. 8 | \itemize{ 9 | \item{\strong{mousebrain/filtered_feature_bc_matrix.h5}:\cr light weight gene expression matrix with 188 genes in hdf5 format filtered to include spots under the tissue} 10 | \item{\strong{mousebrain/spatial/tissue_lowres_image.jpg}: \cr H&E image (600x565) pixels} 11 | \item{\strong{mousebrain/spatial/tissue_positions_list.csv}: \cr CSV file with spot coordinates} 12 | \item{\strong{mousebrain/spatial/scalefactors_json.json}: \cr JSON file with scalefactors} 13 | \item{\strong{mousebrain/se_mbrain}: \cr Seurat object stored as an .Rds file with the top 100 most variable features} 14 | } 15 | } 16 | \seealso{ 17 | Other datasets: 18 | \code{\link{mcolon_dataset}} 19 | } 20 | \concept{datasets} 21 | -------------------------------------------------------------------------------- /man/mcolon_dataset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/extdata.R 3 | \name{mcolon_dataset} 4 | \alias{mcolon_dataset} 5 | \title{Visium mouse colon dataset} 6 | \description{ 7 | A Visium dataset obtained from a "swiss roll" of a mouse colon 8 | \itemize{ 9 | \item{\strong{mousecolon/filtered_feature_bc_matrix.h5}:\cr light weight gene expression matrix with 188 genes in hdf5 format filtered to include spots under the tissue} 10 | \item{\strong{mousecolon/spatial/tissue_lowres_image.jpg}: \cr H&E image (600x541) pixels} 11 | \item{\strong{mousecolon/spatial/tissue_positions_list.csv}: \cr CSV file with spot coordinates} 12 | \item{\strong{mousecolon/spatial/scalefactors_json.json}: \cr JSON file with scalefactors} 13 | \item{\strong{mousecolon/se_mcolon}: \cr Seurat object stored as an .Rds file with the top 100 most variable features} 14 | \item{\strong{mousecolon/galt_spots.csv}: \cr CSV file with GALT spot barcodes} 15 | } 16 | } 17 | \references{ 18 | \doi{10.1038/s41467-022-28497-0} 19 | } 20 | \seealso{ 21 | Other datasets: 22 | \code{\link{mbrain_dataset}} 23 | } 24 | \concept{datasets} 25 | -------------------------------------------------------------------------------- /man/merge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subset_and_merge.R 3 | \name{MergeSTData} 4 | \alias{MergeSTData} 5 | \title{Merge 10x Visium data} 6 | \usage{ 7 | MergeSTData( 8 | x, 9 | y, 10 | merge_data = TRUE, 11 | merge_dr = NULL, 12 | project = "SeuratProject" 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{A \code{Seurat} object} 17 | 18 | \item{y}{A \code{Seurat} object or a list of \code{Seurat} objects} 19 | 20 | \item{merge_data}{Merge the data slots instead of just merging the counts 21 | (which requires re-normalization); this is recommended if the same normalization 22 | approach was applied to all objects. See \code{\link{merge}} for details.} 23 | 24 | \item{merge_dr}{Merge specified DimReducs that are present in all objects; will 25 | only merge the embeddings slots for the first N dimensions that are shared across 26 | all objects. See \code{\link{merge}} for details.} 27 | 28 | \item{project}{\code{\link{Project}} name for the \code{Seurat} object} 29 | } 30 | \value{ 31 | A merged \code{Seurat} object 32 | } 33 | \description{ 34 | Merges two or more Seurat objects containing SRT data while making sure that the 35 | spatial data (images and spot coordinates) are handled correctly. 36 | } 37 | \details{ 38 | NB: If you use the generic \code{\link{merge}} function you will not be able 39 | to use any of the \code{semla} visualization methods on the output object as 40 | the \code{Staffli} object will be broken. 41 | } 42 | \examples{ 43 | se_mbrain <- readRDS(system.file("extdata", 44 | "mousebrain/se_mbrain", 45 | package = "semla")) 46 | se_mcolon <- readRDS(system.file("extdata", 47 | "mousecolon/se_mcolon", 48 | package = "semla")) 49 | 50 | se_mbrain 51 | se_mcolon 52 | 53 | # Merge a mousebrain dataset with two mousecolon datasets 54 | se_merged <- MergeSTData(x = se_mbrain, y = se_mcolon) 55 | se_merged 56 | 57 | # Plot H&E images 58 | ImagePlot(se_merged |> LoadImages(verbose = FALSE)) 59 | 60 | } 61 | \seealso{ 62 | Other subset-and-merge: 63 | \code{\link{SubsetSTData}()} 64 | } 65 | \author{ 66 | Ludvig Larsson 67 | } 68 | \concept{subset-and-merge} 69 | -------------------------------------------------------------------------------- /man/neighborhood-enrichment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/spatial_neighborhood_stats.R 3 | \name{RunNeighborhoodEnrichmentTest} 4 | \alias{RunNeighborhoodEnrichmentTest} 5 | \title{Neighborhood Enrichment Analysis} 6 | \usage{ 7 | RunNeighborhoodEnrichmentTest( 8 | object, 9 | column_name, 10 | column_labels = NA, 11 | n_permutations = 200, 12 | nCores = parallel::detectCores() - 1, 13 | seed = 123, 14 | verbose = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{object}{A Seurat object} 19 | 20 | \item{column_name}{Column name in metadata corresponding to label ID of the spots.} 21 | 22 | \item{column_labels}{Optional. Provide vector of label IDs to subset your analysis by. 23 | Spots of all other labels will be excluded. Must be more than one. Default is all (NA).} 24 | 25 | \item{n_permutations}{Integer specifying number of iterations the labels should be randomized 26 | [default: 200]. Recommended to increase the number of permutations to >=200 for more robust 27 | results. A lower number of permutations will result in high standard deviations and thus more 28 | unreliable z-scores.} 29 | 30 | \item{nCores}{Number of cores [default: parallel::detectCores() - 1]} 31 | 32 | \item{seed}{A seed for reproducibility [default: 123]} 33 | 34 | \item{verbose}{Print messages [default: TRUE]} 35 | } 36 | \value{ 37 | A tibble with scores for each label pair. 38 | } 39 | \description{ 40 | Performs Neighborhood Enrichment Analysis between spot labels, describing whether 41 | spots of two categories lie next to each other spatially more often than expected 42 | by chance. 43 | } 44 | \details{ 45 | This analysis calculates the enrichment score, z-score, based on how often spots 46 | of different categorical labels (specified with \code{column_name}) lies 47 | adjacent to each other. The observed number of edges between the labels is 48 | then compared with the results from a set number of permutations (chosen 49 | with \code{n_permutations}), allowing the calculation of a z-score. 50 | The z-score will indicate if a label pair is overrepresented or underrepresented 51 | as compared to what would be expected to see by chance. 52 | The output of this function is a tibble table that for each label pair contains 53 | information about the observed number of edges (\code{edges}), the mean of the permuted 54 | results (\code{perm_mean}), the standard deviation of the permuted results (\code{perm_sd}), 55 | and the z-score (\code{z_score}). 56 | } 57 | \examples{ 58 | \donttest{ 59 | library(semla) 60 | 61 | # Read data 62 | se <- readRDS(system.file("extdata/mousebrain", 63 | "se_mbrain", 64 | package = "semla")) 65 | 66 | # Generate clusters 67 | se <- se |> 68 | NormalizeData() |> 69 | ScaleData() |> 70 | FindVariableFeatures() |> 71 | RunPCA() |> 72 | FindNeighbors(reduction = "pca", dims = 1:30) |> 73 | FindClusters() 74 | 75 | # Run Neigborhood Enrichment Analysis 76 | res <- RunNeighborhoodEnrichmentTest(object = se, 77 | column_name = "seurat_clusters", 78 | n_permutations = 100, 79 | nCores = 1) 80 | 81 | res |> arrange(desc(abs(z_score))) 82 | } 83 | 84 | } 85 | \seealso{ 86 | Other spatial-methods: 87 | \code{\link{CorSpatialFeatures}()}, 88 | \code{\link{CutSpatialNetwork}()}, 89 | \code{\link{DisconnectRegions}()}, 90 | \code{\link{GetSpatialNetwork}()}, 91 | \code{\link{RadialDistance}()}, 92 | \code{\link{RegionNeighbors}()}, 93 | \code{\link{RunLabelAssortativityTest}()}, 94 | \code{\link{RunLocalG}()} 95 | } 96 | \author{ 97 | Lovisa Franzén 98 | } 99 | \concept{spatial-methods} 100 | -------------------------------------------------------------------------------- /man/osddu-shiny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/osddu.R 3 | \name{osddu-shiny} 4 | \alias{osddu-shiny} 5 | \alias{osdduOutput} 6 | \alias{renderOsddu} 7 | \title{Shiny bindings for osddu} 8 | \usage{ 9 | osdduOutput(outputId, width = "100\%", height = "400px") 10 | 11 | renderOsddu(expr, env = parent.frame(), quoted = FALSE) 12 | } 13 | \arguments{ 14 | \item{outputId}{output variable to read from} 15 | 16 | \item{width, height}{Must be a valid CSS unit (like \code{'100\%'}, 17 | \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a 18 | string and have \code{'px'} appended.} 19 | 20 | \item{expr}{An expression that generates a osddu} 21 | 22 | \item{env}{The environment in which to evaluate \code{expr}.} 23 | 24 | \item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This 25 | is useful if you want to save an expression in a variable.} 26 | } 27 | \value{ 28 | A \code{shiny.tag.list} output or a \code{shiny.render.function} 29 | function produced to be used in a \code{shiny} app. \code{osdduOutput} 30 | is used in the UI and \code{renderOsddu} on the server side. 31 | } 32 | \description{ 33 | Output and render functions for using osddu within Shiny 34 | applications and interactive Rmd documents. 35 | } 36 | -------------------------------------------------------------------------------- /man/osddu.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/osddu.R 3 | \name{osddu} 4 | \alias{osddu} 5 | \title{Create a react app for digital unrolling} 6 | \usage{ 7 | osddu( 8 | sampleID = 1, 9 | host = "127.0.0.1", 10 | port = "8080", 11 | width = NULL, 12 | height = NULL, 13 | elementId = NULL, 14 | quit = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{sampleID}{A section ID} 19 | 20 | \item{host}{A host address} 21 | 22 | \item{port}{A valid port} 23 | 24 | \item{width, height}{Width and height of container} 25 | 26 | \item{elementId}{The element id of the widget} 27 | 28 | \item{quit}{A logical specifying is the app should quit} 29 | } 30 | \value{ 31 | A \code{htmlwidget} to be used in a \code{shiny} application 32 | } 33 | \description{ 34 | This function is used to start an interactive widget for 35 | digital unrolling. It requires a static files server to be 36 | hosted in order to find load the necessary files. 37 | } 38 | \examples{ 39 | 40 | library(semla) 41 | library(magick) 42 | 43 | se_mcolon <- readRDS(system.file("extdata/mousecolon", 44 | "se_mcolon", 45 | package = "semla")) 46 | # Load images 47 | se_mcolon <- se_mcolon |> 48 | LoadImages() 49 | 50 | # fetch path for one H&E image 51 | im <- GetStaffli(se_mcolon)@imgs[1] |> 52 | image_read() 53 | 54 | # Get spatial network 55 | spatnet <- GetSpatialNetwork(se_mcolon)[[1]] 56 | 57 | \dontrun{ 58 | # Tile image 59 | tilepath <- TileImage(im = im, outpath = tempdir()) 60 | 61 | # Export spatial network as JSON 62 | # Make sure that sampleID matches the ID of the H&E image 63 | export_graph(se_mcolon, sampleID = 1, outdir = tilepath$datapath) 64 | 65 | if (interactive()) { 66 | # Host file server 67 | file_server(hostDir = tilepath$datapath) 68 | 69 | # Run widget 70 | osddu(sampleID = 1, 71 | host = "127.0.0.1", 72 | port = 8080L, 73 | width = '800px', 74 | height = '800px', 75 | quit = FALSE) 76 | 77 | beakr::stopAllServers() 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /man/paper-shiny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/paper.R 3 | \name{paper-shiny} 4 | \alias{paper-shiny} 5 | \alias{paperOutput} 6 | \alias{renderPaper} 7 | \title{Shiny bindings for paper} 8 | \usage{ 9 | paperOutput(outputId, width = "100\%", height = "400px") 10 | 11 | renderPaper(expr, env = parent.frame(), quoted = FALSE) 12 | } 13 | \arguments{ 14 | \item{outputId}{output variable to read from} 15 | 16 | \item{width, height}{Must be a valid CSS unit (like \code{'100\%'}, 17 | \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a 18 | string and have \code{'px'} appended.} 19 | 20 | \item{expr}{An expression that generates a paper} 21 | 22 | \item{env}{The environment in which to evaluate \code{expr}.} 23 | 24 | \item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This 25 | is useful if you want to save an expression in a variable.} 26 | } 27 | \value{ 28 | A \code{shiny.tag.list} output or a \code{shiny.render.function} 29 | function produced to be used in a \code{shiny} app. \code{paperOutput} 30 | is used in the UI and \code{renderPaper} on the server side. 31 | } 32 | \description{ 33 | Output and render functions for using paper within Shiny 34 | applications and interactive Rmd documents. 35 | } 36 | -------------------------------------------------------------------------------- /man/paper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/paper.R 3 | \name{paper} 4 | \alias{paper} 5 | \title{Create a react app for paper JS in R} 6 | \usage{ 7 | paper(data, width = NULL, height = NULL, elementId = NULL) 8 | } 9 | \arguments{ 10 | \item{data}{A list of images prepared with \code{\link{prep_image}}} 11 | 12 | \item{width}{Width of component} 13 | 14 | \item{height}{height of component} 15 | 16 | \item{elementId}{Component element ID} 17 | } 18 | \value{ 19 | A \code{htmlwidget} to be used in a \code{shiny} application 20 | } 21 | \description{ 22 | Provided a list of images, this function is used to open an interactive app 23 | built with react and paper JS. The application is mean to be used in a shiny 24 | application and is used for the \code{\link{RunAlignment}} function provided 25 | in \code{semla}. 26 | } 27 | \examples{ 28 | 29 | library(semla) 30 | library(magick) 31 | 32 | im_mbrain <- system.file("extdata/mousebrain/spatial", 33 | "tissue_lowres_image.jpg", 34 | package = "semla") 35 | 36 | img1 <- prep_image(im_mbrain |> 37 | image_read(), 38 | height = 256) 39 | img2 <- prep_image(im_mbrain |> 40 | image_read() |> 41 | image_flip(), 42 | height = 256) 43 | 44 | \dontrun{ 45 | if (interactive()) { 46 | # Run widget 47 | paper(data = list(img1, img2), width = 600, height = 600) 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /man/plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \name{plot,Staffli,missing-method} 4 | \alias{plot,Staffli,missing-method} 5 | \title{Plot method for \code{Staffli} objects} 6 | \usage{ 7 | \S4method{plot}{Staffli,missing}( 8 | x, 9 | image_use = NULL, 10 | coords_use = c("raw", "transformed"), 11 | ncol = NULL, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{A \code{Staffli} object} 17 | 18 | \item{image_use}{A string specifying the image to plot} 19 | 20 | \item{coords_use}{A character vector of length 2 specifying the coordinates to use} 21 | 22 | \item{ncol}{Integer specifying the number of columns in the plot grid} 23 | 24 | \item{...}{Additional parameters passed to \code{geom_point}} 25 | } 26 | \value{ 27 | No return value, plots the content of a \code{Staffli} object 28 | } 29 | \description{ 30 | Plot method for \code{Staffli} objects 31 | } 32 | -------------------------------------------------------------------------------- /man/prep_image.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rigid_transform_manual.R 3 | \name{prep_image} 4 | \alias{prep_image} 5 | \title{Prepare images for paper JS react app} 6 | \usage{ 7 | prep_image(input, height = 256) 8 | } 9 | \arguments{ 10 | \item{input}{An object of class \code{magick-image} or a path 11 | to an image in png or jpeg format} 12 | 13 | \item{height}{Height of image sent to react app} 14 | } 15 | \value{ 16 | a list with an array buffer, the image dimensions and 17 | the length of the array buffer 18 | } 19 | \description{ 20 | Prepare images for paper JS react app 21 | } 22 | \examples{ 23 | library(semla) 24 | library(magick) 25 | 26 | im <- system.file("extdata/mousebrain", "spatial/tissue_lowres_image.jpg", package = "semla") 27 | 28 | # Prep image 29 | im_prepped <- prep_image(im) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/scalebar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scalebar.R 3 | \name{scalebar} 4 | \alias{scalebar} 5 | \title{Create a scale bar to use for plots} 6 | \usage{ 7 | scalebar( 8 | x = 500, 9 | breaks = 6, 10 | highlight_breaks = c(1, 6), 11 | title_position = c("top", "bottom"), 12 | flip_bar = FALSE, 13 | text_height = 2, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{x}{Width of scale bar in microns. If the width is higher than 1,000 microns, 19 | the units will be converted to millimeters in the scale bar title.} 20 | 21 | \item{breaks}{Number of breaks to cut scale bar into. For example, 6 breaks will 22 | create 6 vertical lines and 5 even intervals.} 23 | 24 | \item{highlight_breaks}{Highlight specific breaks by increasing their height.} 25 | 26 | \item{title_position}{One of "top" or "bottom" for title placement} 27 | 28 | \item{flip_bar}{Should the scale bar be flipped to a vertical orientation?} 29 | 30 | \item{text_height}{Height of scale bar title} 31 | 32 | \item{...}{Parameters passed to geom_segment} 33 | } 34 | \value{ 35 | A \code{ggplot} object with a scalebar 36 | } 37 | \description{ 38 | Create a scale bar to use for plots 39 | } 40 | \examples{ 41 | 42 | # Draw a scale bar for a 500 micron distance with 6 breaks where 43 | # the ends are highlighted 44 | scalebar() 45 | 46 | # Draw a scale bar for a 1mm mm distance with 1 breaks where the 47 | # ends and the mid point are highlighted 48 | scalebar(breaks = 11, highlight_breaks = c(1, 6, 11)) 49 | 50 | } 51 | \author{ 52 | Ludvig Larsson 53 | } 54 | -------------------------------------------------------------------------------- /man/semla-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/semla-package.R 3 | \docType{package} 4 | \name{semla-package} 5 | \alias{semla} 6 | \alias{semla-package} 7 | \title{semla: Spatially Resolved Transcriptomics Data Processing, Analysis and Visualization} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | Spatially Resolved Transcriptomics data exploration and analysis. 'semla' provides interactive tools for image alignment and data exploration together with several analysis and visualization methods. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://ludvigla.github.io/semla/} 17 | } 18 | 19 | } 20 | \author{ 21 | \strong{Maintainer}: Ludvig Larsson \email{ludvig.larsson@scilifelab.se} (\href{https://orcid.org/0000-0003-4209-2911}{ORCID}) 22 | 23 | Authors: 24 | \itemize{ 25 | \item Lovisa Franzen \email{lovisa.franzen@scilifelab.se} (\href{https://orcid.org/0000-0003-3755-718X}{ORCID}) 26 | \item Javier Escudero Morlanes \email{javier.escudero.morlanes@scilifelab.se} (\href{https://orcid.org/0009-0004-2885-2456}{ORCID}) 27 | } 28 | 29 | Other contributors: 30 | \itemize{ 31 | \item Spatial Research [funder] 32 | } 33 | 34 | } 35 | \keyword{internal} 36 | -------------------------------------------------------------------------------- /man/show.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/staffli_object.R 3 | \name{show,Staffli-method} 4 | \alias{show,Staffli-method} 5 | \title{Show method for \code{Staffli} objects} 6 | \usage{ 7 | \S4method{show}{Staffli}(object) 8 | } 9 | \arguments{ 10 | \item{object}{object to print pre-selected attributes for} 11 | } 12 | \value{ 13 | No return value, plots the spot coordinates and alternatively also 14 | the images found in a \code{Staffli} object 15 | } 16 | \description{ 17 | Show method for \code{Staffli} objects 18 | } 19 | -------------------------------------------------------------------------------- /man/subset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subset_and_merge.R 3 | \name{SubsetSTData} 4 | \alias{SubsetSTData} 5 | \title{Subset 10x Visium data} 6 | \usage{ 7 | SubsetSTData(object, expression, spots = NULL, features = NULL, idents = NULL) 8 | } 9 | \arguments{ 10 | \item{object}{A Seurat object} 11 | 12 | \item{expression}{Logical expression indicating features/variables to keep} 13 | 14 | \item{spots}{A vector of spots to keep} 15 | 16 | \item{features}{A vector of features to keep} 17 | 18 | \item{idents}{A vector of identity classes to keep} 19 | } 20 | \value{ 21 | A filtered Seurat object 22 | } 23 | \description{ 24 | Subset a \code{Seurat} object while making sure that the spatial data 25 | (images and spot coordinates) are handled correctly. 26 | } 27 | \details{ 28 | If you use the default \code{\link{subset}} function you will most likely not be able 29 | to use any of the \code{semla} visualization methods on the output object as 30 | the \code{Staffli} object will be broken. The exception is when filtering is only 31 | done at the feature level. 32 | } 33 | \examples{ 34 | 35 | se_mbrain <- readRDS(system.file("extdata", "mousebrain/se_mbrain", package = "semla")) 36 | 37 | # Create Seurat object 38 | se_mbrain <- se_mbrain |> LoadImages() 39 | se_mbrain 40 | 41 | # Subset by spot IDs (first 100) 42 | se_fewspots <- SubsetSTData(se_mbrain, spots = colnames(se_mbrain)[1:1000]) 43 | se_fewspots 44 | 45 | # Subset by feature IDs (first 50) 46 | se_fewgenes <- SubsetSTData(se_mbrain, features = rownames(se_mbrain)[1:50]) 47 | se_fewgenes 48 | 49 | # Subset using an expression 50 | se_filtered <- SubsetSTData(se_mbrain, expression = nFeature_Spatial > 20) 51 | se_filtered 52 | 53 | } 54 | \seealso{ 55 | Other subset-and-merge: 56 | \code{\link{MergeSTData}()} 57 | } 58 | \author{ 59 | Ludvig Larsson 60 | } 61 | \concept{subset-and-merge} 62 | -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | margin-top: 1em; 3 | font-weight: 600; 4 | } 5 | h2 { 6 | margin-top: 2em; 7 | } 8 | h3 { 9 | margin-top: 1em; 10 | } 11 | h4 { 12 | font-size: smaller; 13 | font-weight: bold; 14 | } 15 | p { 16 | margin-top: 1em; 17 | margin-bottom: 1em; 18 | font-size: medium; 19 | } 20 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /semla.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: 20185244-00f8-4919-b535-1728e7ecbe32 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Package 17 | PackageUseDevtools: Yes 18 | PackageInstallArgs: --no-multiarch --with-keep.source 19 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if(requireNamespace('spelling', quietly = TRUE)) 2 | spelling::spell_check_test(vignettes = TRUE, error = FALSE, 3 | skip_on_cran = TRUE) 4 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/tests.html 7 | # * https://testthat.r-lib.org/reference/test_package.html#special-files 8 | 9 | library(testthat) 10 | library(semla) 11 | 12 | test_check("semla") 13 | -------------------------------------------------------------------------------- /tests/testthat/test-AdjustTissueCoordinates.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 5 | se_mcolon <- SubsetSTData(se_mcolon, expression = selection == "GALT") 6 | spatial_network <- GetSpatialNetwork(se_mcolon)[[1]] 7 | nodes <- spatial_network |> select(from, x_start, y_start) |> group_by(from) |> 8 | slice_head(n = 1) |> rename(name = from, x = x_start, y = y_start) 9 | edges <- spatial_network |> select(from, to) |> mutate(keep = TRUE) 10 | spatial_network <- tidygraph::tbl_graph(nodes = nodes, edges = edges, directed = FALSE) 11 | 12 | # Test the AdjustTissuecoordinates function 13 | test_that("AdjustTissuecoordinates works as expected", { 14 | 15 | res <- AdjustTissueCoordinates(full_graph = spatial_network) 16 | expect_true(inherits(res, what = "tbl_df")) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-AnglePlot.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Test the centroid_angles_plot function 5 | test_that("centroid_angles_plot returns a ggplot object", { 6 | # Call the centroid_angles_plot function 7 | plot <- centroid_angles_plot(nbreaks = 9, centroid_size = 8) 8 | 9 | # Check if the returned object is a ggplot object 10 | expect_s3_class(plot, "ggplot") 11 | }) 12 | 13 | # Test the AnglePlot function 14 | test_that("AnglePlot returns a patchwork object", { 15 | 16 | # Create a Seurat object for testing (replace with your own test data) 17 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 18 | 19 | # Call the AnglePlot function 20 | se_mcolon <- DisconnectRegions(se_mcolon, column_name = "selection", selected_groups = "GALT") 21 | plot <- AnglePlot(se_mcolon, column_name = "GALT_split", selected_group = "S1_region1") 22 | 23 | # Check if the returned object is a patchwork object 24 | expect_s3_class(plot, "patchwork") 25 | 26 | se_mcolon <- LoadImages(se_mcolon) 27 | plot <- AnglePlot(se_mcolon, column_name = "GALT_split", selected_group = "S1_region1", image_use = "raw") 28 | 29 | # Check if the returned object is a patchwork object 30 | expect_s3_class(plot, "patchwork") 31 | 32 | plot <- AnglePlot(se_mcolon, column_name = "GALT_split", selected_group = "S1_region1", crop_area = c(0.4, 0.4, 0.6, 0.6)) 33 | 34 | # Check if the returned object is a patchwork object 35 | expect_s3_class(plot, "patchwork") 36 | 37 | plot <- AnglePlot(se_mcolon, column_name = "GALT_split", selected_group = "S1_region1", override_plot_dims = TRUE) 38 | 39 | # Check if the returned object is a patchwork object 40 | expect_s3_class(plot, "patchwork") 41 | }) -------------------------------------------------------------------------------- /tests/testthat/test-CoordMirror.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(tibble) 3 | 4 | # Test that CoordMirror handles invalid input correctly 5 | test_that("CoordMirror handles invalid input", { 6 | # Test invalid format 7 | expect_error(CoordMirror(1:10, mirror.x = TRUE), "Invalid class") 8 | 9 | # Test invalid number of columns 10 | expect_error(CoordMirror(matrix(1:6, nrow = 2), mirror.x = TRUE), "Expected 2 columns") 11 | 12 | # Test non-numeric columns 13 | expect_error(CoordMirror(data.frame(x = 1:5, y = letters[1:5])), "Invalid column classes.") 14 | 15 | # Test neither mirror.x nor mirror.y set 16 | expect_error(CoordMirror(matrix(1:10, ncol = 2)), "One of 'mirror.x' or 'mirror.y' or both need to be selected.") 17 | }) 18 | 19 | # Test that CoordMirror mirrors along the x-axis correctly 20 | test_that("CoordMirror mirrors along x-axis", { 21 | input_coords <- tibble(x = 1:5, y = 1:5) 22 | expected_output <- tibble(tr_x = 5:1, tr_y = 1:5) 23 | 24 | mirrored_coords <- CoordMirror(input_coords, mirror.x = TRUE) 25 | expect_equal(mirrored_coords, expected_output) 26 | }) 27 | 28 | # Test that CoordMirror mirrors along the y-axis correctly 29 | test_that("CoordMirror mirrors along y-axis", { 30 | input_coords <- tibble(x = 1:5, y = 1:5) 31 | expected_output <- tibble(tr_x = 1:5, tr_y = 5:1) 32 | 33 | mirrored_coords <- CoordMirror(input_coords, mirror.y = TRUE) 34 | expect_equal(mirrored_coords, expected_output) 35 | }) 36 | 37 | # Test that CoordMirror mirrors along both x and y axes correctly 38 | test_that("CoordMirror mirrors along x and y axes", { 39 | input_coords <- tibble(x = 1:5, y = 1:5) 40 | expected_output <- tibble(tr_x = 5:1, tr_y = 5:1) 41 | 42 | mirrored_coords <- CoordMirror(input_coords, mirror.x = TRUE, mirror.y = TRUE) 43 | expect_equal(mirrored_coords, expected_output) 44 | }) 45 | 46 | # Test that CoordMirror works with specified center 47 | test_that("CoordMirror works with custom center", { 48 | input_coords <- tibble(x = 1:5, y = 1:5) 49 | center <- c(3, 3) 50 | expected_output <- tibble(tr_x = c(5, 4, 3, 2, 1), tr_y = c(5, 4, 3, 2, 1)) 51 | 52 | mirrored_coords <- CoordMirror(input_coords, mirror.x = TRUE, mirror.y = TRUE, center = center) 53 | expect_equal(mirrored_coords, expected_output) 54 | }) 55 | 56 | # Test that CoordMirror returns a tibble 57 | test_that("CoordMirror returns a tibble", { 58 | input_coords <- tibble(x = 1:5, y = 1:5) 59 | mirrored_coords <- CoordMirror(input_coords, mirror.x = TRUE) 60 | expect_s3_class(mirrored_coords, "tbl") 61 | }) 62 | 63 | -------------------------------------------------------------------------------- /tests/testthat/test-CreateMultiModalObject.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Load Seurat objects from semla package for testing 5 | se_mod1 <- readRDS(system.file("extdata", "mousebrain/se_mbrain", package = "semla")) 6 | se_mod2 <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 7 | 8 | test_that("CreateMultiModalObject returns a correct object", { 9 | # Test function for aggregating function "mean" 10 | se_mmo <- CreateMultiModalObject(object_ref = se_mod1, object_map = se_mod2, 11 | agg_func = "mean", 12 | new_assay_name = "Modality2") 13 | 14 | ## Check that the output is a Seurat object 15 | expect_s4_class(se_mmo, "Seurat") 16 | 17 | # Test function for aggregating function "sum" 18 | se_mmo <- CreateMultiModalObject(object_ref = se_mod1, object_map = se_mod2, 19 | agg_func = "sum", 20 | new_assay_name = "Modality2") 21 | 22 | ## Check that the output is a Seurat object 23 | expect_s4_class(se_mmo, "Seurat") 24 | }) 25 | 26 | test_that("CreateMultiModalObject returns an error with wrong input", { 27 | # Expected errors 28 | # expect_error(CreateMultiModalObject(object_ref = se_mod1, object_map = se_mod2, agg_func = "test"), 29 | # '"arg" should be one of "mean", "sum"') 30 | 31 | expect_error(CreateMultiModalObject(object_ref = se_mod1, object_map = se_mod2, n_neighbors = 0), 32 | "'n_neighbors' should be larger than 0") 33 | }) 34 | -------------------------------------------------------------------------------- /tests/testthat/test-ExportDataForViewer.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 5 | "se_mbrain", 6 | package = "semla")) |> LoadImages() 7 | 8 | test_that("ExportDataForViewer exports data correctly", { 9 | 10 | # Set up a temporary directory for testing 11 | test_dir <- tempdir() 12 | 13 | # Test exporting data with default arguments 14 | outpath <- ExportDataForViewer(se_mbrain, outdir = test_dir, overwrite = TRUE) 15 | 16 | # Check if the output path exists 17 | expect_true(dir.exists(outpath), info = "Output directory exists") 18 | 19 | # Check if files were created in the output directory 20 | expect_true(dir.exists(file.path(outpath, "tiles1"))) 21 | expect_true(file.exists(file.path(outpath, "image_info_1.json"))) 22 | expect_true(file.exists(file.path(outpath, "coords_Visium_1.json"))) 23 | }) 24 | 25 | test_that("ExportDataForViewer returns errors correctly", { 26 | 27 | # Set up a temporary directory for testing 28 | test_dir <- tempdir() 29 | 30 | # Test exporting data with wrong sampleID 31 | expect_error(ExportDataForViewer(se_mbrain, sampleIDs = 2, outdir = test_dir, overwrite = TRUE)) 32 | 33 | # Invalid image 34 | se_mbrain@tools$Staffli@imgs <- "invalid" 35 | expect_error(ExportDataForViewer(se_mbrain, outdir = test_dir, overwrite = TRUE)) 36 | 37 | # Invalid outdir 38 | expect_error(ExportDataForViewer(se_mbrain, outdir = "__invalid", overwrite = TRUE)) 39 | expect_error(ExportDataForViewer(se_mbrain, outdir = 1L, overwrite = TRUE)) 40 | 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test-FeatureLoadingsPlot.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 5 | se_mcolon <- se_mcolon |> ScaleData() |> RunPCA() 6 | 7 | test_that("PlotFeatureLoadings function returns valid plots and handles errors", { 8 | 9 | # Test case 1: Check if the function returns a ggplot object 10 | expect_s3_class(PlotFeatureLoadings(se_mcolon), "ggplot") 11 | 12 | # Test case 2: Check if the function returns a ggplot object for different modes 13 | expect_s3_class(PlotFeatureLoadings(se_mcolon, mode = "barplot"), "ggplot") 14 | expect_s3_class(PlotFeatureLoadings(se_mcolon, mode = "dotplot"), "ggplot") 15 | expect_s3_class(PlotFeatureLoadings(se_mcolon, mode = "heatmap", dims = 1:5), "ggplot") 16 | 17 | # Test case 3: Check if the function handles invalid mode gracefully 18 | expect_error(PlotFeatureLoadings(se_mcolon, mode = "invalid_mode"), class = "error") 19 | 20 | # Test case 4: Check if the function handles invalid type gracefully 21 | expect_error(PlotFeatureLoadings(se_mcolon, type = "invalid_type"), class = "error") 22 | 23 | # Test case 5: Check if the function handles invalid dims input gracefully 24 | expect_error(PlotFeatureLoadings(se_mcolon, dims = "invalid_dims"), class = "error") 25 | 26 | # Test case 6: Check if the function handles invalid nfeatures input gracefully 27 | expect_error(PlotFeatureLoadings(se_mcolon, nfeatures = 0), class = "error") 28 | 29 | # Test case 7: Check if the function handles invalid fill input gracefully 30 | expect_error(PlotFeatureLoadings(se_mcolon, fill = 123), class = "error") 31 | 32 | # Test case 8: Check if the function handles invalid color input gracefully 33 | expect_error(PlotFeatureLoadings(se_mcolon, color = 123), class = "error") 34 | 35 | # Test case 9: Check if the function handles invalid bar_width input gracefully 36 | expect_error(PlotFeatureLoadings(se_mcolon, bar_width = "invalid_width"), class = "error") 37 | 38 | # Test case 10: Check if the function handles invalid pt_size input gracefully 39 | expect_error(PlotFeatureLoadings(se_mcolon, pt_size = "invalid_size"), class = "error") 40 | 41 | # Test case 11: Check if the function handles invalid pt_stroke input gracefully 42 | expect_error(PlotFeatureLoadings(se_mcolon, pt_stroke = "invalid_stroke"), class = "error") 43 | 44 | # Test case 12: Check if the function handles invalid color_by_loadings input gracefully 45 | expect_error(PlotFeatureLoadings(se_mcolon, color_by_loadings = "invalid_color"), class = "error") 46 | 47 | # Test case 13: Check if the function handles invalid gradient_colors input gracefully 48 | expect_error(PlotFeatureLoadings(se_mcolon, gradient_colors = 123), class = "error") 49 | 50 | # More checks 51 | expect_s3_class(PlotFeatureLoadings(se_mcolon, mode = "barplot", dims = 1, color_by_loadings = TRUE), "ggplot") 52 | 53 | expect_s3_class(PlotFeatureLoadings(se_mcolon, mode = "barplot", dims = 1, type = "centered"), "ggplot") 54 | 55 | expect_s3_class(PlotFeatureLoadings(se_mcolon, mode = "barplot", dims = 1, type = "positive"), "ggplot") 56 | 57 | expect_s3_class(PlotFeatureLoadings(se_mcolon, mode = "barplot", dims = 1, type = "negative"), "ggplot") 58 | }) 59 | -------------------------------------------------------------------------------- /tests/testthat/test-GetSpatialNetwork.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | 3 | # Create test data 4 | coordfiles <- c(system.file("extdata/mousebrain/spatial", 5 | "tissue_positions_list.csv", 6 | package = "semla"), 7 | system.file("extdata/mousecolon/spatial", 8 | "tissue_positions_list.csv", 9 | package = "semla")) 10 | 11 | # Load coordinate data into a tibble 12 | xys <- do.call(rbind, lapply(seq_along(coordfiles), function(i) { 13 | coords <- setNames(read.csv(coordfiles[i], header = FALSE), 14 | nm = c("barcode", "selection", "grid_y", "grid_x", "y", "x")) 15 | coords$sampleID <- i 16 | coords <- coords |> 17 | dplyr::filter(selection == 1) |> 18 | dplyr::select(barcode, x, y, sampleID) |> 19 | tibble::as_tibble() 20 | return(coords) 21 | })) 22 | 23 | # Test that function returns a list 24 | test_that("GetSpatialNetwork returns a list", { 25 | expect_type(GetSpatialNetwork(xys), "list") 26 | }) 27 | 28 | # Test that function returns a list with the same number of elements as unique sample IDs 29 | test_that("GetSpatialNetwork returns a list with the same number of elements as unique sample IDs", { 30 | expect_equal(length(GetSpatialNetwork(xys)), length(unique(xys$sampleID))) 31 | }) 32 | 33 | # Test that function throws an error when passed an object with invalid class 34 | test_that("GetSpatialNetwork throws an error when passed an object with invalid class", { 35 | expect_error(GetSpatialNetwork(1:10), "Invalid class 'integer'.") 36 | }) 37 | 38 | # Test that function throws an error when passed an object with invalid number of columns 39 | test_that("GetSpatialNetwork throws an error when passed an object with invalid number of columns", { 40 | expect_error(GetSpatialNetwork(xys[, -1]), "Invalid number of columns '3'. Expected 4.") 41 | }) 42 | 43 | # Test that function throws an error when passed an object with invalid column names 44 | test_that("GetSpatialNetwork throws an error when passed an object with invalid column names", { 45 | expect_error(GetSpatialNetwork(xys |> rename(foo = barcode)), "Expected 'barcode', 'x', 'y' and 'sampleID'") 46 | }) 47 | 48 | # Test that function throws an error when passed an object with invalid column classes 49 | test_that("GetSpatialNetwork throws an error when passed an object with invalid column classes", { 50 | expect_error(GetSpatialNetwork(xys |> mutate(x = "string")), "Invalid column class.") 51 | }) 52 | 53 | # Test that function calculates the correct number of nearest neighbors 54 | test_that("GetSpatialNetwork calculates the correct number of nearest neighbors", { 55 | expect_equal(nrow(GetSpatialNetwork(xys)[[1]]), 14818) 56 | }) 57 | 58 | # Test that function discards spots with fewer neighbors than minK 59 | test_that("GetSpatialNetwork discards spots with fewer neighbors than minK", { 60 | expect_equal(nrow(GetSpatialNetwork(xys, minK = 6)[[1]]), 0) 61 | }) 62 | 63 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 64 | 65 | # Test that function throws an error when passed a Seurat object without a Staffli object 66 | test_that("GetSpatialNetwork throws an error when passed a Seurat object without Staffli object", { 67 | tmp <- se_mbrain 68 | tmp@tools$Staffli <- NULL 69 | expect_error(GetSpatialNetwork(tmp), "'Staffli' object is missing from tools slot.") 70 | }) -------------------------------------------------------------------------------- /tests/testthat/test-ImagePlot.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Load a test Seurat object with semla 5 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 6 | 7 | # Test that function throws an error if the images are not loaded 8 | test_that("ImagePlot throws error", { 9 | expect_error(ImagePlot(se_mbrain), "Images have not been loaded yet") 10 | }) 11 | 12 | se_mbrain <- LoadImages(se_mbrain) 13 | 14 | # Test that function runs without errors 15 | test_that("ImagePlot runs without errors", { 16 | expect_invisible(ImagePlot(se_mbrain)) 17 | }) 18 | 19 | # Test that function returns a ggplot object when return_as_gg = TRUE 20 | test_that("ImagePlot returns ggplot object when return_as_gg = TRUE", { 21 | ggplot_obj <- ImagePlot(se_mbrain, return_as_gg = TRUE) 22 | expect_s3_class(ggplot_obj, "ggplot") 23 | }) 24 | 25 | # Test that function throws an error if label_by is not a character or factor 26 | test_that("ImagePlot throws error if label_by is not character or factor", { 27 | expect_error(ImagePlot(se_mbrain, label_by = "nFeature_Spatial"), 28 | "Invalid class 'integer' for 'label_by' column. Expected a 'character' of 'factor'.") 29 | }) 30 | 31 | # Test that function throws an error if label_by is not present in the Seurat object 32 | test_that("ImagePlot throws error if label_by is not present in Seurat object", { 33 | expect_error(ImagePlot(se_mbrain, label_by = "nonexistent_column"), "not present in the Seurat object meta data") 34 | }) 35 | 36 | # Test that function throws an error if label_by column has multiple labels per tissue section 37 | test_that("ImagePlot throws error if label_by column has multiple labels per tissue section", { 38 | se_mbrain$test <- sample(c("brain", "colon"), ncol(se_mbrain), replace = TRUE) 39 | expect_error(ImagePlot(se_mbrain, label_by = "test"), "Invalid 'label_by' meta data column.") 40 | }) 41 | 42 | # Test that function throws an error if transformed images are not available in object 43 | test_that("ImagePlot throws error if transformed images are not available in object", { 44 | expect_error(ImagePlot(se_mbrain, image_use = "transformed"), "Transformed images are not available in this object") 45 | }) 46 | 47 | # Test that function throws an error if crop_area is not numeric 48 | test_that("ImagePlot throws error if crop_area is not numeric", { 49 | expect_error(ImagePlot(se_mbrain, crop_area = "not_a_number"), "Invalid class 'character' for 'crop_area', expected 'numeric'") 50 | }) 51 | 52 | # Test that function throws an error if crop_area is not of length 4 53 | test_that("ImagePlot throws error if crop_area is not of length 4", { 54 | expect_error(ImagePlot(se_mbrain, crop_area = c(0.1, 0.2, 0.3)), "Invalid length for 'crop_area', expected a 'numeric' vector of length 4") 55 | }) 56 | 57 | # Test that function throws an error if crop_area values are not between 0 and 1 58 | test_that("ImagePlot throws error if crop_area values are not between 0 and 1", { 59 | expect_error(ImagePlot(se_mbrain, crop_area = c(1.1, 0.2, 0.3, 0.4)), "'crop_area' can only take values between 0-1") 60 | }) 61 | 62 | # Test that function throws an error if sampleIDs are out of range 63 | test_that("ImagePlot throws error if sampleIDs are out of range", { 64 | expect_error(ImagePlot(se_mbrain, sampleIDs = c(0, 11)), "'sampleIDs' is out of range.") 65 | }) -------------------------------------------------------------------------------- /tests/testthat/test-LoadAndMergeMatrices.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(dplyr) 3 | 4 | # Test if the function returns a matrix 5 | test_that("LoadAndMergeMatrices returns a matrix with correct dimensions", { 6 | paths <- c(system.file("extdata/mousebrain/filtered_feature_bc_matrix.h5", package = "semla"), 7 | system.file("extdata/mousecolon/filtered_feature_bc_matrix.h5", package = "semla")) 8 | 9 | mat <- LoadAndMergeMatrices(paths, verbose = FALSE) 10 | 11 | expect_true(inherits(mat, what = "dgCMatrix")) 12 | expect_true(all(dim(mat) == c(188, 5164))) 13 | }) 14 | 15 | # Test if the function throws an error when provided with non-existing file paths 16 | test_that("LoadAndMergeMatrices throws an error when provided with non-existing file paths", { 17 | paths <- c(system.file("extdata/mousebrain/filtered_feature_bc_matrix.h5", package = "semla"), 18 | "path/does/not/exist.h5") 19 | 20 | expect_error(LoadAndMergeMatrices(paths, verbose = FALSE), "Invalid path") 21 | }) 22 | 23 | # Test if the function throws an error when provided with paths to non-10x matrix files 24 | test_that("LoadAndMergeMatrices throws an error when provided with paths to non-10x matrix files", { 25 | paths <- c(system.file("extdata/mousebrain/filtered_feature_bc_matrix.h5", package = "semla"), 26 | system.file("extdata/mousebrain/spatial/tissue_positions_list.csv", package = "semla")) 27 | 28 | expect_error(LoadAndMergeMatrices(paths, verbose = FALSE), 29 | "Invalid file format") 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-LoadImageInfo.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(dplyr) 3 | library(semla) 4 | 5 | imgfiles <- 6 | c(system.file("extdata/mousebrain/spatial", 7 | "tissue_lowres_image.jpg", 8 | package = "semla"), 9 | system.file("extdata/mousecolon/spatial", 10 | "tissue_lowres_image.jpg", 11 | package = "semla")) 12 | img_info <- LoadImageInfo(imgfiles) 13 | 14 | test_that("LoadImageInfo returns a tibble", { 15 | expect_s3_class(img_info, "tbl") 16 | }) 17 | 18 | test_that("LoadImageInfo returns correct column names", { 19 | expect_equal(colnames(img_info), c("format", "width", "height", "colorspace", "matte", "filesize", "density", "sampleID", "type")) 20 | }) 21 | 22 | test_that("LoadImageInfo returns correct column classes", { 23 | expect_equal(sapply(img_info, class) |> as.character(), c("character","integer","integer", "character","logical","integer", "character", "character", "character")) 24 | }) 25 | 26 | test_that("LoadImageInfo returns correct number of rows names", { 27 | expect_equal(nrow(img_info), 2) 28 | }) 29 | 30 | test_that("LoadImageInfo returns correct number of sampleIDs", { 31 | expect_equal(table(img_info$sampleID) |> length(), 2) 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-LoadImages.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Define test 5 | test_that("LoadImages function loads images and scales them appropriately (default)", { 6 | # Create example input 7 | imgs <- c(system.file("extdata/mousebrain", "spatial/tissue_lowres_image.jpg", package = "semla"), 8 | system.file("extdata/mousecolon", "spatial/tissue_lowres_image.jpg", package = "semla")) 9 | 10 | # Call function 11 | rsts <- LoadImages(imgs, image_height = 300) 12 | heights <- sapply(rsts, nrow) 13 | 14 | # Check output 15 | expect_true(all(heights == 300)) 16 | expect_true(length(rsts) == 2) 17 | expect_true(all(sapply(rsts, class) == "raster")) 18 | }) 19 | 20 | # Define test 21 | test_that("LoadImages function loads images and scales them appropriately (Seurat)", { 22 | # Create example input 23 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 24 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 25 | se_merged <- MergeSTData(se_mbrain, se_mcolon) 26 | 27 | # Call function 28 | se_merged <- LoadImages(se_merged, image_height = 300) 29 | st_object <- GetStaffli(se_merged) 30 | imgs <- st_object@rasterlists$raw 31 | heights <- sapply(imgs, nrow) 32 | 33 | # Check output 34 | expect_true(all(heights == 300)) 35 | expect_true(length(imgs) == 2) 36 | expect_true(all(sapply(imgs, class) == "raster")) 37 | }) 38 | -------------------------------------------------------------------------------- /tests/testthat/test-LoadScaleFactors.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | jsonfiles <- 5 | c(system.file("extdata/mousebrain/spatial", 6 | "scalefactors_json.json", 7 | package = "semla"), 8 | system.file("extdata/mousecolon/spatial", 9 | "scalefactors_json.json", 10 | package = "semla")) 11 | scalefactors <- LoadScaleFactors(jsonfiles) 12 | 13 | test_that("LoadScaleFactors returns a tibble", { 14 | expect_s3_class(scalefactors, "tbl") 15 | }) 16 | 17 | test_that("LoadScaleFactors returns correct column names", { 18 | expect_equal(colnames(scalefactors), c("spot_diameter_fullres","tissue_hires_scalef","fiducial_diameter_fullres", "tissue_lowres_scalef", "sampleID")) 19 | }) 20 | 21 | test_that("LoadScaleFactors returns correct column classes", { 22 | expect_equal(sapply(scalefactors, class) |> as.character(), c("numeric", "numeric", "numeric", "numeric", "character")) 23 | }) 24 | 25 | test_that("LoadScaleFactors returns correct number of rows names", { 26 | expect_equal(nrow(scalefactors), 2) 27 | }) 28 | 29 | test_that("LoadScaleFactors returns correct number of sampleIDs", { 30 | expect_equal(table(scalefactors$sampleID) |> length(), 2) 31 | }) 32 | -------------------------------------------------------------------------------- /tests/testthat/test-LoadSpatialCoordinates.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(dplyr) 3 | library(semla) 4 | 5 | coordinatefiles <- 6 | c(system.file("extdata/mousebrain/spatial", 7 | "tissue_positions_list.csv", 8 | package = "semla"), 9 | system.file("extdata/mousecolon/spatial", 10 | "tissue_positions_list.csv", 11 | package = "semla")) 12 | coordinates <- LoadSpatialCoordinates(coordinatefiles) 13 | 14 | test_that("LoadSpatialCoordinates returns a tibble", { 15 | expect_s3_class(coordinates, "tbl") 16 | }) 17 | 18 | test_that("LoadSpatialCoordinates returns correct column names", { 19 | expect_equal(colnames(coordinates), c("barcode", "selected", "y", "x", "pxl_row_in_fullres", "pxl_col_in_fullres", "sampleID")) 20 | }) 21 | 22 | test_that("LoadSpatialCoordinates returns correct column classes", { 23 | expect_equal(sapply(coordinates, class) |> as.character(), c("character","integer","integer","integer","integer","integer","integer")) 24 | }) 25 | 26 | test_that("LoadSpatialCoordinates returns correct number of rows names", { 27 | expect_equal(nrow(coordinates), 5164) 28 | }) 29 | 30 | test_that("LoadSpatialCoordinates returns correct number of sampleIDs", { 31 | expect_equal(table(coordinates$sampleID) |> length(), 2) 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-MapFeaturesSummary.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 5 | 6 | # Test Case 1: Test if MapFeaturesSummary throws an error when subplot_type is missing 7 | test_that("MapFeaturesSummary returns a ggplot object", { 8 | p <- MapFeaturesSummary(se_mcolon, features = "Nrgn", subplot_type = "violin") 9 | expect_identical(class(p)[1], "patchwork") 10 | 11 | p <- MapFeaturesSummary(se_mcolon, features = "Nrgn", subplot_type = "box") 12 | expect_identical(class(p)[1], "patchwork") 13 | 14 | p <- MapFeaturesSummary(se_mcolon, features = "Nrgn", subplot_type = "histogram") 15 | expect_identical(class(p)[1], "patchwork") 16 | 17 | p <- MapFeaturesSummary(se_mcolon, features = "Nrgn", subplot_type = "density") 18 | expect_identical(class(p)[1], "patchwork") 19 | 20 | p <- MapFeaturesSummary(se_mcolon, features = "Nrgn", subplot_type = "density", crop_area = c(0.4, 0.4, 0.5, 0.5)) 21 | expect_identical(class(p)[1], "patchwork") 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-MapLabelsSummary.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) |> 5 | LoadImages() 6 | 7 | # Test Case 1: Test if MapFeaturesSummary throws an error when subplot_type is missing 8 | test_that("MapFeaturesSummary returns a ggplot object", { 9 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident") 10 | expect_identical(class(p)[1], "patchwork") 11 | 12 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", bar_display = "percent") 13 | expect_identical(class(p)[1], "patchwork") 14 | 15 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", bar_display = "count") 16 | expect_identical(class(p)[1], "patchwork") 17 | 18 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", bar_width = 2) 19 | expect_identical(class(p)[1], "patchwork") 20 | 21 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", image_use = "raw") 22 | expect_identical(class(p)[1], "patchwork") 23 | 24 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", hide_legend = TRUE) 25 | expect_identical(class(p)[1], "patchwork") 26 | 27 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", label_by = "sample_id") 28 | expect_identical(class(p)[1], "patchwork") 29 | 30 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", colors = c("red", "blue")) 31 | expect_identical(class(p)[1], "patchwork") 32 | 33 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", crop_area = c(0.4, 0.4, 0.5, 0.5)) 34 | expect_identical(class(p)[1], "patchwork") 35 | 36 | p <- MapLabelsSummary(se_mcolon, column_name = "orig.ident", section_number = 1) 37 | expect_identical(class(p)[1], "patchwork") 38 | }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-MaskImages.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | library(magick) 4 | library(dplyr) 5 | 6 | # Load example data 7 | lowres_image_file <- system.file("extdata/mousebrain/spatial", 8 | "tissue_lowres_image.jpg", 9 | package = "semla") 10 | im <- image_read(lowres_image_file) 11 | 12 | coordinates_file <- system.file("extdata/mousebrain/spatial", 13 | "tissue_positions_list.csv", 14 | package = "semla") 15 | xy <- LoadSpatialCoordinates(coordinatefiles = coordinates_file) 16 | 17 | scalefactors <- system.file("extdata/mousebrain/spatial", 18 | "scalefactors_json.json", 19 | package = "semla") |> 20 | jsonlite::read_json() 21 | 22 | xy <- xy |> 23 | mutate(across(all_of(c("pxl_row_in_fullres", 24 | "pxl_col_in_fullres")), ~.x*scalefactors$tissue_lowres_scalef)) 25 | 26 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 27 | 28 | test_that("MaskImages.default returns a masked image with the correct class", { 29 | im_masked <- MaskImages(im, xy_coords = xy, verbose = FALSE) 30 | expect_true(inherits(im_masked, "magick-image")) 31 | }) 32 | 33 | test_that("MaskImages.default throws an error when given an incorrect input class", { 34 | expect_error(MaskImages.default("Invalid class", xy_coords = xy, verbose = FALSE), 35 | "Invalid class 'character', expected a 'magick-image' object") 36 | }) 37 | 38 | test_that("MaskImages.Seurat returns a Seurat object with masked images", { 39 | se_mbrain <- LoadImages(se_mbrain) 40 | se_mbrain_masked <- MaskImages(se_mbrain, verbose = FALSE) 41 | expect_true(inherits(se_mbrain_masked, "Seurat")) 42 | expect_true(!is.null(se_mbrain_masked@tools$Staffli@rasterlists[["raw"]])) 43 | }) 44 | 45 | test_that("MaskImages.Seurat throws an error when given an incorrect section number", { 46 | se_mbrain <- LoadImages(se_mbrain) 47 | expect_error(MaskImages(se_mbrain, section_numbers = 99, verbose = FALSE), 48 | "Invalid numbers for 'section_numbers'. Sections available:") 49 | }) 50 | 51 | -------------------------------------------------------------------------------- /tests/testthat/test-MergeSTData.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Load Seurat objects from semla package for testing 5 | se_mbrain <- readRDS(system.file("extdata", "mousebrain/se_mbrain", package = "semla")) 6 | se_mcolon <- readRDS(system.file("extdata", "mousecolon/se_mcolon", package = "semla")) 7 | 8 | test_that("MergeSTData works as expected", { 9 | # Merge Seurat objects 10 | se_merged <- MergeSTData(x = se_mbrain, y = se_mcolon) 11 | 12 | # Check that the output is a Seurat object 13 | expect_s4_class(se_merged, "Seurat") 14 | 15 | # Check that the merged data contains cells from both input objects 16 | expect_equal(length(colnames(se_merged)), length(colnames(se_mbrain)) + length(colnames(se_mcolon))) 17 | 18 | # Check that the Staffli object is present and correctly merged 19 | merged_staffli <- GetStaffli(se_merged) 20 | expect_equal(length(unique(merged_staffli@meta_data$barcode)), length(colnames(se_merged))) 21 | }) 22 | -------------------------------------------------------------------------------- /tests/testthat/test-RadialDistance.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 5 | 6 | test_that("RadialDistance function returns valid results", { 7 | 8 | # Test case 1: Check if the function returns a data frame 9 | expect_s4_class(RadialDistance(se_mcolon, column_name = "selection", selected_groups = "GALT"), "Seurat") 10 | 11 | # Test case 2: Check if the function handles angles correctly 12 | se_mcolon <- DisconnectRegions(se_mcolon, column_name = "selection", selected_groups = "GALT") 13 | expect_s4_class(RadialDistance(se_mcolon, column_name = "GALT_split", selected_groups = "S1_region1", angles = c(0, 90)), "Seurat") 14 | 15 | # Test case 3: Check if the function handles angles_nbreaks correctly 16 | expect_s4_class(RadialDistance(se_mcolon, column_name = "GALT_split", selected_groups = "S1_region1", angles_nbreaks = 4), "Seurat") 17 | 18 | # Test case 4: Check if the function handles remove_singletons correctly 19 | expect_s4_class(RadialDistance(se_mcolon, column_name = "GALT_split", selected_groups = "S1_region1", remove_singletons = FALSE), "Seurat") 20 | 21 | # Test case 5: Check if the function handles convert_to_microns correctly 22 | expect_s4_class(RadialDistance(se_mcolon, column_name = "GALT_split", selected_groups = "S1_region1", convert_to_microns = TRUE), "Seurat") 23 | }) 24 | 25 | test_that("RadialDistance function returns valid errors", { 26 | # Test case 6: Check if the function handles invalid input (e.g., non-existent spots) 27 | expect_error(RadialDistance(se_mcolon, column_name = "missing"), class = "error") 28 | 29 | # Test case 7: Check if the function handles invalid angles 30 | expect_error(RadialDistance(se_mcolon, column_name = "GALT_split", selected_groups = "S1_region1", angles = c(90, 0)), class = "error") 31 | }) -------------------------------------------------------------------------------- /tests/testthat/test-ReadVisiumData.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(dplyr) 3 | 4 | # Test if the function returns a Seurat object 5 | test_that("ReadVisiumData returns a Seurat object", { 6 | infoTable <- tibble(samples = system.file("extdata/mousebrain/filtered_feature_bc_matrix.h5", package = "semla"), 7 | imgs = system.file("extdata/mousebrain/spatial/tissue_lowres_image.jpg", package = "semla"), 8 | spotfiles = system.file("extdata/mousebrain/spatial/tissue_positions_list.csv", package = "semla"), 9 | json = system.file("extdata/mousebrain/spatial/scalefactors_json.json", package = "semla")) 10 | 11 | se <- ReadVisiumData(infoTable, verbose = FALSE) 12 | se_sf <- ReadVisiumData(infoTable |> select(-all_of("json")) |> mutate(scalefactor = 0.5), verbose = FALSE) 13 | 14 | expect_true(class(se) == "Seurat") 15 | expect_true(all(dim(se) == c(188, 2560))) 16 | 17 | expect_true(class(se_sf) == "Seurat") 18 | expect_true(all(dim(se_sf) == c(188, 2560))) 19 | }) 20 | 21 | # Test if the function returns a Seurat object 22 | test_that("ReadVisiumData returns a an error when the infoTable is incorrect", { 23 | infoTable <- tibble(samples = system.file("extdata/mousebrain/filtered_feature_bc_matrix.h5", package = "semla"), 24 | imgs = system.file("extdata/mousebrain/spatial/tissue_lowres_image.jpg", package = "semla"), 25 | spotfiles = system.file("extdata/mousebrain/spatial/tissue_positions_list.csv", package = "semla"), 26 | json = system.file("extdata/mousebrain/spatial/scalefactors_json.json", package = "semla")) 27 | 28 | # Should throw error when samples, imgs or spotfiles is missing 29 | expect_error(ReadVisiumData(infoTable |> select(-samples), verbose = FALSE), 30 | "One or several of 'samples', 'imgs' and 'spotfiles' are missing from infoTable") 31 | expect_error(ReadVisiumData(infoTable |> select(-imgs), verbose = FALSE), 32 | "One or several of 'samples', 'imgs' and 'spotfiles' are missing from infoTable") 33 | expect_error(ReadVisiumData(infoTable |> select(spotfiles), verbose = FALSE), 34 | "One or several of 'samples', 'imgs' and 'spotfiles' are missing from infoTable") 35 | expect_error(ReadVisiumData(infoTable |> select(-json), verbose = FALSE), 36 | "One of 'json' or 'scalefactor' columns needs to be provided") 37 | 38 | # Throw error if column classes are invalid 39 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA), verbose = FALSE), 40 | "Invalid column classes in 'infoTable'. Expected 'character' vectors") 41 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA), verbose = FALSE), 42 | "Invalid column classes in 'infoTable'. Expected 'character' vectors") 43 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA), verbose = FALSE), 44 | "Invalid column classes in 'infoTable'. Expected 'character' vectors") 45 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA), verbose = FALSE), 46 | "Invalid column classes in 'infoTable'. Expected 'character' vectors") 47 | 48 | # Throw error if files are missing 49 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA_character_), verbose = FALSE), 50 | "Missing file") 51 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA_character_), verbose = FALSE), 52 | "Missing file") 53 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA_character_), verbose = FALSE), 54 | "Missing file") 55 | expect_error(ReadVisiumData(infoTable |> mutate(samples = NA_character_), verbose = FALSE), 56 | "Missing file") 57 | }) 58 | -------------------------------------------------------------------------------- /tests/testthat/test-RunLabelAssortativityTest.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Define test data 5 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 6 | 7 | se_mcolon <- se_mcolon |> 8 | ScaleData(verbose = FALSE) |> 9 | RunPCA(verbose = FALSE) |> 10 | FindNeighbors(reduction = "pca", dims = 1:30, verbose = FALSE) |> 11 | FindClusters(verbose = FALSE) 12 | 13 | # Test 14 | test_that("RadialDistance function returns valid results", { 15 | 16 | # Run Label Assortativity Analysis 17 | res <- RunLabelAssortativityTest(object = se_mcolon, 18 | column_name = "seurat_clusters", 19 | n_permutations = 2, 20 | nCores = 1) 21 | 22 | expect_s3_class(res, "tbl_df") 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-RunLocalG.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Mock Seurat object 5 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 6 | 7 | test_that("RunLocalG.Seurat returns valid results", { 8 | result <- RunLocalG(se_mbrain, features = VariableFeatures(se_mbrain)[1:2]) 9 | 10 | # Check if the result is a Seurat object with results in metadata 11 | expect_s4_class(result, "Seurat") 12 | expect_true(all(c("Gi[Hbb-bs]", "Gi[Hbb-bs]") %in% names(result[[]]))) 13 | 14 | result <- RunLocalG(se_mbrain, features = VariableFeatures(se_mbrain)[1:10], store_in_metadata = FALSE, alternative = "greater") 15 | expect_true("GiScores" %in% names(result@assays)) 16 | expect_true(all(c("Gi[Hbb-bs]", "Gi[Hbb-bs]") %in% rownames(result@assays$GiScores))) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-RunNNLS.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | library(RcppML) 4 | 5 | se_mbrain <- readRDS(system.file("extdata/mousebrain", 6 | "se_mbrain", 7 | package = "semla")) 8 | 9 | # Random clusters 10 | se_mbrain$clusters <- sample(c("A", "B", "C"), size = ncol(se_mbrain), replace = TRUE) 11 | se_mbrain <- SetIdent(se_mbrain, value = "clusters") 12 | 13 | test_that("RunNNLS returns valid results", { 14 | 15 | # Test with default arguments 16 | res1 <- suppressWarnings({RunNNLS(se_mbrain, singlecell_object = se_mbrain, groups = "clusters", 17 | singlecell_assay = "Spatial", spatial_assay = "Spatial")}) 18 | expect_s4_class(res1, "Seurat") 19 | expect_true("celltypeprops" %in% names(res1@assays)) 20 | 21 | # Test with return_as_dimred = TRUE 22 | res2 <- suppressWarnings({RunNNLS(se_mbrain, singlecell_object = se_mbrain, groups = "clusters", 23 | singlecell_assay = "Spatial", spatial_assay = "Spatial", return_as_dimred = TRUE)}) 24 | expect_s4_class(res2, "Seurat") 25 | expect_true("nnls" %in% names(res2@reductions)) 26 | 27 | # Test with idents 28 | res3 <- suppressWarnings({RunNNLS(se_mbrain, singlecell_object = se_mbrain, 29 | singlecell_assay = "Spatial", spatial_assay = "Spatial")}) 30 | expect_s4_class(res3, "Seurat") 31 | expect_true("celltypeprops" %in% names(res3@assays)) 32 | 33 | # Test with rare cell type 34 | se_mbrain$clusters[1] <- "D" 35 | res4 <- suppressWarnings({RunNNLS(se_mbrain, singlecell_object = se_mbrain, groups = "clusters", 36 | singlecell_assay = "Spatial", spatial_assay = "Spatial")}) 37 | expect_s4_class(res4, "Seurat") 38 | expect_true("celltypeprops" %in% names(res4@assays)) 39 | 40 | # Test with negative values 41 | mat1 <- GetAssayData(se_mbrain, slot = "data") 42 | mat1[1, 1] <- -1 43 | res5 <- suppressWarnings({RunNNLS(mat1, singlecell_matrix = mat1, groups = se_mbrain$clusters)}) 44 | expect_type(res5, "double") 45 | }) 46 | 47 | test_that("RunNNLS throws expected errors", { 48 | 49 | expect_error(RunNNLS("invalid")) 50 | expect_error(RunNNLS(se_mbrain, singlecell_object = "invalid")) 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/test-RunNeighborhoodEnrichmentTest.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Define test data 5 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 6 | 7 | se_mcolon <- se_mcolon |> 8 | ScaleData(verbose = FALSE) |> 9 | RunPCA(verbose = FALSE) |> 10 | FindNeighbors(reduction = "pca", dims = 1:30, verbose = FALSE) |> 11 | FindClusters(verbose = FALSE) 12 | 13 | # Test 14 | test_that("RadialDistance function returns valid results", { 15 | 16 | # Run Label Assortativity Analysis 17 | res <- RunNeighborhoodEnrichmentTest(object = se_mcolon, 18 | column_name = "seurat_clusters", 19 | n_permutations = 2, 20 | nCores = 1) 21 | 22 | expect_s3_class(res, "tbl_df") 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-SubsetSTData.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Load Seurat objects from semla package for testing 5 | se_mbrain <- readRDS(system.file("extdata", "mousebrain/se_mbrain", package = "semla")) 6 | 7 | test_that("SubsetSTData works as expected", { 8 | # Subset Seurat object 9 | se_subset <- SubsetSTData(se_mbrain, spots = colnames(se_mbrain)[1:1000]) 10 | 11 | # Check that the output is a Seurat object 12 | expect_s4_class(se_subset, "Seurat") 13 | 14 | # Check that the number of cells matches the expected number 15 | expect_equal(length(colnames(se_subset)), 1000) 16 | 17 | # Check that the subsetted cells are correct 18 | expect_equal(colnames(se_subset), colnames(se_mbrain)[1:1000]) 19 | 20 | # Check that the Staffli object is present and correctly subsetted 21 | expect_equal(length(unique(GetStaffli(se_subset)@meta_data$barcode)), 1000) 22 | 23 | # Subset Seurat object 24 | se_subset <- SubsetSTData(se_mbrain, expression = nFeature_Spatial > 60, features = rownames(se_mbrain)[1:100]) 25 | 26 | expect_equal(ncol(se_subset), 686) 27 | expect_equal(nrow(se_subset), 100) 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-UpdateSeuratFromSemla.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Load Seurat objects from semla package for testing 5 | se_mbrain <- readRDS(system.file("extdata", "mousebrain/se_mbrain", package = "semla")) 6 | se_mcolon <- readRDS(system.file("extdata/mousecolon", "se_mcolon", package = "semla")) 7 | se <- MergeSTData(se_mbrain, se_mcolon) 8 | 9 | test_that("UpdateSeuratFromSemla works as expected", { 10 | # Update object for one section raw image 11 | se_upd <- UpdateSeuratFromSemla(se_mbrain, image_use = "raw", verbose = TRUE) 12 | 13 | ## Check that the output is a Seurat object 14 | expect_s4_class(se_upd, "Seurat") 15 | 16 | ## Check that we can plot the image 17 | # expect_s3_class(SpatialFeaturePlot(se_upd, features = "Nrgn"), "patchwork") 18 | 19 | # Update object for one section transformed image 20 | se_mbrain <- LoadImages(se_mbrain) 21 | rotation_angle <- get_array_rotation(se_mbrain, grid_pattern = "hexagonal") 22 | transforms <- generate_rigid_transform(sampleID = 1L, angle = 10) 23 | se_mbrain <- RigidTransformImages(se_mbrain, transforms = transforms) 24 | 25 | se_upd <- UpdateSeuratFromSemla(se_mbrain, image_use = "transformed", verbose = TRUE) 26 | 27 | ## Check that the output is a Seurat object 28 | expect_s4_class(se_upd, "Seurat") 29 | 30 | # Update object for multiple sections raw image 31 | se_upd <- UpdateSeuratFromSemla(se, image_use = "raw", verbose = TRUE) 32 | 33 | ## Check that the output is a Seurat object 34 | expect_s4_class(se_upd, "Seurat") 35 | 36 | # Update object for multiple sections transformed image 37 | se <- LoadImages(se) 38 | rotation_angle <- get_array_rotation(se, grid_pattern = "hexagonal") 39 | transforms <- rbind(generate_rigid_transform(sampleID = 1L, angle = rotation_angle$`1`), 40 | generate_rigid_transform(sampleID = 2L, angle = 12)) 41 | se <- RigidTransformImages(se, transforms = transforms) 42 | 43 | se_upd <- UpdateSeuratFromSemla(se, image_use = "transformed", verbose = TRUE) 44 | 45 | ## Check that the output is a Seurat object 46 | expect_s4_class(se_upd, "Seurat") 47 | 48 | # ## Check that the output is a Seurat object 49 | # expect_s4_class(se_upd, "Seurat") 50 | # 51 | # ## Check that we can plot the image 52 | # expect_s3_class(SpatialFeaturePlot(se_upd, features = "Nrgn"), "patchwork") 53 | # 54 | # # Update object for multiple sections 55 | # se_upd <- UpdateSeuratFromSemla(se_upd, image_use = "raw", verbose = TRUE) 56 | # 57 | # ## Check that the output is a Seurat object 58 | # expect_s4_class(se_upd, "Seurat") 59 | }) -------------------------------------------------------------------------------- /tests/testthat/test-export_graph.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | se_mbrain <- readRDS(system.file("extdata/mousebrain", "se_mbrain", package = "semla")) 5 | 6 | # Test the export_graph function 7 | test_that("export_graph exports a JSON file", { 8 | 9 | # Define a temporary directory for testing 10 | test_outdir <- tempdir() 11 | 12 | # Call the export_graph function 13 | export_graph(se_mbrain, sampleID = 1L, outdir = test_outdir, verbose = FALSE) 14 | 15 | # Check if the JSON file was created in the specified directory 16 | json_file <- file.path(test_outdir, "network_Visium_1.json") 17 | expect_true(file.exists(json_file)) 18 | 19 | # Clean up: Remove the temporary directory and file 20 | unlink(json_file, recursive = TRUE) 21 | }) 22 | 23 | -------------------------------------------------------------------------------- /tests/testthat/test-fileserver.R: -------------------------------------------------------------------------------- 1 | library(beakr) 2 | 3 | # Test case 1: Test if the function can host a directory and return a beakr instance 4 | test_that("file_server returns a beakr instance", { 5 | beakr::stopAllServers() 6 | fs <- file_server(hostDir = tempdir()) 7 | expect_equal(class(fs), c("Beakr", "R6")) 8 | beakr::stopServer(fs) 9 | }) 10 | 11 | # Test case 2: Test if an error is raised if the directory to host files from does not exist 12 | test_that("an error is raised if the directory to host files from does not exist", { 13 | expect_error(suppressWarnings({file_server(hostDir = "invalid_directory")})) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-ftrviewer.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Test ftrviewer 5 | test_that("ftrviewer returns an htmlwidget", { 6 | widget <- ftrviewer(values = 1, opacities = 1, range = c(0, 1)) 7 | expect_s3_class(widget, "htmlwidget") 8 | }) 9 | 10 | # Test widget_html.ftrviewer 11 | test_that("widget_html.ftrviewer returns an HTML tag list", { 12 | tags <- widget_html.ftrviewer("id", "style", "class") 13 | expect_s3_class(tags, "shiny.tag.list") 14 | }) 15 | 16 | # Test ftrviewerOutput 17 | test_that("ftrviewerOutput returns an HTML output element", { 18 | output <- suppressWarnings({ftrviewerOutput("outputId")}) 19 | expect_s3_class(output, "shiny.tag.list") 20 | }) 21 | 22 | # Test renderftrviewer 23 | test_that("renderftrviewer returns a shiny render function", { 24 | renderFunc <- renderFtrviewer(expr = { }) 25 | expect_s3_class(renderFunc, "shiny.render.function") 26 | }) 27 | 28 | # Test Case 2: Test if renderftrviewer generates a render function 29 | test_that("renderftrviewer generates a render function", { 30 | render_function <- renderFtrviewer({ 31 | paper(data = list(), width = "100%", height = "400px") 32 | }) 33 | expect_true(inherits(render_function, what = "shiny.render.function")) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-icp.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Create test data 5 | set.seed(123) 6 | pm <- matrix(runif(100), ncol = 2) 7 | qm <- matrix(runif(100), ncol = 2) 8 | xy_ref <- matrix(runif(100), ncol = 2) 9 | xy_query <- matrix(runif(100), ncol = 2) 10 | 11 | test_that("icp returns valid results", { 12 | result <- icp(xy_ref, xy_query) 13 | 14 | # Check if the result is a list with "y_transf" and "rot_mat" elements 15 | expect_type(result, "list") 16 | expect_named(result, c("y_transf", "rot_mat")) 17 | expect_type(result$y_transf, "double") 18 | expect_type(result$rot_mat, "double") 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-neighborhood_analysis.R: -------------------------------------------------------------------------------- 1 | # Load required libraries 2 | library(testthat) 3 | library(dplyr) 4 | library(tidyr) 5 | library(semla) 6 | 7 | # Define test data 8 | se_mbrain <- readRDS(system.file("extdata", "/mousebrain/se_mbrain", package = "semla")) 9 | 10 | se_mbrain <- se_mbrain %>% 11 | ScaleData(verbose = FALSE) %>% 12 | RunPCA(verbose = FALSE) %>% 13 | FindNeighbors(verbose = FALSE) %>% 14 | FindClusters(verbose = FALSE) 15 | 16 | # Test cases 17 | test_that("RegionNeighbors should work with default parameters", { 18 | res <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "10") 19 | expect_true("nb_to_10" %in% colnames(res@meta.data)) 20 | }) 21 | 22 | test_that("RegionNeighbors should work with different modes", { 23 | res_outer <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "10", mode = "outer") 24 | res_inner <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "10", mode = "inner") 25 | res_inner_outer <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "10", mode = "inner_outer") 26 | res_all_inner_outer <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "10", mode = "all_inner_outer") 27 | 28 | expect_true("nb_to_10" %in% colnames(res_outer@meta.data)) 29 | expect_true("inner_border_10" %in% colnames(res_inner@meta.data)) 30 | expect_true("nb_to_10" %in% colnames(res_inner_outer@meta.data)) 31 | expect_true("nb_to_10" %in% colnames(res_all_inner_outer@meta.data)) 32 | }) 33 | 34 | test_that("RegionNeighbors should work with custom column_key", { 35 | res <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "10", column_key = "custom_key_") 36 | expect_true("custom_key_10" %in% colnames(res@meta.data)) 37 | }) 38 | 39 | test_that("RegionNeighbors should work with multiple column_labels", { 40 | res <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = c("8", "10")) 41 | expect_true("nb_to_8" %in% colnames(res@meta.data)) 42 | expect_true("nb_to_10" %in% colnames(res@meta.data)) 43 | }) 44 | 45 | test_that("RegionNeighbors should work with additional parameters for GetSpatialNetwork", { 46 | res <- RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "10", nNeighbors = 40, maxDist = Inf) 47 | expect_true("nb_to_10" %in% colnames(res@meta.data)) 48 | }) 49 | 50 | test_that("RegionNeighbors should return an error with invalid column_name", { 51 | expect_error(RegionNeighbors(se_mbrain, column_name = "non_existent_column", column_labels = "10")) 52 | }) 53 | 54 | test_that("RegionNeighbors should return an error with invalid column_labels", { 55 | expect_error(RegionNeighbors(se_mbrain, column_name = "seurat_clusters", column_labels = "non_existent_label")) 56 | }) 57 | 58 | -------------------------------------------------------------------------------- /tests/testthat/test-osddu.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Test osddu 5 | test_that("osddu returns an htmlwidget", { 6 | data <- list() # Need actual data for a meaningful test 7 | widget <- osddu(data) 8 | expect_s3_class(widget, "htmlwidget") 9 | }) 10 | 11 | # Test widget_html.osddu 12 | test_that("widget_html.osddu returns an HTML tag list", { 13 | tags <- widget_html.osddu("id", "style", "class") 14 | expect_s3_class(tags, "shiny.tag.list") 15 | }) 16 | 17 | # Test osdduOutput 18 | test_that("osdduOutput returns an HTML output element", { 19 | output <- suppressWarnings({osdduOutput("outputId")}) 20 | expect_s3_class(output, "shiny.tag.list") 21 | }) 22 | 23 | # Test renderOsddu 24 | test_that("renderOsddu returns a shiny render function", { 25 | renderFunc <- renderOsddu(expr = { }) 26 | expect_s3_class(renderFunc, "shiny.render.function") 27 | }) 28 | 29 | # Test Case 2: Test if renderOsddu generates a render function 30 | test_that("renderOsddu generates a render function", { 31 | render_function <- renderOsddu({ 32 | paper(data = list(), width = "100%", height = "400px") 33 | }) 34 | expect_true(inherits(render_function, what = "shiny.render.function")) 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test-paper.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(semla) 3 | 4 | # Test paper 5 | test_that("paper returns an htmlwidget", { 6 | data <- list() # Need actual data for a meaningful test 7 | widget <- paper(data) 8 | expect_s3_class(widget, "htmlwidget") 9 | }) 10 | 11 | # Test widget_html.paper 12 | test_that("widget_html.paper returns an HTML tag list", { 13 | tags <- widget_html.paper("id", "style", "class") 14 | expect_s3_class(tags, "shiny.tag.list") 15 | }) 16 | 17 | # Test paperOutput 18 | test_that("paperOutput returns an HTML output element", { 19 | output <- suppressWarnings({paperOutput("outputId")}) 20 | expect_s3_class(output, "shiny.tag.list") 21 | }) 22 | 23 | # Test renderPaper 24 | test_that("renderPaper returns a shiny render function", { 25 | renderFunc <- renderPaper(expr = { }) 26 | expect_s3_class(renderFunc, "shiny.render.function") 27 | }) 28 | 29 | # Test Case 2: Test if renderPaper generates a render function 30 | test_that("renderPaper generates a render function", { 31 | render_function <- renderPaper({ 32 | paper(data = list(), width = "100%", height = "400px") 33 | }) 34 | expect_true(inherits(render_function, what = "shiny.render.function")) 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test-themes.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(patchwork) 3 | library(ggplot2) 4 | library(semla) 5 | 6 | # Test ThemeClean function 7 | test_that("ThemeClean returns a theme object with expected modifications", { 8 | theme_obj <- ThemeClean() 9 | expect_s3_class(theme_obj, "theme") 10 | }) 11 | 12 | # Test ThemeLegendRight function 13 | test_that("ThemeLegendRight returns a theme object with expected modifications", { 14 | theme_obj <- ThemeLegendRight() 15 | 16 | expect_s3_class(theme_obj, "theme") 17 | }) 18 | 19 | # Test ThemeClean 20 | test_that("ThemeClean returns a theme with blank title, subtitle, and no legend", { 21 | th <- ThemeClean() 22 | expect_true(is(th, "theme")) 23 | expect_equal(th$plot.title, element_blank()) 24 | expect_equal(th$plot.subtitle, element_blank()) 25 | expect_equal(th$legend.position, "none") 26 | }) 27 | 28 | # Test ThemeLegendRight 29 | test_that("ThemeLegendRight returns a theme with legend on the right and horizontal text", { 30 | th <- ThemeLegendRight() 31 | expect_true(is(th, "theme")) 32 | expect_equal(th$legend.position, "right") 33 | expect_equal(th$legend.text, element_text(angle = 0, hjust = 1)) 34 | }) 35 | 36 | # Test ModifyPatchworkTitles 37 | test_that("ModifyPatchworkTitles modifies patchwork titles correctly", { 38 | # Create a patchwork object 39 | p <- (ggplot(mtcars, aes(mpg, disp)) + geom_point()) / (ggplot(mtcars, aes(mpg, hp)) + geom_point()) 40 | 41 | # Modify titles 42 | p_modified <- ModifyPatchworkTitles(p, titles = c("First", "Second")) 43 | 44 | # Check that the titles have been modified correctly 45 | expect_equal(p_modified$patches$plots[[1]]$labels$title, "First") 46 | expect_equal(p_modified$labels$title, "Second") 47 | }) 48 | 49 | 50 | # Test ModifyPatchworkTitles with invalid inputs 51 | test_that("ModifyPatchworkTitles throws an error with invalid inputs", { 52 | # Not a patchwork object 53 | expect_error(ModifyPatchworkTitles(ggplot(mtcars, aes(mpg, disp)) + geom_point(), titles = c("First")), 54 | "Expected a 'patcwork' object") 55 | 56 | # Not a character vector for titles 57 | p <- (ggplot(mtcars, aes(mpg, disp)) + geom_point()) / (ggplot(mtcars, aes(mpg, hp)) + geom_point()) 58 | expect_error(ModifyPatchworkTitles(p, titles = list("First", "Second")), 59 | "Expected titles to be 'character' vector") 60 | 61 | # Incorrect number of titles 62 | expect_error(ModifyPatchworkTitles(p, titles = c("A", "B", "C")), 63 | "Invalid length of 'titles'. Expected a character vector of length 2.") 64 | }) 65 | -------------------------------------------------------------------------------- /vignettes/NNMF/fea_results_nmf_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/NNMF/fea_results_nmf_1 -------------------------------------------------------------------------------- /vignettes/NNMF/gene_loadings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/NNMF/gene_loadings.jpg -------------------------------------------------------------------------------- /vignettes/NNMF/gene_loadings_sorted: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/NNMF/gene_loadings_sorted -------------------------------------------------------------------------------- /vignettes/NNMF/multiple_factors.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/NNMF/multiple_factors.jpg -------------------------------------------------------------------------------- /vignettes/NNMF/multiple_factors_heatmap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/NNMF/multiple_factors_heatmap.jpg -------------------------------------------------------------------------------- /vignettes/NNMF/rank_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/NNMF/rank_plot.jpg -------------------------------------------------------------------------------- /vignettes/NNMF/spatial_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/NNMF/spatial_plot.jpg -------------------------------------------------------------------------------- /vignettes/compare_cell_type_mapping_NNLS/mbrain_cor_bars.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/compare_cell_type_mapping_NNLS/mbrain_cor_bars.jpg -------------------------------------------------------------------------------- /vignettes/compare_cell_type_mapping_NNLS/mbrain_cor_heatmaps.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/compare_cell_type_mapping_NNLS/mbrain_cor_heatmaps.jpg -------------------------------------------------------------------------------- /vignettes/compare_cell_type_mapping_NNLS/mbrain_spatial_map_plots.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/compare_cell_type_mapping_NNLS/mbrain_spatial_map_plots.rds -------------------------------------------------------------------------------- /vignettes/compare_cell_type_mapping_NNLS/mkidney_cor_bars.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/compare_cell_type_mapping_NNLS/mkidney_cor_bars.jpg -------------------------------------------------------------------------------- /vignettes/compare_cell_type_mapping_NNLS/mkidney_cor_heatmaps.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/compare_cell_type_mapping_NNLS/mkidney_cor_heatmaps.jpg -------------------------------------------------------------------------------- /vignettes/compare_cell_type_mapping_NNLS/mkidney_spatial_map_plots.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/compare_cell_type_mapping_NNLS/mkidney_spatial_map_plots.rds -------------------------------------------------------------------------------- /vignettes/comparison/mousebrain/cell2location: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/comparison/mousebrain/cell2location -------------------------------------------------------------------------------- /vignettes/comparison/mousebrain/celltypeprops: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/comparison/mousebrain/celltypeprops -------------------------------------------------------------------------------- /vignettes/comparison/mousebrain/stereoscope: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/comparison/mousebrain/stereoscope -------------------------------------------------------------------------------- /vignettes/comparison/mousekidney/cell2location: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/comparison/mousekidney/cell2location -------------------------------------------------------------------------------- /vignettes/comparison/mousekidney/celltypeprops: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/comparison/mousekidney/celltypeprops -------------------------------------------------------------------------------- /vignettes/comparison/mousekidney/stereoscope: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/comparison/mousekidney/stereoscope -------------------------------------------------------------------------------- /vignettes/digital_unrolling/mBrain.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/digital_unrolling/mBrain.jpg -------------------------------------------------------------------------------- /vignettes/digital_unrolling/mBrain_x_dist.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/digital_unrolling/mBrain_x_dist.jpg -------------------------------------------------------------------------------- /vignettes/images/alignment/aligned_cropped.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/aligned_cropped.jpg -------------------------------------------------------------------------------- /vignettes/images/alignment/aligned_images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/aligned_images.png -------------------------------------------------------------------------------- /vignettes/images/alignment/alignment_brain_colon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/alignment_brain_colon.png -------------------------------------------------------------------------------- /vignettes/images/alignment/alignment_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/alignment_start.png -------------------------------------------------------------------------------- /vignettes/images/alignment/help_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/help_menu.png -------------------------------------------------------------------------------- /vignettes/images/alignment/rotated_and_scaled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/rotated_and_scaled.png -------------------------------------------------------------------------------- /vignettes/images/alignment/selected_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/selected_image.png -------------------------------------------------------------------------------- /vignettes/images/alignment/transformed_images_brain_colon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/transformed_images_brain_colon.jpg -------------------------------------------------------------------------------- /vignettes/images/alignment/unique_genes_aligned.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/alignment/unique_genes_aligned.jpeg -------------------------------------------------------------------------------- /vignettes/images/backup/categorical_features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/categorical_features.png -------------------------------------------------------------------------------- /vignettes/images/backup/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/cut.png -------------------------------------------------------------------------------- /vignettes/images/backup/feature_viewer_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/feature_viewer_start.png -------------------------------------------------------------------------------- /vignettes/images/backup/help_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/help_menu.png -------------------------------------------------------------------------------- /vignettes/images/backup/lasso_tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/lasso_tool.png -------------------------------------------------------------------------------- /vignettes/images/backup/new_label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/new_label.png -------------------------------------------------------------------------------- /vignettes/images/backup/numeric_features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/numeric_features.png -------------------------------------------------------------------------------- /vignettes/images/backup/wrong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/wrong.png -------------------------------------------------------------------------------- /vignettes/images/backup/zoom_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/backup/zoom_in.png -------------------------------------------------------------------------------- /vignettes/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/cut.png -------------------------------------------------------------------------------- /vignettes/images/slide-seq/DG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/slide-seq/DG.jpg -------------------------------------------------------------------------------- /vignettes/images/slide-seq/unique_genes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/slide-seq/unique_genes.jpg -------------------------------------------------------------------------------- /vignettes/images/viewer/categorical_features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/viewer/categorical_features.png -------------------------------------------------------------------------------- /vignettes/images/viewer/feature_viewer_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/viewer/feature_viewer_start.png -------------------------------------------------------------------------------- /vignettes/images/viewer/help_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/viewer/help_menu.png -------------------------------------------------------------------------------- /vignettes/images/viewer/lasso_tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/viewer/lasso_tool.png -------------------------------------------------------------------------------- /vignettes/images/viewer/new_label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/viewer/new_label.png -------------------------------------------------------------------------------- /vignettes/images/viewer/numeric_features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/viewer/numeric_features.png -------------------------------------------------------------------------------- /vignettes/images/viewer/zoom_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/viewer/zoom_in.png -------------------------------------------------------------------------------- /vignettes/images/wrong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/images/wrong.png -------------------------------------------------------------------------------- /vignettes/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/logo.png -------------------------------------------------------------------------------- /vignettes/reference/AnglePlot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/AnglePlot-1.png -------------------------------------------------------------------------------- /vignettes/reference/CoordAndImageTransform-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/CoordAndImageTransform-1.png -------------------------------------------------------------------------------- /vignettes/reference/CoordAndImageTransform-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/CoordAndImageTransform-2.png -------------------------------------------------------------------------------- /vignettes/reference/CoordMirror-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/CoordMirror-1.png -------------------------------------------------------------------------------- /vignettes/reference/CoordTransform-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/CoordTransform-1.png -------------------------------------------------------------------------------- /vignettes/reference/ImagePlot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/ImagePlot-1.png -------------------------------------------------------------------------------- /vignettes/reference/ImagePlot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/ImagePlot-2.png -------------------------------------------------------------------------------- /vignettes/reference/ImagePlot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/ImagePlot-3.png -------------------------------------------------------------------------------- /vignettes/reference/ImagePlot-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/ImagePlot-4.png -------------------------------------------------------------------------------- /vignettes/reference/ImagePlot-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/ImagePlot-5.png -------------------------------------------------------------------------------- /vignettes/reference/ImagePlot-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/ImagePlot-6.png -------------------------------------------------------------------------------- /vignettes/reference/MapFeaturesSummary-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/MapFeaturesSummary-1.png -------------------------------------------------------------------------------- /vignettes/reference/MapFeaturesSummary-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/MapFeaturesSummary-2.png -------------------------------------------------------------------------------- /vignettes/reference/MapFeaturesSummary-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/MapFeaturesSummary-3.png -------------------------------------------------------------------------------- /vignettes/reference/MapFeaturesSummary-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/MapFeaturesSummary-4.png -------------------------------------------------------------------------------- /vignettes/reference/MapLabelsSummary-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/MapLabelsSummary-1.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot001.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot002.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot003.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot004.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot005.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot006.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot007.png -------------------------------------------------------------------------------- /vignettes/reference/Rplot008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/Rplot008.png -------------------------------------------------------------------------------- /vignettes/reference/centroid_angles_plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/centroid_angles_plot-1.png -------------------------------------------------------------------------------- /vignettes/reference/disconnect-regions-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/disconnect-regions-1.png -------------------------------------------------------------------------------- /vignettes/reference/disconnect-regions-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/disconnect-regions-2.png -------------------------------------------------------------------------------- /vignettes/reference/disconnect-regions-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/disconnect-regions-3.png -------------------------------------------------------------------------------- /vignettes/reference/disconnect-regions-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/disconnect-regions-4.png -------------------------------------------------------------------------------- /vignettes/reference/disconnect-regions-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/disconnect-regions-5.png -------------------------------------------------------------------------------- /vignettes/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/figures/logo.png -------------------------------------------------------------------------------- /vignettes/reference/figures/sr-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/figures/sr-logo.png -------------------------------------------------------------------------------- /vignettes/reference/icp-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/icp-1.png -------------------------------------------------------------------------------- /vignettes/reference/icp-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/icp-2.png -------------------------------------------------------------------------------- /vignettes/reference/icp-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/icp-3.png -------------------------------------------------------------------------------- /vignettes/reference/local-G-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/local-G-1.png -------------------------------------------------------------------------------- /vignettes/reference/local-G-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/local-G-2.png -------------------------------------------------------------------------------- /vignettes/reference/local-G-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/local-G-3.png -------------------------------------------------------------------------------- /vignettes/reference/mask-images-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/mask-images-1.png -------------------------------------------------------------------------------- /vignettes/reference/mask-images-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/mask-images-2.png -------------------------------------------------------------------------------- /vignettes/reference/merge-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/merge-1.png -------------------------------------------------------------------------------- /vignettes/reference/radial-distance-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/radial-distance-1.png -------------------------------------------------------------------------------- /vignettes/reference/radial-distance-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/radial-distance-2.png -------------------------------------------------------------------------------- /vignettes/reference/radial-distance-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/radial-distance-3.png -------------------------------------------------------------------------------- /vignettes/reference/region-neighbors-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/region-neighbors-1.png -------------------------------------------------------------------------------- /vignettes/reference/region-neighbors-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/region-neighbors-2.png -------------------------------------------------------------------------------- /vignettes/reference/region-neighbors-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/region-neighbors-3.png -------------------------------------------------------------------------------- /vignettes/reference/transform-images-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/transform-images-1.png -------------------------------------------------------------------------------- /vignettes/reference/transform-images-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/transform-images-2.png -------------------------------------------------------------------------------- /vignettes/reference/transform-images-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/transform-images-3.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-features-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-features-1.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-features-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-features-2.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-features-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-features-3.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-features-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-features-4.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-features-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-features-5.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-features-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-features-6.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-1.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-2.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-3.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-4.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-5.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-6.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-7.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-labels-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-labels-8.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-multiple-features-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-multiple-features-1.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-multiple-features-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-multiple-features-2.png -------------------------------------------------------------------------------- /vignettes/reference/visualize-multiple-features-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/reference/visualize-multiple-features-3.png -------------------------------------------------------------------------------- /vignettes/semla.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Get started" 3 | format: 4 | html: 5 | toc: true 6 | toc-depth: 3 7 | embed-resources: true 8 | editor: visual 9 | --- 10 | 11 | ```{r setup, include=FALSE} 12 | knitr::opts_chunk$set(echo = TRUE) 13 | ``` 14 | 15 | The goal with this package is to provide simple, fast and flexible methods for processing, analysis and visualization of spatially resolved transcriptomics data. Currently, the package only supports [Seurat](https://satijalab.org/seurat/) objects. 16 | 17 | ## Installation 18 | 19 | `semla` is currently only available as a development version on GitHub: 20 | 21 | ```{r eval=FALSE} 22 | remotes::install_github("ludvigla/semla") 23 | ``` 24 | 25 | Load library 26 | 27 | ```{r eval=FALSE} 28 | library(semla) 29 | packageVersion("semla") 30 | ``` 31 | 32 | ## Authors 33 | 34 | The package is written by *Ludvig Larsson* and *Lovisa Franzén* who are both part of the [Spatial Research lab](https://www.spatialresearch.org/) at [SciLifeLab](https://www.scilifelab.se/) in Stockholm. It is moreover maintained by *Javier Escudero Morlanes*. 35 | 36 | ## Publication 37 | 38 | If you use `semla` in published research, please cite the following article: 39 | 40 | > Larsson L, Franzén L, Ståhl PL, Lundeberg J. Semla: a versatile toolkit for spatially resolved transcriptomics analysis and visualization. *Bioinformatics*. 2023;39(10):btad626. doi:10.1093/bioinformatics/btad626 41 | 42 |
43 | -------------------------------------------------------------------------------- /vignettes/slide-seq.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Slide-Seq data" 3 | date: "Last compiled: `r format(Sys.time(), '%d %B %Y')`" 4 | format: html 5 | editor: visual 6 | editor_options: 7 | chunk_output_type: inline 8 | --- 9 | 10 | ```{r setup, include=FALSE} 11 | knitr::opts_chunk$set(echo = TRUE) 12 | ``` 13 | 14 | In this article, we'll demonstrate how to load Slide-Seq data with `semla`. First, we need to load a `Seurat` object with Slide-Seq data. Here we'll use a prepared `Seurat` object that can be install with the `SeuratData` R package. 15 | 16 | See `?ReadSlideSeq` for more information on how to load raw data. 17 | 18 | ```{r eval=FALSE} 19 | library(semla) 20 | library(SeuratData) 21 | InstallData("ssHippo") 22 | ``` 23 | 24 | ```{r eval=FALSE} 25 | slide_seq <- LoadData("ssHippo") 26 | ``` 27 | 28 | Next, we can convert the `Seurat` object to make it compatible with `semla` using the `UpdateSeuratForSemla` function. Note that the Slide-Seq data doesn't contain H&E images and therefore, all image related functionality of `semla` will be inaccessible. This includes the Feature Viewer and image alignment tools which requires H&E images to work. 29 | 30 | ```{r eval=FALSE} 31 | slide_seq_semla <- UpdateSeuratForSemla(slide_seq) 32 | ``` 33 | 34 | Now we can use visualization functions from `semla` on our Slide-Seq data. 35 | 36 | ```{r eval=FALSE} 37 | MapFeatures(slide_seq_semla, features = "nFeature_Spatial", colors = viridis::magma(n = 11, direction = -1)) & ThemeLegendRight() 38 | ``` 39 | 40 | ```{r eval=FALSE, include=FALSE} 41 | jpeg(filename = "slide-seq/unique_genes.jpg", width = 2e3, height = 2e3, res = 200) 42 | MapFeatures(slide_seq_semla, features = "nFeature_Spatial", colors = viridis::magma(n = 11, direction = -1)) & ThemeLegendRight() 43 | dev.off() 44 | ``` 45 | 46 | ![](images/slide-seq/unique_genes.jpg) 47 | 48 | Zoom in on Dentate gyrus: 49 | 50 | ```{r eval=FALSE} 51 | MapFeatures(slide_seq_semla, features = "PROX1", colors = viridis::magma(n = 11, direction = -1), 52 | crop_area = c(0.35, 0.45, 0.7, 0.7)) & 53 | ThemeLegendRight() & 54 | ggtitle("PROX1 expression in the Dentate Gyrus", subtitle = "") 55 | ``` 56 | 57 | ```{r eval=FALSE, include=FALSE} 58 | jpeg(filename = "slide-seq/DG.jpg", width = 2e3, height = 1.6e3, res = 300) 59 | MapFeatures(slide_seq_semla, features = "PROX1", colors = viridis::magma(n = 11, direction = -1), 60 | crop_area = c(0.35, 0.45, 0.7, 0.7)) & 61 | ThemeLegendRight() & 62 | ggtitle("PROX1 expression in the Dentate Gyrus", subtitle = "") 63 | dev.off() 64 | ``` 65 | 66 | ![](images/slide-seq/DG.jpg) 67 | 68 |
69 | 70 | ------------------------------------------------------------------------ 71 | 72 |
73 | 74 | **Package versions** 75 | 76 | - `semla`: `r packageVersion("semla")` 77 | 78 |
79 | 80 |
81 | 82 | **Session info** 83 | 84 | ```{r} 85 | sessionInfo() 86 | ``` 87 | 88 |
89 | 90 |
91 | -------------------------------------------------------------------------------- /vignettes/sr-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ludvigla/semla/d2dc689b08518e6c04ed812a7fa1827f283efd6d/vignettes/sr-logo.png --------------------------------------------------------------------------------