comparison NcbiCcdsCompound.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('NcbiccdsCompound')) { # Do not load again if already loaded
2
3 source('BiodbEntry.R')
4
5 #####################
6 # CLASS DECLARATION #
7 #####################
8
9 NcbiccdsCompound <- setRefClass("NcbiccdsCompound", contains = "BiodbEntry")
10
11 ###########
12 # FACTORY #
13 ###########
14
15 createNcbiccdsCompoundFromHtml <- function(contents, drop = TRUE) {
16
17 library(XML)
18
19 compounds <- list()
20
21 for (html in contents) {
22
23 # Create instance
24 compound <- NcbiccdsCompound$new()
25
26 # Parse HTML
27 xml <- htmlTreeParse(html, asText = TRUE, useInternalNodes = TRUE)
28
29 if (length(getNodeSet(xml, "//*[starts-with(.,'No results found for CCDS ID ')]")) == 0) {
30 compound$setField(RBIODB.ACCESSION, xpathSApply(xml, "//input[@id='DATA']", xmlGetAttr, "value"))
31 compound$setField(RBIODB.SEQUENCE, xpathSApply(xml, "//b[starts-with(.,'Nucleotide Sequence')]/../tt", xmlValue))
32 }
33
34 compounds <- c(compounds, compound)
35 }
36
37 # Replace elements with no accession id by NULL
38 compounds <- lapply(compounds, function(x) if (is.na(x$getField(RBIODB.ACCESSION))) NULL else x)
39
40 # If the input was a single element, then output a single object
41 if (drop && length(contents) == 1)
42 compounds <- compounds[[1]]
43
44 return(compounds)
45 }
46 }