前提・実現したいこと
初めまして、プログラム超初心者ですが、以下の事で頓挫しており、
皆様のお力添えをお願いします。
pdb_contact.pyというプログラムを使っていますが、オプションで残基番号を一つしか指定出来ません。
Win10にCentOS7をVirtual boxで入れている環境にて、
[kak@localhost]$ ./pdbTools_0.2.1/pdb_contact.py lig-rec.pdb -n 1 lig-rec N GLN H 1 GLN H 1 lig-rec CA GLN H 1 GLN H 1 lig-rec C GLN H 1 GLN H 1 VAL H 2 lig-rec O GLN H 1 GLN H 1 lig-rec CB GLN H 1 GLN H 1 lig-rec CG GLN H 1 GLN H 1 lig-rec CD GLN H 1 GLN H 1 lig-rec NE2 GLN H 1 GLN H 1 lig-rec OE1 GLN H 1 GLN H 1 lig-rec N ASP L 1 ASP L 1 lig-rec CA ASP L 1 ASP L 1 lig-rec C ASP L 1 ASP L 1 ILE L 2 lig-rec O ASP L 1 ASP L 1 lig-rec CB ASP L 1 ASP L 1 lig-rec CG ASP L 1 ASP L 1 lig-rec OD1 ASP L 1 ASP L 1 lig-rec OD2 ASP L 1 ASP L 1
と打ち込めばlig-rec.pdbの中から残基番号1と関連した結合の一覧が得られることを確認しています。
このプログラムを「残基番号の範囲を1-22のようにして動かす」
ようにしたいと思っています。
方法としてfor i in range(1,23):と範囲を指定してAnaconda3-5.3.1(pythonはsystemの2.7.5のまま)にてpdb_contact.pyを動かそうと思いましたが、やり方が分かりません。
Anacondaでのpdb_contact.pyの起動方法と残基番号の指定範囲の拡げ方を教えてください。
発生している問題・エラーメッセージ
In [1]: import sys In [3]: sys.path.append("pdbTools_0.2.1") In [4]: import pdb_contact In [19]: pdb_contact.pdbContacting("lig-rec.pdb","TRP",3.5) Out[19]: []
のように何もOutputされず、ソースコードを見ていて
main()のoutと
# If run from command line... if __name__ == "__main__": out = main() print "".join(out)
の部分で合わさって出力されるのかと思ったのですが、
pdbContacting()とmain()の依存関係と両者同時の起動方法も全体の結果出力方法もわかりませんでした。
さらにmain()での単独起動ではpbdファイルの指定の仕方が分からず上記のようなエラーが返ってきました。
In [21]: pdb_contact.main() Usage: ipython [options] pdb files and directories with pdb files ipython: error: You must specify at least one pdb file! An exception has occurred, use %tb to see the full traceback. SystemExit: 2 /HOME/.pyenv/versions/anaconda2-5.3.1/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2886: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
該当のソースコード
cat
1#!/usr/bin/env python 2 3# Copyright 2008, Michael J. Harms 4# This program is distributed under General Public License v. 3. See the file 5# COPYING for a copy of the license. 6 7__description__ = \ 8""" 9pdb_contacting-residues.py 10 11Find all residues within some cutoff of a target residue in a pdb file. 12""" 13__author__ = "Michael J. Harms" 14__date__ = "111116" 15 16import os 17 18def pdbContacting(pdb,target,cutoff,target_type="resname"): 19 """ 20 """ 21 22 cutoff_sq = (cutoff)**2 23 24 to_take = ["ATOM ","HETATM"] 25 all_coord = [[l[12:26],[float(l[30+8*i:38+8*i]) for i in range(3)]] 26 for l in pdb if l[0:6] in to_take] 27 28 if target_type == "resname": 29 target_list = [a for a in all_coord if a[0][5:8].strip() == target] 30 else: 31 target_list = [a for a in all_coord if int(a[0][10:14]) == target] 32 33 out = [] 34 for t in target_list: 35 contacts = [] 36 for a in all_coord: 37 if sum([(a[1][i]-t[1][i])**2 for i in range(3)]) < cutoff: 38 39 # ignore self 40 if t[0] == a[0]: 41 continue 42 contacts.append(a[0][5:].strip()) 43 44 # Grab only unique contacts 45 contacts = dict([(c,()) for c in contacts]).keys() 46 out.append("%s\t%s\n" % (t[0],("\t".join(contacts)))) 47 48 return out 49 50def main(): 51 """ 52 Function to call if run from command line. 53 """ 54 55 from helper import cmdline 56 import pdb_splitnmr 57 58 59 cmdline.initializeParser(__description__,__date__) 60 cmdline.addOption(short_flag="r", 61 long_flag="resname", 62 action="store", 63 default="TRP", 64 help="look for contacts near specified resname", 65 nargs=1) 66 cmdline.addOption(short_flag="n", 67 long_flag="resnum", 68 action="store", 69 default=None, 70 help="look for contacts near specified residue number", 71 nargs=1) 72 cmdline.addOption(short_flag="d", 73 long_flag="distance", 74 action="store", 75 default=3.5, 76 help="distance cutoff for calling contacts", 77 nargs=1, 78 type=float) 79 80 file_list, options = cmdline.parseCommandLine() 81 82 if options.resnum != None: 83 target_type = "resnum" 84 target = int(options.resnum) 85 else: 86 target_type = "resname" 87 target = options.resname 88 89 90 out = [] 91 for pdb_file in file_list: 92 93 f = open(pdb_file,'r') 94 pdb = f.readlines() 95 f.close() 96 97 # Only take the first NMR model 98 models = pdb_splitnmr.splitNMR(pdb) 99 if len(models) > 0: 100 pdb = models[0] 101 102 tmp_out = pdbContacting(pdb,target,options.distance,target_type) 103 104 out.extend(["%s\t%s" % (pdb_file[:-4],t) for t in tmp_out]) 105 106 return out 107 108 109# If run from command line... 110if __name__ == "__main__": 111 112 out = main() 113 print "".join(out) 114
試したこと
その他、
cmdline.addOption(short_flag="n", long_flag="resnum", action="store", default=None, help="look for contacts near specified residue number", nargs=1)
のnargs=1を2や"+"などに変えてみましたが上手くいきませんでした。
<追記>
nargs=2とした時のエラーです。
[kak@localhost ]$ ./pdbTools_0.2.1/pdb_contact2.py -n 1 2 lig-rec.pdb Traceback (most recent call last): File "./pdbTools_0.2.1/pdb_contact2.py", line 112, in <module> out = main() File "./pdbTools_0.2.1/pdb_contact2.py", line 80, in main file_list, options = cmdline.parseCommandLine() File "/home/kako/zdock/pdbTools_0.2.1/helper/cmdline.py", line 120, in parseCommandLine options, args = parser.parse_args() File "/usr/lib64/python2.7/optparse.py", line 1399, in parse_args stop = self._process_args(largs, rargs, values) File "/usr/lib64/python2.7/optparse.py", line 1443, in _process_args self._process_short_opts(rargs, values) File "/usr/lib64/python2.7/optparse.py", line 1540, in _process_short_opts % (opt, nargs)) TypeError: %d format: a number is required, not str
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー