-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add edges pointing from higher ATC levels to lower ATC levels (e.g. A…
…TC2 --> ATC3) (#10)
- Loading branch information
1 parent
a080f14
commit 4675522
Showing
13 changed files
with
223 additions
and
133 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
function _get_all_atc_nodes(graph::PharmGraph) | ||
all_atc_nodes_set = Vector{PharmClass}(undef, 0) | ||
|
||
function f(class) | ||
system = class.system::String | ||
if startswith(system, "ATC") | ||
push!(all_atc_nodes_set, class) | ||
end | ||
return nothing | ||
end | ||
|
||
_for_each_node(f, graph) | ||
|
||
all_atc_nodes_vector = collect(all_atc_nodes_set) | ||
unique!(all_atc_nodes_vector) | ||
sort!(all_atc_nodes_vector) | ||
return all_atc_nodes_vector | ||
end | ||
|
||
function add_atc_hierarchy_edges!(graph::PharmGraph) | ||
all_atc_levels = _get_all_atc_nodes(graph) | ||
|
||
all_atc1 = Vector{PharmClass}(undef, 0) | ||
all_atc2 = Vector{PharmClass}(undef, 0) | ||
all_atc3 = Vector{PharmClass}(undef, 0) | ||
all_atc4 = Vector{PharmClass}(undef, 0) | ||
all_atc5 = Vector{PharmClass}(undef, 0) | ||
|
||
for x in all_atc_levels | ||
system = x.system | ||
if system == "ATC1" | ||
push!(all_atc1, x) | ||
elseif system == "ATC2" | ||
push!(all_atc2, x) | ||
elseif system == "ATC3" | ||
push!(all_atc3, x) | ||
elseif system == "ATC4" | ||
push!(all_atc4, x) | ||
elseif system == "ATC5" | ||
push!(all_atc5, x) | ||
end | ||
end | ||
|
||
unique!(all_atc1) | ||
unique!(all_atc2) | ||
unique!(all_atc3) | ||
unique!(all_atc4) | ||
unique!(all_atc5) | ||
|
||
sort!(all_atc1) | ||
sort!(all_atc2) | ||
sort!(all_atc3) | ||
sort!(all_atc4) | ||
sort!(all_atc5) | ||
|
||
atc = [all_atc1, all_atc2, all_atc3, all_atc4, all_atc5] | ||
|
||
for i in 1:4 | ||
atc_i = atc[i] | ||
atc_iplusone = atc[i + 1] | ||
for less_specific_node in atc_i | ||
for more_specific_node in atc_iplusone | ||
if startswith(more_specific_node.value, less_specific_node.value) | ||
PharmaceuticalClassification._add_edge!( | ||
graph, | ||
less_specific_node => more_specific_node, | ||
) | ||
end | ||
end | ||
end | ||
end | ||
|
||
return nothing | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import MetaGraphs | ||
|
||
struct PharmClass | ||
system::String | ||
value::String | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
@testset "Integration tests" begin | ||
@testset "Integration tests with synthetic data" begin | ||
in_temporary_directory() do | ||
rxnrel = "RXNREL.RRF" | ||
rxnsat = "RXNSAT.RRF" | ||
|
||
open(rxnrel, "w") do io | ||
generate_synthetic_rxnrel(io) | ||
end | ||
open(rxnsat, "w") do io | ||
generate_synthetic_rxnsat(io) | ||
end | ||
|
||
graph_built = build_graph(; | ||
showprogress = false, | ||
rxnrel, | ||
rxnsat, | ||
) | ||
my_filename_for_serialization = "my_filename.serialized" | ||
rm(my_filename_for_serialization; force = true, recursive = true) | ||
Serialization.serialize(my_filename_for_serialization, graph_built) | ||
graph_loaded_from_file = Serialization.deserialize(my_filename_for_serialization) | ||
for graph in [graph_built, graph_loaded_from_file] | ||
@test graph isa PharmGraph | ||
@test available_systems(graph) == ["ATC1", "ATC2", "ATC3", "ATC4", "ATC5", "NDC", "RXCUI"] | ||
@test haskey(graph, PharmClass("ATC5", "A01BC23"); normalization = true) | ||
@test haskey(graph, PharmClass("ATC5", "A01BC23"); normalization = false) | ||
@test graph[PharmClass("ATC5", "A01BC23")] == PharmClass("ATC5", "A01BC23") | ||
@test getindex(graph, PharmClass("ATC5", "A01BC23"); normalization = true) == PharmClass("ATC5", "A01BC23") | ||
@test getindex(graph, PharmClass("ATC5", "A01BC23"); normalization = false) == PharmClass("ATC5", "A01BC23") | ||
@test equivalent(graph, PharmClass("ATC5", "A01BC23"); normalization = true) == [PharmClass("ATC5", "A01BC23")] | ||
@test equivalent(graph, PharmClass("ATC5", "A01BC23"); normalization = false) == [PharmClass("ATC5", "A01BC23")] | ||
@test equivalent(graph, PharmClass("NDC", "12345678901")) == [PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test equivalent(graph, PharmClass("RXCUI", "1234567")) == [PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test parents(graph, PharmClass("ATC5", "A01BC23"); normalization = true) == PharmClass[PharmClass("ATC1", "A"), PharmClass("ATC2", "A01"), PharmClass("ATC3", "A01B"), PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23")] | ||
@test parents(graph, PharmClass("ATC5", "A01BC23"); normalization = false) == PharmClass[PharmClass("ATC1", "A"), PharmClass("ATC2", "A01"), PharmClass("ATC3", "A01B"), PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23")] | ||
@test parents(graph, PharmClass("NDC", "12345678901")) == PharmClass[PharmClass("ATC1", "A"), PharmClass("ATC2", "A01"), PharmClass("ATC3", "A01B"), PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23"), PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test parents(graph, PharmClass("RXCUI", "1234567")) == PharmClass[PharmClass("ATC1", "A"), PharmClass("ATC2", "A01"), PharmClass("ATC3", "A01B"), PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23"), PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test children(graph, PharmClass("ATC5", "A01BC23"); normalization = true) == [PharmClass("ATC5", "A01BC23"), PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test children(graph, PharmClass("ATC5", "A01BC23"); normalization = false) == [PharmClass("ATC5", "A01BC23"), PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test children(graph, PharmClass("NDC", "12345678901")) == [PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test children(graph, PharmClass("RXCUI", "1234567")) == [PharmClass("NDC", "12345678901"), PharmClass("RXCUI", "1234567")] | ||
@test all_neighbors(graph, PharmClass("ATC5", "A01BC23"); normalization = true) == PharmClass[PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23"), PharmClass("RXCUI", "1234567")] | ||
@test all_neighbors(graph, PharmClass("ATC5", "A01BC23"); normalization = false) == PharmClass[PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23"), PharmClass("RXCUI", "1234567")] | ||
@test inneighbors(graph, PharmClass("ATC5", "A01BC23"); normalization = true) == PharmClass[PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23")] | ||
@test inneighbors(graph, PharmClass("ATC5", "A01BC23"); normalization = false) == PharmClass[PharmClass("ATC4", "A01BC"), PharmClass("ATC5", "A01BC23")] | ||
@test outneighbors(graph, PharmClass("ATC5", "A01BC23"); normalization = true) == PharmClass[PharmClass("ATC5", "A01BC23"), PharmClass("RXCUI", "1234567")] | ||
@test outneighbors(graph, PharmClass("ATC5", "A01BC23"); normalization = false) == PharmClass[PharmClass("ATC5", "A01BC23"), PharmClass("RXCUI", "1234567")] | ||
a = sort(unique(all_neighbors(graph, PharmClass("ATC5", "A01BC23")))) | ||
b = sort(unique(inneighbors(graph, PharmClass("ATC5", "A01BC23")))) | ||
c = sort(unique(outneighbors(graph, PharmClass("ATC5", "A01BC23")))) | ||
@test a == sort(unique(vcat(b, c))) | ||
@test !issubset(a, b) | ||
@test issubset(b, a) | ||
@test issubset(c, a) | ||
@test !issubset(c, b) | ||
@test length(graph) == 9 | ||
count = 0 | ||
for node in graph | ||
count += 1 | ||
end | ||
@test count == length(graph) | ||
@test eltype(graph) == PharmClass | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
Oops, something went wrong.