Binary files /tmp/tmpme8lxtik/8_b8CAWY5p/r-bioc-scater-1.24.0+ds/build/vignette.rds and /tmp/tmpme8lxtik/dI4ssCy8y9/r-bioc-scater-1.26.1+ds/build/vignette.rds differ diff -Nru r-bioc-scater-1.24.0+ds/debian/changelog r-bioc-scater-1.26.1+ds/debian/changelog --- r-bioc-scater-1.24.0+ds/debian/changelog 2022-05-31 12:56:07.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/debian/changelog 2022-11-28 07:22:52.000000000 +0000 @@ -1,3 +1,14 @@ +r-bioc-scater (1.26.1+ds-1) unstable; urgency=medium + + * Team upload. + * New upstream version + * dh-update-R to update Build-Depends (routine-update) + * Reduce piuparts noise in transitions (routine-update) + * Build-Depends: r-cran-ggrastr + Closes: #1024751 + + -- Andreas Tille Mon, 28 Nov 2022 08:22:52 +0100 + r-bioc-scater (1.24.0+ds-1) unstable; urgency=medium * Team upload. diff -Nru r-bioc-scater-1.24.0+ds/debian/control r-bioc-scater-1.26.1+ds/debian/control --- r-bioc-scater-1.24.0+ds/debian/control 2022-05-31 12:56:07.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/debian/control 2022-11-28 07:22:52.000000000 +0000 @@ -31,6 +31,9 @@ r-cran-rtsne, r-cran-rcolorbrewer, r-cran-rcppml, + r-cran-uwot, + r-cran-pheatmap, + r-cran-ggrastr, r-cran-ggrepel Testsuite: autopkgtest-pkg-r diff -Nru r-bioc-scater-1.24.0+ds/debian/salsa-ci.yml r-bioc-scater-1.26.1+ds/debian/salsa-ci.yml --- r-bioc-scater-1.24.0+ds/debian/salsa-ci.yml 2022-05-31 12:56:07.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/debian/salsa-ci.yml 2022-11-28 07:22:52.000000000 +0000 @@ -9,3 +9,7 @@ # Thus reprotest is disabled here variables: SALSA_CI_DISABLE_REPROTEST: 1 + +# Reduce piuparts noise in transitions +piuparts: + allow_failure: true diff -Nru r-bioc-scater-1.24.0+ds/DESCRIPTION r-bioc-scater-1.26.1+ds/DESCRIPTION --- r-bioc-scater-1.24.0+ds/DESCRIPTION 2022-04-26 21:59:46.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/DESCRIPTION 2022-11-13 23:06:23.000000000 +0000 @@ -8,8 +8,8 @@ person("Vladimir", "Kiselev", role=c("ctb"), email="vk6@sanger.ac.uk"), person("Felix G.M.", "Ernst", role=c("ctb"), email="felix.gm.ernst@outlook.com"), person("Alan", "O'Callaghan", role=c("ctb", "cre"), email="alan.ocallaghan@outlook.com")) -Version: 1.24.0 -Date: 2022-02-21 +Version: 1.26.1 +Date: 2022-11-13 License: GPL-3 Title: Single-Cell Analysis Toolkit for Gene Expression Data in R Description: A collection of tools for doing various analyses of @@ -20,9 +20,9 @@ S4Vectors, SummarizedExperiment, DelayedArray, DelayedMatrixStats, beachmat, BiocNeighbors, BiocSingular, BiocParallel, rlang, ggbeeswarm, viridis, Rtsne, RColorBrewer, - RcppML, ggrepel -Suggests: BiocStyle, biomaRt, cowplot, knitr, scRNAseq, robustbase, - rmarkdown, uwot, testthat, pheatmap, snifter, Biobase + RcppML, uwot, pheatmap, ggrastr, ggrepel +Suggests: BiocStyle, snifter, cowplot, biomaRt, knitr, scRNAseq, + robustbase, rmarkdown, testthat, Biobase VignetteBuilder: knitr biocViews: ImmunoOncology, SingleCell, RNASeq, QualityControl, Preprocessing, Normalization, Visualization, @@ -30,16 +30,16 @@ Sequencing, Software, DataImport, DataRepresentation, Infrastructure, Coverage Encoding: UTF-8 -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.1 URL: http://bioconductor.org/packages/scater/ BugReports: https://support.bioconductor.org/ git_url: https://git.bioconductor.org/packages/scater -git_branch: RELEASE_3_15 -git_last_commit: 013f093 -git_last_commit_date: 2022-04-26 -Date/Publication: 2022-04-26 +git_branch: RELEASE_3_16 +git_last_commit: d73b6c0 +git_last_commit_date: 2022-11-13 +Date/Publication: 2022-11-13 NeedsCompilation: no -Packaged: 2022-04-26 21:59:46 UTC; biocbuild +Packaged: 2022-11-13 23:06:23 UTC; biocbuild Author: Davis McCarthy [aut], Kieran Campbell [aut], Aaron Lun [aut, ctb], diff -Nru r-bioc-scater-1.24.0+ds/inst/NEWS.Rd r-bioc-scater-1.26.1+ds/inst/NEWS.Rd --- r-bioc-scater-1.24.0+ds/inst/NEWS.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/inst/NEWS.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -1,6 +1,16 @@ \name{NEWS} \title{News for Package \pkg{scater}} +\section{Changes in version 1.26.0, Bioconductor 3.16 Release}{ + \itemize{ + \item Add \code{projectReducedDim} function to project points into + an existing reduced dimensionality embedding. + \item Support "color" and "colour" spellings in all plotting functions. + \item Add \code{order_by} argument to cellwise plot functions. + \item Add \code{rasterise} argument to \code{plotReducedDim} using + \code{\link[ggrastr]{rasterise}}. + } +} \section{Changes in version 1.24.0, Bioconductor 3.15 Release}{ \itemize{ \item Remove diffusion map functions that relied on destiny. diff -Nru r-bioc-scater-1.24.0+ds/man/ggsce.Rd r-bioc-scater-1.26.1+ds/man/ggsce.Rd --- r-bioc-scater-1.24.0+ds/man/ggsce.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/ggsce.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -37,15 +37,7 @@ \item{features}{Character vector specifying the features for which to extract expression profiles across cells. May also include features in alternative Experiments if permitted by \code{use_altexps}.} -\item{exprs_values}{Soft-deprecated equivalents of the arguments described above.} - -\item{use_dimred}{Soft-deprecated equivalents of the arguments described above.} - -\item{use_altexps}{Soft-deprecated equivalents of the arguments described above.} - -\item{prefix_altexps}{Soft-deprecated equivalents of the arguments described above.} - -\item{check_names}{Soft-deprecated equivalents of the arguments described above.} +\item{exprs_values, use_dimred, use_altexps, prefix_altexps, check_names}{Soft-deprecated equivalents of the arguments described above.} \item{extract_mapping}{Logical scalar indicating whether \code{features} or \code{cells} should be automatically expanded to include variables referenced in \code{mapping}.} @@ -78,7 +70,7 @@ example_sce <- logNormCounts(example_sce) example_sce <- runPCA(example_sce) -ggcells(example_sce, aes(x=PCA.1, y=PCA.2, color=Gene_0001)) + +ggcells(example_sce, aes(x=PCA.1, y=PCA.2, colour=Gene_0001)) + geom_point() ggcells(example_sce, aes(x=Mutation_Status, y=Gene_0001)) + diff -Nru r-bioc-scater-1.24.0+ds/man/plotColData.Rd r-bioc-scater-1.26.1+ds/man/plotColData.Rd --- r-bioc-scater-1.24.0+ds/man/plotColData.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotColData.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -8,12 +8,14 @@ object, y, x = NULL, - colour_by = NULL, + colour_by = color_by, shape_by = NULL, size_by = NULL, + order_by = NULL, by_exprs_values = "logcounts", other_fields = list(), swap_rownames = NULL, + color_by = NULL, ... ) } @@ -33,6 +35,8 @@ \item{size_by}{Specification of a column metadata field or a feature to size by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values.} +\item{order_by}{Specification of a column metadata field or a feature to order points by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values.} + \item{by_exprs_values}{A string or integer scalar specifying which assay to obtain expression values from, for use in point aesthetics - see \code{?\link{retrieveCellInfo}} for details.} @@ -42,6 +46,8 @@ identify features instead of \code{rownames(object)} when labelling plot elements.} +\item{color_by}{Alias to \code{colour_by}.} + \item{...}{Additional arguments for visualization, see \code{?"\link{scater-plot-args}"} for details.} } \value{ diff -Nru r-bioc-scater-1.24.0+ds/man/plotDots.Rd r-bioc-scater-1.26.1+ds/man/plotDots.Rd --- r-bioc-scater-1.24.0+ds/man/plotDots.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotDots.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -12,6 +12,7 @@ exprs_values = "logcounts", detection_limit = 0, zlim = NULL, + colour = color, color = NULL, max_detected = NULL, other_fields = list(), @@ -19,15 +20,15 @@ swap_rownames = NULL, center = FALSE, scale = FALSE, - low_color = NULL, - high_color = NULL, + low_colour = NULL, + high_colour = NULL, max_ave = NULL ) } \arguments{ \item{object}{A \linkS4class{SingleCellExperiment} object.} -\item{features}{A character vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize.} +\item{features}{A character (or factor) vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize. When using character or integer vectors, the ordering specified by the user is retained. When using factor vectors, ordering is controlled by the factor levels.} \item{group}{String specifying the field of \code{\link{colData}(object)} containing the grouping factor, e.g., cell types or clusters. Alternatively, any value that can be used in the \code{by} argument to \code{\link{retrieveCellInfo}}.} @@ -39,14 +40,16 @@ \item{detection_limit}{Numeric scalar providing the value above which observations are deemed to be expressed.} -\item{zlim}{A numeric vector of length 2, specifying the upper and lower bounds for color mapping of expression values. -Values outside this range are set to the most extreme color. +\item{zlim}{A numeric vector of length 2, specifying the upper and lower bounds for colour mapping of expression values. +Values outside this range are set to the most extreme colour. If \code{NULL}, it defaults to the range of the expression matrix. If \code{center=TRUE}, this defaults to the range of the centered expression matrix, made symmetric around zero.} -\item{color}{A vector of colours specifying the palette to use for increasing expression. +\item{colour}{A vector of colours specifying the palette to use for increasing expression. This defaults to \link[viridis]{viridis} if \code{center=FALSE}, and the the \code{"RdYlBu"} -color palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise.} +colour palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise.} + +\item{color}{Alias to \code{colour}.} \item{max_detected}{Numeric value specifying the cap on the proportion of detected expression values.} @@ -66,14 +69,14 @@ \item{scale}{A logical scalar specifying whether each row should have its average expression values scaled to unit variance prior to plotting.} -\item{low_color, high_color, max_ave}{Deprecated arguments.} +\item{low_colour, high_colour, max_ave}{Deprecated arguments.} } \value{ A \link{ggplot} object containing a dot plot. } \description{ Create a dot plot of expression values for a grouping of cells, -where the size and color of each dot represents the proportion of detected expression values and the average expression, +where the size and colour of each dot represents the proportion of detected expression values and the average expression, respectively, for each feature in each group of cells. } \details{ @@ -81,13 +84,13 @@ The proportion of detected expression values and the average expression for each feature in each group of cells is visualized efficiently using the size and colour, respectively, of each dot. If \code{block} is specified, batch-corrected averages for each group are computed with \code{\link{correctGroupSummary}}. -Some caution is required during interpretation due to the difficulty of simultaneously interpreting both size and color. -For example, if we colored by z-score on a conventional blue-white-red color axis, a gene that is downregulated in a group of cells would show up as a small blue dot. -If the background color was also white, this could be easily mistaken for a gene that is not downregulated at all. -We suggest choosing a color scale that remains distinguishable from the background color at all points. -Admittedly, that is easier said than done as many color scales will approach a lighter color at some stage, so some magnifying glasses may be required. +Some caution is required during interpretation due to the difficulty of simultaneously interpreting both size and colour. +For example, if we coloured by z-score on a conventional blue-white-red colour axis, a gene that is downregulated in a group of cells would show up as a small blue dot. +If the background colour was also white, this could be easily mistaken for a gene that is not downregulated at all. +We suggest choosing a colour scale that remains distinguishable from the background colour at all points. +Admittedly, that is easier said than done as many colour scales will approach a lighter colour at some stage, so some magnifying glasses may be required. -We can also cap the color and size scales using \code{zlim} and \code{max_detected}, respectively. +We can also cap the colour and size scales using \code{zlim} and \code{max_detected}, respectively. This aims to preserve resolution for low-abundance genes by preventing domination of the scales by high-abundance features. } \examples{ diff -Nru r-bioc-scater-1.24.0+ds/man/plotExpression.Rd r-bioc-scater-1.26.1+ds/man/plotExpression.Rd --- r-bioc-scater-1.24.0+ds/man/plotExpression.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotExpression.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -10,17 +10,20 @@ x = NULL, exprs_values = "logcounts", log2_values = FALSE, - colour_by = NULL, + colour_by = color_by, shape_by = NULL, size_by = NULL, + order_by = NULL, by_exprs_values = exprs_values, xlab = NULL, - feature_colours = TRUE, + feature_colours = feature_colors, one_facet = TRUE, ncol = 2, scales = "fixed", other_fields = list(), swap_rownames = NULL, + color_by = NULL, + feature_colors = TRUE, ... ) } @@ -42,6 +45,8 @@ \item{size_by}{Specification of a column metadata field or a feature to size by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values.} +\item{order_by}{Specification of a column metadata field or a feature to order points by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values.} + \item{by_exprs_values}{A string or integer scalar specifying which assay to obtain expression values from, for use in point aesthetics - see the \code{exprs_values} argument in \code{?\link{retrieveCellInfo}}.} @@ -64,6 +69,10 @@ identify features instead of \code{rownames(object)} when labelling plot elements.} +\item{color_by}{Alias to \code{colour_by}.} + +\item{feature_colors}{Alias to \code{feature_colours}.} + \item{...}{Additional arguments for visualization, see \code{?"\link{scater-plot-args}"} for details.} } \value{ diff -Nru r-bioc-scater-1.24.0+ds/man/plotGroupedHeatmap.Rd r-bioc-scater-1.26.1+ds/man/plotGroupedHeatmap.Rd --- r-bioc-scater-1.24.0+ds/man/plotGroupedHeatmap.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotGroupedHeatmap.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -14,16 +14,17 @@ center = FALSE, scale = FALSE, zlim = NULL, - color = NULL, + colour = color, swap_rownames = NULL, symmetric = NULL, + color = NULL, ... ) } \arguments{ \item{object}{A \linkS4class{SingleCellExperiment} object.} -\item{features}{A character vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize.} +\item{features}{A character (or factor) vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize. When using character or integer vectors, the ordering specified by the user is retained. When using factor vectors, ordering is controlled by the factor levels.} \item{group}{String specifying the field of \code{\link{colData}(object)} containing the grouping factor, e.g., cell types or clusters. Alternatively, any value that can be used in the \code{by} argument to \code{\link{retrieveCellInfo}}.} @@ -41,14 +42,14 @@ \item{scale}{A logical scalar specifying whether each row should have its average expression values scaled to unit variance prior to plotting.} -\item{zlim}{A numeric vector of length 2, specifying the upper and lower bounds for color mapping of expression values. -Values outside this range are set to the most extreme color. +\item{zlim}{A numeric vector of length 2, specifying the upper and lower bounds for colour mapping of expression values. +Values outside this range are set to the most extreme colour. If \code{NULL}, it defaults to the range of the expression matrix. If \code{center=TRUE}, this defaults to the range of the centered expression matrix, made symmetric around zero.} -\item{color}{A vector of colours specifying the palette to use for increasing expression. +\item{colour}{A vector of colours specifying the palette to use for increasing expression. This defaults to \link[viridis]{viridis} if \code{center=FALSE}, and the the \code{"RdYlBu"} -color palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise.} +colour palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise.} \item{swap_rownames}{Column name of \code{rowData(object)} to be used to identify features instead of \code{rownames(object)} when labelling plot @@ -56,6 +57,8 @@ \item{symmetric}{Deprecated and ignored.} +\item{color}{Alias to \code{colour}.} + \item{...}{Additional arguments to pass to \code{\link[pheatmap]{pheatmap}}.} } \value{ diff -Nru r-bioc-scater-1.24.0+ds/man/plotHeatmap.Rd r-bioc-scater-1.26.1+ds/man/plotHeatmap.Rd --- r-bioc-scater-1.24.0+ds/man/plotHeatmap.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotHeatmap.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -12,24 +12,29 @@ center = FALSE, scale = FALSE, zlim = NULL, - color = NULL, - color_columns_by = NULL, - column_annotation_colors = list(), - color_rows_by = NULL, - row_annotation_colors = list(), + colour = color, + colour_columns_by = color_columns_by, + column_annotation_colours = column_annotation_colors, + colour_rows_by = color_rows_by, + row_annotation_colours = row_annotation_colors, order_columns_by = NULL, by_exprs_values = exprs_values, show_colnames = FALSE, cluster_cols = is.null(order_columns_by), swap_rownames = NULL, symmetric = NULL, + color = NULL, + color_columns_by = NULL, + color_rows_by = NULL, + column_annotation_colors = list(), + row_annotation_colors = list(), ... ) } \arguments{ \item{object}{A \linkS4class{SingleCellExperiment} object.} -\item{features}{A character vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize.} +\item{features}{A character (or factor) vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize. When using character or integer vectors, the ordering specified by the user is retained. When using factor vectors, ordering is controlled by the factor levels.} \item{columns}{A vector specifying the subset of columns in \code{object} to show as columns in the heatmap. Also specifies the column order if \code{cluster_cols=FALSE} and \code{order_columns_by=NULL}. @@ -41,38 +46,38 @@ \item{scale}{A logical scalar specifying whether each feature should have its expression values scaled to have unit variance prior to plotting.} -\item{zlim}{A numeric vector of length 2, specifying the upper and lower bounds for color mapping of expression values. -Values outside this range are set to the most extreme color. +\item{zlim}{A numeric vector of length 2, specifying the upper and lower bounds for colour mapping of expression values. +Values outside this range are set to the most extreme colour. If \code{NULL}, it defaults to the range of the expression matrix. If \code{center=TRUE}, this defaults to the range of the centered expression matrix, made symmetric around zero.} -\item{color}{A vector of colours specifying the palette to use for increasing expression. +\item{colour}{A vector of colours specifying the palette to use for increasing expression. This defaults to \link[viridis]{viridis} if \code{center=FALSE}, and the the \code{"RdYlBu"} -color palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise.} +colour palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise.} -\item{color_columns_by}{A list of values specifying how the columns should be annotated with colours. +\item{colour_columns_by}{A list of values specifying how the columns should be annotated with colours. Each entry of the list can be any acceptable input to the \code{by} argument in \code{?\link{retrieveCellInfo}}. A character vector can also be supplied and will be treated as a list of strings.} -\item{column_annotation_colors}{A named list of color scales to be used for -the column annotations specified in \code{color_columns_by}. Names -should be character values present in \code{color_columns_by}, -If a color scale is not specified for a particular annotation, a default -color scale is chosen. +\item{column_annotation_colours}{A named list of colour scales to be used for +the column annotations specified in \code{colour_columns_by}. Names +should be character values present in \code{colour_columns_by}, +If a colour scale is not specified for a particular annotation, a default +colour scale is chosen. The full list of colour maps is passed to \code{\link[pheatmap]{pheatmap}} as the \code{annotation_colours} argument.} -\item{color_rows_by}{Similar to \code{color_columns_by} but for rows rather +\item{colour_rows_by}{Similar to \code{colour_columns_by} but for rows rather than columns. Each entry of the list can be any acceptable input to the \code{by} argument in \code{?\link{retrieveFeatureInfo}}.} -\item{row_annotation_colors}{Similar to \code{column_annotation_colors} but +\item{row_annotation_colours}{Similar to \code{column_annotation_colours} but relating to row annotation rather than column annotation.} \item{order_columns_by}{A list of values specifying how the columns should be ordered. Each entry of the list can be any acceptable input to the \code{by} argument in \code{?\link{retrieveCellInfo}}. A character vector can also be supplied and will be treated as a list of strings. -This argument is automatically appended to \code{color_columns_by}.} +This argument is automatically appended to \code{colour_columns_by}.} \item{by_exprs_values}{A string or integer scalar specifying which assay to obtain expression values from, for colouring of column-level data - see the \code{exprs_values} argument in \code{?\link{retrieveCellInfo}}.} @@ -84,6 +89,10 @@ elements.} \item{symmetric}{Deprecated and ignored.} + +\item{color, color_columns_by, column_annotation_colors, color_rows_by, row_annotation_colors}{Aliases to \code{color}, \code{color_columns_by}, +\code{column_annotation_colors}, \code{color_rows_by}, +\code{row_annotation_colors}.} } \value{ A heatmap is produced on the current graphics device. @@ -100,7 +109,7 @@ Otherwise, the plot may be dominated by a few genes, which will \dQuote{flatten} the observed colours for the rest of the heatmap. Setting \code{order_columns_by} is useful for automatically ordering the heatmap by one or more factors of interest, e.g., cluster identity. -This avoids the need to set \code{color_columns_by}, \code{cluster_cols} and \code{columns} to achieve the same effect. +This avoids the need to set \code{colour_columns_by}, \code{cluster_cols} and \code{columns} to achieve the same effect. } \examples{ example_sce <- mockSCE() @@ -112,7 +121,7 @@ center=TRUE) plotHeatmap(example_sce, features=rownames(example_sce)[1:10], - color_columns_by=c("Mutation_Status", "Cell_Cycle")) + colour_columns_by=c("Mutation_Status", "Cell_Cycle")) } \seealso{ diff -Nru r-bioc-scater-1.24.0+ds/man/plotHighestExprs.Rd r-bioc-scater-1.26.1+ds/man/plotHighestExprs.Rd --- r-bioc-scater-1.24.0+ds/man/plotHighestExprs.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotHighestExprs.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -7,13 +7,14 @@ plotHighestExprs( object, n = 50, - colour_cells_by = NULL, + colour_cells_by = color_cells_by, drop_features = NULL, exprs_values = "counts", by_exprs_values = exprs_values, feature_names_to_plot = NULL, as_percentage = TRUE, - swap_rownames = NULL + swap_rownames = NULL, + color_cells_by = NULL ) } \arguments{ @@ -41,6 +42,8 @@ \item{swap_rownames}{Column name of \code{rowData(object)} to be used to identify features instead of \code{rownames(object)} when labelling plot elements.} + +\item{color_cells_by}{Alias to \code{colour_cells_by}.} } \value{ A \link{ggplot} object. diff -Nru r-bioc-scater-1.24.0+ds/man/plotPlatePosition.Rd r-bioc-scater-1.26.1+ds/man/plotPlatePosition.Rd --- r-bioc-scater-1.24.0+ds/man/plotPlatePosition.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotPlatePosition.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -7,16 +7,18 @@ plotPlatePosition( object, plate_position = NULL, - colour_by = NULL, + colour_by = color_by, size_by = NULL, shape_by = NULL, + order_by = NULL, by_exprs_values = "logcounts", add_legend = TRUE, theme_size = 24, point_alpha = 0.6, point_size = 24, other_fields = list(), - swap_rownames = NULL + swap_rownames = NULL, + color_by = NULL ) } \arguments{ @@ -32,6 +34,8 @@ \item{shape_by}{Specification of a column metadata field or a feature to shape by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values.} +\item{order_by}{Specification of a column metadata field or a feature to order points by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values.} + \item{by_exprs_values}{A string or integer scalar specifying which assay to obtain expression values from, for use in point aesthetics - see the \code{exprs_values} argument in \code{?\link{retrieveCellInfo}}.} @@ -48,6 +52,8 @@ \item{swap_rownames}{Column name of \code{rowData(object)} to be used to identify features instead of \code{rownames(object)} when labelling plot elements.} + +\item{color_by}{Alias to \code{colour_by}.} } \value{ A ggplot object. diff -Nru r-bioc-scater-1.24.0+ds/man/plotReducedDim.Rd r-bioc-scater-1.26.1+ds/man/plotReducedDim.Rd --- r-bioc-scater-1.24.0+ds/man/plotReducedDim.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotReducedDim.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -9,18 +9,22 @@ dimred, ncomponents = 2, percentVar = NULL, - colour_by = NULL, + colour_by = color_by, shape_by = NULL, size_by = NULL, + order_by = NULL, by_exprs_values = "logcounts", text_by = NULL, text_size = 5, - text_colour = "black", + text_colour = text_color, label_format = c("\%s \%i", " (\%i\%\%)"), other_fields = list(), + text_color = "black", + color_by = NULL, swap_rownames = NULL, point.padding = NA, force = 1, + rasterise = FALSE, ... ) } @@ -51,6 +55,10 @@ size by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values.} +\item{order_by}{Specification of a column metadata field or a feature to +order points by, see the \code{by} argument in +\code{?\link{retrieveCellInfo}} for possible values.} + \item{by_exprs_values}{A string or integer scalar specifying which assay to obtain expression values from, for use in point aesthetics - see the \code{exprs_values} argument in @@ -76,12 +84,21 @@ \item{other_fields}{Additional cell-based fields to include in the data.frame, see \code{?"\link{scater-plot-args}"} for details.} +\item{text_color}{Alias to \code{text_colour}.} + +\item{color_by}{Alias to \code{colour_by}.} + \item{swap_rownames}{Column name of \code{rowData(object)} to be used to identify features instead of \code{rownames(object)} when labelling plot elements.} \item{point.padding, force}{See \code{?ggrepel::geom_text_repel}.} +\item{rasterise}{Whether to rasterise the points in the plot with +\code{\link[ggrastr]{rasterise}}. To control the dpi, set +\code{options(ggrastr.default.dpi)}, +for example \code{options(ggrastr.default.dpi=300)}.} + \item{...}{Additional arguments for visualization, see \code{?"\link{scater-plot-args}"} for details.} } diff -Nru r-bioc-scater-1.24.0+ds/man/plotRLE.Rd r-bioc-scater-1.26.1+ds/man/plotRLE.Rd --- r-bioc-scater-1.24.0+ds/man/plotRLE.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotRLE.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -12,9 +12,10 @@ style = "minimal", legend = TRUE, ordering = NULL, - colour_by = NULL, + colour_by = color_by, by_exprs_values = exprs_values, BPPARAM = BiocParallel::bpparam(), + color_by = NULL, ... ) } @@ -40,6 +41,8 @@ \item{BPPARAM}{A \linkS4class{BiocParallelParam} object to be used to parallelise operations using \code{\link{DelayedArray}}.} +\item{color_by}{Alias to \code{colour_by}.} + \item{...}{further arguments passed to \code{\link[ggplot2]{geom_boxplot}} when \code{style="full"}.} } \value{ diff -Nru r-bioc-scater-1.24.0+ds/man/plotRowData.Rd r-bioc-scater-1.26.1+ds/man/plotRowData.Rd --- r-bioc-scater-1.24.0+ds/man/plotRowData.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotRowData.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -8,11 +8,12 @@ object, y, x = NULL, - colour_by = NULL, + colour_by = color_by, shape_by = NULL, size_by = NULL, by_exprs_values = "logcounts", other_fields = list(), + color_by = NULL, ... ) } @@ -37,6 +38,8 @@ \item{other_fields}{Additional feature-based fields to include in the data.frame, see \code{?"\link{scater-plot-args}"} for details.} +\item{color_by}{Alias to \code{colour_by}.} + \item{...}{Additional arguments for visualization, see \code{?"\link{scater-plot-args}"} for details.} } \value{ diff -Nru r-bioc-scater-1.24.0+ds/man/plotScater.Rd r-bioc-scater-1.26.1+ds/man/plotScater.Rd --- r-bioc-scater-1.24.0+ds/man/plotScater.Rd 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/plotScater.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -8,13 +8,14 @@ x, nfeatures = 500, exprs_values = "counts", - colour_by = NULL, + colour_by = color_by, by_exprs_values = exprs_values, block1 = NULL, block2 = NULL, ncol = 3, line_width = 1.5, - theme_size = 10 + theme_size = 10, + color_by = NULL ) } \arguments{ @@ -41,6 +42,8 @@ \item{line_width}{Numeric scalar specifying the line width.} \item{theme_size}{Numeric scalar specifying the font size to use for the plotting theme.} + +\item{color_by}{Alias to \code{colour_by}.} } \value{ A \link{ggplot} object. diff -Nru r-bioc-scater-1.24.0+ds/man/projectReducedDim.Rd r-bioc-scater-1.26.1+ds/man/projectReducedDim.Rd --- r-bioc-scater-1.24.0+ds/man/projectReducedDim.Rd 1970-01-01 00:00:00.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/man/projectReducedDim.Rd 2022-11-01 18:57:52.000000000 +0000 @@ -0,0 +1,74 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AllGenerics.R, R/projectReducedDim.R +\name{projectReducedDim} +\alias{projectReducedDim} +\alias{projectReducedDim,matrix-method} +\alias{projectReducedDim,SummarizedExperiment-method} +\title{Project cells into an arbitrary dimensionality reduction space.} +\usage{ +projectReducedDim(x, ...) + +\S4method{projectReducedDim}{matrix}(x, old.embedding, ...) + +\S4method{projectReducedDim}{SummarizedExperiment}( + x, + old.sce, + dimred.embed = "TSNE", + dimred.knn = "PCA", + dimred.name = dimred.embed, + k = 5 +) +} +\arguments{ +\item{x}{A numeric matrix of a dimensionality reduction containing the cells that should be projected into the existing embedding defined in either \code{old.embedding} or \code{old.sce}. +Alternatively, a \linkS4class{SummarizedExperiment} or \linkS4class{SingleCellExperiment} containing such a matrix.} + +\item{...}{Passed to methods.} + +\item{old.embedding}{If \code{x} is a matrix and \code{old} is given, then \code{old.embedding} is the existing dimensionality reduction embedding that \code{x} should be projected into.} + +\item{old.sce}{The object containing the original dimensionality points. If \code{x} is a matrix, then \code{old.points} must be supplied as a matrix of} + +\item{dimred.embed}{The name of the target dimensionality reduction that points should be embedded into, if \code{}.} + +\item{dimred.knn}{The name of the dimensionality reduction to use to identify the K-nearest neighbours from \code{x} in the dimensionality reduction slot of the same name defined in either \code{old} or \code{old.sce}.} + +\item{dimred.name}{The name of the dimensionality reduction that the projected embedding will be saved as, for the \linkS4class{SummarizedExperiment} method.} + +\item{k}{The number of nearest neighours to use to project points into the embedding.} +} +\value{ +When \code{x} is a matrix, a matrix is returned. When \code{x} is a +\code{\linkS4class{SummarizedExperiment}} +(or \code{\linkS4class{SingleCellExperiment}}), the return value is of +the same class as the input, but the projected dimensionality reduction +is added as a \code{reducedDim} field. +} +\description{ +Projects observations into arbitrary dimensionality reduction space (e.g., t-SNE, UMAP) using a tricube weighted average of the k nearest neighbours. +} +\examples{ +example_sce <- mockSCE() +example_sce <- logNormCounts(example_sce) +example_sce <- runUMAP(example_sce) +example_sce <- runPCA(example_sce) + +example_sce_new <- mockSCE() +example_sce_new <- logNormCounts(example_sce_new) +example_sce_new <- runPCA(example_sce_new) + +## sce method +projectReducedDim( + example_sce_new, + old.sce = example_sce, + dimred.embed="UMAP", + dimred.knn="PCA" +) + +## matrix method +projectReducedDim( + reducedDim(example_sce, "PCA"), + new.points = reducedDim(example_sce_new, "PCA"), + old.embedding = reducedDim(example_sce, "UMAP") +) +} diff -Nru r-bioc-scater-1.24.0+ds/NAMESPACE r-bioc-scater-1.26.1+ds/NAMESPACE --- r-bioc-scater-1.24.0+ds/NAMESPACE 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/NAMESPACE 2022-11-01 18:57:52.000000000 +0000 @@ -65,6 +65,7 @@ export(plotScater) export(plotTSNE) export(plotUMAP) +export(projectReducedDim) export(quickPerCellQC) export(readSparseCounts) export(retrieveCellInfo) @@ -95,6 +96,7 @@ exportMethods(nexprs) exportMethods(normalize) exportMethods(plotPCA) +exportMethods(projectReducedDim) exportMethods(runPCA) import(SingleCellExperiment) import(methods) @@ -183,10 +185,10 @@ importFrom(ggplot2,guide_legend) importFrom(ggplot2,guides) importFrom(ggplot2,position_jitter) -importFrom(ggplot2,scale_color_gradient) -importFrom(ggplot2,scale_color_gradient2) -importFrom(ggplot2,scale_color_gradientn) -importFrom(ggplot2,scale_color_manual) +importFrom(ggplot2,scale_colour_gradient) +importFrom(ggplot2,scale_colour_gradient2) +importFrom(ggplot2,scale_colour_gradientn) +importFrom(ggplot2,scale_colour_manual) importFrom(ggplot2,scale_fill_manual) importFrom(ggplot2,scale_size) importFrom(ggplot2,scale_x_log10) @@ -215,7 +217,7 @@ importFrom(stats,model.matrix) importFrom(stats,runif) importFrom(utils,head) -importFrom(viridis,scale_color_viridis) +importFrom(viridis,scale_colour_viridis) importFrom(viridis,scale_fill_viridis) importFrom(viridis,viridis) importMethodsFrom(DelayedArray,sweep) diff -Nru r-bioc-scater-1.24.0+ds/R/AllGenerics.R r-bioc-scater-1.26.1+ds/R/AllGenerics.R --- r-bioc-scater-1.24.0+ds/R/AllGenerics.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/AllGenerics.R 2022-11-01 18:57:52.000000000 +0000 @@ -77,3 +77,7 @@ #' @export #' @rdname runNMF setGeneric("calculateNMF", function(x, ...) standardGeneric("calculateNMF")) + +#' @export +#' @rdname projectReducedDim +setGeneric("projectReducedDim", function(x, ...) standardGeneric("projectReducedDim")) diff -Nru r-bioc-scater-1.24.0+ds/R/ggsce.R r-bioc-scater-1.26.1+ds/R/ggsce.R --- r-bioc-scater-1.24.0+ds/R/ggsce.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/ggsce.R 2022-11-01 18:57:52.000000000 +0000 @@ -1,4 +1,4 @@ -#' Create a ggplot from a SingleCellExperiment +4#' Create a ggplot from a SingleCellExperiment #' #' Create a base \link{ggplot} object from a \linkS4class{SingleCellExperiment}, #' the contents of which can be directly referenced in subsequent layers without prior specification. @@ -37,7 +37,7 @@ #' example_sce <- logNormCounts(example_sce) #' example_sce <- runPCA(example_sce) #' -#' ggcells(example_sce, aes(x=PCA.1, y=PCA.2, color=Gene_0001)) + +#' ggcells(example_sce, aes(x=PCA.1, y=PCA.2, colour=Gene_0001)) + #' geom_point() #' #' ggcells(example_sce, aes(x=Mutation_Status, y=Gene_0001)) + diff -Nru r-bioc-scater-1.24.0+ds/R/plot_central.R r-bioc-scater-1.26.1+ds/R/plot_central.R --- r-bioc-scater-1.24.0+ds/R/plot_central.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plot_central.R 2022-11-01 18:57:52.000000000 +0000 @@ -58,7 +58,8 @@ colour_by = NULL, shape_by = NULL, size_by = NULL, fill_by = NULL, show_median = FALSE, show_violin = TRUE, show_smooth = FALSE, show_se = TRUE, theme_size = 10, point_alpha = 0.6, point_size = NULL, add_legend = TRUE, - point_FUN = NULL, jitter_type = "swarm") + point_FUN = NULL, jitter_type = "swarm", + rasterise = FALSE) # Internal ggplot-creating function to plot anything that involves points. # Creates either a scatter plot, (horizontal) violin plots, or a rectangle plot. { @@ -154,7 +155,7 @@ # Creating the plot: plot_out <- ggplot(object, aes_string(x="X", y="Y")) + xlab(xlab) + ylab(ylab) plot_out <- plot_out + geom_tile(aes_string(x = "X", y = "Y", height = "2*YWidth", width = "2*XWidth"), - data=summary.data, color = 'grey60', size = 0.5, fill='grey90') + data=summary.data, colour = 'grey60', size = 0.5, fill='grey90') # Adding points. point_out <- .get_point_args(colour_by, shape_by, size_by, alpha = point_alpha, size = point_size) @@ -181,7 +182,9 @@ if (!add_legend) { plot_out <- plot_out + theme(legend.position = "none") } - + if (rasterise) { + plot_out <- ggrastr::rasterise(plot_out) + } plot_out } diff -Nru r-bioc-scater-1.24.0+ds/R/plotColData.R r-bioc-scater-1.26.1+ds/R/plotColData.R --- r-bioc-scater-1.24.0+ds/R/plotColData.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotColData.R 2022-11-01 18:57:52.000000000 +0000 @@ -11,12 +11,14 @@ #' @param colour_by Specification of a column metadata field or a feature to colour by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param shape_by Specification of a column metadata field or a feature to shape by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param size_by Specification of a column metadata field or a feature to size by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. +#' @param order_by Specification of a column metadata field or a feature to order points by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param by_exprs_values A string or integer scalar specifying which assay to obtain expression values from, #' for use in point aesthetics - see \code{?\link{retrieveCellInfo}} for details. #' @param other_fields Additional cell-based fields to include in the data.frame, see \code{?"\link{scater-plot-args}"} for details. #' @param swap_rownames Column name of \code{rowData(object)} to be used to #' identify features instead of \code{rownames(object)} when labelling plot #' elements. +#' @param color_by Alias to \code{colour_by}. #' @param ... Additional arguments for visualization, see \code{?"\link{scater-plot-args}"} for details. #' #' @details @@ -52,9 +54,9 @@ #' #' @export plotColData <- function(object, y, x = NULL, - colour_by = NULL, shape_by = NULL, size_by = NULL, + colour_by = color_by, shape_by = NULL, size_by = NULL, order_by = NULL, by_exprs_values = "logcounts", other_fields=list(), - swap_rownames = NULL, ...) + swap_rownames = NULL, color_by = NULL, ...) { if (!is(object, "SingleCellExperiment")) { stop("object must be an SingleCellExperiment object.") @@ -84,6 +86,7 @@ vis_out <- .incorporate_common_vis_col(df_to_plot, se = object, colour_by = colour_by, shape_by = shape_by, size_by = size_by, by_exprs_values = by_exprs_values, other_fields = other_fields, + order_by = order_by, swap_rownames = swap_rownames) df_to_plot <- vis_out$df diff -Nru r-bioc-scater-1.24.0+ds/R/plot_colours.R r-bioc-scater-1.26.1+ds/R/plot_colours.R --- r-bioc-scater-1.24.0+ds/R/plot_colours.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plot_colours.R 2022-11-01 18:57:52.000000000 +0000 @@ -1,5 +1,5 @@ .get_palette <- function(palette_name) -# Function to define color palettes. +# Function to define colour palettes. { switch(palette_name, tableau20 = c("#1F77B4", "#AEC7E8", "#FF7F0E", "#FFBB78", "#2CA02C", @@ -12,6 +12,9 @@ colorblind10 = c("#006BA4", "#FF800E", "#ABABAB", "#595959", "#5F9ED1", "#C85200", "#898989", "#A2C8EC", "#FFBC79", "#CFCFCF"), + colourblind10 = c("#006BA4", "#FF800E", "#ABABAB", "#595959", + "#5F9ED1", "#C85200", "#898989", "#A2C8EC", + "#FFBC79", "#CFCFCF"), trafficlight = c("#B10318", "#DBA13A", "#309343", "#D82526", "#FFC156", "#69B764", "#F26C64", "#FFDD71", "#9FCD99"), @@ -31,8 +34,8 @@ ) } -#' @importFrom ggplot2 scale_fill_manual scale_color_manual -#' @importFrom viridis scale_fill_viridis scale_color_viridis +#' @importFrom ggplot2 scale_fill_manual scale_colour_manual +#' @importFrom viridis scale_fill_viridis scale_colour_viridis .resolve_plot_colours <- function(plot_out, colour_by, colour_by_name, fill = FALSE) # Get nice plotting colour schemes for very general colour variables { @@ -45,8 +48,8 @@ VIRIDFUN <- scale_fill_viridis SCALEFUN <- scale_fill_manual } else { - VIRIDFUN <- scale_color_viridis - SCALEFUN <- scale_color_manual + VIRIDFUN <- scale_colour_viridis + SCALEFUN <- scale_colour_manual } # Set a sensible colour scheme and return the plot_out object diff -Nru r-bioc-scater-1.24.0+ds/R/plotDots.R r-bioc-scater-1.26.1+ds/R/plotDots.R --- r-bioc-scater-1.24.0+ds/R/plotDots.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotDots.R 2022-11-01 18:57:52.000000000 +0000 @@ -1,7 +1,7 @@ #' Create a dot plot of expression values #' #' Create a dot plot of expression values for a grouping of cells, -#' where the size and color of each dot represents the proportion of detected expression values and the average expression, +#' where the size and colour of each dot represents the proportion of detected expression values and the average expression, #' respectively, for each feature in each group of cells. #' #' @inheritParams plotGroupedHeatmap @@ -11,7 +11,7 @@ #' @param other_fields Additional feature-based fields to include in the data.frame, see \code{?"\link{scater-plot-args}"} for details. #' Note that any \link{AsIs} vectors or data.frames must be of length equal to \code{nrow(object)}, not \code{features}. #' @param by_exprs_values A string or integer scalar specifying which assay to obtain expression values from, for entries of \code{other_fields}. -#' @param low_color,high_color,max_ave Deprecated arguments. +#' @param low_colour,high_colour,max_ave Deprecated arguments. #' #' @return #' A \link{ggplot} object containing a dot plot. @@ -21,13 +21,13 @@ #' The proportion of detected expression values and the average expression for each feature in each group of cells is visualized efficiently using the size and colour, respectively, of each dot. #' If \code{block} is specified, batch-corrected averages for each group are computed with \code{\link{correctGroupSummary}}. #' -#' Some caution is required during interpretation due to the difficulty of simultaneously interpreting both size and color. -#' For example, if we colored by z-score on a conventional blue-white-red color axis, a gene that is downregulated in a group of cells would show up as a small blue dot. -#' If the background color was also white, this could be easily mistaken for a gene that is not downregulated at all. -#' We suggest choosing a color scale that remains distinguishable from the background color at all points. -#' Admittedly, that is easier said than done as many color scales will approach a lighter color at some stage, so some magnifying glasses may be required. +#' Some caution is required during interpretation due to the difficulty of simultaneously interpreting both size and colour. +#' For example, if we coloured by z-score on a conventional blue-white-red colour axis, a gene that is downregulated in a group of cells would show up as a small blue dot. +#' If the background colour was also white, this could be easily mistaken for a gene that is not downregulated at all. +#' We suggest choosing a colour scale that remains distinguishable from the background colour at all points. +#' Admittedly, that is easier said than done as many colour scales will approach a lighter colour at some stage, so some magnifying glasses may be required. #' -#' We can also cap the color and size scales using \code{zlim} and \code{max_detected}, respectively. +#' We can also cap the colour and size scales using \code{zlim} and \code{max_detected}, respectively. #' This aims to preserve resolution for low-abundance genes by preventing domination of the scales by high-abundance features. #' #' @author Aaron Lun @@ -49,22 +49,23 @@ #' #' @export #' @importFrom ggplot2 ggplot aes_string geom_point -#' scale_size scale_color_gradient theme element_line element_rect -#' scale_color_gradient2 +#' scale_size scale_colour_gradient theme element_line element_rect +#' scale_colour_gradient2 #' @importFrom SummarizedExperiment assay #' @importFrom scuttle summarizeAssayByGroup plotDots <- function(object, features, group = NULL, block=NULL, - exprs_values = "logcounts", detection_limit = 0, zlim = NULL, color = NULL, + exprs_values = "logcounts", detection_limit = 0, zlim = NULL, + colour = color, color = NULL, max_detected = NULL, other_fields = list(), by_exprs_values = exprs_values, swap_rownames = NULL, center = FALSE, scale = FALSE, - low_color = NULL, high_color = NULL, max_ave = NULL) + low_colour = NULL, high_colour = NULL, max_ave = NULL) { # Handling all the deprecation. - if (!is.null(low_color)) { - .Deprecated(msg="'low_color=' is deprecated, use 'color=' instead") + if (!is.null(low_colour)) { + .Deprecated(msg="'low_colour=' is deprecated, use 'colour=' instead") } - if (!is.null(high_color)) { - .Deprecated(msg="'high_color=' is deprecated, use 'color=' instead") + if (!is.null(high_colour)) { + .Deprecated(msg="'high_colour=' is deprecated, use 'colour=' instead") } if (!is.null(max_ave)) { .Deprecated(msg="'max_ave=' is deprecated, use 'zlim=' instead") @@ -77,7 +78,8 @@ group <- retrieveCellInfo(object, group, search="colData")$value } - feature_names <- .swap_rownames(object, features, swap_rownames) + object <- .swap_rownames(object, swap_rownames) + features <- .handle_features(features, object) group <- factor(group) # Computing, possibly also batch correcting. @@ -86,10 +88,11 @@ ids$block <- retrieveCellInfo(object, block, search="colData")$value } - summarized <- summarizeAssayByGroup(assay(object, exprs_values), - ids=ids, subset.row=feature_names, - statistics=c("mean", "prop.detected"), threshold=detection_limit) - + summarized <- summarizeAssayByGroup( + assay(object, exprs_values)[as.character(features), , drop = FALSE], + ids=ids, statistics=c("mean", "prop.detected"), + threshold=detection_limit) + ave <- assay(summarized, "mean") num <- assay(summarized, "prop.detected") group.names <- summarized$group @@ -99,7 +102,7 @@ num <- correctGroupSummary(num, group=summarized$group, block=summarized$block, transform="logit") group.names <- colnames(ave) } - heatmap_scale <- .heatmap_scale(ave, center=center, scale=scale, color=color, zlim=zlim) + heatmap_scale <- .heatmap_scale(ave, center=center, scale=scale, colour=colour, zlim=zlim) # Creating a long-form table. evals_long <- data.frame( @@ -116,12 +119,12 @@ vis_out <- .incorporate_common_vis_row(evals_long, se = object, colour_by = NULL, shape_by = NULL, size_by = NULL, by_exprs_values = by_exprs_values, other_fields = other_fields, - multiplier = rep(.subset2index(feature_names, object), ncol(num))) + multiplier = rep(.subset2index(features, object), ncol(num))) evals_long <- vis_out$df ggplot(evals_long) + geom_point(aes_string(x="Group", y="Feature", size="NumDetected", col="Average")) + scale_size(limits=c(0, max(evals_long$NumDetected))) + - heatmap_scale$color_scale + + heatmap_scale$colour_scale + theme( panel.background = element_rect(fill = "white"), panel.grid.major = element_line(size=0.5, colour = "grey80"), diff -Nru r-bioc-scater-1.24.0+ds/R/plotExpression.R r-bioc-scater-1.26.1+ds/R/plotExpression.R --- r-bioc-scater-1.24.0+ds/R/plotExpression.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotExpression.R 2022-11-01 18:57:52.000000000 +0000 @@ -11,6 +11,7 @@ #' @param colour_by Specification of a column metadata field or a feature to colour by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param shape_by Specification of a column metadata field or a feature to shape by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param size_by Specification of a column metadata field or a feature to size by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. +#' @param order_by Specification of a column metadata field or a feature to order points by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param by_exprs_values A string or integer scalar specifying which assay to obtain expression values from, #' for use in point aesthetics - see the \code{exprs_values} argument in \code{?\link{retrieveCellInfo}}. #' @param xlab String specifying the label for x-axis. @@ -25,6 +26,8 @@ #' @param swap_rownames Column name of \code{rowData(object)} to be used to #' identify features instead of \code{rownames(object)} when labelling plot #' elements. +#' @param color_by Alias to \code{colour_by}. +#' @param feature_colors Alias to \code{feature_colours}. #' @param ... Additional arguments for visualization, see \code{?"\link{scater-plot-args}"} for details. #' #' @details @@ -80,11 +83,12 @@ #' plotExpression <- function(object, features, x = NULL, exprs_values = "logcounts", log2_values = FALSE, - colour_by = NULL, shape_by = NULL, size_by = NULL, + colour_by = color_by, shape_by = NULL, size_by = NULL, order_by = NULL, by_exprs_values = exprs_values, xlab = NULL, - feature_colours = TRUE, one_facet = TRUE, ncol = 2, + feature_colours = feature_colors, one_facet = TRUE, ncol = 2, scales = "fixed", other_fields = list(), - swap_rownames = NULL, ...) + swap_rownames = NULL, + color_by = NULL, feature_colors = TRUE, ...) { if (!is(object, "SingleCellExperiment")) { stop("object must be an SingleCellExperiment object.") @@ -131,7 +135,8 @@ ## checking visualization arguments vis_out <- .incorporate_common_vis_col(evals_long, se = object, - colour_by = colour_by, shape_by = shape_by, size_by = size_by, + colour_by = colour_by, shape_by = shape_by, size_by = size_by, + order_by = order_by, by_exprs_values = by_exprs_values, other_fields = other_fields, multiplier = rep(seq_len(ncol(object)), nfeatures), swap_rownames = swap_rownames) diff -Nru r-bioc-scater-1.24.0+ds/R/plotGroupedHeatmap.R r-bioc-scater-1.26.1+ds/R/plotGroupedHeatmap.R --- r-bioc-scater-1.24.0+ds/R/plotGroupedHeatmap.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotGroupedHeatmap.R 2022-11-13 19:03:42.000000000 +0000 @@ -13,7 +13,7 @@ #' Alternatively, any value that can be used in the \code{by} argument to \code{\link{retrieveCellInfo}}. #' @param block String specifying the field of \code{\link{colData}(object)} containing a blocking factor (e.g., batch of origin). #' Alternatively, any value that can be used in the \code{by} argument to \code{\link{retrieveCellInfo}}. -#' +#' @param color Alias to \code{colour}. #' @details #' This function shows the average expression values for each group of cells on a heatmap, as defined using the \code{group} factor. #' A per-group visualization can be preferable to a per-cell visualization when dealing with large number of cells or groups with different size. @@ -54,20 +54,25 @@ #' @importFrom scuttle summarizeAssayByGroup plotGroupedHeatmap <- function(object, features, group, block = NULL, columns=NULL, exprs_values = "logcounts", center = FALSE, scale = FALSE, - zlim = NULL, color = NULL, swap_rownames=NULL, symmetric=NULL, ...) + zlim = NULL, colour = color, swap_rownames=NULL, symmetric=NULL, + color = NULL, ...) { # Setting names, otherwise the downstream colouring fails. if (is.null(colnames(object))) { colnames(object) <- seq_len(ncol(object)) } - # Pulling out the features. swap_rownames makes features index a rowdata col - feats <- .swap_rownames(object, features, swap_rownames) - heat.vals <- assay(object, exprs_values)[feats, , drop=FALSE] - rownames(heat.vals) <- features + # Pulling out the features. swap_rownames swaps the rownames of the object + object <- .swap_rownames(object, swap_rownames) + # in case of numeric or logical features, converts to character or factor + features <- .handle_features(features, object) + heat.vals <- assay(object, exprs_values)[as.character(features), , drop=FALSE] + if (is.factor(features)) { + heat.vals <- heat.vals[levels(features), , drop = FALSE] + } if (!is.null(columns)) { columns <- .subset2index(columns, object, byrow=FALSE) - heat.vals <- heat.vals[,columns,drop=FALSE] + heat.vals <- heat.vals[, columns, drop=FALSE] } # Computing aggregates for each group. @@ -80,9 +85,9 @@ } heat.se <- summarizeAssayByGroup(heat.vals, ids, statistic="mean") heat.vals <- correctGroupSummary(assay(heat.se), group=heat.se$group, block=heat.se$group) - heatmap_scale <- .heatmap_scale(heat.vals, center=center, scale=scale, color=color, zlim=zlim, symmetric=symmetric) + heatmap_scale <- .heatmap_scale(heat.vals, center=center, scale=scale, colour=colour, zlim=zlim, symmetric=symmetric) # Creating the heatmap as specified. - pheatmap::pheatmap(heatmap_scale$x, color=heatmap_scale$color, breaks=heatmap_scale$color_breaks, ...) + pheatmap::pheatmap(heatmap_scale$x, color=heatmap_scale$colour, breaks=heatmap_scale$colour_breaks, ...) } diff -Nru r-bioc-scater-1.24.0+ds/R/plotHeatmap.R r-bioc-scater-1.26.1+ds/R/plotHeatmap.R --- r-bioc-scater-1.24.0+ds/R/plotHeatmap.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotHeatmap.R 2022-11-01 18:57:52.000000000 +0000 @@ -3,39 +3,39 @@ #' Create a heatmap of expression values for each cell and specified features in a SingleCellExperiment object. #' #' @param object A \linkS4class{SingleCellExperiment} object. -#' @param features A character vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize. +#' @param features A character (or factor) vector of row names, a logical vector, or integer vector of indices specifying rows of \code{object} to visualize. When using character or integer vectors, the ordering specified by the user is retained. When using factor vectors, ordering is controlled by the factor levels. #' @param columns A vector specifying the subset of columns in \code{object} to show as columns in the heatmap. #' Also specifies the column order if \code{cluster_cols=FALSE} and \code{order_columns_by=NULL}. #' By default, all columns are used. #' @param exprs_values A string or integer scalar indicating which assay of \code{object} should be used as expression values. #' @param center A logical scalar indicating whether each feature should have its mean expression centered at zero prior to plotting. #' @param scale A logical scalar specifying whether each feature should have its expression values scaled to have unit variance prior to plotting. -#' @param zlim A numeric vector of length 2, specifying the upper and lower bounds for color mapping of expression values. -#' Values outside this range are set to the most extreme color. +#' @param zlim A numeric vector of length 2, specifying the upper and lower bounds for colour mapping of expression values. +#' Values outside this range are set to the most extreme colour. #' If \code{NULL}, it defaults to the range of the expression matrix. #' If \code{center=TRUE}, this defaults to the range of the centered expression matrix, made symmetric around zero. -#' @param color A vector of colours specifying the palette to use for increasing expression. +#' @param colour A vector of colours specifying the palette to use for increasing expression. #' This defaults to \link[viridis]{viridis} if \code{center=FALSE}, and the the \code{"RdYlBu"} -#' color palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise. -#' @param color_columns_by A list of values specifying how the columns should be annotated with colours. +#' colour palette from \code{\link[RColorBrewer]{brewer.pal}} otherwise. +#' @param colour_columns_by A list of values specifying how the columns should be annotated with colours. #' Each entry of the list can be any acceptable input to the \code{by} argument in \code{?\link{retrieveCellInfo}}. #' A character vector can also be supplied and will be treated as a list of strings. -#' @param column_annotation_colors A named list of color scales to be used for -#' the column annotations specified in \code{color_columns_by}. Names -#' should be character values present in \code{color_columns_by}, -#' If a color scale is not specified for a particular annotation, a default -#' color scale is chosen. +#' @param column_annotation_colours A named list of colour scales to be used for +#' the column annotations specified in \code{colour_columns_by}. Names +#' should be character values present in \code{colour_columns_by}, +#' If a colour scale is not specified for a particular annotation, a default +#' colour scale is chosen. #' The full list of colour maps is passed to \code{\link[pheatmap]{pheatmap}} #' as the \code{annotation_colours} argument. -#' @param color_rows_by Similar to \code{color_columns_by} but for rows rather +#' @param colour_rows_by Similar to \code{colour_columns_by} but for rows rather #' than columns. Each entry of the list can be any acceptable input to the #' \code{by} argument in \code{?\link{retrieveFeatureInfo}}. -#' @param row_annotation_colors Similar to \code{column_annotation_colors} but +#' @param row_annotation_colours Similar to \code{column_annotation_colours} but #' relating to row annotation rather than column annotation. #' @param order_columns_by A list of values specifying how the columns should be ordered. #' Each entry of the list can be any acceptable input to the \code{by} argument in \code{?\link{retrieveCellInfo}}. #' A character vector can also be supplied and will be treated as a list of strings. -#' This argument is automatically appended to \code{color_columns_by}. +#' This argument is automatically appended to \code{colour_columns_by}. #' @param by_exprs_values A string or integer scalar specifying which assay to obtain expression values from, #' for colouring of column-level data - see the \code{exprs_values} argument in \code{?\link{retrieveCellInfo}}. #' @param show_colnames,cluster_cols,... Additional arguments to pass to \code{\link[pheatmap]{pheatmap}}. @@ -43,6 +43,10 @@ #' identify features instead of \code{rownames(object)} when labelling plot #' elements. #' @param symmetric Deprecated and ignored. +#' @param color,color_columns_by,column_annotation_colors,color_rows_by,row_annotation_colors +#' Aliases to \code{color}, \code{color_columns_by}, +#' \code{column_annotation_colors}, \code{color_rows_by}, +#' \code{row_annotation_colors}. #' #' @details #' Setting \code{center=TRUE} is useful for examining log-fold changes of each cell's expression profile from the average across all cells. @@ -52,7 +56,7 @@ #' Otherwise, the plot may be dominated by a few genes, which will \dQuote{flatten} the observed colours for the rest of the heatmap. #' #' Setting \code{order_columns_by} is useful for automatically ordering the heatmap by one or more factors of interest, e.g., cluster identity. -#' This avoids the need to set \code{color_columns_by}, \code{cluster_cols} and \code{columns} to achieve the same effect. +#' This avoids the need to set \code{colour_columns_by}, \code{cluster_cols} and \code{columns} to achieve the same effect. #' #' @return A heatmap is produced on the current graphics device. #' The output of \code{\link[pheatmap]{pheatmap}} is invisibly returned. @@ -71,7 +75,7 @@ #' center=TRUE) #' #' plotHeatmap(example_sce, features=rownames(example_sce)[1:10], -#' color_columns_by=c("Mutation_Status", "Cell_Cycle")) +#' colour_columns_by=c("Mutation_Status", "Cell_Cycle")) #' #' @export #' @importFrom DelayedArray DelayedArray @@ -80,25 +84,36 @@ #' @importFrom SummarizedExperiment assay assayNames plotHeatmap <- function(object, features, columns = NULL, exprs_values = "logcounts", center = FALSE, scale = FALSE, zlim = NULL, - color = NULL, color_columns_by = NULL, column_annotation_colors = list(), - color_rows_by = NULL, row_annotation_colors = list(), + colour = color, colour_columns_by = color_columns_by, + column_annotation_colours = column_annotation_colors, + colour_rows_by = color_rows_by, + row_annotation_colours = row_annotation_colors, order_columns_by = NULL, by_exprs_values = exprs_values, show_colnames = FALSE, cluster_cols = is.null(order_columns_by), - swap_rownames = NULL, symmetric=NULL, ...) + swap_rownames = NULL, symmetric=NULL, + color = NULL, + color_columns_by = NULL, color_rows_by = NULL, + column_annotation_colors = list(), + row_annotation_colors = list(), + ...) { # Setting names, otherwise the downstream colouring fails. if (is.null(colnames(object))) { colnames(object) <- seq_len(ncol(object)) } - # Pulling out the features. swap_rownames makes features index a rowdata col - feats <- .swap_rownames(object, features, swap_rownames) - heat.vals <- assay(object, exprs_values)[feats, , drop=FALSE] - rownames(heat.vals) <- features + # Pulling out the features. swap_rownames swaps out for alt genenames + object <- .swap_rownames(object, swap_rownames) + # in case of numeric or logical features, converts to character or factor + features <- .handle_features(features, object) + heat.vals <- assay(object, exprs_values)[as.character(features), , drop=FALSE] + if (is.factor(features)) { + heat.vals <- heat.vals[levels(features), , drop = FALSE] + } if (!is.null(columns)) { columns <- .subset2index(columns, object, byrow=FALSE) - heat.vals <- heat.vals[,columns,drop=FALSE] + heat.vals <- heat.vals[, columns, drop=FALSE] } if (!is.null(order_columns_by)) { ordering <- list() @@ -111,17 +126,16 @@ } heat.vals <- heat.vals[,do.call(order, ordering),drop=FALSE] cluster_cols <- FALSE - color_columns_by <- c(color_columns_by, order_columns_by) + colour_columns_by <- c(colour_columns_by, order_columns_by) } - - heatmap_scale <- .heatmap_scale(heat.vals, center=center, scale=scale, color=color, zlim=zlim, symmetric=symmetric) + heatmap_scale <- .heatmap_scale(heat.vals, center=center, scale=scale, colour=colour, zlim=zlim, symmetric=symmetric) # Collecting variables to colour_by. - if (length(color_columns_by)) { + if (length(colour_columns_by)) { column_variables <- list() - for (i in seq_along(color_columns_by)) { - field <- color_columns_by[[i]] + for (i in seq_along(colour_columns_by)) { + field <- colour_columns_by[[i]] colour_by_out <- retrieveCellInfo(object, field, exprs_values = by_exprs_values, swap_rownames = swap_rownames) @@ -151,8 +165,8 @@ col_name <- paste0("unnamed", i) } column_variables[[col_name]] <- colour_fac - if (is.null(column_annotation_colors[[col_name]])) { - column_annotation_colors[[col_name]] <- col_scale + if (is.null(column_annotation_colours[[col_name]])) { + column_annotation_colours[[col_name]] <- col_scale } } @@ -160,16 +174,16 @@ # as pheatmap::pheatmap uses the rownames to handle this for us. column_variables <- do.call(data.frame, c(column_variables, list(row.names=colnames(object)))) - column_annotation_colors <- column_annotation_colors[colnames(column_variables)] + column_annotation_colours <- column_annotation_colours[colnames(column_variables)] } else { - column_variables <- column_annotation_colors <- NULL + column_variables <- column_annotation_colours <- NULL } - if (length(color_rows_by)) { + if (length(colour_rows_by)) { row_variables <- list() - for (i in seq_along(color_rows_by)) { - field <- color_rows_by[[i]] + for (i in seq_along(colour_rows_by)) { + field <- colour_rows_by[[i]] colour_by_out <- retrieveFeatureInfo(object, field, exprs_values = by_exprs_values) @@ -199,38 +213,39 @@ col_name <- paste0("unnamed", i) } row_variables[[col_name]] <- colour_fac - if (is.null(row_annotation_colors[[col_name]])) { - row_annotation_colors[[col_name]] <- col_scale + if (is.null(row_annotation_colours[[col_name]])) { + row_annotation_colours[[col_name]] <- col_scale } } - - # No need to subset for 'columns' or 'order_columns_by', - # as pheatmap::pheatmap uses the rownames to handle this for us. row_variables <- do.call( data.frame, c(row_variables, list(row.names = rownames(object))) ) - row_annotation_colors <- row_annotation_colors[colnames(row_variables)] + row_annotation_colours <- row_annotation_colours[colnames(row_variables)] } else { - row_variables <- row_annotation_colors <- NULL + row_variables <- row_annotation_colours <- NULL } - if (length(intersect(names(row_annotation_colors), names(column_annotation_colors)))) { + if (length(intersect(names(row_annotation_colours), names(column_annotation_colours)))) { warning("Element with the same name in row and column annotations. ", "Assuming they're the same.") } - annotation_colors <- c(row_annotation_colors, column_annotation_colors) + annotation_colours <- c(row_annotation_colours, column_annotation_colours) # Creating the heatmap as specified. - pheatmap::pheatmap(heatmap_scale$x, color=heatmap_scale$color, - breaks=heatmap_scale$color_breaks, + pheatmap::pheatmap( + heatmap_scale$x, + color=heatmap_scale$colour, + breaks=heatmap_scale$colour_breaks, annotation_col=column_variables, annotation_row=row_variables, - annotation_colors=annotation_colors, - show_colnames=show_colnames, cluster_cols=cluster_cols, ...) + annotation_colors=annotation_colours, + show_colnames=show_colnames, + cluster_cols=cluster_cols, + ...) } -#' @importFrom ggplot2 scale_color_gradientn -.heatmap_scale <- function(x, center, scale, color=NULL, zlim=NULL, symmetric=NULL) { +#' @importFrom ggplot2 scale_colour_gradientn +.heatmap_scale <- function(x, center, scale, colour=NULL, zlim=NULL, symmetric=NULL) { if (!is.null(symmetric)) { .Deprecated(msg="'symmetric=' is deprecated and is automatically set to TRUE when 'center=TRUE'") } @@ -238,6 +253,9 @@ x <- x - rowMeans(x) } if (scale) { + if (!center & any(rowSums(x) == 0)) { + stop("Cannot include non-expressed genes when scale=TRUE.") + } x <- x / sqrt(rowSums(x^2) / (ncol(x) - 1)) } if (is.null(zlim)) { @@ -248,21 +266,20 @@ zlim <- range(x) } } - if (is.null(color)) { + if (is.null(colour)) { if (center) { - color <- rev(RColorBrewer::brewer.pal(9, "RdYlBu")) + colour <- rev(RColorBrewer::brewer.pal(9, "RdYlBu")) } else { - color <- viridis::viridis(9) + colour <- viridis::viridis(9) } } x[x < zlim[1]] <- zlim[1] x[x > zlim[2]] <- zlim[2] - list( x = x, - color = color, - color_breaks = seq(zlim[1], zlim[2], length.out=length(color) + 1L), - color_scale = scale_color_gradientn(colours = color, limits = zlim), + colour = colour, + colour_breaks = seq(zlim[1], zlim[2], length.out=length(colour) + 1L), + colour_scale = scale_colour_gradientn(colours = colour, limits = zlim), zlim = zlim ) } diff -Nru r-bioc-scater-1.24.0+ds/R/plotHighestExprs.R r-bioc-scater-1.26.1+ds/R/plotHighestExprs.R --- r-bioc-scater-1.24.0+ds/R/plotHighestExprs.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotHighestExprs.R 2022-11-01 18:57:52.000000000 +0000 @@ -18,6 +18,7 @@ #' @param swap_rownames Column name of \code{rowData(object)} to be used to #' identify features instead of \code{rownames(object)} when labelling plot #' elements. +#' @param color_cells_by Alias to \code{colour_cells_by}. #' #' @details #' This function will plot the percentage of counts accounted for by the top \code{n} most highly expressed features across the dataset. @@ -42,11 +43,12 @@ #' @importFrom DelayedMatrixStats rowSums2 colSums2 #' @importFrom SummarizedExperiment assay #' @importFrom ggplot2 ggplot geom_point ggtitle xlab ylab theme_bw theme element_text -#' scale_color_gradient scale_fill_manual guides -plotHighestExprs <- function(object, n = 50, colour_cells_by = NULL, +#' scale_colour_gradient scale_fill_manual guides +plotHighestExprs <- function(object, n = 50, colour_cells_by = color_cells_by, drop_features = NULL, exprs_values = "counts", by_exprs_values = exprs_values, feature_names_to_plot = NULL, - as_percentage = TRUE, swap_rownames = NULL) + as_percentage = TRUE, swap_rownames = NULL, + color_cells_by = NULL) { ## Find the most highly expressed features in this dataset exprs_mat <- assay(object, exprs_values, withDimnames=FALSE) @@ -62,6 +64,9 @@ sub_mat <- exprs_mat[chosen,,drop=FALSE] sub_ave <- ave_exprs[chosen] + ## swap out rownames for alt genenames + object <- .swap_rownames(object, swap_rownames) + ## define feature names for plot if (is.null(feature_names_to_plot)) { feature_names <- rownames(object) @@ -71,7 +76,6 @@ } else { feature_names <- retrieveFeatureInfo(object, feature_names_to_plot, search = "rowData")$val } - feature_names <- .swap_rownames(object, feature_names, swap_rownames) sub_names <- feature_names[chosen] ## Compute expression values and reshape them for ggplot. diff -Nru r-bioc-scater-1.24.0+ds/R/plotPlatePosition.R r-bioc-scater-1.26.1+ds/R/plotPlatePosition.R --- r-bioc-scater-1.24.0+ds/R/plotPlatePosition.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotPlatePosition.R 2022-11-01 18:57:52.000000000 +0000 @@ -9,6 +9,7 @@ #' @param colour_by Specification of a column metadata field or a feature to colour by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param shape_by Specification of a column metadata field or a feature to shape by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param size_by Specification of a column metadata field or a feature to size by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. +#' @param order_by Specification of a column metadata field or a feature to order points by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for possible values. #' @param by_exprs_values A string or integer scalar specifying which assay to obtain expression values from, #' for use in point aesthetics - see the \code{exprs_values} argument in \code{?\link{retrieveCellInfo}}. #' @param add_legend Logical scalar specifying whether a legend should be shown. @@ -19,6 +20,7 @@ #' @param swap_rownames Column name of \code{rowData(object)} to be used to #' identify features instead of \code{rownames(object)} when labelling plot #' elements. +#' @param color_by Alias to \code{colour_by}. #' #' @details #' This function expects plate positions to be given in a charcter format where a letter indicates the row on the plate and a numeric value indicates the column. @@ -52,11 +54,11 @@ #' #' @export plotPlatePosition <- function(object, plate_position = NULL, - colour_by = NULL, size_by = NULL, shape_by = NULL, + colour_by = color_by, size_by = NULL, shape_by = NULL, order_by = NULL, by_exprs_values = "logcounts", add_legend = TRUE, theme_size = 24, point_alpha = 0.6, point_size = 24, other_fields=list(), - swap_rownames = NULL) + swap_rownames = NULL, color_by = NULL) { ## check object is SingleCellExperiment object if ( !is(object, "SingleCellExperiment") ) { @@ -86,6 +88,7 @@ ## checking visualization arguments vis_out <- .incorporate_common_vis_col(df_to_plot, se = object, colour_by = colour_by, shape_by = shape_by, size_by = size_by, + order_by = order_by, by_exprs_values = by_exprs_values, other_fields = other_fields, swap_rownames = swap_rownames) diff -Nru r-bioc-scater-1.24.0+ds/R/plotReducedDim.R r-bioc-scater-1.26.1+ds/R/plotReducedDim.R --- r-bioc-scater-1.24.0+ds/R/plotReducedDim.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotReducedDim.R 2022-11-01 18:57:52.000000000 +0000 @@ -22,6 +22,9 @@ #' @param size_by Specification of a column metadata field or a feature to #' size by, see the \code{by} argument in \code{?\link{retrieveCellInfo}} for #' possible values. +#' @param order_by Specification of a column metadata field or a feature to +#' order points by, see the \code{by} argument in +#' \code{?\link{retrieveCellInfo}} for possible values. #' @param by_exprs_values A string or integer scalar specifying which assay to #' obtain expression values from, #' for use in point aesthetics - see the \code{exprs_values} argument in @@ -44,7 +47,13 @@ #' @param swap_rownames Column name of \code{rowData(object)} to be used to #' identify features instead of \code{rownames(object)} when labelling plot #' elements. +#' @param color_by Alias to \code{colour_by}. +#' @param text_color Alias to \code{text_colour}. #' @param point.padding,force See \code{?ggrepel::geom_text_repel}. +#' @param rasterise Whether to rasterise the points in the plot with +#' \code{\link[ggrastr]{rasterise}}. To control the dpi, set +#' \code{options(ggrastr.default.dpi)}, +#' for example \code{options(ggrastr.default.dpi=300)}. #' @param ... Additional arguments for visualization, see #' \code{?"\link{scater-plot-args}"} for details. #' @@ -88,12 +97,15 @@ #' @export #' @importFrom SingleCellExperiment reducedDim #' @importFrom ggrepel geom_text_repel -plotReducedDim <- function(object, dimred, ncomponents = 2, percentVar = NULL, - colour_by = NULL, shape_by = NULL, size_by = NULL, - by_exprs_values = "logcounts", - text_by = NULL, text_size = 5, text_colour = "black", +plotReducedDim <- function( + object, dimred, ncomponents = 2, percentVar = NULL, + colour_by = color_by, shape_by = NULL, size_by = NULL, + order_by = NULL, by_exprs_values = "logcounts", + text_by = NULL, text_size = 5, text_colour = text_color, label_format = c("%s %i", " (%i%%)"), other_fields = list(), - swap_rownames = NULL, point.padding = NA, force = 1, ... + text_color = "black", color_by = NULL, + swap_rownames = NULL, point.padding = NA, force = 1, + rasterise = FALSE, ... ) { ## Extract reduced dimension representation of cells @@ -124,13 +136,14 @@ ## checking visualization arguments vis_out <- .incorporate_common_vis_col(df_to_plot, se = object, colour_by = colour_by, shape_by = shape_by, size_by = size_by, + order_by = order_by, by_exprs_values = by_exprs_values, other_fields = other_fields, swap_rownames = swap_rownames) df_to_plot <- vis_out$df colour_by <- vis_out$colour_by shape_by <- vis_out$shape_by size_by <- vis_out$size_by - + ## Dispatching to the central plotter in the simple case of two dimensions. if (length(to_plot) == 2L) { colnames(df_to_plot)[seq_along(to_plot)] <- c("X", "Y") @@ -142,10 +155,11 @@ sprintf(label_format[2], round(percentVar[to_plot])) ) } - + plot_out <- .central_plotter(df_to_plot, xlab = labs[1], ylab = labs[2], colour_by = colour_by, size_by = size_by, - shape_by = shape_by, ..., point_FUN = NULL) + shape_by = shape_by, ..., point_FUN = NULL, + rasterise = rasterise) # Adding text with the median locations of the 'text_by' vector. if (!is.null(text_by)) { @@ -166,7 +180,7 @@ data = data.frame( x = by_text_x, y = by_text_y, label = names(by_text_x) ), - mapping = aes(x = x, y = y, label = label), + mapping = aes_string(x = "x", y = "y", label = "label"), inherit.aes = FALSE, size = text_size, colour = text_colour, force = force, point.padding = point.padding @@ -175,18 +189,18 @@ return(plot_out) } - ## Otherwise, creating a paired reddim plot. paired_reddim_plot(df_to_plot, to_plot = to_plot, percentVar = percentVar, colour_by = colour_by, shape_by = shape_by, size_by = size_by, - dimred = dimred, label_format = label_format, ...) + dimred = dimred, label_format = label_format, rasterise = rasterise, ...) } #' @importFrom ggplot2 ggplot facet_grid stat_density geom_point theme paired_reddim_plot <- function(df_to_plot, to_plot, dimred, percentVar = NULL, colour_by=NULL, shape_by=NULL, size_by=NULL, label_format=c("%s %i", " (%i%%)"), - add_legend = TRUE, theme_size = 10, point_alpha = 0.6, point_size = NULL + add_legend = TRUE, theme_size = 10, point_alpha = 0.6, point_size = NULL, + rasterise = FALSE ) { reddim_cols <- seq_along(to_plot) @@ -231,6 +245,8 @@ if (!add_legend) { plot_out <- plot_out + theme(legend.position = "none") } - + if (rasterise) { + plot_out <- ggrastr::rasterise(plot_out, geoms = "Point") + } plot_out } diff -Nru r-bioc-scater-1.24.0+ds/R/plotRLE.R r-bioc-scater-1.26.1+ds/R/plotRLE.R --- r-bioc-scater-1.24.0+ds/R/plotRLE.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotRLE.R 2022-11-01 18:57:52.000000000 +0000 @@ -14,6 +14,7 @@ #' @param by_exprs_values A string or integer scalar specifying which assay to obtain expression values from, #' for use in point aesthetics - see the \code{exprs_values} argument in \code{?\link{retrieveCellInfo}}. #' @param BPPARAM A \linkS4class{BiocParallelParam} object to be used to parallelise operations using \code{\link{DelayedArray}}. +#' @param color_by Alias to \code{colour_by}. #' @param ... further arguments passed to \code{\link[ggplot2]{geom_boxplot}} when \code{style="full"}. #' #' @return A ggplot object @@ -62,8 +63,9 @@ #' @importFrom ggplot2 aes_string theme plotRLE <- function(object, exprs_values="logcounts", exprs_logged = TRUE, style = "minimal", legend = TRUE, ordering = NULL, - colour_by = NULL, by_exprs_values = exprs_values, - BPPARAM = BiocParallel::bpparam(), ...) { + colour_by = color_by, by_exprs_values = exprs_values, + BPPARAM = BiocParallel::bpparam(), color_by = NULL, + ...) { oldbp <- getAutoBPPARAM() setAutoBPPARAM(BPPARAM) @@ -156,7 +158,7 @@ .plotRLE_full <- function(df, aesth, ncol, ...) { plot_out <- ggplot(df, aesth) + geom_boxplot(...) + # geom_boxplot(notch=T) to compare groups - stat_summary(geom = "crossbar", width = 0.65, fatten = 0, color = "white", + stat_summary(geom = "crossbar", width = 0.65, fatten = 0, colour = "white", fun.data = function(x){ c(y = median(x), ymin = median(x), ymax = median(x)) }) + ylab("Relative log expression") + xlab("Sample") + theme_classic() + diff -Nru r-bioc-scater-1.24.0+ds/R/plotRowData.R r-bioc-scater-1.26.1+ds/R/plotRowData.R --- r-bioc-scater-1.24.0+ds/R/plotRowData.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotRowData.R 2022-11-01 18:57:52.000000000 +0000 @@ -14,6 +14,7 @@ #' @param by_exprs_values A string or integer scalar specifying which assay to obtain expression values from, #' for use in point aesthetics - see \code{?\link{retrieveFeatureInfo}} for details. #' @param other_fields Additional feature-based fields to include in the data.frame, see \code{?"\link{scater-plot-args}"} for details. +#' @param color_by Alias to \code{colour_by}. #' @param ... Additional arguments for visualization, see \code{?"\link{scater-plot-args}"} for details. #' #' @details @@ -37,8 +38,9 @@ #' #' @export plotRowData <- function(object, y, x = NULL, - colour_by = NULL, shape_by = NULL, size_by = NULL, - by_exprs_values = "logcounts", other_fields = list(), ...) + colour_by = color_by, shape_by = NULL, size_by = NULL, + by_exprs_values = "logcounts", other_fields = list(), color_by = NULL, + ...) { if (!is(object, "SingleCellExperiment")) { stop("object must be an SingleCellExperiment object.") diff -Nru r-bioc-scater-1.24.0+ds/R/plotScater.R r-bioc-scater-1.26.1+ds/R/plotScater.R --- r-bioc-scater-1.24.0+ds/R/plotScater.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/plotScater.R 2022-11-01 18:57:52.000000000 +0000 @@ -16,6 +16,7 @@ #' @param ncol Number of columns to use for \code{\link{facet_wrap}} if only one block is defined. #' @param line_width Numeric scalar specifying the line width. #' @param theme_size Numeric scalar specifying the font size to use for the plotting theme. +#' @param color_by Alias to \code{colour_by}. #' #' @details #' For each cell, the features are ordered from most-expressed to least-expressed. @@ -41,9 +42,9 @@ #' @importFrom SummarizedExperiment assay #' @importFrom ggplot2 ggplot geom_line facet_grid facet_wrap xlab ylab theme_bw aes_string plotScater <- function(x, nfeatures = 500, exprs_values = "counts", - colour_by = NULL, by_exprs_values = exprs_values, + colour_by = color_by, by_exprs_values = exprs_values, block1 = NULL, block2 = NULL, ncol = 3, - line_width = 1.5, theme_size = 10) + line_width = 1.5, theme_size = 10, color_by = NULL) { if (!is(x, "SingleCellExperiment")) { stop("x must be of class SingleCellExperiment") diff -Nru r-bioc-scater-1.24.0+ds/R/projectReducedDim.R r-bioc-scater-1.26.1+ds/R/projectReducedDim.R --- r-bioc-scater-1.24.0+ds/R/projectReducedDim.R 1970-01-01 00:00:00.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/projectReducedDim.R 2022-11-01 18:57:52.000000000 +0000 @@ -0,0 +1,101 @@ +#' Project cells into an arbitrary dimensionality reduction space. +#' +#' Projects observations into arbitrary dimensionality reduction space (e.g., t-SNE, UMAP) using a tricube weighted average of the k nearest neighbours. +#' +#' @param x A numeric matrix of a dimensionality reduction containing the cells that should be projected into the existing embedding defined in either \code{old.embedding} or \code{old.sce}. +#' Alternatively, a \linkS4class{SummarizedExperiment} or \linkS4class{SingleCellExperiment} containing such a matrix. +#' @param old.sce The object containing the original dimensionality points. If \code{x} is a matrix, then \code{old.points} must be supplied as a matrix of +#' @param old.embedding If \code{x} is a matrix and \code{old} is given, then \code{old.embedding} is the existing dimensionality reduction embedding that \code{x} should be projected into. +#' @param dimred.embed The name of the target dimensionality reduction that points should be embedded into, if \code{}. +#' @param dimred.knn The name of the dimensionality reduction to use to identify the K-nearest neighbours from \code{x} in the dimensionality reduction slot of the same name defined in either \code{old} or \code{old.sce}. +#' @param dimred.name The name of the dimensionality reduction that the projected embedding will be saved as, for the \linkS4class{SummarizedExperiment} method. +#' @param k The number of nearest neighours to use to project points into the embedding. +#' @param ... Passed to methods. +#' @name projectReducedDim +#' +#' @return When \code{x} is a matrix, a matrix is returned. When \code{x} is a +#' \code{\linkS4class{SummarizedExperiment}} +#' (or \code{\linkS4class{SingleCellExperiment}}), the return value is of +#' the same class as the input, but the projected dimensionality reduction +#' is added as a \code{reducedDim} field. +#' @examples +#' example_sce <- mockSCE() +#' example_sce <- logNormCounts(example_sce) +#' example_sce <- runUMAP(example_sce) +#' example_sce <- runPCA(example_sce) +#' +#' example_sce_new <- mockSCE() +#' example_sce_new <- logNormCounts(example_sce_new) +#' example_sce_new <- runPCA(example_sce_new) +#' +#' ## sce method +#' projectReducedDim( +#' example_sce_new, +#' old.sce = example_sce, +#' dimred.embed="UMAP", +#' dimred.knn="PCA" +#' ) +#' +#' ## matrix method +#' projectReducedDim( +#' reducedDim(example_sce, "PCA"), +#' new.points = reducedDim(example_sce_new, "PCA"), +#' old.embedding = reducedDim(example_sce, "UMAP") +#' ) +NULL + +.project_reduced_dim <- function(old.points, new.points, old.embedding, k = 5) { + res <- BiocNeighbors::queryKNN(X = old.points, query = new.points, k = k) + new.embedding <- .compute_tricube_average(old.embedding, res$index, res$distance) + rownames(new.embedding) <- rownames(new.points) + new.embedding +} + +#' @export +#' @rdname projectReducedDim +setMethod("projectReducedDim", "matrix", function(x, old.embedding, ...) { + .project_reduced_dim(x, old.embedding, ...) +}) + +#' @export +#' @rdname projectReducedDim +setMethod("projectReducedDim", "SummarizedExperiment", function(x, old.sce, dimred.embed="TSNE", dimred.knn="PCA", dimred.name=dimred.embed, k=5) { + reddim <- .project_reduced_dim( + reducedDim(old.sce, dimred.knn), + reducedDim(x, dimred.knn), + reducedDim(old.sce, dimred.embed), + k = k + ) + reducedDim(x, dimred.name) <- reddim + x + } +) + +## https://github.com/LTLA/batchelor/blob/fd33fe0c5cc9843e8ed030297251efdf4278fcb5/R/utils_tricube.R +.compute_tricube_average <- function(vals, indices, distances, bandwidth=NULL, ndist=3) +# Centralized function to compute tricube averages. +# Bandwidth is set at 'ndist' times the median distance, if not specified. +{ + if (is.null(bandwidth)) { + middle <- ceiling(ncol(indices)/2L) + mid.dist <- distances[, middle] + bandwidth <- mid.dist * ndist + } + bandwidth <- pmax(1e-8, bandwidth) + + rel.dist <- distances/bandwidth + rel.dist[rel.dist > 1] <- 1 # don't use pmin(), as this destroys dimensions. + tricube <- (1 - rel.dist^3)^3 + weight <- tricube/rowSums(tricube) + + output <- 0 + for (kdx in seq_len(ncol(indices))) { + output <- output + vals[indices[,kdx],,drop=FALSE] * weight[,kdx] + } + + if (is.null(dim(output))) { + matrix(0, nrow(vals), ncol(vals)) + } else { + output + } +} diff -Nru r-bioc-scater-1.24.0+ds/R/retrieveCellInfo.R r-bioc-scater-1.26.1+ds/R/retrieveCellInfo.R --- r-bioc-scater-1.24.0+ds/R/retrieveCellInfo.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/retrieveCellInfo.R 2022-11-01 18:57:52.000000000 +0000 @@ -108,11 +108,8 @@ return(.mopUp(by, cd[,by])) } } else if (s=="assays") { - if (!is.null(swap_rownames)) { - m <- match(by, .get_rowData_column(x, swap_rownames)) - } else { - m <- match(by, rownames(x)) - } + x <- .swap_rownames(x, swap_rownames) + m <- match(by, rownames(x)) if (!is.na(m)) { return(.mopUp(by, assay(x, exprs_values, withDimnames = FALSE)[m, ])) } diff -Nru r-bioc-scater-1.24.0+ds/R/runTSNE.R r-bioc-scater-1.26.1+ds/R/runTSNE.R --- r-bioc-scater-1.24.0+ds/R/runTSNE.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/runTSNE.R 2022-11-01 18:57:52.000000000 +0000 @@ -104,6 +104,7 @@ } args$n_components <- as.integer(args$dims) args$dims <- NULL + args$n_jobs <- num_threads tsne_out <- do.call( snifter::fitsne, c(list(x), args, simplified = TRUE) diff -Nru r-bioc-scater-1.24.0+ds/R/scater-pkg.R r-bioc-scater-1.26.1+ds/R/scater-pkg.R --- r-bioc-scater-1.24.0+ds/R/scater-pkg.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/scater-pkg.R 2022-11-01 18:57:52.000000000 +0000 @@ -12,4 +12,3 @@ #' @import SingleCellExperiment #' @import methods NULL - diff -Nru r-bioc-scater-1.24.0+ds/R/utils_plotting.R r-bioc-scater-1.26.1+ds/R/utils_plotting.R --- r-bioc-scater-1.24.0+ds/R/utils_plotting.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/R/utils_plotting.R 2022-11-01 18:57:52.000000000 +0000 @@ -33,8 +33,9 @@ list(df=df, colour_by = colour_by, shape_by = shape_by, size_by = size_by) } -.incorporate_common_vis_col <- function(df, se, mode, colour_by, size_by, shape_by, - by_exprs_values, by_show_single, other_fields, multiplier = NULL, swap_rownames = NULL) +.incorporate_common_vis_col <- function(df, se, mode, colour_by, size_by, + shape_by, order_by, by_exprs_values, by_show_single, other_fields, + multiplier = NULL, swap_rownames = NULL) { colour_by_out <- retrieveCellInfo(se, colour_by, exprs_values = by_exprs_values, swap_rownames=swap_rownames) @@ -60,6 +61,15 @@ } df$size_by <- size_by_out$value + order_by_out <- retrieveCellInfo(se, order_by, exprs_values = by_exprs_values, + swap_rownames=swap_rownames) + order_by <- order_by_out$name + df$order_by <- order_by_out$value + if (is.null(df$order_by)) { + df$order_by <- seq_len(nrow(df)) + } + df <- df[order(df$order_by), ] + for (o in other_fields) { other <- retrieveCellInfo(se, o, exprs_values=by_exprs_values, swap_rownames=swap_rownames) @@ -69,7 +79,7 @@ df <- .add_other_or_warn(df, other) } - list(df = df, colour_by = colour_by, shape_by = shape_by, size_by = size_by) + list(df = df, colour_by = colour_by, shape_by = shape_by, size_by = size_by, order_by = order_by) } .add_other_or_warn <- function(df, other) { @@ -111,12 +121,36 @@ ################################################ ## Using non-standard gene IDs -.swap_rownames <- function(object, features, swap_rownames = NULL) { +.swap_rownames <- function(object, swap_rownames = NULL) { if (is.null(swap_rownames)) { - return(features) + return(object) + } + rownames(object) <- .get_rowData_column(object, swap_rownames) + object +} + +.handle_features <- function(features, object) { + if (is.logical(features)) { + if (length(features) != nrow(object)) { + stop("logical features index should be the of length nrow(object).") + } + features <- rownames(object)[features] + } else if (is.numeric(features)) { + if (any(features > nrow(object)) | any(features <= 0) | any(features != round(features))) { + stop("All features should be round numbers; > 0 and <= nrow(object).") + } + features <- rownames(object)[features] + } else if (is.character(features) | is.factor(features)) { + if (!all(as.character(features) %in% rownames(object))) { + stop("Some features not in input object.") + } + } + # if it's character by now, preserve the order + if (is.character(features)) { + features <- factor(features, levels = features) } - m <- match(features, .get_rowData_column(object, swap_rownames)) - rownames(object)[m] + # otherwise it's presumably a factor and should keep its levels + features } .get_rowData_column <- function(object, column) { diff -Nru r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-dimred.R r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-dimred.R --- r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-dimred.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-dimred.R 2022-11-01 18:57:52.000000000 +0000 @@ -111,3 +111,15 @@ # Handles multiple components properly. expect_s3_class(P4 <- plotMDS(example_sce, ncomponents=4), "ggplot") }) + + +test_that("order by works", { + set.seed(42) + example_sce <- mockSCE() + example_sce <- logNormCounts(example_sce) + example_sce <- runPCA(example_sce) + p <- plotReducedDim(example_sce, "PCA", order_by = "Gene_0001") + expect_equal(order(p$data$order_by), seq_len(nrow(p$data))) + p <- plotReducedDim(example_sce, "PCA", order_by = "Mutation_Status") + expect_equal(order(p$data$order_by), seq_len(nrow(p$data))) +}) diff -Nru r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-heat.R r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-heat.R --- r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-heat.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-heat.R 2022-11-01 18:57:52.000000000 +0000 @@ -22,7 +22,7 @@ # Colour parameters for the expression values. plotHeatmap(example_sce, features=rownames(example_sce)[1:10], zlim=c(0, 2)) - plotHeatmap(example_sce, features=rownames(example_sce)[1:10], color=viridis::viridis(20)) + plotHeatmap(example_sce, features=rownames(example_sce)[1:10], colour=viridis::viridis(20)) expect_warning( plotHeatmap(example_sce, features=rownames(example_sce)[1:10], center=TRUE, symmetric=TRUE) ) @@ -31,6 +31,27 @@ plotHeatmap(example_sce, features=rownames(example_sce)[1:10], colour_columns_by=c("Mutation_Status", "Cell_Cycle")) + rowData(example_sce)$class <- sample(c("A", "B"), nrow(example_sce), replace = TRUE) + + # Testing out the row colouring. + plotHeatmap(example_sce, + features = rownames(example_sce)[1:10], colour_rows_by = "class") + plotHeatmap(example_sce, features = rownames(example_sce)[1:10], + colour_rows_by = "class", + row_annotation_colours = list(class = c("A" = "blue", "B" = "red"))) + + example_sce$class <- sample(c("A", "B"), ncol(example_sce), replace=TRUE) + expect_warning( + plotHeatmap(example_sce, features = rownames(example_sce)[1:10], + colour_rows_by = "class", + colour_columns_by = "class", + row_annotation_colours = list(class = c("A" = "blue", "B" = "red")), + column_annotation_colours = list(class = c("A" = "blue", "B" = "red")) + ), + "Element with the same name" + ) + + plotHeatmap(example_sce, features=rownames(example_sce)[1:10], colour_columns_by=c("Mutation_Status", "Gene_0001"), by_exprs_values = "logcounts") @@ -60,7 +81,7 @@ plotHeatmap(example_sce, features = rowData(example_sce)[1:10, "ENS"], swap_rownames = "ENS", columns = 1:20) expect_error( - plotHeatmap(example_sce, features = NA, swap_rownames = "ENS_e1", + plotHeatmap(example_sce, features = rownames(example_sce)[[1]], columns = 1:20), "must have n >= 2 objects to cluster" ) @@ -72,7 +93,7 @@ ) expect_error( - plotHeatmap(example_sce, features = NA, swap_rownames = "sdfsf", + plotHeatmap(example_sce, features = rownames(example_sce)[[1]], swap_rownames = "sdfsf", columns = 1:20), "Cannot find column sdfsf in rowData" ) @@ -93,7 +114,7 @@ plotGroupedHeatmap(example_sce, features=1:10, group="Group", block="Cell_Cycle") plotGroupedHeatmap(example_sce, features=1:10, group="Group", block="Cell_Cycle", columns=20:30) - # Works with the various color options. + # Works with the various colour options. expect_warning( plotGroupedHeatmap(example_sce, features=rownames(example_sce)[1:10], group="Group", center=TRUE, symmetric=TRUE) @@ -104,10 +125,31 @@ group="Group", center=TRUE, symmetric=TRUE) ) - plotGroupedHeatmap(example_sce, features=rownames(example_sce)[1:10], group="Group", color=viridis::viridis(20)) + plotGroupedHeatmap(example_sce, features=rownames(example_sce)[1:10], group="Group", colour=viridis::viridis(20)) plotGroupedHeatmap(example_sce, features=rownames(example_sce)[1:10], group="Group", zlim=c(0, 2)) # Works with rownames swapping. plotGroupedHeatmap(example_sce, features = rowData(example_sce)[1:10, "ENS"], group="Group", swap_rownames = "ENS", columns = 1:20) }) + + +test_that("plotHeatmap indexing is consistent", { + p1 <- plotHeatmap(example_sce, features=rownames(example_sce)[1:10], cluster_rows = FALSE, cluster_columns = FALSE) + p2 <- plotHeatmap(example_sce, features=1:10, cluster_rows = FALSE, cluster_columns = FALSE) + p3 <- plotHeatmap(example_sce, features=c(rep(TRUE, 10), rep(FALSE, 1990)), cluster_rows = FALSE, cluster_columns = FALSE) + p4 <- plotHeatmap(example_sce, features=factor(rownames(example_sce)[1:10]), cluster_rows = FALSE, cluster_columns = FALSE) + + ## this is apparently the ordering of genes! + expect_equal(rownames(p1$gtable$grobs[[2]]$children[[1]]$gp$fill), rownames(p2$gtable$grobs[[2]]$children[[1]]$gp$fill)) + expect_equal(rownames(p2$gtable$grobs[[2]]$children[[1]]$gp$fill), rownames(p3$gtable$grobs[[2]]$children[[1]]$gp$fill)) + expect_equal(rownames(p3$gtable$grobs[[2]]$children[[1]]$gp$fill), rownames(p4$gtable$grobs[[2]]$children[[1]]$gp$fill)) + + p1 <- plotHeatmap(example_sce, features=rownames(example_sce)[10:1], cluster_rows = FALSE, cluster_columns = FALSE) + p2 <- plotHeatmap(example_sce, features=10:1, cluster_rows = FALSE, cluster_columns = FALSE) + p3 <- plotHeatmap(example_sce, features=factor(rownames(example_sce)[1:10], levels = rownames(example_sce)[10:1]), cluster_rows = FALSE, cluster_columns = FALSE) + + + expect_equal(rownames(p1$gtable$grobs[[2]]$children[[1]]$gp$fill), rownames(p2$gtable$grobs[[2]]$children[[1]]$gp$fill)) + expect_equal(rownames(p2$gtable$grobs[[2]]$children[[1]]$gp$fill), rownames(p3$gtable$grobs[[2]]$children[[1]]$gp$fill)) +}) diff -Nru r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-other.R r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-other.R --- r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-other.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-other.R 2022-11-01 18:57:52.000000000 +0000 @@ -171,7 +171,7 @@ test_that("plotDots works as expected", { expect_s3_class(plotDots(example_sce, group="Cell_Cycle", features=rownames(example_sce)[1:10]), "ggplot") - expect_s3_class(plotDots(example_sce, group="Cell_Cycle", features=rownames(example_sce)[1:10], color = rainbow(7)), "ggplot") + expect_s3_class(plotDots(example_sce, group="Cell_Cycle", features=rownames(example_sce)[1:10], colour = rainbow(7)), "ggplot") expect_s3_class(plotDots(example_sce, group="Cell_Cycle", features=rownames(example_sce)[1:10], zlim=c(-1, 1)), "ggplot") @@ -199,3 +199,49 @@ expect_identical(p$data$stuff, rep(rowData(example_sce)$stuff[1:10], nuniq)) expect_identical(p$data$otherstuff, rep(rowData(example_sce)$otherstuff[1:10], nuniq)) }) + +test_that("plotDots works w/factors", { + + counts <- matrix(rpois(100, 5), ncol = 10) + rownames(counts) <- paste("Feature", 1:10) + sce <- SingleCellExperiment(assays = list(counts = counts)) + sce <- logNormCounts(sce) + + p1 <- plotDots(sce, features=factor(rownames(counts), levels = paste("Feature", 10:1))) + p2 <- plotDots(sce, features=factor(rownames(counts), levels = paste("Feature", 1:10))) + pd1 <- p1$data + rownames(pd1) <- pd1$Feature + pd2 <- p2$data + rownames(pd2) <- pd2$Feature + expect_equal( + pd1[as.character(pd1$Feature), "Average"], + pd2[as.character(pd1$Feature), "Average"], + ) +}) + + +test_that("plotDots indexing is consistent", { + p1 <- plotDots(example_sce, features=rownames(example_sce)[1:10]) + p2 <- plotDots(example_sce, features=1:10) + p3 <- plotDots(example_sce, features=c(rep(TRUE, 10), rep(FALSE, 1990))) + p4 <- plotDots(example_sce, features=factor(rownames(example_sce)[1:10])) + + expect_equal(p1, p2) + expect_equal(p2, p3) + expect_equal(p3, p4) + + p1 <- plotDots(example_sce, features=rownames(example_sce)[10:1]) + p2 <- plotDots(example_sce, features=10:1) + p3 <- plotDots(example_sce, features=factor(rownames(example_sce)[1:10], levels = rownames(example_sce)[10:1])) + + expect_equal(p1, p2) + ## this has a different order but we want to check the order + pd2 <- p2$data + rownames(pd2) <- pd2$Feature + pd3 <- p3$data + rownames(pd3) <- pd3$Feature + expect_equal( + pd2[as.character(pd2$Feature), "Average"], + pd3[as.character(pd2$Feature), "Average"], + ) +}) diff -Nru r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-utils.R r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-utils.R --- r-bioc-scater-1.24.0+ds/tests/testthat/test-plot-utils.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/tests/testthat/test-plot-utils.R 2022-11-01 18:57:52.000000000 +0000 @@ -171,3 +171,38 @@ expect_s3_class(gg, "ggplot") }) + +set.seed(1000009) +test_that("tricube calculations work correctly", { + A <- matrix(runif(1000), ncol=20) + self <- BiocNeighbors::findKNN(A, k=10) + + out <- scater:::.compute_tricube_average(A, indices=self$index, distances=self$distance) + expect_identical(dim(out), dim(A)) + + # Logic checks. + out <- scater:::.compute_tricube_average(A, indices=self$index[,1,drop=FALSE], distances=self$distance[,1,drop=FALSE]) + expect_identical(out, A[self$index[,1],]) + + uni.dist <- self$distance + uni.dist[] <- 1 + out <- scater:::.compute_tricube_average(A, indices=self$index, distances=uni.dist) + assembly <- A + for (i in seq_len(nrow(assembly))) { + assembly[i,] <- colMeans(A[self$index[i,],]) + } + expect_equal(out, assembly) + + uni.index <- self$index + uni.index[] <- seq_len(nrow(A)) + out <- scater:::.compute_tricube_average(A, indices=uni.index, distances=self$distance) + expect_equal(out, A) + + # Silly input checks. + out <- scater:::.compute_tricube_average(A, indices=self$index[,0], distances=self$distance[,0]) + expect_identical(dim(out), dim(A)) + expect_true(all(out==0)) + + out <- scater:::.compute_tricube_average(A[0,], indices=self$index[0,], distances=self$distance[0,]) + expect_identical(dim(out), c(0L, ncol(A))) +}) diff -Nru r-bioc-scater-1.24.0+ds/tests/testthat/test-red-dim.R r-bioc-scater-1.26.1+ds/tests/testthat/test-red-dim.R --- r-bioc-scater-1.24.0+ds/tests/testthat/test-red-dim.R 2022-04-26 18:14:17.000000000 +0000 +++ r-bioc-scater-1.26.1+ds/tests/testthat/test-red-dim.R 2022-11-01 18:57:52.000000000 +0000 @@ -584,3 +584,31 @@ # expect_error(runDiffusionMap(normed), NA) expect_error(runMDS(normed), NA) }) + +test_that("projectReducedDim works as expected", { + example_sce <- mockSCE() + example_sce <- logNormCounts(example_sce) + example_sce <- runUMAP(example_sce) + example_sce <- runPCA(example_sce) + + example_sce_new <- mockSCE() + example_sce_new <- logNormCounts(example_sce_new) + example_sce_new <- runPCA(example_sce_new) + + projected <- projectReducedDim( + reducedDim(example_sce, "PCA"), + reducedDim(example_sce_new, "PCA"), + reducedDim(example_sce, "UMAP") + ) + projected_sce <- projectReducedDim( + example_sce_new, + example_sce, + "UMAP" + ) + expect_equal(projected, reducedDim(projected_sce, "UMAP")) + expect_true( + min(projected) > min(reducedDim(example_sce, "UMAP")), + max(projected) < max(reducedDim(example_sce, "UMAP")), + ) + +})