Abdullah-Basar's picture
Create app.py
6f6a1bd verified
import streamlit as st
from difflib import SequenceMatcher
# Title and Description
st.title("πŸ”¬ DNA Sequence Matching App")
st.write("""
This app allows you to compare two DNA sequences to determine their similarity.
It highlights matches, mismatches, and calculates an alignment score.
""")
# Sidebar Instructions
st.sidebar.title("Instructions")
st.sidebar.write("""
1. Input two DNA sequences in the text boxes.
2. Click the **Compare Sequences** button.
3. View the results, including aligned sequences, match highlights, and the similarity score.
""")
# Input DNA Sequences
st.subheader("Enter DNA Sequences:")
seq1 = st.text_area("Sequence 1:", placeholder="Enter the first DNA sequence (e.g., ATCGTACG)...")
seq2 = st.text_area("Sequence 2:", placeholder="Enter the second DNA sequence (e.g., ATGGTACC)...")
# Compare Sequences Button
if st.button("Compare Sequences"):
if not seq1 or not seq2:
st.error("Please enter both DNA sequences to compare!")
else:
# Function to align and highlight matches
def align_sequences(seq1, seq2):
matcher = SequenceMatcher(None, seq1, seq2)
alignment1, alignment2, highlight = "", "", ""
for opcode, a1, a2, b1, b2 in matcher.get_opcodes():
if opcode == "equal":
alignment1 += seq1[a1:a2]
alignment2 += seq2[b1:b2]
highlight += "|" * (a2 - a1)
elif opcode == "replace" or opcode == "delete":
alignment1 += seq1[a1:a2]
alignment2 += "-" * (a2 - a1)
highlight += " " * (a2 - a1)
elif opcode == "insert":
alignment1 += "-" * (b2 - b1)
alignment2 += seq2[b1:b2]
highlight += " " * (b2 - b1)
return alignment1, alignment2, highlight
# Align sequences
aligned_seq1, aligned_seq2, highlights = align_sequences(seq1, seq2)
# Calculate similarity score
similarity = SequenceMatcher(None, seq1, seq2).ratio() * 100
# Display Results
st.subheader("Results:")
st.write("**Aligned Sequences:**")
st.code(aligned_seq1)
st.code(highlights)
st.code(aligned_seq2)
st.write(f"**Similarity Score:** {similarity:.2f}%")
st.write("---")
# Footer
st.write("πŸ” **Developed by Abdullah**")