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
5 changes: 3 additions & 2 deletions protzilla/constants/colors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PROTZILLA_DISCRETE_COLOR_SEQUENCE = [
PROTZILLA_COLOR_SEQUENCE = [
"#4A536A",
"#87A8B9",
"#CE5A5A",
"#8E3325",
"#E2A46D",
]
PROTZILLA_DISCRETE_COLOR_OUTLIER_SEQUENCE = ["#4A536A", "#CE5A5A"]
PROTZILLA_PRIMARY_COLOR = PROTZILLA_COLOR_SEQUENCE[0]
PROTZILLA_SECONDARY_COLOR = PROTZILLA_COLOR_SEQUENCE[2]
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 *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich frage mich, ob es hier vielleicht sinnvoll/"Best Parctice" wäre, die Namen der Konstanten zu importieren? Dann weiß man, was es gibt, ohne dass man die andere File anschauen muss (für Code-Verständlichkeit und so, musste an SWT denken)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genau das gleiche habe ich mich auch gefragt ... Meine Gedanken waren hierzu:

  • Der Name protzilla.constants.colors sollte intuitiv genug sein, dass sich in der File halt konstante Variablen mit Farben befinden.
  • Nicht unbedingt in data_analysis, aber in den anderen Sections werden eigentlich alle drei Variablen (Liste, primary und secondary Farben) verwendet - daher fand ich es an der Stelle sinnvoller, einfach * zu schreiben, statt etwas umständlich alle drei einzeln zu importieren.

Ich schreibe aber mal unten als einzelnen Kommentar, was mir gerade generell als Kompromiss einfällt! :)

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=PROTZILLA_PRIMARY_COLOR)
sarahvgls marked this conversation as resolved.
Show resolved Hide resolved
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=PROTZILLA_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 *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hier würde ich das gleiche wie oben anmerken

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=PROTZILLA_SECONDARY_COLOR),
selector=dict(name=f"Significant {item_type}s"),
)
fig.update_traces(
marker=dict(color=PROTZILLA_DISCRETE_COLOR_SEQUENCE[0]),
marker=dict(color=PROTZILLA_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": PROTZILLA_COLOR_SEQUENCE[0],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warum hast du manchmal [0] und manchmal primary color? Wäre es da sinnvoll das irgendwie auch einheitlich zu machen?

"C": PROTZILLA_COLOR_SEQUENCE[1],
}

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=PROTZILLA_COLOR_SEQUENCE[1]),
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=PROTZILLA_COLOR_SEQUENCE[1]),
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=PROTZILLA_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 ..constants.colors import *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hier auch die gleiche Bemerkung wie oben, bzw könnte man hier halt genau nur die eine Konstante importieren, da nur die verwendet wird und in anderen Files wo mehr verwendet wird, dann alle importieren



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=PROTZILLA_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 = PROTZILLA_COLOR_SEQUENCE
size_y = top_terms * 0.5 * len(gene_sets)
try:
ax = gseapy.barplot(
Expand Down
Loading
Loading