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

fix merge conflicts #331

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions alphastats/gui/pages/02_Import Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
sidebar_info,
empty_session_state,
init_session_state,
StateKeys,
)


Expand All @@ -27,11 +28,11 @@ def _finalize_data_loading(
dataset: DataSet,
) -> None:
"""Finalize the data loading process."""
st.session_state["loader"] = (
st.session_state[StateKeys.LOADER] = (
loader # TODO: Figure out if we even need the loader here, as the dataset has the loader as an attribute.
)
st.session_state["metadata_columns"] = metadata_columns
st.session_state["dataset"] = dataset
st.session_state[StateKeys.METADATA_COLUMNS] = metadata_columns
st.session_state[StateKeys.DATASET] = dataset

load_options()
sidebar_info()
Expand Down Expand Up @@ -64,7 +65,7 @@ def _finalize_data_loading(


st.markdown("### Import Proteomics Data")
if "dataset" in st.session_state:
if StateKeys.DATASET in st.session_state:
st.info(f"DataSet already present.")
st.page_link("pages/03_Data Overview.py", label="=> Go to data overview page..")
st.stop()
Expand Down
6 changes: 3 additions & 3 deletions alphastats/gui/pages/03_Data Overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
get_intensity_distribution_unprocessed,
display_loaded_dataset,
)
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state, StateKeys

init_session_state()
sidebar_info()

if "dataset" not in st.session_state:
if StateKeys.DATASET not in st.session_state:
st.info("Import Data first")
st.stop()

st.markdown("### DataSet Info")

display_loaded_dataset(st.session_state["dataset"])
display_loaded_dataset(st.session_state[StateKeys.DATASET])

st.markdown("## DataSet overview")

Expand Down
30 changes: 17 additions & 13 deletions alphastats/gui/pages/03_Preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
reset_preprocessing,
PREPROCESSING_STEPS,
)
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state
from alphastats.gui.utils.ui_helper import sidebar_info, init_session_state, StateKeys

init_session_state()
sidebar_info()

