How to use the bamnostic.bai.Bai function in bamnostic

To help you get started, we’ve selected a few bamnostic 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 betteridiot / bamnostic / bamnostic / bam.py View on Github external
def _init_index(self):
        """Initialize the index file (BAI)"""

        if self._check_idx:
            # self._index = bamnostic.bai.Bai(self._index_path)
            if self._index_ext == "csi":
                self._index = csi.Csi(self._index_path)
            elif self._index_ext == "bai":
                self._index = bai.Bai(self._index_path)

            self.__nocoordinate = self._index.n_no_coor
            self.__mapped = sum(
                self._index.unmapped[mapped].n_mapped
                for mapped in self._index.unmapped
            ) + (self.__nocoordinate if self.__nocoordinate is not None else 0)
            self.__unmapped = sum(
                self._index.unmapped[unmapped].n_unmapped
                for unmapped in self._index.unmapped
            ) + (self.__nocoordinate if self.__nocoordinate is not None else 0)
github betteridiot / bamnostic / bamnostic / csi.py View on Github external
level = total = 0
    
    while level <= depth:
        beg = total + (rbeg >> shift)
        end = total + (rend >> shift)
        
        i = beg
        while i <= end:
            yield i
            i += 1
        shift -= 3
        total += 1 << level * 3
        level += 1


class Csi(bai.Bai):
    """ This class defines the bam CSI index file object and its interface.

    The purpose of this class is the binary parsing of the bam index file (CSI) associated with
    a given bam file. When queried, the Csi object identifies the bins of data that overlap the
    requested region and directs which parts of the bam file contain it.

    Virtual offsets are processed using the following method:
    Beginning of compressed block = coffset = virtual offset >> 16
    Position within uncompressed block = uoffset = virtual offset ^ (coffset << 16)

    Attributes:
        _io (fileObject): opened CSI file object
        _UNMAP_BIN (int): constant for bin ID of unmapped read stats
        magic (bytes): first 4 bytes of file. Must be equal to b'CSI\x01'
        n_refs (int): number of references in CSI
        unmapped (dict): dictionary of the unmapped read stats by each reference