|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 leoric666 于 2021-2-15 09:45 编辑
代码1
seq = 'GCCGGCCCTCAGACAGGAGTGGTCCTGGATGTGGATG'
kmer_length = 6
kmer_dictionary = {}
stop = len(seq) - kmer_length + 1
for start in range(0, stop):
kmer = seq[start:start + kmer_length]
if kmer in kmer_dictionary:
kmer_dictionary[kmer] += 1
else:
kmer_dictionary[kmer] = 1
t = "\t"
for kmer in kmer_dictionary:
count = kmer_dictionary[kmer]
out = (kmer, str(count))
print(t.join(out))
代码2
aip_kmers = open("newlines.txt",'w')
kmer1 = "ATGCNA"
kmer2 = "AAGCNC"
# Append newline when using write
aip_kmers.write(kmer1 + "\n")
aip_kmers.write(kmer2 + "\n")
# Appending newline not needed when using print
print(kmer1)
aip_kmers.close()
请问大家我如何把代码一中的基因序列全部保存到想代码2那样的文件中 |
|