gpt4 book ai didi

python - 使用python计算肽单同位素

转载 作者:太空宇宙 更新时间:2023-11-03 21:16:15 24 4
gpt4 key购买 nike

我正在制作肽单同位素计算器,但有一些无法解决的问题。

import re

aminoacid = {
"I": "C6H13NO2",
"L": "C6H13NO2",
"K": "C6H14N2O2",
"M": "C5H11NO2S",
"F": "C9H11NO2",
"T": "C4H9NO3",
"W": "C11H12N2O2",
"V": "C5H11NO2",
"R": "C6H14N4O2",
"H": "C6H9N3O2",
"A": "C3H7NO2",
"N": "C4H8N2O3",
"D": "C4H7NO4",
"C": "C3H7NO2S",
"E": "C5H9NO4",
"Q": "C5H10N2O3",
"G": "C2H5NO2",
"P": "C5H9NO2",
"S": "C3H7NO3",
"Y": "C9H11NO3"
}

acid = input('Sequence: ')

s = re.findall('([A-Z][a-z]?)([0-9]*)', formula)

monoisotopic = {'S': 31.972, 'C': 12.0000, 'H': 1.0078, 'O': 15.9949, 'N': 14.0031}

weight = 0
for elem, count in s:

#For singular elements
if count=='':
count = 1

weight = weight + int(count) * monoisotopic[elem]

print('[M + H]+ : ', weight-(len(acid)-1)*18.0105+1.0078)

print('# of amino acids : ', len(acid))

如果我输入单个氨基酸,如“A”,效果很好。但是当我输入“AILWNG”之类的序列时,程序无法识别它。我怎样才能让这个程序识别两个或多个氨基酸?

最佳答案

如果我们将程序分成单独的函数,可能会有所帮助。首先,我们定义氨基酸和(相关)原子的原子量:

aminoacid = {
'I': 'C6H13NO2',
'L': 'C6H13NO2',
'K': 'C6H14N2O2',
'M': 'C5H11NO2S',
'F': 'C9H11NO2',
'T': 'C4H9NO3',
'W': 'C11H12N2O2',
'V': 'C5H11NO2',
'R': 'C6H14N4O2',
'H': 'C6H9N3O2',
'A': 'C3H7NO2',
'N': 'C4H8N2O3',
'D': 'C4H7NO4',
'C': 'C3H7NO2S',
'E': 'C5H9NO4',
'Q': 'C5H10N2O3',
'G': 'C2H5NO2',
'P': 'C5H9NO2',
'S': 'C3H7NO3',
'Y': 'C9H11NO3'
}
monoisotopic = {
'S': 31.972,
'C': 12.0000,
'H': 1.0078,
'O': 15.9949,
'N': 14.0031
}

然后可以定义一个函数来计算氨基酸(或任何其他原子)的重量:

from re import findall as refindall

def molecular_weight(molecule):
return sum(
monoisotopic[atom] * int(num or '1')
for atom, num in refindall(r'([A-Z][a-z]*)(\d*)', molecule)
)

然后我们可以总结氨基酸的分子量,例如:

def proteine_mass(proteine):
return sum(molecular_weight(aminoacid[char]) for char in proteine)

例如:

>>> proteine_mass('WATER')
733.3594
>>> proteine_mass('AILWNG')
762.4109000000001

(当然这不是H2O,可能上面的蛋白质不存在)

关于python - 使用python计算肽单同位素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54688466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com