From a05dd47343c9bc8d9d5c6e61ce47903b0af74aab Mon Sep 17 00:00:00 2001 From: YonghuiDong Date: Mon, 8 Feb 2021 14:33:15 +0200 Subject: [PATCH] update contam() and getMax() functions --- .gitignore | 1 + NAMESPACE | 2 +- R/contaminant.R | 2 +- R/doStat.R | 2 +- R/{getSname.R => getMax.R} | 11 +++++++---- man/contam.Rd | 6 +++--- man/{getSname.Rd => getMax.Rd} | 10 +++++----- 7 files changed, 19 insertions(+), 15 deletions(-) rename R/{getSname.R => getMax.R} (78%) rename man/{getSname.Rd => getMax.Rd} (79%) diff --git a/.gitignore b/.gitignore index f732fe3..a3116e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .Rproj.user .Rhistory .RData +.RDataTmp .Ruserdata .Rbuildignore diff --git a/NAMESPACE b/NAMESPACE index 68c2352..9cdf479 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,9 +10,9 @@ export(doNormalization) export(doStat) export(getCV) export(getFC) +export(getMax) export(getOPLSDA) export(getP) -export(getSname) export(mass) export(mz) export(ppm) diff --git a/R/contaminant.R b/R/contaminant.R index 4e094f2..4d90df5 100644 --- a/R/contaminant.R +++ b/R/contaminant.R @@ -9,7 +9,7 @@ #' contam(33.0335, ppm = 10, mode = '+') #' contam(44.998, ppm = 10, mode = '-') -contam <- function (mz, ppm = 10, mode = c('+', '-')) { +contam <- function (mz, mode = NULL, ppm = 10) { ##(1) input check if(is.numeric(mz) == FALSE) {stop("Warning: mass to charge ratio mz shoule be numeric!")} diff --git a/R/doStat.R b/R/doStat.R index 1cc9b97..a9a730b 100644 --- a/R/doStat.R +++ b/R/doStat.R @@ -12,7 +12,7 @@ doStat <- function(x, Group = NULL){ cat("\nPerforming statistics: \n") - maxSample <- getSname(x) + maxSample <- getMax(x) myCV <- getCV(x, Group = Group) myFC <- getFC(x, Group = Group) myP <- getP(x, Group = Group) diff --git a/R/getSname.R b/R/getMax.R similarity index 78% rename from R/getSname.R rename to R/getMax.R index b2bd8b4..99e5977 100644 --- a/R/getSname.R +++ b/R/getMax.R @@ -6,18 +6,21 @@ #' @examples #' dat <- cbind.data.frame(mz = c(100, 101, 300), mz2 = c(0, 0 , 1), mz3 = c(1, 9, 1)) #' rownames(dat) <- c("A", "B", "C") -#' out <- getSname(dat) +#' out <- getMax(dat) -getSname <- function(x){ +getMax <- function(x){ cat("\n- Geting sample name with max intensity...\n") - ## get the sample name which has the max intensity of each m/z. + ## get the sample name which has the max intensity of each m/z + ## get the max peak intensity/area ## It is useful for further manual identification tmp <- t(x) if(is.null(colnames(tmp))) stop("No sample names found") sample_index <- as.matrix(apply(tmp, 1, which.max)) sample_index <- as.vector(sample_index, mode = "numeric") sample_name <- colnames(tmp)[sample_index] - return(sample_name) + max_Int <- apply(tmp, 1, max) + max_Result <- cbind.data.frame(maxSample = sample_name, maxInt = max_Int) + return(max_Result) cat("done"); } diff --git a/man/contam.Rd b/man/contam.Rd index 547da89..536d718 100644 --- a/man/contam.Rd +++ b/man/contam.Rd @@ -4,14 +4,14 @@ \alias{contam} \title{Contaminants in MS} \usage{ -contam(mz, ppm = 10, mode = c("+", "-")) +contam(mz, mode = NULL, ppm = 10) } \arguments{ \item{mz}{suspected m/z value} -\item{ppm}{mass tolerance, default value = 10} - \item{mode}{ionization mode, either positive '+' or negative '-'} + +\item{ppm}{mass tolerance, default value = 10} } \description{ check the possible contaminants diff --git a/man/getSname.Rd b/man/getMax.Rd similarity index 79% rename from man/getSname.Rd rename to man/getMax.Rd index ddfc2f4..11928f9 100644 --- a/man/getSname.Rd +++ b/man/getMax.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getSname.R -\name{getSname} -\alias{getSname} +% Please edit documentation in R/getMax.R +\name{getMax} +\alias{getMax} \title{Get the sample name which has the max ion intensity} \usage{ -getSname(x) +getMax(x) } \arguments{ \item{x}{sample ion intensity matrix, row sample, column feature.} @@ -18,5 +18,5 @@ get the sample name which has the max ion intensity \examples{ dat <- cbind.data.frame(mz = c(100, 101, 300), mz2 = c(0, 0 , 1), mz3 = c(1, 9, 1)) rownames(dat) <- c("A", "B", "C") -out <- getSname(dat) +out <- getMax(dat) }