Spaces:
Build error
Build error
| import streamlit as st | |
| # Function to find matches between reference and query sequences | |
| def find_matches(reference, query): | |
| matches = "" | |
| for ref_char, query_char in zip(reference, query): | |
| if ref_char == query_char: | |
| matches += ref_char.upper() | |
| else: | |
| matches += "-" | |
| match_percentage = (matches.count("-") / len(reference)) if len(reference) else 0 | |
| return matches, round((1 - match_percentage) * 100, 2) | |
| # Streamlit app | |
| st.title("DNA Sequence Matching 🧬") | |
| st.subheader("Analyze the similarity between two DNA sequences") | |
| # Input fields for sequences | |
| reference = st.text_area( | |
| "Enter Reference DNA Sequence:", | |
| placeholder="e.g., ACTGACTGACTG" | |
| ).strip().upper() | |
| query = st.text_area( | |
| "Enter Query DNA Sequence:", | |
| placeholder="e.g., ACTGTTTGACTG" | |
| ).strip().upper() | |
| # Validate input | |
| if st.button("Match DNA Sequences"): | |
| if not reference or not query: | |
| st.error("Please provide both Reference and Query DNA sequences.") | |
| elif len(reference) != len(query): | |
| st.error("The Reference and Query sequences must have the same length.") | |
| else: | |
| # Find matches and calculate percentage | |
| matches, percentage = find_matches(reference, query) | |
| # Display results | |
| st.write("**Reference Sequence:**") | |
| st.code(reference) | |
| st.write("**Query Sequence:**") | |
| st.code(query) | |
| st.write("**Matching Sequence:**") | |
| st.code(matches) | |
| st.success(f"Match Percentage: {percentage}%") | |
| st.write("Note: Sequences must be of the same length for accurate matching.") | |