Skip to content

Commit

Permalink
FIX: openai api call
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Lebedev committed Feb 23, 2024
1 parent 1455d01 commit bd80aac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions alphastats/gui/pages/02_Import Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ def load_sample_data():

loader = MaxQuantLoader(file=filepath)
ds = DataSet(loader=loader, metadata_path=metadatapath, sample_column="sample")
metadatapath = os.path.join(_this_directory, "sample_data/metadata.xlsx").replace(
metadatapath = os.path.join(_this_directory, "sample_data", "metadata.xlsx").replace(
"pages/", ""
)
).replace("pages\\", "")

loader = MaxQuantLoader(file=filepath)
ds = DataSet(loader=loader, metadata_path=metadatapath, sample_column="sample")
Expand Down
9 changes: 5 additions & 4 deletions alphastats/gui/pages/05_GPT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import streamlit as st
from openai import OpenAI

Expand Down Expand Up @@ -256,20 +257,20 @@ def select_analysis():
display_proteins([], st.session_state["downregulated"])

st.session_state["instructions"] = (
"You are an expert biologist and have extensive experience in molecular biology, medicine and biochemistry.\n"
f"You are an expert biologist and have extensive experience in molecular biology, medicine and biochemistry.{os.linesep}"
"A user will present you with data regarding proteins upregulated in certain cells "
"sourced from UniProt and abstracts from scientific publications. They seek your "
"expertise in understanding the connections between these proteins and their potential role "
"in disease genesis. \nProvide a detailed and insightful, yet concise response based on the given information. "
f"in disease genesis. {os.linesep}Provide a detailed and insightful, yet concise response based on the given information. "
f"The data you have has following groups and respective subgroups: {str(get_subgroups_for_each_group(st.session_state.dataset.metadata))}."
"Plots are visualized using a graphical environment capable of rendering images, you don't need to worry about that."
)
if "column" in chosen_parameter_dict and "upregulated" in st.session_state:
st.session_state["user_prompt"] = (
f"We've recently identified several proteins that appear to be differently regulated in cells "
f"when comparing {chosen_parameter_dict['group1']} and {chosen_parameter_dict['group2']} in the {chosen_parameter_dict['column']} group. "
f"From our proteomics experiments, we know that the following ones are upregulated: {', '.join(st.session_state['upregulated'])}.\n\n"
f"Here is the list of proteins that are downregulated: {', '.join(st.session_state['downregulated'])}.\n\n"
f"From our proteomics experiments, we know that the following ones are upregulated: {', '.join(st.session_state['upregulated'])}.{os.linesep}{os.linesep}"
f"Here is the list of proteins that are downregulated: {', '.join(st.session_state['downregulated'])}.{os.linesep}{os.linesep}"
f"Help us understand the potential connections between these proteins and how they might be contributing "
f"to the differences. After that provide a high level summary"
)
Expand Down
20 changes: 11 additions & 9 deletions alphastats/gui/utils/gpt_helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
from typing import Optional, Union
from pathlib import Path
import requests
Expand Down Expand Up @@ -315,8 +316,8 @@ def get_assistant_functions(
"description": "False Discovery Rate cutoff for SAM",
},
},
"required": ["column", "group1", "group2"],
},
"required": ["group", "subgroups"],
},
},
{"type": "code_interpreter"},
Expand Down Expand Up @@ -574,10 +575,10 @@ def get_info(genes_list: list[str], organism_id: str) -> list[str]:

def get_gene_function(gene_name: Union[str, dict], organism_id: str = None) -> str:
"""
Get the gene function and description by UniProt lookup of gene identifier/name.
Get the gene function and description by UniProt lookup of gene identifier / name.
Args:
gene_name (Union[str, dict]): Gene identifier/name for UniProt lookup.
gene_name (Union[str, dict]): Gene identifier / name for UniProt lookup.
organism_id (str): The UniProt organism ID to search in.
Returns:
Expand Down Expand Up @@ -615,7 +616,7 @@ def turn_args_to_float(json_string: Union[str, bytes, bytearray]) -> dict:


def get_gene_to_prot_id_mapping(gene_id: str) -> str:
"""Get protein id from gene id. If gene id is not present, return gene id, as we might already have a gene id (LLM moment).
"""Get protein id from gene id. If gene id is not present, return gene id, as we might already have a gene id.
'VCL;HEL114' -> 'P18206;A0A024QZN4;V9HWK2;B3KXA2;Q5JQ13;B4DKC9;B4DTM7;A0A096LPE1'
Args:
gene_id (str): Gene id
Expand All @@ -624,11 +625,12 @@ def get_gene_to_prot_id_mapping(gene_id: str) -> str:
str: Protein id or gene id if not present in the mapping.
"""
import streamlit as st

print(st.session_state["gene_to_prot_id"])
if gene_id in st.session_state["gene_to_prot_id"]:
return st.session_state["gene_to_prot_id"][gene_id]
for gene, prot_id in st.session_state["gene_to_prot_id"].items():
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 gene_id in gene.split(";"):
return prot_id
return gene_id
Expand Down

0 comments on commit bd80aac

Please sign in to comment.