@@ -4,6 +4,7 @@ import SciMLBase
44import StructUtils
55
66using AbstractTrees: Leaves, PostOrderDFS
7+ using AutoHashEquals: @auto_hash_equals
78using DynamicalSystemsBase: ArbitrarySteppable, current_parameters, initial_state
89using Graphs: AbstractGraph, SimpleDiGraph, add_edge!, add_vertex!, ne
910using HerbConstraints: DomainRuleNode, Forbidden, Ordered, Unique, VarNode, addconstraint!
@@ -226,14 +227,31 @@ struct EntityName{S} <: EntityLabel
226227end
227228name (e:: EntityName ) = e. name
228229
229- struct EntityIdName{S} <: EntityLabel
230+ @auto_hash_equals struct EntityIdName{S} <: EntityLabel
230231 id:: Int
231232 name:: S
232233end
234+ function EntityIdName (en:: EntityName )
235+ en_str = string (name (en))
236+ name_id_str_split = rsplit (en_str, " _" ; limit = 2 )
237+ if length (name_id_str_split) != 2
238+ error (""" Failed to convert the EntityName $en to an EntityIdName. \
239+ Expecting an EntityName with a name in the form of "Name_00".""" )
240+ end
241+ (name_str, id_str) = name_id_str_split
242+
243+ id_val = tryparse (Int, id_str)
244+ if isnothing (id_val)
245+ error (""" Entity name ($(name (en)) ) contained an underscore but the \
246+ content after the underscore ($id_str ) could not be parsed as \
247+ an integer to convert it to an ID.""" )
248+ end
249+
250+ return EntityIdName (id_val, string (name_str))
251+ end
233252id (e:: EntityIdName ) = e. id
234253name (e:: EntityIdName ) = e. name
235254combined_name (e:: EntityIdName ) = Symbol (" $(name (e)) _$(id (e)) " )
236- Base.:(== )(e:: EntityIdName , e2:: EntityIdName ) = id (e) == id (e2) && name (e) == name (e2)
237255
238256struct Entity{I<: EntityLabel ,D}
239257 label:: I
@@ -293,14 +311,15 @@ function update_functions_to_interaction_graph(
293311
294312 for dst in entities_in_model
295313 input_entities = get_used_entities (target_function (dst), entities_in_model)
296- for src in EntityName .(input_entities)
314+ for src in EntityIdName .(EntityName .(input_entities))
315+ dst_label = label (dst)
297316 l = collect (labels (graph))
298- if ! (src ∈ l && label (dst) ∈ l)
317+ if ! (src ∈ l && dst_label ∈ l)
299318 error (
300- """ Could not add edge from $src to $(label (dst) ) . The vertex labels in the graph are currently $(collect (labels (graph))) .""" ,
319+ """ Could not add edge from $src to $(dst_label ) . The vertex labels in the graph are currently $(collect (labels (graph))) .""" ,
301320 )
302321 end
303- add_edge! (graph, src, label (dst) )
322+ add_edge! (graph, src, dst_label )
304323 end
305324 end
306325
@@ -759,12 +778,14 @@ function qn_to_bma_dict(qn::QN{N,S,M}) where {N,S,C,G,L<:EntityIdName,M<:MetaGra
759778 " Name" => n,
760779 ) for (d, i, n, f) in zip (lower_upper, ids, entity_names, functions)
761780 ]
781+ Main. @infiltrate
762782 relationships = [
763783 Dict (
764784 " Id" => i,
765- " FromVariable" => tryparse (Int, last ( split ( string ( src), ' _ ' )) ),
766- " ToVariable" => tryparse (Int, last ( split ( string ( dst), ' _ ' )) ),
785+ " FromVariable" => id ( src),
786+ " ToVariable" => id ( dst),
767787 " Type" => let (activators, inhibitors) = activator_inhibitor_pairs[dst]
788+ Main. @infiltrate
768789 if src in activators
769790 " Activator"
770791 elseif src in inhibitors
0 commit comments