File size: 2,432 Bytes
6f6a1bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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**")