Sparq allows querying external server. Understanding of RDF is usefull
doInstall <- F;toInstall <-c("SPARQL");if(doInstall){install.packages(toInstall)};lapply(toInstall,library, character.only = T)
## Loading required package: XML
## Loading required package: RCurl
## Loading required package: bitops
## [[1]]
## [1] "SPARQL" "RCurl" "bitops" "XML" "stats"
## [6] "graphics" "grDevices" "utils" "datasets" "methods"
## [11] "base"
endpoint<-'http://clinicaltrials.bio2rdf.org/sparql'
qs<-'
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX ct: <http://bio2rdf.org/clinicaltrials:>
PREFIX ctv: <http://bio2rdf.org/clinicaltrials_vocabulary:>
SELECT *
WHERE {
?x ctv:condition-mesh <http://bio2rdf.org/clinicaltrials_resource:4938444ea4887b824f41147e31329e6c>. #wet AMD
?x <http://bio2rdf.org/bio2rdf_vocabulary:identifier> ?xid.
?x rdfs:label ?label.
?x ctv:phase [rdfs:label ?phase].
OPTIONAL {
?x ctv:firstreceived-results-date ?res_date.
}
}
'
#no line breaks
print(qs)
## [1] "\n PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n PREFIX dc: <http://purl.org/dc/elements/1.1/>\n PREFIX dct: <http://purl.org/dc/terms/>\n PREFIX ct: <http://bio2rdf.org/clinicaltrials:>\n PREFIX ctv: <http://bio2rdf.org/clinicaltrials_vocabulary:>\n \n SELECT *\n WHERE {\n ?x ctv:condition-mesh <http://bio2rdf.org/clinicaltrials_resource:4938444ea4887b824f41147e31329e6c>. #wet AMD \n ?x <http://bio2rdf.org/bio2rdf_vocabulary:identifier> ?xid.\n ?x rdfs:label ?label.\n ?x ctv:phase [rdfs:label ?phase].\n OPTIONAL {\n ?x ctv:firstreceived-results-date ?res_date.\n }\n }\n"
#nicer format
cat(qs)
##
## PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
## PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
## PREFIX dc: <http://purl.org/dc/elements/1.1/>
## PREFIX dct: <http://purl.org/dc/terms/>
## PREFIX ct: <http://bio2rdf.org/clinicaltrials:>
## PREFIX ctv: <http://bio2rdf.org/clinicaltrials_vocabulary:>
##
## SELECT *
## WHERE {
## ?x ctv:condition-mesh <http://bio2rdf.org/clinicaltrials_resource:4938444ea4887b824f41147e31329e6c>. #wet AMD
## ?x <http://bio2rdf.org/bio2rdf_vocabulary:identifier> ?xid.
## ?x rdfs:label ?label.
## ?x ctv:phase [rdfs:label ?phase].
## OPTIONAL {
## ?x ctv:firstreceived-results-date ?res_date.
## }
## }
#actual query
#rs<-SPARQL(endpoint, qs)
#what is the structure of the result set
#str(rs)
#result set is a
#ttr<-(rs$results)
#print(ttr)
#ttr$xid
#how many rows
#nrow(ttr)
see https://www.nlm.nih.gov/pubs/techbull/mj15/mj15_mesh_rdf.html for more info
endpoint <-'http://id.nlm.nih.gov/mesh/sparql'
qs<-"
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
SELECT DISTINCT ?predicate
FROM <http://id.nlm.nih.gov/mesh>
WHERE {
?s ?predicate ?o
}
ORDER BY ?p
"
cat(qs)
##
## PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
## PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
##
## SELECT DISTINCT ?predicate
## FROM <http://id.nlm.nih.gov/mesh>
## WHERE {
##
## ?s ?predicate ?o
##
## }
## ORDER BY ?p
#formats can be different, however the result has formatting code in it
#rs<-SPARQL(url=endpoint, query=qs,format='csv')
#default XML looks good
ttr<-SPARQL(url=endpoint, query=qs)$results
#str(rs)
str(ttr)
## 'data.frame': 1 obs. of 46 variables:
## $ predicate : chr "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"
## $ predicate.1 : chr "<http://www.w3.org/2000/01/rdf-schema#label>"
## $ predicate.2 : chr "<http://id.nlm.nih.gov/mesh/vocab#note>"
## $ predicate.3 : chr "<http://id.nlm.nih.gov/mesh/vocab#concept>"
## $ predicate.4 : chr "<http://id.nlm.nih.gov/mesh/vocab#dateCreated>"
## $ predicate.5 : chr "<http://id.nlm.nih.gov/mesh/vocab#dateRevised>"
## $ predicate.6 : chr "<http://id.nlm.nih.gov/mesh/vocab#frequency>"
## $ predicate.7 : chr "<http://id.nlm.nih.gov/mesh/vocab#identifier>"
## $ predicate.8 : chr "<http://id.nlm.nih.gov/mesh/vocab#indexerConsiderAlso>"
## $ predicate.9 : chr "<http://id.nlm.nih.gov/mesh/vocab#mappedTo>"
## $ predicate.10: chr "<http://id.nlm.nih.gov/mesh/vocab#parentTreeNumber>"
## $ predicate.11: chr "<http://id.nlm.nih.gov/mesh/vocab#pharmacologicalAction>"
## $ predicate.12: chr "<http://id.nlm.nih.gov/mesh/vocab#preferredConcept>"
## $ predicate.13: chr "<http://id.nlm.nih.gov/mesh/vocab#preferredMappedTo>"
## $ predicate.14: chr "<http://id.nlm.nih.gov/mesh/vocab#preferredTerm>"
## $ predicate.15: chr "<http://id.nlm.nih.gov/mesh/vocab#previousIndexing>"
## $ predicate.16: chr "<http://id.nlm.nih.gov/mesh/vocab#source>"
## $ predicate.17: chr "<http://id.nlm.nih.gov/mesh/vocab#broaderConcept>"
## $ predicate.18: chr "<http://id.nlm.nih.gov/mesh/vocab#casn1_label>"
## $ predicate.19: chr "<http://id.nlm.nih.gov/mesh/vocab#narrowerConcept>"
## $ predicate.20: chr "<http://id.nlm.nih.gov/mesh/vocab#registryNumber>"
## $ predicate.21: chr "<http://id.nlm.nih.gov/mesh/vocab#relatedConcept>"
## $ predicate.22: chr "<http://id.nlm.nih.gov/mesh/vocab#relatedRegistryNumber>"
## $ predicate.23: chr "<http://id.nlm.nih.gov/mesh/vocab#scopeNote>"
## $ predicate.24: chr "<http://id.nlm.nih.gov/mesh/vocab#term>"
## $ predicate.25: chr "<http://id.nlm.nih.gov/mesh/vocab#allowableQualifier>"
## $ predicate.26: chr "<http://id.nlm.nih.gov/mesh/vocab#annotation>"
## $ predicate.27: chr "<http://id.nlm.nih.gov/mesh/vocab#broaderDescriptor>"
## $ predicate.28: chr "<http://id.nlm.nih.gov/mesh/vocab#dateEstablished>"
## $ predicate.29: chr "<http://id.nlm.nih.gov/mesh/vocab#hasDescriptor>"
## $ predicate.30: chr "<http://id.nlm.nih.gov/mesh/vocab#hasQualifier>"
## $ predicate.31: chr "<http://id.nlm.nih.gov/mesh/vocab#historyNote>"
## $ predicate.32: chr "<http://id.nlm.nih.gov/mesh/vocab#onlineNote>"
## $ predicate.33: chr "<http://id.nlm.nih.gov/mesh/vocab#publicMeSHNote>"
## $ predicate.34: chr "<http://id.nlm.nih.gov/mesh/vocab#seeAlso>"
## $ predicate.35: chr "<http://id.nlm.nih.gov/mesh/vocab#treeNumber>"
## $ predicate.36: chr "<http://id.nlm.nih.gov/mesh/vocab#useInstead>"
## $ predicate.37: chr "<http://id.nlm.nih.gov/mesh/vocab#abbreviation>"
## $ predicate.38: chr "<http://id.nlm.nih.gov/mesh/vocab#considerAlso>"
## $ predicate.39: chr "<http://id.nlm.nih.gov/mesh/vocab#altLabel>"
## $ predicate.40: chr "<http://id.nlm.nih.gov/mesh/vocab#broaderQualifier>"
## $ predicate.41: chr "<http://id.nlm.nih.gov/mesh/vocab#entryVersion>"
## $ predicate.42: chr "<http://id.nlm.nih.gov/mesh/vocab#lexicalTag>"
## $ predicate.43: chr "<http://id.nlm.nih.gov/mesh/vocab#prefLabel>"
## $ predicate.44: chr "<http://id.nlm.nih.gov/mesh/vocab#sortVersion>"
## $ predicate.45: chr "<http://id.nlm.nih.gov/mesh/vocab#thesaurusID>"
#result is not a well behaved data.frame (wide instead of long)
#print(ttr)