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