Mercurial > repos > prog > lcmsmatching
comparison NcbiccdsEntry.R @ 2:20d69a062da3 draft
planemo upload for repository https://github.com/workflow4metabolomics/lcmsmatching.git commit d4048accde6bdfd5b3e14f5394902d38991854f8
author | prog |
---|---|
date | Thu, 02 Mar 2017 08:55:00 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:253d531a0193 | 2:20d69a062da3 |
---|---|
1 ##################### | |
2 # CLASS DECLARATION # | |
3 ##################### | |
4 | |
5 NcbiccdsEntry <- methods::setRefClass("NcbiccdsEntry", contains = "BiodbEntry") | |
6 | |
7 ########### | |
8 # FACTORY # | |
9 ########### | |
10 | |
11 createNcbiccdsEntryFromHtml <- function(contents, drop = TRUE) { | |
12 | |
13 entries <- list() | |
14 | |
15 for (html in contents) { | |
16 | |
17 # Create instance | |
18 entry <- NcbiccdsEntry$new() | |
19 | |
20 # Parse HTML | |
21 xml <- XML::htmlTreeParse(html, asText = TRUE, useInternalNodes = TRUE) | |
22 | |
23 if (length(XML::getNodeSet(xml, "//*[starts-with(.,'No results found for CCDS ID ')]")) == 0) { | |
24 entry$setField(BIODB.ACCESSION, XML::xpathSApply(xml, "//input[@id='DATA']", XML::xmlGetAttr, "value")) | |
25 entry$setField(BIODB.SEQUENCE, XML::xpathSApply(xml, "//b[starts-with(.,'Nucleotide Sequence')]/../tt", XML::xmlValue)) | |
26 } | |
27 | |
28 entries <- c(entries, entry) | |
29 } | |
30 | |
31 # Replace elements with no accession id by NULL | |
32 entries <- lapply(entries, function(x) if (is.na(x$getField(BIODB.ACCESSION))) NULL else x) | |
33 | |
34 # If the input was a single element, then output a single object | |
35 if (drop && length(contents) == 1) | |
36 entries <- entries[[1]] | |
37 | |
38 return(entries) | |
39 } |