# $CVSHeader: pal8e/src/P-SeaParser.py,v 1.2 2005/02/15 01:10:26 indraneel Rel $

# parses P-Sea output files and stores for comparisons
# stores in dict format

import os
import string

class PSea(dict):
    def __init__(self, logger=None):
        if logger:
            self.logger = logger
            
    def store(self, fname):
        if not os.path.isfile(fname): return 'Err'
        self.fname = os.path.basename(fname)
        fh = file(fname)
        lines = fh.readlines()
        fh.close()
        ctr = 0
        for line in lines:
            aa = line[13]
            if aa == '!': continue
            chain=line[11]
            resid=int(line[6:10].lstrip())
            icode=line[10]
            ss=line[16]
            handedness = line[22]
            if (ss == 'H') and (handedness == '-'):
                ss = ' '
            if not self.has_key(chain):
                self[chain]={}
            ctr += 1
            self[chain][(resid, icode)] = {'#':ctr, 'AA':aa, 'SS':[ss]}
        dssp_elements = DSSPElements(self.logger, fname)
        typedef={'H':'H', 'G':'H', 'I':'H', 'E':'E'}
        dssp_elements.setType(typedef)
        self.elements = dssp_elements.getElements()
    
    
    
