How to use the bitarray.bits2bytes function in bitarray

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 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:
github bvernot / freezing-archer / bin / myBedTools3.py View on Github external
#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:
                    self.bases = ~ar
                else:
                    print "not initialized, and using fn other than set_to_one!"

bitarray

efficient arrays of booleans -- C extension

Python-2.0
Latest version published 2 months ago

Package Health Score

91 / 100
Full package analysis