More than one Neighborhood + DistanceTransform Plugin

35 views
Skip to first unread message

Osman Abhimata Nugraha

unread,
Nov 22, 2024, 6:51:08 AM11/22/24
to Morpheus users
Hello, I would like to ask two questions:
  1. I would like to implement a CPM model with several (>1) NeighborhoodReporter for each cell, and I need to use distinct neighborhood definition for each of them, e.g. one NeighborhoodReporter is to find how many neighboring cells of cellType.id = 2 at neighborhood distance = 2, and the other NeighborhoodReporter is to find how many neighboring cells of cellType.id = 3 at neighborhood distance = 10. Is it possible to do this? Because as far as I know currently Morpheus only allows us to use one Neighborhood for the whole model.
  2. Is there a DistanceTransform plugin in the newest version of Morpheus? I need to calculate some distance from a certain celltype to the other celltype over the course of the simulation.
Thank you!

Best,
Osman 

Lutz Brusch

unread,
Nov 22, 2024, 9:53:58 AM11/22/24
to Morpheus users
Hi Osman,

thank you for your advanced questions! I don't have simple answers but can only suggest two hacks.

1. True, there is only one type of NeighborhoodReporter with one chosen distance. But you can set this neighborhood distance to the maximum that your model needs (e.g. 10 in your example) and use the following hack. Mind to correctly choose 'distance' or 'order'. Then one of your NeighborhoodReporters works out of the box. For the narrower neighborhood, you then have to insert a condition into the Input of that NeighborhoodReporter and thereby reset the unwanted inputs from larger distance to a trivial value (e.g. zero in a sum or maximum stats). To measure the distance between the two centers of mass of a pair of neighboring cells (and use that in the filter condition), you have to use the scope-prefix 'local.' as the NeighborhoodReporter normally evaluates all symbols in the scope of a neighboring cell. Hence your Input would look like this (on a 2D square or hex lattice):
(sqrt((cell.center.x-local.cell.center.x)^2+(cell.center.y-local.cell.center.y)^2) <= short_distance) * (cell.type == celltype.second.id)
Note, that the <= will evaluate the second condition for all cells at distance==short_distance AND CLOSER, else replace the <= by == to get the fewer cells at exactly that distance (but check if you need some tolerance due to the numerics here).
This hack has been used before in a model of viral infection of a tissue where cells were single nodes on a hex lattice and there was no cell movement or CPM mechanics, please see and run: https://identifiers.org/morpheus/M7677
There are also limits to this hack since the neighborhood kernels are so far implemented for 'reasonable' distances and orders. But it should be relatively easy to fork the source code and duplicate the three NeighborhoodReporter files and modify the copy towards MyNeighborhoodReporter and build MyMorpheus.
For details on the kernels (for each lattice type) and on the 'local.' scope, please also see the in-app docu.

2. There is no public DistanceTransform plugin in Morpheus yet. But under GUI/Analysis, you may check the various Tracker Plugins (e.g. ClusteringTracker) if they are useful for you. Else you can use the 'External' Plugin and let that periodically start an external script to calculate and plot distances from saved data in files.
This has been used in https://identifiers.org/morpheus/M0007 to calculate the radial density statistics on the fly.
However, results from those external calculation cannot feed back into the running model. If you need the latter, then you could work with the Morpheus-Python interface that is provided as a Docker container with a matching Python from https://morpheus.gitlab.io/model/m0006/#installation-instructions
That Morpheus-Python interface has been applied in https://identifiers.org/morpheus/M0006 and more advanced in https://identifiers.org/morpheus/M0008

Please let us know here if any of the above is useful or otherwise open a feature request here: https://gitlab.com/morpheus.lab/morpheus/-/issues (which may queue for a while).

Best,
Lutz for Morpheus.lab

Osman Abhimata Nugraha

unread,
Nov 27, 2024, 8:19:09 AM11/27/24
to Morpheus users
Dear Lutz,

Thank you so much for your swift reply! I have looked into it and I still have some doubts:
  1. I tried to do as you suggested, but it still did not work due to the limitation of the neighborhood distance that I could use. It is said in Morpheus that I cannot use neighborhood distance > 3, but I need it to be much larger (maybe around <= 20, I am not sure). Is there a way to do this? Do I have to fork and modify the source code?
  2. Thank you, I will look into this later, but in general I understand what you said!
Best,
Osman

Lutz Brusch

unread,
Dec 23, 2024, 8:44:48 AM12/23/24
to Morpheus users
Hi Osman,

to extend the spatial range of the NeighborhoodReporter to around 20 lattice nodes would be one option but, as these neighborhoods are currently also used for the CPM interaction energies and CPM updates, this node-based description requires complicated handling at the boundaries. 

It seems better to add a new mode to NeighborhoodReporter which selects the further away cells based on their contact graph or distance of their centroids. I've opened a feature request (https://gitlab.com/morpheus.lab/morpheus/-/issues/300) where we can collect ideas and test models for this. Also, if you would like to implement a prototype for this in your fork, we would be happy to support you and later merge it into the public Morpheus.

Best,
Lutz for Morpheus.lab
Reply all
Reply to author
Forward
0 new messages