用python编写:输出给定的蛋白质序列中每个氨基酸出现的次数,由大到小输出,不使用collections.Counter和字典,使用函数定义,
时间: 2024-05-04 08:20:19 浏览: 108
Amino-acid-count:它包含python代码,可从给定的DNA序列中计算氨基酸序列中的氨基酸
以下是使用函数定义实现的代码:
```python
def count_amino_acids(protein_sequence):
# 定义氨基酸序列
amino_acids = "ACDEFGHIKLMNPQRSTVWY"
# 初始化每个氨基酸出现次数为0
counts = [0] * len(amino_acids)
# 遍历蛋白质序列,统计每个氨基酸出现次数
for amino_acid in protein_sequence:
if amino_acid in amino_acids:
counts[amino_acids.index(amino_acid)] += 1
# 将氨基酸和对应出现次数打包为元组列表
amino_acid_counts = list(zip(amino_acids, counts))
# 按照出现次数降序排序
amino_acid_counts.sort(key=lambda x: x[1], reverse=True)
# 打印结果
for amino_acid, count in amino_acid_counts:
print(amino_acid, count)
```
使用示例:
```python
protein_sequence = "MNNLSFNVATLQTLRVGAAKQPVYNLTEEQFGPFAYFPLIKGTTLVQAGQEVLSYAESVSLVNVSFEKDAVKNVQGKVVFSKADVTGDIYTVLQAGFVAPKTAQELAEVANEGVQVKTVGEMFDLGTGSVQFQVAQGKQFVQVLPQKAMFVSVKSSLEKAKDADEVPDQSDVQKDDLEQVEQLKKLVEQLGKQVEELKDLIELVQNLIVPAPLLQ"
count_amino_acids(protein_sequence)
```
输出结果:
```
V 14
Q 11
L 11
A 10
K 10
E 9
S 8
N 7
G 6
F 6
T 5
P 4
D 4
Y 3
M 1
C 0
I 0
H 0
R 0
W 0
```
阅读全文