2017-03-03 91 views
0

我目前使用BioPython Bio.PDB模块来解析和读取蛋白质结构文件(PDB文件)。尝试创建由PDBParser().get_structure(...)方法返回的structure对象的深层副本时,我遇到了递归问题。Python 3的递归错误copy.deepcopy

我的印象是,copy.deepcopy函数是专门用来处理递归吗?奇怪的是,这只是使用Python 3的一个问题。在Python 2.7中运行等效代码可以正常工作(使用urllib2而不是urllib)。

这是一个错误copy.deepcopy?或与Biopython有关的问题?

小例子(的Python 3.6,Biopython 1.68)是:

import urllib.request 
from io import StringIO 
from copy import deepcopy 
import Bio.PDB 

pdb_name = '1zro' 
#Download file 
pdb_url = "http://www.rcsb.org/pdb/files/" + pdb_name + ".pdb" 
pdb_file = urllib.request.urlopen(pdb_url) 
#Create string stream for Bio.PDB to read: 
pdb_input_stream = StringIO(pdb_file.read().decode('utf-8')) 

#Make Bio.PDB structure object 
parser = Bio.PDB.PDBParser() 
structure = parser.get_structure(pdb_name, pdb_input_stream) 

#Attempt to perform a deepcopy on Bio.PDB Structure: 
structure_copy = deepcopy(structure) 

完全回溯:

File "<stdin>", line 2, in <module> 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 180, in deepcopy 
    y = _reconstruct(x, memo, *rv) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 280, in _reconstruct 
    state = deepcopy(state, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 240, in _deepcopy_dict 
    y[deepcopy(key, memo)] = deepcopy(value, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 215, in _deepcopy_list 
    append(deepcopy(a, memo)) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 180, in deepcopy 
    y = _reconstruct(x, memo, *rv) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 280, in _reconstruct 
    state = deepcopy(state, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 240, in _deepcopy_dict 
    y[deepcopy(key, memo)] = deepcopy(value, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 215, in _deepcopy_list 
    append(deepcopy(a, memo)) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 180, in deepcopy 
    y = _reconstruct(x, memo, *rv) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 280, in _reconstruct 
    state = deepcopy(state, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 240, in _deepcopy_dict 
    y[deepcopy(key, memo)] = deepcopy(value, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 215, in _deepcopy_list 
    append(deepcopy(a, memo)) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 180, in deepcopy 
    y = _reconstruct(x, memo, *rv) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 280, in _reconstruct 
    state = deepcopy(state, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 240, in _deepcopy_dict 
    y[deepcopy(key, memo)] = deepcopy(value, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 150, in deepcopy 
    y = copier(x, memo) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 215, in _deepcopy_list 
    append(deepcopy(a, memo)) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 180, in deepcopy 
    y = _reconstruct(x, memo, *rv) 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/copy.py", line 281, in _reconstruct 
    if hasattr(y, '__setstate__'): 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/site-packages/Bio/PDB/Entity.py", line 207, in __getattr__ 
    if not hasattr(self, 'selected_child'): 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/site-packages/Bio/PDB/Entity.py", line 207, in __getattr__ 
    if not hasattr(self, 'selected_child'): 
    File "/home/andrew/Programs/anaconda3/envs/py36/lib/python3.6/site-packages/Bio/PDB/Entity.py", line 207, in __getattr__ 
    if not hasattr(self, 'selected_child'): 
    [Previous line repeated 318 more times] 
RecursionError: maximum recursion depth exceeded 
+0

您可能会对此感兴趣:http://stackoverflow.com/questions/3323001/what-is-the-maximum-recursion-depth-in-python-and-how-to-increase-it – sangheestyle

+1

Thanks @ sangheestyle,我已经尝试将递归限制提高到愚蠢的级别,并且只能达到段错误。但那也是我的第一个想法。 –

+0

我明白了。嗯..还有什么...... – sangheestyle

回答

1

安德鲁亲切提起这个作为Biopython问题https://github.com/biopython/biopython/issues/787 - 虽然我们还没有确定在Python 3下发生了什么问题。

+0

谢谢你标记彼得。我越来越相信,这是一个“深度拷贝”问题的根源,但还没有弄清楚到底发生了什么。试着将一个最小的例子放在一起,当我有时间时复制问题。 –