Importing Nanotoxicity Data with SPARQL into R for analysis

[This article was first published on chem-bla-ics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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:
library(rrdf)

endpoint = "http://127.0.0.1/mediawiki/index.php/Special:SPARQLEndpoint"

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.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)