NayabShakeel commited on
Commit
056c79e
·
verified ·
1 Parent(s): 34976a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -15,15 +15,22 @@ def calculate_match_percentage(user_seq, reference_seq):
15
  match_percentage = (matches / len(reference_seq)) * 100
16
  return match_percentage, highlighted
17
 
 
 
 
 
18
  def main():
19
  st.title("DNA Sequence Matcher")
20
 
21
- st.write("This application compares a DNA sequence you provide to a reference DNA sequence and calculates the match percentage.")
22
 
23
  # Input fields
24
  reference_seq = st.text_input("Enter the reference DNA sequence:", "ACGTACGTACGT")
25
  user_seq = st.text_input("Enter your DNA sequence:")
26
 
 
 
 
27
  if len(user_seq) != len(reference_seq):
28
  st.warning("The length of your DNA sequence must match the length of the reference sequence.")
29
  elif user_seq and st.button("Compare"):
@@ -33,5 +40,10 @@ def main():
33
  st.markdown("### Highlighted Sequence:")
34
  st.markdown(f"{highlighted}", unsafe_allow_html=True)
35
 
 
 
 
 
 
36
  if __name__ == "__main__":
37
  main()
 
15
  match_percentage = (matches / len(reference_seq)) * 100
16
  return match_percentage, highlighted
17
 
18
+ def count_sequence_occurrences(sequence, substring):
19
+ """Counts the occurrences of a substring in the sequence."""
20
+ return sequence.count(substring)
21
+
22
  def main():
23
  st.title("DNA Sequence Matcher")
24
 
25
+ st.write("This application compares a DNA sequence you provide to a reference DNA sequence, calculates the match percentage, and finds occurrences of a specific sequence in the reference.")
26
 
27
  # Input fields
28
  reference_seq = st.text_input("Enter the reference DNA sequence:", "ACGTACGTACGT")
29
  user_seq = st.text_input("Enter your DNA sequence:")
30
 
31
+ # Input for substring to search
32
+ substring = st.text_input("Enter the DNA sequence to count its occurrences in the reference:")
33
+
34
  if len(user_seq) != len(reference_seq):
35
  st.warning("The length of your DNA sequence must match the length of the reference sequence.")
36
  elif user_seq and st.button("Compare"):
 
40
  st.markdown("### Highlighted Sequence:")
41
  st.markdown(f"{highlighted}", unsafe_allow_html=True)
42
 
43
+ # Check for substring occurrences
44
+ if substring:
45
+ count = count_sequence_occurrences(reference_seq, substring)
46
+ st.markdown(f"### Occurrences of '{substring}' in the reference sequence: {count}")
47
+
48
  if __name__ == "__main__":
49
  main()