From 36c91f73fdd2859836537cc094fb8e0c6aa3af57 Mon Sep 17 00:00:00 2001 From: Carlos Loucera Date: Sat, 1 Apr 2023 20:34:44 +0200 Subject: [PATCH 1/6] Add cross-mrtric plot and default to it. --- drexml/cli/cli.py | 4 +-- drexml/plotting.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/drexml/cli/cli.py b/drexml/cli/cli.py index 3ad30121..cb9649af 100644 --- a/drexml/cli/cli.py +++ b/drexml/cli/cli.py @@ -18,7 +18,7 @@ import click import joblib -from drexml.plotting import plot_stability +from drexml.plotting import plot_metrics from drexml.utils import ( get_data, get_number_cuda_devices, @@ -271,7 +271,7 @@ def run(ctx, **kwargs): def plot(ctx, stab_path): """Plot the stability results""" - plot_stability(stab_path) + plot_metrics(stab_path) @main.command() diff --git a/drexml/plotting.py b/drexml/plotting.py index e463ffe1..1887a073 100644 --- a/drexml/plotting.py +++ b/drexml/plotting.py @@ -128,6 +128,7 @@ def plot_r2_ax(ax_right, data): def plot_stability(input_path, output_path=None): """Plot the stability results.""" + print(input_path) print(output_path) input_path = pathlib.Path(input_path) @@ -172,3 +173,63 @@ def plot_stability(input_path, output_path=None): output_path.joinpath(f"{input_path.stem}.png"), dpi=300, bbox_inches="tight" ) plt.savefig(output_path.joinpath(f"{input_path.stem}.pdf"), bbox_inches="tight") + + +def plot_metrics(input_path, output_folder=None, width=2.735): + """Plot stability versus R^2 with 95% CI""" + + input_path = pathlib.Path(input_path).absolute() + if output_folder is None: + output_folder = input_path.parent + else: + output_folder = pathlib.Path(output_folder) + + results_df = pd.read_csv(input_path, sep="\t").fillna(0) + results_df["r2_error"] = 1.96 * results_df.r2_std / 2 + results_df = results_df.sort_values(by="stability", ascending=True).reset_index() + + custom_params = { + "axes.spines.right": False, + "axes.spines.top": False, + "axes.spines.left": False, + "axes.spines.bottom": False, + } + sns.set_theme( + style="whitegrid", palette="colorblind", context="paper", rc=custom_params + ) + + fig, ax = plt.subplots(1, 1) + + plt.scatter(results_df.stability, results_df.r2_mean, s=1) + plt.errorbar( + results_df.stability, + results_df.r2_mean, + yerr=results_df.r2_error, + linestyle="None", + linewidth=1, + label=r"$R^2$ mean 95% CI", + ) + plt.errorbar( + results_df.stability, + results_df.r2_mean, + xerr=results_df.stability - results_df.stability_lower_95ci, + linestyle="None", + linewidth=1, + label="Stability 95% CI", + ) + + ax.axvspan(0, 0.4, color="red", alpha=0.1) + ax.axvspan(0.4, 0.75, color="y", alpha=0.1) + ax.axvspan(0.75, 1.0, color="g", alpha=0.1) + ax.set_xticks([0, 0.4, 0.75, 1]) + + plt.xlabel("Stability") + plt.ylabel(r"$R^2$ score") + plt.legend() + + fig.tight_layout() + fig.set_size_inches(width, (width * 3) / 4) + + fname = "stability-vs-r2_by-circuit" + plt.savefig(output_folder.joinpath(f"{fname}.png"), dpi=300, bbox_inches="tight") + plt.savefig(output_folder.joinpath(f"{fname}.pdf"), bbox_inches="tight") From 43864d97e3cb2a69635f8a5ec43a47cab2aa4d81 Mon Sep 17 00:00:00 2001 From: Carlos Loucera Date: Sat, 1 Apr 2023 20:36:03 +0200 Subject: [PATCH 2/6] Bump version. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2476f555..07e41055 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "drexml" -version = "0.9.6" +version = "0.9.7" description = "(DRExM³L) Drug REpurposing using and eXplainable Machine Learning and Mechanistic Models of signal transduction\"" authors = [ "Carlos Loucera ", From b13f75ed84ba302a2de068881d440498892ba74b Mon Sep 17 00:00:00 2001 From: Carlos Loucera Date: Mon, 3 Apr 2023 19:28:02 +0200 Subject: [PATCH 3/6] Add LICENSE.txt --- LICENSE.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..5d11bafa --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +LICENSE.txtMIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file From 49c463dbbb59bca64a71eaf68224a7aab90a5b15 Mon Sep 17 00:00:00 2001 From: Carlos Loucera Date: Mon, 3 Apr 2023 19:39:26 +0200 Subject: [PATCH 4/6] Fix aesthetics. --- makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 94923ce2..0556eb95 100644 --- a/makefile +++ b/makefile @@ -8,7 +8,8 @@ all: install format test install: ifeq ($(use_gpu),1) - conda create -y -p ./.venv --override-channels -c "nvidia/label/cuda-11.8.0" -c conda-forge cuda cuda-nvcc cuda-toolkit gxx=11.2 python=3.10 + conda create -y -p ./.venv --override-channels -c "nvidia/label/cuda-11.8.0" \ + -c conda-forge cuda cuda-nvcc cuda-toolkit gxx=11.2 python=3.10 else conda create -y -p ./.venv --override-channels -c conda-forge python=3.10 endif From 8b4269dc0cb208fbbacbb6f890ab41423d7d3d3a Mon Sep 17 00:00:00 2001 From: Carlos Loucera Date: Mon, 3 Apr 2023 20:03:10 +0200 Subject: [PATCH 5/6] Update plotting test to reflect the use of plot_metrics. --- drexml/plotting.py | 2 +- tests/test_datasets.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drexml/plotting.py b/drexml/plotting.py index 1887a073..fcba6442 100644 --- a/drexml/plotting.py +++ b/drexml/plotting.py @@ -230,6 +230,6 @@ def plot_metrics(input_path, output_folder=None, width=2.735): fig.tight_layout() fig.set_size_inches(width, (width * 3) / 4) - fname = "stability-vs-r2_by-circuit" + fname = "stability_results_symbol" plt.savefig(output_folder.joinpath(f"{fname}.png"), dpi=300, bbox_inches="tight") plt.savefig(output_folder.joinpath(f"{fname}.pdf"), bbox_inches="tight") diff --git a/tests/test_datasets.py b/tests/test_datasets.py index 3ee80651..a8fd2464 100644 --- a/tests/test_datasets.py +++ b/tests/test_datasets.py @@ -15,6 +15,7 @@ from drexml.datasets import get_disease_data, load_df from drexml.utils import check_gputree_availability +PLOTTING_EXTENSIONS = ["pdf", "png"] N_GPU_LST = [-1, 0] if check_gputree_availability() else [0] DATA_NAMES = [ @@ -126,6 +127,7 @@ def test_cli_run(n_gpus): plot_files = [ ml_folder_expected.joinpath(f"{x.stem}_symbol.png") + for ext in PLOTTING_EXTENSIONS for x in exist_files if "stability" in x.stem ] From fbaf1f2fee385d53d53ec6a35004f8c91dc1b193 Mon Sep 17 00:00:00 2001 From: loucerac Date: Fri, 21 Apr 2023 09:58:24 +0200 Subject: [PATCH 6/6] Update LICENSE.txt --- LICENSE.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 5d11bafa..8aa26455 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -LICENSE.txtMIT License +MIT License Copyright (c) [year] [fullname] @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE.