Spaces:
Build error
Build error
Download app.py from hareshchander/DNASequence: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/hareshchander/DNASequence/resolve/main/app.py
- Command line
-
hf download hf://spaces/hareshchander/DNASequence/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hareshchander/DNASequence/resolve/main/app.py
1.59 kB
| 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` | |
| """) | |