Mercurial > repos > prog > lcmsmatching
annotate spec-dist.R @ 4:b34c14151f25 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 494194bb501d1d7033613131865f7bd68976041c
author | prog |
---|---|
date | Tue, 14 Mar 2017 12:40:22 -0400 |
parents | 20d69a062da3 |
children |
rev | line source |
---|---|
2
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
1 #dyn.load('src/closeMatchPpm.dll') |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
2 # commented out for refactoring as package |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
3 #dyn.load('src/closeMatchPpm.so') |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
4 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
5 matchPpm <- function(x, y, ppm = 3, mzmin = 0) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
6 if (any(is.na(y))) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
7 stop("NA's are not allowed in y !\n") |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
8 ok <- !(is.na(x)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
9 ans <- order(x) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
10 keep <- seq_along(ok)[ok] |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
11 xidx <- ans[ans %in% keep] |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
12 xs <- x[xidx] |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
13 yidx <- order(y) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
14 ys <- y[yidx] |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
15 if (!is.double(xs)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
16 xs <- as.double(xs) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
17 if (!is.double(ys)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
18 ys <- as.double(ys) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
19 if (!is.integer(xidx)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
20 xidx <- as.integer(xidx) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
21 if (!is.integer(yidx)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
22 yidx <- as.integer(yidx) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
23 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
24 fm <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
25 .Call( |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
26 "closeMatchPpm", |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
27 xs, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
28 ys, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
29 xidx, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
30 yidx, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
31 as.integer(length(x)), |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
32 as.double(ppm), |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
33 as.double(mzmin) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
34 ) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
35 fm |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
36 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
37 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
38 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
39 simpList <- function(v) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
40 vapply(v, function(x) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
41 if (is.null(x)) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
42 -1 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
43 } else{ |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
44 x |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
45 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
46 }, FUN.VALUE = -1) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
47 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
48 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
49 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
50 ##Stein and scott values : mzexp 3 intexp 0.6 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
51 ##Massbank values : mzexp 2 intexp 0.5 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
52 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
53 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
54 cosine <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
55 function(mz1, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
56 mz2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
57 int1, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
58 int2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
59 mzexp = 2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
60 intexp = 0.5, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
61 ppm, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
62 dmz = 0.005) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
63 matchList <- matchPpm(mz1, mz2, ppm, dmz) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
64 ###Weigthed intensity |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
65 pfound <- which(!sapply(matchList, is.null, simplify = TRUE)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
66 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
67 ###If no peak is found. |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
68 if (length(pfound) == 0) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
69 return(list(measure = 0, matched = rep(-1, length(mz1)))) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
70 w1 <- int1 ^ intexp * mz1 ^ mzexp |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
71 w2 <- int2 ^ intexp * mz2 ^ mzexp |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
72 cat(w1[pfound], w2[unlist(matchList[pfound])],'\n') |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
73 cos_value <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
74 sum((w1[pfound] * w2[unlist(matchList[pfound])]) ^ 2) / (sum(w1[pfound] ^ |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
75 2) * sum(w2[unlist(matchList[pfound])] ^ 2)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
76 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
77 ####Adding the penality if needed. |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
78 list(measure = cos_value, matched = simpList(matchList)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
79 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
80 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
81 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
82 ###penalized cosine |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
83 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
84 wcosine <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
85 function(mz1, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
86 mz2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
87 int1, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
88 int2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
89 mzexp = 2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
90 intexp = 0.5, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
91 ppm, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
92 dmz = 0.005, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
93 penality = c("rweigth")) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
94 penality <- match.arg(penality) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
95 matchList <- matchPpm(mz1, mz2, ppm, dmz) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
96 ###Weigthed intensity |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
97 pfound <- which(!sapply(matchList, is.null, simplify = TRUE)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
98 ###If no peak is found. |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
99 if (length(pfound) == 0) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
100 return(list(measure = 0, matched = rep(-1, length(mz1)))) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
101 w1 <- int1 ^ intexp * mz1 ^ mzexp |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
102 w2 <- int2 ^ intexp * mz2 ^ mzexp |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
103 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
104 cos_value <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
105 sum((w1[pfound] * w2[unlist(matchList[pfound])]) ^ 2) / (sum(w1[pfound] ^ |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
106 2) * sum(w2[unlist(matchList[pfound])] ^ 2)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
107 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
108 if(is.nan(cos_value)) cos_value <- 0 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
109 ####Adding the penality if needed. |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
110 div = 1 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
111 if (penality == "rweigth") { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
112 p <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
113 (sum(w1[pfound]) / sum(w1) + sum(w2[unlist(matchList[pfound])]) / sum(w2)) / |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
114 2 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
115 div = 2 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
116 } else{ |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
117 p <- 0 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
118 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
119 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
120 measure <- (cos_value + p) / div |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
121 if(is.nan(measure)) measure <- (cos_value) / div |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
122 list(measure = measure, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
123 matched = simpList(matchList)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
124 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
125 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
126 ##A gaussian of the two spectra seen as a mixture of gaussian, derived form Heinonen et al 2012 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
127 pkernel <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
128 function(mz1, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
129 mz2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
130 int1, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
131 int2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
132 mzexp = 2, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
133 intexp = 0.5, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
134 ppm, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
135 dmz = 0.005, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
136 sigint = 0.5, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
137 penality = c("rweigth")) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
138 ###We first match the peak |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
139 matchList <- matchPpm(mz1, mz2, ppm, dmz) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
140 # ###Weigthed intensity |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
141 pfound <- which(!sapply(matchList, is.null, simplify = TRUE)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
142 # |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
143 ###If no peak is found. |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
144 if (length(pfound) == 0) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
145 return(list(measure = 0, matched = rep(-1, length(mz1)))) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
146 w1 <- int1 ^ intexp * mz1 ^ mzexp |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
147 w2 <- int2 ^ intexp * mz2 ^ mzexp |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
148 w1 <- w1 * 1 / sum(w1) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
149 w2 <- w2 * 1 / sum(w2) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
150 l1 <- length(w1) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
151 l2 <- length(w2) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
152 ###The mz dev |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
153 vsig1 = mz1 * ppm * 3 * 10 ^ -6 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
154 vsig1 = sapply(vsig1, function(x, y) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
155 return(max(x, y)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
156 }, y = dmz) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
157 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
158 vsig2 = mz2 * ppm * 3 * 10 ^ -6 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
159 vsig2 = sapply(vsig2, function(x, y) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
160 return(max(x, y)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
161 }, y = dmz) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
162 accu = 0 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
163 ###TO DO rcopder en C |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
164 for (i in 1:l1) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
165 for (j in 1:l2) { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
166 divisor = max(stats::dnorm( |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
167 mz1[i], |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
168 mean = mz1[i], |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
169 sd = sqrt(vsig1[i] ^ 2 + vsig1[i] ^ 2) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
170 ), |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
171 stats::dnorm( |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
172 mz2[j], |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
173 mean = mz2[j], |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
174 sd = sqrt(vsig2[j] ^ 2 + vsig2[j] ^ 2) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
175 )) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
176 if (divisor == 0) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
177 next |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
178 scalet = stats::dnorm(mz1[i], |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
179 mean = mz2[j], |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
180 sd = sqrt(vsig1[i] ^ 2 + vsig2[j] ^ 2)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
181 accu = accu + scalet / divisor |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
182 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
183 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
184 div = 1 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
185 if (penality == "rweigth") { |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
186 p <- |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
187 (sum(w1[pfound]) / sum(w1) + sum(w2[unlist(matchList[pfound])]) / sum(w2)) / |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
188 2 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
189 div = 2 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
190 } else{ |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
191 p <- 0 |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
192 } |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
193 accu = accu / (l2 * l1) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
194 list(measure = (accu + p) / div, |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
195 matched = simpList(matchList)) |
20d69a062da3
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
prog
parents:
diff
changeset
|
196 } |