Mercurial > repos > prog > lcmsmatching
diff MassbankConn.R @ 1:253d531a0193 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 36c9d8099c20a1ae848f1337c16564335dd8fb2b
author | prog |
---|---|
date | Sat, 03 Sep 2016 17:02:01 -0400 |
parents | e66bb061af06 |
children | 20d69a062da3 |
line wrap: on
line diff
--- a/MassbankConn.R Tue Jul 12 12:02:37 2016 -0400 +++ b/MassbankConn.R Sat Sep 03 17:02:01 2016 -0400 @@ -1,43 +1,69 @@ if ( ! exists('MassbankConn')) { # Do not load again if already loaded - source('BiodbConn.R') + source('RemotedbConn.R') + source('MassdbConn.R') source('MassbankSpectrum.R') ##################### # CLASS DECLARATION # ##################### - MassbankConn <- setRefClass("MassbankConn", contains = "BiodbConn") + MassbankConn <- setRefClass("MassbankConn", contains = c("RemotedbConn", "MassdbConn")) ########################## # GET ENTRY CONTENT TYPE # ########################## MassbankConn$methods( getEntryContentType = function(type) { - return(if (type == RBIODB.SPECTRUM) RBIODB.TXT else NULL) + return(if (type == BIODB.SPECTRUM) BIODB.TXT else NULL) }) ##################### # GET ENTRY CONTENT # ##################### - MassbankConn$methods( getEntryContent = function(type, id) { + MassbankConn$methods( getEntryContent = function(type, ids) { - if (type == RBIODB.SPECTRUM) { + # Debug + .self$.print.debug.msg(paste0("Get entry content(s) for ", length(ids)," id(s)...")) + + if (type == BIODB.SPECTRUM) { + + URL.MAX.LENGTH <- 2083 # Initialize return values - content <- rep(NA_character_, length(id)) + content <- rep(NA_character_, length(ids)) + + # Loop on all + n <- 0 + while (n < length(ids)) { - # Request - xmlstr <- .self$.scheduler$getUrl(get.entry.url(RBIODB.MASSBANK, id, RBIODB.TXT)) + # Get list of accession ids to retrieve + accessions <- ids[(n + 1):length(ids)] + + # Create URL request + x <- get.entry.url(class = BIODB.MASSBANK, accession = accessions, content.type = BIODB.TXT, max.length = URL.MAX.LENGTH) + + # Debug + .self$.print.debug.msg(paste0("Send URL request for ", x$n," id(s)...")) - # Parse XML and get text - if ( ! is.na(xmlstr)) { - library(XML) - xml <- xmlInternalTreeParse(xmlstr, asText = TRUE) - ns <- c(ax21 = "http://api.massbank/xsd") - returned.ids <- xpathSApply(xml, "//ax21:id", xmlValue, namespaces = ns) - content[match(returned.ids, id)] <- xpathSApply(xml, "//ax21:info", xmlValue, namespaces = ns) + # Send request + xmlstr <- .self$.scheduler$getUrl(x$url) + + # Increase number of entries retrieved + n <- n + x$n + + # Parse XML and get text + if ( ! is.na(xmlstr)) { + library(XML) + xml <- xmlInternalTreeParse(xmlstr, asText = TRUE) + ns <- c(ax21 = "http://api.massbank/xsd") + returned.ids <- xpathSApply(xml, "//ax21:id", xmlValue, namespaces = ns) + content[match(returned.ids, ids)] <- xpathSApply(xml, "//ax21:info", xmlValue, namespaces = ns) + } + + # Debug + .self$.print.debug.msg(paste0("Now ", length(ids) - n," id(s) left to be retrieved...")) } return(content) @@ -54,6 +80,13 @@ # content A file content, downloaded from the public database. # RETURN A spectrum instance. MassbankConn$methods( createEntry = function(type, content, drop = TRUE) { - return(if (type == RBIODB.SPECTRUM) createMassbankSpectrumFromTxt(content, drop = drop) else NULL) + return(if (type == BIODB.SPECTRUM) createMassbankSpectrumFromTxt(content, drop = drop) else NULL) + }) + + ################# + # GET MZ VALUES # + ################# + + MassbankConn$methods( getMzValues = function(mode = NULL, max.results = NA_integer_) { }) }