comparison PubchemCompound.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
comparison
equal deleted inserted replaced
0:e66bb061af06 1:253d531a0193
21 # Set XML namespace 21 # Set XML namespace
22 ns <- c(pubchem = "http://pubchem.ncbi.nlm.nih.gov/pug_view") 22 ns <- c(pubchem = "http://pubchem.ncbi.nlm.nih.gov/pug_view")
23 23
24 # Define xpath expressions 24 # Define xpath expressions
25 xpath.expr <- character() 25 xpath.expr <- character()
26 xpath.expr[[RBIODB.ACCESSION]] <- "//pubchem:RecordType[text()='CID']/../pubchem:RecordNumber" 26 xpath.expr[[BIODB.ACCESSION]] <- "//pubchem:RecordType[text()='CID']/../pubchem:RecordNumber"
27 xpath.expr[[RBIODB.INCHI]] <- "//pubchem:Name[text()='InChI']/../pubchem:StringValue" 27 xpath.expr[[BIODB.INCHI]] <- "//pubchem:Name[text()='InChI']/../pubchem:StringValue"
28 xpath.expr[[RBIODB.INCHIKEY]] <- "//pubchem:Name[text()='InChI Key']/../pubchem:StringValue" 28 xpath.expr[[BIODB.INCHIKEY]] <- "//pubchem:Name[text()='InChI Key']/../pubchem:StringValue"
29 29
30 for (content in contents) { 30 for (content in contents) {
31 31
32 # Create instance 32 # Create instance
33 compound <- PubchemCompound$new() 33 compound <- PubchemCompound$new()
50 name <- NA_character_ 50 name <- NA_character_
51 tryCatch( { name <- xpathSApply(xml, "//pubchem:Name[text()='IUPAC Name']/../pubchem:StringValue", xmlValue, namespaces = ns) }, warning = function(w) {}) 51 tryCatch( { name <- xpathSApply(xml, "//pubchem:Name[text()='IUPAC Name']/../pubchem:StringValue", xmlValue, namespaces = ns) }, warning = function(w) {})
52 if (is.na(name)) 52 if (is.na(name))
53 tryCatch( { name <- xpathSApply(xml, "//pubchem:Name[text()='Record Title']/../pubchem:StringValue", xmlValue, namespaces = ns) }, warning = function(w) {}) 53 tryCatch( { name <- xpathSApply(xml, "//pubchem:Name[text()='Record Title']/../pubchem:StringValue", xmlValue, namespaces = ns) }, warning = function(w) {})
54 if ( ! is.na(name)) 54 if ( ! is.na(name))
55 compound$setField(RBIODB.NAME, name) 55 compound$setField(BIODB.NAME, name)
56 56
57 } 57 }
58 58
59 compounds <- c(compounds, compound) 59 compounds <- c(compounds, compound)
60 } 60 }
61 61
62 # Replace elements with no accession id by NULL 62 # Replace elements with no accession id by NULL
63 compounds <- lapply(compounds, function(x) if (is.na(x$getField(RBIODB.ACCESSION))) NULL else x) 63 compounds <- lapply(compounds, function(x) if (is.na(x$getField(BIODB.ACCESSION))) NULL else x)
64 64
65 # If the input was a single element, then output a single object 65 # If the input was a single element, then output a single object
66 if (drop && length(contents) == 1) 66 if (drop && length(contents) == 1)
67 compounds <- compounds[[1]] 67 compounds <- compounds[[1]]
68 68