Spaces:
Build error
Build error
File size: 1,586 Bytes
a87ee26 f823828 a87ee26 f823828 a87ee26 f823828 a87ee26 f823828 a87ee26 f823828 | 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 | import streamlit as st
# --- Title and Description ---
st.title("🔍 DNA Sequence Frequency Counter")
st.write("""
This application allows you to count how many times a specific DNA sequence appears in a larger DNA string.
""")
# --- Function to Validate DNA Sequence ---
def is_valid_dna(sequence):
return all(base in 'ATCG' for base in sequence.upper())
# --- Function to Count DNA Sequence Occurrences ---
def count_sequence_occurrences(dna_string, sub_sequence):
dna_string = dna_string.upper()
sub_sequence = sub_sequence.upper()
count = dna_string.count(sub_sequence)
return count
# --- Input for the Larger DNA String ---
dna_string = st.text_area("Enter the DNA string (A, T, C, G):", "")
# --- Input for the DNA Sequence to Search For ---
sub_sequence = st.text_input("Enter the DNA sequence to search for (A, T, C, G):", "")
# --- Count Button ---
if st.button("Count Occurrences"):
if not dna_string or not sub_sequence:
st.error("Please enter both the DNA string and the DNA sequence to search for.")
elif not is_valid_dna(dna_string) or not is_valid_dna(sub_sequence):
st.error("Invalid DNA input. Please use only A, T, C, and G.")
else:
# Count occurrences
count = count_sequence_occurrences(dna_string, sub_sequence)
# Display result
st.success(f"The sequence '{sub_sequence}' appears {count} time(s) in the given DNA string.")
# --- Example Usage ---
st.info("""
**Example DNA String:**
`ATGCGTATGCGTATGCTAGCTAGCTAGC`
**Example DNA Sequence to Search:**
`ATGCGT`
""")
|