Skip to content

Commit

Permalink
add rm.zero option
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokwee committed Nov 7, 2024
1 parent 8e4059f commit 2eebc6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions R/pgx-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,8 @@ make_unique <- function(s, sep = "") {
s
}

#' Check if values are logarithm
#'
#' @export
is_logged <- function(x, verbose = 0) {
## force as matrix
Expand Down
19 changes: 12 additions & 7 deletions R/pgx-normalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,19 @@ NORMALIZATION.METHODS <- c("none", "mean.center", "median.center", "sum", "CPM",
#' normalized <- pgx.countNormalization(counts, c("TMM", "RLE"))
#' }
#' @export
pgx.countNormalization <- function(x, methods, ref = NULL) {
pgx.countNormalization <- function(x, methods, ref = NULL, rm.zero=FALSE) {
## Column-wise normalization (along samples).
## x: counts (linear)
## method: single method

methods <- methods[1]
## which.zero <- which(x == 0, arr.ind = TRUE)
## x1 <- x
## x1[which.zero] <- NA


if(rm.zero) {
minx <- min(x,na.rm = TRUE)
which.zero <- which(x == minx, arr.ind = TRUE)
x[which.zero] <- NA
}

for (m in methods) {
if (m == "none") {
x <- x
Expand Down Expand Up @@ -227,8 +230,10 @@ pgx.countNormalization <- function(x, methods, ref = NULL) {
}
}

## put back zeros as zeros
## x[which.zero] <- 0
if(rm.zero) {
## put back zeros as zeros
x[which.zero] <- minx
}
return(x)
}

Expand Down

0 comments on commit 2eebc6f

Please sign in to comment.