Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing holes or removing a patch of cells from within a tissue #220

Open
sniffo opened this issue Feb 2, 2021 · 16 comments · Fixed by #263
Open

Introducing holes or removing a patch of cells from within a tissue #220

sniffo opened this issue Feb 2, 2021 · 16 comments · Fixed by #263

Comments

@sniffo
Copy link
Contributor

sniffo commented Feb 2, 2021

I was wondering if there is a way to remove cells from the middle of a tissue patch? I tried the remove_face method, but running the update_all method from the geometry classes seems to connect all the loose edges and fill the gap - is there a way to prevent this from happening - not quite sure which update method is causing it to close.

Thanks,
Tasnif

@glyg
Copy link
Member

glyg commented Feb 2, 2021

Hi Tasnif,

When you draw the sheet with sheet_view(sheet, face={"visible": True}, edge={'headwidth': 1.0}) does the face appear? The only edges left should be the ones form the adjacent faces. You should also see the arrows from the edges

@sniffo
Copy link
Contributor Author

sniffo commented Feb 2, 2021

image
This is what it looks like after removing the faces

@sniffo
Copy link
Contributor Author

sniffo commented Feb 2, 2021

After running update_all method:

image

@sniffo
Copy link
Contributor Author

sniffo commented Feb 2, 2021

I would like to connect the dangling edges. Or remove them and sanitize the inner border if you will.

@sniffo
Copy link
Contributor Author

sniffo commented Feb 2, 2021

Apologies for multiple comments, but here it is with faces visible

image

@glyg
Copy link
Member

glyg commented Feb 2, 2021

IDK why all the edges are not deleted by the remove_faces method. I suspect that what you see is matplotlib replacing Nans by 0s.

What you can try after the remove_face is to apply sheet.sanitize(trim_borders=True) hopefully it should do what you want.
I think there is still something buggy in the remove_face method. Can you loolk if you have NaNs in sheet.edge_df?

@glyg
Copy link
Member

glyg commented Feb 2, 2021

Also it is not clear to me if you want to keep the partially deleted cells on you first graph

@sniffo
Copy link
Contributor Author

sniffo commented Feb 2, 2021

No Nans in edge_df, I believe remove_face removes the face by collapsing all edges to a single vertex in the center. However, the method does not run update_all since it does not take geom as an argument, and that may be required to display the correct connections.

# collapse all edges connected to the face vertices sheet.edge_df.replace({"srce": verts, "trgt": verts}, new_vert, inplace=True)

The sheet.sanitize method does not work unfortunately

I do want to keep the partially deleted cells, their indices were not included when using remove_face. The missing edges are the edges shared by the deleted face and their neighbors.

You can find the code in this notebook: https://github.com/sniffo/Tyssue-General-Notebooks/blob/main/Hole%20in%20Tissue.ipynb

@sniffo
Copy link
Contributor Author

sniffo commented Feb 2, 2021

I propose an alternative method for removing a face, which simply removes the face itself, and only the half-edges associated with the face. This should achieve what I am trying to do, please let me know if that is incorrect. I will start working on this asap.

@glyg
Copy link
Member

glyg commented Feb 2, 2021

Oh yes you're right! Maybe the method could be caled drop_face or someting!

You can use the remove method that removes the edges (and the associated face)

Please open a PR when you have something if you don't mind (maybe also add a comment in remove_face docstring)

@sniffo
Copy link
Contributor Author

sniffo commented Feb 4, 2021

I came up with the following, however, there seems to be an issue with removing multiple faces. Using sanitize or setting trim_borders = True removes some unwanted edges.

This is what I have:

def drop_face(sheet, face, **kwargs):
    """
    Removes the face indexed by "face" and all associated edges
    """    
    edge = sheet.edge_df.loc[(sheet.edge_df['face'] == face)].index
    
     
    sheet.remove(edge, **kwargs)

Currently only takes one face as an argument, changing it to array-like for multiple faces should be simple. However, there is the following issue. The initial tissue:

image

After sequentially "dropping" the center face and its 5 neighbors:

image

After running sanitize with trim_borders = True:

