Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ead450f

Browse files
update #17 refactore code
1 parent b2f91d3 commit ead450f

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed
Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
import sys
1+
def max_frequency(chars: str) -> tuple:
2+
""" This function returns the element that has the most repetitions in the DNA strand """
3+
prevous_max = 0
4+
current_max = 0
5+
max_char = ""
6+
A = len(chars) - 1
7+
i = 0
28

3-
def find_seq(dna,sample):
4-
"""return number of sequences OF sample in a dna"""
9+
while i < A:
10+
j = i
11+
current_max = 0
512

6-
#safty check
7-
if (sample not in ['A', 'T', 'C', 'G']):
8-
#invalid sample
9-
return 0
13+
while A >= j and chars[j] == chars[i]:
14+
current_max += 1
15+
j += 1
1016

11-
point = 0
12-
for i in range(len(dna)):
13-
if (dna[i] == sample):
14-
point += 1
15-
return point
17+
if current_max >= prevous_max:
18+
prevous_max = current_max
19+
max_char = chars[i]
1620

21+
i += 1
22+
return max_char, prevous_max
1723

18-
def main():
19-
user = input("Enter Dna SEQUENCE: ").strip().upper()
20-
lenght = len(user)
21-
22-
biggest = 0
23-
for i in range(lenght):
24-
temp = find_seq(sample = user[i],dna = user)
25-
26-
if (temp > biggest):
27-
biggest = temp
2824

29-
# print biggest number of sequences in dna
30-
print(biggest)
31-
25+
def main():
26+
chars = "aaabbbaaabbbbbbbbaaaaaaaaaaababababababababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
27+
r = max_frequency(chars=chars)
28+
print(r)
3229

33-
main()
30+
if __name__ == "__main__":
31+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /