Package htsjdk.samtools.cram.build
Class CramIO
- java.lang.Object
-
- htsjdk.samtools.cram.build.CramIO
-
public class CramIO extends Object
A collection of methods to open and close CRAM files.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CRAM_FILE_EXTENSION
static byte[]
ZERO_B_EOF_MARKER
The 'zero-B' EOF marker as per CRAM specs v2.1.static byte[]
ZERO_F_EOF_MARKER
The zero-F EOF marker as per CRAM specs v3.0.
-
Constructor Summary
Constructors Constructor Description CramIO()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkHeaderAndEOF(File file)
Check if the file: 1) contains proper CRAM header.static long
issueEOF(Version version, OutputStream outputStream)
Write an end-of-file marker to theOutputStream
.static CramHeader
readCramHeader(InputStream inputStream)
Read CRAM header from the givenInputStream
.static boolean
replaceCramHeader(File file, CramHeader newHeader)
Attempt to replace the SAM file header in the CRAM file.static long
writeCramHeader(CramHeader cramHeader, OutputStream outputStream)
Writes CRAM header into the specifiedOutputStream
.static long
writeHeader(Version cramVersion, OutputStream outStream, SAMFileHeader samFileHeader, String cramID)
Write a CRAM File header and a SAM Header to an output stream.
-
-
-
Field Detail
-
CRAM_FILE_EXTENSION
public static final String CRAM_FILE_EXTENSION
- See Also:
- Constant Field Values
-
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.
-
-
Method Detail
-
issueEOF
public static long issueEOF(Version version, OutputStream outputStream) throws IOException
Write an end-of-file marker to theOutputStream
. The specific EOF marker is chosen based on the CRAM version.- Parameters:
version
- the CRAM version to assumeoutputStream
- 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 specifiedOutputStream
.- Parameters:
cramHeader
- theCramHeader
object to writeoutputStream
- the output stream to write to- Returns:
- the number of bytes written out
- Throws:
IOException
- as per java IO contract
-
readCramHeader
public static CramHeader readCramHeader(InputStream inputStream) throws IOException
Read CRAM header from the givenInputStream
.- Parameters:
inputStream
- input stream to read from- Returns:
- complete
CramHeader
object - 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 filenewHeader
- 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
-
-