RobertGregg / CellularPotts.jl

Link to Documentation
https://robertgregg.github.io/CellularPotts.jl/dev/
MIT License
20 stars 5 forks source link

BoundsError using ChemoTaxis #51

Closed aminGhorbel93 closed 11 months ago

aminGhorbel93 commented 12 months ago

I try to use this package for a chemotaxis simulation and got the following MWE

using CellularPotts

space = CellSpace(100, 100, isPeriodic=false)

initialCellState = CellTable(
    [:Epithelial, :Epithelial],
    [200, 200],
    [1, 1]
)

positions = [
    (10, 10),
    (90, 90)
]

initialCellState = addcellproperty(initialCellState, :positions, positions)

species = [100exp(-((x-xdim/2)^2+(y-ydim/2)^2)/10000) for x in 1:xdim, y in 1:ydim];

penalties = [
    AdhesionPenalty([30 30 30;
                    30 30 30;
                    30 30 30]),
    VolumePenalty([30, 30]),
    PerimeterPenalty([0, 5]),
    MigrationPenalty(50, [100, 100], size(space)),
    ChemoTaxisPenalty([50], species)
]

cpm = CellPotts(space, initialCellState, penalties)
ModelStep!(cpm)

which errors with

ERROR: BoundsError: attempt to access 2-element OffsetArray(::Vector{Int64}, 0:1) with eltype Int64 with indices 0:1 at index [-1]
Stacktrace:
 [1] throw_boundserror(A::OffsetArrays.OffsetVector{Int64, Vector{Int64}}, I::Tuple{Int64})
   @ Base .\abstractarray.jl:703
 [2] checkbounds
   @ .\abstractarray.jl:668 [inlined]
 [3] getindex
   @ C:\Users\amine\.julia\packages\OffsetArrays\0MOrf\src\OffsetArrays.jl:435 [inlined]
 [4] addPenalty!
   @ c:\Users\amine\.julia\dev\CellularPotts\src\Penalties.jl:200 [inlined]
 [5] calculateΔH(cpm::CellPotts{2, Int64, NamedTuple{(:names, :cellIDs, :typeIDs, :volumes, :desiredVolumes, :perimeters, :desiredPerimeters, :positions), Tuple{OffsetArrays.OffsetVector{Symbol, Vector{Symbol}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Tuple{Int64, Int64}, Vector{Tuple{Int64, Int64}}}}}, Union{AdhesionPenalty{OffsetArrays.OffsetMatrix{Int64, Matrix{Int64}}}, ChemoTaxisPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}, Matrix{Float64}}, MigrationPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}, PerimeterPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}, VolumePenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}}})
   @ CellularPotts C:\Users\amine\.julia\dev\CellularPotts\src\MarkovStep.jl:10
 [6] MHStep!(cpm::CellPotts{2, Int64, NamedTuple{(:names, :cellIDs, :typeIDs, :volumes, :desiredVolumes, :perimeters, :desiredPerimeters, :positions), Tuple{OffsetArrays.OffsetVector{Symbol, Vector{Symbol}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Tuple{Int64, Int64}, Vector{Tuple{Int64, Int64}}}}}, Union{AdhesionPenalty{OffsetArrays.OffsetMatrix{Int64, Matrix{Int64}}}, ChemoTaxisPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}, Matrix{Float64}}, MigrationPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}, PerimeterPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}, VolumePenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}}})
   @ CellularPotts C:\Users\amine\.julia\dev\CellularPotts\src\MarkovStep.jl:59
 [7] ModelStep!(cpm::CellPotts{2, Int64, NamedTuple{(:names, :cellIDs, :typeIDs, :volumes, :desiredVolumes, :perimeters, :desiredPerimeters, :positions), Tuple{OffsetArrays.OffsetVector{Symbol, Vector{Symbol}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Int64, Vector{Int64}}, OffsetArrays.OffsetVector{Tuple{Int64, Int64}, Vector{Tuple{Int64, Int64}}}}}, Union{AdhesionPenalty{OffsetArrays.OffsetMatrix{Int64, Matrix{Int64}}}, ChemoTaxisPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}, Matrix{Float64}}, MigrationPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}, PerimeterPenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}, VolumePenalty{OffsetArrays.OffsetVector{Int64, Vector{Int64}}}}})
   @ CellularPotts C:\Users\amine\.julia\dev\CellularPotts\src\MarkovStep.jl:105
 [8] top-level scope
   @ c:\Users\amine\Documents\Julia playground\julia_playground\ChemoTaxis_mwe.jl:31

Thank you for working on this!

RobertGregg commented 12 months ago

Hi @aminGhorbel93! Thank you for trying out my package. It looks like I need to update this example. Could you check that you're using the most recent version of the package? Some small fixes:

initialCellState = CellState(
    [:Epithelial],
    [200],
    [2]
)

Or even this would work because we only have one cell type:

initialCellState = CellState(:Epithelial, 200, 2)

After these small fixes your code should look like this:

using CellularPotts

const xdim = 100
const ydim = 100

space = CellSpace(xdim, ydim, periodic=false)

initialCellState = CellState(:Epithelial, 200, 2)

positions = [
    (10, 10),
    (90, 90)
]

initialCellState = addcellproperty(initialCellState, :positions, positions)

species = [100exp(-((x-xdim/2)^2+(y-ydim/2)^2)/10000) for x in 1:xdim, y in 1:ydim];

penalties = [
    AdhesionPenalty([30 30 30;
                    30 30 30;
                    30 30 30]),
    VolumePenalty([30, 30]),
    PerimeterPenalty([0, 5]),
    MigrationPenalty(50, [100, 100], size(space)),
    ChemoTaxisPenalty([50], species)
]

cpm = CellPotts(space, initialCellState, penalties)
ModelStep!(cpm)

Unfortunately there is a small bug in the ChemoTaxisPenalty which I need to fix. I will try and update the package with the fix asap and the above code should run fine. I'll let you know when that happens.

aminGhorbel93 commented 12 months ago

Hi there,

Thank you for the swift response and the helpful code updates. I've implemented the changes you suggested, though they didn't directly resolve the issues I encountered. Your CellularPotts package has been immensely valuable in my simulations.

I eagerly await the upcoming fix for the ChemoTaxisPenalty bug. Your prompt assistance is greatly appreciated! :)

RobertGregg commented 11 months ago

I've submitted the request to update the package in the Julia registry (v0.3.2). The new package version should be up soon with the fix you need.