Mercurial > repos > prog > lcmsmatching
comparison MassbankConn.R @ 0:e66bb061af06 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit 3529b25417f8e1a5836474c9adec4b696d35099d-dirty
| author | prog |
|---|---|
| date | Tue, 12 Jul 2016 12:02:37 -0400 |
| parents | |
| children | 253d531a0193 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:e66bb061af06 |
|---|---|
| 1 if ( ! exists('MassbankConn')) { # Do not load again if already loaded | |
| 2 | |
| 3 source('BiodbConn.R') | |
| 4 source('MassbankSpectrum.R') | |
| 5 | |
| 6 ##################### | |
| 7 # CLASS DECLARATION # | |
| 8 ##################### | |
| 9 | |
| 10 MassbankConn <- setRefClass("MassbankConn", contains = "BiodbConn") | |
| 11 | |
| 12 ########################## | |
| 13 # GET ENTRY CONTENT TYPE # | |
| 14 ########################## | |
| 15 | |
| 16 MassbankConn$methods( getEntryContentType = function(type) { | |
| 17 return(if (type == RBIODB.SPECTRUM) RBIODB.TXT else NULL) | |
| 18 }) | |
| 19 | |
| 20 ##################### | |
| 21 # GET ENTRY CONTENT # | |
| 22 ##################### | |
| 23 | |
| 24 MassbankConn$methods( getEntryContent = function(type, id) { | |
| 25 | |
| 26 if (type == RBIODB.SPECTRUM) { | |
| 27 | |
| 28 # Initialize return values | |
| 29 content <- rep(NA_character_, length(id)) | |
| 30 | |
| 31 # Request | |
| 32 xmlstr <- .self$.scheduler$getUrl(get.entry.url(RBIODB.MASSBANK, id, RBIODB.TXT)) | |
| 33 | |
| 34 # Parse XML and get text | |
| 35 if ( ! is.na(xmlstr)) { | |
| 36 library(XML) | |
| 37 xml <- xmlInternalTreeParse(xmlstr, asText = TRUE) | |
| 38 ns <- c(ax21 = "http://api.massbank/xsd") | |
| 39 returned.ids <- xpathSApply(xml, "//ax21:id", xmlValue, namespaces = ns) | |
| 40 content[match(returned.ids, id)] <- xpathSApply(xml, "//ax21:info", xmlValue, namespaces = ns) | |
| 41 } | |
| 42 | |
| 43 return(content) | |
| 44 } | |
| 45 | |
| 46 return(NULL) | |
| 47 }) | |
| 48 | |
| 49 ################ | |
| 50 # CREATE ENTRY # | |
| 51 ################ | |
| 52 | |
| 53 # Creates a Spectrum instance from file content. | |
| 54 # content A file content, downloaded from the public database. | |
| 55 # RETURN A spectrum instance. | |
| 56 MassbankConn$methods( createEntry = function(type, content, drop = TRUE) { | |
| 57 return(if (type == RBIODB.SPECTRUM) createMassbankSpectrumFromTxt(content, drop = drop) else NULL) | |
| 58 }) | |
| 59 } |
