Skip to content

Commit

Permalink
update contam() and getMax() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
YonghuiDong committed Feb 8, 2021
1 parent 8b341c8 commit a05dd47
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.Rproj.user
.Rhistory
.RData
.RDataTmp
.Ruserdata
.Rbuildignore
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/contaminant.R
Original file line number Diff line number Diff line change
Expand Up @@ -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!")}
Expand Down
2 changes: 1 addition & 1 deletion R/doStat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions R/getSname.R → R/getMax.R
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
6 changes: 3 additions & 3 deletions man/contam.Rd

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

10 changes: 5 additions & 5 deletions man/getSname.Rd → man/getMax.Rd

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

0 comments on commit a05dd47

Please sign in to comment.