allpy
changeset 552:fb1fb5d5327f
structure.py: separate pdb-loading from auto_pdb
| author | boris (kodomo) <bnagaev@gmail.com> |
|---|---|
| date | Fri, 04 Mar 2011 15:16:28 +0300 |
| parents | f10570153cf7 |
| children | 1c8fb586d646 |
| files | allpy/structure.py |
| diffstat | 1 files changed, 9 insertions(+), 17 deletions(-) [+] |
line diff
1.1 --- a/allpy/structure.py Tue Mar 01 00:17:13 2011 +0300 1.2 +++ b/allpy/structure.py Fri Mar 04 15:16:28 2011 +0300 1.3 @@ -9,7 +9,6 @@ 1.4 import re 1.5 import os 1.6 import os.path 1.7 -from tempfile import NamedTemporaryFile 1.8 import urllib2 1.9 from copy import copy 1.10 1.11 @@ -39,10 +38,15 @@ 1.12 d['model'] = int(d['model']) 1.13 return d 1.14 1.15 - 1.16 def get_structure(file, name): 1.17 return PDBParser().get_structure(name, file) 1.18 1.19 +def download_pdb(code, pdb_url=config.pdb_url): 1.20 + """ Download pdb_file from web and return unnamed tempfile """ 1.21 + url = pdb_url % code 1.22 + print "Download %s" % url 1.23 + return urllib2.urlopen(url) 1.24 + 1.25 class SequenceMixin(base.Sequence): 1.26 """Mixin for adding PDB data to a Sequence. 1.27 1.28 @@ -106,7 +110,7 @@ 1.29 sequence.append(monomer) 1.30 return sequence 1.31 1.32 - def auto_pdb(self, conformity=None, dir='/tmp', mask='%s.pdb'): 1.33 + def auto_pdb(self, conformity=None, pdb_getter=download_pdb): 1.34 """ Adds pdb information to each monomer 1.35 1.36 Returns if information has been successfully added 1.37 @@ -120,20 +124,8 @@ 1.38 code = match['code'] 1.39 chain = match['chain'] 1.40 model = match['model'] 1.41 - user_path = os.path.join(dir, mask % code) 1.42 - path = user_path 1.43 - if not os.path.exists(path) or not os.path.getsize(path): 1.44 - path = config.pdb_path % code 1.45 - if not os.path.exists(path) or not os.path.getsize(path): 1.46 - url = config.pdb_url % code 1.47 - print "Download %s" % url 1.48 - path = user_path 1.49 - data = urllib2.urlopen(url).read() 1.50 - pdb_file = open(path, 'w') 1.51 - pdb_file.write(data) 1.52 - pdb_file.close() 1.53 - print "Save %s" % path 1.54 - self.set_pdb_chain(open(path), code, chain, model) 1.55 + pdb_file = pdb_getter(code) 1.56 + self.set_pdb_chain(pdb_file, code, chain, model) 1.57 return True 1.58 1.59 def save_pdb(self, out_filename, new_chain=None, new_model=None):
