Skip to content

Commit

Permalink
Simplify CellState
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGregg committed Aug 29, 2024
1 parent 7c278ea commit 6bd0784
Show file tree
Hide file tree
Showing 37 changed files with 734 additions and 809 deletions.
8 changes: 1 addition & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name = "CellularPotts"
uuid = "11b7dee7-cd95-48a5-a457-717aae94d0bd"
authors = ["Robert <[email protected]> and contributors"]
version = "0.3.4"
version = "0.3.5"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -17,22 +16,17 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
ColorSchemes = "3"
Colors = "0.12"
DataFrames = "1"
Documenter = "1"
Graphs = "1"
Literate = "2"
Metis = "1"
OffsetArrays = "1"
Plots = "1"
PrettyTables = "2"
StatsBase = "0.34"
Tables = "1"
julia = "1"

[extras]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 24 additions & 21 deletions docs/src/ExampleGallery/BringingODEsToLife/BringingODEsToLife.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ space = CellSpace(200,200)

# In the CellState we specify one epithelial cell with a volume of 200 pixels
# The cell will be positioned at the halfway point within the space.
initialCellState = CellState(:Epithelial, 200, 1, positions = size(space) 2);

# From the DifferentialEquations example, a theoretical protein X was created for each cell that increases linearly in time with rate parameter α
const α = 0.3;

# ProteinX needs an initial condition which we set to 0.2. Note that for :Medium (grid locations without a cell) we give a concentration of zero.
u0 = [0.0, 0.2]
initialCellState = addcellproperty(initialCellState, :ProteinX, u0)
state = CellState(
names = :Epithelial,
volumes = 200,
counts = 1,
positions = size(space) 2
);

# Keeping the model simple, we'll only include an Adhesion and Volume penalty
penalties = [
Expand All @@ -29,12 +27,15 @@ penalties = [
]

# Now that we have all the pieces, we can generate a new CPM model.
cpm = CellPotts(space, initialCellState, penalties);
cpm = CellPotts(space, state, penalties);

# By default, CellularPotts models to not record states as they change overtime to increase computional speed. To have the model record past states we can toggle the appropriate keyword.
cpm.recordHistory = true;

# ## DifferentialEquations.jl setup

# Currently by default CellularPotts models to not record states as they change overtime to increase computional speed. To have the model record past states we can toggle the appropriate keyword.
cpm.recordHistory = true;
# From the DifferentialEquations example, a theoretical protein X was created for each cell that increases linearly in time with rate parameter α
const α = 0.3;

# As ProteinX evolves over time for each cell, the CPM model also needs to step forward in time to try and minimize its energy. To facilitate this, we can use the callback feature from DifferentialEquations.jl. Here specifically we use the `PeriodicCallback` function which will stop the ODE solve at regular time intervals and run some other function for us (Here it will be the `ModelStep!` function).

Expand Down Expand Up @@ -69,18 +70,19 @@ function affect!(integrator,cpm)
u[end] = 1-Θ

#Adding a call to divide the cells in the CPM
CellDivision!(cpm, cellID-1)
CellDivision!(cpm, cellID)
return nothing
end

# This will instantiate the ContinuousCallback triggering cell division
ccb = ContinuousCallback(condition,integrator -> affect!(integrator, cpm));

# To pass multiple callback into DifferentialEquations we need to collect them into a set.
# To pass multiple callbacks into DifferentialEquations, we need to collect them into a set.
callbacks = CallbackSet(pcb, ccb);


# Define the ODE model and solve
u0 = [0.2]
tspan = (0.0,20.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob, Tsit5(), callback=callbacks);
Expand All @@ -91,12 +93,13 @@ sol = solve(prob, Tsit5(), callback=callbacks);
using Plots, Printf

# Plot the total cell count over time
plot(sol.t,map((x)->length(x),sol[:]),lw=3,
ylabel="Number of Cells",xlabel="Time",legend=nothing)
plot(sol.t, map((x)->length(x),sol[:]), lw=3,
ylabel="Number of Cells", xlabel="Time", legend=nothing)

# Plot ProteinX dynamics for a specific cell
ts = range(0, stop=20, length=100)
plot(ts,map((x)->x[2],sol.(ts)),lw=3, ylabel="Amount of X in Cell 1",xlabel="Time",legend=nothing)
ts = range(0, stop=20, length=1000)
plot(ts, first.(sol.(ts)), lw=3,
ylabel="Amount of X in Cell 1", xlabel="Time", legend=nothing)

# Finally, we can create an animation of the CPM to see the cells dividing. I've dropped the first few frames because the first cell takes a while to divide.
proteinXConc = zeros(size(space)...)
Expand All @@ -105,11 +108,11 @@ anim = @animate for t in Iterators.drop(1:cpm.step.counter,5*timeScale)
currTime = @sprintf "Time: %.2f" t/timeScale

cpmt = cpm(t)
currSol = sol((t+1)/timeScale )
currSol = sol((t+1)/timeScale)

#Map protein concentrations to space
for i in CartesianIndices(proteinXConc)
proteinXConc[i] = currSol[cpmt.space.nodeIDs[i]+1]
#Map protein concentrations to space, set :Medium to zero
for (i,cellID) in enumerate(cpmt.space.nodeIDs)
proteinXConc[i] = iszero(cellID) ? 0.0 : currSol[cellID]
end

plt = heatmap(
Expand Down
Loading

2 comments on commit 6bd0784

@RobertGregg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/114132

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.5 -m "<description of version>" 6bd0784b1d4f7df5d586bc3bee1c5e2a244d6fcb
git push origin v0.3.5

Please sign in to comment.