From b2a03694821da959a52e13186016f5a3e786fc85 Mon Sep 17 00:00:00 2001 From: wjm41 Date: Thu, 24 Nov 2022 15:24:59 +0000 Subject: [PATCH 1/5] update version number --- setup_pip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup_pip.py b/setup_pip.py index 780d821..cd03fa7 100644 --- a/setup_pip.py +++ b/setup_pip.py @@ -18,7 +18,7 @@ author="William McCorkindale", author_email="wjm41@cam.ac.uk", url="https://github.com/wjm41/molplotly", - download_url="https://github.com/wjm41/molplotly/archive/refs/tags/v1.1.4.tar.gz", + download_url="https://github.com/wjm41/molplotly/archive/refs/tags/v1.1.5.tar.gz", install_requires=[ "dash>=2.0.0", "werkzeug>=2.0.0", From 6c5e3e2275dcb2c802b3cef8dc9d8a2bb21f09a4 Mon Sep 17 00:00:00 2001 From: wjm41 Date: Sat, 11 Mar 2023 20:40:11 +0000 Subject: [PATCH 2/5] updated "value" to "smiles_value" --- molplotly/main.py | 23 +++++++++++++---------- setup.py | 2 +- setup_pip.py | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/molplotly/main.py b/molplotly/main.py index 0eb63ec..3c490f8 100644 --- a/molplotly/main.py +++ b/molplotly/main.py @@ -215,7 +215,7 @@ def add_molecules( if mol_col is not None and len(mol_col) > 1: menu = dcc.Dropdown( - options=[{"label": x, "value": x} for x in mol_col], + options=[{"label": x, "smiles_value": x} for x in mol_col], value=mol_col[0], multi=True, id="smiles-menu", @@ -223,7 +223,7 @@ def add_molecules( ) elif smiles_col is not None and len(smiles_col) > 1: menu = dcc.Dropdown( - options=[{"label": x, "value": x} for x in smiles_col], + options=[{"label": x, "smiles_value": x} for x in smiles_col], value=smiles_col[0], multi=True, id="smiles-menu", @@ -251,21 +251,24 @@ def add_molecules( Output("graph-tooltip", "bbox"), Output("graph-tooltip", "children"), ], - inputs=[Input("graph-basic-2", "hoverData"), Input("smiles-menu", "value")], + inputs=[ + Input("graph-basic-2", "hoverData"), + Input("smiles-menu", "smiles_value"), + ], ) - def display_hover(hoverData, value): + def display_hover(hoverData, smiles_value): if hoverData is None: return False, no_update, no_update - if value is None: + if smiles_value is None: if mol_col is not None: - value = mol_col + smiles_value = mol_col elif smiles_col is not None: - value = smiles_col - if isinstance(value, str): - chosen_smiles = [value] + smiles_value = smiles_col + if isinstance(smiles_value, str): + chosen_smiles = [smiles_value] else: - chosen_smiles = value + chosen_smiles = smiles_value pt = hoverData["points"][0] bbox = pt["bbox"] diff --git a/setup.py b/setup.py index 283979e..24ddc84 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="molplotly", - version="1.1.5", + version="1.1.6", description="plotly add-on to render molecule images on mouseover", long_description=open("README.md").read(), long_description_content_type="text/markdown", diff --git a/setup_pip.py b/setup_pip.py index cd03fa7..82e4f5a 100644 --- a/setup_pip.py +++ b/setup_pip.py @@ -10,7 +10,7 @@ setup( name="molplotly", packages=["molplotly"], - version="1.1.5", + version="1.1.6", license="Apache License, Version 2.0", description="molplotly is an add-on to plotly built on RDKit which allows 2D images of molecules to be shown in scatterplots when hovering over the datapoints.", long_description=long_description, From cfebea0c315c40b34e3e3ee49c66d3d3a8afb704 Mon Sep 17 00:00:00 2001 From: wjm41 Date: Sat, 11 Mar 2023 20:40:55 +0000 Subject: [PATCH 3/5] updated str value for title_col --- molplotly/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molplotly/main.py b/molplotly/main.py index 3c490f8..19f74d1 100644 --- a/molplotly/main.py +++ b/molplotly/main.py @@ -333,7 +333,7 @@ def display_hover(hoverData, smiles_value): ) if title_col is not None: - title = df_row[title_col].astype(str) + title = str(df_row[title_col]) if title_col in caption_transform: title = caption_transform[title_col](title) From 728e4ab695626300fbba65d6d821d2101f75082d Mon Sep 17 00:00:00 2001 From: wjm41 Date: Sat, 11 Mar 2023 21:18:08 +0000 Subject: [PATCH 4/5] fix for numeric color/facet cols --- molplotly/main.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/molplotly/main.py b/molplotly/main.py index 19f74d1..e552e9a 100644 --- a/molplotly/main.py +++ b/molplotly/main.py @@ -8,6 +8,7 @@ import re import pandas as pd +import numpy as np from dash import Input, Output, dcc, html, no_update from jupyter_dash import JupyterDash from pandas.core.groupby import DataFrameGroupBy @@ -54,14 +55,14 @@ def find_grouping( ) -> tuple[DataFrameGroupBy, dict]: if fig.data[0].hovertemplate is not None: - col_names = re.findall(r"(.*?)=(?!%).*?<.*?>", fig.data[0].hovertemplate) + col_names = re.findall(r"(.*?)=.*?<.*?>", fig.data[0].hovertemplate) col_names = [re.sub(r"(.*)>", "", col_name) for col_name in col_names] - if set(col_names) != set(cols): + if set(cols).issubset(set(col_names)) is False: raise ValueError( f"marker_col/color_col/facet_col is misspecified because the specified dataframe grouping names {cols} don't match the names in the plotly figure {col_names}.", ) - df_grouped = df_data.groupby(col_names) + df_grouped = df_data.groupby(cols) str_groups = {} for name, group in df_grouped: @@ -72,8 +73,20 @@ def find_grouping( curve_dict = {} for index, data in enumerate(fig.data): - curve_name = re.findall(r".*?=(?!%)(.*?)<.*?>", data.hovertemplate) + curve_name = re.findall(r".*?=(.*?)<.*?>", data.hovertemplate) curve_name = ", ".join(str(x) for x in curve_name) + if "%{x}" in curve_name: + unique_x_values = np.unique(data.x) + if len(unique_x_values) == 1: + curve_name = curve_name.replace("%{x}", str(unique_x_values[0])) + else: + curve_name = curve_name.replace(", %{x}", "") + if "%{y}" in curve_name: + unique_y_values = np.unique(data.y) + if len(unique_y_values) == 1: + curve_name = curve_name.replace("%{y}", str(unique_y_values[0])) + else: + curve_name = curve_name.replace(", %{y}", "") curve_dict[index] = str_groups[curve_name] return df_grouped, curve_dict From 990222c37262496190e66d797eddb1c166ccd45e Mon Sep 17 00:00:00 2001 From: wjm41 Date: Tue, 14 Mar 2023 21:02:09 +0000 Subject: [PATCH 5/5] added rdkit-pypi dependency --- README.md | 1 - setup.py | 3 +++ setup_pip.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e9b4930..46bcd47 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ A readable walkthrough of how to use the package together with some useful examp ```sh pip install molplotly -conda install rdkit ``` ## Usage diff --git a/setup.py b/setup.py index 24ddc84..97b6696 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ "werkzeug>=2.0.0", "jupyter-dash>=0.4.2", "plotly>=5.0.0", + "rdkit-pypi>=2021.9.4", "pandas", "ipykernel", "nbformat", @@ -29,3 +30,5 @@ "Programming Language :: Python :: 3", ], ) + +# TODO - change link in blog \ No newline at end of file diff --git a/setup_pip.py b/setup_pip.py index 82e4f5a..b30163a 100644 --- a/setup_pip.py +++ b/setup_pip.py @@ -18,12 +18,13 @@ author="William McCorkindale", author_email="wjm41@cam.ac.uk", url="https://github.com/wjm41/molplotly", - download_url="https://github.com/wjm41/molplotly/archive/refs/tags/v1.1.5.tar.gz", + download_url="https://github.com/wjm41/molplotly/archive/refs/tags/v1.1.6.tar.gz", install_requires=[ "dash>=2.0.0", "werkzeug>=2.0.0", "jupyter-dash>=0.4.2", "plotly>=5.0.0", + "rdkit-pypi>=2021.9.4", "pandas", "ipykernel", "nbformat",