Class CramIO


  • public class CramIO
    extends Object
    A collection of methods to open and close CRAM files.
    • Field Detail

      • ZERO_B_EOF_MARKER

        public static final byte[] ZERO_B_EOF_MARKER
        The 'zero-B' EOF marker as per CRAM specs v2.1. This is basically a serialized empty CRAM container with sequence id set to some number to spell out 'EOF' in hex.
      • ZERO_F_EOF_MARKER

        public static final byte[] ZERO_F_EOF_MARKER
        The zero-F EOF marker as per CRAM specs v3.0. This is basically a serialized empty CRAM container with sequence id set to some number to spell out 'EOF' in hex.
    • Constructor Detail

      • CramIO

        public CramIO()
    • Method Detail

      • issueEOF

        public static long issueEOF​(Version version,
                                    OutputStream outputStream)
                             throws IOException
        Write an end-of-file marker to the OutputStream. The specific EOF marker is chosen based on the CRAM version.
        Parameters:
        version - the CRAM version to assume
        outputStream - the stream to write to
        Returns:
        the number of bytes written out
        Throws:
        IOException - as per java IO contract
      • writeHeader

        public static long writeHeader​(Version cramVersion,
                                       OutputStream outStream,
                                       SAMFileHeader samFileHeader,
                                       String cramID)
        Write a CRAM File header and a SAM Header to an output stream.
        Parameters:
        cramVersion -
        outStream -
        samFileHeader -
        cramID -
        Returns:
        the offset in the stream after writing the headers
      • checkHeaderAndEOF

        public static boolean checkHeaderAndEOF​(File file)
                                         throws IOException
        Check if the file: 1) contains proper CRAM header. 2) given the version info from the header check the end of file marker.
        Parameters:
        file - the CRAM file to check
        Returns:
        true if the file is a valid CRAM file and is properly terminated with respect to the version.
        Throws:
        IOException - as per java IO contract
      • writeCramHeader

        public static long writeCramHeader​(CramHeader cramHeader,
                                           OutputStream outputStream)
                                    throws IOException
        Writes CRAM header into the specified OutputStream.
        Parameters:
        cramHeader - the CramHeader object to write
        outputStream - the output stream to write to
        Returns:
        the number of bytes written out
        Throws:
        IOException - as per java IO contract
      • replaceCramHeader

        public static boolean replaceCramHeader​(File file,
                                                CramHeader newHeader)
                                         throws IOException
        Attempt to replace the SAM file header in the CRAM file. This will succeed only if there is sufficient space reserved in the existing CRAM header. The implementation re-writes the first FILE_HEADER block in the first container of the CRAM file using random file access.
        Parameters:
        file - the CRAM file
        newHeader - the new CramHeader container a new SAM file header
        Returns:
        true if successfully replaced the header, false otherwise
        Throws:
        IOException - as per java IO contract