Created
September 6, 2023 13:55
-
-
Save vjcitn/cb316b89d08be63ebc9e3c9194e17b36 to your computer and use it in GitHub Desktop.
import semantic SQL content to ontology_index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' produce an ontology_index instance from semantic sql sqlite connection | |
#' @param con DBI::dbConnect value for sqlite table | |
#' @return result of ontologyIndex::ontology_index evaluated for the labels and | |
#' parent-child relations in tables statements and edge of the semantic sql resource | |
#' @export | |
semsql_to_oi = function(con) { | |
# sqlite> select * from statements where predicate = 'rdfs:label' limit 40; | |
alltabs = DBI::dbListTables(con) | |
stopifnot(all(c("edge", "statements") %in% alltabs)) | |
labdf = dplyr::tbl(con, "statements") |> dplyr::filter(predicate == "rdfs:label") |> | |
as.data.frame() | |
edgdf = dplyr::tbl(con, "edge") |> dplyr::filter(predicate == "rdfs:subClassOf") |> | |
as.data.frame() | |
nn = split(labdf$value, labdf$subject) # value!! | |
pl = split(edgdf$object, edgdf$subject) | |
okn = intersect(names(nn), names(pl)) | |
pl = pl[okn] | |
nn = nn[okn] | |
ontologyIndex::ontology_index(name=nn, parents=pl) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/INCATools/semantic-sql indicates how to acquire, e.g., hp.db
get efo.db by the same means
in R, use the semsql_to_oi function on dbConnect(SQLite(), "efo.db") to produce efoo
verify that this plot looks right:
onto_plot2(efoo, c(unlist(efoo$ancestors[c("EFO:0004997", "HP:0012594", "EFO:0004518")])))