if "workflow" not in st.session_state:
st.session_state["workflow"] = [
if StateKeys.WORKFLOW not in st.session_state:
st.session_state[StateKeys.WORKFLOW] = [
PREPROCESSING_STEPS.REMOVE_CONTAMINATIONS,
PREPROCESSING_STEPS.SUBSET,
PREPROCESSING_STEPS.LOG2_TRANSFORM,
Expand All @@ -27,29 +27,33 @@
c1, c2 = st.columns([1, 1])

with c2:
if "dataset" in st.session_state:
settings = configure_preprocessing(dataset=st.session_state["dataset"])
if StateKeys.DATASET in st.session_state:
settings = configure_preprocessing(dataset=st.session_state[StateKeys.DATASET])
new_workflow = update_workflow(settings)
if new_workflow != st.session_state.workflow:
st.session_state.workflow = new_workflow
if new_workflow != st.session_state[StateKeys.WORKFLOW]:
st.session_state[StateKeys.WORKFLOW] = new_workflow

with c1:
st.write("#### Flowchart of preprocessing workflow:")

selected_nodes = draw_workflow(st.session_state.workflow)
selected_nodes = draw_workflow(st.session_state[StateKeys.WORKFLOW])

if "dataset" not in st.session_state:
if StateKeys.DATASET not in st.session_state:
st.info("Import data first to configure and run preprocessing")

else:
c11, c12 = st.columns([1, 1])
if c11.button("Run preprocessing", key="_run_preprocessing"):
run_preprocessing(settings, st.session_state["dataset"])
run_preprocessing(settings, st.session_state[StateKeys.DATASET])
# TODO show more info about the preprocessing steps
display_preprocessing_info(st.session_state["dataset"].preprocessing_info)
display_preprocessing_info(
st.session_state[StateKeys.DATASET].preprocessing_info
)

if c12.button("Reset all Preprocessing steps", key="_reset_preprocessing"):
reset_preprocessing(st.session_state["dataset"])
display_preprocessing_info(st.session_state["dataset"].preprocessing_info)
reset_preprocessing(st.session_state[StateKeys.DATASET])
display_preprocessing_info(
st.session_state[StateKeys.DATASET].preprocessing_info
)

# TODO: Add comparison plot of intensity distribution before and after preprocessing
20 changes: 11 additions & 9 deletions alphastats/gui/pages/04_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
sidebar_info,
init_session_state,
convert_df,
StateKeys,
)
from alphastats.gui.utils.analysis_helper import (
get_analysis,
Expand All @@ -24,8 +25,8 @@ def select_analysis():
load_options()
method = st.selectbox(
"Analysis",
options=list(st.session_state.plotting_options.keys())
+ list(st.session_state.statistic_options.keys()),
options=list(st.session_state[StateKeys.PLOTTING_OPTIONS].keys())
+ list(st.session_state[StateKeys.STATISTIC_OPTIONS].keys()),
)
return method

Expand All @@ -50,11 +51,11 @@ def select_analysis():
st.markdown(styl, unsafe_allow_html=True)


if "plot_list" not in st.session_state:
st.session_state["plot_list"] = []
if StateKeys.PLOT_LIST not in st.session_state:
st.session_state[StateKeys.PLOT_LIST] = []


if "dataset" in st.session_state:
if StateKeys.DATASET in st.session_state:
c1, c2 = st.columns((1, 2))

plot_to_display = False
Expand All @@ -64,15 +65,16 @@ def select_analysis():
with c1:
method = select_analysis()

if method in st.session_state.plotting_options.keys():
if method in st.session_state[StateKeys.PLOTTING_OPTIONS].keys():
analysis_result = get_analysis(
method=method, options_dict=st.session_state.plotting_options
method=method, options_dict=st.session_state[StateKeys.PLOTTING_OPTIONS]
)
plot_to_display = True

elif method in st.session_state.statistic_options.keys():
elif method in st.session_state[StateKeys.STATISTIC_OPTIONS].keys():
analysis_result = get_analysis(
method=method, options_dict=st.session_state.statistic_options
method=method,
options_dict=st.session_state[StateKeys.STATISTIC_OPTIONS],
)
df_to_display = True

Expand Down
1 change: 0 additions & 1 deletion alphastats/gui/pages/05_LLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

init_session_state()
sidebar_info()
st.session_state[StateKeys.PLOT_DICT] = {}


@check_if_options_are_loaded
Expand Down
5 changes: 3 additions & 2 deletions alphastats/gui/pages/06_Results.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
sidebar_info,
init_session_state,
convert_df,
StateKeys,
)


Expand Down Expand Up @@ -44,8 +45,8 @@ def download_preprocessing_info(plot, name, count):
st.markdown("### Results")


if "plot_list" in st.session_state:
for count, plot in enumerate(st.session_state.plot_list):
if StateKeys.PLOT_LIST in st.session_state:
for count, plot in enumerate(st.session_state[StateKeys.PLOT_LIST]):
print("plot", type(plot), count)
count = str(count)

Expand Down
21 changes: 13 additions & 8 deletions alphastats/gui/utils/gpt_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import streamlit as st

from alphastats.plots.DimensionalityReduction import DimensionalityReduction

from alphastats.gui.utils.ui_helper import StateKeys

Entrez.email = "lebedev_mikhail@outlook.com" # Always provide your email address when using NCBI services.

Expand Down Expand Up @@ -143,6 +143,10 @@ def get_assistant_functions(
Returns:
list[dict]: A list of assistant functions.
"""
# TODO figure out how this relates to the parameter `subgroups_for_each_group`
subgroups_for_each_group_ = str(
get_subgroups_for_each_group(st.session_state[StateKeys.DATASET].metadata)
)
return [
{
"type": "function",
Expand All @@ -165,7 +169,8 @@ def get_assistant_functions(
"subgroups": {
"type": "array",
"items": {"type": "string"},
"description": f"Specific subgroups within the group to analyze. For each group you need to look up the subgroups in the dict {str(get_subgroups_for_each_group(st.session_state['dataset'].metadata))} or present user with them first if you are not sure what to choose",
"description": f"Specific subgroups within the group to analyze. For each group you need to look up the subgroups in the dict"
f" {subgroups_for_each_group_} or present user with them first if you are not sure what to choose",
},
"method": {
"type": "string",
Expand Down Expand Up @@ -302,7 +307,7 @@ def get_assistant_functions(

def perform_dimensionality_reduction(group, method, circle, **kwargs):
dr = DimensionalityReduction(
st.session_state.dataset, group, method, circle, **kwargs
st.session_state[StateKeys.DATASET], group, method, circle, **kwargs
)
return dr.plot

Expand Down Expand Up @@ -339,11 +344,11 @@ def get_gene_to_prot_id_mapping(gene_id: str) -> str:
import streamlit as st

session_state_copy = dict(copy.deepcopy(st.session_state))
if "gene_to_prot_id" not in session_state_copy:
session_state_copy["gene_to_prot_id"] = {}
if gene_id in session_state_copy["gene_to_prot_id"]:
return session_state_copy["gene_to_prot_id"][gene_id]
for gene, prot_id in session_state_copy["gene_to_prot_id"].items():
if StateKeys.GENE_TO_PROT_ID not in session_state_copy:
session_state_copy[StateKeys.GENE_TO_PROT_ID] = {}
if gene_id in session_state_copy[StateKeys.GENE_TO_PROT_ID]:
return session_state_copy[StateKeys.GENE_TO_PROT_ID][gene_id]
for gene, prot_id in session_state_copy[StateKeys.GENE_TO_PROT_ID].items():
if gene_id in gene.split(";"):
return prot_id
return gene_id
5 changes: 3 additions & 2 deletions alphastats/gui/utils/import_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
from alphastats.DataSet import DataSet
from alphastats.gui.utils.options import SOFTWARE_OPTIONS
from alphastats.loader.MaxQuantLoader import MaxQuantLoader, BaseLoader
from alphastats.gui.utils.ui_helper import StateKeys


def load_options():
# TODO move import to top
from alphastats.gui.utils.options import plotting_options, statistic_options

st.session_state["plotting_options"] = plotting_options(st.session_state)
st.session_state["statistic_options"] = statistic_options(st.session_state)
st.session_state[StateKeys.PLOTTING_OPTIONS] = plotting_options(st.session_state)
st.session_state[StateKeys.STATISTIC_OPTIONS] = statistic_options(st.session_state)


def load_proteomics_data(uploaded_file, intensity_column, index_column, software):
Expand Down
Loading
Loading