我写了一个读取整个DNA基因组的代码,并返回一个字典所有8-引物及其位置,我想循环浏览这本字典,并根据它们以a,T,G和C开头的字母将这些密码子排序到其他4个字典中。 但我不知道如何检查每把钥匙的第一个字母
这是我的代码:
"""
Generating all the possible 8-codon primers.
saving them in a text file with their locations.
"""
import csv
##MAIN FUNCTION:
def k_mer(Text, k):
dictionary = {}
for i in range (len(Text) - k + 1):
if(Text[i: i+k] in dictionary):
dictionary[Text[i: i+k]].append(i)
else:
dictionary[Text[i: i+k]] = [i]
return dictionary
##INPUT:
# open the file with the original sequence
myfile = open('Vibrio_cholerae.txt')
# set the file to the variable Text to read and scan
Text = myfile.read()
result = k_mer(Text.strip(), 8)
with open("result.txt","w") as f:
from collections import Counter
wr = csv.writer(f,delimiter=":")
wr.writerows(Counter(result).items())
考虑到你的
dictionary
,就是这样。这不是一个复杂的问题相关问题 更多 >
编程相关推荐