From 8e7d57c7f7f067e994ae6b56ac19a35e50f387d5 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 9 Apr 2024 17:50:55 -0400 Subject: [PATCH 1/6] started some work drafting oncological models. --- src/canon/Oncology.jl | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/canon/Oncology.jl diff --git a/src/canon/Oncology.jl b/src/canon/Oncology.jl new file mode 100644 index 00000000..2b1a65e5 --- /dev/null +++ b/src/canon/Oncology.jl @@ -0,0 +1,73 @@ +module Oncology + +using DiagrammaticEquations +using DiagrammaticEquations.Deca + +# for testing +using Decapodes +using ComponentArrays +using CombinatorialSpaces + +using ..Canon +using Markdown + +@docapode("Logistic" + ,"https://www.google.com" + ,"" + ,logistic + ,begin + r::Constant # intrinsic growth rate + K::Constant # carrying capacity + V::Form0 + + ∂ₜ(V) == r * V * (1 - V / K) + end +) + +logistic = @decapode begin + K::Constant + r::Constant + V::Form0 + + ∂ₜ(V) == r * V * (1 - V / K) +end + +logadv = @decapode begin + K₀::Constant # carrying-capacity + c::Constant # waste metabolite process + r::Constant # TODO should be contingent on nutrient influx + K::Form0 # current carrying-capacity + W::Form0 # waste + V::Form0 + ∂ₜ(W) == c * V + K == K₀- W + ∂ₜ(V) == r * V * (1 - V / K) +end + +## Another way to account for angiogenesis effect on tumor +## growth is by assuming the carrying capacity of the tumor is +## determined by the effective tumor vascular support that is +## in turn affected by the tumor volume (Eqs. 15 and 16). -Review of... + +# gompertz = @decapode begin +# {a,b,c}::Constant +# V::Form0 +# ∂ₜ(V) == a * V * log(b / (V + c)) +# end + +space = Icosphere(1) |> loadmesh + +sim = evalsim(logistic) + +f = sim(space, default_dec_generate) + +forms = ComponentArray(V = rand(nv(space))) + +copied = copy(forms) + +params = ComponentArray(r = 1, K = 2) + +f(copied, forms, params, 0) + + +end From 5ffc0fa5949981fa870f6da89ac75c55b9b45cc5 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 10 Apr 2024 06:52:31 -0400 Subject: [PATCH 2/6] added docapodes for LM/GR/MC's logistic/gompertz models. --- src/canon/Canon.jl | 1 + src/canon/Oncology.jl | 65 ++++++++++++++----------------------------- 2 files changed, 22 insertions(+), 44 deletions(-) diff --git a/src/canon/Canon.jl b/src/canon/Canon.jl index 2008dd69..aaec6be6 100644 --- a/src/canon/Canon.jl +++ b/src/canon/Canon.jl @@ -45,5 +45,6 @@ include("Physics.jl") include("Chemistry.jl") include("Biology.jl") include("Environment.jl") +include("Oncology.jl") end diff --git a/src/canon/Oncology.jl b/src/canon/Oncology.jl index 2b1a65e5..6c25ba78 100644 --- a/src/canon/Oncology.jl +++ b/src/canon/Oncology.jl @@ -13,61 +13,38 @@ using Markdown @docapode("Logistic" ,"https://www.google.com" - ,"" + ,"Eq. 34 from Yi et al. + A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance + Evolution of Solid Tumors, + with f given as logistic growth. (Eq. 5)" ,logistic ,begin - r::Constant # intrinsic growth rate - K::Constant # carrying capacity - V::Form0 + C::Form0 + (Dif, Kd, Cmax)::Constant - ∂ₜ(V) == r * V * (1 - V / K) + fC == C * (1 - C / Cmax) + ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C end ) -logistic = @decapode begin - K::Constant - r::Constant - V::Form0 +@docapode("Gompertz" + ,"https://www.google.com" + ,"Eq. 34 from Yi et al. + A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance + Evolution of Solid Tumors, + with f given as Gompertz growth. (Eq. 6)" + ,gompertz + ,begin + C::Form0 + (Dif, Kd, Cmax)::Constant - ∂ₜ(V) == r * V * (1 - V / K) -end - -logadv = @decapode begin - K₀::Constant # carrying-capacity - c::Constant # waste metabolite process - r::Constant # TODO should be contingent on nutrient influx - K::Form0 # current carrying-capacity - W::Form0 # waste - V::Form0 - ∂ₜ(W) == c * V - K == K₀- W - ∂ₜ(V) == r * V * (1 - V / K) -end + fC == C * ln(Cmax / C) + ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C +end) ## Another way to account for angiogenesis effect on tumor ## growth is by assuming the carrying capacity of the tumor is ## determined by the effective tumor vascular support that is ## in turn affected by the tumor volume (Eqs. 15 and 16). -Review of... -# gompertz = @decapode begin -# {a,b,c}::Constant -# V::Form0 -# ∂ₜ(V) == a * V * log(b / (V + c)) -# end - -space = Icosphere(1) |> loadmesh - -sim = evalsim(logistic) - -f = sim(space, default_dec_generate) - -forms = ComponentArray(V = rand(nv(space))) - -copied = copy(forms) - -params = ComponentArray(r = 1, K = 2) - -f(copied, forms, params, 0) - - end From c995a7f58d75ad790f70179b3c54630064c3a9a1 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 10 Apr 2024 06:54:30 -0400 Subject: [PATCH 3/6] added better sources for the two new oncology docapodes --- src/canon/Oncology.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/canon/Oncology.jl b/src/canon/Oncology.jl index 6c25ba78..3107100f 100644 --- a/src/canon/Oncology.jl +++ b/src/canon/Oncology.jl @@ -12,7 +12,7 @@ using ..Canon using Markdown @docapode("Logistic" - ,"https://www.google.com" + ,"https://en.wikipedia.org/wiki/Logistic_function" ,"Eq. 34 from Yi et al. A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance Evolution of Solid Tumors, @@ -28,7 +28,7 @@ using Markdown ) @docapode("Gompertz" - ,"https://www.google.com" + ,"https://en.wikipedia.org/wiki/Gompertz_function" ,"Eq. 34 from Yi et al. A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance Evolution of Solid Tumors, From aba9dcc63d50e0d60f43b89d763c10d5f3149d0a Mon Sep 17 00:00:00 2001 From: Luke Morris <70283489+lukem12345@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:23:34 -0400 Subject: [PATCH 4/6] Added Gompertz Decapode example --- examples/chemistry/gompertz.jl | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 examples/chemistry/gompertz.jl diff --git a/examples/chemistry/gompertz.jl b/examples/chemistry/gompertz.jl new file mode 100644 index 00000000..a0bf50f3 --- /dev/null +++ b/examples/chemistry/gompertz.jl @@ -0,0 +1,97 @@ +using Catlab +using CombinatorialSpaces +using Decapodes +using DiagrammaticEquations +using Distributions +using MLStyle +using OrdinaryDiffEq +using LinearAlgebra +using ComponentArrays +using CairoMakie +using GeometryBasics: Point2, Point3 +Point2D = Point2{Float64} +Point3D = Point3{Float64} + +function show_heatmap(Cdata) + heatmap(reshape(Cdata, (floor(Int64, sqrt(length(Cdata))), floor(Int64, sqrt(length(Cdata)))))) +end + +s = triangulated_grid(50,50,0.2,0.2,Point2D) +sd = EmbeddedDeltaDualComplex2D{Bool, Float64, Point2D}(s) +subdivide_duals!(sd, Circumcenter()) + +constants_and_parameters = ( + Dif = 0.005, + Kd = 0.5, + Cmax = 10 +) + +# Eq. 34 from Yi et al. +# A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance +# Evolution of Solid Tumors, +# with f given as logistic growth. (Eq. 5) +Logistic = @decapode begin + C::Form0 + (Dif, Kd, Cmax)::Constant + + fC == C * (1 - C / Cmax) + ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C +end + +sim = eval(gensim(Logistic)) + +fₘ = sim(sd, nothing, DiagonalHodge()) + +# "The model ... considers an equivalent radially symmetric tumour" +# - Murray J.D., Glioblastoma brain tumours +c_dist = MvNormal([25, 25], 2) +C = 100 * [pdf(c_dist, [p[1], p[2]]) for p in sd[:point]] + +u₀ = ComponentArray(C=C) +tₑ = 15.0 + +prob = ODEProblem(fₘ, u₀, (0, tₑ), constants_and_parameters) +soln = solve(prob, Tsit5()) + +show_heatmap(soln(0).C) +show_heatmap(soln(tₑ).C) + +Gompertz = @decapode begin + C::Form0 + (Dif, Kd, Cmax)::Constant + + fC == C * ln(Cmax / C) + ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C +end + +sim = eval(gensim(Gompertz)) + +function generate(sd, symbol, hodge=DiagonalHodge()) + op = @match symbol begin + :ln => (x -> log.(x)) + _ => error("Unmatched operator $my_symbol") + end + return op +end + +fₘ = sim(sd, generate, DiagonalHodge()) + +constants_and_parameters = ( + Dif = 0.005, + Kd = 0.5, + Cmax = 10 +) + +# "The model ... considers an equivalent radially symmetric tumour" +# - Murray J.D., Glioblastoma brain tumours +c_dist = MvNormal([25, 25], 2) +C = 100 * [pdf(c_dist, [p[1], p[2]]) for p in sd[:point]] + +u₀ = ComponentArray(C=C) +tₑ = 15.0 + +prob = ODEProblem(fₘ, u₀, (0, tₑ), constants_and_parameters) +soln = solve(prob, Tsit5()) + +show_heatmap(soln(0).C) +show_heatmap(soln(tₑ).C) \ No newline at end of file From 7fbbb4bae0a370f1aeb3217862deea812d1d70fd Mon Sep 17 00:00:00 2001 From: Luke Morris <70283489+lukem12345@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:37:34 -0400 Subject: [PATCH 5/6] Decompose tumor models, promote /, add ln --- examples/chemistry/gompertz.jl | 109 +++++++++++++++------------------ src/canon/Oncology.jl | 38 +++++++----- src/canon/Physics.jl | 2 +- src/operators.jl | 1 + src/simulation.jl | 3 + 5 files changed, 78 insertions(+), 75 deletions(-) diff --git a/examples/chemistry/gompertz.jl b/examples/chemistry/gompertz.jl index a0bf50f3..d39ae5dc 100644 --- a/examples/chemistry/gompertz.jl +++ b/examples/chemistry/gompertz.jl @@ -1,7 +1,9 @@ +# Load Dependencies using Catlab +using Catlab.Graphics using CombinatorialSpaces using Decapodes -using DiagrammaticEquations +using DiagrammaticEquations, DiagrammaticEquations.Deca using Distributions using MLStyle using OrdinaryDiffEq @@ -12,35 +14,30 @@ using GeometryBasics: Point2, Point3 Point2D = Point2{Float64} Point3D = Point3{Float64} +# Load in our Decapodes models +using Decapodes.Canon.Oncology + +# Examine our models +# Note that the implementation is entirely specified by its documentation +@doc invasion + +@doc logistic + +@doc gompertz + +# Load in a mesh, initial conditions, and a plotting function function show_heatmap(Cdata) heatmap(reshape(Cdata, (floor(Int64, sqrt(length(Cdata))), floor(Int64, sqrt(length(Cdata)))))) end -s = triangulated_grid(50,50,0.2,0.2,Point2D) -sd = EmbeddedDeltaDualComplex2D{Bool, Float64, Point2D}(s) -subdivide_duals!(sd, Circumcenter()) +s = triangulated_grid(50,50,0.2,0.2,Point2D); +sd = EmbeddedDeltaDualComplex2D{Bool, Float64, Point2D}(s); +subdivide_duals!(sd, Circumcenter()); constants_and_parameters = ( - Dif = 0.005, - Kd = 0.5, - Cmax = 10 -) - -# Eq. 34 from Yi et al. -# A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance -# Evolution of Solid Tumors, -# with f given as logistic growth. (Eq. 5) -Logistic = @decapode begin - C::Form0 - (Dif, Kd, Cmax)::Constant - - fC == C * (1 - C / Cmax) - ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C -end - -sim = eval(gensim(Logistic)) - -fₘ = sim(sd, nothing, DiagonalHodge()) + invasion_Dif = 0.005, + invasion_Kd = 0.5, + Cmax = 10) # "The model ... considers an equivalent radially symmetric tumour" # - Murray J.D., Glioblastoma brain tumours @@ -48,50 +45,44 @@ c_dist = MvNormal([25, 25], 2) C = 100 * [pdf(c_dist, [p[1], p[2]]) for p in sd[:point]] u₀ = ComponentArray(C=C) -tₑ = 15.0 -prob = ODEProblem(fₘ, u₀, (0, tₑ), constants_and_parameters) -soln = solve(prob, Tsit5()) +# Compose our Proliferation-Invasion models +proliferation_invasion_composition_diagram = @relation () begin + proliferation(C, fC, Cmax) + invasion(C, fC, Cmax) +end -show_heatmap(soln(0).C) -show_heatmap(soln(tₑ).C) +logistic_proliferation_invasion_cospan = oapply(proliferation_invasion_composition_diagram, + [Open(logistic, [:C, :fC, :Cmax]), + Open(invasion, [:C, :fC, :Cmax])]) -Gompertz = @decapode begin - C::Form0 - (Dif, Kd, Cmax)::Constant +logistic_proliferation_invasion = apex(logistic_proliferation_invasion_cospan) - fC == C * ln(Cmax / C) - ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C -end +gompertz_proliferation_invasion_cospan = oapply(proliferation_invasion_composition_diagram, + [Open(gompertz, [:C, :fC, :Cmax]), + Open(invasion, [:C, :fC, :Cmax])]) -sim = eval(gensim(Gompertz)) +gompertz_proliferation_invasion = apex(gompertz_proliferation_invasion_cospan) -function generate(sd, symbol, hodge=DiagonalHodge()) - op = @match symbol begin - :ln => (x -> log.(x)) - _ => error("Unmatched operator $my_symbol") - end - return op -end +# Generate the logistic simulation +logistic_sim = evalsim(logistic_proliferation_invasion) -fₘ = sim(sd, generate, DiagonalHodge()) +lₘ = logistic_sim(sd, default_dec_generate, DiagonalHodge()) -constants_and_parameters = ( - Dif = 0.005, - Kd = 0.5, - Cmax = 10 -) +# Execute the logistic simulation +tₑ = 15.0 -# "The model ... considers an equivalent radially symmetric tumour" -# - Murray J.D., Glioblastoma brain tumours -c_dist = MvNormal([25, 25], 2) -C = 100 * [pdf(c_dist, [p[1], p[2]]) for p in sd[:point]] +prob = ODEProblem(lₘ, u₀, (0, tₑ), constants_and_parameters) +logistic_soln = solve(prob, Tsit5()) -u₀ = ComponentArray(C=C) -tₑ = 15.0 +show_heatmap(logistic_soln(tₑ).C) + +# Generate the Gompertz simulation +gompertz_sim = evalsim(gompertz_proliferation_invasion) +gₘ = gompertz_sim(sd, default_dec_generate, DiagonalHodge()) -prob = ODEProblem(fₘ, u₀, (0, tₑ), constants_and_parameters) -soln = solve(prob, Tsit5()) +# Execute the Gompertz simulation +prob = ODEProblem(gₘ, u₀, (0, tₑ), constants_and_parameters) +gompertz_soln = solve(prob, Tsit5()) -show_heatmap(soln(0).C) -show_heatmap(soln(tₑ).C) \ No newline at end of file +show_heatmap(gompertz_soln(tₑ).C) diff --git a/src/canon/Oncology.jl b/src/canon/Oncology.jl index 3107100f..3b5b7ddd 100644 --- a/src/canon/Oncology.jl +++ b/src/canon/Oncology.jl @@ -11,35 +11,43 @@ using CombinatorialSpaces using ..Canon using Markdown +@docapode("TumorInvasion" + ,"https://en.wikipedia.org/wiki/Cancer_cell#Causes" + ,"Eq. 35 from Yi et al. + A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance + Evolution of Solid Tumors" + ,invasion + ,begin + (C,fC)::Form0 + (Dif, Kd, Cmax)::Constant + + ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C +end) + @docapode("Logistic" ,"https://en.wikipedia.org/wiki/Logistic_function" - ,"Eq. 34 from Yi et al. + ,"Eq. 5 from Yi et al. A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance - Evolution of Solid Tumors, - with f given as logistic growth. (Eq. 5)" + Evolution of Solid Tumors" ,logistic ,begin - C::Form0 - (Dif, Kd, Cmax)::Constant + (C,fC)::Form0 + Cmax::Constant fC == C * (1 - C / Cmax) - ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C - end -) + end) @docapode("Gompertz" ,"https://en.wikipedia.org/wiki/Gompertz_function" - ,"Eq. 34 from Yi et al. + ,"Eq. 6 from Yi et al. A Review of Mathematical Models for Tumor Dynamics and Treatment Resistance - Evolution of Solid Tumors, - with f given as Gompertz growth. (Eq. 6)" + Evolution of Solid Tumors" ,gompertz ,begin - C::Form0 - (Dif, Kd, Cmax)::Constant + (C,fC)::Form0 + Cmax::Constant - fC == C * ln(Cmax / C) - ∂ₜ(C) == Dif * Δ(C) + fC - Kd * C + fC == C * ln(Cmax / C) end) ## Another way to account for angiogenesis effect on tumor diff --git a/src/canon/Physics.jl b/src/canon/Physics.jl index 90839fe7..44afb8b3 100644 --- a/src/canon/Physics.jl +++ b/src/canon/Physics.jl @@ -101,7 +101,7 @@ end) end ) -@docapode("Schoedinger" +@docapode("Schroedinger" ,"https://en.wikipedia.org/wiki/Schrodinger_equation" ,"The evolution of the wave function over time." ,schroedinger diff --git a/src/operators.jl b/src/operators.jl index f8f60098..2e77cecb 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -136,6 +136,7 @@ function default_dec_generate(sd, my_symbol, hodge=GeometricHodge()) :plus => (+) :(-) || :neg => x -> -1 .* x + :ln => (x -> log.(x)) _ => error("Unmatched operator $my_symbol") end diff --git a/src/simulation.jl b/src/simulation.jl index 3de62f5d..0f3d4633 100644 --- a/src/simulation.jl +++ b/src/simulation.jl @@ -339,6 +339,9 @@ end =# if(operator == :(-)) operator = promote_arithmetic_map[operator] end + if(operator == :(/)) + operator = promote_arithmetic_map[operator] + end visited_2[op] = true visited_Var[r] = true From 9fe499e72cd92e0e6ce9620573b34abcd983ac80 Mon Sep 17 00:00:00 2001 From: Luke Morris <70283489+lukem12345@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:39:41 -0400 Subject: [PATCH 6/6] Move gompertz.jl to oncology directory --- .../gompertz.jl => oncology/tumor_proliferation_invasion.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{chemistry/gompertz.jl => oncology/tumor_proliferation_invasion.jl} (100%) diff --git a/examples/chemistry/gompertz.jl b/examples/oncology/tumor_proliferation_invasion.jl similarity index 100% rename from examples/chemistry/gompertz.jl rename to examples/oncology/tumor_proliferation_invasion.jl