Skip to content

Commit cdd284f

Browse files
committed
init
1 parent a45a1bc commit cdd284f

File tree

2 files changed

+119
-8
lines changed

2 files changed

+119
-8
lines changed

src/reaction.jl

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,16 @@ end
470470
"""
471471
has_noise_scaling(reaction::Reaction)
472472
473-
Checks whether a specific reaction has the metadata field `noise_scaing`. If so, returns `true`, else
474-
returns `false`.
473+
Returns `true` if the input reaction has the `noise_scaing` metadata field assigned, else `false`.
475474
476475
Arguments:
477-
- `reaction`: The reaction for which we wish to check.
476+
- `reaction`: The reaction we wish to check for the `noise_scaing` metadata field.
478477
479478
Example:
480479
```julia
481480
reaction = @reaction k, 0 --> X, [noise_scaling=0.0]
482481
has_noise_scaling(reaction)
482+
```
483483
"""
484484
function has_noise_scaling(reaction::Reaction)
485485
return hasmetadata(reaction, :noise_scaling)
@@ -488,15 +488,16 @@ end
488488
"""
489489
get_noise_scaling(reaction::Reaction)
490490
491-
Returns the noise_scaling metadata from a specific reaction.
491+
Returns `noise_scaing` metadata field for the input reaction.
492492
493493
Arguments:
494-
- `reaction`: The reaction for which we wish to retrive all metadata.
494+
- `reaction`: The reaction we wish to retrieve the `noise_scaing` metadata field.
495495
496496
Example:
497497
```julia
498498
reaction = @reaction k, 0 --> X, [noise_scaling=0.0]
499499
get_noise_scaling(reaction)
500+
```
500501
"""
501502
function get_noise_scaling(reaction::Reaction)
502503
if has_noise_scaling(reaction)
@@ -506,6 +507,88 @@ function get_noise_scaling(reaction::Reaction)
506507
end
507508
end
508509

510+
# Description.
511+
"""
512+
has_description(reaction::Reaction)
513+
514+
Returns `true` if the input reaction has the `description` metadata field assigned, else `false`.
515+
516+
Arguments:
517+
- `reaction`: The reaction we wish to check for the `description` metadata field.
518+
519+
Example:
520+
```julia
521+
reaction = @reaction k, 0 --> X, [description="A reaction"]
522+
has_description(reaction)
523+
```
524+
"""
525+
function has_description(reaction::Reaction)
526+
return hasmetadata(reaction, :description)
527+
end
528+
529+
"""
530+
get_description(reaction::Reaction)
531+
532+
Returns `description` metadata field for the input reaction.
533+
534+
Arguments:
535+
- `reaction`: The reaction we wish to retrieve the `description` metadata field.
536+
537+
Example:
538+
```julia
539+
reaction = @reaction k, 0 --> X, [description="A reaction"]
540+
get_description(reaction)
541+
```
542+
"""
543+
function get_description(reaction::Reaction)
544+
if has_description(reaction)
545+
return getmetadata(reaction, :description)
546+
else
547+
error("Attempts to access `description` metadata field for a reaction which does not have a value assigned for this metadata.")
548+
end
549+
end
550+
551+
# Misc.
552+
"""
553+
has_misc(reaction::Reaction)
554+
555+
Returns `true` if the input reaction has the `misc` metadata field assigned, else `false`.
556+
557+
Arguments:
558+
- `reaction`: The reaction we wish to check for the `misc` metadata field.
559+
560+
Example:
561+
```julia
562+
reaction = @reaction k, 0 --> X, [misc="A reaction"]
563+
misc(reaction)
564+
```
565+
"""
566+
function has_misc(reaction::Reaction)
567+
return hasmetadata(reaction, :misc)
568+
end
569+
570+
"""
571+
get_misc(reaction::Reaction)
572+
573+
Returns `misc` metadata field for the input reaction.
574+
575+
Arguments:
576+
- `reaction`: The reaction we wish to retrieve the `misc` metadata field.
577+
578+
Example:
579+
```julia
580+
reaction = @reaction k, 0 --> X, [misc="A reaction"]
581+
get_misc(reaction)
582+
```
583+
"""
584+
function get_misc(reaction::Reaction)
585+
if has_description(reaction)
586+
return getmetadata(reaction, :misc)
587+
else
588+
error("Attempts to access `misc` metadata field for a reaction which does not have a value assigned for this metadata.")
589+
end
590+
end
591+
509592

510593
### Units Handling ###
511594

test/reactionsystem_core/reaction.jl

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,41 @@ let
8080
@parameters k η
8181
@species X(t) X2(t)
8282

83-
metadata = Pair{Symbol,Any}[]
84-
push!(metadata, :noise_scaling => η)
8583
r1 = Reaction(k, [X], [X2], [2], [1])
86-
r2 = Reaction(k, [X], [X2], [2], [1]; metadata=metadata)
84+
r2 = Reaction(k, [X], [X2], [2], [1]; metadata=[:noise_scaling => η])
8785

8886
@test !Catalyst.has_noise_scaling(r1)
8987
@test Catalyst.has_noise_scaling(r2)
9088
@test_throws Exception Catalyst.get_noise_scaling(r1)
9189
@test isequal(Catalyst.get_noise_scaling(r2), η)
90+
end
91+
92+
# Tests the description metadata.
93+
let
94+
@variables t
95+
@parameters k η
96+
@species X(t) X2(t)
97+
98+
r1 = Reaction(k, [X], [X2], [2], [1])
99+
r2 = Reaction(k, [X], [X2], [2], [1]; metadata=[:description => "A reaction"])
100+
101+
@test !Catalyst.has_description(r1)
102+
@test Catalyst.has_description(r2)
103+
@test_throws Exception Catalyst.get_description(r1)
104+
@test isequal(Catalyst.get_description(r2), "A reaction")
105+
end
106+
107+
# Tests the misc metadata.
108+
let
109+
@variables t
110+
@parameters k η
111+
@species X(t) X2(t)
112+
113+
r1 = Reaction(k, [X], [X2], [2], [1])
114+
r2 = Reaction(k, [X], [X2], [2], [1]; metadata=[:misc => ('M', :M)])
115+
116+
@test !Catalyst.has_misc(r1)
117+
@test Catalyst.has_misc(r2)
118+
@test_throws Exception Catalyst.get_misc(r1)
119+
@test isequal(Catalyst.get_misc(r2), ('C', :C))
92120
end

0 commit comments

Comments
 (0)