def fetch(self, chrom, start, end, strand=None):
        '''
        For TABIX indexed BED files, find all regions w/in a range

        For non-TABIX index BED files, use the calculated bins, and
        output matching regions
        '''

        if self.__tabix:
            for match in self.__tabix.fetch(chrom, start, end):
                region = BedRegion(*match.split('\t'))
                if not strand or (strand and region.strand == strand):
                    yield region
        else:
            startbin = start / BedFile._bin_const
            endbin = end / BedFile._bin_const

            buf = set()

            for bin in xrange(startbin, endbin + 1):
                if (chrom, bin) in self._bins:
                    for region in self._bins[(chrom, bin)]:
                        if strand and strand != region.strand:
                            continue
                        if start <= region.start <= end or start <= region.end <= end:
                            if not region in buf:
                                yield region
                                buf.add(region)
                        elif region.start < start and region.end > end:
                            if not region in buf:
                                yield region
                                buf.add(region)
dataset/ETHPy150Open ngsutils/ngsutils/ngsutils/bed/__init__.py/BedFile.fetch/original