def test_plot_kwargs(self, ligrec_result: Mapping[str, pd.DataFrame]): # color_on is intentionally ignored pl.ligrec(ligrec_result, grid=False, color_on="square", x_padding=2, y_padding=2)
def test_invalid_means_range_size(self, ligrec_result: Mapping[str, pd.DataFrame]): with pytest.raises( ValueError, match= r"Expected `means_range` to be a sequence of size `2`, found `3`." ): pl.ligrec(ligrec_result, means_range=[0, 1, 2])
def test_all_interactions_empty(self, ligrec_result: Mapping[str, pd.DataFrame]): empty = pd.DataFrame(np.nan, index=ligrec_result["pvalues"].index, columns=ligrec_result["pvalues"].columns) with pytest.raises( ValueError, match= r"After removing rows with only NaN interactions, none remain." ): pl.ligrec({ "means": empty, "pvalues": empty, "metadata": empty }, remove_empty_interactions=True)
def test_plot_swap_axes(self, ligrec_result: Mapping[str, pd.DataFrame]): pl.ligrec(ligrec_result, swap_axes=True)
def test_plot_dendrogram_both(self, ligrec_result: Mapping[str, pd.DataFrame]): np.random.seed(42) pl.ligrec(ligrec_result, dendrogram="both")
def test_plot_dendrogram_clusters(self, ligrec_result: Mapping[str, pd.DataFrame]): # this currently "fails" (i.e. no dendrogram) np.random.seed(42) pl.ligrec(ligrec_result, dendrogram="interacting_clusters")
def test_plot_dendrogram_pairs(self, ligrec_result: Mapping[str, pd.DataFrame]): np.random.seed(42) pl.ligrec(ligrec_result, dendrogram="interacting_molecules")
def test_plot_means_range(self, ligrec_result: Mapping[str, pd.DataFrame]): pl.ligrec(ligrec_result, means_range=(0.5, 1))
def test_invalid_key(self, adata: AnnData): with pytest.raises( KeyError, match=r"Key `foobar_ligrec` not found in `adata.uns`."): pl.ligrec(adata, cluster_key="foobar")
def test_plot_cmap(self, ligrec_result: Mapping[str, pd.DataFrame]): pl.ligrec(ligrec_result, cmap="inferno")
def test_plot_target_clusters(self, ligrec_result: Mapping[str, pd.DataFrame]): tgt_cls = ligrec_result["pvalues"].columns.get_level_values(1)[0] pl.ligrec(ligrec_result, target_groups=tgt_cls)
def test_plot_source_clusters(self, ligrec_result: Mapping[str, pd.DataFrame]): src_cls = ligrec_result["pvalues"].columns.get_level_values(0)[0] pl.ligrec(ligrec_result, source_groups=src_cls)
def test_invalid_clusters(self, ligrec_result: Mapping[str, pd.DataFrame]): with pytest.raises(ValueError, match=r"No valid clusters have been selected."): pl.ligrec(ligrec_result, source_groups="foo", target_groups="bar")
def test_invalid_alpha(self, ligrec_result: Mapping[str, pd.DataFrame]): with pytest.raises(ValueError, match=r"Expected `alpha`"): pl.ligrec(ligrec_result, alpha=1.2)
def test_valid_key_invalid_object(self, adata: AnnData): adata.uns["foobar_ligrec"] = "baz" with pytest.raises(TypeError, match=r"Expected `adata` .+ found `str`."): pl.ligrec(adata, cluster_key="foobar")
def test_plot_swap_axes_dedrogram(self, ligrec_result: Mapping[str, pd.DataFrame]): pl.ligrec(ligrec_result, swap_axes=True, dendrogram="interacting_molecules")
def test_plot_alpha(self, ligrec_result: Mapping[str, pd.DataFrame]): pl.ligrec(ligrec_result, alpha=1)
def test_plot_no_remove_empty_interactions( self, ligrec_result: Mapping[str, pd.DataFrame]): tmp = deepcopy(ligrec_result) tmp["pvalues"].values[:2, :] = np.nan pl.ligrec(tmp, remove_empty_interactions=False)
def test_plot_pvalue_threshold(self, ligrec_result: Mapping[str, pd.DataFrame]): pl.ligrec(ligrec_result, pvalue_threshold=0.05)
def test_invalid_type(self): with pytest.raises(TypeError, match=r"Expected `adata` .+ found `int`."): pl.ligrec(42)