Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/diff/32b9f4fadd35/lib/allpy_pdb.py
Дата изменения: Unknown
Дата индексирования: Sun Mar 2 02:57:04 2014
Кодировка:
allpy: lib/allpy_pdb.py diff

allpy

diff lib/allpy_pdb.py @ 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 ea3113da42ca
children 57c923c2e333
line diff
     1.1 --- a/lib/allpy_pdb.py	Sun Oct 24 17:06:15 2010 +0400
     1.2 +++ b/lib/allpy_pdb.py	Sun Oct 24 17:29:59 2010 +0400
     1.3 @@ -1,62 +1,59 @@
     1.4  
     1.5  import re
     1.6  
     1.7 +"""
     1.8 +Functions to get pdb information from fasta id
     1.9 +and to generate fasta id from pdb information
    1.10 +
    1.11 +pdb information: code, chain, model
    1.12 +
    1.13 +TODO: same for local pdb files
    1.14 +"""
    1.15 +
    1.16  # for pdb-codes
    1.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])")
    1.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])")
    1.19  
    1.20 -# for files
    1.21 -re2 = re.compile(r"(^)([^^]+\.(ent|pdb))([^a-zA-Z0-9]([0-9A-Za-z ]?)([^a-zA-Z0-9]([0-9]{1,3}))?)?$")
    1.22 +#~ # for files
    1.23 +#~ re2 = re.compile(r"(^)([^^]+\.(ent|pdb))([^a-zA-Z0-9]([0-9A-Za-z ]?)([^a-zA-Z0-9]([0-9]{1,3}))?)?$")
    1.24  
    1.25 -class Pdb(object):
    1.26 -    """
    1.27 -    """
    1.28 -    @staticmethod
    1.29 -    def std_id(pdb_id, pdb_chain, pdb_model=None):
    1.30 -        if pdb_model:
    1.31 -            return "%s_%s_%s" % \
    1.32 -            (pdb_id.lower().strip(), pdb_chain.upper().strip(), pdb_model)
    1.33 -        else:
    1.34 -            return "%s_%s" % \
    1.35 -            (pdb_id.lower().strip(), pdb_chain.upper().strip())
    1.36 +def std_id(pdb_id, pdb_chain, pdb_model=None):
    1.37 +    if pdb_model:
    1.38 +        return "%s_%s_%s" % \
    1.39 +        (pdb_id.lower().strip(), pdb_chain.upper().strip(), pdb_model)
    1.40 +    else:
    1.41 +        return "%s_%s" % \
    1.42 +        (pdb_id.lower().strip(), pdb_chain.upper().strip())
    1.43      
    1.44 +def pdb_id_parse(ID):
    1.45 +    match = re1.search(ID, re.I)
    1.46 +    if not match:
    1.47 +        return None
    1.48 +    return match.groupdict()
    1.49      
    1.50 -    def std_id_parse(ID):
    1.51 -        """
    1.52 -        Parse standart ID to pdb_code, chain and model
    1.53 -        """
    1.54 -        if '.ent' in ID.lower() or '.pdb' in ID.lower():
    1.55 -            # it is file
    1.56 -            parseO = self.re2.search(ID) # files
    1.57 -        else:
    1.58 -            parseO = self.re1.search(ID.lower()) # pdb codes
    1.59 -        if not parseO:
    1.60 -            return None
    1.61 -        parse = parseO.groups()
    1.62 -        if len(parse) < 2:
    1.63 -            return None
    1.64 -        code = parse[1]
    1.65 -        chain = ''
    1.66 -        model = None
    1.67 -        if len(parse) >= 4:
    1.68 -            chain = parse[3]
    1.69 -            if chain:
    1.70 -                chain = chain.upper()
    1.71 -            if len(parse) >= 6:
    1.72 -                if parse[5]:
    1.73 -                    model = parse[5]
    1.74 -        return code, chain, model
    1.75      
    1.76 +#~ def std_id_parse(ID):
    1.77 +    #~ """
    1.78 +    #~ Parse standart ID to pdb_code, chain and model
    1.79 +    #~ """
    1.80 +    #~ if '.ent' in ID.lower() or '.pdb' in ID.lower():
    1.81 +        #~ # it is file
    1.82 +        #~ parseO = self.re2.search(ID) # files
    1.83 +    #~ else:
    1.84 +        #~ parseO = self.re1.search(ID.lower()) # pdb codes
    1.85 +    #~ if not parseO:
    1.86 +        #~ return None
    1.87 +    #~ parse = parseO.groups()
    1.88 +    #~ if len(parse) < 2:
    1.89 +        #~ return None
    1.90 +    #~ code = parse[1]
    1.91 +    #~ chain = ''
    1.92 +    #~ model = None
    1.93 +    #~ if len(parse) >= 4:
    1.94 +        #~ chain = parse[3]
    1.95 +        #~ if chain:
    1.96 +            #~ chain = chain.upper()
    1.97 +        #~ if len(parse) >= 6:
    1.98 +            #~ if parse[5]:
    1.99 +                #~ model = parse[5]
   1.100 +    #~ return code, chain, model
   1.101      
   1.102 -    
   1.103 -    
   1.104 -    
   1.105 -
   1.106 -#~ class Coordinates(object):
   1.107 -    """
   1.108 -    float x, y, z
   1.109 -    
   1.110 -    Coordinates(x, y, z) -> Coordinates
   1.111 -    Coordinates() -> new Coordinates
   1.112 -    """
   1.113 -
   1.114 -