首页 > 编程语言 > 详细

【Python小试】统计一条核酸序列中频数非0或为2的双核苷酸

时间:2020-04-21 00:56:58      阅读:102      评论:0      收藏:0      [点我收藏+]

概念

双核苷酸由任意2个碱基组成

测试1

dna = "AATGATGAACGAC"
#一一列举
dinucleotides = [‘AA‘,‘AT‘,‘AG‘,‘AC‘,
                 ‘TA‘,‘TT‘,‘TG‘,‘TC‘,
                 ‘GA‘,‘GT‘,‘GG‘,‘GC‘,
                 ‘CA‘,‘CT‘,‘CG‘,‘CT‘]

all_counts = {}
for dinucleotide in dinucleotides:
    count = dna.count(dinucleotide)
    if count > 0:
        all_counts[dinucleotide] = count
print(all_counts)

for dinucleotide in all_counts.keys():
    if all_counts.get(dinucleotide, 0) == 2:
        print(dinucleotide)

测试2

dna = "AATGATGAACGAC"
bases = [‘A‘,‘T‘,‘G‘,‘C‘]
all_counts = {}
#循环生成
for base1 in bases:
    for base2 in bases:
        dinucleotide = base1 + base2
        count = dna.count(dinucleotide)
        if count > 0:
            all_counts[dinucleotide] = count
print(all_counts)

for dinucleotide in all_counts.keys():
    if all_counts.get(dinucleotide, 0) == 2:
        print(dinucleotide)

结果

AA
AT
AC
TG

【Python小试】统计一条核酸序列中频数非0或为2的双核苷酸

原文:https://www.cnblogs.com/jessepeng/p/12741468.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!