Skip to content

Commit

Permalink
Fixed bug where viper and singscore would not run successfully when t…
Browse files Browse the repository at this point in the history
…here was only one custom gene set and the elements in the gene set were duplicated. Here we thank Zedan Zhang for coming up with the bug.
  • Loading branch information
chuiqin committed May 17, 2023
1 parent a205959 commit 5fb5e36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: irGSEA
Type: Package
Title: The integration of single cell rank-based gene set enrichment analysis
Version: 2.1.4
Version: 2.1.5
Author: Chuiqin Fan
Author@R: person("Chuiqin", "Fan", role = c('aut', 'cre'), email = '[email protected]')
Maintainer: Chuiqin Fan <[email protected]>
Expand Down
39 changes: 32 additions & 7 deletions R/irGSEA.score.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ irGSEA.score <- function(object = NULL, assay = NULL, slot = "data",
}

h.gsets.list <- geneset %>% purrr::compact()

# remove duplication
h.gsets.list <- lapply(h.gsets.list, function(x){unique(unlist(x))})

# Filter gene sets by minGSSize and maxGSSize
h.gsets.list2 <- sapply(h.gsets.list, function(x){
length(x) >= minGSSize & length(x) <= maxGSSize
Expand Down Expand Up @@ -1011,13 +1015,34 @@ irGSEA.score <- function(object = NULL, assay = NULL, slot = "data",

viper.scores.list <- list()
for (k in seq_along(my.matrix.list)) {
viper.scores.list[[k]] <- decoupleR::run_viper(mat = as.matrix(my.matrix[, my.matrix.list[[k]]]),
net = net,
.source='source',
.target='target',
.mor='weight',
minsize = minGSSize,
cores = ncores)

if (length(unique(net$source)) == 1) {
net.copy <- rbind(net, net)
net.star <- (0.5 * nrow(net.copy))+1
net.end <- nrow(net.copy)
net.copy$source[net.star:net.end] <- paste0(net$source[1:nrow(net)], "_copy")
viper.scores.list[[k]] <- decoupleR::run_viper(mat = as.matrix(my.matrix[, my.matrix.list[[k]]]),
net = net.copy,
.source='source',
.target='target',
.mor='weight',
minsize = minGSSize,
cores = ncores)
source <- NULL
viper.scores.list[[k]] <- viper.scores.list[[k]] %>%
dplyr::filter(source != unique(paste0(net$source[1:nrow(net)], "_copy")))

}else{
viper.scores.list[[k]] <- decoupleR::run_viper(mat = as.matrix(my.matrix[, my.matrix.list[[k]]]),
net = net,
.source='source',
.target='target',
.mor='weight',
minsize = minGSSize,
cores = ncores)
}


source <- NULL
condition <- NULL
score <- NULL
Expand Down

0 comments on commit 5fb5e36

Please sign in to comment.