Given: A DNA string s of length at most 1000 nt.
Return: Four integers (separated by spaces) counting the respective number of times that the symbols 'A', 'C', 'G', and 'T' occur in s.
I've wrote even two functions to count lettes:
import sys
import re
def cycle(s):
a_num = 0
t_num = 0
g_num = 0
c_num = 0
for i in s:
if i == 'A':
a_num += 1
elif i == 'T':
t_num += 1
elif i == 'G':
g_num += 1
elif i == 'C':
c_num += 1
return str(a_num) + ' ' + str(c_num) + ' ' + str(g_num) + ' ' + str(t_num)
def reg_expr(s):
A = re.findall(r'A', s)
C = re.findall(r'C', s)
G = re.findall(r'G', s)
T = re.findall(r'T', s)
return str(len(A)) + ' ' + str(len(C)) + ' ' + str(len(G)) + ' ' + str(len(T))
def main():
if len(sys.argv) > 1:
print reg_expr(sys.argv[1]) #cycle(sys.argv[1])
else:
print 'Enter your sequence!'
if __name__ == '__main__':
main()
Return: Four integers (separated by spaces) counting the respective number of times that the symbols 'A', 'C', 'G', and 'T' occur in s.
I've wrote even two functions to count lettes:
import sys
import re
def cycle(s):
a_num = 0
t_num = 0
g_num = 0
c_num = 0
for i in s:
if i == 'A':
a_num += 1
elif i == 'T':
t_num += 1
elif i == 'G':
g_num += 1
elif i == 'C':
c_num += 1
return str(a_num) + ' ' + str(c_num) + ' ' + str(g_num) + ' ' + str(t_num)
def reg_expr(s):
A = re.findall(r'A', s)
C = re.findall(r'C', s)
G = re.findall(r'G', s)
T = re.findall(r'T', s)
return str(len(A)) + ' ' + str(len(C)) + ' ' + str(len(G)) + ' ' + str(len(T))
def main():
if len(sys.argv) > 1:
print reg_expr(sys.argv[1]) #cycle(sys.argv[1])
else:
print 'Enter your sequence!'
if __name__ == '__main__':
main()
Комментариев нет:
Отправить комментарий