How to use the bamnostic.bgzf.get_block 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 write_header(self, copy_header = None, header = b'', reference_names = None, reference_lengths = None):
        """Modified code from Peter Cock's [BamWriter](https://github.com/peterjc/biopython/blob/SamBam2015/Bio/Sequencing/SamBam/__init__.py#L1714)

        Writes the header into a BAM file

        Args:
            copy_header (filepath_or_object): copy the header from another BAM file
            header (bytes): SAM-style header
            reference_names (:py:obj:`list` of :py:obj:`str`): list of all reference names used in file
            reference_lengths (:py:obj:`list` of :py:obj:`int`): list of all reference lengths used in file
        """
        if copy_header is not None:
            if isinstance(copy_header, bamnostic.core.AlignmentFile):
                print('From bam')
                self._handle.write(bgzf.get_block(copy_header))
                self._handle.flush()

        elif reference_names is not None and reference_lengths is not None:
            if len(reference_names) != len(reference_lengths):
                raise IOError('Reference names and reference lengths must be equal is size')
            header, references = _cross_check_header_refs(reads,
                                                        header,
                                                        reference_names,
                                                        reference_lengths)
            header = _as_bytes(_check_header_text(header))
            # Write BAM header:
            handle.write(_bam_magic)
            handle.write(struct.pack("
github betteridiot / bamnostic / bamnostic / bam.py View on Github external
self._SAMheader_end = _io._handle.tell()

        # Each reference is listed with the @SQ tag. We need the number of refs to process the data
        self.n_refs = unpack('