Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Plotly Configurations #544

Merged
merged 10 commits into from
Nov 25, 2024
12 changes: 9 additions & 3 deletions protzilla/constants/colors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
PROTZILLA_DISCRETE_COLOR_SEQUENCE = [
PLOT_COLOR_SEQUENCE = [
"#4A536A",
"#87A8B9",
"#CE5A5A",
"#87A8B9",
"#8E3325",
"#E2A46D",
]
PROTZILLA_DISCRETE_COLOR_OUTLIER_SEQUENCE = ["#4A536A", "#CE5A5A"]
"""List of colors to use in plots."""

PLOT_PRIMARY_COLOR = PLOT_COLOR_SEQUENCE[0]
"""First color in list. Conventionally used for visualizing outliers."""

PLOT_SECONDARY_COLOR = PLOT_COLOR_SEQUENCE[1]
"""Second color in list."""
5 changes: 3 additions & 2 deletions protzilla/constants/paths.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pathlib import Path

PROJECT_PATH = Path(__file__).resolve().parent.parent.parent
RUNS_PATH = Path(PROJECT_PATH, "user_data/runs")
WORKFLOWS_PATH = Path(PROJECT_PATH, "user_data/workflows")
USER_DATA_PATH = Path(PROJECT_PATH, "user_data")
RUNS_PATH = USER_DATA_PATH / "runs"
WORKFLOWS_PATH = USER_DATA_PATH / "workflows"
EXTERNAL_DATA_PATH = Path(PROJECT_PATH, "user_data/external_data")
sarahvgls marked this conversation as resolved.
Show resolved Hide resolved
WORKFLOW_META_PATH = Path(PROJECT_PATH, "protzilla/constants/workflow_meta.json")
UI_PATH = Path(PROJECT_PATH, "ui")
Expand Down
6 changes: 3 additions & 3 deletions protzilla/data_analysis/model_evaluation_plots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib.pyplot as plot
from sklearn.metrics import PrecisionRecallDisplay, RocCurveDisplay

from protzilla.constants.colors import PROTZILLA_DISCRETE_COLOR_SEQUENCE
from protzilla.constants.colors import PLOT_PRIMARY_COLOR
from protzilla.data_analysis.classification_helper import encode_labels
from protzilla.utilities.utilities import fig_to_base64

Expand All @@ -28,7 +28,7 @@ def precision_recall_curve_plot(model, input_test_df, labels_test_df, plot_title
display = PrecisionRecallDisplay.from_estimator(
model, input_test_df, labels_test_df["Encoded Label"]
)
display.plot(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[0])
display.plot(color=PLOT_PRIMARY_COLOR)
plot.title(plot_title)
return [fig_to_base64(display.figure_)]

Expand All @@ -55,6 +55,6 @@ def roc_curve_plot(model, input_test_df, labels_test_df, plot_title=None):
display = RocCurveDisplay.from_estimator(
model, input_test_df, labels_test_df["Encoded Label"]
)
display.plot(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[0])
display.plot(color=PLOT_PRIMARY_COLOR)
plot.title(plot_title)
return [fig_to_base64(display.figure_)]
16 changes: 8 additions & 8 deletions protzilla/data_analysis/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scipy import stats
from sklearn.metrics.pairwise import cosine_similarity, euclidean_distances

from protzilla.constants.colors import PROTZILLA_DISCRETE_COLOR_SEQUENCE
from protzilla.constants.colors import PLOT_COLOR_SEQUENCE, PLOT_PRIMARY_COLOR, PLOT_SECONDARY_COLOR
from protzilla.utilities.clustergram import Clustergram
from protzilla.utilities.transform_dfs import is_long_format, long_to_wide

Expand Down Expand Up @@ -171,11 +171,11 @@ def create_volcano_plot(
)
)
fig.update_traces(
marker=dict(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[2]),
marker=dict(color=PLOT_SECONDARY_COLOR),
selector=dict(name=f"Significant {item_type}s"),
)
fig.update_traces(
marker=dict(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[0]),
marker=dict(color=PLOT_PRIMARY_COLOR),
selector=dict(name=f"Not Significant {item_type}s"),
)

Expand Down Expand Up @@ -326,8 +326,8 @@ def prot_quant_plot(
fig = go.Figure()

color_mapping = {
"A": PROTZILLA_DISCRETE_COLOR_SEQUENCE[0],
"C": PROTZILLA_DISCRETE_COLOR_SEQUENCE[1],
"A": PLOT_PRIMARY_COLOR,
"C": PLOT_COLOR_SEQUENCE[2],
}

lower_upper_x = []
Expand Down Expand Up @@ -381,7 +381,7 @@ def prot_quant_plot(
y=wide_df[group],
mode="lines",
name=group[:15] + "..." if len(group) > 15 else group,
line=dict(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[1]),
line=dict(color=PLOT_COLOR_SEQUENCE[2]),
showlegend=len(similar_groups) <= 7,
)
)
Expand All @@ -392,7 +392,7 @@ def prot_quant_plot(
x=[None],
y=[None],
mode="lines",
line=dict(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[1]),
line=dict(color=PLOT_COLOR_SEQUENCE[2]),
name="Similar Protein Groups",
)
)
Expand All @@ -406,7 +406,7 @@ def prot_quant_plot(
y=wide_df[protein_group],
mode="lines",
name=formatted_protein_name,
line=dict(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[2]),
line=dict(color=PLOT_SECONDARY_COLOR),
)
)

Expand Down
8 changes: 4 additions & 4 deletions protzilla/data_integration/di_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from protzilla.constants.protzilla_logging import logger
from protzilla.utilities.utilities import fig_to_base64

from ..constants.colors import PROTZILLA_DISCRETE_COLOR_SEQUENCE
from protzilla.constants.colors import PLOT_COLOR_SEQUENCE


def GO_enrichment_bar_plot(
Expand All @@ -17,7 +17,7 @@ def GO_enrichment_bar_plot(
value,
gene_sets=[],
title="",
colors=PROTZILLA_DISCRETE_COLOR_SEQUENCE,
colors=PLOT_COLOR_SEQUENCE,
figsize=None,
):
"""
Expand All @@ -39,7 +39,7 @@ def GO_enrichment_bar_plot(
:type value: str
:param title: Title of the plot, defaults to ""
:type title: str, optional
:param colors: Colors to use for the bars, defaults to PROTZILLA_DISCRETE_COLOR_SEQUENCE
:param colors: Colors to use for the bars, defaults to PROTZILLA_COLOR_SEQUENCE
:type colors: list, optional
:param figsize: Size of the plot, defaults to None and is calculated dynamically if not provided.
:type figsize: tuple, optional
Expand Down Expand Up @@ -110,7 +110,7 @@ def GO_enrichment_bar_plot(


if colors == "" or colors is None or len(colors) == 0:
colors = PROTZILLA_DISCRETE_COLOR_SEQUENCE
colors = PLOT_COLOR_SEQUENCE
size_y = top_terms * 0.5 * len(gene_sets)
try:
ax = gseapy.barplot(
Expand Down
Loading
Loading