Mercurial > repos > prog > lcmsmatching
comparison MirbaseConn.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('MirbaseConn')) { # Do not load again if already loaded | |
2 | |
3 source('BiodbConn.R') | |
4 source('MirbaseCompound.R') | |
5 | |
6 ##################### | |
7 # CLASS DECLARATION # | |
8 ##################### | |
9 | |
10 MirbaseConn <- setRefClass("MirbaseConn", contains = "BiodbConn") | |
11 | |
12 ########################## | |
13 # GET ENTRY CONTENT TYPE # | |
14 ########################## | |
15 | |
16 MirbaseConn$methods( getEntryContentType = function(type) { | |
17 return(RBIODB.HTML) | |
18 }) | |
19 | |
20 ##################### | |
21 # GET ENTRY CONTENT # | |
22 ##################### | |
23 | |
24 MirbaseConn$methods( getEntryContent = function(type, id) { | |
25 | |
26 if (type == RBIODB.COMPOUND) { | |
27 | |
28 # Initialize return values | |
29 content <- rep(NA_character_, length(id)) | |
30 | |
31 # Request | |
32 content <- vapply(id, function(x) .self$.scheduler$getUrl(get.entry.url(RBIODB.MIRBASE, x, content.type = RBIODB.HTML)), FUN.VALUE = '') | |
33 | |
34 return(content) | |
35 } | |
36 | |
37 return(NULL) | |
38 }) | |
39 | |
40 ################ | |
41 # CREATE ENTRY # | |
42 ################ | |
43 | |
44 MirbaseConn$methods( createEntry = function(type, content, drop = TRUE) { | |
45 return(if (type == RBIODB.COMPOUND) createMirbaseCompoundFromHtml(content, drop = drop) else NULL) | |
46 }) | |
47 | |
48 ################### | |
49 # FIND ACCESSIONS # | |
50 ################### | |
51 | |
52 MirbaseConn$methods( | |
53 findAccessions = function(name) { | |
54 | |
55 # Get HTML | |
56 htmlstr <- .self$.scheduler$getUrl('http://www.mirbase.org/cgi-bin/query.pl', params = c(terms = name, submit = 'Search')) | |
57 | |
58 # Parse HTML | |
59 xml <- htmlTreeParse(htmlstr, asText = TRUE, useInternalNodes = TRUE) | |
60 | |
61 # Get accession number | |
62 acc <- unlist(xpathSApply(xml, "//a[starts-with(.,'MIMAT')]", xmlValue)) | |
63 | |
64 return(acc) | |
65 }) | |
66 } |