def __init__(self, path, accessor, sense_specific=True, description="unlabeled track", system="hg18", dim=1, auto_flush=False, mode="r", **kwargs): self.path = path self.mode = mode self.acc_cache = {} self.accessor = accessor self.kwargs = kwargs self.sense_specific = to_bool(sense_specific) self.dim = int(dim) self.description = description self.auto_flush = auto_flush self.last_chrom = "" self.logger = getLogger("Track('%s')" % path) self.system = system self.logger.debug("Track(auto_flush=%s)" % (str(auto_flush))) kwargs['sense_specific'] = self.sense_specific kwargs['mode'] = self.mode kwargs['system'] = self.system kwargs['description'] = self.description kwargs['dim'] = self.dim if "w" in mode: # make sure the path exists right away so that the accessors # can flush the actual data there! from byo.io import ensure_path ensure_path(self.path)
def __init__(self,path,accessor,sense_specific=True,description="unlabeled track",system=None,dim=1,auto_flush=False,mode="r",**kwargs): self.path = path self.mode = mode self.acc_cache = {} self.accessor = accessor self.kwargs = kwargs self.sense_specific = to_bool(sense_specific) self.dim = int(dim) self.description = description self.auto_flush = auto_flush self.last_chrom = "" self.logger = logging.getLogger("byo.Track({0} {1} '{2}')".format(system,accessor,path)) self.system = system self.no_data = False self.logger.debug("Track(auto_flush=%s)" % (str(auto_flush))) kwargs['sense_specific'] = self.sense_specific kwargs['mode'] = self.mode kwargs['system'] = self.system kwargs['description'] = self.description kwargs['dim'] = self.dim if "w" in mode: # make sure the path exists right away so that the accessors # can flush the actual data there! from byo.io import ensure_path ensure_path(self.path)
def __init__(self,path,chrom,sense,sense_specific=True,dtype=numpy.float32,mode="r",dim=1,ext=".bin",**kwargs): super(ArrayAccessor,self).__init__(path,chrom,sense,sense_specific=sense_specific,**kwargs) self.logger = logging.getLogger('byo.io.ArrayAccessor') self.logger.debug("mmap'ing '%s' array data for chromosome %s%s from '%s'" % (str(dtype),chrom,sense,path)) # in case we havent been given the actual type, just its name: retrieve it if type(dtype) == str: dtype = getattr(numpy,dtype) self.dtype=dtype self.sense_specific = sense_specific self.dim = dim # preferred mode-codes for how to open an mmap array by assumed intention mode_trans = {"r" : "c","rw":"w+","w":"w+"} if sense_specific: fname = os.path.join(path,chrom+sense+ext) else: fname = os.path.join(path,chrom+ext) if not "w" in mode: # read-only access try: self.data = numpy.memmap(filename=fname,dtype=dtype,mode=mode_trans[mode]) except IOError: self.logger.warning("Could not access '%s'. Switching to dummy mode (only zeros)" % fname) self.data = ZeroSource(self.dtype) #self.get_data = self.get_dummy else: # create a sparse file from byo.io import ensure_path ensure_path(path) import byo.systems system = getattr(byo.systems,kwargs['system']) try: size = system.chr_sizes[chrom] except KeyError: self.logger.warning("Unknown chromosome '%s'. Switching to (read-only) dummy mode (only zeros)" % fname) self.data = ZeroSource(self.dtype) else: self.logger.info("opening '%s' (size=%d) for write-access" % (fname,size)) self.data = numpy.memmap(filename=fname,dtype=dtype,mode=mode_trans[mode],shape=size)
def __init__(self,path,chrom,sense,sense_specific=True,dtype=numpy.float32,mode="r",dim=1,**kwargs): debug("# ArrayAccessor mmap: Loading '%s' array data for chromosome %s%s from '%s'" % (str(dtype),chrom,sense,path)) super(ArrayAccessor,self).__init__(path,chrom,sense,sense_specific=sense_specific,**kwargs) # in case we havent been given the actual type, just its name: retrieve it if type(dtype) == str: dtype = getattr(numpy,dtype) self.dtype=dtype self.sense_specific = sense_specific self.dim = dim # preferred mode-codes for how to open an mmap array by assumed intention mode_trans = {"r" : "c","rw":"w+","w":"w+"} if sense_specific: fname = os.path.join(path,chrom+sense+".bin") else: fname = os.path.join(path,chrom+".bin") if not "w" in mode: # read-only access try: self.data = numpy.memmap(filename=fname,dtype=dtype,mode=mode_trans[mode]) except IOError: warning("Could not access '%s'. Switching to dummy mode (only zeros)" % fname) self.data = ZeroSource(self.dtype) #self.get_data = self.get_dummy else: # create a sparse file from byo.io import ensure_path ensure_path(path) import byo.systems system = getattr(byo.systems,kwargs['system']) try: size = system.chr_sizes[chrom] except KeyError: warning("Unknown chromosome '%s'. Switching to (read-only) dummy mode (only zeros)" % fname) self.data = ZeroSource(self.dtype) else: info("opening '%s' (size=%d) for write-access" % (fname,size)) self.data = numpy.memmap(filename=fname,dtype=dtype,mode=mode_trans[mode],shape=size)
def prep_storage(self): from byo.io import ensure_path import os if not self.store: ensure_path(os.path.dirname(self.path)) self.store = file(self.path, "w")
def prep_storage(self): from byo.io import ensure_path import os if not self.store: ensure_path(os.path.dirname(self.path)) self.store = file(self.path,"w")