|
import streamlit as st |
|
from difflib import SequenceMatcher |
|
|
|
|
|
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. |
|
""") |
|
|
|
|
|
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. |
|
""") |
|
|
|
|
|
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)...") |
|
|
|
|
|
if st.button("Compare Sequences"): |
|
if not seq1 or not seq2: |
|
st.error("Please enter both DNA sequences to compare!") |
|
else: |
|
|
|
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 |
|
|
|
|
|
aligned_seq1, aligned_seq2, highlights = align_sequences(seq1, seq2) |
|
|
|
|
|
similarity = SequenceMatcher(None, seq1, seq2).ratio() * 100 |
|
|
|
|
|
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("---") |
|
|
|
|
|
st.write("π **Developed by Abdullah**") |
|
|