【发布时间】:2017-02-13 11:45:14
【问题描述】:
我正在使用的数据来自一个 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 包,它在那里捕获“未知氨基酸”或有其他建议吗?
【问题讨论】:
-
这个问题似乎是非常特定于包的,这不是任何 python 标准模块。我建议查看特定论坛或项目的 github 页面。
标签: python bioinformatics xlrd biopython