annotate lib.r @ 4:52b222a626b0 draft default tip

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