How to use bitarray - 10 common examples

To help you get started, we’ve selected a few bitarray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bvernot / freezing-archer / bin / myBedTools3.py View on Github external
code.fromfile(file, 8)
            if code.to01() != myBedTools.binaryseqfilegenome_code:
                print "unexpected code for binary seq file genome!"
                print "code:     ", code
                print "expected: ", myBedTools.binaryseqfilegenome_code
                sys.exit(-1)
            try:
                chr_byte_start = self.chr_offset[exp_chr] * self.factor // 8
                chr_partial_byte_start = (self.chr_offset[exp_chr] * self.factor) % 8
                print 'starting at', chr_byte_start, 'bytes, with', chr_partial_byte_start, 'offset'
                file.seek(chr_byte_start, 0)
                ar.fromfile(file, self.chr_lens[exp_chr] * self.factor + 16)
                print ar[0:100]
            except EOFError:
                pass
            if ar.length() != bitarray_m.bits2bytes(self.chr_lens[exp_chr] * self.factor) * 8:
                print "expected length of array to match given start and end!"
                print filename
                print ar.length(), bitarray_m.bits2bytes(self.genome_len * self.factor), self.genome_len * self.factor
                sys.exit(-1)
                pass
            # shorten ar to genome_len
            for i in xrange(ar.length() - self.genome_len * self.factor):
                #print self.genome_len, ar.length(), 'popping'
                ar.pop()
                pass

            self.bases = ar
            pass

        elif self.output_type == myBedTools.binaryseqfilegenome:
            infile = myBedTools.open_file(filename, discard_header = header)
