import streamlit as st import pandas as pd import prediction as pred_module # Import the prediction module import os def extract_windows(sequence, window_size=55): """ Extract windows of a given size centered around each 'K' residue in the sequence. Parameters: sequence (str): The amino acid sequence. window_size (int): The size of the window to extract (must be an odd number). Returns: list: A list of subsequences of the specified window size centered on 'K'. """ half_window = window_size // 2 windows = [] for i in range(len(sequence)): if sequence[i] == 'K': start = i - half_window end = i + half_window + 1 if start >= 0 and end <= len(sequence): window_sequence = sequence[start:end] windows.append((i, window_sequence)) return windows def main(): st.title("Ubiquitinated Protein Sequence Predictor") st.write(""" This app predicts whether a given protein sequence contains ubiquitination sites. Enter a protein sequence and the app will analyze windows size 'n-1/2' residues centered around each 'K' residue. If any window is predicted positive, the sequence is considered to contain ubiquitination sites. """) sequence_input = st.text_area("Enter protein sequence:") if st.button("Predict"): if len(sequence_input) < 55: st.error("Sequence length must be at least 55 residues.") else: windows = extract_windows(sequence_input) final_prediction = 0 # Initialize final prediction as negative for i, window_sequence in windows: pred_result = pred_module.predict_sequence_label(window_sequence) if pred_result == 1: final_prediction = 1 # If any window is positive, set final prediction to positive break if final_prediction == 1: st.success("The sequence contains ubiquitination sites.") else: st.success("The sequence does not contain ubiquitination sites.") # Collect user feedback st.write("Provide your feedback on the prediction:") feedback = st.radio( "Was the prediction correct?", ("Yes", "No"), key="feedback" ) if st.button("Submit Feedback"): feedback_data = { "sequence": [sequence_input], "predicted_label": [final_prediction], "feedback": [feedback] } feedback_df = pd.DataFrame(feedback_data) # Check if feedback.csv exists if not os.path.isfile("feedback.csv"): feedback_df.to_csv("feedback.csv", index=False) else: try: existing_feedback = pd.read_csv("feedback.csv") feedback_df = pd.concat([existing_feedback, feedback_df], ignore_index=True) feedback_df.to_csv("feedback.csv", index=False) except pd.errors.EmptyDataError: feedback_df.to_csv("feedback.csv", index=False) st.success("Feedback submitted successfully!") # Display feedback table st.write("User Feedback Table (Last 10 Entries):") try: feedback_df = pd.read_csv("feedback.csv") last_10_feedback = feedback_df.tail(10) st.dataframe(last_10_feedback) except FileNotFoundError: st.write("No feedback available yet.") except pd.errors.EmptyDataError: st.write("Feedback file is empty. No feedback available yet.") if __name__ == "__main__": main() # Add a footer st.markdown( """
""", unsafe_allow_html=True )