Skip to content

Commit 417c5fa

Browse files
committed
tss
1 parent 0d62325 commit 417c5fa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

R/NMF.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
#' When estimate is TRUE, only the error matrix is returned.
2121
#' @param nnlm_args arguments passed to NNLM functions
2222
#' @param nnlm_na_perc NA frequency when the cross-validation is performed.
23+
#' @param tss perform total sum scaling to the matrix
2324
#' @importFrom NMF nmf nmfEstimateRank
2425
#' @export
2526
NMF <- function(stana, species, rank=3, target="KO", seed=53, method="snmf/r",
2627
deleteZeroDepth=FALSE, beta=0.01, estimate=FALSE, estimate_range=1:6, nnlm_flag=FALSE,
27-
nnlm_args=list(), nnlm_na_perc=0.3) {
28+
nnlm_args=list(), nnlm_na_perc=0.3, tss=FALSE) {
2829

2930
## References for the missing value handling in NMF:
3031
## https://github.com/scikit-learn/scikit-learn/pull/8474
@@ -51,20 +52,24 @@ NMF <- function(stana, species, rank=3, target="KO", seed=53, method="snmf/r",
5152
nnlm_flag <- TRUE
5253
}
5354
}
55+
if (tss) {
56+
cat_subtle("# Performing TSS\n")
57+
mat <- apply(mat, 2, function(x) x / sum(x))
58+
}
5459
cat_subtle("# Original features: ", dim(mat)[1], "\n", sep="")
5560
cat_subtle("# Original samples: ", dim(mat)[2], "\n", sep="")
5661
if (!nnlm_flag) {
5762
mat <- mat[apply(mat, 1, function(x) sum(x)!=0),]
5863
mat <- mat[,apply(mat, 2, function(x) sum(x)!=0)]
5964

60-
cat_subtle("# Filtered features:", dim(mat)[1], "\n", sep="")
61-
cat_subtle("# Filtered samples:", dim(mat)[2], "\n", sep="")
65+
cat_subtle("# Filtered features: ", dim(mat)[1], "\n", sep="")
66+
cat_subtle("# Filtered samples: ", dim(mat)[2], "\n", sep="")
6267
}
6368

6469
## Test multiple ranks
6570
if (estimate) {
6671
if (nnlm_flag) {
67-
cat_subtle("# NNLM flag enabled, the cross-validation error matrix only will be returned.\n")
72+
cat_subtle("# NNLM flag enabled, the error matrix only will be returned.\n")
6873
## Following the vignette procedures in NNLM
6974
## Comparing the MSE and randomly assigned missing values
7075
A <- as.matrix(mat)

0 commit comments

Comments
 (0)