test_build_onto_map = function() { dirpath = system.file('ontologies', package = 'nlpembeds') if (dirpath != '') { # build_ontology_map() # devtools::load_all() filenames = list.files(dirpath, pattern = '.csv.gz$', full.names = TRUE) match_idxs = c(13, 21, 25) l_df_onto = lapply(filenames[match_idxs], data.table::fread, data.table = FALSE) df_cui = l_onto_to_df_cui(l_df_onto) df_act = subset(df_cui, `Class ID` == "https://www.wikidata.org/wiki/Q1914636") expect_equal(nrow(df_act), 0) df_act = subset(df_cui, Parents == "https://www.wikidata.org/wiki/Q1914636") expect_equal(nrow(df_act), 0) df_role = subset(df_cui, `Class ID` == "http://purl.obolibrary.org/obo/BFO_0000023") expect_equal(df_role$`Preferred Label`, 'role') df_role = subset(df_cui, Parents == "http://purl.obolibrary.org/obo/BFO_0000023") expect_equal(df_role$`Preferred Label`, 'medication role') l_graph = onto_graph(df_cui) l_graph %<>% propagate_cuis df_map = nodes_to_mapping(l_graph$df_nodes) # I guess this should be true # expect_equal(nrow(df_cui), nrow(df_map)) expect_equal(nrow(df_cui), 2838) expect_equal(nrow(df_map), 3433) # also this is strange expect_equal(length(unique(df_cui$`Class ID`)), 2838) expect_equal(length(unique(df_map$id)), 1660) # these are not consistent either # subset(df_map, label == 'activity') # subset(df_cui, `Preferred Label` == 'activity') # though role is consistent expect_equal(subset(df_map, label == 'role')$id, subset(df_cui, `Preferred Label` == 'role')$`Class ID`) } } #test_that('build_onto_map', test_build_onto_map()) test_shiny_cui_onto = function() { data('onto_graph_raw') data('onto_graph_processed') for (input_db in c('raw', 'processed')) { obj_name = paste0('onto_graph_', input_db) igraph = get(obj_name) expect_s3_class(igraph, 'igraph') for (label in c('CUI', 'label')) { sg_obj = sgraph::sgraph_clusters(igraph, clusters = FALSE, label = label, arrows = TRUE) expect_s3_class(sg_obj, 'sgraph') } } } test_that('shiny_cui_onto', test_shiny_cui_onto())