Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from difflib import SequenceMatcher
|
3 |
+
|
4 |
+
# Title and Description
|
5 |
+
st.title("🔬 DNA Sequence Matching App")
|
6 |
+
st.write("""
|
7 |
+
This app allows you to compare two DNA sequences to determine their similarity.
|
8 |
+
It highlights matches, mismatches, and calculates an alignment score.
|
9 |
+
""")
|
10 |
+
|
11 |
+
# Sidebar Instructions
|
12 |
+
st.sidebar.title("Instructions")
|
13 |
+
st.sidebar.write("""
|
14 |
+
1. Input two DNA sequences in the text boxes.
|
15 |
+
2. Click the **Compare Sequences** button.
|
16 |
+
3. View the results, including aligned sequences, match highlights, and the similarity score.
|
17 |
+
""")
|
18 |
+
|
19 |
+
# Input DNA Sequences
|
20 |
+
st.subheader("Enter DNA Sequences:")
|
21 |
+
seq1 = st.text_area("Sequence 1:", placeholder="Enter the first DNA sequence (e.g., ATCGTACG)...")
|
22 |
+
seq2 = st.text_area("Sequence 2:", placeholder="Enter the second DNA sequence (e.g., ATGGTACC)...")
|
23 |
+
|
24 |
+
# Compare Sequences Button
|
25 |
+
if st.button("Compare Sequences"):
|
26 |
+
if not seq1 or not seq2:
|
27 |
+
st.error("Please enter both DNA sequences to compare!")
|
28 |
+
else:
|
29 |
+
# Function to align and highlight matches
|
30 |
+
def align_sequences(seq1, seq2):
|
31 |
+
matcher = SequenceMatcher(None, seq1, seq2)
|
32 |
+
alignment1, alignment2, highlight = "", "", ""
|
33 |
+
|
34 |
+
for opcode, a1, a2, b1, b2 in matcher.get_opcodes():
|
35 |
+
if opcode == "equal":
|
36 |
+
alignment1 += seq1[a1:a2]
|
37 |
+
alignment2 += seq2[b1:b2]
|
38 |
+
highlight += "|" * (a2 - a1)
|
39 |
+
elif opcode == "replace" or opcode == "delete":
|
40 |
+
alignment1 += seq1[a1:a2]
|
41 |
+
alignment2 += "-" * (a2 - a1)
|
42 |
+
highlight += " " * (a2 - a1)
|
43 |
+
elif opcode == "insert":
|
44 |
+
alignment1 += "-" * (b2 - b1)
|
45 |
+
alignment2 += seq2[b1:b2]
|
46 |
+
highlight += " " * (b2 - b1)
|
47 |
+
|
48 |
+
return alignment1, alignment2, highlight
|
49 |
+
|
50 |
+
# Align sequences
|
51 |
+
aligned_seq1, aligned_seq2, highlights = align_sequences(seq1, seq2)
|
52 |
+
|
53 |
+
# Calculate similarity score
|
54 |
+
similarity = SequenceMatcher(None, seq1, seq2).ratio() * 100
|
55 |
+
|
56 |
+
# Display Results
|
57 |
+
st.subheader("Results:")
|
58 |
+
st.write("**Aligned Sequences:**")
|
59 |
+
st.code(aligned_seq1)
|
60 |
+
st.code(highlights)
|
61 |
+
st.code(aligned_seq2)
|
62 |
+
st.write(f"**Similarity Score:** {similarity:.2f}%")
|
63 |
+
st.write("---")
|
64 |
+
|
65 |
+
# Footer
|
66 |
+
st.write("🔍 **Developed by Abdullah**")
|