-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.R
49 lines (41 loc) · 1.6 KB
/
client.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## This script demonstrates how to connect to a simple web service published in the
## biovel biodiversity catalogue using R.
##
## The webservice (NeXMLExtractor https://www.biodiversitycatalogue.org/rest_methods/222)
## takes as input a nexml document from which then information can be extracted. Below,
## we extract the 'Matrices' (DNA alignment) and use this as input to build
## a phylogenetic tree using the 'phangorn' package
require('phangorn')
require('RCurl')
## Define parameters for web service:
## URL and name of webservice
url <- 'http://biovel.naturalis.nl/biovel'
service <- 'NeXMLExtractor'
## encoded location of input NexML file
nexml <- URLencode('http://raw.githubusercontent.com/naturalis/biovel-nbc/master/Examples/treebase-record.xml')
## Item(s) to exatract
object <- 'Matrices'
## format of the extracted object
dataformat <- 'fasta'
## make query for web service
rest.query <- paste0(url,
'?',
'service=',service,
'&',
'nexml=', nexml,
'&',
'object=', object,
'&',
'dataformat=', dataformat)
## query web service and get result as FASTA string
fasta.str <- getURL(rest.query)
## write result into temporary directory
temp <- tempfile()
write(fasta.str, file=temp)
## read data as alignment
data <- read.phyDat(temp, format=dataformat)
## make a simple Neighbor-joining tree and root at outgroup "Grifola sordulenta", plot tree
dm <- dist.ml(data)
tree <- NJ(dm)
tree <- root(tree, "Grifola sordulenta", resolve.root=T)
plot(tree)