Skip to content

Commit

Permalink
add a new option to toggle whether to keep the id_cp_interaction valu…
Browse files Browse the repository at this point in the history
…e when plotting
  • Loading branch information
zktuong committed Dec 6, 2023
1 parent d2c134d commit 6cb91a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ktplotspy/plot/plot_cpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def plot_cpdb(
scale_alpha_by_interaction_scores: bool = False,
scale_alpha_by_cellsign: bool = False,
filter_by_cellsign: bool = False,
keep_id_cp_interaction: bool = False,
) -> Union[ggplot, pd.DataFrame]:
"""Plotting CellPhoneDB results as a dot plot.
Expand Down Expand Up @@ -157,6 +158,8 @@ def plot_cpdb(
Whether or not to filter the transparency of interactions by the cellsign.
filter_by_cellsign: bool, optional
Filter out interactions with a 0 value cellsign.
keep_id_cp_interaction: bool, optional
Whether to keep the original `id_cp_interaction` value when plotting.
Returns
-------
Union[ggplot, pd.DataFrame]
Expand Down Expand Up @@ -384,6 +387,11 @@ def plot_cpdb(
if return_table:
return df
else:
# change the labelling of interaction_group
if keep_id_cp_interaction:
df.interaction_group = [re.sub(DEFAULT_SEP * 3, "_", c) for c in df.interaction_group]
else:
df.interaction_group = [c.split(DEFAULT_SEP * 3)[1] for c in df.interaction_group]
# set global figure size
options.figure_size = figsize

Expand Down
16 changes: 16 additions & 0 deletions tests/test_plot_cpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ def test_plot_cpdb(mock_show, adata, means, pvals):
g


@patch("matplotlib.pyplot.show")
@pytest.mark.usefixtures("adata", "means", "pvals")
def test_plot_cpdb_keep_id(mock_show, adata, means, pvals):
g = plot_cpdb(
adata=adata,
cell_type1="B cell",
cell_type2="CD4T cell",
means=means,
pvals=pvals,
celltype_key="celltype",
genes=["CXCL13", "CD274", "CXCR5"],
keep_id_cp_interaction=True,
)
g


@patch("matplotlib.pyplot.show")
@pytest.mark.usefixtures("adata", "means", "pvals")
def test_plot_cpdb_title(mock_show, adata, means, pvals):
Expand Down

0 comments on commit 6cb91a5

Please sign in to comment.