Skip to content

Commit 7209ff6

Browse files
committed
add optional parameters for score ordering in plotting functions
1 parent f175815 commit 7209ff6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ data/
1313
.pybiomart.sqlite
1414
docs/assets/snp2cell_schematic.pdf
1515
.coverage*
16+
_notebooks

snp2cell/snp2cell_class.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ def plot_group_summary(
12251225
self,
12261226
score_key: str = "score",
12271227
plt_df: Optional[pd.DataFrame] = None,
1228+
order: Optional[List[str]] = None,
12281229
topn: Optional[int] = 20,
12291230
errorbar: Literal["pi", "std", "ci", "se"] = "ci",
12301231
row_pattern: str = ".*DE_(?P<rowname>.+?)__",
@@ -1253,6 +1254,8 @@ def plot_group_summary(
12531254
Only used if `plt_df` is not set.
12541255
plt_df : Optional[pd.DataFrame], optional
12551256
Data frame with scores to plot (as retrieved by `snp2cell.get_scores()`), by default None. If not set, scores in the object will be plotted.
1257+
order : Optional[List[str]], optional
1258+
Order of scores to plot, by default None. If not set, scores will be plotted in descending order by mean across rows.
12561259
topn : Optional[int], optional
12571260
Number of top scores to plot, by default 20. If None, all scores will be plotted.
12581261
errorbar : Literal["pi", "std", "ci", "se"], optional
@@ -1285,7 +1288,8 @@ def plot_group_summary(
12851288
columns=lambda c: self.rename_column(c, row_pattern=row_pattern)
12861289
)
12871290

1288-
order = plt_df.mean(axis=0).sort_values(ascending=False).index.tolist()
1291+
if order is None:
1292+
order = plt_df.mean(axis=0).sort_values(ascending=False).index.tolist()
12891293
if topn:
12901294
order = order[:topn]
12911295

@@ -1316,6 +1320,8 @@ def plot_group_heatmap(
13161320
row_pattern: str = ".*DE_(?P<rowname>.+?)__",
13171321
figsize: Tuple[int, int] = (7, 7),
13181322
dendrogram_ratio: Tuple[float, float] = (0.1, 0.1),
1323+
cluster_rows: bool = True,
1324+
cluster_cols: bool = True,
13191325
**kwargs: Any,
13201326
) -> None:
13211327
"""
@@ -1353,6 +1359,10 @@ def plot_group_heatmap(
13531359
Figure size, by default (7, 7).
13541360
dendrogram_ratio : Tuple[float, float], optional
13551361
Ratio of the dendrogram size to the heatmap size, by default (0.1, 0.1).
1362+
cluster_rows : bool, optional
1363+
Whether to cluster rows, by default True.
1364+
cluster_cols : bool, optional
1365+
Whether to cluster columns, by default True.
13561366
kwargs : Any
13571367
Options passed to `get_scores(**kwargs)`.
13581368
@@ -1416,8 +1426,8 @@ def plot_group_heatmap(
14161426
dendrogram_ratio=dendrogram_ratio,
14171427
row_linkage=row_linkage,
14181428
col_linkage=col_linkage,
1419-
col_cluster=True,
1420-
row_cluster=True,
1429+
col_cluster=cluster_cols,
1430+
row_cluster=cluster_rows,
14211431
z_score=None,
14221432
)
14231433

0 commit comments

Comments
 (0)