Skip to content

Commit c1744d5

Browse files
committed
persistence plot
1 parent 8645d8e commit c1744d5

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ We have tested python version `3.9.0`, `3.10.8`, `3.10.14`, `3.11.0`, `3.11.5`,
7575
- scanpy (>=1.9.3)
7676
- adjustText (>=0.8)
7777
- pygraphviz (>=1.11)
78+
- gudhi (>=3.10.1)
7879
- magic-impute (>=3.0.0)
7980
- anndata (>=0.9.2)
8081

phlower/plot/persistence.py

+26-15
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
import gudhi as gd
1212

1313
def persisitence_barcodes(adata: AnnData,
14-
include_holes=True,
15-
persistence='persistence',
16-
barcodes_dim=[0],
17-
min_persistence=0.01,
18-
show_threshold=True,
19-
show_legend=True,
14+
include_holes:bool=True,
15+
persistence:str='persistence',
16+
barcodes_dim:List[int]=[0],
17+
min_persistence:float=0.01,
18+
show_threshold:bool=True,
19+
show_legend:bool=True,
20+
manual_threshold:Optional[List[float]] = None,
2021
ax=None,
2122
**args):
2223
"""
@@ -34,6 +35,7 @@ def persisitence_barcodes(adata: AnnData,
3435
if not set(barcodes_dim) <= set([0, 1, 2, 3]):
3536
raise ValueError(f"barcodes_dim: {barcodes_dim} should be in [0, 1, 2, 3]")
3637

38+
3739
if include_holes:
3840
simplex_tree = adata.uns[persistence]['simplextree_tri_ae']
3941
else:
@@ -45,21 +47,26 @@ def persisitence_barcodes(adata: AnnData,
4547
limit = max(adata.uns[persistence]['filter_num']+10, ax.get_xlim()[1])
4648
ax.set_xlim(0, limit)
4749
if show_threshold:
48-
ax.axvline(x=adata.uns[persistence]['filter_num'], ls='--', color='blue')
50+
if not manual_threshold:
51+
ax.axvline(x=adata.uns[persistence]['filter_num'], ls='--', color='blue')
52+
else:
53+
for th in manual_threshold:
54+
ax.axvline(x=th, ls='--', color='blue')
4955
if not show_legend:
5056
ax.get_legend().remove()
5157

5258
return ax
5359

5460

5561
def persisitence_birth_death(adata: AnnData,
56-
include_holes=True,
57-
persistence='persistence',
58-
min_persistence=0.01,
59-
show_threshold=True,
60-
show_legend=True,
61-
ax=None,
62-
**args):
62+
include_holes:bool=True,
63+
persistence:str='persistence',
64+
min_persistence:float=0.01,
65+
show_threshold:bool=True,
66+
show_legend:bool=True,
67+
manual_threshold:Optional[List[float]] = None,
68+
ax=None,
69+
**args):
6370
"""
6471
Plot the persistence birth death diagram
6572
@@ -81,7 +88,11 @@ def persisitence_birth_death(adata: AnnData,
8188
pers = simplex_tree.persistence(min_persistence=min_persistence)
8289
ax = gd.plot_persistence_diagram(pers, axes=ax, **args)
8390
if show_threshold:
84-
ax.axhline(y=adata.uns[persistence]['filter_num'], ls='--', color='blue')
91+
if not manual_threshold:
92+
ax.axhline(y=adata.uns[persistence]['filter_num'], ls='--', color='blue')
93+
else:
94+
for th in manual_threshold:
95+
ax.axhline(y=th, ls='--', color='blue')
8596
if not show_legend:
8697
ax.get_legend().remove()
8798
return ax

phlower/tools/triangulation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,6 @@ def barcode0_max(barcode0):
10691069

10701070

10711071
def persistence_tree_edges(g, filtration_list, edge_list, filter_num):
1072-
index = np.where(np.array(filtration_list) < filter_num)[0]
1072+
index = np.where(np.array(filtration_list) <= filter_num)[0]
10731073
keep_edges = np.array(edge_list)[index]
10741074
return keep_edges

0 commit comments

Comments
 (0)