```python
else {BdDStandards <- BdDStandard[which/names(BdDStandard) %in% Liste)]}
```

## Nombre de metabolites inclus dans BdD de composes standards

nbMetabolitesBdD <- length(BdDStandards)

matrixAnnotation <- data.frame()

allMetabolitesList <- data.frame()

seuil_score <- seuil

## Boucle sur les metabolites inclus dans BdD

for (i in 1:nbMetabolitesBdD)

}

## Infos metabolite en cours

iMetabolite <- BdDStandards[[i]]

ppm1M <- iMetabolite[,1]

ppm2M <- iMetabolite[,2]

nbPeakMetabolite <- length(ppm1M)

MetaboliteName <- names(BdDStandards[i])

## print(MetaboliteName)

## Initialisation

k <- 0

presenceScore <- 0

annotatedPpmRef <- data.frame()

annotatedPpmList <- data.frame()

annotatedPeakLength <- 0

metabolites <- data.frame()

metabolitesList <- data.frame()

## Boucle sur les couples de pics de la matrice a annoter

for (p in 1:PeakListLength)

}

ppmAnnotationF1 <- as.numeric matriceComplexe [p, 3])

ppmAnnotationF2 <- as.numeric matriceComplexe [p, 2])

e <- simpleMessage("end of file")

