77from spatialdata import SpatialData
88
99
10- def celltype_communication (
11- sdata ,
12- kind = "heatmap" ,
13- celltype_key = "cell type" ,
14- vmax = None ,
15- vmin = None ,
16- cmap = "BuPu" ,
17- dendrogram_ratio = 0.1 ,
18- ** kwargs
19- ):
10+ def celltype_communication (sdata , kind = "heatmap" , celltype_key = "cell type" , vmax = None , vmin = None , cmap = "BuPu" , dendrogram_ratio = 0.1 , ** kwargs ):
2011 """Plot cell type-cell type interaction strength as a heatmap or chord diagram."""
2112 interaction_strength = sdata ["source_score" ].uns ["interaction_strength" ]
2213 source_table = sdata ["source_score" ]
@@ -28,10 +19,7 @@ def celltype_communication(
2819
2920 # Assign colors to cell types
3021 try :
31- cols = dict (zip (
32- np .unique (sdata ["table" ].obs [celltype_key ]),
33- sdata ["table" ].uns [celltype_key + "_colors" ], strict = False
34- ))
22+ cols = dict (zip (np .unique (sdata ["table" ].obs [celltype_key ]), sdata ["table" ].uns [celltype_key + "_colors" ], strict = False ))
3523 colors = [cols [c ] for c in source_table .var .index ]
3624 except KeyError :
3725 colpalette = plt .get_cmap ("tab20" )
@@ -48,20 +36,13 @@ def celltype_communication(
4836 col_colors = colors ,
4937 dendrogram_ratio = dendrogram_ratio ,
5038 cbar_pos = (0.02 , 0.8 , 0.02 , 0.15 ), # Adjust colorbar position: (x, y, width, height)
51- ** kwargs
39+ ** kwargs ,
5240 )
5341 g .fig .suptitle ("Interaction Strength" , y = 1.05 )
5442 g .ax_heatmap .grid (False ) # remove grid from heatmap
5543
5644 elif kind == "chord" :
57- chord_diagram (
58- celltype_ints ,
59- source_table .var .index ,
60- directed = True ,
61- fontsize = 6 ,
62- colors = colors ,
63- ** kwargs
64- )
45+ chord_diagram (celltype_ints , source_table .var .index , directed = True , fontsize = 6 , colors = colors , ** kwargs )
6546 plt .title ("Interaction Strength" , fontweight = "bold" )
6647 plt .grid (False )
6748
0 commit comments