我正在使用下面的代码创建一个文件夹,然后下载带有该蛋白质的关联PDB。我遇到的问题是PDB被下载到错误的位置。它们使用python脚本下载到loaction中,而不是下载到Cytochrome_C文件夹中。
pdb = [
['Cytochrome_C']
['1giw','TITLE']
['1lc1','TITLE']
['1lc2','TITLE']
]
for pdb in pdbs:
if str(pdb[0]) == 'Cytochrome_C':
os.popen('mkdir Cytochrome_C')
os.popen('cd ./Cytochrome_C')
if len(pdb) == 2:
os.popen('wget http://www.pdb.org/pdb/files/%s.pdb' % (str(pdb[0])))
答案 0 :(得分:4)
os.popen对于每个任务都是不必要的。使用shutil和urllib2:
pdb = [
['Cytochrome_C']
['1giw','TITLE']
['1lc1','TITLE']
['1lc2','TITLE']
]
cwd = os.path.abspath(os.getcwd())
for pdb in pdbs:
if pdb[0] == 'Cytochrome_C':
shutil.mkdir(os.path.join(cwd, pdb[0]))
if len(pdb) == 2:
s = urllib2.urlopen('http://www.pdb.org/pdb/files/%s.pdb' % pdb[0]).read()
open(os.path.join(cwd, 'Cytochrome_C', '%s.pdb' % pdb[0]), "w").write(s)