allpy
changeset 138:32b9f4fadd35
allpy_pdb: new fasta id parsing function
broken: remove class Pdb
author | boris <bnagaev@gmail.com> |
---|---|
date | Sun, 24 Oct 2010 17:29:59 +0400 |
parents | 0b366ce3257f |
children | 57c923c2e333 |
files | geometrical_core/geometrical_core.py lib/allpy_pdb.py lib/project.py lib/sequence.py |
diffstat | 4 files changed, 68 insertions(+), 64 deletions(-) [+] |
line diff
1.1 --- a/geometrical_core/geometrical_core.py Sun Oct 24 17:06:15 2010 +0400 1.2 +++ b/geometrical_core/geometrical_core.py Sun Oct 24 17:29:59 2010 +0400 1.3 @@ -109,19 +109,20 @@ 1.4 1.5 try: 1.6 args = p.parse_args() 1.7 + 1.8 + if not args.l and not args.f and not args.g and not args.p and not args.s: 1.9 + print 'Error: no output file provided' 1.10 + exit() 1.11 + if not (args.p and args.s) and not (not args.p and not args.s): 1.12 + print 'Error: provide both pdb and spt file or none of them' 1.13 + exit() 1.14 + 1.15 + project = Project(args.i) 1.16 + project 1.17 + 1.18 except Exception, t: 1.19 print t 1.20 exit() 1.21 - 1.22 -if not args.l and not args.f and not args.g and not args.p and not args.s: 1.23 - print 'Error: no output file provided' 1.24 - exit() 1.25 1.26 -if not (args.p and args.s) and not (not args.p and not args.s): 1.27 - print 'Error: provide both pdb and spt file or none of them' 1.28 - exit() 1.29 1.30 1.31 - 1.32 - 1.33 -
2.1 --- a/lib/allpy_pdb.py Sun Oct 24 17:06:15 2010 +0400 2.2 +++ b/lib/allpy_pdb.py Sun Oct 24 17:29:59 2010 +0400 2.3 @@ -1,62 +1,59 @@ 2.4 2.5 import re 2.6 2.7 +""" 2.8 +Functions to get pdb information from fasta id 2.9 +and to generate fasta id from pdb information 2.10 + 2.11 +pdb information: code, chain, model 2.12 + 2.13 +TODO: same for local pdb files 2.14 +""" 2.15 + 2.16 # for pdb-codes 2.17 -re1 = re.compile(r"(^|[^a-z0-9])([0-9][0-9a-z]{3})([^a-z0-9]([0-9a-z ]?)([^a-z0-9]([0-9]{1,3}))?)?($|[^a-z0-9])") 2.18 +re1 = re.compile(r"(^|[^a-z0-9])(?P<code>[0-9][0-9a-z]{3})([^a-z0-9](?P<chain>[0-9a-z ]?)(?P<model>[^a-z0-9]([0-9]{1,3}))?)?($|[^a-z0-9])") 2.19 2.20 -# for files 2.21 -re2 = re.compile(r"(^)([^^]+\.(ent|pdb))([^a-zA-Z0-9]([0-9A-Za-z ]?)([^a-zA-Z0-9]([0-9]{1,3}))?)?$") 2.22 +#~ # for files 2.23 +#~ re2 = re.compile(r"(^)([^^]+\.(ent|pdb))([^a-zA-Z0-9]([0-9A-Za-z ]?)([^a-zA-Z0-9]([0-9]{1,3}))?)?$") 2.24 2.25 -class Pdb(object): 2.26 - """ 2.27 - """ 2.28 - @staticmethod 2.29 - def std_id(pdb_id, pdb_chain, pdb_model=None): 2.30 - if pdb_model: 2.31 - return "%s_%s_%s" % \ 2.32 - (pdb_id.lower().strip(), pdb_chain.upper().strip(), pdb_model) 2.33 - else: 2.34 - return "%s_%s" % \ 2.35 - (pdb_id.lower().strip(), pdb_chain.upper().strip()) 2.36 +def std_id(pdb_id, pdb_chain, pdb_model=None): 2.37 + if pdb_model: 2.38 + return "%s_%s_%s" % \ 2.39 + (pdb_id.lower().strip(), pdb_chain.upper().strip(), pdb_model) 2.40 + else: 2.41 + return "%s_%s" % \ 2.42 + (pdb_id.lower().strip(), pdb_chain.upper().strip()) 2.43 2.44 +def pdb_id_parse(ID): 2.45 + match = re1.search(ID, re.I) 2.46 + if not match: 2.47 + return None 2.48 + return match.groupdict() 2.49 2.50 - def std_id_parse(ID): 2.51 - """ 2.52 - Parse standart ID to pdb_code, chain and model 2.53 - """ 2.54 - if '.ent' in ID.lower() or '.pdb' in ID.lower(): 2.55 - # it is file 2.56 - parseO = self.re2.search(ID) # files 2.57 - else: 2.58 - parseO = self.re1.search(ID.lower()) # pdb codes 2.59 - if not parseO: 2.60 - return None 2.61 - parse = parseO.groups() 2.62 - if len(parse) < 2: 2.63 - return None 2.64 - code = parse[1] 2.65 - chain = '' 2.66 - model = None 2.67 - if len(parse) >= 4: 2.68 - chain = parse[3] 2.69 - if chain: 2.70 - chain = chain.upper() 2.71 - if len(parse) >= 6: 2.72 - if parse[5]: 2.73 - model = parse[5] 2.74 - return code, chain, model 2.75 2.76 +#~ def std_id_parse(ID): 2.77 + #~ """ 2.78 + #~ Parse standart ID to pdb_code, chain and model 2.79 + #~ """ 2.80 + #~ if '.ent' in ID.lower() or '.pdb' in ID.lower(): 2.81 + #~ # it is file 2.82 + #~ parseO = self.re2.search(ID) # files 2.83 + #~ else: 2.84 + #~ parseO = self.re1.search(ID.lower()) # pdb codes 2.85 + #~ if not parseO: 2.86 + #~ return None 2.87 + #~ parse = parseO.groups() 2.88 + #~ if len(parse) < 2: 2.89 + #~ return None 2.90 + #~ code = parse[1] 2.91 + #~ chain = '' 2.92 + #~ model = None 2.93 + #~ if len(parse) >= 4: 2.94 + #~ chain = parse[3] 2.95 + #~ if chain: 2.96 + #~ chain = chain.upper() 2.97 + #~ if len(parse) >= 6: 2.98 + #~ if parse[5]: 2.99 + #~ model = parse[5] 2.100 + #~ return code, chain, model 2.101 2.102 - 2.103 - 2.104 - 2.105 - 2.106 -#~ class Coordinates(object): 2.107 - """ 2.108 - float x, y, z 2.109 - 2.110 - Coordinates(x, y, z) -> Coordinates 2.111 - Coordinates() -> new Coordinates 2.112 - """ 2.113 - 2.114 -
3.1 --- a/lib/project.py Sun Oct 24 17:06:15 2010 +0400 3.2 +++ b/lib/project.py Sun Oct 24 17:29:59 2010 +0400 3.3 @@ -212,3 +212,9 @@ 3.4 else: 3.5 yield (column[indexes[original]], dict([(s, column[indexes[s]]) for s in sequences])) 3.6 3.7 + def add_pdb(self, conformity_file=None): 3.8 + pass 3.9 + 3.10 + 3.11 + 3.12 +
4.1 --- a/lib/sequence.py Sun Oct 24 17:06:15 2010 +0400 4.2 +++ b/lib/sequence.py Sun Oct 24 17:29:59 2010 +0400 4.3 @@ -1,7 +1,7 @@ 4.4 #!/usr/bin/python 4.5 from monomer import AminoAcidType 4.6 from Bio.PDB import PDBParser, CaPPBuilder 4.7 -from allpy_pdb import Pdb 4.8 +from allpy_pdb import std_id 4.9 import project 4.10 import sys 4.11 4.12 @@ -45,7 +45,7 @@ 4.13 Reads Pdb chain from file 4.14 and align each Monomer with PDB.Residue (TODO) 4.15 """ 4.16 - name = Pdb.std_id(pdb_id, pdb_chain, pdb_model) 4.17 + name = std_id(pdb_id, pdb_chain, pdb_model) 4.18 chain = PDBParser().get_structure(name, pdb_file)[pdb_model][pdb_chain] 4.19 self.pdb_chains.append(chain) 4.20 pdb_sequence = Sequence.from_pdb_chain(chain)