Mercurial > repos > prog > lcmsmatching
comparison MsPeakForestDb.R @ 4:b34c14151f25 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 494194bb501d1d7033613131865f7bd68976041c
| author | prog |
|---|---|
| date | Tue, 14 Mar 2017 12:40:22 -0400 |
| parents | f61ce21ed17c |
| children | fb9c0409d85c |
comparison
equal
deleted
inserted
replaced
| 3:f61ce21ed17c | 4:b34c14151f25 |
|---|---|
| 257 | 257 |
| 258 # Get spectra | 258 # Get spectra |
| 259 spectra <- .self$.get.url(url = url) | 259 spectra <- .self$.get.url(url = url) |
| 260 | 260 |
| 261 # Build result data frame | 261 # Build result data frame |
| 262 results <- data.frame(MSDB.TAG.MOLID = character(), MSDB.TAG.MOLNAMES = character(), MSDB.TAG.MZTHEO = numeric(), MSDB.TAG.COMP = character(), MSDB.TAG.ATTR = character()) | 262 results <- data.frame(MSDB.TAG.MOLID = character(), MSDB.TAG.MOLNAMES = character(), MSDB.TAG.MOLMASS = numeric(), MSDB.TAG.MZTHEO = numeric(), MSDB.TAG.COMP = character(), MSDB.TAG.ATTR = character(), MSDB.TAG.INCHI = character(), MSDB.TAG.INCHIKEY = character(), MSDB.TAG.CHEBI = character(), MSDB.TAG.HMDB = character(), MSDB.TAG.KEGG = character(), MSDB.TAG.PUBCHEM = character()) |
| 263 for (x in spectra) { | 263 for (x in spectra) { |
| 264 if ('source' %in% names(x) && is.list(x$source)) | 264 if ('source' %in% names(x) && is.list(x$source)) |
| 265 results <- rbind(results, data.frame(MSDB.TAG.MOLID = vapply(x$source$listOfCompounds, function(c) as.character(c$id), FUN.VALUE = ''), | 265 mztheo <- if ('theoricalMass' %in% names(x)) as.numeric(x$theoricalMass) else NA_real_ |
| 266 MSDB.TAG.MOLNAMES = vapply(x$source$listOfCompounds, function(c) paste(c$names, collapse = MSDB.MULTIVAL.FIELD.SEP), FUN.VALUE = ''), | 266 comp <- if ('composition' %in% names(x)) x$composition else NA_character_ |
| 267 MSDB.TAG.MZTHEO = as.numeric(x$theoricalMass), | 267 attr <- if ('attribution' %in% names(x)) x$attribution else NA_character_ |
| 268 MSDB.TAG.COMP = as.character(x$composition), | 268 if ('listOfCompounds' %in% names(x$source)) { |
| 269 MSDB.TAG.ATTR = as.character(x$attribution), | 269 molids <- vapply(x$source$listOfCompounds, function(c) as.character(c$id), FUN.VALUE = '') |
| 270 stringsAsFactors = FALSE)) | 270 molnames <- vapply(x$source$listOfCompounds, function(c) paste(c$names, collapse = MSDB.MULTIVAL.FIELD.SEP), FUN.VALUE = '') |
| 271 mass <- vapply(x$source$listOfCompounds, function(c) as.character(c$averageMass), FUN.VALUE = '') | |
| 272 inchi <- vapply(x$source$listOfCompounds, function(c) as.character(c$inChI), FUN.VALUE = '') | |
| 273 inchikey <- vapply(x$source$listOfCompounds, function(c) as.character(c$inChIKey), FUN.VALUE = '') | |
| 274 chebi <- vapply(x$source$listOfCompounds, function(c) as.character(c$ChEBI), FUN.VALUE = '') | |
| 275 chebi[chebi == 'CHEBI:null'] <- NA_character_ | |
| 276 hmdb <- vapply(x$source$listOfCompounds, function(c) as.character(c$HMDB), FUN.VALUE = '') | |
| 277 hmdb[hmdb == 'HMDBnull'] <- NA_character_ | |
| 278 kegg <- vapply(x$source$listOfCompounds, function(c) as.character(c$KEGG), FUN.VALUE = '') | |
| 279 pubchem <- vapply(x$source$listOfCompounds, function(c) as.character(c$PubChemCID), FUN.VALUE = '') | |
| 280 if (length(molids) > 0 && length(molids) == length(molnames)) | |
| 281 results <- rbind(results, data.frame(MSDB.TAG.MOLID = molids, MSDB.TAG.MOLNAMES = molnames, MSDB.TAG.MOLMASS = mass, MSDB.TAG.MZTHEO = mztheo, MSDB.TAG.COMP = comp, MSDB.TAG.ATTR = attr, MSDB.TAG.INCHI = inchi, MSDB.TAG.INCHIKEY = inchikey, MSDB.TAG.CHEBI = chebi, MSDB.TAG.HMDB = hmdb, MSDB.TAG.KEGG = kegg, MSDB.TAG.PUBCHEM = pubchem, stringsAsFactors = FALSE)) | |
| 282 } | |
| 271 } | 283 } |
| 272 | 284 |
| 273 # RT search | 285 # RT search |
| 274 if ( ! is.null(rt.low) && ! is.null(rt.high)) { | 286 if ( ! is.null(rt.low) && ! is.null(rt.high)) { |
| 275 | 287 |
