当前位置 : 主页 > 编程语言 > python >

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

来源:互联网 收集:自由互联 发布时间:2022-06-15
概念 双核苷酸由任意2个碱基组成 测试1 dna="AATGATGAACGAC" #一一列举 dinucleotides=['AA','AT','AG','AC', 'TA','TT','TG','TC', 'GA','GT','GG','GC', 'CA','CT','CG','CT'] all_counts={} fordinucleotideindinucleotides: count=dn

概念

双核苷酸由任意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


作者:Bioinfarmer

 若要及时了解动态信息,请关注同名微信公众号:Bioinfarmer。


上一篇:【Python小试】根据外显子位置生成CDS序列
下一篇:没有了
网友评论