いつも勉強させていただいてます。
カレントディレクトリにある”complex..pdb” (に1~1000の数字に振り分けられたファイル)をglob関数で取得していき、pdb=PDBParser().get_structure(”complex.”, ”complex..pdb”)という形に入力していき(*に同じ数字を入力)、(”complex.1”, ”complex.1.pdb”)、(”complex.2”, ”complex.2.pdb”)・・・という形に出力していきたいのですが、for文でくみ合わせると上手くいきませんでした。
同じようなことをしようとしていつもつまづいていますが、ループ処理中に同じ変数を複数個所に含むようなものの処理はどのようにしたらいいのでしょうか。for文を二個組み合わせたりしても2変数がバラバラになり無限ループに陥ります。
お願いします。
In [5]: for filenames in glob.glob("complex.*.pdb"): ...: for lignames in glob.glob("complex.*.pdb"): ...: pdb=PDBParser().get_structure(lignames,filenames)
追記です。
Pythonについての質問です。
教えていただいたコマンドにて以下の様にいくつかのファイルをカレントディレクトリに置いてそれぞれ、id、filenamesを得ることが出来ました。
しかし、PDBParser().get_structure(lignames,filenames)に入力すると何故かcomplex.7.pdbしか処理されませんでした。
PDBParserの仕様によるものだと思うのですが、どなたか原因をご教授ください。
In [8]: for filenames in glob.glob("complex.*.pdb"): ...: id, ext=os.path.splitext(filenames) ...: print(id) ...: ...: ...: complex.10 complex.1-2 complex.4 complex.5 complex.8 complex.3 complex.6 complex.2 complex.9 complex.7
In [9]: for filenames in glob.glob("complex.*.pdb"): ...: id, ext=os.path.splitext(filenames) ...: print(filenames) ...: ...: ...: ...: complex.10.pdb complex.1-2.pdb complex.4.pdb complex.5.pdb complex.8.pdb complex.3.pdb complex.6.pdb complex.2.pdb complex.9.pdb complex.7.pdb
以下のサイトよりPDBParserのクラス内容です。
https://biopython.org/DIST/docs/api/Bio.PDB.PDBParser%27-pysrc.html#PDBParser.get_structure
1 # Copyright (C) 2002, Thomas Hamelryck (thamelry@binf.ku.dk) 2 # This code is part of the Biopython distribution and governed by its 3 # license. Please see the LICENSE file that should have been included 4 # as part of this package. 5 6 """Parser for PDB files.""" 7 8 from __future__ import print_function 9 10 import warnings 11 12 try: 13 import numpy 14 except ImportError: 15 from Bio import MissingPythonDependencyError 16 raise MissingPythonDependencyError( 17 "Install NumPy if you want to use the PDB parser.") 18 19 from Bio.File import as_handle 20 21 from Bio.PDB.PDBExceptions import PDBConstructionException 22 from Bio.PDB.PDBExceptions import PDBConstructionWarning 23 24 from Bio.PDB.StructureBuilder import StructureBuilder 25 from Bio.PDB.parse_pdb_header import _parse_pdb_header_list 26 27 28 # If PDB spec says "COLUMNS 18-20" this means line[17:20] 29 30 31 -class PDBParser(object): 32 """Parse a PDB file and return a Structure object.""" 33 34 + def __init__(self, PERMISSIVE=True, get_header=False, 35 structure_builder=None, QUIET=False): ... 65 66 # Public methods 67 68 - def get_structure(self, id, file): 69 """Return the structure. 70 71 Arguments: 72 - id - string, the id that will be used for the structure 73 - file - name of the PDB file OR an open filehandle 74 75 """ 76 with warnings.catch_warnings(): 77 if self.QUIET: 78 warnings.filterwarnings("ignore", category=PDBConstructionWarning) 79 80 self.header = None 81 self.trailer = None 82 # Make a StructureBuilder instance (pass id of structure as parameter) 83 self.structure_builder.init_structure(id) 84 85 with as_handle(file, mode='rU') as handle: 86 self._parse(handle.readlines()) 87 88 self.structure_builder.set_header(self.header) 89 # Return the Structure instance 90 structure = self.structure_builder.get_structure() 91 92 return structure
PDBParserのせいでは無かったようです。
以下で上手くいきました。
for filenames in glob.glob("complex.*.pdb"): id=os.path.splitext(filenames)[0] pdb=PDBParser().get_structure(id,filenames)
回答1件
あなたの回答
tips
プレビュー