Skip to content

Commit

Permalink
Merge pull request #46 from loucerac/ass_crossplot
Browse files Browse the repository at this point in the history
Ass crossplot
  • Loading branch information
loucerac authored May 2, 2023
2 parents 8b8c4e4 + fbaf1f2 commit fc223d6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT 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.
4 changes: 2 additions & 2 deletions drexml/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
61 changes: 61 additions & 0 deletions drexml/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_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")
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
]
Expand Down

0 comments on commit fc223d6

Please sign in to comment.