Importing Nanotoxicity Data with SPARQL into R for analysis

June 14, 2011

(This article was first published on chem-bla-ics, and kindly contributed to R-bloggers)

Not so long ago I wrote about [i]mporting RDF input in R for analysis. I am collecting nanotoxicology data in a Semantic MediaWiki with the RDFIO extension installed (by Samuel), allowing me to SPARQL that data directly from R. There is nothing much structural to visualize at this moment, so I’m skipping the Bioclipse intermediate. I did show some visualization of the data itself in the wiki, earlier this week.

Anyway, release 1.2 of rrdf is on its way, adding a sparql.remote method for running SPARQL queries at remote repositories. It also has a patch by Ryan Kohl, to support CONSTRUCT-like SPARQL queries.

I haven’t aligned my wiki with any ontology yet, so the properties have SMW-like resource form, which makes the SPARQL a bit weird looking. Other than that, the code to pull in nanotoxicology data from my data notebook now looks like:


endpoint = ""

query = paste("PREFIX w: ",
"SELECT ?min ?max ?zeta WHERE ",
"{ ?inst a w:Category-3AMetalOxides . ",
" OPTIONAL { ?inst w:Property-3AHas_Size_Min ?min . }",
" OPTIONAL { ?inst w:Property-3AHas_Size_Max ?max . }",
" OPTIONAL { ?inst w:Property-3AHas_Zeta_potential ?zeta . }",

data = sparql.remote(endpoint, query)

Which results in a data matrix that looks like (mind you, this matrix is numeric, needing a bit of rrdf 1.3 functionality):

> data
min max zeta
[1,] 15 90 NA
[2,] 15 90 NA
[3,] 15 90 NA
[4,] 15 90 NA
[5,] 15 90 NA
[6,] 15 90 NA
[7,] 15 90 NA
[8,] 15 90 NA
[9,] 15 90 NA
[10,] 15 90 NA
[11,] 15 90 NA
[12,] 15 90 NA
[13,] 10 100 34.2
[14,] 30 60 -17.3
[15,] 20 30 1.8
[16,] 15 90 NA

So, now it is time for some PCA.

To leave a comment for the author, please follow the link and comment on their blog: chem-bla-ics. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)