Skip to content

Commit f1eebd7

Browse files
committed
review comments
1 parent 9fe7852 commit f1eebd7

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

alphastats/gui/pages/06_LLM.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
)
1313
from alphastats.gui.utils.llm_helper import (
1414
display_uniprot,
15+
get_df_for_protein_selector,
1516
llm_connection_test,
1617
protein_selector,
1718
set_api_key,
@@ -127,34 +128,14 @@ def llm_config():
127128
# Create dataframes with checkboxes for selection
128129
if st.session_state[StateKeys.SELECTED_GENES_UP] is None:
129130
st.session_state[StateKeys.SELECTED_GENES_UP] = upregulated_genes
130-
upregulated_genes_df = pd.DataFrame(
131-
{
132-
"Gene": [
133-
st.session_state[StateKeys.DATASET]._feature_to_repr_map[protein]
134-
for protein in upregulated_genes
135-
],
136-
"Selected": [
137-
protein in st.session_state[StateKeys.SELECTED_GENES_UP]
138-
for protein in upregulated_genes
139-
],
140-
"Protein": upregulated_genes,
141-
}
131+
upregulated_genes_df = get_df_for_protein_selector(
132+
upregulated_genes, st.session_state[StateKeys.SELECTED_GENES_UP]
142133
)
143134

144135
if st.session_state[StateKeys.SELECTED_GENES_DOWN] is None:
145136
st.session_state[StateKeys.SELECTED_GENES_DOWN] = downregulated_genes
146-
downregulated_genes_df = pd.DataFrame(
147-
{
148-
"Gene": [
149-
st.session_state[StateKeys.DATASET]._feature_to_repr_map[protein]
150-
for protein in downregulated_genes
151-
],
152-
"Selected": [
153-
protein in st.session_state[StateKeys.SELECTED_GENES_DOWN]
154-
for protein in downregulated_genes
155-
],
156-
"Protein": downregulated_genes,
157-
}
137+
downregulated_genes_df = get_df_for_protein_selector(
138+
downregulated_genes, st.session_state[StateKeys.SELECTED_GENES_DOWN]
158139
)
159140

160141

@@ -175,13 +156,13 @@ def llm_config():
175156
)
176157

177158
# Combine the selected genes into a new regulated_genes_dict
178-
selected_regulated_genes = (
159+
selected_genes = (
179160
st.session_state[StateKeys.SELECTED_GENES_UP]
180161
+ st.session_state[StateKeys.SELECTED_GENES_DOWN]
181162
)
182163
regulated_genes_dict = {
183164
gene: "up" if gene in st.session_state[StateKeys.SELECTED_GENES_UP] else "down"
184-
for gene in selected_regulated_genes
165+
for gene in selected_genes
185166
}
186167

187168
# If no genes are selected, stop the script
@@ -190,11 +171,11 @@ def llm_config():
190171
st.stop()
191172

192173
if st.button("Gather UniProt data for selected proteins"):
193-
gather_uniprot_data(selected_regulated_genes)
174+
gather_uniprot_data(selected_genes)
194175

195176
if any(
196177
feature not in st.session_state[StateKeys.ANNOTATION_STORE]
197-
for feature in selected_regulated_genes
178+
for feature in selected_genes
198179
):
199180
st.info(
200181
"No UniProt data stored for some proteins. Please run UniProt data fetching first to ensure correct annotation from Protein IDs instead of gene names."

alphastats/gui/utils/llm_helper.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,29 @@ def protein_selector(df: pd.DataFrame, title: str, state_key: str) -> List[str]:
5252
return edited_df.loc[edited_df["Selected"], "Protein"].tolist()
5353

5454

55+
def get_df_for_protein_selector(
56+
proteins: List[str], selected: List[str]
57+
) -> pd.DataFrame:
58+
"""Create a DataFrame for the protein selector.
59+
60+
Args:
61+
proteins (List[str]): A list of proteins.
62+
63+
Returns:
64+
pd.DataFrame: A DataFrame with 'Gene', 'Selected', 'Protein' columns.
65+
"""
66+
return pd.DataFrame(
67+
{
68+
"Gene": [
69+
st.session_state[StateKeys.DATASET]._feature_to_repr_map[protein]
70+
for protein in proteins
71+
],
72+
"Selected": [protein in selected for protein in proteins],
73+
"Protein": proteins,
74+
}
75+
)
76+
77+
5578
def get_display_proteins_html(
5679
protein_ids: List[str], is_upregulated: True, annotation_store, feature_to_repr_map
5780
) -> str:

0 commit comments

Comments
 (0)