Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions R/ModuleScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

})

}
Expand All @@ -184,16 +198,16 @@ 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)

#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
Expand Down
2 changes: 1 addition & 1 deletion R/RNAIntegration.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down