Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
st.set_page_config(page_title="Protein Repeat Comparator", layout="centered")
|
5 |
+
st.title("🧬 Protein Repeat Comparator")
|
6 |
+
st.write("Upload two Excel files containing protein repeat frequencies. The tool will compare the values and return a sorted Excel file based on frequency differences.")
|
7 |
+
|
8 |
+
# File upload
|
9 |
+
uploaded_file1 = st.file_uploader("Upload First Excel File", type=["xlsx"])
|
10 |
+
uploaded_file2 = st.file_uploader("Upload Second Excel File", type=["xlsx"])
|
11 |
+
|
12 |
+
if uploaded_file1 and uploaded_file2:
|
13 |
+
try:
|
14 |
+
# Read both Excel files
|
15 |
+
df1 = pd.read_excel(uploaded_file1)
|
16 |
+
df2 = pd.read_excel(uploaded_file2)
|
17 |
+
|
18 |
+
# Ensure structure compatibility
|
19 |
+
common_cols = df1.columns.intersection(df2.columns)
|
20 |
+
df1 = df1[common_cols]
|
21 |
+
df2 = df2[common_cols]
|
22 |
+
|
23 |
+
# Merge on Entry ID and Protein Name
|
24 |
+
merged = pd.merge(df1, df2, on=["Entry ID", "Protein Name"], suffixes=('_file1', '_file2'))
|
25 |
+
|
26 |
+
# Compute differences
|
27 |
+
repeat_cols = common_cols[2:]
|
28 |
+
diff_data = {
|
29 |
+
"Entry ID": merged["Entry ID"],
|
30 |
+
"Protein Name": merged["Protein Name"]
|
31 |
+
}
|
32 |
+
|
33 |
+
for col in repeat_cols:
|
34 |
+
diff_data[col + "_diff"] = (merged[col + "_file1"] - merged[col + "_file2"]).abs()
|
35 |
+
|
36 |
+
diff_df = pd.DataFrame(diff_data)
|
37 |
+
diff_df["Total Difference"] = diff_df.iloc[:, 2:].sum(axis=1)
|
38 |
+
sorted_diff = diff_df.sort_values(by="Total Difference", ascending=False)
|
39 |
+
|
40 |
+
# Save to Excel
|
41 |
+
output_file = "protein_repeat_comparison.xlsx"
|
42 |
+
sorted_diff.to_excel(output_file, index=False)
|
43 |
+
|
44 |
+
st.success("✅ Comparison complete!")
|
45 |
+
with open(output_file, "rb") as f:
|
46 |
+
st.download_button(
|
47 |
+
label="📥 Download Comparison Excel",
|
48 |
+
data=f,
|
49 |
+
file_name=output_file,
|
50 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
51 |
+
)
|
52 |
+
|
53 |
+
except Exception as e:
|
54 |
+
st.error(f"⚠️ Error: {e}")
|