From 87b96b15dc87017d0ff9dc65f877d79f4e598ee4 Mon Sep 17 00:00:00 2001 From: ejohnson643 Date: Fri, 17 Dec 2021 15:39:34 -0600 Subject: [PATCH] Committing updates to plotting utility. --- EMBEDR/embedr.py | 12 ++++++++++++ EMBEDR/plotting_utility.py | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/EMBEDR/embedr.py b/EMBEDR/embedr.py index 78d7630..270022f 100644 --- a/EMBEDR/embedr.py +++ b/EMBEDR/embedr.py @@ -1999,6 +1999,18 @@ def plot(self, cite_EMBEDR=cite_EMBEDR, **plot_kwds) + elif plot_type.lower() in ['keff']: + from EMBEDR.plots.embedr_scatterplots import Scatterplot + + plotObj = Scatterplot(plot_Y, + self._kEff, + fig=fig, + axis=axis, + cbar_ax=cbar_ax, + show_cbar=show_cbar, + cite_EMBEDR=cite_EMBEDR, + **plot_kwds) + elif (metadata is not None) and (plot_type in metadata): if is_categorical: diff --git a/EMBEDR/plotting_utility.py b/EMBEDR/plotting_utility.py index f1301f9..ac5ea9c 100644 --- a/EMBEDR/plotting_utility.py +++ b/EMBEDR/plotting_utility.py @@ -658,3 +658,29 @@ def process_categorical_label(metadata, label, return raw_labels, label_counts, long_labels, lab_2_idx_map, label_cmap + +def get_DBSCAN_clusters(Y, min_samples=10, pwd_perc=1.5): + from sklearn.cluster import DBSCAN + + PWD = pwd(Y, metric='euclidean') + PWD_triu = np.triu(PWD, k=1) + eps = np.percentile(PWD_triu[PWD_triu.nonzero()], pwd_perc) + + DBObj = DBSCAN(eps=eps, min_samples=min_samples) + DBObj.fit(Y) + + db_labels = DBObj.labels_ + + ## Count the labels + raw_counts = Counter(db_labels) + ## Sort in descending order + db_lab_counts = sorted(raw_counts.items(), key=lambda item: -item[1]) + ## Remove -1 label + db_lab_counts = {el[0]: el[1] for el in db_lab_counts if el[0] != -1} + ## Create mapping from old labels to size-sorted labels + db_lab_remap = {old_lab: new_lab for new_lab, old_lab in enumerate(db_lab_counts.keys())} + ## Add -1 to map + if -1 in raw_counts: + db_lab_remap[-1] = -1 + ## Remap labels + return np.asarray([db_lab_remap[old_lab] for old_lab in db_labels])