-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.R
33 lines (30 loc) · 1.07 KB
/
helpers.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
percentageA <- function(peaklist) {
per1 = sum(!is.na(peaklist$an1))
per2 = sum(!is.na(peaklist$an2))
per3 = sum(!is.na(peaklist$an3))
per4 = sum(!is.na(peaklist$an4))
per5 = sum(!is.na(peaklist$an5))
meanper <- mean(c(per1,per2,per3,per4,per5))
return(meanper/nrow(peaklist))
}
mastot <- function(peaklist) {
meanmass <- c(length(unique(peaklist$mass1)),
length(unique(peaklist$mass2)),
length(unique(peaklist$mass3)),
length(unique(peaklist$mass4)),
length(unique(peaklist$mass5))
)
return(mean(meanmass))
}
searchmass <- function(peaklist, rtmin, rtmax, mm, ppm) {
rtminC <- peaklist[peaklist$rtmin >= rtmin,]
rtmaxC <- rtminC[rtminC$rtmax <= rtmax,]
rowsC <- unique(unlist(lapply(1:5, function(x) {
mass = paste("mass",x, sep = "")
goodR <- rtmaxC[!is.na(rtmaxC[,mass]),]
error <- abs(goodR[,mass]-mm)/mm
pos <- which(sqrt(2)*error < ppm*1e-6)
candidates <- rownames(goodR[pos,])
})))
return(rowsC)
}