Skip to content

Commit

Permalink
doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
noriakis committed Oct 22, 2024
1 parent b951111 commit 8092a99
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export(plotStackedBarPlot)
export(rankComponents)
export(returnGenes)
export(reverseAnnot)
export(scaler.NNLM)
export(setAnnotation)
export(setGroup)
export(setMap)
Expand Down
18 changes: 12 additions & 6 deletions R/NMF.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ NMF <- function(stana, species, rank=3, target="kos", seed=53, method="snmf/r",
#'
#' @param stana stana boject
#' @param sp species
#' @param by "NMF" or "coef"
#' @param by "NMF", "manual", or "coef"
#' @param mat manual matrix
#' @return ggplot
#' @export
plotStackedBarPlot <- function(stana, sp, by="NMF") {
plotStackedBarPlot <- function(stana, sp, by="NMF", mat=NULL) {
if (is.null(stana@NMF[[sp]]) & is.null(stana@coefMat[[sp]])) {
stop("NMF results or coefficient matrix should be set")
}
Expand All @@ -193,7 +194,9 @@ plotStackedBarPlot <- function(stana, sp, by="NMF") {
coefMat <- coef(res)
} else if (by=="coef") {
coefMat <- stana@coefMat[[sp]]
} else {
} else if (by=="manual") {
coefMat <- mat
} else {
stop("NMF results or coefficient matrix should be set")
}
relab <- apply(coefMat, 2, function(x) x / sum(x))
Expand Down Expand Up @@ -261,9 +264,10 @@ alphaDiversityWithinSpecies <- function(stana, species, method="shannon", rank=5
#' @param tss perform total sum scaling
#' @param return_data return only the data, not plot
#' @param by NMF or coef matrix set to `coefMat` slot
#' @param mat matrix (row factor column sample) of H
#' @export
#' @return ggplot object
plotAbundanceWithinSpecies <- function(stana, species, tss=TRUE, return_data=FALSE, by="NMF") {
plotAbundanceWithinSpecies <- function(stana, species, tss=TRUE, return_data=FALSE, by="NMF", mat=NULL) {
if (by=="NMF") {
if (is.null(stana@NMF[[species]])) {
stana <- NMF(stana, species)
Expand All @@ -272,8 +276,10 @@ plotAbundanceWithinSpecies <- function(stana, species, tss=TRUE, return_data=FAL
H <- coef(res)
} else if (by=="coef") {
H <- stana@coefMat[[species]]
} else {
stop("NMF or coef should be specified in `by`")
} else if (by=="manual") {
H <- mat
} else {
stop("NMF, manual, or coef should be specified in `by`")
}

if (tss) {
Expand Down
7 changes: 5 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ setGroup <- function(stana, cl) {
}



#' @noRd
#' scaler.NNLM
#' @param nmf NNLM object
#' @param target coef or basis
#' @export
#' @return list
scaler.NNLM <- function(nmf, target="coef") {
if (target=="basis") {
scaledW <- apply(nmf$W, 2, function(x) x / sum(x))
Expand Down
5 changes: 4 additions & 1 deletion man/plotAbundanceWithinSpecies.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/plotStackedBarPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/scaler.NNLM.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8092a99

Please sign in to comment.