tryCatch(

if (!is.na(ppmAnnotationF1))

{

matrixAnnotation <- unique.data.frame(rbind.data.frame(matrixAnnotation, matriceComplexe[p, ]))

}

# Recherche du couple de pics de la matrice la liste des couples du metabolite standard

metaboliteIn <- (ppm1M >= (ppmAnnotationF2-ppm1Tol) &

ppm1M <= (ppmAnnotationF2+ppm1Tol) &

ppm2M >= (ppmAnnotationF1-ppm2Tol) &

ppm2M <= (ppmAnnotationF1+ppm2Tol))

WhichMetaboliteIn <- which(metaboliteIn)

# Si au moins un couple de la matrice a annoter dans liste couples metabolite standard

if (length(WhichMetaboliteIn) > 0)

{

for (a in 1:length(WhichMetaboliteIn))

{

annotatedPpmList <- data.frame(ppm1=ppm1M[WhichMetaboliteIn[a]],

ppm2=ppm2M[WhichMetaboliteIn[a]],
else{BdDStandards <- BdDStandard[which Exhibit(BdDStandard) %in% List)}}

## Nombre de metabolites inclus dans BdD de composes standards

nbMetabolitesBdD <- length(BdDStandards)

matrixAnnotation <- data.frame()

allMetabolitesList <- data.frame()

seuil_score <- seuil

## Boucle sur les metabolites inclus dans BdD

for (i in 1:nbMetabolitesBdD)

{

## Infos metabolite en cours

iMetabolite <- BdDStandards[[i]]

ppm1M <- iMetabolite[,1]

ppm2M <- iMetabolite[,2]

nbPeakMetabolite <- length(ppm1M)

MetaboliteName <- names(BdDStandards[i])

## print(MetaboliteName)

## Initialisation

k <- 0

presenceScore <- 0

annotatedPpmRef <- data.frame()

annotatedPpmList <- data.frame()

annotatedPeakLength <- 0

metabolites <- data.frame()

metabolitesList <- data.frame()

## Boucle sur les couples de pics de la matrice a annoter

for (p in 1:PeakListLength)

{

ppmAnnotationF1 <- as.numeric matriceComplexe[p, 3])

ppmAnnotationF2 <- as.numeric matriceComplexe[p, 2])

e <- simpleMessage("end of file")

tryCatch(

if (!is.na(ppmAnnotationF1))

{

matrixAnnotation <- unique.data.frame(rbind.data.frame(matrixAnnotation, matriceComplexe[p, ]))

}

# Recherche du couple de pics de la matrice la liste des couples du metabolite standard

metaboliteIn <- (ppm1M >= (ppmAnnotationF2-ppm1Tol) &

ppm1M <= (ppmAnnotationF2+ppm1Tol) &

ppm2M >= (ppmAnnotationF1-ppm2Tol) &

ppm2M <= (ppmAnnotationF1+ppm2Tol))

WhichMetaboliteIn <- which(metaboliteIn)

# Si au moins un couple de la matrice a annoter dans liste couples metabolite standard

if (length(WhichMetaboliteIn) > 0)

{

for (a in 1:length(WhichMetaboliteIn))

{

annotatedPpmList <- data.frame(ppm1=ppm1M[WhichMetaboliteIn[a]],

ppm2=ppm2M[WhichMetaboliteIn[a]],
nbPeakMetabolite <- length(ppm1M)
MetaboliteName <- names(BdDStandards[i])

metabolitesInAll <- (ppm1M >= (allMetabolitesList[j,1]-ppm1Tot1) &
                    ppm1M <= (allMetabolitesList[j,1]+ppm1Tot1) &
                    ppm2M >= (allMetabolitesList[j,2]-ppm2Tot1) &
                    ppm2M <= (allMetabolitesList[j,2]+ppm2Tot1))
WhichMetabolitesInAll <- which(metabolitesInAll)

if (MetaboliteName != allMetabolitesList[j, 3] & length(WhichMetabolitesInAll) > 0)
{
  metabolitesAllUnicite <- rbind.data.frame(metabolitesAllUnicite, listeTotale_2D_unicite[j,])
  commonPpm <- data.frame(ppm1=allMetabolitesList[j,1], ppm2=allMetabolitesList[j,2])
}
commonPpmList <- rbind.data.frame(commonPpmList, commonPpm)
commonPpmList <- unique(commonPpmList)
metaboliteAdd <- data.frame(nom_metabolite=MetaboliteName)
metaboliteAddList <- rbind.data.frame(metaboliteAddList, metaboliteAdd)
# metabolite_ref <- data.frame(nom_metabolite=allMetabolitesList[j,3])
commonMetabolitesList <- rbind.data.frame(data.frame(nom_metabolite=allMetabolitesList[j,3]),
                                         metaboliteAddList)
commonMetabolitesPpmList <- cbind.data.frame(commonPpm, commonMetabolitesList)
commonMetabolitesPpmAllList1 <- rbind.data.frame(commonMetabolitesPpmAllList1,
                                                commonMetabolitesPpmList)
commonMetabolitesPpmAllList1 <- unique.data.frame(commonMetabolitesPpmAllList1)
}
commonMetabolitesPpmAllList <- rbind.data.frame(commonMetabolitesPpmAllList,
                                                commonMetabolitesPpmAllList1)
commonMetabolitesPpmAllList <- unique.data.frame(commonMetabolitesPpmAllList)

#initialisation des data.frame
commonPpm <- data.frame()
metaboliteAdd <- data.frame()
metaboliteAddList <- data.frame()
metabolite_ref <- data.frame()
commonMetabolitesList <- data.frame()
commonMetabolitesPpmList <- data.frame()
commonMetabolitesPpmAllList1 <- data.frame()
}

unicityAllList <- listeTotale_2D_unicite
if (nrow(listeTotale_2D_unicite)!=0 & nrow(metabolitesAllUnicite)!=0)
  unicityAllList <- setdiff(listeTotale_2D_unicite, metabolitesAllUnicite)

unicitynbCouplesRectif <- data.frame()
for (g in 1:nrow(unicityAllList))
{
  metaboliteUnicity <- (unicityAllList$Metabolite == unicityAllList$Metabolite[g])
  WhichMetaboliteUnicity <- which(metaboliteUnicity)
  nb_occurence <- length(WhichMetaboliteUnicity)
  unicitynbCouplesRectif <- rbind.data.frame(unicitynbCouplesRectif, nb_occurence)
nbPeakMetabolite <- length(ppm1M)
MetaboliteName <- names(BdDStandards[i])

metabolitesInAll <- (ppm1M >= (allMetabolitesList[j,1]-ppm1Tot1) &
  ppm1M <= (allMetabolitesList[j,1]+ppm1Tot1) &
  ppm2M >= (allMetabolitesList[j,2]-ppm2Tot1) &
  ppm2M <= (allMetabolitesList[j,2]+ppm2Tot1))

WhichMetabolitesInAll <- which(metabolitesInAll)

if (MetaboliteName != allMetabolitesList[j, 3] & length(WhichMetabolitesInAll) > 0)
{
  metabolitesAllUnicite <- rbind.data.frame(metabolitesAllUnicite, listeTotale_2D_unicite[j,])
  commonPpm <- data.frame(ppm1=allMetabolitesList[j,1], ppm2=allMetabolitesList[j,2])
}

commonPpmList <- rbind.data.frame(commonPpmList, commonPpm)
commonPpmList <- unique(commonPpmList)
metaboliteAdd <- data.frame(nom_metabolite=MetaboliteName)
metaboliteAddList <- rbind.data.frame(metaboliteAddList, metaboliteAdd)

# metabolite_ref <- data.frame(nom_metabolite=allMetabolitesList[j,3])
commonMetabolitesList <- rbind.data.frame(data.frame(nom_metabolite=allMetabolitesList[j, 3]),
  metaboliteAddList)
commonMetabolitesPpmList <- cbind.data.frame(commonPpm, commonMetabolitesList)
commonMetabolitesPpmAllList1 <- rbind.data.frame(commonMetabolitesPpmAllList1,
  commonMetabolitesPpmList)
commonMetabolitesPpmAllList1 <- unique.data.frame(commonMetabolitesPpmAllList1)
}

commonMetabolitesPpmAllList <- rbind.data.frame(commonMetabolitesPpmAllList,
  commonMetabolitesPpmAllList1)
commonMetabolitesPpmAllList <- unique.data.frame(commonMetabolitesPpmAllList)

#initialisation des data.frame
commonPpm <- data.frame()
metaboliteAdd <- data.frame()
metaboliteAddList <- data.frame()
metabolite_ref <- data.frame()
commonMetabolitesList <- data.frame()
commonMetabolitesPpmList <- data.frame()
commonMetabolitesPpmAllList1 <- data.frame()
}

unicityAllList <- listeTotale_2D_unicite
if (nrow(listeTotale_2D_unicite)!=0 & nrow(metabolitesAllUnicite)!=0)
  unicityAllList <- setdiff(listeTotale_2D_unicite, metabolitesAllUnicite)

unicitynbCouplesRectif <- data.frame()
for (g in 1:nrow(unicityAllList))
{
  metaboliteUnicity <- (unicityAllList$Metabolite == unicityAllList$Metabolite[g])
  WhichMetaboliteUnicity <- which(metaboliteUnicity)
  nb_occurence <- length(WhichMetaboliteUnicity)
  unicitynbCouplesRectif <- rbind.data.frame(unicitynbCouplesRectif, nb_occurence)
```r
}
names(unicitynbCouplesRectif) <- "NbCouplesAnnotes"
unicityAllList <- cbind.data.frame(unicityAllList, unicitynbCouplesRectif)
unicityAllList <- cbind.data.frame(unicityAllList,
                                score_unicite=unicityAllList$NbCouplesAnnotes/unicityAllList$theoreticalLength)
unicityAllList <- unicityAllList[, -3]
unicityAllList <- unicityAllList[, -4]
```

```r
## unicityAllList <- filter(unicityAllList, unicityAllList$score_unicite > seuil_score)
unicityAllList <- unicityAllList[unicityAllList$score_unicite > seuil_score,]
```

```r
listeTotale_metabo <- data.frame()
if (nrow(commonPpmList) !=0)
{
    for (o in 1:length(commonPpmList[, 1]))
    {
        tf6 <- (commonMetabolitesPpmAllList$ppm1 == commonPpmList[o,1] &
                commonMetabolitesPpmAllList$ppm2 == commonPpmList[o,2])
        w6 <- which(tf6)
    }
    for (s in 1:length(w6))
    {
        metaboliteAdd <- data.frame(nom_metabolite=commonMetabolitesPpmAllList[w6[s],3])
        commonMetabolitesList <- paste(commonMetabolitesList, metaboliteAdd[1,], sep=" ")
    }
    liste_metabo_ppm<-cbind.data.frame(ppm1=commonPpmList[o,1], ppm2=commonPpmList[o,2],
                                     commonMetabolitesList)
    listeTotale_metabo <- rbind.data.frame(listeTotale_metabo, liste_metabo_ppm)
    commonMetabolitesList <- data.frame()
}
}
```

```r
# Representation graphique
if (nom_sequence == "HSQC" | nom_sequence == "HMBC")
{
    atome <- "13C"
    indice_positif <- 1
    indice negatif <- -10
}else{
    atome <- "1H"
    indice_positif <- 0.5
    indice negatif <- -0.5
}
```

```r
matriceComplexe <- matrixAnnotation
ppm1 <- as.numeric(matriceComplexe[,2])
ppm2 <- as.numeric(matriceComplexe[,3])
```

```r
if (unicite == "NO")
{
    listeTotale_2D_a_utiliser <- allMetabolitesList
d1.ppm <- allMetabolitesList$ppm1
}
```
```r
}
names(unicitynbCouplesRectif) <- "NbCouplesAnnotes"
unicityAllList <- cbind.data.frame(unicityAllList, unicitynbCouplesRectif)
unicityAllList <- cbind.data.frame(unicityAllList,
                                score_unicite=unicityAllList$NbCouplesAnnotes/unicityAllList$theoreticalLength)
unicityAllList <- unicityAllList[, -3]
unicityAllList <- unicityAllList[, -4]
```

```r
## unicityAllList <- filter(unicityAllList, unicityAllList$score_unicite > seuil_score)
unicityAllList <- unicityAllList[unicityAllList$score_unicite > seuil_score,]
```

```r
listeTotale_metabo <- data.frame()
if (nrow(commonPpmList) !=0)
{
    for (o in 1:length(commonPpmList[, 1]))
    {
        tf6 <- (commonMetabolitesPpmAllList$ppm1 == commonPpmList[o,1] &
                commonMetabolitesPpmAllList$ppm2 == commonPpmList[o,2])
        w6 <- which(tf6)
    }
    for (s in 1:length(w6))
    {
        metaboliteAdd <- data.frame(nom_metabolite=commonMetabolitesPpmAllList[w6[s],3])
        commonMetabolitesList <- paste(commonMetabolitesList, metaboliteAdd[1,], sep=" ")
    }
    liste_metabo_ppm<-cbind.data.frame(ppm1=commonPpmList[o,1], ppm2=commonPpmList[o,2],
                                     commonMetabolitesList)
    listeTotale_metabo <- rbind.data.frame(listeTotale_metabo, liste_metabo_ppm)
    commonMetabolitesList <- data.frame()
}
}
```

```r
# Representation graphique
if (nom_sequence == "HSQC" | nom_sequence == "HMBC")
{
    atome <- "13C"
    indice_positif <- 1
    indice negatives <- -10
}else{
    atome <- "1H"
    indice_positif <- 0.5
    indice negatives <- -0.5
}
```

```r
matriceComplexe <- matrixAnnotation
ppm1 <- as.numeric(matriceComplexe[,2])
ppm2 <- as.numeric(matriceComplexe[,3])
```

```r
if (unicite == "NO")
{
    listeTotale_2D_a_utiliser <- allMetabolitesList
d1.ppm <- allMetabolitesList$ppm1
}
```
```r
d2.ppm <- allMetabolitesList$ppm2
}else{
    listeTotale_2D_a_utiliser <- unicityAllList
d1.ppm <- listeTotale_2D_a_utiliser$ppm1
d2.ppm <- listeTotale_2D_a_utiliser$ppm2
}

if (nrow(listeTotale_2D_a_utiliser) > 0)
{
    ## Taches de correlations
    # Matrice biologique + Annotations
    maxX <- max(round(max(as.numeric matriceComplexe[,2]))+0.5,
               round(max(as.numeric matriceComplexe[,2]))))
    maxY <- max(round(max(as.numeric matriceComplexe[,3]))+indice_positif,
               round(max(as.numeric matriceComplexe[,3]))))
    probability.score <- as.factor(round(listeTotale_2D_a_utiliser[,4],2))
    lgr <- length unique(probability.score))
    ## X11()
    sp <- ggplot matriceComplexe, aes(x=ppm1, y=ppm2))
    sp <- sp + geom_point(size=2) + scale_x(breaks=seq(maxX, 0, -0.5)) +
           scale_y reverse(breaks=seq(maxY, 0, indice_negatif)) +
           xlab("1H chemical shift (ppm)") +
           ylab(paste(atome, " chemical shift (ppm)")) +
           ggtitle(nom_sequence) +
           geom_text(data=listeTotale_2D_a_utiliser,
                     aes(d1.ppm, d2.ppm,
                         label=str_to_lower(substr(listeTotale_2D_a_utiliser[,3],1,3)),
                         col=probability.score),
                     size=6, hjust=0, nudge_x=0.02, vjust=0, nudge_y=0.2) +
                     scaleColour_manual(values=viridis(lgr)) +
                     theme(axis.title.x=element_text(size=16), axis.title.y=element_text(size=16)) +
                     theme(legend.text=element_text(size=16), legend.title=element_text(size=16))
    ## scale_colorcolormap('Annotation', discrete=T, reverse=T)
    print(sp)
}

# Liste des résultats (couples pmm / metabolite / score) + liste ppms metabolites commu
ns
if (unicite == "NO")
{
    return(list(liste_resultat=allMetabolitesList, listing_ppm_commun=listeTotale_meta)
)
}else{
    return(list(liste_resultat_unicite=unicityAllList, listing_ppm_commun_affichage=liste
    Totale_meta))
}
}
```
```r
d2.ppm <- allMetabolitesList$ppm2
}else{
  listeTotale_2D_a_utiliser <- unicityAllList
d1.ppm <- listeTotale_2D_a_utiliser$ppm1
d2.ppm <- listeTotale_2D_a_utiliser$ppm2
}

if (nrow(listeTotale_2D_a_utiliser) > 0)
{
  ## Taches de correlations
  # Matrice biologique + Annotations
  maxX <- max(round(max(as.numeric matriceComplexe[,2]))+0.5,
               round(max(as.numeric matriceComplexe[,2]))))
  maxY <- max(round(max(as.numeric matriceComplexe[,3]))+indice_positif,
               round(max(as.numeric matriceComplexe[,3]))))
  probability.score <- as.factor(round(listeTotale_2D_a_utiliser[,4],2))
  lgr <- length unique(probability.score))
  ## X11()
  sp <- ggplot matriceComplexe, aes(x=ppm1, y=ppm2))
  sp <- sp + geom_point(size=2) + scale_x(breaks=seq(maxX, 0, -0.5)) +
        scale_y reverse(breaks=seq(maxY, 0, indice_negatif)) +
        xlab("1H chemical shift (ppm)") +
        ylab(paste(atome, " chemical shift (ppm)")) +
        ggtitle(nom_sequence) +
        geom_text(data=listeTotale_2D_a_utiliser,
                  aes(d1.ppm, d2.ppm,
                      label=str_to_lower(substr(listeTotale_2D_a_utiliser[,3],1,3)),
                      col=probability.score),
                  size=6, hjust=0, nudge_x=0.02, vjust=0, nudge_y=0.2) +
        scaleColour_manual(values=viridis(lgr)) +
        themeaxis.title.x=element_text(size=16), axis.title.y=element_text(size=16)) +
        theme(legend.text=element_text(size=16), legend.title=element_text(size=16))
  ## scale_colorcolormap('Annotation', discrete=T, reverse=T)
  print(sp)
}

# Liste des résultats (couples pmm / metabolite / score) + liste ppms metabolites commu
ns
if (unicite == "NO")
{
  return(list(liste_resultat=allMetabolitesList, listing_ppm_commun=listeTotale_meta)
)
}else{
  return(list(liste_resultat_unicite=unicityAllList, listing_ppm_commun_affichage=liste
  Totale_meta))
}
}
```
## Suppression des zones sans intérêt après la détection des pics

```javascript
nettoyage <- function(peaklist, type){
  if(type == "COSY"){
    peaklist <- subset(peaklist, ! (peaklist$x < 0.7))
    peaklist <- subset(peaklist, ! (peaklist$y < 0.7))
    peaklist <- subset(peaklist, ! (peaklist$x > 8.05))
    peaklist <- subset(peaklist, ! (peaklist$y > 8.05))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$y < 3))
    peaklist <- subset(peaklist, ! (peaklist$y > 5.1 & peaklist$x < 3))
    peaklist <- subset(peaklist, ! (peaklist$x > 4.2 & peaklist$x < 6.7 & peaklist$y > 5.1))
    peaklist <- subset(peaklist, ! (peaklist$y > 4.2 & peaklist$y < 6.7 & peaklist$x > 5.1))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.4 & peaklist$x < 6.7 & peaklist$y < 4.5))
    peaklist <- subset(peaklist, ! (peaklist$y > 5.4 & peaklist$y < 6.7 & peaklist$x < 4.5))
  }
  else if(type == "TOCSY"){
    peaklist <- subset(peaklist, ! (peaklist$x < 0.9 | peaklist$y < 0.9 |
                                     peaklist$y > 8.1 | peaklist$x > 8.1)))
    peaklist <- subset(peaklist, ! (peaklist$x < 3 & peaklist$y > 5.2))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$y < 3))
  }
  else if(type == "HSQC"){
    peaklist <- subset(peaklist, ! (peaklist$x < 0.78))
    peaklist <- subset(peaklist, ! (peaklist$y < 11.2))
    peaklist <- subset(peaklist, ! (peaklist$x > 8.5))
    peaklist <- subset(peaklist, ! (peaklist$y > 140))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$y < 90))
    peaklist <- subset(peaklist, ! (peaklist$x > 3.6 & peaklist$y < 50))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.3 & peaklist$y < 110))
    peaklist <- subset(peaklist, ! (peaklist$x < 4.5 & peaklist$y > 85))
    peaklist <- subset(peaklist, ! (peaklist$x < 2.5 & peaklist$y < 85 & peaklist$y > 50))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$x < 6.7 & peaklist$y > 110))
  }
  return(peaklist)
}
```

## Combinaison des sequences

### Annotation d'une seule séquence

```javascript
annotation <- function(spect, liste_1D, type = c("COSY", "TOCSY", "HSQC"),
                     level = NULL, shift = FALSE, net = FALSE,
                     ppm1Tol=tolPpm1, ppm2Tol=tolPpm1){

  if(shift == TRUE){
    if(type == "COSY" | type == "TOCSY"){
      rownames(spect) <- as.numeric(rownames(spect)) + 0.1
      colnames(spect) <- as.numeric(colnames(spect)) + 0.1
    }
  }
```
## Suppression des zones sans intérêt après la détection des pics

```javascript
nettoyage <- function(peaklist, type){
  if(type == "COSY"){
    peaklist <- subset(peaklist, ! (peaklist$x < 0.7))
    peaklist <- subset(peaklist, ! (peaklist$y < 0.7))
    peaklist <- subset(peaklist, ! (peaklist$x > 8.05))
    peaklist <- subset(peaklist, ! (peaklist$y > 8.05))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$y < 3))
    peaklist <- subset(peaklist, ! (peaklist$y > 5.1 & peaklist$x < 3))
    peaklist <- subset(peaklist, ! (peaklist$x > 4.2 & peaklist$x < 6.7 & peaklist$y > 5.1))
    peaklist <- subset(peaklist, ! (peaklist$y > 4.2 & peaklist$y < 6.7 & peaklist$x > 5.1))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.4 & peaklist$x < 6.7 & peaklist$y < 4.5))
    peaklist <- subset(peaklist, ! (peaklist$y > 5.4 & peaklist$y < 6.7 & peaklist$x < 4.5))
  }
  else if(type == "TOCSY"){
    peaklist <- subset(peaklist, ! (peaklist$x < 0.9 | peaklist$y < 0.9 |
                                     peaklist$y > 8.1 | peaklist$x > 8.1)))
    peaklist <- subset(peaklist, ! (peaklist$x < 3 & peaklist$y > 5.2))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$y < 3))
  }
  else if(type == "HSQC"){
    peaklist <- subset(peaklist, ! (peaklist$x < 0.78))
    peaklist <- subset(peaklist, ! (peaklist$y < 11.2))
    peaklist <- subset(peaklist, ! (peaklist$x > 8.5))
    peaklist <- subset(peaklist, ! (peaklist$y > 140))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$y < 90))
    peaklist <- subset(peaklist, ! (peaklist$x > 3.6 & peaklist$y < 50))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.3 & peaklist$y < 110))
    peaklist <- subset(peaklist, ! (peaklist$x < 4.5 & peaklist$y > 85))
    peaklist <- subset(peaklist, ! (peaklist$x < 2.5 & peaklist$y < 85 & peaklist$y > 50))
    peaklist <- subset(peaklist, ! (peaklist$x > 5.1 & peaklist$x < 6.7 & peaklist$y > 110))
  }
  return(peaklist)
}
```

## Combinaison des sequences

### Annotation d'une seule séquence

```javascript
annotation <- function(spect, liste_1D, type = c("COSY", "TOCSY", "HSQC"),
                     level = NULL, shift = FALSE, net = FALSE,
                     ppm1Tol=tolPpm1, ppm2Tol=tolPpm1){

  if(shift == TRUE){
    if(type == "COSY" | type == "TOCSY"){
      rownames(spect) <- as.numeric(rownames(spect)) + 0.1
      colnames(spect) <- as.numeric(colnames(spect)) + 0.1
    }
  }
```
```javascript
}
else if(type == "HSQC"){
    rownames(spect) <- as.numeric(rownames(spect)) + 0.1
    colnames(spect) <- as.numeric(colnames(spect)) + 3
}

peaklist <- peak_detection(spect, level, type = type)
if(net == TRUE){
    peaklist <- nettoyage(peaklist, type)
}

BdDReference <- NA
if(type == "COSY") {BdDReference = BdDReference_TOCSY}
else if(type == "TOCSY") {BdDReference = BdDReference_TOCSY}
else {BdDReference = BdDReference_HSQC}

annotat <- annotationRmn2Dr(peaklist, BdDReference, Liste = liste_1D,
                             L = TRUE, type, ppm1Tol, ppm2Tol, seuil=0, unicite="NO")
return(annotat)
}
```

## Annotation de toutes les sequences à la fois

```javascript
annotationGlob <- function(spect_1 = NULL, spect_2 = NULL, spect_3, liste_1D,
                         cosy = 1, tocsy = 1, hsqc = 1,
                         tolPpm1 = 0.01, tolPpm2C = 0.5,
                         shift = FALSE, net = TRUE){
    if(cosy == 1){
        res_annC <- annotation(spect_1, liste_1D = liste_1D, type = "COSY", net = net,
                             ppm1Tol=tolPpm1, ppm2Tol=tolPpm1)
    }
    if(tocsy == 1){
        res_annT <- annotation(spect_2, liste_1D = liste_1D, type = "TOCSY", net = net,
                             ppm1Tol=tolPpm1, ppm2Tol=tolPpm1)
    }
    if(hsqc == 1){
        res_annH <- annotation(spect_3, liste_1D = liste_1D, type = "HSQC", net = net,
                             ppm1Tol=tolPpm1, ppm2Tol=tolPpm2C)
    }

    if(cosy == 1 & tocsy == 0){
        return(list(COSY+WQC+WQH=0, HSQC+WQH=0, WQH=0))
    }
    else if(cosy == 0 & tocsy == 1){
        return(list(TOCSY+WQH=0, HSQC+WQH=0, WQH=0))
    }
    else if(cosy == 1 & tocsy == 1){
        return(list(COSY+WQH=0, TOCSY+WQH=0, WQH=0))
    }
}
```
```javascript
}
else if(type == "HSQC"){
    rownames(spect) <- as.numeric(rownames(spect)) + 0.1
    colnames(spect) <- as.numeric(colnames(spect)) + 3
}
}
peaklist <- peak_detection(spect, level, type = type)
if(net == TRUE){
    peaklist <- nettoyage(peaklist, type)
}

BdDReference <- NA
if(type == "COSY") {BdDReference = BdDReference_TOCSY}
else if(type == "TOCSY") {BdDReference = BdDReference_TOCSY}
else {BdDReference = BdDReference_HSQC}

annotat <- annotationRmn2Dr(peaklist, BdDReference, Liste = liste_1D,
                             L = TRUE, type, ppm1Tol, ppm2Tol, seuil=0, unicite="NO")
return(annotat)
}
```

## Annotation de toutes les sequences à la fois

```javascript
annotationGlob <- function(spect_1 = NULL, spect_2 = NULL, spect_3, liste_1D,
                          cosy = 1, tocsy = 1, hsqc = 1,
                          tolPpm1 = 0.01, tolPpm2C = 0.5,
                          shift = FALSE, net = TRUE){
    if(cosy == 1){
        res_annC <- annotation(spect_1, liste_1D = liste_1D, type = "COSY", net = net,
                             ppm1Tol=tolPpm1, ppm2Tol=tolPpm1)
    }
    if(tocsy == 1){
        res_annT <- annotation(spect_2, liste_1D = liste_1D, type = "TOCSY", net = net,
                             ppm1Tol=tolPpm1, ppm2Tol=tolPpm1)
    }
    if(hsqc == 1){
        res_annH <- annotation(spect_3, liste_1D = liste_1D, type = "HSQC", net = net,
                             ppm1Tol=tolPpm1, ppm2Tol=tolPpm2C)
    }

    if(cosy == 1 & tocsy == 0){
        return(list(COSY+WQC+WQH=0, WQC+WQH=0, WQH+WQC+WQH=0))
    }
    else if(cosy == 0 & tocsy == 1){
        return(list(TOCSY+WQH+WQH=0, WQH+WQH=0, WQH+WQH+WQH=0))
    }
    else if(cosy == 1 & tocsy == 1){
        return(list(COSY+WQH+WQH=0, WQH+WQH=0, WQH+WQH+WQH=0))
    }
}
```
## Tableau des scores

```R
Tab_scores <- function(List_ann, Liste_1D, cosy = 1, tocsy = 1, hsqc = 1){
  if(cosy == 1){
    Metabolites_COSY <- List_ann$COSY$Metabolite
    Scores_COSY <- List_ann$COSY$score
    datNC <- data.frame(Metabolites_COSY, Scores_COSY)
    datNC <- subset.datNC, !duplicated(Metabolites_COSY))
  }
  if(tocsy == 1){
    Metabolites_TOCSY <- List_ann$TOCSY$Metabolite
    Scores_TOCSY <- List_ann$TOCSY$score
    datNT <- data.frame(Metabolites_TOCSY, Scores_TOCSY)
    datNT <- subset.datNT, !duplicated(Metabolites_TOCSY))
  }
  if(hsqc == 1){
    Metabolites_HSQC <- List_ann$HSQC$Metabolite
    Scores_HSQC <- List_ann$HSQC$score
    datNH <- data.frame(Metabolites_HSQC, Scores_HSQC)
    datNH <- subset.datNH, !duplicated(Metabolites_HSQC))
  }
  Score_COSY <- rep(0, length(Liste_1D))
  Score_TOCSY <- rep(0, length(Liste_1D))
  Score_HSQC <- rep(0, length(Liste_1D))
  Score_moyen <- rep(0, length(Liste_1D))
  Score_max <- rep(0, length(Liste_1D))

  if(cosy == 1 & tocsy == 0){
    for(i in 1:length(Liste_1D)){
      if(Liste_1D[i] %in% unique(Metabolites_COSY)){
        Score_COSY[i] <- datNC$Scores_COSY[which.datNC$Metabolites_COSY == Liste_1D[i])]
      }
      if(ListeN[i] %in% unique(Metabolites_HSQC)){
        Score_HSQC[i] <- datNH$Scores_HSQC[which.datNH$Metabolites_HSQC == Liste_1D[i])]
      }
      Score_moyen[i] <- mean(c(Score_COSY[i], Score_HSQC[i]))
      Score_max[i] <- max(c(Score_COSY[i], Score_HSQC[i]))
    }
    Tab_10 <- data.frame(Metabolites = Liste_1D, Score_COSY, Score_HSQC, Score_moyen, Score_max)
    return(Tab_10)
  }
  else if(cosy == 0 & tocsy == 1){
    for(i in 1:length(Liste_1D)){
      if(Liste_1D[i] %in% unique(Metabolites_TOCSY)){
        Score_TOCSY[i] <- datNT$Scores_TOCSY[which.datNT$Metabolites_TOCSY == Liste_1D[i])]
      }
      if(ListeN[i] %in% unique(Metabolites_HSQC)){
        Score_HSQC[i] <- datNH$Scores_HSQC[which.datNH$Metabolites_HSQC == Liste_1D[i])]
      }
      Score_moyen[i] <- mean(c(Score_TOCSY[i], Score_HSQC[i]))
    }
  }
```
## Tableau des scores

```R
Tab_scores <- function(List_ann, Liste_1D, cosy = 1, tocsy = 1, hsqc = 1){
  if(cosy == 1){
    Metabolites_COSY <- List_ann$COSY$Metabolite
    Scores_COSY <- List_ann$COSY$score
    datNC <- data.frame(Metabolites_COSY, Scores_COSY)
    datNC <- subset.datNC, !duplicated(Metabolites_COSY))
  }
  if(tocsy == 1){
    Metabolites_TOCSY <- List_ann$TOCSY$Metabolite
    Scores_TOCSY <- List_ann$TOCSY$score
    datNT <- data.frame(Metabolites_TOCSY, Scores_TOCSY)
    datNT <- subset.datNT, !duplicated(Metabolites_TOCSY))
  }
  if(hsqc == 1){
    Metabolites_HSQC <- List_ann$HSQC$Metabolite
    Scores_HSQC <- List_ann$HSQC$score
    datNH <- data.frame(Metabolites_HSQC, Scores_HSQC)
    datNH <- subset.datNH, !duplicated(Metabolites_HSQC))
  }

  Score_COSY <- rep(0, length(Liste_1D))
  Score_TOCSY <- rep(0, length(Liste_1D))
  Score_HSQC <- rep(0, length(Liste_1D))
  Score_moyen <- rep(0, length(Liste_1D))
  Score_max <- rep(0, length(Liste_1D))

  if(cosy == 1 & tocsy == 0){
    for(i in 1:length(Liste_1D)){
      if(Liste_1D[i] %in% unique(Metabolites_COSY)){
        Score_COSY[i] <- datNC$Scores_COSY[which.datNC$Metabolites_COSY == Liste_1D[i])]
      }
      if(ListeN[i] %in% unique(Metabolites_HSQC)){
        Score_HSQC[i] <- datNH$Scores_HSQC[which.datNH$Metabolites_HSQC == Liste_1D[i])]
      }
      Score_moyen[i] <- mean(c(Score_COSY[i], Score_HSQC[i]))
      Score_max[i] <- max(c(Score_COSY[i], Score_HSQC[i]))
    }
    Tab_10 <- data.frame(Metabolites = Liste_1D, Score_COSY, Score_HSQC, Score_moyen, Score_max)
    return(Tab_10)
  }
  else if(cosy == 0 & tocsy == 1){
    for(i in 1:length(Liste_1D)){
      if(Liste_1D[i] %in% unique(Metabolites_TOCSY)){
        Score_TOCSY[i] <- datNT$Scores_TOCSY[which.datNT$Metabolites_TOCSY == Liste_1D[i])]
      }
      if(ListeN[i] %in% unique(Metabolites_HSQC)){
        Score_HSQC[i] <- datNH$Scores_HSQC[which.datNH$Metabolites_HSQC == Liste_1D[i])]
      }
      Score_moyen[i] <- mean(c(Score_TOCSY[i], Score_HSQC[i]))
    }
  }
```
```R
Score_max[i] <- max(c(Score_TOCSY[i], Score_HSQC[i]))
}
Tab_01 <- data.frame(Metabolites = Liste_1D, Score_TOCSY, Score_HSQC, Score_moyen, Score_max)
return(Tab_01)
}
else if(cosy == 1 & tocsy == 1){
    for(i in 1:length(Liste_1D)){
        if(Liste_1D[i] %in% unique(Metabolites_COSY)){
            Score_COSY[i] <- datNC$Scores_COSY[which.datNC$Metabolites_COSY == Liste_1D[i])]
        }
        if(Liste_1D[i] %in% unique(Metabolites_TOCSY)){
            Score_TOCSY[i] <- datNT$Scores_TOCSY[which.datNT$Metabolites_TOCSY == Liste_1D[i]]
        }
        if(ListeN[i] %in% unique(Metabolites_HSQC)){
            Score_HSQC[i] <- datNH$Scores_HSQC[which.datNH$Metabolites_HSQC == Liste_1D[i])]
        }
        Score_moyen[i] <- mean(c(Score_COSY[i], Score_TOCSY[i], Score_HSQC[i]))
        Score_max[i] <- max(c(Score_COSY[i], Score_TOCSY[i], Score_HSQC[i]))
    }
}
Tab_11 <- data.frame(Metabolites = Liste_1D, Score_COSY, Score_TOCSY, Score_HSQC, Score_moyen, Score_max)
return(Tab_11)
}
}
```

## Combinaison des séquences avec le score maximal et le seuil fixé à 0.1

```R
annotation_globale <- function(spect_COSY = NULL, spect_TOCSY = NULL, spect_HSQC,
                             liste_1D, cosy = 1, tocsy = 1, hsqc = 1, seuil,
                             tolPpm1 = 0.01, tolPpm2C = 0.5,
                             shift = FALSE, net = TRUE){

    if(missing(seuil)){seuil = 0.1}

    List_ann <- annotationGlob(spect_1 = spect_COSY, spect_2 = spect_TOCSY,
                             spect_3 = spect_HSQC, liste_1D, cosy = cosy,
                             tocsy = ocsy, hsqc = hsqc, tolPpm1 = tolPpm1,
                             tolPpm2C = tolPpm2C, shift = shift, net = net)

    tab <- Tab_scores(List_ann, Liste_1D, cosy = cosy, tocsy = ocsy, hsqc = hsqc)

    quant <- tab$Metabolites[which.tab$Score_max > seuil)]

    return(quant)
}
```
```R
Score_max[i] <- max(c(Score_TOCSY[i], Score_HSQC[i]))
}
Tab_01 <- data.frame(Metabolites = Liste_1D, Score_TOCSY, Score_HSQC, Score_moyen, Score_max)
return(Tab_01)
}
else if(cosy == 1 & tocsy == 1){
    for(i in 1:length(Liste_1D)){
        if(Liste_1D[i] %in% unique(Metabolites_COSY)){
            Score_COSY[i] <- datNC$Scores_COSY[which.datNC$Metabolites_COSY == Liste_1D[i])]
        }
        if(Liste_1D[i] %in% unique(Metabolites_TOCSY)){
            Score_TOCSY[i] <- datNT$Scores_TOCSY[which.datNT$Metabolites_TOCSY == Liste_1D[i]]
        }
        if(ListeN[i] %in% unique(Metabolites_HSQC)){
            Score_HSQC[i] <- datNH$Scores_HSQC[which.datNH$Metabolites_HSQC == Liste_1D[i])]
        }
        Score_moyen[i] <- mean(c(Score_COSY[i], Score_TOCSY[i], Score_HSQC[i]))
        Score_max[i] <- max(c(Score_COSY[i], Score_TOCSY[i], Score_HSQC[i]))
    }
    Tab_11 <- data.frame(Metabolites = Liste_1D, Score_COSY, Score_TOCSY, Score_HSQC, Score_moyen, Score_max)
    return(Tab_11)
}
}
```

## Combinaison des séquences avec le score maximal et le seuil fixé à 0.1

```R
annotation_globale <- function(spect_COSY = NULL, spect_TOCSY = NULL, spect_HSQC,
                             liste_1D, cosy = 1, tocsy = 1, hsqc = 1, seuil,
                             tolPpm1 = 0.01, tolPpm2C = 0.5,
                             shift = FALSE, net = TRUE){

    if(missing(seuil)){seuil = 0.1}

    List_ann <- annotationGlob(spect_1 = spect_COSY, spect_2 = spect_TOCSY,
                             spect_3 = spect_HSQC, liste_1D, cosy = cosy,
                             tocsy = ocsy, hsqc = hsqc, tolPpm1 = tolPpm1,
                             tolPpm2C = tolPpm2C, shift = shift, net = net)

    tab <- Tab_scores(List_ann, Liste_1D, cosy = cosy, tocsy = ocsy, hsqc = hsqc)

    quant <- tab$Metabolites[which.tab$Score_max > seuil)]

    return(quant)
}
```
## Calculs des vrais et faux positifs après annotation

```
metabo_1D <- function(Vrais, quantif){
  L <- quantif[which(quantif %in% Vrais)]
  u <- quantif[-which(quantif %in% Vrais)]
  return(list(detect = unique(quantif), VP = unique(L), FP = unique(u)))
}
```

```
metabo_2D <- function(Vrais, liste_1D, quantif){
  L <- quantif[which(quantif %in% Vrais)]
  u <- quantif[-which(quantif %in% Vrais)]
  nd <- liste_1D[-which(liste_1D %in% quantif)]
  fn <- nd[which(nd %in% Vrais)]
  vn <- nd[-which(nd %in% Vrais)]
  return(list(detect = unique(quantif), VP = unique(L), FP = unique(u), VN = unique(vn),
          FN = unique(fn)))
}
```
## Calculs des vrais et faux positifs après annotation

```
metabo_1D <- function(Vrais, quantif){
  L <- quantif[which(quantif %in% Vrais)]
  u <- quantif[-which(quantif %in% Vrais)]
  return(list(detect = unique(quantif), VP = unique(L), FP = unique(u)))
}
```

```
metabo_2D <- function(Vrais, liste_1D, quantif){
  L <- quantif[which(quantif %in% Vrais)]
  u <- quantif[-which(quantif %in% Vrais)]
  nd <- liste_1D[-which(liste_1D %in% quantif)]
  fn <- nd[which(nd %in% Vrais)]
  vn <- nd[-which(nd %in% Vrais)]
  return(list(detect = unique(quantif), VP = unique(L), FP = unique(u), VN = unique(vn),
          FN = unique(fn)))
}
```