Mercurial > repos > prog > lcmsmatching
comparison ChebiCompound.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 |
---|---|
18 | 18 |
19 compounds <- list() | 19 compounds <- list() |
20 | 20 |
21 # Define xpath expressions | 21 # Define xpath expressions |
22 xpath.expr <- character() | 22 xpath.expr <- character() |
23 # xpath.expr[[RBIODB.ACCESSION]] <- "//b[starts-with(., 'CHEBI:')]" | 23 # xpath.expr[[BIODB.ACCESSION]] <- "//b[starts-with(., 'CHEBI:')]" |
24 xpath.expr[[RBIODB.INCHI]] <- "//td[starts-with(., 'InChI=')]" | 24 xpath.expr[[BIODB.INCHI]] <- "//td[starts-with(., 'InChI=')]" |
25 xpath.expr[[RBIODB.INCHIKEY]] <- "//td[text()='InChIKey']/../td[2]" | 25 xpath.expr[[BIODB.INCHIKEY]] <- "//td[text()='InChIKey']/../td[2]" |
26 | 26 |
27 for (html in contents) { | 27 for (html in contents) { |
28 | 28 |
29 # Create instance | 29 # Create instance |
30 compound <- ChebiCompound$new() | 30 compound <- ChebiCompound$new() |
41 | 41 |
42 # Get accession | 42 # Get accession |
43 accession <- xpathSApply(xml, "//b[starts-with(., 'CHEBI:')]", xmlValue) | 43 accession <- xpathSApply(xml, "//b[starts-with(., 'CHEBI:')]", xmlValue) |
44 if (length(accession) > 0) { | 44 if (length(accession) > 0) { |
45 accession <- sub('^CHEBI:([0-9]+)$', '\\1', accession, perl = TRUE) | 45 accession <- sub('^CHEBI:([0-9]+)$', '\\1', accession, perl = TRUE) |
46 compound$setField(RBIODB.ACCESSION, accession) | 46 compound$setField(BIODB.ACCESSION, accession) |
47 } | 47 } |
48 | 48 |
49 compounds <- c(compounds, compound) | 49 compounds <- c(compounds, compound) |
50 } | 50 } |
51 | 51 |
52 # Replace elements with no accession id by NULL | 52 # Replace elements with no accession id by NULL |
53 compounds <- lapply(compounds, function(x) if (is.na(x$getField(RBIODB.ACCESSION))) NULL else x) | 53 compounds <- lapply(compounds, function(x) if (is.na(x$getField(BIODB.ACCESSION))) NULL else x) |
54 | 54 |
55 # If the input was a single element, then output a single object | 55 # If the input was a single element, then output a single object |
56 if (drop && length(contents) == 1) | 56 if (drop && length(contents) == 1) |
57 compounds <- compounds[[1]] | 57 compounds <- compounds[[1]] |
58 | 58 |