File size: 2,562 Bytes
c8e874d
186e4b6
f132523
7c87bff
232e962
 
c8e874d
49c5855
253caff
7c87bff
253caff
088cb01
7c87bff
 
 
 
 
 
088cb01
7c87bff
232e962
 
 
 
 
 
8a7095f
232e962
 
 
 
80f9224
 
 
88dbd92
232e962
 
 
80f9224
88dbd92
 
232e962
88dbd92
 
7c87bff
 
232e962
80f9224
 
88dbd92
80f9224
7c87bff
88dbd92
7c87bff
232e962
253caff
8a7095f
 
 
44d5af7
232e962
 
49c5855
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import streamlit as st
from utils import validate_sequence, predict, plot_prediction_graphs
from model import models
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

def main():
    st.set_page_config(layout="wide")  # Keep the wide layout for overall flexibility
    st.title("AA Property Inference Demo", anchor=None)

    # Instructional text below title
    st.markdown("""
        <style>
        .reportview-container {
            font-family: 'Courier New', monospace;
        }
        </style>
        <p style='font-size:16px;'><span style='font-size:24px;'>&larr;</span> Don't know where to start? Open tab to input a sequence.</p>
        """, unsafe_allow_html=True)

    # Input section in the sidebar
    sequence = st.sidebar.text_input("Enter your amino acid sequence:")
    uploaded_file = st.sidebar.file_uploader("Or upload a CSV file with amino acid sequences", type="csv")
    analyze_pressed = st.sidebar.button("Analyze Sequence")
    show_graphs = st.sidebar.checkbox("Show Prediction Graphs")

    sequences = [sequence] if sequence else []
    if uploaded_file:
        df = pd.read_csv(uploaded_file)
        sequences.extend(df['sequence'].tolist())
        names = df['name'].tolist()  # Store names from the CSV file
    else:
        names = [f"Seq {i+1}" for i in range(len(sequences))]  # Default names if no file

    results = []
    all_data = {}
    if analyze_pressed:
        for name, seq in zip(names, sequences):
            if validate_sequence(seq):
                model_results = {}
                graph_data = {}
                for model_name, model in models.items():
                    prediction, confidence = predict(model, seq)
                    model_results[f"{model_name}_prediction"] = prediction
                    model_results[f"{model_name}_confidence"] = round(confidence, 3)
                    graph_data[model_name] = (prediction, confidence)
                results.append({"Name": name, "Sequence": seq, **model_results})
                all_data[name] = graph_data  # Use name as key
            else:
                st.sidebar.error(f"Invalid sequence for {name}: {seq}")

        if results:
            results_df = pd.DataFrame(results)
            st.write("### Results")
            st.dataframe(results_df.style.format(precision=3), width=None, height=None)
            
            if show_graphs and all_data:
                st.write("## Graphs")
                plot_prediction_graphs(all_data,models.keys())


if __name__ == "__main__":
    main()