Jayesh13 commited on
Commit
2114be5
Β·
verified Β·
1 Parent(s): 5a2a00f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -7,7 +7,7 @@ from io import BytesIO
7
 
8
  st.set_page_config(page_title="Protein Repeat Comparator", layout="centered")
9
  st.title("🧬 Protein Repeat Comparator")
10
- st.write("Upload two Excel files with protein data. Frequency values should start from the second row.")
11
 
12
  uploaded_file1 = st.file_uploader("Upload First Excel File", type=["xlsx"])
13
  uploaded_file2 = st.file_uploader("Upload Second Excel File", type=["xlsx"])
@@ -40,12 +40,17 @@ if uploaded_file1 and uploaded_file2:
40
  freq1 = row1[repeat_col]
41
  freq2 = row2[repeat_col]
42
 
43
- if pd.isna(freq1) or pd.isna(freq2) or freq1 == 0:
44
  continue
45
 
46
  if freq1 != freq2:
 
 
 
 
 
 
47
  diff = abs(freq1 - freq2)
48
- pct_change = ((freq2 - freq1) / freq1) * 100
49
  differences.append({
50
  id_col: entry_id,
51
  name_col: protein_name,
@@ -60,24 +65,31 @@ if uploaded_file1 and uploaded_file2:
60
  result_df = pd.DataFrame(differences)
61
  result_df = result_df.sort_values(by="Difference", ascending=False)
62
 
63
- # Style for Excel (green for +, red for -)
 
 
 
 
64
  def color_pct(val):
65
- if val > 0:
66
  return 'color: green'
67
- elif val < 0:
68
- return 'color: red'
 
 
 
69
  return ''
70
 
71
  styled_df = result_df.style.applymap(color_pct, subset=["%age Change"])
72
 
 
73
  output = BytesIO()
74
  with pd.ExcelWriter(output, engine='openpyxl') as writer:
75
  styled_df.to_excel(writer, index=False, sheet_name="Changed Repeats")
76
  output.seek(0)
77
 
78
- st.success("βœ… Comparison complete. Showing only changed repeats.")
79
  st.download_button(
80
- label="πŸ“₯ Download Excel",
81
  data=output,
82
  file_name="changed_repeats_with_percentage.xlsx",
83
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
 
7
 
8
  st.set_page_config(page_title="Protein Repeat Comparator", layout="centered")
9
  st.title("🧬 Protein Repeat Comparator")
10
+ st.write("Upload two Excel files with protein data. Frequency values should start from the first row (header).")
11
 
12
  uploaded_file1 = st.file_uploader("Upload First Excel File", type=["xlsx"])
13
  uploaded_file2 = st.file_uploader("Upload Second Excel File", type=["xlsx"])
 
40
  freq1 = row1[repeat_col]
41
  freq2 = row2[repeat_col]
42
 
43
+ if pd.isna(freq1) or pd.isna(freq2):
44
  continue
45
 
46
  if freq1 != freq2:
47
+ if freq1 == 0:
48
+ pct_change = "Infinity"
49
+ else:
50
+ pct_change = ((freq2 - freq1) / freq1) * 100
51
+ pct_change = round(pct_change, 2)
52
+
53
  diff = abs(freq1 - freq2)
 
54
  differences.append({
55
  id_col: entry_id,
56
  name_col: protein_name,
 
65
  result_df = pd.DataFrame(differences)
66
  result_df = result_df.sort_values(by="Difference", ascending=False)
67
 
68
+ # Show DataFrame in Streamlit app
69
+ st.subheader("πŸ” View Changed Repeats")
70
+ st.dataframe(result_df, use_container_width=True)
71
+
72
+ # Apply styling
73
  def color_pct(val):
74
+ if isinstance(val, str) and val == "Infinity":
75
  return 'color: green'
76
+ elif isinstance(val, (int, float)):
77
+ if val > 0:
78
+ return 'color: green'
79
+ elif val < 0:
80
+ return 'color: red'
81
  return ''
82
 
83
  styled_df = result_df.style.applymap(color_pct, subset=["%age Change"])
84
 
85
+ # Save styled output
86
  output = BytesIO()
87
  with pd.ExcelWriter(output, engine='openpyxl') as writer:
88
  styled_df.to_excel(writer, index=False, sheet_name="Changed Repeats")
89
  output.seek(0)
90
 
 
91
  st.download_button(
92
+ label="πŸ“₯ Download Excel File",
93
  data=output,
94
  file_name="changed_repeats_with_percentage.xlsx",
95
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"