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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -18,10 +18,10 @@ if uploaded_file1 and uploaded_file2:
18
  df1 = pd.read_excel(uploaded_file1, header=1)
19
  df2 = pd.read_excel(uploaded_file2, header=1)
20
 
21
- # Column names
22
- id_col = "Entry ID"
23
- name_col = "Protein Name"
24
- repeat_cols = [col for col in df1.columns if col not in [id_col, name_col]]
25
 
26
  records = []
27
 
@@ -29,7 +29,7 @@ if uploaded_file1 and uploaded_file2:
29
  entry_id = row1[id_col]
30
  protein_name = row1[name_col]
31
 
32
- # Match protein in second file
33
  match = df2[(df2[id_col] == entry_id) & (df2[name_col] == protein_name)]
34
  if match.empty:
35
  continue
@@ -41,8 +41,8 @@ if uploaded_file1 and uploaded_file2:
41
  if freq1 != freq2:
42
  diff = abs(freq1 - freq2)
43
  records.append({
44
- "Entry ID": entry_id,
45
- "Protein Name": protein_name,
46
  "Repeat": repeat,
47
  "Frequency File 1": freq1,
48
  "Frequency File 2": freq2,
@@ -52,7 +52,6 @@ if uploaded_file1 and uploaded_file2:
52
  result_df = pd.DataFrame(records)
53
  result_df = result_df.sort_values(by="Difference", ascending=False)
54
 
55
- # In-memory Excel
56
  output = BytesIO()
57
  with pd.ExcelWriter(output, engine="openpyxl") as writer:
58
  result_df.to_excel(writer, index=False)
@@ -67,5 +66,4 @@ if uploaded_file1 and uploaded_file2:
67
  )
68
 
69
  except Exception as e:
70
- st.error(f"⚠️ Error: {e}")
71
-
 
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
 
 
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
 
41
  if freq1 != freq2:
42
  diff = abs(freq1 - freq2)
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,
 
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)
 
66
  )
67
 
68
  except Exception as e:
69
+ st.error(f"⚠️ Error: {e}")