From 16f93397ae2bec221aecca1de61c015c1dec5d48 Mon Sep 17 00:00:00 2001 From: Sidney Bell Date: Thu, 21 Mar 2019 19:06:05 -0700 Subject: [PATCH] Support `diffmap` and `phate` layouts. Explicitly handle embeddings with >2 components. (#662) * Add diffmap and phate to supported embeddings * Explicitly pull the first two components of any given layout --- README.md | 2 +- server/app/scanpy_engine/scanpy_engine.py | 7 ++++++- server/cli/launch.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 59559f4a..20473131 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ You should see your web browser open with the following There are several options available, such as: -- `--layout` to specify the layout as `tsne`, `umap`, `draw_graph_fa`, or `draw_graph_fr` +- `--layout` to specify the layout as `tsne`, `umap`, `diffmap`, `phate`, `draw_graph_fa`, or `draw_graph_fr` - `--title` to show a title on the explorer - `--open` to automatically open the web browser after launching (OS X only) diff --git a/server/app/scanpy_engine/scanpy_engine.py b/server/app/scanpy_engine/scanpy_engine.py index 3f54c9b9..88b6bf29 100644 --- a/server/app/scanpy_engine/scanpy_engine.py +++ b/server/app/scanpy_engine/scanpy_engine.py @@ -328,10 +328,15 @@ class ScanpyEngine(CXGDriver): * only returns Matrix in columnar layout """ try: - df_layout = self.data.obsm[f"X_{self.layout_method}"] + full_embedding = self.data.obsm[f"X_{self.layout_method}"] + if full_embedding.shape[1] > 2: + warnings.warn(f"Warning: found {full_embedding.shape[1]} \ + components of embedding. Using the first two for layout display.") + df_layout = full_embedding[:, :2] except ValueError as e: raise PrepareError( f"Layout has not been calculated using {self.layout_method}, " f"please prepare your datafile and relaunch cellxgene") from e + normalized_layout = (df_layout - df_layout.min()) / (df_layout.max() - df_layout.min()) return encode_matrix_fbs(normalized_layout.astype(dtype=np.float32), col_idx=None, row_idx=None) diff --git a/server/cli/launch.py b/server/cli/launch.py index 6d643bc9..06801388 100644 --- a/server/cli/launch.py +++ b/server/cli/launch.py @@ -16,7 +16,7 @@ from server.app.util.utils import custom_format_warning @click.option( "--layout", "-l", - type=click.Choice(["umap", "tsne", "draw_graph_fa", "draw_graph_fr"]), + type=click.Choice(["umap", "tsne", "draw_graph_fa", "draw_graph_fr", "diffmap", "phate"]), default="umap", show_default=True, help="Method for layout."