问题:假设存在一个蛋白序列seq 'MPKRKKMRLFEEDDEIRESLLGADNKDKDEDEDLQSDTENRTFLEDTDTV',计算各个氨基酸出现的频率。
方法1:
seq = 'MPKRKKMRLFEEDDEIRESLLGADNKDKDEDEDLQSDTENRTFLEDTDTV'
ani_result = {}
for ani in range(len(seq)):
if seq[ani] in ani_result:
ani_result[seq[ani]] += 1
else:
ani_result[seq[ani]] = 1
for each in sorted(ani_result.keys()):
print(each + " " + str(ani_result[each]))
#或者是列表格式
print(sorted(ani_result.items(), key=lambda x: x[1]))
运行结果
方法2:利用count函数,统计20种氨基酸在蛋白序列中出现的次数
seq = 'MPKRKKMRLFEEDDEIRESLLGADNKDKDEDEDLQSDTENRTFLEDTDTV'
for ani in 'ARNDCQEGHIKMFPSTWYV':
num_result = seq.count(ani)
print(ani, num_result)
网友评论