def _process_file(self):
        '''Process rebase file into dict with name and cut site information.'''
        print 'Processing file'
        with open(self._rebase_file, 'r') as f:
            raw = f.readlines()
        names = [line.strip()[3:] for line in raw if line.startswith('<1>')]
        seqs = [line.strip()[3:] for line in raw if line.startswith('<5>')]
        if len(names) != len(seqs):
            raise Exception('Found different number of enzyme names and '
                            'sequences.')
        self._enzyme_dict = {}
        for name, seq in zip(names, seqs):
            if '?' in seq:
                # Is unknown sequence, don't keep it
                pass
            elif seq.startswith('(') and seq.endswith(')'):
                # Has four+ cut sites, don't keep it
                pass
            elif '^' in seq:
                # Has reasonable internal cut sites, keep it
                top_cut = seq.index('^')
                bottom_cut = len(seq) - top_cut - 1
                site = seq.replace('^', '')
                self._enzyme_dict[name] = (site, (top_cut, bottom_cut))
            elif seq.endswith(')'):
                # Has reasonable external cut sites, keep it
                # (4-cutter also starts with '(')
                # separate site and cut locations
                site, cuts = seq.split('(')
                cuts = cuts.replace(')', '')
                top_cut, bottom_cut = [int(x) + len(site) for x in
                                       cuts.split('/')]
                self._enzyme_dict[name] = (site, (top_cut, bottom_cut))
        shutil.rmtree(self._tmpdir)
def _process_file ( self ) : print 'Processing file' with open ( self . _rebase_file , 'r' ) as f : raw = f . readlines ( ) names = [ line . strip ( ) [ 3 : ] for line in raw if line . startswith ( '<1>' ) ] seqs = [ line . strip ( ) [ 3 : ] for line in raw if line . startswith ( '<5>' ) ] if len ( names ) != len ( seqs ) : raise Exception ( 'Found different number of enzyme names and ' 'sequences.' ) self . _enzyme_dict = { } for name , seq in zip ( names , seqs ) : if '?' in seq : pass elif seq . startswith ( '(' ) and seq . endswith ( ')' ) : pass elif '^' in seq : top_cut = seq . index ( '^' ) bottom_cut = len ( seq ) - top_cut - 1 site = seq . replace ( '^' , '' ) self . _enzyme_dict [ name ] = ( site , ( top_cut , bottom_cut ) ) elif seq . endswith ( ')' ) : site , cuts = seq . split ( '(' ) cuts = cuts . replace ( ')' , '' ) top_cut , bottom_cut = [ int ( x ) + len ( site ) for x in cuts . split ( '/' ) ] self . _enzyme_dict [ name ] = ( site , ( top_cut , bottom_cut ) ) shutil . rmtree ( self . _tmpdir )
Process rebase file into dict with name and cut site information.