From e008328cb634a266b30b25841b3d36d987263af1 Mon Sep 17 00:00:00 2001 From: Ryan Corces Date: Wed, 25 May 2022 09:22:40 -0700 Subject: [PATCH 1/7] add marker subsetting to plotMarkerHeatMap --- R/MarkerFeatures.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index c0e655f6..e077744b 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -823,6 +823,8 @@ markerHeatmap <- function(...){ #' @param pal A custom continuous palette from `ArchRPalettes` (see `paletteContinuous()`) used to override the default continuous palette for the heatmap. #' @param binaryClusterRows A boolean value that indicates whether a binary sorting algorithm should be used for fast clustering of heatmap rows. #' @param clusterCols A boolean value that indicates whether the columns of the marker heatmap should be clustered. +#' @param subsetMarkers A vector of rownames from seMarker to use for subsetting of seMarker to only plot specific features on the heatmap. +#' Note that these rownames are expected to be integers that come from `rownames(rowData(seMarker))`. #' @param labelMarkers A character vector listing the `rownames` of `seMarker` that should be labeled on the side of the heatmap. #' @param nLabel An integer value that indicates whether the top `n` features for each column in `seMarker` should be labeled on the side of the heatmap. #' @param nPrint If provided `seMarker` is from "GeneScoreMatrix" print the top n genes for each group based on how uniquely up-regulated the gene is. @@ -847,6 +849,7 @@ plotMarkerHeatmap <- function( pal = NULL, binaryClusterRows = TRUE, clusterCols = TRUE, + subsetMarkers = NULL, labelMarkers = NULL, nLabel = 15, nPrint = 15, @@ -919,6 +922,11 @@ plotMarkerHeatmap <- function( }else{ idx <- which(rowSums(passMat, na.rm = TRUE) > 0 & matrixStats::rowVars(mat) != 0 & !is.na(matrixStats::rowVars(mat))) } + + if(!is.null(subsetMarkers)) { + idx <- subsetMarkers + } + mat <- mat[idx,,drop=FALSE] passMat <- passMat[idx,,drop=FALSE] From eaa15993b4fdae69cacd9fd03d74c5aa8c230cc8 Mon Sep 17 00:00:00 2001 From: Ryan Corces Date: Wed, 25 May 2022 09:34:13 -0700 Subject: [PATCH 2/7] remove printing of marker genes when subsetMarkers is used --- R/MarkerFeatures.R | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index e077744b..5cecbb36 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -959,15 +959,19 @@ plotMarkerHeatmap <- function( } spmat <- passMat / rowSums(passMat) - if(metadata(seMarker)$Params$useMatrix == "GeneScoreMatrix"){ - message("Printing Top Marker Genes:") - for(x in seq_len(ncol(spmat))){ - genes <- head(order(spmat[,x], decreasing = TRUE), nPrint) - message(colnames(spmat)[x], ":") - message("\t", paste(as.vector(rownames(mat)[genes]), collapse = ", ")) + #only print out identified marker genes if subsetMarkers is NULL + if(is.null(subsetMarkers)) { + if(metadata(seMarker)$Params$useMatrix == "GeneScoreMatrix"){ + message("Printing Top Marker Genes:") + for(x in seq_len(ncol(spmat))){ + genes <- head(order(spmat[,x], decreasing = TRUE), nPrint) + message(colnames(spmat)[x], ":") + message("\t", paste(as.vector(rownames(mat)[genes]), collapse = ", ")) + } } } + if(is.null(labelMarkers)){ labelMarkers <- lapply(seq_len(ncol(spmat)), function(x){ as.vector(rownames(mat)[head(order(spmat[,x], decreasing = TRUE), nLabel)]) From d74445f35cbce0e1bb4eb150111e507110b98951 Mon Sep 17 00:00:00 2001 From: Ryan Corces Date: Wed, 25 May 2022 09:43:38 -0700 Subject: [PATCH 3/7] update param def for subsetMarkers --- R/MarkerFeatures.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index 5cecbb36..94adfac6 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -824,7 +824,8 @@ markerHeatmap <- function(...){ #' @param binaryClusterRows A boolean value that indicates whether a binary sorting algorithm should be used for fast clustering of heatmap rows. #' @param clusterCols A boolean value that indicates whether the columns of the marker heatmap should be clustered. #' @param subsetMarkers A vector of rownames from seMarker to use for subsetting of seMarker to only plot specific features on the heatmap. -#' Note that these rownames are expected to be integers that come from `rownames(rowData(seMarker))`. +#' Note that these rownames are expected to be integers that come from `rownames(rowData(seMarker))`. If this parameter is used for +#' subsetting, then the values provided to `cutOff` are effectively ignored. #' @param labelMarkers A character vector listing the `rownames` of `seMarker` that should be labeled on the side of the heatmap. #' @param nLabel An integer value that indicates whether the top `n` features for each column in `seMarker` should be labeled on the side of the heatmap. #' @param nPrint If provided `seMarker` is from "GeneScoreMatrix" print the top n genes for each group based on how uniquely up-regulated the gene is. From 03a8d6b8b9cbb9ced2b13d5491287f9f29a43ed1 Mon Sep 17 00:00:00 2001 From: Ryan Corces Date: Wed, 25 May 2022 09:44:26 -0700 Subject: [PATCH 4/7] add validInput for subsetMarkers --- R/MarkerFeatures.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index 94adfac6..7d3a2657 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -872,6 +872,7 @@ plotMarkerHeatmap <- function( .validInput(input = pal, name = "pal", valid = c("character", "null")) .validInput(input = binaryClusterRows, name = "binaryClusterRows", valid = c("boolean")) .validInput(input = clusterCols, name = "clusterCols", valid = c("boolean")) + .validInput(input = subsetMarkers, name = "subsetMarkers", valid = c("integer", "null")) .validInput(input = labelMarkers, name = "labelMarkers", valid = c("character", "null")) .validInput(input = nLabel, name = "nLabel", valid = c("integer", "null")) .validInput(input = nPrint, name = "nPrint", valid = c("integer", "null")) From b3dd16436fcde4aeb3a5b3e20343e248ec34679f Mon Sep 17 00:00:00 2001 From: Ryan Corces Date: Wed, 25 May 2022 09:48:57 -0700 Subject: [PATCH 5/7] catch problematic inputs to subsetMarkers --- R/MarkerFeatures.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index 7d3a2657..2e59051c 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -926,7 +926,12 @@ plotMarkerHeatmap <- function( } if(!is.null(subsetMarkers)) { - idx <- subsetMarkers + if(length(which(subsetMarkers %ni% 1:nrow(mat)))){ + idx <- subsetMarkers + } else { + stop("Rownames / indices provided to the subsetMarker parameter are outside of the boundaries of seMarker.") + } + } mat <- mat[idx,,drop=FALSE] From 80d57bb2e9309263beead385aa5c967aea783f39 Mon Sep 17 00:00:00 2001 From: Ryan Corces Date: Wed, 25 May 2022 09:50:03 -0700 Subject: [PATCH 6/7] fix if statement typo --- R/MarkerFeatures.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index 2e59051c..fe914ec5 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -926,7 +926,7 @@ plotMarkerHeatmap <- function( } if(!is.null(subsetMarkers)) { - if(length(which(subsetMarkers %ni% 1:nrow(mat)))){ + if(length(which(subsetMarkers %ni% 1:nrow(mat))) > 0){ idx <- subsetMarkers } else { stop("Rownames / indices provided to the subsetMarker parameter are outside of the boundaries of seMarker.") From 673943f1cae2e32060939f2ca773386f726bc98f Mon Sep 17 00:00:00 2001 From: Ryan Corces Date: Wed, 25 May 2022 09:50:33 -0700 Subject: [PATCH 7/7] fix if statement typo --- R/MarkerFeatures.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/MarkerFeatures.R b/R/MarkerFeatures.R index fe914ec5..69879538 100644 --- a/R/MarkerFeatures.R +++ b/R/MarkerFeatures.R @@ -926,7 +926,7 @@ plotMarkerHeatmap <- function( } if(!is.null(subsetMarkers)) { - if(length(which(subsetMarkers %ni% 1:nrow(mat))) > 0){ + if(length(which(subsetMarkers %ni% 1:nrow(mat))) == 0){ idx <- subsetMarkers } else { stop("Rownames / indices provided to the subsetMarker parameter are outside of the boundaries of seMarker.")