Skip to content

Commit

Permalink
Bugfix to PlotMarkerSeries when no matching features are found (#125)
Browse files Browse the repository at this point in the history
* Bugfix to PlotMarkerSeries when no matching features are found
  • Loading branch information
bbimber authored Jan 29, 2025
1 parent 662c965 commit a219af9
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions R/Phenotyping.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ PlotImmuneMarkers <- function(seuratObj, reductions = c('tsne', 'umap')) {
#' @import Seurat
PlotMarkerSeries <- function(seuratObj, features, reductions = c('umap'), title = NULL, setSize = 4) {
featuresToPlot <- .FindPlotableFeatures(seuratObj, features)
if (is.null(featuresToPlot)) {
print('None of the requested features were found, aborting')
return()
}

steps <- ceiling(length(featuresToPlot) / setSize) - 1

for (i in 0:steps) {
Expand All @@ -220,8 +225,12 @@ PlotMarkerSeries <- function(seuratObj, features, reductions = c('umap'), title
}

.FindPlotableFeatures <- function(seuratObj, features) {
df <- Seurat::FetchData(seuratObj, vars = unique(features), cells = 1)
return(unique(names(df)))
tryCatch({
df <- Seurat::FetchData(seuratObj, vars = unique(features), cells = 1)
return(unique(names(df)))
}, error = function(e){
return(NULL)
})
}

.RemoveUnchangedOrZero <- function(seuratObj, reduction, features) {
Expand All @@ -245,6 +254,11 @@ PlotMarkerSet <- function(seuratObj, reductions, title, features) {
missingFeats <- c()
for (reduction in reductions) {
featuresToPlot <- .FindPlotableFeatures(seuratObj, features)
if (is.null(featuresToPlot)) {
print('None of the requested features were found, aborting')
return()
}

featuresToPlot <- .RemoveUnchangedOrZero(seuratObj, reduction, featuresToPlot)

if (length(features) != length(featuresToPlot)){
Expand Down

0 comments on commit a219af9

Please sign in to comment.