diff --git a/R/ModuleScore.R b/R/ModuleScore.R index b143f48f..466e9a4f 100644 --- a/R/ModuleScore.R +++ b/R/ModuleScore.R @@ -148,32 +148,46 @@ addModuleScore <- function( #Figure out the index numbers of the selected features within the given matrix if(grepl(":",unlist(features)[1])){ - sname <- stringr::str_split(unlist(features),pattern=":",simplify=TRUE)[,1] - name <- stringr::str_split(unlist(features),pattern=":",simplify=TRUE)[,2] - - idx <- lapply(seq_along(name), function(x){ - ix <- intersect( - which(tolower(name[x]) == tolower(featureDF$name)), - BiocGenerics::which(tolower(sname[x]) == tolower(featureDF$seqnames)) - ) - if(length(ix)==0){ - .logStop(sprintf("FeatureName (%s) does not exist! See available features using getFeatures()", name[x]), logFile = logFile) + idx <- lapply(seq_along(features), function(x){ + sname <- stringr::str_split(features[[x]], pattern=":", simplify=TRUE)[,1] + fname <- stringr::str_split(features[[x]], pattern=":", simplify=TRUE)[,2] + + ix <- vapply(seq_along(fname), function(z){ + hit <- intersect( + which(tolower(fname[z]) == tolower(featureDF$name)), + BiocGenerics::which(tolower(sname[z]) == tolower(featureDF$seqnames)) + ) + if(length(hit) == 0) return(NA_integer_) + hit[1] + }, integer(1)) + + missing <- features[[x]][is.na(ix)] + if(length(missing) > 0){ + if(all(is.na(ix))){ + .logStop(sprintf("All features (%s) in feature set %s not found! See available features using getFeatures()", paste(missing, collapse = ", "), x), logFile = logFile) + } + .logMessage(sprintf("Warning: %d of %d features not found and will be omitted: %s", length(missing), length(ix), paste(missing, collapse = ", ")), logFile = logFile) + warning(sprintf("Features not found and will be omitted: %s", paste(missing, collapse = ", "))) + ix <- ix[!is.na(ix)] } ix }) }else{ - idx <- lapply(seq_along(unlist(features)), function(x){ - - ix <- which(tolower(unlist(features)[x]) == tolower(featureDF$name))[1] - - if(length(ix) == 0){ - .logStop(sprintf("FeatureName (%s) no regions found overlapping! See available features using getFeatures()", unlist(features)[x]), logFile = logFile) + idx <- lapply(seq_along(features), function(x){ + + ix <- match(tolower(features[[x]]), tolower(featureDF$name)) + missing <- features[[x]][is.na(ix)] + if(length(missing) > 0){ + if(all(is.na(ix))){ + .logStop(sprintf("All features (%s) in feature set %s not found! See available features using getFeatures()", paste(missing, collapse = ", "), x), logFile = logFile) + } + .logMessage(sprintf("Warning: %d of %d features not found and will be omitted: %s", length(missing), length(ix), paste(missing, collapse = ", ")), logFile = logFile) + warning(sprintf("Features not found and will be omitted: %s", paste(missing, collapse = ", "))) + ix <- ix[!is.na(ix)] } - ix - }) } @@ -184,7 +198,7 @@ addModuleScore <- function( stop("Feature Input is Not A GRanges object!") } - idx <- lapply(seq_along(unlist(features)), function(x){ + idx <- lapply(seq_along(features), function(x){ #Check o <- tryCatch({GenomeInfoDb::seqlevelsStyle(features[[x]]) <- "UCSC"}, warning = function(w) 0, error = function(e) 0) @@ -192,8 +206,8 @@ addModuleScore <- function( #Overlaps ix <- which(overlapsAny(featureData, features[[x]], ignore.strand=TRUE)) - if(length(ix)==0){ - .logStop(sprintf("FeatureName (%s) does not exist! See available features using getFeatures()", unlist(features)[x]), logFile = logFile) + if(length(ix) == 0){ + .logStop(sprintf("All GRanges features in feature set %s have no overlapping regions! See available features using getFeatures()", x), logFile = logFile) } ix diff --git a/R/RNAIntegration.R b/R/RNAIntegration.R index 209aaa4d..8854a7b3 100644 --- a/R/RNAIntegration.R +++ b/R/RNAIntegration.R @@ -531,7 +531,7 @@ addGeneIntegrationMatrix <- function( if(addToArrow){ .logDiffTime(sprintf("%s Seurat TransferData GeneMatrix", prefix), tstart, verbose = verbose, logFile = logFile) - transferParams$refdata <- GetAssayData(subRNA, assay = "RNA", slot = "data") + transferParams$refdata <- GetAssayData(subRNA, assay = "RNA", layer = "data") gc() matchedRNA <- do.call(Seurat::TransferData, transferParams) matchedRNA <- matchedRNA@data