Pages

Tuesday, June 14, 2011

Importing Nanotoxicity Data with SPARQL into R for analysis

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.