Problem
A string is simply an ordered collection of symbols selected from some alphabet and formed into a word; the length of a string is the number of symbols that it contains.
An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G', and 'T') is "ATGCTTCAGAAAGGTCTTACG."
Given: A DNA string ss 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 ss.
Sample Dataset
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC
Sample Output
20 12 17 21
# -*- coding: utf-8 -*-
@author: hyl
"""
### 2. Transcribing DNA into RNA ###
d = {'A':0,'T':0,'G':0,'C':0}
with open('C:\\Users\\hyl\\Desktop\\rosalind_dna.txt') as f:
for line in f:
for i in line :
if i == "A":
d['A'] +=1
if i == "T":
d['T'] +=1
if i == "G":
d['G'] +=1
if i == "C":
d['C'] +=1
print str( d['A']) + " "+str(d['C']) + " " + str(d['G']) + " " + str(d['T'])
本文介绍了一种计算DNA字符串中A、C、G、T四种核苷酸出现次数的方法,通过遍历字符串并使用字典记录每种核苷酸的数量,最终输出这些数量。该方法适用于长度不超过1000nt的DNA字符串。

436

被折叠的 条评论
为什么被折叠?