image

Seems that for the cells that have two border edges on the new "inner" border, the edges are simply removed and a new edge is not created. Currently trying to figure out why this might be.

@sniffo
Copy link
Contributor Author

sniffo commented Feb 4, 2021

Apologies, I have figured out the issue here, it was the order of operations. Running geom.update_all after running sanitize seems to do the trick.

image

I will update the method to take a list of face indices and create the PR.

@glyg
Copy link
Member

glyg commented Feb 4, 2021

Great, thank you Tasnif

@glyg
Copy link
Member

glyg commented May 12, 2021

hi @sniffo did you have a chance to update your code, are you up to create a PR?
Thanks

Guillaume

@sniffo
Copy link
Contributor Author

sniffo commented Aug 3, 2021

Hi @glyg sincere apologies, have not been working on simulations for a bit so I just saw this. The code has been updated I will put in the PR this weekend,

Best,
Tasnif

@glyg
Copy link
Member

glyg commented Aug 7, 2021

Hi Tasnif, I'm on holiday for tow more weeks, will review your PR then with great pleasure!

sophietheis added a commit to sophietheis/tyssue that referenced this issue Feb 28, 2023
@sophietheis sophietheis linked a pull request Feb 28, 2023 that will close this issue
glyg added a commit that referenced this issue Dec 27, 2023
* Fix for Issues #261 - cell division failed at the border

* Fix Mesh creation

Surface mesh create wasn't create all faces. Now it is fixed. 
Also : -add two methods to Mesh to list faces and vertices. 
           -generalised coordinates
           -add `write_polygon_mesh` to export mesh into .ply to visualised with blinder

* Add 2D collision solver

Add class to solve collision in 2D or in 3D. 
3D collision solver need to be fixed

* Update README.md

Add `How to cite` section
Add `Geometry` section
Add `Publications` section
Update bibliography link

* Generalised wich vertex penetrate face

* Attempt to set out particular cases

* Detect and fix self-crossing face

Unable to make this algo works... https://europepmc.org/article/PMC/3660981
Use ordered vertices and their angle position.
     -> uncrossed face : angles are monotonically increasing
     -> crossed face : angles are not monotonically increasing

* Use `.apply()` 

Need to recalculate angle_e for twisted face
One fix which is only suitable for 2D lateral sheet...

