Skip to main content
 首页 » 编程设计

python之BioPython:氨基酸序列包含 'J',无法计算分子量

2025年05月04日27zdz8207

我正在处理的数据来自一个 Excel 文件,该文件的氨基酸序列位于索引 1 上。我正在尝试使用 BioPython 根据该序列计算不同的属性。我现在拥有的代码:

import xlrd 
import sys 
from Bio.SeqUtils.ProtParam import ProteinAnalysis 
 
print '~~~~~~~~~~~~~~~ EXCEL PARSER FOR PVA/NON-PVA DATA ~~~~~~~~~~~~~~~' 
 
print 'Path to Excel file:', str(sys.argv[1]) 
fname = sys.argv[1] 
workbook = xlrd.open_workbook(fname, 'rU') 
 
print '' 
print 'The sheet names that have been found in the Excel file: ' 
sheet_names = workbook.sheet_names() 
number_of_sheet = 1 
for sheet_name in sheet_names: 
    print '*', number_of_sheet, ':     ', sheet_name 
    number_of_sheet += 1 
 
with open("thefile.txt","w") as f: 
    lines = [] 
    f.write('LENGTH.SEQUENCE,SEQUENCE,MOLECULAR.WEIGHT\n') 
    for sheet_name in sheet_names: 
        worksheet = workbook.sheet_by_name(sheet_name) 
        print 'opened: ', sheet_name 
        for i in range(1, worksheet.nrows): 
            row = worksheet.row_values(i) 
            analysed_seq = ProteinAnalysis(row[1].encode('utf-8')) 
            weight = analysed_seq.molecular_weight() 
            lines.append('{},{},{}\n'.format(row[2], row[1].encode('utf-8'), weight)) 
    f.writelines(lines) 

它一直在工作,直到我添加了分子量的计算。这表明出现以下错误:

Traceback (most recent call last): 
  File "Excel_PVAdata_Parser.py", line 28, in <module> 
    weight = analysed_seq.molecular_weight() 
  File "/usr/lib/python2.7/dist-packages/Bio/SeqUtils/ProtParam.py", line 114, in molecular_weight 
    total_weight += aa_weights[aa] 
KeyError: 'J' 

我查看了 Excel 数据文件,这表明氨基酸序列确实包含一个 J。有人知道一个 BioPython 包可以捕捉到“未知氨基酸”或有其他建议吗?

请您参考如下方法:

Biopython 使用来自 IUPAC 的蛋白质分子量,参见 https://github.com/biopython/biopython/blob/master/Bio/Data/IUPACData.py

J 是亮氨酸或异亮氨酸(L 或 I)的模糊氨基酸编码,用于无法区分它们的 NMR。

根据您需要分子量的原因,使用 L 和 I 的重量平均值可能适合您?