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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from dataloader import filter_data, load_data,load_singlecell_data
|
| 6 |
+
from Correlation import load_data, filter_data, plot_correlation
|
| 7 |
+
from boxplot import plot_boxplot
|
| 8 |
+
from volcano import plot_volcano
|
| 9 |
+
|
| 10 |
+
# Get current file path
|
| 11 |
+
BASE_PATH = Path(__file__).parent
|
| 12 |
+
|
| 13 |
+
# Construct paths
|
| 14 |
+
METADATA_PATH = str(BASE_PATH.parent / "Core data/somalogic_metadata.csv")
|
| 15 |
+
PROTEINS_PATH = str(BASE_PATH.parent / "Core data/proteins_plot.csv")
|
| 16 |
+
VOLCANO_PATH = str(BASE_PATH.parent / "Core data/SSC_all_Healthy_allproteins.csv")
|
| 17 |
+
SINGLECELLADATA_PATH = str(BASE_PATH.parent / "Core data")
|
| 18 |
+
SSC_HEALTHY_PROTS_PATH = str(BASE_PATH.parent / "Core data/SSC_all_Healthy_allproteins.csv")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# Set page configuration
|
| 22 |
+
st.set_page_config(
|
| 23 |
+
page_title="ScleroBase",
|
| 24 |
+
page_icon="🧬",
|
| 25 |
+
layout="wide",
|
| 26 |
+
initial_sidebar_state="collapsed"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Add custom fonts from Google Fonts
|
| 30 |
+
st.markdown("""
|
| 31 |
+
<link href="https://fonts.googleapis.com/css2?family=MuseoModerno:wght@400&family=Actor&display=swap" rel="stylesheet">
|
| 32 |
+
<style>
|
| 33 |
+
/* Hide the Streamlit default elements */
|
| 34 |
+
#MainMenu {visibility: hidden;}
|
| 35 |
+
footer {visibility: hidden;}
|
| 36 |
+
header {visibility: hidden;}
|
| 37 |
+
.css-1e5imcs, .css-17eq0hr {display: none !important;}
|
| 38 |
+
|
| 39 |
+
.navbar {
|
| 40 |
+
background-color: #2E7D32; /* Green background */
|
| 41 |
+
padding: 10px 20px;
|
| 42 |
+
font-size: 26px;
|
| 43 |
+
display: flex;
|
| 44 |
+
justify-content: space-between;
|
| 45 |
+
align-items: center;
|
| 46 |
+
width: 100vw; /* Full width of the viewport */
|
| 47 |
+
position: fixed;
|
| 48 |
+
top: 0;
|
| 49 |
+
left: 0;
|
| 50 |
+
z-index: 999; /* Ensure navbar stays above other elements */
|
| 51 |
+
}
|
| 52 |
+
.navbar a {
|
| 53 |
+
color: white;
|
| 54 |
+
padding: 30px 30px;
|
| 55 |
+
text-decoration: none;
|
| 56 |
+
font-weight: normal;
|
| 57 |
+
font-size: 18px;
|
| 58 |
+
}
|
| 59 |
+
.navbar a:hover {
|
| 60 |
+
background-color: #1B5E20; /* Darker green background on hover */
|
| 61 |
+
color: white; /* Keep the text white */
|
| 62 |
+
}
|
| 63 |
+
.brand {
|
| 64 |
+
font-family: 'MuseoModerno', cursive; /* Updated to MuseoModerno */
|
| 65 |
+
font-size: 42px; /* Brand name size */
|
| 66 |
+
font-weight: 400;
|
| 67 |
+
color: white;
|
| 68 |
+
padding-left: 60px;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/* Mobile-specific styles */
|
| 72 |
+
@media screen and (max-width: 768px) {
|
| 73 |
+
.navbar {
|
| 74 |
+
flex-direction: column;
|
| 75 |
+
padding: 5px 10px;
|
| 76 |
+
}
|
| 77 |
+
.navbar a {
|
| 78 |
+
font-size: 14px;
|
| 79 |
+
padding: 8px 15px;
|
| 80 |
+
width: 100%; /* Full width on small screens */
|
| 81 |
+
text-align: center;
|
| 82 |
+
}
|
| 83 |
+
.brand {
|
| 84 |
+
font-size: 24px;
|
| 85 |
+
text-align: center;
|
| 86 |
+
margin-bottom: 10px;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
</style>
|
| 90 |
+
""", unsafe_allow_html=True)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
@st.cache_data
|
| 94 |
+
def get_data():
|
| 95 |
+
"""Load and cache metadata and protein data."""
|
| 96 |
+
metadata, proteins = load_data(METADATA_PATH, PROTEINS_PATH)
|
| 97 |
+
volcano = pd.read_csv(VOLCANO_PATH) # Load the volcano dataset separately
|
| 98 |
+
single_cell_data = load_singlecell_data(SINGLECELLADATA_PATH)
|
| 99 |
+
return metadata, proteins, volcano,single_cell_data
|
| 100 |
+
|
| 101 |
+
def home():
|
| 102 |
+
"""Home page with plots and analysis."""
|
| 103 |
+
|
| 104 |
+
if "protein_options" not in st.session_state:
|
| 105 |
+
# Load and cache data
|
| 106 |
+
metadata, proteins, _ = get_data()
|
| 107 |
+
st.session_state["protein_options_map"] = {
|
| 108 |
+
"EntrezGeneID": proteins["EntrezGeneID"].dropna().unique().tolist(),
|
| 109 |
+
"EntrezGeneSymbol": proteins["EntrezGeneSymbol"].dropna().unique().tolist(),
|
| 110 |
+
"TargetFullName": proteins["TargetFullName"].dropna().unique().tolist(),
|
| 111 |
+
"Target": proteins["Target"].dropna().unique().tolist(),
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
def generate_and_display_plots(button_name, id_type, protein_id, button_key):
|
| 115 |
+
|
| 116 |
+
# Button for generating plots
|
| 117 |
+
if st.button(button_name, key=button_key):
|
| 118 |
+
st.session_state["active_button"] = button_key # Track which button was clicked
|
| 119 |
+
if not protein_id:
|
| 120 |
+
st.error("Please enter a valid Protein ID.")
|
| 121 |
+
else:
|
| 122 |
+
try:
|
| 123 |
+
# Load data and cache in session state
|
| 124 |
+
metadata, proteins, volcano = get_data()
|
| 125 |
+
merged_data = filter_data(proteins, metadata, protein_id, id_type)
|
| 126 |
+
protein_name = merged_data["TargetFullName"].iloc[0]
|
| 127 |
+
|
| 128 |
+
# Store data in session state
|
| 129 |
+
st.session_state["plot_data"] = {
|
| 130 |
+
"merged_data": merged_data,
|
| 131 |
+
"protein_name": protein_name,
|
| 132 |
+
"volcano_plot_data": volcano
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
except Exception as e:
|
| 136 |
+
st.error(f"An unexpected error occurred: {str(e)}.")
|
| 137 |
+
st.session_state["active_button"] = None
|
| 138 |
+
|
| 139 |
+
# Only display plots if the current button is active
|
| 140 |
+
if st.session_state.get("active_button") == button_key:
|
| 141 |
+
try:
|
| 142 |
+
data = st.session_state["plot_data"]
|
| 143 |
+
protein_name = data["protein_name"]
|
| 144 |
+
merged_data = data["merged_data"]
|
| 145 |
+
volcano = data["volcano_plot_data"]
|
| 146 |
+
|
| 147 |
+
# Add tabs and display plots
|
| 148 |
+
corr_tab, box_tab, volc_tab = st.tabs(['Correlation Plot', 'Box Plot', 'Volcano Plot'])
|
| 149 |
+
with corr_tab:
|
| 150 |
+
st.subheader(f"Correlation Plot for {protein_name}")
|
| 151 |
+
corr_plot = plot_correlation(merged_data, protein_name)
|
| 152 |
+
st.pyplot(corr_plot)
|
| 153 |
+
|
| 154 |
+
with box_tab:
|
| 155 |
+
st.subheader(f"Box Plot for {protein_name}")
|
| 156 |
+
box_plot = plot_boxplot(merged_data, protein_name)
|
| 157 |
+
st.pyplot(box_plot)
|
| 158 |
+
|
| 159 |
+
with volc_tab:
|
| 160 |
+
st.subheader(f"Volcano Plot")
|
| 161 |
+
st.markdown("Displaying a volcano plot for the provided dataset.")
|
| 162 |
+
volcano_plot = plot_volcano(volcano)
|
| 163 |
+
st.pyplot(volcano_plot)
|
| 164 |
+
|
| 165 |
+
except Exception as e:
|
| 166 |
+
st.error(f"An error occurred while displaying the plots: {str(e)}")
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
#Dropdown box
|
| 171 |
+
col1, col2 = st.columns([2, 2]) # Two equal-width columns (1:1)
|
| 172 |
+
with col1:
|
| 173 |
+
id_type = st.selectbox(
|
| 174 |
+
"Select Protein Reference Type:",
|
| 175 |
+
["EntrezGeneID", "EntrezGeneSymbol", "TargetFullName", "Target"]
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
# Update the options based on the selected reference type
|
| 179 |
+
protein_options = st.session_state["protein_options_map"][id_type]
|
| 180 |
+
|
| 181 |
+
# Create an autocomplete selectbox for protein ID suggestions
|
| 182 |
+
protein_id = st.selectbox(
|
| 183 |
+
"Enter or select Protein ID:",
|
| 184 |
+
options=[""] + protein_options, # Add an empty default option for manual input
|
| 185 |
+
index=0,
|
| 186 |
+
help=f"Select or type a valid {id_type} from the dataset."
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
generate_and_display_plots("Generate Plots", id_type, protein_id, "generate_plots_button")
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
# Initialize session state keys if they don't exist
|
| 194 |
+
if "selected_proteins" not in st.session_state:
|
| 195 |
+
st.session_state["selected_proteins"] = []
|
| 196 |
+
|
| 197 |
+
if "show_comparison" not in st.session_state:
|
| 198 |
+
st.session_state["show_comparison"] = False
|
| 199 |
+
|
| 200 |
+
# Control variable to check if "Generate Plots" has been clicked
|
| 201 |
+
if "generate_plots_clicked" not in st.session_state:
|
| 202 |
+
st.session_state["generate_plots_clicked"] = False
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
with col2:
|
| 206 |
+
selected_protein = st.selectbox(
|
| 207 |
+
"Selected Proteins for Comparison:",
|
| 208 |
+
options=st.session_state.get("selected_proteins", []),
|
| 209 |
+
index=0 if st.session_state.get("selected_proteins") else -1, # Default to first item or empty
|
| 210 |
+
help="Select a protein to view detailed information."
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
# "Compare Proteins" button
|
| 214 |
+
if st.button("Add Protein"):
|
| 215 |
+
if not protein_id:
|
| 216 |
+
st.error("Please enter a valid Protein ID.")
|
| 217 |
+
else:
|
| 218 |
+
# Initialize session state for comparison
|
| 219 |
+
if "show_comparison" not in st.session_state:
|
| 220 |
+
st.session_state["show_comparison"] = True
|
| 221 |
+
if "selected_proteins" not in st.session_state:
|
| 222 |
+
st.session_state["selected_proteins"] = []
|
| 223 |
+
|
| 224 |
+
# Add protein to the comparison list
|
| 225 |
+
if protein_id not in st.session_state["selected_proteins"]:
|
| 226 |
+
st.session_state["selected_proteins"].append(protein_id)
|
| 227 |
+
st.success(f"Added {protein_id} to comparison list!")
|
| 228 |
+
else:
|
| 229 |
+
st.warning(f"{protein_id} is already in the comparison list.")
|
| 230 |
+
|
| 231 |
+
generate_and_display_plots("Generate Comparison", id_type, selected_protein, "compare_proteins_button")
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def research():
|
| 235 |
+
"""Research page with publications."""
|
| 236 |
+
st.title("Research and Publications")
|
| 237 |
+
st.markdown("""
|
| 238 |
+
- **2024**: Stimulation of skeletal stem cells in the growth plate promotes linear bone growth.
|
| 239 |
+
- **2023**: Plasticity of epithelial cells during wound healing.
|
| 240 |
+
- **2022**: ARF suppression in pediatric brain tumors.
|
| 241 |
+
""")
|
| 242 |
+
|
| 243 |
+
def about():
|
| 244 |
+
st.title("About Us")
|
| 245 |
+
st.write("Learn more about the Higgins Lab and our work.")
|
| 246 |
+
|
| 247 |
+
def data():
|
| 248 |
+
st.title("Data")
|
| 249 |
+
st.write("Access our latest datasets and reports.")
|
| 250 |
+
|
| 251 |
+
def contact():
|
| 252 |
+
st.title("Contact Us")
|
| 253 |
+
st.write("Feel free to contact us for more information!")
|
| 254 |
+
|
| 255 |
+
def main():
|
| 256 |
+
"""Main function to run the Streamlit app."""
|
| 257 |
+
# Navbar Section
|
| 258 |
+
st.markdown("""
|
| 259 |
+
<div class="navbar">
|
| 260 |
+
<div class="brand">ScleroBase</div>
|
| 261 |
+
<div>
|
| 262 |
+
<a href="?page=home">Home</a>
|
| 263 |
+
<a href="?page=about">About Us</a>
|
| 264 |
+
<a href="?page=research">Research</a> <!-- Link to Research -->
|
| 265 |
+
<a href="?page=data">Data</a>
|
| 266 |
+
<a href="?page=contact">Contact Us</a>
|
| 267 |
+
</div>
|
| 268 |
+
</div>
|
| 269 |
+
""", unsafe_allow_html=True)
|
| 270 |
+
|
| 271 |
+
query_params = st.query_params
|
| 272 |
+
page = query_params.get("page", "home")
|
| 273 |
+
|
| 274 |
+
if page == "home":
|
| 275 |
+
home()
|
| 276 |
+
elif page == "research":
|
| 277 |
+
research()
|
| 278 |
+
elif page == "about":
|
| 279 |
+
about()
|
| 280 |
+
elif page == "data":
|
| 281 |
+
data()
|
| 282 |
+
elif page == "contact":
|
| 283 |
+
contact()
|
| 284 |
+
|
| 285 |
+
if __name__ == "__main__":
|
| 286 |
+
main()
|