* ENH: write `mean_XX` method in `Epithelium` class (Issue #224)

* Fix according to comments

* Fix Issue #258 ax argument not considered in `plt_draw.sheet_view`

* ENH: pass column name to `data_at_opposite` issue (#245)

* Add publication and remove bibtex reference

* Add check face convexity

* Use reset_index and code simplification

* yAdd to_mesh function (issue #221) and some test

* Remove the use of reset_index in face_self_intersect

* use ipv_draw with 2D data

* Fix solution after detection point inside polygon

* Remove solving collision for 2 same face...

* Abord vertex displacement if it creates twisted face

* New way to calculate the position of "penetrate" vertices

For now, it is the best way to fix collision (compare to what I tried before). So when a vertex is inside an other face. It is pullback by 10% of the length of the ([v-f1]+[v-f2]/2). with v, f1, f2 position of vertices and center of face 1 and face 2, which are the faces to which the vertex belongs.  It is not perfect and very arbitrary for now, but it avoids vertex displacement at strange place.

* WIP - use force field to fix collision

* Small fix

* Remove function duplication due to circular import

* Calculate "repulsion" gradient in the effector method. Remove loop

* Fix tests

Remove collisions tests
Fix method call in meshes test
Comment "update_repulstion" method in planar geometry

* Add lateralsheet shapes + test

* Update publication + add collapse texte

* Add test for Repulsion effector

* Add test update repulsion

* Remove unused import

* Add `drop_face` to allow hole (issues #220 and #141) (associate #221)

* Update readme.md

* Update publications in README.md

* Add `lineage` attribute to `Epithelium`

In order to keep track of cell lineage

* Remove memory oscillation

* dependency (#277)

* bug fixes

---------

Co-authored-by: Guillaume Gay <guillaume@damcb.com>
glyg added a commit that referenced this issue Jan 10, 2024
* dependency

* Update history.py

> Added the self.time_stamps() method code for HistoryHdf5 class into the __init__() method so that time_stamps are only calculated once as self._time_stamps
> Edited self.time_stamps() method to return self._time_stamps
> Greatly improves efficiency of retrieve() method as time_stamps is not computed each time a new time-point is loaded.

* Solving mesh collision (#263)

* Fix for Issues #261 - cell division failed at the border

* Fix Mesh creation

Surface mesh create wasn't create all faces. Now it is fixed. 
Also : -add two methods to Mesh to list faces and vertices. 
           -generalised coordinates
           -add `write_polygon_mesh` to export mesh into .ply to visualised with blinder

* Add 2D collision solver

Add class to solve collision in 2D or in 3D. 
3D collision solver need to be fixed

* Update README.md

Add `How to cite` section
Add `Geometry` section
Add `Publications` section
Update bibliography link

* Generalised wich vertex penetrate face

* Attempt to set out particular cases

* Detect and fix self-crossing face

Unable to make this algo works... https://europepmc.org/article/PMC/3660981
Use ordered vertices and their angle position.
     -> uncrossed face : angles are monotonically increasing
     -> crossed face : angles are not monotonically increasing

* Use `.apply()` 

Need to recalculate angle_e for twisted face
One fix which is only suitable for 2D lateral sheet...

* ENH: write `mean_XX` method in `Epithelium` class (Issue #224)

* Fix according to comments

* Fix Issue #258 ax argument not considered in `plt_draw.sheet_view`

* ENH: pass column name to `data_at_opposite` issue (#245)

* Add publication and remove bibtex reference

* Add check face convexity

* Use reset_index and code simplification

* yAdd to_mesh function (issue #221) and some test

* Remove the use of reset_index in face_self_intersect

* use ipv_draw with 2D data

* Fix solution after detection point inside polygon

* Remove solving collision for 2 same face...

* Abord vertex displacement if it creates twisted face

* New way to calculate the position of "penetrate" vertices

For now, it is the best way to fix collision (compare to what I tried before). So when a vertex is inside an other face. It is pullback by 10% of the length of the ([v-f1]+[v-f2]/2). with v, f1, f2 position of vertices and center of face 1 and face 2, which are the faces to which the vertex belongs.  It is not perfect and very arbitrary for now, but it avoids vertex displacement at strange place.

* WIP - use force field to fix collision

* Small fix

* Remove function duplication due to circular import

* Calculate "repulsion" gradient in the effector method. Remove loop

* Fix tests

Remove collisions tests
Fix method call in meshes test
Comment "update_repulstion" method in planar geometry

* Add lateralsheet shapes + test

* Update publication + add collapse texte

* Add test for Repulsion effector

* Add test update repulsion

* Remove unused import

* Add `drop_face` to allow hole (issues #220 and #141) (associate #221)

* Update readme.md

* Update publications in README.md

* Add `lineage` attribute to `Epithelium`

In order to keep track of cell lineage

* Remove memory oscillation

* dependency (#277)

* bug fixes

---------

Co-authored-by: Guillaume Gay <guillaume@damcb.com>

* tests pass

* fixes unknown namz

---------

Co-authored-by: sniffo <tasnif.rahman@gmail.com>
Co-authored-by: Sophie THEIS <sophiets13@gmail.com>
glyg added a commit that referenced this issue Feb 13, 2024
* Fix for Issues #261 - cell division failed at the border

* Fix Mesh creation

Surface mesh create wasn't create all faces. Now it is fixed. 
Also : -add two methods to Mesh to list faces and vertices. 
           -generalised coordinates
           -add `write_polygon_mesh` to export mesh into .ply to visualised with blinder

* Add 2D collision solver

Add class to solve collision in 2D or in 3D. 
3D collision solver need to be fixed

* Update README.md

Add `How to cite` section
Add `Geometry` section
Add `Publications` section
Update bibliography link

* Generalised wich vertex penetrate face

* Attempt to set out particular cases

* Detect and fix self-crossing face

Unable to make this algo works... https://europepmc.org/article/PMC/3660981
Use ordered vertices and their angle position.
     -> uncrossed face : angles are monotonically increasing
     -> crossed face : angles are not monotonically increasing

* Use `.apply()` 

Need to recalculate angle_e for twisted face
One fix which is only suitable for 2D lateral sheet...

* ENH: write `mean_XX` method in `Epithelium` class (Issue #224)

* Fix according to comments

* Fix Issue #258 ax argument not considered in `plt_draw.sheet_view`

* ENH: pass column name to `data_at_opposite` issue (#245)

* Add publication and remove bibtex reference

* Add check face convexity

* Use reset_index and code simplification

* yAdd to_mesh function (issue #221) and some test

* Remove the use of reset_index in face_self_intersect

* use ipv_draw with 2D data

* Fix solution after detection point inside polygon

* Remove solving collision for 2 same face...

* Abord vertex displacement if it creates twisted face

* New way to calculate the position of "penetrate" vertices

For now, it is the best way to fix collision (compare to what I tried before). So when a vertex is inside an other face. It is pullback by 10% of the length of the ([v-f1]+[v-f2]/2). with v, f1, f2 position of vertices and center of face 1 and face 2, which are the faces to which the vertex belongs.  It is not perfect and very arbitrary for now, but it avoids vertex displacement at strange place.

* WIP - use force field to fix collision

* Small fix

* Remove function duplication due to circular import

* Calculate "repulsion" gradient in the effector method. Remove loop

* Fix tests

Remove collisions tests
Fix method call in meshes test
Comment "update_repulstion" method in planar geometry

* Add lateralsheet shapes + test

* Update publication + add collapse texte

* Add test for Repulsion effector

* Add test update repulsion

* Remove unused import

* Add `drop_face` to allow hole (issues #220 and #141) (associate #221)

* Update readme.md

* Update publications in README.md

* Add `lineage` attribute to `Epithelium`

In order to keep track of cell lineage

* Remove memory oscillation

* builds with pip

adds pyproject.toml
build command:
pip install --no-build-isolation --config-settings=editable.rebuild=true -ve.

* debugging, still no build apparently

* build and tests

* update nb submodule

* fix pyproject

* install with pip in CI

* install with pip in CI

* install with pip in CI

* adds scikit-build dep

* python version

* python version specifier

* remove strang flags

* adds _version.py

* setuptools_scm dep

* simplified I guess

* zdds setuptools-scm to env, MakeFilelist shenanigans

* restricting to 3.10

* install dev

* pyhon version coherence

* install cmd

* trying to move to modern sckit-build (it's painful)

* WIP change build

* getting closer I hope

* make_spherical test pasess \o/

* tests passing, warnings still to be treated

* don't install editable version in gh action

* remove diff chars

* tagging again to avoid metadata mismatch

* Uncomment 2D repulsion + tests

Fix pandas issue

* Add comments in effectors.py

* rmeove _version.py and ignore in git

* Update history.py (#274)

> Added the self.time_stamps() method code for HistoryHdf5 class into the __init__() method so that time_stamps are only calculated once as self._time_stamps
> Edited self.time_stamps() method to return self._time_stamps
> Greatly improves efficiency of retrieve() method as time_stamps is not computed each time a new time-point is loaded.

* skip 2 tests

* fix non existing hdf5

* submodules

* adds notebooks submodule

* should fix history bug

* adds submodules again

---------

Co-authored-by: Sophie T <sophiets13@gmail.com>
Co-authored-by: sniffo <tasnif.rahman@gmail.com>
glyg added a commit that referenced this issue Feb 13, 2024
* Fix for Issues #261 - cell division failed at the border

* Fix Mesh creation

Surface mesh create wasn't create all faces. Now it is fixed. 
Also : -add two methods to Mesh to list faces and vertices. 
           -generalised coordinates
           -add `write_polygon_mesh` to export mesh into .ply to visualised with blinder

* Add 2D collision solver

Add class to solve collision in 2D or in 3D. 
3D collision solver need to be fixed

* Update README.md

Add `How to cite` section
Add `Geometry` section
Add `Publications` section
Update bibliography link

* Generalised wich vertex penetrate face

* Attempt to set out particular cases

* Detect and fix self-crossing face

Unable to make this algo works... https://europepmc.org/article/PMC/3660981
Use ordered vertices and their angle position.
     -> uncrossed face : angles are monotonically increasing
     -> crossed face : angles are not monotonically increasing

* Use `.apply()` 

Need to recalculate angle_e for twisted face
One fix which is only suitable for 2D lateral sheet...

* ENH: write `mean_XX` method in `Epithelium` class (Issue #224)

* Fix according to comments

* Fix Issue #258 ax argument not considered in `plt_draw.sheet_view`

* ENH: pass column name to `data_at_opposite` issue (#245)

* Add publication and remove bibtex reference

* Add check face convexity

* Use reset_index and code simplification

* yAdd to_mesh function (issue #221) and some test

* Remove the use of reset_index in face_self_intersect

* use ipv_draw with 2D data

* Fix solution after detection point inside polygon

* Remove solving collision for 2 same face...

* Abord vertex displacement if it creates twisted face

* New way to calculate the position of "penetrate" vertices

For now, it is the best way to fix collision (compare to what I tried before). So when a vertex is inside an other face. It is pullback by 10% of the length of the ([v-f1]+[v-f2]/2). with v, f1, f2 position of vertices and center of face 1 and face 2, which are the faces to which the vertex belongs.  It is not perfect and very arbitrary for now, but it avoids vertex displacement at strange place.

* WIP - use force field to fix collision

* Small fix

* Remove function duplication due to circular import

* Calculate "repulsion" gradient in the effector method. Remove loop

* Fix tests

Remove collisions tests
Fix method call in meshes test
Comment "update_repulstion" method in planar geometry

* Add lateralsheet shapes + test

* Update publication + add collapse texte

* Add test for Repulsion effector

* Add test update repulsion

* Remove unused import

* Add `drop_face` to allow hole (issues #220 and #141) (associate #221)

* Update readme.md

* Update publications in README.md

* Add `lineage` attribute to `Epithelium`

In order to keep track of cell lineage

* Remove memory oscillation

* builds with pip

adds pyproject.toml
build command:
pip install --no-build-isolation --config-settings=editable.rebuild=true -ve.

* debugging, still no build apparently

* build and tests

* update nb submodule

* fix pyproject

* install with pip in CI

* install with pip in CI

* install with pip in CI

* adds scikit-build dep

* python version

* python version specifier

* remove strang flags

* adds _version.py

* setuptools_scm dep

* simplified I guess

* zdds setuptools-scm to env, MakeFilelist shenanigans

* restricting to 3.10

* install dev

* pyhon version coherence

* install cmd

* trying to move to modern sckit-build (it's painful)

* WIP change build

* getting closer I hope

* make_spherical test pasess \o/

* tests passing, warnings still to be treated

* don't install editable version in gh action

* remove diff chars

* tagging again to avoid metadata mismatch

* Uncomment 2D repulsion + tests

Fix pandas issue

* Add comments in effectors.py

* rmeove _version.py and ignore in git

* Update history.py (#274)

> Added the self.time_stamps() method code for HistoryHdf5 class into the __init__() method so that time_stamps are only calculated once as self._time_stamps
> Edited self.time_stamps() method to return self._time_stamps
> Greatly improves efficiency of retrieve() method as time_stamps is not computed each time a new time-point is loaded.

* skip 2 tests

* fix non existing hdf5

* submodules

* adds notebooks submodule

* should fix history bug

* adds submodules again

* minoor fix, notebooks

* updates readme and rtd

---------

Co-authored-by: Sophie T <sophiets13@gmail.com>
Co-authored-by: sniffo <tasnif.rahman@gmail.com>
glyg added a commit that referenced this issue Feb 13, 2024
* Fix for Issues #261 - cell division failed at the border

* Fix Mesh creation

Surface mesh create wasn't create all faces. Now it is fixed. 
Also : -add two methods to Mesh to list faces and vertices. 
           -generalised coordinates
           -add `write_polygon_mesh` to export mesh into .ply to visualised with blinder

* Add 2D collision solver

Add class to solve collision in 2D or in 3D. 
3D collision solver need to be fixed

* Update README.md

Add `How to cite` section
Add `Geometry` section
Add `Publications` section
Update bibliography link

* Generalised wich vertex penetrate face

* Attempt to set out particular cases

* Detect and fix self-crossing face

Unable to make this algo works... https://europepmc.org/article/PMC/3660981
Use ordered vertices and their angle position.
     -> uncrossed face : angles are monotonically increasing
     -> crossed face : angles are not monotonically increasing

* Use `.apply()` 

Need to recalculate angle_e for twisted face
One fix which is only suitable for 2D lateral sheet...

* ENH: write `mean_XX` method in `Epithelium` class (Issue #224)

* Fix according to comments

* Fix Issue #258 ax argument not considered in `plt_draw.sheet_view`

* ENH: pass column name to `data_at_opposite` issue (#245)

* Add publication and remove bibtex reference

* Add check face convexity

* Use reset_index and code simplification

* yAdd to_mesh function (issue #221) and some test

* Remove the use of reset_index in face_self_intersect

* use ipv_draw with 2D data

* Fix solution after detection point inside polygon

* Remove solving collision for 2 same face...

* Abord vertex displacement if it creates twisted face

* New way to calculate the position of "penetrate" vertices

For now, it is the best way to fix collision (compare to what I tried before). So when a vertex is inside an other face. It is pullback by 10% of the length of the ([v-f1]+[v-f2]/2). with v, f1, f2 position of vertices and center of face 1 and face 2, which are the faces to which the vertex belongs.  It is not perfect and very arbitrary for now, but it avoids vertex displacement at strange place.

* WIP - use force field to fix collision

* Small fix

* Remove function duplication due to circular import

* Calculate "repulsion" gradient in the effector method. Remove loop

* Fix tests

Remove collisions tests
Fix method call in meshes test
Comment "update_repulstion" method in planar geometry

* Add lateralsheet shapes + test

* Update publication + add collapse texte

* Add test for Repulsion effector

* Add test update repulsion

* Remove unused import

* Add `drop_face` to allow hole (issues #220 and #141) (associate #221)

* Update readme.md

* Update publications in README.md

* Add `lineage` attribute to `Epithelium`

In order to keep track of cell lineage

* Remove memory oscillation

* builds with pip

adds pyproject.toml
build command:
pip install --no-build-isolation --config-settings=editable.rebuild=true -ve.

* debugging, still no build apparently

* build and tests

* update nb submodule

* fix pyproject

* install with pip in CI

* install with pip in CI

* install with pip in CI

* adds scikit-build dep

* python version

* python version specifier

* remove strang flags

* adds _version.py

* setuptools_scm dep

* simplified I guess

* zdds setuptools-scm to env, MakeFilelist shenanigans

* restricting to 3.10

* install dev

* pyhon version coherence

* install cmd

* trying to move to modern sckit-build (it's painful)

* WIP change build

* getting closer I hope

* make_spherical test pasess \o/

* tests passing, warnings still to be treated

* don't install editable version in gh action

* remove diff chars

* tagging again to avoid metadata mismatch

* Uncomment 2D repulsion + tests

Fix pandas issue

* Add comments in effectors.py

* rmeove _version.py and ignore in git

* Update history.py (#274)

> Added the self.time_stamps() method code for HistoryHdf5 class into the __init__() method so that time_stamps are only calculated once as self._time_stamps
> Edited self.time_stamps() method to return self._time_stamps
> Greatly improves efficiency of retrieve() method as time_stamps is not computed each time a new time-point is loaded.

* skip 2 tests

* fix non existing hdf5

* submodules

* adds notebooks submodule

* should fix history bug

* adds submodules again

* minoor fix, notebooks

* updates readme and rtd

* fixing pyproject

---------

Co-authored-by: Sophie T <sophiets13@gmail.com>
Co-authored-by: sniffo <tasnif.rahman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants