From 8092a9989917104744098eead7cd441047c46df7 Mon Sep 17 00:00:00 2001 From: noriakis <31095487+noriakis@users.noreply.github.com> Date: Tue, 22 Oct 2024 22:41:37 +0900 Subject: [PATCH] doc updates --- NAMESPACE | 1 + R/NMF.R | 18 ++++++++++++------ R/utils.R | 7 +++++-- man/plotAbundanceWithinSpecies.Rd | 5 ++++- man/plotStackedBarPlot.Rd | 6 ++++-- man/scaler.NNLM.Rd | 19 +++++++++++++++++++ 6 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 man/scaler.NNLM.Rd diff --git a/NAMESPACE b/NAMESPACE index 3607c8d..d0e7f6e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -68,6 +68,7 @@ export(plotStackedBarPlot) export(rankComponents) export(returnGenes) export(reverseAnnot) +export(scaler.NNLM) export(setAnnotation) export(setGroup) export(setMap) diff --git a/R/NMF.R b/R/NMF.R index 824082e..250518a 100644 --- a/R/NMF.R +++ b/R/NMF.R @@ -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") } @@ -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)) @@ -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) @@ -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) { diff --git a/R/utils.R b/R/utils.R index dba3b08..7f18f89 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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)) diff --git a/man/plotAbundanceWithinSpecies.Rd b/man/plotAbundanceWithinSpecies.Rd index 691e281..8bb5a9b 100644 --- a/man/plotAbundanceWithinSpecies.Rd +++ b/man/plotAbundanceWithinSpecies.Rd @@ -9,7 +9,8 @@ plotAbundanceWithinSpecies( species, tss = TRUE, return_data = FALSE, - by = "NMF" + by = "NMF", + mat = NULL ) } \arguments{ @@ -22,6 +23,8 @@ plotAbundanceWithinSpecies( \item{return_data}{return only the data, not plot} \item{by}{NMF or coef matrix set to `coefMat` slot} + +\item{mat}{matrix (row factor column sample) of H} } \value{ ggplot object diff --git a/man/plotStackedBarPlot.Rd b/man/plotStackedBarPlot.Rd index 61e302e..475f536 100644 --- a/man/plotStackedBarPlot.Rd +++ b/man/plotStackedBarPlot.Rd @@ -4,14 +4,16 @@ \alias{plotStackedBarPlot} \title{plotStackedBarPlot} \usage{ -plotStackedBarPlot(stana, sp, by = "NMF") +plotStackedBarPlot(stana, sp, by = "NMF", mat = NULL) } \arguments{ \item{stana}{stana boject} \item{sp}{species} -\item{by}{"NMF" or "coef"} +\item{by}{"NMF", "manual", or "coef"} + +\item{mat}{manual matrix} } \value{ ggplot diff --git a/man/scaler.NNLM.Rd b/man/scaler.NNLM.Rd new file mode 100644 index 0000000..5fb2c33 --- /dev/null +++ b/man/scaler.NNLM.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{scaler.NNLM} +\alias{scaler.NNLM} +\title{scaler.NNLM} +\usage{ +scaler.NNLM(nmf, target = "coef") +} +\arguments{ +\item{nmf}{NNLM object} + +\item{target}{coef or basis} +} +\value{ +list +} +\description{ +scaler.NNLM +}