github desbma / sacad / sacad / cover.py View on Github external
See: https://github.com/JohannesBuchner/imagehash/blob/4.0/imagehash/__init__.py#L125

    """
    parser = PIL.ImageFile.Parser()
    parser.feed(image_data)
    img = parser.close()
    target_size = (__class__.IMG_SIG_SIZE, __class__.IMG_SIG_SIZE)
    img.thumbnail(target_size, PIL.Image.BICUBIC)
    if img.size != target_size:
      logging.getLogger("Cover").debug("Non square thumbnail after resize to %ux%u, unable to compute signature" % target_size)
      return None
    img = img.convert(mode="RGB")
    pixels = img.getdata()
    pixel_count = target_size[0] * target_size[1]
    color_count = 3
    r = bitarray.bitarray(pixel_count * color_count)
    r.setall(False)
    for ic in range(color_count):
      mean = sum(p[ic] for p in pixels) // pixel_count
      for ip, p in enumerate(pixels):
        if p[ic] > mean:
          r[pixel_count * ic + ip] = True
    return r
github data61 / clkhash / tests / test_bloomhash.py View on Github external
def generate_bitarray(self, length):
        return bitarray(
            ''.join('1' if random.random() > 0.5 else '0' for _ in range(length))
        )
github openschc / openschc / src / comp_bitmap.py View on Github external
def gen_bits(N):
            #
            if N < 1:
                return None
            if N == 1:
                b = BitBuffer()
                b.set_bit(0)
                yield b
                b = BitBuffer()
                b._wpos = 0
                b.set_bit(1)
                yield b
            else:
                p = (1<
github openschc / openschc / src / comp_bitmap.py View on Github external
def gen_bits(N):
            #
            if N < 1:
                return None
            if N == 1:
                b = BitBuffer()
                b.set_bit(0)
                yield b
                b = BitBuffer()
                b._wpos = 0
                b.set_bit(1)
                yield b
            else:
                p = (1<
github openschc / openschc / src / comp_bitmap.py View on Github external
b = BitBuffer()
                b.set_bit(0)
                yield b
                b = BitBuffer()
                b._wpos = 0
                b.set_bit(1)
                yield b
            else:
                p = (1<
github openschc / openschc / src / comp_bitmap.py View on Github external
def gen_bits(N):
            #
            if N < 1:
                return None
            if N == 1:
                b = BitBuffer()
                b.set_bit(0)
                yield b
                b = BitBuffer()
                b._wpos = 0
                b.set_bit(1)
                yield b
            else:
                p = (1<
github bvernot / freezing-archer / bin / myBedTools3.py View on Github external
pass
            code.fromfile(file, 8)
            if code.to01() != myBedTools.binaryseqfilegenome_code:
                print "unexpected code for binary seq file genome!"
                print "code:     ", code
                print "expected: ", myBedTools.binaryseqfilegenome_code
                sys.exit(-1)
            try:
                #ar.fromfile(file, self.genome_len * self.factor + 16)
                ar.fromfile(file)
            except EOFError:
                pass
            if ar.length() != bitarray_m.bits2bytes(self.genome_len * self.factor) * 8:
                print "expected length of array to match given start and end!"
                print filename
                print ar.length(), bitarray_m.bits2bytes(self.genome_len * self.factor), self.genome_len * self.factor
                sys.exit(-1)
                pass
            # shorten ar to genome_len
            for i in xrange(ar.length() - self.genome_len * self.factor):
                #print self.genome_len, ar.length(), 'popping'
                ar.pop()
                pass

            self.bases = ar
            pass

        elif filetype == self.binaryseqfilegenomechr:
            print "THIS DOESN'T WORK"
            sys.exit(-1)
            ar = bitarray()
            code = bitarray()
github bvernot / freezing-archer / bin / myBedTools3.py View on Github external
file = gzip.open(filename, 'r')
            else:
                file = open(filename, 'r')
                pass
            code.fromfile(file, 8)
            if code.to01() != myBedTools.binaryseqfilegenome_code:
                print "unexpected code for binary seq file genome!"
                print "code:     ", code
                print "expected: ", myBedTools.binaryseqfilegenome_code
                sys.exit(-1)
            try:
                #ar.fromfile(file, self.genome_len * self.factor + 16)
                ar.fromfile(file)
            except EOFError:
                pass
            if ar.length() != bitarray_m.bits2bytes(self.genome_len * self.factor) * 8:
                print "expected length of array to match given start and end!"
                print filename
                print ar.length(), bitarray_m.bits2bytes(self.genome_len * self.factor), self.genome_len * self.factor
                sys.exit(-1)
                pass
            # shorten ar to genome_len
            for i in xrange(ar.length() - self.genome_len * self.factor):
                #print self.genome_len, ar.length(), 'popping'
                ar.pop()
                pass

            self.bases = ar
            pass

        elif filetype == self.binaryseqfilegenomechr:
            print "THIS DOESN'T WORK"
github bvernot / freezing-archer / bin / myBedTools3.py View on Github external
ar = bitarray()
            code = bitarray()
            file = open(filename, 'r')
            #code.fromfile(file)
            code.fromfile(file, 8)
            if code.to01() != myBedTools.binarybedfilegenome_code:
                print "unexpected code for binary bed file genome!"
                print "code:     ", code
                print "expected: ", myBedTools.binarybedfilegenome_code
                sys.exit(-1)
            try:
                #ar.fromfile(file, self.genome_len + 16)
                ar.fromfile(file)
            except EOFError:
                pass
            if ar.length() != bitarray_m.bits2bytes(self.genome_len) * 8:
                print "expected length of array to match given start and end!"
                print filename
                print ar.length(), bitarray_m.bits2bytes(self.genome_len), self.genome_len
                sys.exit(-1)
                pass
            # shorten ar to genome_len
            for i in xrange(ar.length() - self.genome_len):
                #print self.genome_len, ar.length(), 'popping'
                ar.pop()
                pass
            #### COULD CHECK FNS FOR BITARRAY STUFF (AND, OR ETC)
            if not self.initialize:
                self.initialize = True
                if fn == myBedTools.set_to_one:
                    self.bases = ar
                elif fn == myBedTools.set_to_zero:

bitarray

efficient arrays of booleans -- C extension

Python-2.0
Latest version published 6 months ago

Package Health Score

88 / 100
Full package analysis