Jayesh13 commited on
Commit
a0d5a6c
·
verified ·
1 Parent(s): b533841

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -14,22 +14,24 @@ uploaded_file2 = st.file_uploader("Upload Second Excel File", type=["xlsx"])
14
 
15
  if uploaded_file1 and uploaded_file2:
16
  try:
17
- # Read both Excel files, assuming header is in second row
18
  df1 = pd.read_excel(uploaded_file1, header=1)
19
  df2 = pd.read_excel(uploaded_file2, header=1)
20
 
21
- # Automatically detect first two columns
22
  id_col = df1.columns[0]
23
  name_col = df1.columns[1]
24
  repeat_cols = df1.columns[2:]
25
 
 
 
 
26
  records = []
27
 
28
  for _, row1 in df1.iterrows():
29
  entry_id = row1[id_col]
30
  protein_name = row1[name_col]
31
 
32
- # Match in second file
33
  match = df2[(df2[id_col] == entry_id) & (df2[name_col] == protein_name)]
34
  if match.empty:
35
  continue
@@ -43,27 +45,31 @@ if uploaded_file1 and uploaded_file2:
43
  records.append({
44
  id_col: entry_id,
45
  name_col: protein_name,
46
- "Repeat": repeat,
47
  "Frequency File 1": freq1,
48
  "Frequency File 2": freq2,
49
  "Difference": diff
50
  })
51
 
52
- result_df = pd.DataFrame(records)
53
- result_df = result_df.sort_values(by="Difference", ascending=False)
 
54
 
55
- output = BytesIO()
56
- with pd.ExcelWriter(output, engine="openpyxl") as writer:
57
- result_df.to_excel(writer, index=False)
58
- output.seek(0)
59
 
60
- st.success("✅ Comparison complete! Showing only changed repeats.")
61
- st.download_button(
62
- label="📥 Download Changed Repeats Excel",
63
- data=output,
64
- file_name="changed_protein_repeats.xlsx",
65
- mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
66
- )
 
 
67
 
68
  except Exception as e:
69
- st.error(f"⚠️ Error: {e}")
 
 
14
 
15
  if uploaded_file1 and uploaded_file2:
16
  try:
17
+ # Read Excel files (header starts from second row)
18
  df1 = pd.read_excel(uploaded_file1, header=1)
19
  df2 = pd.read_excel(uploaded_file2, header=1)
20
 
21
+ # Automatically get ID and Name column
22
  id_col = df1.columns[0]
23
  name_col = df1.columns[1]
24
  repeat_cols = df1.columns[2:]
25
 
26
+ # Ensure all column names are strings
27
+ repeat_cols = [str(col) for col in repeat_cols]
28
+
29
  records = []
30
 
31
  for _, row1 in df1.iterrows():
32
  entry_id = row1[id_col]
33
  protein_name = row1[name_col]
34
 
 
35
  match = df2[(df2[id_col] == entry_id) & (df2[name_col] == protein_name)]
36
  if match.empty:
37
  continue
 
45
  records.append({
46
  id_col: entry_id,
47
  name_col: protein_name,
48
+ "Repeat": str(repeat),
49
  "Frequency File 1": freq1,
50
  "Frequency File 2": freq2,
51
  "Difference": diff
52
  })
53
 
54
+ if records:
55
+ result_df = pd.DataFrame(records)
56
+ result_df = result_df.sort_values(by="Difference", ascending=False)
57
 
58
+ output = BytesIO()
59
+ with pd.ExcelWriter(output, engine="openpyxl") as writer:
60
+ result_df.to_excel(writer, index=False)
61
+ output.seek(0)
62
 
63
+ st.success("✅ Comparison complete! Only changed repeats are included.")
64
+ st.download_button(
65
+ label="📥 Download Changed Repeats Excel",
66
+ data=output,
67
+ file_name="changed_protein_repeats.xlsx",
68
+ mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
69
+ )
70
+ else:
71
+ st.info("No changes in repeat frequencies were found.")
72
 
73
  except Exception as e:
74
+ st.error(f"⚠️ Error: {e}")
75
+