basilboy commited on
Commit
8a7095f
·
verified ·
1 Parent(s): 232e962

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -21,13 +21,9 @@ def main():
21
  # Input section in the sidebar
22
  sequence = st.sidebar.text_input("Enter your amino acid sequence:")
23
  uploaded_file = st.sidebar.file_uploader("Or upload a CSV file with amino acid sequences", type="csv")
24
-
25
- # Button to analyze sequence
26
  analyze_pressed = st.sidebar.button("Analyze Sequence")
27
-
28
- # Show graphs toggle
29
  show_graphs = st.sidebar.checkbox("Show Prediction Graphs")
30
-
31
  sequences = [sequence] if sequence else []
32
  if uploaded_file:
33
  df = pd.read_csv(uploaded_file)
@@ -54,24 +50,26 @@ def main():
54
  results_df = pd.DataFrame(results)
55
  st.write("### Results")
56
  st.dataframe(results_df.style.format(precision=3), width=None, height=None)
57
-
58
- # Display graphs in sidebar if toggle is active
59
- if show_graphs and all_data:
60
- plot_prediction_graphs(all_data)
61
 
62
  def plot_prediction_graphs(data):
63
- # Function to plot graphs for predictions in the sidebar
64
  for model_name in models.keys():
65
  plt.figure(figsize=(10, 4))
66
- predictions = {seq: values[model_name][0] for seq, values in data.items()}
67
- confidences = {seq: values[model_name][1] for seq, values in data.items()}
68
- sequences = list(predictions.keys())
69
- conf_values = list(confidences.values())
 
70
  sns.barplot(x=sequences, y=conf_values, palette="viridis")
71
  plt.title(f'Confidence Scores for {model_name.capitalize()} Model')
72
  plt.xlabel('Sequences')
73
  plt.ylabel('Confidence')
74
- st.sidebar.pyplot(plt) # Display each plot in the sidebar
 
75
 
76
  if __name__ == "__main__":
77
  main()
 
21
  # Input section in the sidebar
22
  sequence = st.sidebar.text_input("Enter your amino acid sequence:")
23
  uploaded_file = st.sidebar.file_uploader("Or upload a CSV file with amino acid sequences", type="csv")
 
 
24
  analyze_pressed = st.sidebar.button("Analyze Sequence")
 
 
25
  show_graphs = st.sidebar.checkbox("Show Prediction Graphs")
26
+
27
  sequences = [sequence] if sequence else []
28
  if uploaded_file:
29
  df = pd.read_csv(uploaded_file)
 
50
  results_df = pd.DataFrame(results)
51
  st.write("### Results")
52
  st.dataframe(results_df.style.format(precision=3), width=None, height=None)
53
+
54
+ if show_graphs and all_data:
55
+ st.write("## Graphs")
56
+ plot_prediction_graphs(all_data)
57
 
58
  def plot_prediction_graphs(data):
59
+ # Function to plot graphs for predictions
60
  for model_name in models.keys():
61
  plt.figure(figsize=(10, 4))
62
+ predictions = {seq: values[model_name][1] for seq, values in data.items()} # Using confidence for ordering
63
+ # Sorting sequences based on confidence, descending
64
+ sorted_sequences = sorted(predictions.items(), key=lambda x: x[1], reverse=True)
65
+ sequences = [x[0] for x in sorted_sequences]
66
+ conf_values = [x[1] for x in sorted_sequences]
67
  sns.barplot(x=sequences, y=conf_values, palette="viridis")
68
  plt.title(f'Confidence Scores for {model_name.capitalize()} Model')
69
  plt.xlabel('Sequences')
70
  plt.ylabel('Confidence')
71
+ plt.xticks(rotation=45) # Rotate x labels for better visibility
72
+ st.pyplot(plt) # Display each plot below the results table
73
 
74
  if __name__ == "__main__":
75
  main()