Skip to content

Commit 76362e9

Browse files
committed
WIP: fix update_functions_to_interaction_graph
1 parent 4954a36 commit 76362e9

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/qualitative_networks.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,18 @@ name(e::EntityName) = e.name
231231
id::Int
232232
name::S
233233
end
234-
function EntityIdName(en::EntityName)
235-
en_str = string(name(en))
234+
function EntityIdName(en::Symbol)
235+
en_str = string(en)
236236
name_id_str_split = rsplit(en_str, "_"; limit = 2)
237237
if length(name_id_str_split) != 2
238-
error("""Failed to convert the EntityName $en to an EntityIdName. \
238+
error("""Failed to convert the Symbol $en to an EntityIdName. \
239239
Expecting an EntityName with a name in the form of "Name_00".""")
240240
end
241241
(name_str, id_str) = name_id_str_split
242242

243243
id_val = tryparse(Int, id_str)
244244
if isnothing(id_val)
245-
error("""Entity name ($(name(en))) contained an underscore but the \
245+
error("""Entity name ($en) contained an underscore but the \
246246
content after the underscore ($id_str) could not be parsed as \
247247
an integer to convert it to an ID.""")
248248
end
@@ -284,10 +284,10 @@ end
284284
function update_functions_to_interaction_graph(
285285
entities_in_model::AbstractVector{<:E},
286286
schedule = Synchronous,
287-
) where {I,E<:Entity{I}}
287+
) where {EntityLabelType,E<:Entity{EntityLabelType}}
288288
graph = MetaGraph(
289289
SimpleDiGraph();
290-
label_type = I,
290+
label_type = EntityLabelType,
291291
vertex_data_type = E,
292292
graph_data = schedule,
293293
)
@@ -311,7 +311,7 @@ function update_functions_to_interaction_graph(
311311

312312
for dst in entities_in_model
313313
input_entities = get_used_entities(target_function(dst), entities_in_model)
314-
for src in EntityIdName.(EntityName.(input_entities))
314+
for src in EntityLabelType.(input_entities)
315315
dst_label = label(dst)
316316
l = collect(labels(graph))
317317
if !(src l && dst_label l)
@@ -737,7 +737,7 @@ function classify_activators_inhibitors(ex, activators = [], inhibitors = [])
737737
end
738738

739739
function classify_activators_inhibitors(d::AbstractDict)
740-
return Dict(e => fn for (e, fn) in d)
740+
return Dict(e => classify_activators_inhibitors(fn) for (e, fn) in d)
741741
end
742742

743743
function remove_ids_from_entities_in_target_fn(ex)
@@ -767,7 +767,7 @@ function qn_to_bma_dict(qn::QN{N,S,M}) where {N,S,C,G,L<:EntityIdName,M<:MetaGra
767767
ids = id.(entities(qn))
768768
entity_names = name.(entities(qn))
769769
functions = [target_functions(qn)[e] for e in entities(qn)]
770-
activator_inhibitor_pairs = classify_activators_inhibitors(functions)
770+
activator_inhibitor_pairs = classify_activators_inhibitors(target_functions(qn))
771771
functions = remove_ids_from_entities_in_target_fn.(functions)
772772
variables = [
773773
Dict(
@@ -778,20 +778,22 @@ function qn_to_bma_dict(qn::QN{N,S,M}) where {N,S,C,G,L<:EntityIdName,M<:MetaGra
778778
"Name" => n,
779779
) for (d, i, n, f) in zip(lower_upper, ids, entity_names, functions)
780780
]
781-
Main.@infiltrate
782781
relationships = [
783782
Dict(
784783
"Id" => i,
785784
"FromVariable" => id(src),
786785
"ToVariable" => id(dst),
787786
"Type" => let (activators, inhibitors) = activator_inhibitor_pairs[dst]
788-
Main.@infiltrate
789-
if src in activators
787+
activators_transformed = EntityIdName.(activators)
788+
inhibitors_transformed = EntityIdName.(inhibitors)
789+
if src in activators_transformed
790790
"Activator"
791-
elseif src in inhibitors
791+
elseif src in inhibitors_transformed
792792
"Inhibitor"
793793
else
794-
error("Malformed edge")
794+
error(
795+
"Malformed edge. $src not found in activators ($activators_transformed) or inhibitors ($inhibitors_transformed).",
796+
)
795797
end
796798
end,
797799
) for (i, (src, dst)) in enumerate(edge_labels(get_graph(qn)))

test/quick.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TestEnv.activate() do
1212
runtests(
1313
GraphDynamicalSystems,
1414
name = r"^(?!Code).+$",
15-
# failfast = true,
15+
failfast = true,
1616
failures_first = true,
1717
)
1818
end

0 commit comments

Comments
 (0)