How to use the bamnostic.bam.BamReader 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 / core.py View on Github external
except TypeError:
            return chr(ord(base_qual) + 33)

    return map(offset, qual_string)


# compiled/performant struct objects
_unpack_refId_pos = struct.Struct('<2i').unpack
_unpack_bmq_flag = struct.Struct('<2I').unpack
_unpack_lseq_nrid_npos_tlen = struct.Struct('<4i').unpack
_unpack_tag_val = struct.Struct('<2ss').unpack
_unpack_string = struct.Struct('
github betteridiot / bamnostic / bamnostic / core.py View on Github external
except KeyError:
                    pass
            bam.BamWriter.__init__(self, **wargs)

        else:
            read_args = ('filepath_or_object', 'mode', 'max_cache', 'index_filename',
                'filename', 'check_header', 'check_sq', 'reference_filename',
                'filepath_index', 'require_index', 'duplicate_filehandle',
                'ignore_truncation')
            rargs = {}
            for key in read_args:
                try:
                    rargs.update({key: kwargs.pop(key)})
                except KeyError:
                    pass
            bam.BamReader.__init__(self, **rargs)
github betteridiot / bamnostic / bamnostic / bam.py View on Github external
check_sq (bool): Inspect BAM file for `@SQ` entries within the header
            reference_filename (str): Not implemented. Maintained for backwards compatibility
            filepath_index (str): synonym for `index_filename`
            require_index (bool): require the presence of an index file or raise (default: False)
            duplicate_filehandle (bool): Not implemented. Raises warning if True.
            ignore_truncation (bool): Whether or not to allow trucated file processing (default: False).

        """

        # # Connect to the BAM file
        # self._handle = handle
        super_args = {'filepath_or_object': locals()['filepath_or_object'], 
                    'mode': locals()['mode'], 'max_cache': locals()['max_cache'],
                    'filename': locals()['filename'], 'ignore_truncation': locals()['ignore_truncation'], 
                    'duplicate_filehandle': locals()['duplicate_filehandle']}
        super(BamReader, self).__init__(**super_args)
        
        self._ignore_truncation = ignore_truncation
        self._truncated = self._check_truncation()

        # Check BAM file integrity
        if not self._ignore_truncation:
            if self._truncated:
                raise Exception('BAM file may be truncated. Turn off ignore_truncation if you wish to continue')

        # Connect and process the Index file (if present)
        self._index_ext = None
        self._index = None

        if filepath_index and index_filename and index_filename != filepath_index:
            raise IOError('Use index_filename or filepath_or_object. Not both')