How to use the bamnostic.bam 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
def to_bam(bam_file):
        """Writes the alignment record to a BAM file

        Args:
            bam_file (string or :py:obj:`bamnostic.bam.BamWriter`): BAM file path or open bam file in a write mode
        """

        if type(bam_file) == str:
            # Natively go into append mode
            if os.path.isfile(bam_file):
                with bam.BamWriter(bam_file, mode = 'ab') as bam_out:
                    bam_out.write(self._raw_stream)
            else:
                raise IOError('BAM file must already exist, or be initilaized through bamnostic.bam.BamWriter')
        elif isinstance(bam_file, bgzf.BgzfWriter):
            bam_file.write(self._raw_stream)
        else:
            raise IOError('BAM file must already exist, or be initilaized through bamnostic.bam.BamWriter')