rosalind练习题一

这篇文章描述了一个问题,即给定一个不超过1000个核苷酸的DNA字符串,计算其中A、C、G和T出现的次数。提供了两种Python方法来解决这个问题,一种是使用内置的`count`函数,另一种是通过循环遍历字符串并累加计数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 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.

Sample Dataset

AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC

Sample Output

20 12 17 21

代码:

seq="AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"

# 第一种方法

print(seq.count("A"))

print(seq.count("C"))

print(seq.count("G"))

print(seq.count("T"))

# 第二种方法

a = 0

b = 0

c = 0

d = 0

for i in seq:

    if i == "A":

    a += 1

    elif i == "C":

    b += 1

    elif i == "G":

    c += 1

    elif i == "T":

    d += 1

print(a, b, c, d)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值