diff --git a/gat/Engine.pyx b/gat/Engine.pyx index 66c43e0..20e232c 100644 --- a/gat/Engine.pyx +++ b/gat/Engine.pyx @@ -1,6 +1,7 @@ # cython: embedsignature=True # cython: profile=False +import traceback import collections import re import os @@ -3181,6 +3182,7 @@ cdef class Samples(object): If cache is given, samples will be stored persistently on disk. ''' + E.info(">>>Samples class initialized in Engine.pyx") self.samples = {} def add( self, track, sample_id, isochore, segmentlist ): @@ -3245,25 +3247,31 @@ cdef class SamplesCached( Samples ): cdef FILE * findex cdef dict index cdef char * filename + cdef char * indexextension def __init__(self, filename ): - '''create a new SampleCollection. - - If cache is given, samples will be stored persistently on disk. - ''' - Samples.__init__(self) - - self.filename = filename - tmp = self.filename + ".idx" - - if not os.path.exists( filename ): - self.fcache = fopen( filename, "wb" ) - self.findex = fopen( tmp, "wb" ) - self.index = {} - else: - self.fcache = fopen( filename, "rb" ) - self.loadIndex() - self.findex = fopen( tmp, "rb" ) + try: + E.info(">>>Trying from Engine.pyx: intializing SamplesCached class") + '''create a new SampleCollection. + If cache is given, samples will be stored persistently on disk. + ''' + Samples.__init__(self) + + self.filename = filename + self.indexextension = ".idx" + tmp = self.filename + self.indexextension + + if not os.path.exists( filename ): + self.fcache = fopen( filename, "wb" ) + self.findex = fopen( tmp, "wb" ) + self.index = {} + else: + self.fcache = fopen( filename, "rb" ) + self.loadIndex() + self.findex = fopen( tmp, "rb" ) + except Exception: + E.info(">>>Exception from Engine.pyx") + E.info(traceback.format_exc()) def loadIndex( self ): '''load index from cache. @@ -3276,7 +3284,7 @@ cdef class SamplesCached( Samples ): cdef char keylen cdef FILE * findex self.index = {} - tmp = self.filename + ".idx" + tmp = self.filename + self.indexextension findex = fopen( tmp, "rb" ) ckey = calloc(sizeof(char) * 256, 1) @@ -3339,6 +3347,7 @@ cdef class SamplesCached( Samples ): return self.toKey(track, sample_id, isochore) in self.index def __dealloc__(self): + E.info(">>>Saving cache files!") fclose( self.fcache) fclose( self.findex) diff --git a/gat/__init__.py b/gat/__init__.py index 8e57188..bfd00bb 100644 --- a/gat/__init__.py +++ b/gat/__init__.py @@ -948,7 +948,7 @@ def run(segments, if cache: E.info("samples are cached in %s" % cache) - samples = Engine.SamplesCached(filename=cache) + samples = Engine.SamplesCached(filename=cache.encode('utf-8')) elif sample_files: if not output_samples_pattern: raise ValueError( diff --git a/scripts/gat-run.py b/scripts/gat-run.py index d6338aa..9b75b88 100644 --- a/scripts/gat-run.py +++ b/scripts/gat-run.py @@ -72,9 +72,10 @@ import gat.Stats as Stats import gat.SegmentList as SegmentList import gat.Engine as Engine +import traceback -def fromSegments(options, args): +def _fromSegments(options, args): '''run analysis from segment files. This is the most common use case. @@ -219,6 +220,13 @@ def fromSegments(options, args): return annotator_results +def fromSegments(options, args): + try: + E.info(">>>Trying from gat-run.py") + return _fromSegments(options, args) + except Exception: + E.info(">>>Exception from gat-run.py") + E.info(traceback.format_exc()) def main(argv=None): """script main.