diff --git a/src/main/java/htsjdk/samtools/cram/encoding/ByteArrayLenEncoding.java b/src/main/java/htsjdk/samtools/cram/encoding/ByteArrayLenEncoding.java index 0c45577932..dd97346109 100644 --- a/src/main/java/htsjdk/samtools/cram/encoding/ByteArrayLenEncoding.java +++ b/src/main/java/htsjdk/samtools/cram/encoding/ByteArrayLenEncoding.java @@ -47,11 +47,11 @@ public static EncodingParams toParam(final EncodingParams lenParams, final EncodingParams byteParams) { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { - byteArrayOutputStream.write((byte) lenParams.id.ordinal()); + byteArrayOutputStream.write((byte) lenParams.id.getId()); ITF8.writeUnsignedITF8(lenParams.params.length, byteArrayOutputStream); byteArrayOutputStream.write(lenParams.params); - byteArrayOutputStream.write((byte) byteParams.id.ordinal()); + byteArrayOutputStream.write((byte) byteParams.id.getId()); ITF8.writeUnsignedITF8(byteParams.params.length, byteArrayOutputStream); byteArrayOutputStream.write(byteParams.params); } catch (final IOException e) { @@ -64,12 +64,12 @@ public static EncodingParams toParam(final EncodingParams lenParams, public byte[] toByteArray() { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { - byteArrayOutputStream.write((byte) lenEncoding.id().ordinal()); + byteArrayOutputStream.write((byte) lenEncoding.id().getId()); final byte[] lenBytes = lenEncoding.toByteArray(); ITF8.writeUnsignedITF8(lenBytes.length, byteArrayOutputStream); byteArrayOutputStream.write(lenBytes); - byteArrayOutputStream.write((byte) byteEncoding.id().ordinal()); + byteArrayOutputStream.write((byte) byteEncoding.id().getId()); final byte[] byteBytes = byteEncoding.toByteArray(); ITF8.writeUnsignedITF8(byteBytes.length, byteArrayOutputStream); byteArrayOutputStream.write(byteBytes); diff --git a/src/main/java/htsjdk/samtools/cram/structure/Block.java b/src/main/java/htsjdk/samtools/cram/structure/Block.java index b74577a2f8..938709e46a 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/Block.java +++ b/src/main/java/htsjdk/samtools/cram/structure/Block.java @@ -283,8 +283,8 @@ private void doWrite(final OutputStream outputStream) throws IOException { if (!isCompressed()) compress(); if (!isUncompressed()) uncompress(); - outputStream.write(getMethod().ordinal()); - outputStream.write(getContentType().ordinal()); + outputStream.write(getMethod().getMethodId()); + outputStream.write(getContentType().getContentTypeId()); ITF8.writeUnsignedITF8(getContentId(), outputStream); ITF8.writeUnsignedITF8(compressedContentSize, outputStream); diff --git a/src/main/java/htsjdk/samtools/cram/structure/BlockCompressionMethod.java b/src/main/java/htsjdk/samtools/cram/structure/BlockCompressionMethod.java index 918b3bd68c..466fcad041 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/BlockCompressionMethod.java +++ b/src/main/java/htsjdk/samtools/cram/structure/BlockCompressionMethod.java @@ -17,6 +17,30 @@ */ package htsjdk.samtools.cram.structure; +/** + * The block compression methods specified by Section 8 of the CRAM spec + */ public enum BlockCompressionMethod { - RAW, GZIP, BZIP2, LZMA, RANS + RAW(0), + GZIP(1), + BZIP2(2), + LZMA(3), + RANS(4); + + private final int methodId; + + /** + * The block compression methods specified by Section 8 of the CRAM spec + * @param id the number assigned to each block compression method in the CRAM spec + */ + BlockCompressionMethod(final int id) { + methodId = id; + } + + /** + * @return the number assigned to each block compression method in the CRAM spec + */ + public int getMethodId() { + return methodId; + } } diff --git a/src/main/java/htsjdk/samtools/cram/structure/BlockContentType.java b/src/main/java/htsjdk/samtools/cram/structure/BlockContentType.java index e10b9f1aa2..258ef271f0 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/BlockContentType.java +++ b/src/main/java/htsjdk/samtools/cram/structure/BlockContentType.java @@ -17,6 +17,31 @@ */ package htsjdk.samtools.cram.structure; +/** + * The block content types specified by Section 8.1 of the CRAM spec + */ public enum BlockContentType { - FILE_HEADER, COMPRESSION_HEADER, MAPPED_SLICE, RESERVED, EXTERNAL, CORE + FILE_HEADER(0), + COMPRESSION_HEADER(1), + MAPPED_SLICE(2), + RESERVED(3), + EXTERNAL(4), + CORE(5); + + private final int contentTypeId; + + /** + * The block content types specified by Section 8.1 of the CRAM spec + * @param id the ID assigned to each content type in the CRAM spec + */ + BlockContentType(final int id) { + contentTypeId = id; + } + + /** + * @return the ID assigned to each content type in the CRAM spec + */ + public int getContentTypeId() { + return contentTypeId; + } } diff --git a/src/main/java/htsjdk/samtools/cram/structure/CompressionHeader.java b/src/main/java/htsjdk/samtools/cram/structure/CompressionHeader.java index 2278bf17e7..4aae519cca 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/CompressionHeader.java +++ b/src/main/java/htsjdk/samtools/cram/structure/CompressionHeader.java @@ -264,7 +264,7 @@ void write(final OutputStream outputStream) throws IOException { mapBuffer.put((byte) encodingKey.name().charAt(1)); final EncodingParams params = encodingMap.get(encodingKey); - mapBuffer.put((byte) (0xFF & params.id.ordinal())); + mapBuffer.put((byte) (0xFF & params.id.getId())); ITF8.writeUnsignedITF8(params.params.length, mapBuffer); mapBuffer.put(params.params); } @@ -283,7 +283,7 @@ void write(final OutputStream outputStream) throws IOException { ITF8.writeUnsignedITF8(encodingKey, mapBuffer); final EncodingParams params = tMap.get(encodingKey); - mapBuffer.put((byte) (0xFF & params.id.ordinal())); + mapBuffer.put((byte) (0xFF & params.id.getId())); ITF8.writeUnsignedITF8(params.params.length, mapBuffer); mapBuffer.put(params.params); } diff --git a/src/main/java/htsjdk/samtools/cram/structure/EncodingID.java b/src/main/java/htsjdk/samtools/cram/structure/EncodingID.java index 3073704289..b731aa76ae 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/EncodingID.java +++ b/src/main/java/htsjdk/samtools/cram/structure/EncodingID.java @@ -18,47 +18,64 @@ package htsjdk.samtools.cram.structure; /** - * Encoding ID as defined in the CRAM specs. These are basically ways to serialize a data series. + * Encoding ID as specified by Section 3 of the CRAM spec. These are basically ways to serialize a data series. */ public enum EncodingID { /** * "Do nothing" encoding. Should throw an exception when trying reading or writing with this encoding. */ - NULL, + NULL(0), /** * Shove the data into a byte array for compressing later with a generic compressor like GZIP. */ - EXTERNAL, + EXTERNAL(1), /** * 'naf said: http://en.wikipedia.org/wiki/Golomb_coding */ - GOLOMB, + GOLOMB(2), /** * http://en.wikipedia.org/wiki/Huffman_coding */ - HUFFMAN, + HUFFMAN(3), /** * A byte array serialized as [length][elements] */ - BYTE_ARRAY_LEN, + BYTE_ARRAY_LEN(4), /** * A byte array serialized as [elements][stop] */ - BYTE_ARRAY_STOP, + BYTE_ARRAY_STOP(5), /** * http://en.wikipedia.org/wiki/Beta_Code */ - BETA, + BETA(6), /** * Subexponential codes, see the CRAM specs for details. */ - SUBEXPONENTIAL, + SUBEXPONENTIAL(7), /** * A variant of GOLOMB encoding: http://en.wikipedia.org/wiki/Golomb_coding */ - GOLOMB_RICE, + GOLOMB_RICE(8), /** * http://en.wikipedia.org/wiki/Elias_gamma_coding */ - GAMMA + GAMMA(9); + + private final int id; + + /** + * The encodings specified by Section 3 of the CRAM spec + * @param id the number assigned to each encoding in the CRAM spec + */ + EncodingID(final int id) { + this.id = id; + } + + /** + * @return the number assigned to each encoding in the CRAM spec + */ + public int getId() { + return id; + } }