Skip to content

Commit

Permalink
Solves #17
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-jimenez committed Dec 17, 2021
1 parent 9c5709b commit bf8f0cc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions R/Score.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,20 @@ bcScore <- function(sc, gs, expr.thres = 0.1) {
}))
rownames(below.thres) <- names(gs@genelist)
below.thres <- below.thres[, colnames(expr.matrix)]
# If all cells are below the threshold, remove that signature and raise a
# warning
nan.rows.idx <- which(rowSums(below.thres) == ncol(below.thres))
if (length(nan.rows.idx) > 0) {
warning(paste0("The following signatures have no cells that pass the ",
"expr.thres and will be removed: ",
paste0(rownames(below.thres)[nan.rows.idx], collapse = ", "),
"."))
below.thres <- below.thres[-nan.rows.idx, ]
gs@genelist <- gs@genelist[-nan.rows.idx]
}
# BCS.
bcs <- lapply(seq_along(gs@mode), function(j) {
score <- t(sapply(1:len.gs, function(k) {
score <- t(sapply(1:length(gs@genelist), function(k) {
### Common genes between the expr.marix and each signature.
common.genes <- unique(intersect(genes, gs@genelist[[k]][[gs@mode[j]]]))
### Subset expr.matrix with common.genes.
Expand All @@ -109,7 +120,7 @@ bcScore <- function(sc, gs, expr.thres = 0.1) {
### Normalized BCS.
norm.score <- raw * ((sum.expr - sig.stdev)/(raw + sig.stdev))
### Update the progress bar.
step <- len.gs + (j - 1) * len.gs + k
step <- len.gs + (j - 1) * len.gs + k + length(nan.rows.idx)
if (step%%bins == 0 | step == total) {
Sys.sleep(0.1)
setTxtProgressBar(pb, value = step)
Expand Down

0 comments on commit bf8f0cc

Please sign in to comment.