11
11
import gudhi as gd
12
12
13
13
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 ,
20
21
ax = None ,
21
22
** args ):
22
23
"""
@@ -34,6 +35,7 @@ def persisitence_barcodes(adata: AnnData,
34
35
if not set (barcodes_dim ) <= set ([0 , 1 , 2 , 3 ]):
35
36
raise ValueError (f"barcodes_dim: { barcodes_dim } should be in [0, 1, 2, 3]" )
36
37
38
+
37
39
if include_holes :
38
40
simplex_tree = adata .uns [persistence ]['simplextree_tri_ae' ]
39
41
else :
@@ -45,21 +47,26 @@ def persisitence_barcodes(adata: AnnData,
45
47
limit = max (adata .uns [persistence ]['filter_num' ]+ 10 , ax .get_xlim ()[1 ])
46
48
ax .set_xlim (0 , limit )
47
49
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' )
49
55
if not show_legend :
50
56
ax .get_legend ().remove ()
51
57
52
58
return ax
53
59
54
60
55
61
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 ):
63
70
"""
64
71
Plot the persistence birth death diagram
65
72
@@ -81,7 +88,11 @@ def persisitence_birth_death(adata: AnnData,
81
88
pers = simplex_tree .persistence (min_persistence = min_persistence )
82
89
ax = gd .plot_persistence_diagram (pers , axes = ax , ** args )
83
90
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' )
85
96
if not show_legend :
86
97
ax .get_legend ().remove ()
87
98
return ax
0 commit comments