Mercurial > repos > mmonsoor > probmetab
annotate lib.r @ 0:e13ec2c3fabe draft
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
author | mmonsoor |
---|---|
date | Mon, 04 Jul 2016 04:29:25 -0400 |
parents | |
children | abcfa1648b66 |
rev | line source |
---|---|
0
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
1 # lib.r ProbMetab version="1.0.0" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
2 # Author: Misharl Monsoor ABIMS TEAM mmonsoor@sb-roscoff.fr |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
3 # Contributors: Yann Guitton and Jean-francois Martin |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
4 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
5 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
6 ##Main probmetab function launch by the Galaxy ProbMetab wrapper |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
7 probmetab = function(xa, xaP, xaN, variableMetadata, variableMetadataP, variableMetadataN, listArguments){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
8 ##ONE MODE ACQUISITION## |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
9 if(listArguments[["mode_acquisition"]]=="one") { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
10 comb=NULL |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
11 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
12 #Get the polarity from xa object |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
13 polarity=xa@polarity |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
14 #SNR option |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
15 if ("xsetnofill" %in% names(listArguments)) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
16 load(listArguments[["xsetnofill"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
17 xsetnofill=xset |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
18 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
19 else{ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
20 xsetnofill=NULL |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
21 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
22 #Exclude samples |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
23 if ("toexclude" %in% names(listArguments)) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
24 toexclude=listArguments[["toexclude"]] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
25 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
26 else { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
27 toexclude=NULL |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
28 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
29 ionAnnot=get.annot(xa, polarity=polarity, allowMiss=listArguments[["allowMiss"]],xset=xsetnofill,toexclude=toexclude) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
30 comb=NULL |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
31 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
32 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
33 ##TWO MODES ACQUISITION## |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
34 #Mode annotatediffreport |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
35 else if(listArguments[["inputs_mode"]]=="two"){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
36 ##Prepare the objects that will be used for the get.annot function |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
37 comb=1 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
38 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
39 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
40 xsetPnofill=NULL |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
41 xsetNnofill=NULL |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
42 # TODO: a reactiver |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
43 #if ("xsetPnofill" %in% names(listArguments)) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
44 # load(listArguments[["xsetPnofill"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
45 # xsetPnofill=xset |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
46 #} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
47 #if ("xsetNnofill" %in% names(listArguments)) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
48 # load(listArguments[["xsetNnofill"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
49 # xsetNnofill=xset |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
50 #} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
51 # include CAMERA non-annotated compounds, and snr retrieval |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
52 # comb 2+ - used on Table 1 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
53 ionAnnotP2plus = get.annot(axP, allowMiss=listArguments[["allowMiss"]], xset=xsetPnofill,toexclude=listArguments[["toexclude"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
54 ionAnnotN2plus = get.annot(axN, polarity="negative", allowMiss=listArguments[["allowMiss"]], xset=xsetNnofill,toexclude=listArguments[["toexclude"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
55 ionAnnot = combineMolIon(ionAnnotP2plus, ionAnnotN2plus) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
56 print(sum(ionAnnot$molIon[,3]==1)) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
57 print(sum(ionAnnot$molIon[,3]==0)) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
58 write.table(ionAnnot[1], sep="\t", quote=FALSE, row.names=FALSE, file="CombineMolIon.tsv") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
59 #Merge variableMetadata Negative and positive acquisitions mode |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
60 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
61 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
62 #Mode combinexsannos TODO bug avec tableau issus de combinexsannos |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
63 #else { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
64 #load(listArguments[["image_combinexsannos"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
65 #image_combinexsannos=cAnnot |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
66 ##Prepare the objects that will be used for the combineMolIon function |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
67 #load(listArguments[["image_pos"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
68 #image_pos=xa |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
69 #ionAnnot=combineMolIon(peaklist=cAnnot, cameraobj=image_pos, polarity="pos") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
70 #} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
71 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
72 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
73 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
74 ##DATABASE MATCHING## |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
75 if (listArguments[["kegg_db"]]=="KEGG"){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
76 DB=build.database.kegg(orgID = NULL) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
77 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
78 else{ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
79 table_list <<- NULL |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
80 ids=strsplit(listArguments[["kegg_db"]],",") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
81 ids=ids[[1]] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
82 if(length(ids)>1){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
83 for(i in 1:length(ids)){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
84 table_list[[i]] <- build.database.kegg(ids[i]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
85 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
86 db_table=do.call("rbind",table_list) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
87 DB=unique(db_table) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
88 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
89 else{ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
90 DB=build.database.kegg(listArguments[["kegg_db"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
91 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
92 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
93 #Matching des mass exactes mesurees avec les masses des compounds KEGG (pas M+H ou M-H) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
94 reactionM = create.reactionM(DB, ionAnnot, ppm.tol=listArguments[["ppm_tol"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
95 ##PROBABILITY RANKING## |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
96 # number of masses with candidates inside the fixed mass window |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
97 # and masses with more than one candidate |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
98 length(unique(reactionM[reactionM[,"id"]!="unknown",1])) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
99 sum(table(reactionM[reactionM[,"id"]!="unknown",1])>1) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
100 #if (listArguments[["useIso"]]){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
101 #BUG TODO |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
102 # Calculate the ratio between observed and theoretical isotopic patterns. |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
103 # If you don't have an assessment of carbon offset to carbon number prediction |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
104 # skip this step and use the reactionM as input to weigthM function. |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
105 #isoPatt < incorporate.isotopes(comb2plus, reactionM, , samp=12:23, DB=DB) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
106 # calculate the likelihood of each mass to compound assignment using mass accuracy,and isotopic pattern, when present |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
107 #wl < weightM(isoPatt,intervals=seq(0,1000,by=500), offset=c(3.115712, 3.434146, 2.350798)) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
108 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
109 #isoPatt=incorporate.isotopes(ionAnnot, reactionM,comb=comb,var=listArguments[["var"]],DB=DB) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
110 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
111 #wl = weightM(reactionM, useIso=true) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
112 #} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
113 #else { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
114 #wl = weightM(reactionM, useIso=FALSE) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
115 #} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
116 wl =weightM(reactionM, useIso=FALSE) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
117 w = design.connection(reactionM) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
118 # Probability calculations |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
119 x = 1:ncol(wl$wm) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
120 y = 1:nrow(wl$wm) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
121 conn = gibbs.samp(x, y, 5000, w, wl$wm) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
122 ansConn = export.class.table(conn, reactionM, ionAnnot, DB=DB,html=listArguments[["html"]],filename="AnalysisExample",prob=listArguments[["prob"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
123 if(listArguments[["html"]]){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
124 #Zip the EICS plot |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
125 system(paste('zip -r "Analysis_Report.zip" "AnalysisExample_fig"')) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
126 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
127 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
128 # calculate the correlations and partial correlations and cross reference then with reactions |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
129 mw=which(w==1,arr.ind=TRUE) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
130 #reac2cor function : Use the intensity of putative molecules in repeated samples to calculate correlations and partial |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
131 #correlation in a user defined threshold of false discovery rate for significance testing. After the |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
132 #correlation test the function also overlay significant correlations with all putative reactions between |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
133 #two masses. |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
134 #It generates a list of estimated correlations and reactions. |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
135 corList=reac2cor(mw,ansConn$classTable,listArguments[["opt"]],listArguments[["corths"]],listArguments[["corprob"]],listArguments[["pcorprob"]]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
136 ans=list("ansConn"=ansConn,"corList"=corList) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
137 #Generate the siff table for CytoScape |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
138 cytoscape_output(corList,ansConn) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
139 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
140 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
141 #Execute the merge_probmetab function to merge the variableMetadata table and annotations from ProbMetab results |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
142 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
143 if(listArguments[["mode_acquisition"]]=="one") { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
144 #Retrocompatibility with previous annotateDiffreport variableMetadata dataframe (must replace mzmed column by mz, and rtmed by rt) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
145 names(variableMetadata)[names(variableMetadata)=="mzmed"] <- "mz" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
146 names(variableMetadata)[names(variableMetadata)=="rtmed"] <- "rt" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
147 variableM=merge_probmetab(variableMetadata, ansConn) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
148 write.table(variableM, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata.tsv") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
149 } else if (listArguments[["mode_acquisition"]]=="two") { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
150 #Retrocompatibility with previous annotateDiffreport variableMetadata dataframe (must replace mzmed column by mz, and rtmed by rt) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
151 names(variableMetadataP)[names(variableMetadata)=="mzmed"] <- "mz" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
152 names(variableMetadataP)[names(variableMetadata)=="rtmed"] <- "rt" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
153 names(variableMetadataN)[names(variableMetadata)=="mzmed"] <- "mz" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
154 names(variableMetadataN)[names(variableMetadata)=="rtmed"] <- "rt" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
155 variableMP=merge_probmetab(variableMetadataP, ansConn) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
156 write.table(variableMP, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata_Positive.tsv") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
157 variableMN=merge_probmetab(variableMetadataN, ansConn) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
158 write.table(variableMN, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata_Negative.tsv") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
159 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
160 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
161 return(ans) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
162 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
163 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
164 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
165 ##Function that generates a siff table for CytoScape |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
166 cytoscape_output=function(corList,ansConn){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
167 signif_cor=as.data.frame(corList$signif.cor) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
168 classTable=as.data.frame(ansConn$classTable) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
169 #Siff table |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
170 siff_table=cbind(signif_cor["node1"],signif_cor["cor"],signif_cor["node2"]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
171 #attribute table output for Cytoscape |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
172 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
173 ## START Code part from the export2cytoscape function of ProbMetab written by Ricardo R. Silva |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
174 for (i in 1:nrow(classTable)) if (classTable[i, 1] == ""){ |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
175 classTable[i, c(1, 4, 6, 7)] <- classTable[i - 1, c(1, 4, 6, 7)] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
176 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
177 msel <- as.matrix(classTable[, 1:7]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
178 msel <- cbind(msel[, 6], msel[,-6]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
179 colnames(msel)[1] <- "Id" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
180 msel[, 1] <- sub("^\\s+", "", msel[, 1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
181 colnames(msel)[1] <- "Id" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
182 ids <- unique(msel[, 1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
183 attrMatrix <- matrix("", nrow = length(ids), ncol = ncol(msel)-1) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
184 for (i in 1:length(ids)) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
185 attrMatrix[i, 1] <- unique(msel[msel[, 1] == ids[i], |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
186 2]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
187 attrMatrix[i, 2] <- paste("[", paste(msel[msel[, |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
188 1] == ids[i], 3], collapse = ", "), "]", sep = "") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
189 attrMatrix[i, 3] <- paste("[", paste(msel[msel[, |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
190 1] == ids[i], 4], collapse = ", "), "]", sep = "") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
191 attrMatrix[i, 4] <- unique(msel[msel[, 1] == ids[i], |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
192 5]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
193 attrMatrix[i, 5] <- paste("[", paste(msel[msel[, |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
194 1] == ids[i], 6], collapse = ", "), "]", sep = "") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
195 attrMatrix[i, 6] <- unique(msel[msel[, 1] == ids[i], |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
196 7]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
197 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
198 ids <- as.numeric(unique(msel[, 1])) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
199 attrMatrix <- cbind(ids, attrMatrix) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
200 colnames(attrMatrix) <- colnames(msel) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
201 ## END Code part from the export2cytoscape function of ProbMetab writieen by Ricardo R. Silva |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
202 write.table(attrMatrix, sep="\t", quote=FALSE, row.names=FALSE, file="Analysis_Report.tsv") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
203 write.table(siff_table, sep="\t", quote=FALSE, row.names=FALSE, file="sif.tsv") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
204 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
205 return(attrMatrix) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
206 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
207 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
208 ##Functions written by Jean-Francois Martin |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
209 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
210 deter_ioni <- function (aninfo, pm) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
211 { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
212 # determine ionisation in ProbMetab result file, used in function merge_probmetab |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
213 # input : for 1 ion, aninfo = string with m/z rt and CAMERA annotation from ProbMetab result file |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
214 # if the difference between m/z and the probmetab proposed mass is ~1 we use the sign (positive or negative) of this diference |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
215 # to define the type of ionisation |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
216 # If adduct or fragment was detected, therefore diff >>1 and so, we search for substring "+" ou "2+" ou "3+" ou "-"... |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
217 # to define the type of ionisation |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
218 # aninfo : vecteur of character resulting of the parsing(sep="#") of the probmetab annotation |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
219 if (round(abs(as.numeric(aninfo[1]) - pm),0) ==1) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
220 if (as.numeric(aninfo[1]) - pm <0) {esi <- "n"} else {esi <- "p"} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
221 } else |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
222 if (!is.na(aninfo[4])) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
223 anstr <- aninfo[4] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
224 # cat(anstr) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
225 if ((grepl("]+",anstr,fixed=T)==T) || (grepl("]2+",anstr,fixed=T)==T) || (grepl("]3+",anstr,fixed=T)==T)) { esi <- "p"} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
226 else |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
227 if ((grepl("]-",anstr,fixed=T)==T) || (grepl("]2-",anstr,fixed=T)==T) || (grepl("]3-",anstr,fixed=T)==T)) { esi <- "n"} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
228 # cat(" ioni ",esi,"\n") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
229 } else |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
230 { esi <- "u"} |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
231 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
232 return(esi) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
233 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
234 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
235 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
236 merge_probmetab <- function(metaVar,ansConn) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
237 ## Parse ProbMetab information result file and merge in variable_metaData initial file |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
238 ## inputs : |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
239 ## metaVar : data.frame of metadataVariable input of probmetab function |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
240 ## ansConn : data.frame of ProbMetab result |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
241 ## output : dataframe with Probmetab results merge with variableMetadata |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
242 ## Constante |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
243 ## iannot : indice de la colonne annotation dans le resultat de probMetab |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
244 iannot <- 4 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
245 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
246 ## definition of an unique identification of ions mz with 3 decimals and rt(sec) with 1 decimal to avoid |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
247 ## duplicate ions name in the diffreport result file |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
248 ions <- paste ("M",round(metaVar$mz,3),"T",round(metaVar$rt,1),sep="") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
249 metaVar <- data.frame(ions,metaVar) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
250 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
251 ###### Result data.frame from ProbMetab result list |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
252 an_ini <- ansConn$classTable |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
253 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
254 ## Suppression of rows without mz and rt or unknown and columns of intensities |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
255 ## COLUMNS SUBSCRIPTS HAVE TO BE CHECKED WITh DIFFERENT RESULTS FILES |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
256 an <- an_ini[(an_ini[,2]!="unknown"),c(1,2,3,7)] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
257 ## initialisation of vectors receiving the result of the parse of the column annotation (subscrip iannot) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
258 mz <- rep(0,dim(an)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
259 rt <- rep(0,dim(an)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
260 propmz <- rep(0,dim(an)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
261 ioni <- rep("u",dim(an)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
262 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
263 ## parse the column annotation and define ionisation mode |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
264 for (i in 1:dim(an)[1]) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
265 if (an[i,1] != "") { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
266 info_mzrt <- unlist(strsplit(an[i,iannot],"#")) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
267 propmz[i] <- as.numeric(an[i,1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
268 mz[i] <- as.numeric(info_mzrt[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
269 rt[i] <- as.numeric(info_mzrt[2]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
270 ioni[i] <- deter_ioni(info_mzrt,as.numeric(an[i,1])) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
271 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
272 else { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
273 propmz[i] <- as.numeric(propmz[i-1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
274 mz[i] <- as.numeric(mz[i-1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
275 rt[i] <- as.numeric(rt[i-1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
276 ioni[i] <- ioni[i-1] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
277 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
278 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
279 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
280 ## definition of an unique identification of ions : mz with 3 decimals and rt(sec) with 1 decimal |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
281 ## The same as for the metadataVariable data.frame to match with. |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
282 ions <- paste ("M",round(mz,3),"T",round(rt,1),sep="") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
283 an <- data.frame(ions,ioni,propmz,mz,rt,an) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
284 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
285 ## transposition of the different probmetab annotations which are in different rows in the initial result data.frame |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
286 ## on only 1 row separated with a ";" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
287 li <- as.matrix(table(an$propmz)) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
288 li <- data.frame(dimnames(li)[1],li) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
289 dimnames(li)[[2]][1] <- "propmz" |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
290 ions <- rep("u",dim(li)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
291 propmz <- rep(0,dim(li)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
292 mpc <- rep("c",dim(li)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
293 proba <- rep("p",dim(li)[1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
294 c <- 0 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
295 while (c < dim(li)[1]) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
296 c <- c + 1 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
297 suban <- an[an$propmz==li[c,1],] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
298 ions[c] <- as.character(suban[1,1]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
299 propmz[c] <- as.numeric(suban[1,3]) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
300 mpc[c] <- paste(suban[,7],collapse=";") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
301 proba[c] <- paste(as.character(suban[,8]),collapse=";") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
302 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
303 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
304 ## Creation of the data.frame with 1 row per ions |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
305 anc <- data.frame(ions,propmz,mpc,proba) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
306 anc <- anc[order(anc[,1]),] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
307 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
308 metaVarFinal <- merge(metaVar, anc, by.x=1, by.y=1, all.x=T, all.y=T) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
309 metaVarFinal <- metaVarFinal[,-1] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
310 #write.table(metaVarFinal,file="res.txt", sep="\t", row.names=F, quote=F) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
311 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
312 return (metaVarFinal) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
313 } |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
314 |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
315 # RETROCOMPATIBILITE avec ancienne version de annotate |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
316 getVariableMetadata = function(xa) { |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
317 # --- variableMetadata --- |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
318 peakList=getPeaklist(xa) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
319 peakList=cbind(groupnames(xa@xcmsSet),peakList); colnames(peakList)[1] = c("name"); |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
320 variableMetadata=peakList[,!(colnames(peakList) %in% c(sampnames(xa@xcmsSet)))] |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
321 variableMetadata$name= paste("M",round(variableMetadata$mz),"T",round(variableMetadata$rt),sep="") |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
322 return (variableMetadata) |
e13ec2c3fabe
planemo upload commit 25fd6a739741295e3f434e0be0286dee61e06825
mmonsoor
parents:
diff
changeset
|
323 } |