Jayesh13 commited on
Commit
5a2a00f
Β·
verified Β·
1 Parent(s): 2c0f1ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -14,18 +14,15 @@ uploaded_file2 = st.file_uploader("Upload Second Excel File", type=["xlsx"])
14
 
15
  if uploaded_file1 and uploaded_file2:
16
  try:
17
- # Read files: header is in the first row (index 0)
18
  df1 = pd.read_excel(uploaded_file1, header=0)
19
  df2 = pd.read_excel(uploaded_file2, header=0)
20
 
21
- # Ensure column names are strings
22
  df1.columns = df1.columns.astype(str)
23
  df2.columns = df2.columns.astype(str)
24
 
25
- # Get ID and Name columns
26
  id_col = df1.columns[0]
27
  name_col = df1.columns[1]
28
- repeat_columns = df1.columns[2:] # Repeat columns start from index 2
29
 
30
  differences = []
31
 
@@ -43,34 +40,46 @@ if uploaded_file1 and uploaded_file2:
43
  freq1 = row1[repeat_col]
44
  freq2 = row2[repeat_col]
45
 
46
- if pd.isna(freq1) or pd.isna(freq2):
47
  continue
48
 
49
  if freq1 != freq2:
50
  diff = abs(freq1 - freq2)
 
51
  differences.append({
52
  id_col: entry_id,
53
  name_col: protein_name,
54
  "Repeat": repeat_col,
55
  "Frequency File 1": freq1,
56
  "Frequency File 2": freq2,
57
- "Difference": diff
 
58
  })
59
 
60
  if differences:
61
  result_df = pd.DataFrame(differences)
62
  result_df = result_df.sort_values(by="Difference", ascending=False)
63
 
 
 
 
 
 
 
 
 
 
 
64
  output = BytesIO()
65
  with pd.ExcelWriter(output, engine='openpyxl') as writer:
66
- result_df.to_excel(writer, index=False)
67
  output.seek(0)
68
 
69
  st.success("βœ… Comparison complete. Showing only changed repeats.")
70
  st.download_button(
71
  label="πŸ“₯ Download Excel",
72
  data=output,
73
- file_name="changed_repeats.xlsx",
74
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
75
  )
76
  else:
 
14
 
15
  if uploaded_file1 and uploaded_file2:
16
  try:
 
17
  df1 = pd.read_excel(uploaded_file1, header=0)
18
  df2 = pd.read_excel(uploaded_file2, header=0)
19
 
 
20
  df1.columns = df1.columns.astype(str)
21
  df2.columns = df2.columns.astype(str)
22
 
 
23
  id_col = df1.columns[0]
24
  name_col = df1.columns[1]
25
+ repeat_columns = df1.columns[2:]
26
 
27
  differences = []
28
 
 
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,
52
  "Repeat": repeat_col,
53
  "Frequency File 1": freq1,
54
  "Frequency File 2": freq2,
55
+ "Difference": diff,
56
+ "%age Change": pct_change
57
  })
58
 
59
  if differences:
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"
84
  )
85
  else: