Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dycpm
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roman Belousov
dycpm
Commits
8038fa63
Commit
8038fa63
authored
1 year ago
by
Roman Belousov
Browse files
Options
Downloads
Patches
Plain Diff
CellGraph
parent
a34d4692
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dycpm/analysis.py
+28
-4
28 additions, 4 deletions
dycpm/analysis.py
tests/test_dycpm.py
+48
-1
48 additions, 1 deletion
tests/test_dycpm.py
with
76 additions
and
5 deletions
dycpm/analysis.py
+
28
−
4
View file @
8038fa63
...
...
@@ -58,7 +58,31 @@ def neighbor_index(state, same, other):
values
.
append
(
count
/
total
)
return
np
.
mean
(
values
)
def
cluster_number
(
state
,
type_id
):
"""
Calculate number of clusters of a given cell type
"""
for
cell_id
in
cells
.
keys
():
pass
class
CellGraph
(
nx
.
Graph
):
"""
Graph of cell connectivity
"""
def
__init__
(
self
,
state
,
type_id
):
"""
Construct graph of a given cell type from a state
"""
super
().
__init__
()
lattice
=
state
.
lattice
()
visited_epi
=
[]
for
cell_id
,
cell
in
state
.
cells
.
items
():
if
cell
.
type_id
==
type_id
:
self
.
add_node
(
cell_id
)
visited_epi
.
append
(
cell_id
)
visited_cached
=
visited_epi
.
copy
()
for
vid
in
cell
.
voxel_ids
:
ref
=
state
.
voxel_coordinates
(
vid
)
for
i
in
range
(
-
1
,
2
):
for
j
in
range
(
-
1
,
2
):
for
k
in
range
(
-
1
,
2
):
xyz
=
np
.
array
([
i
,
j
,
k
],
dtype
=
int
)
+
ref
if
np
.
any
(
xyz
<
0
)
or
np
.
any
(
xyz
>=
state
.
side
):
continue
cid
=
lattice
[
tuple
(
xyz
)]
if
cid
in
visited_cached
:
continue
visited_cached
.
append
(
cid
)
if
state
.
cell_type
(
cid
)
==
type_id
:
self
.
add_edge
(
cell_id
,
cid
)
This diff is collapsed.
Click to expand it.
tests/test_dycpm.py
+
48
−
1
View file @
8038fa63
...
...
@@ -3,7 +3,7 @@ import dycpm
import
dycpm.analysis
import
pytest
import
json
import
numpy
as
np
import
numpy
as
np
,
networkx
as
nx
def
test_cell
():
"""
Test `dycpm.Cell`
"""
...
...
@@ -213,3 +213,50 @@ def test_analysis_neighborIndex():
assert
dycpm
.
analysis
.
neighbor_index
(
state
,
[
1
],
[
0
,
2
])
==
2
/
3
assert
dycpm
.
analysis
.
neighbor_index
(
state
,
[
2
],
[
1
])
==
1
/
3
assert
dycpm
.
analysis
.
neighbor_index
(
state
,
[
2
],
[
0
,
1
])
==
2
/
3
def
test_analysis_cellGraph
():
"""
Test `dycpm.analysis.cellGraph()`
"""
state
=
dycpm
.
State
(
time
=
0
,
side
=
10
,
action_probabilities
=
3
*
[
0.3
],
death_probability
=
1e-4
,
growth_rate
=
2
*
[
1.6
],
volume_elasticity
=
2
*
[
1
],
surface_tension
=
5
*
[
10
],
division_distribution
=
dycpm
.
DIVISION_VOLUME_DISTRIBUTION
,
cells
=
{
1
:
{
'
type_id
'
:
1
,
'
parent_id
'
:
0
,
'
age
'
:
0
,
'
preferred_volume
'
:
1
,
'
division_volume
'
:
dycpm
.
sample_division_volume
(),
"
voxel_ids
"
:
[
4
*
10
**
2
+
4
*
10
+
4
]
},
2
:
{
'
type_id
'
:
1
,
'
parent_id
'
:
0
,
'
age
'
:
0
,
'
preferred_volume
'
:
1
,
'
division_volume
'
:
dycpm
.
sample_division_volume
(),
"
voxel_ids
"
:
[
4
*
10
**
2
+
4
*
10
+
5
]
},
3
:
{
'
type_id
'
:
2
,
'
parent_id
'
:
0
,
'
age
'
:
0
,
'
preferred_volume
'
:
1
,
'
division_volume
'
:
dycpm
.
sample_division_volume
(),
"
voxel_ids
"
:
[
4
*
10
**
2
+
5
*
10
+
4
]
},
4
:
{
'
type_id
'
:
2
,
'
parent_id
'
:
0
,
'
age
'
:
0
,
'
preferred_volume
'
:
1
,
'
division_volume
'
:
dycpm
.
sample_division_volume
(),
"
voxel_ids
"
:
[
0
*
10
**
2
+
0
*
10
+
0
]
},
5
:
{
'
type_id
'
:
2
,
'
parent_id
'
:
0
,
'
age
'
:
0
,
'
preferred_volume
'
:
1
,
'
division_volume
'
:
dycpm
.
sample_division_volume
(),
"
voxel_ids
"
:
[
1
*
10
**
2
+
0
*
10
+
0
]
}
}
)
epi
=
dycpm
.
analysis
.
CellGraph
(
state
,
dycpm
.
EPI
)
pre
=
dycpm
.
analysis
.
CellGraph
(
state
,
dycpm
.
PRE
)
assert
len
(
epi
.
nodes
)
==
2
assert
len
(
pre
.
nodes
)
==
3
assert
nx
.
number_connected_components
(
epi
)
==
1
assert
nx
.
number_connected_components
(
pre
)
==
2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment