annotate nmr_annotation2d/annotationRmn2D.R @ 0:8035235e46c7 draft

Uploaded
author marie-tremblay-metatoul
date Mon, 23 Dec 2019 09:26:20 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
1 ###########################################################################################################################################
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
2 # ANNOTATION SPECTRE 2D MATRICE COMPLEXE BASEE SUR UNE SEQUENCE RMN #
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
3 # matriceComplexe : data.frame liste couples ppm de la matrice a annoter #
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
4 # BdDStandards : objet contenant la base de donnees des composes standards #
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
5 # nom_séquence : nom sequence 2D a utiliser pour annotation ("JRES","COSY","TOCSY","HMBC","HSQC") #
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
6 # ppm1Tol : tolerance ppm axe abscisses #
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
7 # ppm2Tol : tolerance ppm axe ordonnees #
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
8 # nb_ligne_template : préciser le nombre total de ligne de la feuille de calcul à annoter #
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
9 ###########################################################################################################################################
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
10 annotationRmn2D <- function(matriceComplexe, BdDStandards, nom_sequence, ppm1Tol=0.01, ppm2Tol=0.01,
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
11 seuil=0, unicite="NO")
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
12 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
13 ## Longueur de la peak-list de la matrice a annoter
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
14 PeakListLength <- length(matriceComplexe[, 1])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
15
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
16 ## Nombre de metabolites inclus dans BdD de composes standards
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
17 nbMetabolitesBdD <- length(BdDStandards)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
18 matrixAnnotation <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
19 allMetabolitesList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
20 seuil_score <- seuil
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
21
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
22 ## Boucle sur les metabolites inclus dans BdD
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
23 for (i in 1:nbMetabolitesBdD)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
24 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
25 ## Infos metabolite en cours
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
26 iMetabolite <- BdDStandards[[i]]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
27 ppm1M <- iMetabolite[,1]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
28 ppm2M <- iMetabolite[,2]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
29 nbPeakMetabolite <- length(ppm1M)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
30 MetaboliteName <- names(BdDStandards[i])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
31 ## print(MetaboliteName)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
32 ## Initialisation
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
33 k <- 0
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
34 presenceScore <- 0
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
35 annotatedPpmRef <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
36 annotatedPpmList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
37 annotatedPeakLength <- 0
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
38 metabolites <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
39 metabolitesList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
40
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
41 ## Boucle sur les couples de pics de la matrice a annoter
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
42 for (p in 1:PeakListLength)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
43 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
44 ppmAnnotationF1 <- as.numeric(matriceComplexe[p, 3])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
45 ppmAnnotationF2 <- as.numeric(matriceComplexe[p, 2])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
46 e <- simpleMessage("end of file")
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
47 tryCatch({
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
48 if (!is.na(ppmAnnotationF1))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
49 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
50 matrixAnnotation <- unique.data.frame(rbind.data.frame(matrixAnnotation, matriceComplexe[p, ]))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
51 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
52 # Recherche du couple de pics de la matrice la liste des couples du metabolite standard
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
53 metaboliteIn <- (ppm1M >= (ppmAnnotationF2-ppm1Tol) & ppm1M <= (ppmAnnotationF2+ppm1Tol) &
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
54 ppm2M >= (ppmAnnotationF1-ppm2Tol) & ppm2M <= (ppmAnnotationF1+ppm2Tol))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
55 WhichMetaboliteIn <- which(metaboliteIn)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
56 # Si au moins un couple de la matrice a annoter dans liste couples metabolite standard
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
57 if (length(WhichMetaboliteIn) > 0)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
58 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
59 for (a in 1:length(WhichMetaboliteIn))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
60 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
61 annotatedPpmList <- data.frame(ppm1=ppm1M[WhichMetaboliteIn[a]], ppm2=ppm2M[WhichMetaboliteIn[a]], theoricalLength=nbPeakMetabolite)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
62 annotatedPpmRef <- rbind(annotatedPpmRef,annotatedPpmList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
63 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
64 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
65 }, error=function(e){cat ("End of file \n");})
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
66 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
67
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
68 # Au - 1 couple de ppm de la matrice complexe annote
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
69 if (nrow(annotatedPpmRef) >= 1)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
70 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
71 ## Nombre couples annotes
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
72 annotatedPeakLength <- nrow(annotatedPpmRef)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
73
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
74 ## Recherche doublons
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
75 annotatedDoublons <- duplicated(annotatedPpmRef)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
76 if (sum(duplicated(annotatedPpmRef)) > 0)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
77 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
78 annotatedPeakLength <- nrow(annotatedPpmRef) - sum(duplicated(annotatedPpmRef))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
79 annotatedPpmRef <- annotatedPpmRef[-duplicated(annotatedPpmRef), ]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
80 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
81 presenceScore <- annotatedPeakLength/nbPeakMetabolite
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
82 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
83
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
84 ## Conservation metabolites dont score > seuil
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
85 if (presenceScore > seuil_score)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
86 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
87 metabolites <- data.frame(Metabolite=MetaboliteName, score=presenceScore)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
88 metabolitesList <- cbind.data.frame(annotatedPpmRef, metabolites)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
89 allMetabolitesList <- rbind.data.frame(allMetabolitesList, metabolitesList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
90 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
91 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
92
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
93 # Initialisation
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
94 commonPpm <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
95 commonPpmList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
96 metaboliteAdd <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
97 metaboliteAddList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
98 # metabolite_ref <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
99 commonMetabolitesList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
100 commonMetabolitesPpmList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
101 commonMetabolitesPpmAllList1 <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
102 commonMetabolitesPpmAllList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
103 listeTotale_2D_unicite <- allMetabolitesList[, 1:4]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
104 allMetabolitesList <- allMetabolitesList[, -3]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
105 metabolitesAllUnicite <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
106
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
107 ## Boucle sur tous couples annotes
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
108 for (j in 1:length(allMetabolitesList$ppm1))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
109 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
110 ## Boucle sur metabolites dans BdD composes standards
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
111 for (i in 1:nbMetabolitesBdD)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
112 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
113 ppmMetaboliteBdD <- BdDStandards[[i]]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
114 ppm1M <- ppmMetaboliteBdD[,1]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
115 ppm2M <- ppmMetaboliteBdD[,2]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
116 # Nombre de couples metabolite
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
117 nbPeakMetabolite <- length(ppm1M)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
118 MetaboliteName <- names(BdDStandards[i])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
119
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
120 metabolitesInAll <- (ppm1M >= (allMetabolitesList[j,1]-ppm1Tol) & ppm1M <= (allMetabolitesList[j,1]+ppm1Tol) &
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
121 ppm2M >= (allMetabolitesList[j,2]-ppm2Tol) & ppm2M <= (allMetabolitesList[j,2]+ppm2Tol))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
122 WhichMetabolitesInAll <- which(metabolitesInAll)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
123
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
124 if (MetaboliteName != allMetabolitesList[j, 3] & length(WhichMetabolitesInAll) > 0)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
125 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
126 metabolitesAllUnicite <- rbind.data.frame(metabolitesAllUnicite, listeTotale_2D_unicite[j,])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
127 commonPpm <- data.frame(ppm1=allMetabolitesList[j,1], ppm2=allMetabolitesList[j,2])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
128 commonPpmList <- rbind.data.frame(commonPpmList, commonPpm)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
129 commonPpmList <- unique(commonPpmList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
130 metaboliteAdd <- data.frame(nom_metabolite=MetaboliteName)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
131 metaboliteAddList <- rbind.data.frame(metaboliteAddList, metaboliteAdd)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
132 # metabolite_ref <- data.frame(nom_metabolite=allMetabolitesList[j,3])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
133 commonMetabolitesList <- rbind.data.frame(data.frame(nom_metabolite=allMetabolitesList[j, 3]), metaboliteAddList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
134 commonMetabolitesPpmList <- cbind.data.frame(commonPpm, commonMetabolitesList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
135 commonMetabolitesPpmAllList1 <- rbind.data.frame(commonMetabolitesPpmAllList1, commonMetabolitesPpmList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
136 commonMetabolitesPpmAllList1 <- unique.data.frame(commonMetabolitesPpmAllList1)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
137 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
138 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
139 commonMetabolitesPpmAllList <- rbind.data.frame(commonMetabolitesPpmAllList, commonMetabolitesPpmAllList1)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
140 commonMetabolitesPpmAllList <- unique.data.frame(commonMetabolitesPpmAllList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
141
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
142 #initialisation des data.frame
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
143 commonPpm <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
144 metaboliteAdd <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
145 metaboliteAddList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
146 metabolite_ref <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
147 commonMetabolitesList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
148 commonMetabolitesPpmList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
149 commonMetabolitesPpmAllList1 <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
150 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
151
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
152 unicityAllList <- listeTotale_2D_unicite
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
153 if (nrow(listeTotale_2D_unicite)!=0 & nrow(metabolitesAllUnicite)!=0)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
154 unicityAllList <- setdiff(listeTotale_2D_unicite, metabolitesAllUnicite)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
155
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
156 unicitynbCouplesRectif <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
157 for (g in 1:nrow(unicityAllList))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
158 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
159 metaboliteUnicity <- (unicityAllList$Metabolite == unicityAllList$Metabolite[g])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
160 WhichMetaboliteUnicity <- which(metaboliteUnicity)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
161 nb_occurence <- length(WhichMetaboliteUnicity)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
162 unicitynbCouplesRectif <- rbind.data.frame(unicitynbCouplesRectif, nb_occurence)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
163 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
164 names(unicitynbCouplesRectif) <- "NbCouplesAnnotes"
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
165 unicityAllList <- cbind.data.frame(unicityAllList, unicitynbCouplesRectif)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
166
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
167 unicityAllList <- cbind.data.frame(unicityAllList, score_unicite=unicityAllList$NbCouplesAnnotes/unicityAllList$theoricalLength)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
168 unicityAllList <- unicityAllList[, -3]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
169 unicityAllList <- unicityAllList[, -4]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
170
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
171 ## unicityAllList <- filter(unicityAllList, unicityAllList$score_unicite > seuil_score)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
172 unicityAllList <- unicityAllList[unicityAllList$score_unicite > seuil_score,]
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
173
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
174 listeTotale_metabo <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
175 if (nrow(commonPpmList) !=0)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
176 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
177 for (o in 1:length(commonPpmList[, 1]))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
178 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
179 tf6 <- (commonMetabolitesPpmAllList$ppm1 == commonPpmList[o,1] & commonMetabolitesPpmAllList$ppm2 == commonPpmList[o,2])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
180 w6 <- which(tf6)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
181
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
182 for (s in 1:length(w6))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
183 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
184 metaboliteAdd <- data.frame(nom_metabolite=commonMetabolitesPpmAllList[w6[s],3])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
185 commonMetabolitesList <- paste(commonMetabolitesList, metaboliteAdd[1,], sep = " ")
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
186 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
187 liste_metabo_ppm <- cbind.data.frame(ppm1=commonPpmList[o,1],ppm2=commonPpmList[o,2], commonMetabolitesList)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
188 listeTotale_metabo <- rbind.data.frame(listeTotale_metabo, liste_metabo_ppm)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
189 commonMetabolitesList <- data.frame()
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
190 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
191 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
192
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
193 # Representation graphique
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
194 if (nom_sequence == "HSQC" | nom_sequence == "HMBC")
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
195 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
196 atome <- "13C"
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
197 indice_positif <- 1
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
198 indice_negatif <- -10
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
199 }else{
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
200 atome <- "1H"
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
201 indice_positif <- 0.5
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
202 indice_negatif <- -0.5
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
203 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
204
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
205 matriceComplexe <- matrixAnnotation
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
206 ppm1 <- as.numeric(matriceComplexe[,2])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
207 ppm2 <- as.numeric(matriceComplexe[,3])
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
208
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
209 if (unicite == "NO")
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
210 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
211 listeTotale_2D_a_utiliser <- allMetabolitesList
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
212 d1.ppm <- allMetabolitesList$ppm1
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
213 d2.ppm <- allMetabolitesList$ppm2
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
214 }else{
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
215 listeTotale_2D_a_utiliser <- unicityAllList
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
216 d1.ppm <- listeTotale_2D_a_utiliser$ppm1
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
217 d2.ppm <- listeTotale_2D_a_utiliser$ppm2
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
218 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
219
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
220 if (nrow(listeTotale_2D_a_utiliser) > 0)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
221 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
222 ## Taches de correlations
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
223 # Matrice biologique + Annotations
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
224 maxX <- max(round(max(as.numeric(matriceComplexe[,2])))+0.5, round(max(as.numeric(matriceComplexe[,2]))))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
225 maxY <- max(round(max(as.numeric(matriceComplexe[,3])))+indice_positif, round(max(as.numeric(matriceComplexe[,3]))))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
226 probability.score <- as.factor(round(listeTotale_2D_a_utiliser[,4],2))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
227 lgr <- length(unique(probability.score))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
228 sp <- ggplot(matriceComplexe, aes(x=ppm1, y=ppm2))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
229 sp <- sp + geom_point(size=2) + scale_x_reverse(breaks=seq(maxX, 0, -0.5)) +
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
230 scale_y_reverse(breaks=seq(maxY, 0, indice_negatif)) +
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
231 xlab("1H chemical shift (ppm)") + ylab(paste(atome, " chemical shift (ppm)")) + ggtitle(nom_sequence) +
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
232 geom_text(data=listeTotale_2D_a_utiliser, aes(d1.ppm, d2.ppm, label=str_to_lower(substr(listeTotale_2D_a_utiliser[,3],1,3)),
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
233 col=probability.score),
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
234 size=4, hjust=0, nudge_x=0.02, vjust=0, nudge_y=0.2) + scale_colour_manual(values=viridis(lgr))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
235 ## scale_color_colormap('Annotation', discrete=T, reverse=T)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
236 print(sp)
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
237 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
238
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
239 # Liste des résultats (couples pmm / metabolite / score) + liste ppms metabolites communs
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
240 if (unicite == "NO")
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
241 {
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
242 return(list(liste_resultat=allMetabolitesList, listing_ppm_commun=listeTotale_metabo))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
243 }else{
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
244 return(list(liste_resultat_unicite=unicityAllList, listing_ppm_commun_affichage=listeTotale_metabo))
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
245 }
8035235e46c7 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
246 }