diff --git a/src/main/java/htsjdk/samtools/SAMBinaryTagAndUnsignedArrayValue.java b/src/main/java/htsjdk/samtools/SAMBinaryTagAndUnsignedArrayValue.java index c171d3686e..2eeb67fa75 100644 --- a/src/main/java/htsjdk/samtools/SAMBinaryTagAndUnsignedArrayValue.java +++ b/src/main/java/htsjdk/samtools/SAMBinaryTagAndUnsignedArrayValue.java @@ -35,7 +35,7 @@ public SAMBinaryTagAndUnsignedArrayValue(final short tag, final Object value) { if (!value.getClass().isArray() || value instanceof float[]) { throw new IllegalArgumentException("Attribute type " + value.getClass() + " cannot be encoded as an unsigned array. Tag: " + - SAMTagUtil.makeStringTag(tag)); + SAMTag.makeStringTag(tag)); } } diff --git a/src/main/java/htsjdk/samtools/SAMBinaryTagAndValue.java b/src/main/java/htsjdk/samtools/SAMBinaryTagAndValue.java index 5a5272a199..578c7e6785 100644 --- a/src/main/java/htsjdk/samtools/SAMBinaryTagAndValue.java +++ b/src/main/java/htsjdk/samtools/SAMBinaryTagAndValue.java @@ -59,7 +59,7 @@ public SAMBinaryTagAndValue(final short tag, final Object value) { } if (!isAllowedAttributeValue(value)) { throw new IllegalArgumentException("Attribute type " + value.getClass() + " not supported. Tag: " + - SAMTagUtil.makeStringTag(tag)); + SAMTag.makeStringTag(tag)); } this.tag = tag; this.value = value; diff --git a/src/main/java/htsjdk/samtools/SAMRecord.java b/src/main/java/htsjdk/samtools/SAMRecord.java index d12a53fce7..00b5b45125 100644 --- a/src/main/java/htsjdk/samtools/SAMRecord.java +++ b/src/main/java/htsjdk/samtools/SAMRecord.java @@ -1163,7 +1163,7 @@ public boolean hasAttribute(final String tag) { * @return Appropriately typed tag value, or null if the requested tag is not present. */ public Object getAttribute(final String tag) { - return getAttribute(SAMTagUtil.makeBinaryTag(tag)); + return getAttribute(SAMTag.makeBinaryTag(tag)); } /** @@ -1197,7 +1197,7 @@ public Integer getIntegerAttribute(final String tag) { * @throws {@link htsjdk.samtools.SAMException} if the value is out of range for a 32-bit unsigned value, or not a Number */ public Long getUnsignedIntegerAttribute(final String tag) throws SAMException { - return getUnsignedIntegerAttribute(SAMTagUtil.makeBinaryTag(tag)); + return getUnsignedIntegerAttribute(SAMTag.makeBinaryTag(tag)); } /** @@ -1220,11 +1220,11 @@ public Long getUnsignedIntegerAttribute(final short tag) throws SAMException { return lValue; } else { throw new SAMException("Unsigned integer value of tag " + - SAMTagUtil.makeStringTag(tag) + " is out of bounds for a 32-bit unsigned integer: " + lValue); + SAMTag.makeStringTag(tag) + " is out of bounds for a 32-bit unsigned integer: " + lValue); } } else { throw new SAMException("Unexpected attribute value data type " + value.getClass() + " for tag " + - SAMTagUtil.makeStringTag(tag)); + SAMTag.makeStringTag(tag)); } } @@ -1375,7 +1375,7 @@ public float[] getFloatArrayAttribute(final String tag) { * @throws SAMException if the tag is not present. */ public boolean isUnsignedArrayAttribute(final String tag) { - final SAMBinaryTagAndValue tmp = this.mAttributes.find(SAMTagUtil.makeBinaryTag(tag)); + final SAMBinaryTagAndValue tmp = this.mAttributes.find(SAMTag.makeBinaryTag(tag)); if (tmp != null) return tmp.isUnsignedArray(); throw new SAMException("Tag " + tag + " is not present in this SAMRecord"); } @@ -1420,7 +1420,7 @@ public Object getAttribute(final short tag) { * String values are not validated to ensure that they conform to SAM spec. */ public void setAttribute(final String tag, final Object value) { - setAttribute(SAMTagUtil.makeBinaryTag(tag), value); + setAttribute(SAMTag.makeBinaryTag(tag), value); } /** @@ -1436,7 +1436,7 @@ public void setUnsignedArrayAttribute(final String tag, final Object value) { if (Array.getLength(value) == 0) { throw new IllegalArgumentException("Empty array passed to setUnsignedArrayAttribute for tag " + tag); } - setAttribute(SAMTagUtil.makeBinaryTag(tag), value, true); + setAttribute(SAMTag.makeBinaryTag(tag), value, true); } /** @@ -1557,7 +1557,7 @@ public List getAttributes() { SAMBinaryTagAndValue binaryAttributes = getBinaryAttributes(); final List ret = new ArrayList<>(); while (binaryAttributes != null) { - ret.add(new SAMTagAndValue(SAMTagUtil.makeStringTag(binaryAttributes.tag), + ret.add(new SAMTagAndValue(SAMTag.makeStringTag(binaryAttributes.tag), binaryAttributes.value)); binaryAttributes = binaryAttributes.getNext(); } @@ -1771,7 +1771,7 @@ private void addField(final StringBuilder buffer, final String field) { } private static String formatTagValue(final short tag, final Object value) { - final String tagString = SAMTagUtil.makeStringTag(tag); + final String tagString = SAMTag.makeStringTag(tag); if (value == null || value instanceof String) { return tagString + ":Z:" + value; } else if (value instanceof Integer || value instanceof Long || diff --git a/src/main/java/htsjdk/samtools/SAMTag.java b/src/main/java/htsjdk/samtools/SAMTag.java index f5f328042a..1ea8b88239 100644 --- a/src/main/java/htsjdk/samtools/SAMTag.java +++ b/src/main/java/htsjdk/samtools/SAMTag.java @@ -23,6 +23,8 @@ */ package htsjdk.samtools; +import htsjdk.samtools.util.StringUtil; + /** * The standard tags for a SAM record that are defined in the SAM spec. */ @@ -105,7 +107,11 @@ public enum SAMTag { U2, UQ; - private final short shortValue = SAMTag.makeBinaryTag(this.name());; + // Cache of already-converted tags. Should speed up SAM text generation. + // Not synchronized because race condition is not a problem. + private static final String[] stringTags = new String[Short.MAX_VALUE]; + + private final short shortValue = SAMTag.makeBinaryTag(this.name()); /** * Convert from String representation of tag name to short representation. @@ -113,16 +119,34 @@ public enum SAMTag { * @param tag 2-character String representation of a tag name. * @return Tag name packed as 2 ASCII bytes in a short. */ - static short makeBinaryTag(String tag) { + public static short makeBinaryTag(String tag) { if (tag.length() != 2) { throw new IllegalArgumentException("String tag does not have length() == 2: " + tag); } return (short)(tag.charAt(1) << 8 | tag.charAt(0)); } + /** + * Convert from short representation of tag name to String representation. + * + * @param tag Tag name packed as 2 ASCII bytes in a short. + * @return 2-character String representation of a tag name. + */ + public static String makeStringTag(final short tag) { + String ret = stringTags[tag]; + if (ret == null) { + final byte[] stringConversionBuf = new byte[2]; + stringConversionBuf[0] = (byte)(tag & 0xff); + stringConversionBuf[1] = (byte)((tag >> 8) & 0xff); + ret = StringUtil.bytesToString(stringConversionBuf); + stringTags[tag] = ret; + } + return ret; + } + /** * Get the binary representation of this tag name. - * @see SAMTagUtil#makeBinaryTag(String) + * @see #makeBinaryTag(String) * * @return the binary representation of this tag name */ diff --git a/src/main/java/htsjdk/samtools/SAMTagUtil.java b/src/main/java/htsjdk/samtools/SAMTagUtil.java index cf0a3c10d5..b23a735844 100644 --- a/src/main/java/htsjdk/samtools/SAMTagUtil.java +++ b/src/main/java/htsjdk/samtools/SAMTagUtil.java @@ -27,108 +27,147 @@ /** * Facility for converting between String and short representation of a SAM tag. short representation - * is used by SAM JDK internally and is much more efficient. Callers are encouraged to obtain the short + * is used by HTSJDK internally and is much more efficient. Callers are encouraged to obtain the short * value for a tag of interest once, and then use the SAMRecord attribute API that takes shorts rather than * Strings. * + * Tags that are defined by the SAM spec are included in the enum {@link SAMTag} along with their precomputed short tag. + * * @author alecw@broadinstitute.org + * @deprecated as of 11/2018, the functions in this class have been absorbed by the {@link SAMTag} enum. */ -public final class SAMTagUtil { - - /** - * @deprecated This constructor is public despite being a utility class for backwards compatibility reasons. - */ - @Deprecated - public SAMTagUtil(){} +@Deprecated +public class SAMTagUtil { - // Standard tags pre-computed for convenience - public static final short AM = SAMTag.AM.getBinaryTag(); - public static final short AS = SAMTag.AS.getBinaryTag(); - public static final short BC = SAMTag.BC.getBinaryTag(); - public static final short BQ = SAMTag.BQ.getBinaryTag(); - public static final short BZ = SAMTag.BZ.getBinaryTag(); - public static final short CB = SAMTag.CB.getBinaryTag(); - public static final short CC = SAMTag.CC.getBinaryTag(); - public static final short CG = SAMTag.CG.getBinaryTag(); - public static final short CM = SAMTag.CM.getBinaryTag(); - public static final short CO = SAMTag.CO.getBinaryTag(); - public static final short CP = SAMTag.CP.getBinaryTag(); - public static final short CQ = SAMTag.CQ.getBinaryTag(); - public static final short CR = SAMTag.CR.getBinaryTag(); - public static final short CS = SAMTag.CS.getBinaryTag(); - public static final short CT = SAMTag.CT.getBinaryTag(); - public static final short CY = SAMTag.CY.getBinaryTag(); - public static final short E2 = SAMTag.E2.getBinaryTag(); - public static final short FI = SAMTag.FI.getBinaryTag(); - public static final short FS = SAMTag.FS.getBinaryTag(); - public static final short FT = SAMTag.FT.getBinaryTag(); - public static final short FZ = SAMTag.FZ.getBinaryTag(); - /** @deprecated reserved tag for backwards compatibility only */ - @Deprecated - public static final short GC = SAMTag.GC.getBinaryTag(); - /** @deprecated reserved tag for backwards compatibility only */ - @Deprecated - public static final short GS = SAMTag.GS.getBinaryTag(); - /** @deprecated reserved tag for backwards compatibility only */ - @Deprecated - public static final short GQ = SAMTag.GQ.getBinaryTag(); - public static final short LB = SAMTag.LB.getBinaryTag(); - public static final short H0 = SAMTag.H0.getBinaryTag(); - public static final short H1 = SAMTag.H1.getBinaryTag(); - public static final short H2 = SAMTag.H2.getBinaryTag(); - public static final short HI = SAMTag.HI.getBinaryTag(); - public static final short IH = SAMTag.IH.getBinaryTag(); - public static final short MC = SAMTag.MC.getBinaryTag(); - /** @deprecated reserved tag for backwards compatibility only */ - @Deprecated - public static final short MF = SAMTag.MF.getBinaryTag(); - public static final short MI = SAMTag.MI.getBinaryTag(); - public static final short MD = SAMTag.MD.getBinaryTag(); - public static final short MQ = SAMTag.MQ.getBinaryTag(); - public static final short NH = SAMTag.NH.getBinaryTag(); - public static final short NM = SAMTag.NM.getBinaryTag(); - public static final short OQ = SAMTag.OQ.getBinaryTag(); - public static final short OP = SAMTag.OP.getBinaryTag(); - public static final short OC = SAMTag.OC.getBinaryTag(); - public static final short OF = SAMTag.OF.getBinaryTag(); - public static final short OR = SAMTag.OR.getBinaryTag(); - public static final short OX = SAMTag.OX.getBinaryTag(); - public static final short PG = SAMTag.PG.getBinaryTag(); - public static final short PQ = SAMTag.PQ.getBinaryTag(); - public static final short PT = SAMTag.PT.getBinaryTag(); - public static final short PU = SAMTag.PU.getBinaryTag(); - public static final short QT = SAMTag.QT.getBinaryTag(); - public static final short Q2 = SAMTag.Q2.getBinaryTag(); - public static final short QX = SAMTag.QX.getBinaryTag(); - public static final short R2 = SAMTag.R2.getBinaryTag(); - public static final short RG = SAMTag.RG.getBinaryTag(); - /** @deprecated use BC instead */ - @Deprecated - public static final short RT = SAMTag.RT.getBinaryTag(); - public static final short RX = SAMTag.RX.getBinaryTag(); - /** @deprecated reserved tag for backwards compatibility only */ - @Deprecated - public static final short S2 = SAMTag.S2.getBinaryTag(); - public static final short SA = SAMTag.SA.getBinaryTag(); - public static final short SM = SAMTag.SM.getBinaryTag(); - /** @deprecated reserved tag for backwards compatibility only */ - @Deprecated - public static final short SQ = SAMTag.SQ.getBinaryTag(); - public static final short TC = SAMTag.TC.getBinaryTag(); - public static final short U2 = SAMTag.U2.getBinaryTag(); - public static final short UQ = SAMTag.UQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short AM = SAMTag.AM.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short AS = SAMTag.AS.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short BC = SAMTag.BC.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short BQ = SAMTag.BQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short BZ = SAMTag.BZ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CB = SAMTag.CB.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CC = SAMTag.CC.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CG = SAMTag.CG.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CM = SAMTag.CM.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CO = SAMTag.CO.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CP = SAMTag.CP.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CQ = SAMTag.CQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CR = SAMTag.CR.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CS = SAMTag.CS.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CT = SAMTag.CT.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short CY = SAMTag.CY.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short E2 = SAMTag.E2.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short FI = SAMTag.FI.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short FS = SAMTag.FS.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short FT = SAMTag.FT.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short FZ = SAMTag.FZ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short GC = SAMTag.GC.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short GS = SAMTag.GS.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short GQ = SAMTag.GQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short LB = SAMTag.LB.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short H0 = SAMTag.H0.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short H1 = SAMTag.H1.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short H2 = SAMTag.H2.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short HI = SAMTag.HI.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short IH = SAMTag.IH.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short MC = SAMTag.MC.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short MF = SAMTag.MF.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short MI = SAMTag.MI.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short MD = SAMTag.MD.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short MQ = SAMTag.MQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short NH = SAMTag.NH.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short NM = SAMTag.NM.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short OQ = SAMTag.OQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short OP = SAMTag.OP.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short OC = SAMTag.OC.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short OF = SAMTag.OF.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short OR = SAMTag.OR.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short OX = SAMTag.OX.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short PG = SAMTag.PG.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short PQ = SAMTag.PQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short PT = SAMTag.PT.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short PU = SAMTag.PU.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short QT = SAMTag.QT.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short Q2 = SAMTag.Q2.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short QX = SAMTag.QX.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short R2 = SAMTag.R2.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short RG = SAMTag.RG.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short RT = SAMTag.RT.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short RX = SAMTag.RX.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short S2 = SAMTag.S2.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short SA = SAMTag.SA.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short SM = SAMTag.SM.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short SQ = SAMTag.SQ.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short TC = SAMTag.TC.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short U2 = SAMTag.U2.getBinaryTag(); + /** @deprecated use {@link SAMTag#getBinaryTag()} instead. */ + @Deprecated public final short UQ = SAMTag.UQ.getBinaryTag(); - @Deprecated private static final SAMTagUtil SINGLETON = new SAMTagUtil(); - // Cache of already-converted tags. Should speed up SAM text generation. - // Not synchronized because race condition is not a problem. - private static final String[] stringTags = new String[Short.MAX_VALUE]; - /** * Despite the fact that this class has state, it should be thread-safe because the cache * gets filled with the same values by any thread. - * @deprecated All methods on this class have been made static, use them directly + * @deprecated use the static methods in {@link SAMTag} instead */ @Deprecated public static SAMTagUtil getSingleton() { @@ -140,8 +179,10 @@ public static SAMTagUtil getSingleton() { * * @param tag 2-character String representation of a tag name. * @return Tag name packed as 2 ASCII bytes in a short. + * @deprecated use {@link SAMTag#makeBinaryTag(String) instead} */ - public static short makeBinaryTag(final String tag) { + @Deprecated + public short makeBinaryTag(final String tag) { return SAMTag.makeBinaryTag(tag); } @@ -150,16 +191,10 @@ public static short makeBinaryTag(final String tag) { * * @param tag Tag name packed as 2 ASCII bytes in a short. * @return 2-character String representation of a tag name. + * @deprecated use {@link SAMTag#makeStringTag(short)} instead */ - public static String makeStringTag(final short tag) { - String ret = stringTags[tag]; - if (ret == null) { - final byte[] stringConversionBuf = new byte[2]; - stringConversionBuf[0] = (byte)(tag & 0xff); - stringConversionBuf[1] = (byte)((tag >> 8) & 0xff); - ret = StringUtil.bytesToString(stringConversionBuf); - stringTags[tag] = ret; - } - return ret; + @Deprecated + public String makeStringTag(final short tag) { + return SAMTag.makeStringTag(tag); } } diff --git a/src/main/java/htsjdk/samtools/SAMTextWriter.java b/src/main/java/htsjdk/samtools/SAMTextWriter.java index ac7eaa6af4..bf54e773d0 100644 --- a/src/main/java/htsjdk/samtools/SAMTextWriter.java +++ b/src/main/java/htsjdk/samtools/SAMTextWriter.java @@ -157,9 +157,9 @@ public void writeAlignment(final SAMRecord alignment) { out.write(FIELD_SEPARATOR); final String encodedTag; if (attribute.isUnsignedArray()) { - encodedTag = tagCodec.encodeUnsignedArray(SAMTagUtil.makeStringTag(attribute.tag), attribute.value); + encodedTag = tagCodec.encodeUnsignedArray(SAMTag.makeStringTag(attribute.tag), attribute.value); } else { - encodedTag = tagCodec.encode(SAMTagUtil.makeStringTag(attribute.tag), attribute.value); + encodedTag = tagCodec.encode(SAMTag.makeStringTag(attribute.tag), attribute.value); } out.write(encodedTag); attribute = attribute.getNext(); diff --git a/src/main/java/htsjdk/samtools/cram/digest/ContentDigests.java b/src/main/java/htsjdk/samtools/cram/digest/ContentDigests.java index 00a34b8961..6b4a340bec 100644 --- a/src/main/java/htsjdk/samtools/cram/digest/ContentDigests.java +++ b/src/main/java/htsjdk/samtools/cram/digest/ContentDigests.java @@ -2,7 +2,7 @@ import htsjdk.samtools.SAMBinaryTagAndValue; import htsjdk.samtools.SAMRecord; -import htsjdk.samtools.SAMTagUtil; +import htsjdk.samtools.SAMTag; import htsjdk.samtools.cram.structure.CramCompressionRecord; import htsjdk.samtools.util.Log; @@ -33,7 +33,7 @@ public static ContentDigests create(final SAMBinaryTagAndValue binaryTags) { final List digesters = new LinkedList(); SAMBinaryTagAndValue binaryTag = binaryTags; while (binaryTag != null) { - final String tagID = SAMTagUtil.makeStringTag( + final String tagID = SAMTag.makeStringTag( binaryTag.tag); final KNOWN_DIGESTS hash; try { @@ -131,7 +131,7 @@ private static class Digester { this.digest = digest; this.series = series; this.tagID = tagID; - this.tagCode = SAMTagUtil.makeBinaryTag(tagID); + this.tagCode = SAMTag.makeBinaryTag(tagID); } void add(final SAMRecord record) { diff --git a/src/main/java/htsjdk/samtools/cram/structure/ReadTag.java b/src/main/java/htsjdk/samtools/cram/structure/ReadTag.java index 3704e6bafb..0bbe117869 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/ReadTag.java +++ b/src/main/java/htsjdk/samtools/cram/structure/ReadTag.java @@ -17,14 +17,8 @@ */ package htsjdk.samtools.cram.structure; -import htsjdk.samtools.SAMException; -import htsjdk.samtools.SAMFormatException; +import htsjdk.samtools.*; import htsjdk.samtools.SAMRecord.SAMTagAndValue; -import htsjdk.samtools.SAMTagUtil; -import htsjdk.samtools.SAMUtils; -import htsjdk.samtools.SAMValidationError; -import htsjdk.samtools.TagValueAndUnsignedArrayFlag; -import htsjdk.samtools.ValidationStringency; import htsjdk.samtools.util.StringUtil; import java.nio.ByteBuffer; @@ -62,7 +56,7 @@ public ReadTag(final int id, final byte[] dataAsByteArray, ValidationStringency keyType3BytesAsInt = id; - code = SAMTagUtil.makeBinaryTag(this.key); + code = SAMTag.makeBinaryTag(this.key); } private ReadTag(final String key, final char type, final Object value) { @@ -86,7 +80,7 @@ private ReadTag(final String key, final char type, final Object value) { keyType3Bytes = this.key + this.type; keyType3BytesAsInt = nameType3BytesToInt(this.key, this.type); - code = SAMTagUtil.makeBinaryTag(this.key); + code = SAMTag.makeBinaryTag(this.key); } public static int name3BytesToInt(final byte[] name) { diff --git a/src/main/java/htsjdk/samtools/cram/structure/Slice.java b/src/main/java/htsjdk/samtools/cram/structure/Slice.java index 2df2130e42..a68a5c19bc 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/Slice.java +++ b/src/main/java/htsjdk/samtools/cram/structure/Slice.java @@ -185,7 +185,7 @@ public void setRefMD5(final byte[] ref) { /** * Get tag value attached to the slice. - * @param tag tag ID as a short integer as returned by {@link htsjdk.samtools.SAMTagUtil#makeBinaryTag(java.lang.String)} + * @param tag tag ID as a short integer as returned by {@link SAMTag#makeBinaryTag(String)} * @return a value of the tag */ public Object getAttribute(final short tag) { @@ -199,14 +199,14 @@ public Object getAttribute(final short tag) { /** * Set a value for the tag. - * @param tag tag ID as a short integer as returned by {@link htsjdk.samtools.SAMTagUtil#makeBinaryTag(java.lang.String)} + * @param tag tag ID as a short integer as returned by {@link SAMTag#makeBinaryTag(String)} * @param value tag value */ public void setAttribute(final String tag, final Object value) { if (value != null && value.getClass().isArray() && Array.getLength(value) == 0) { throw new IllegalArgumentException("Empty value passed for tag " + tag); } - setAttribute(SAMTagUtil.makeBinaryTag(tag), value); + setAttribute(SAMTag.makeBinaryTag(tag), value); } public void setUnsignedArrayAttribute(final String tag, final Object value) { @@ -216,7 +216,7 @@ public void setUnsignedArrayAttribute(final String tag, final Object value) { if (Array.getLength(value) == 0) { throw new IllegalArgumentException("Empty array passed to setUnsignedArrayAttribute for tag " + tag); } - setAttribute(SAMTagUtil.makeBinaryTag(tag), value, true); + setAttribute(SAMTag.makeBinaryTag(tag), value, true); } void setAttribute(final short tag, final Object value) { diff --git a/src/main/java/htsjdk/samtools/cram/structure/SliceIO.java b/src/main/java/htsjdk/samtools/cram/structure/SliceIO.java index 9872e12bd1..c5958209a8 100644 --- a/src/main/java/htsjdk/samtools/cram/structure/SliceIO.java +++ b/src/main/java/htsjdk/samtools/cram/structure/SliceIO.java @@ -17,10 +17,7 @@ */ package htsjdk.samtools.cram.structure; -import htsjdk.samtools.BinaryTagCodec; -import htsjdk.samtools.SAMBinaryTagAndValue; -import htsjdk.samtools.SAMTagUtil; -import htsjdk.samtools.ValidationStringency; +import htsjdk.samtools.*; import htsjdk.samtools.cram.common.CramVersions; import htsjdk.samtools.cram.io.CramIntArray; import htsjdk.samtools.cram.io.ITF8; @@ -66,7 +63,7 @@ private static void parseSliceHeaderBlock(final int major, final Slice slice) th SAMBinaryTagAndValue tags = slice.sliceTags; while (tags != null) { - log.debug(String.format("Found slice tag: %s", SAMTagUtil.makeStringTag(tags.tag))); + log.debug(String.format("Found slice tag: %s", SAMTag.makeStringTag(tags.tag))); tags = tags.getNext(); } } @@ -95,7 +92,7 @@ private static byte[] createSliceHeaderBlockContent(final int major, final Slice final BinaryTagCodec binaryTagCodec = new BinaryTagCodec(binaryCoded); SAMBinaryTagAndValue samBinaryTagAndValue = slice.sliceTags; do { - log.debug("Writing slice tag: " + SAMTagUtil.makeStringTag(samBinaryTagAndValue.tag)); + log.debug("Writing slice tag: " + SAMTag.makeStringTag(samBinaryTagAndValue.tag)); binaryTagCodec.writeTag(samBinaryTagAndValue.tag, samBinaryTagAndValue.value, samBinaryTagAndValue.isUnsignedArray()); } while ((samBinaryTagAndValue = samBinaryTagAndValue.getNext()) != null); // BinaryCodec doesn't seem to cache things. diff --git a/src/main/java/htsjdk/samtools/sra/SRALazyRecord.java b/src/main/java/htsjdk/samtools/sra/SRALazyRecord.java index fb8dbdd802..418ee3af2f 100644 --- a/src/main/java/htsjdk/samtools/sra/SRALazyRecord.java +++ b/src/main/java/htsjdk/samtools/sra/SRALazyRecord.java @@ -667,7 +667,7 @@ protected SAMBinaryTagAndValue getBinaryAttributes() { @Override public boolean isUnsignedArrayAttribute(final String tag) { - Short binaryTag = SAMTagUtil.makeBinaryTag(tag); + Short binaryTag = SAMTag.makeBinaryTag(tag); LazyAttribute attr = lazyAttributeTags.get(binaryTag); if (attr != null && !initializedAttributes.contains(attr)) { getAttribute(binaryTag); diff --git a/src/test/java/htsjdk/samtools/SAMBinaryTagAndValueUnitTest.java b/src/test/java/htsjdk/samtools/SAMBinaryTagAndValueUnitTest.java index 7db32da8f5..06e41ee195 100644 --- a/src/test/java/htsjdk/samtools/SAMBinaryTagAndValueUnitTest.java +++ b/src/test/java/htsjdk/samtools/SAMBinaryTagAndValueUnitTest.java @@ -39,7 +39,7 @@ public void test_isAllowedAttribute(final Object value) { @Test(dataProvider="allowedAttributeTypes") public void test_isAllowedConstructor(final Object value) { - Assert.assertNotNull(new SAMBinaryTagAndValue(SAMTagUtil.makeBinaryTag("UI"), value)); + Assert.assertNotNull(new SAMBinaryTagAndValue(SAMTag.makeBinaryTag("UI"), value)); } @DataProvider(name="notAllowedAttributeTypes") @@ -61,7 +61,7 @@ public void test_isNotAllowedAttribute(final Object value) { @Test(dataProvider="notAllowedAttributeTypes", expectedExceptions=IllegalArgumentException.class) public void test_isNotAllowedConstructor(final Object value) { - new SAMBinaryTagAndValue(SAMTagUtil.makeBinaryTag("ZZ"), value); + new SAMBinaryTagAndValue(SAMTag.makeBinaryTag("ZZ"), value); } @DataProvider(name="allowedUnsignedArrayTypes") @@ -75,7 +75,7 @@ public Object[][] allowedUnsignedArrayTypes() { @Test(dataProvider="allowedUnsignedArrayTypes") public void test_isAllowedUnsignedArrayAttribute(final Object value) { - final short binaryTag = SAMTagUtil.makeBinaryTag("UI"); + final short binaryTag = SAMTag.makeBinaryTag("UI"); Assert.assertNotNull(new SAMBinaryTagAndUnsignedArrayValue(binaryTag, value)); } @@ -89,13 +89,13 @@ public Object[][] notAllowedUnsignedArrayTypes() { @Test(dataProvider="notAllowedUnsignedArrayTypes", expectedExceptions=IllegalArgumentException.class) public void test_isNotAllowedUnsignedArrayAttribute(final Object value) { - final short binaryTag = SAMTagUtil.makeBinaryTag("UI"); + final short binaryTag = SAMTag.makeBinaryTag("UI"); new SAMBinaryTagAndUnsignedArrayValue(binaryTag, value); } @DataProvider(name="hashCopyEquals") public Object[][] hashCopyEquals() { - final short tag = SAMTagUtil.makeBinaryTag("UI"); + final short tag = SAMTag.makeBinaryTag("UI"); return new Object[][] { {new SAMBinaryTagAndValue(tag, new String("a string")), new SAMBinaryTagAndValue(tag, new String("a string")), true, true}, {new SAMBinaryTagAndValue(tag, new String("a string")), new SAMBinaryTagAndValue(tag, new String("different string")), false, false}, diff --git a/src/test/java/htsjdk/samtools/SAMRecordUnitTest.java b/src/test/java/htsjdk/samtools/SAMRecordUnitTest.java index 5231a0e05b..f4757d56d7 100644 --- a/src/test/java/htsjdk/samtools/SAMRecordUnitTest.java +++ b/src/test/java/htsjdk/samtools/SAMRecordUnitTest.java @@ -335,7 +335,7 @@ private SAMRecord testDeepCopy(SAMRecord sam) { @Test public void test_getUnsignedIntegerAttribute_valid() { final String stringTag = "UI"; - final short binaryTag = SAMTagUtil.makeBinaryTag(stringTag); + final short binaryTag = SAMTag.makeBinaryTag(stringTag); SAMFileHeader header = new SAMFileHeader(); SAMRecord record = new SAMRecord(header); Assert.assertNull(record.getUnsignedIntegerAttribute(stringTag)); @@ -374,7 +374,7 @@ record = new SAMRecord(header){ */ @Test public void test_getUnsignedIntegerAttribute_valid_alternative() { - final short tag = SAMTagUtil.makeBinaryTag("UI"); + final short tag = SAMTag.makeBinaryTag("UI"); SAMFileHeader header = new SAMFileHeader(); SAMRecord record; @@ -457,7 +457,7 @@ public void test_setAttribute_unsigned_int_tooLarge() { @Test public void test_setAttribute_null_removes_tag() { - final short tag = SAMTagUtil.makeBinaryTag("UI"); + final short tag = SAMTag.makeBinaryTag("UI"); SAMFileHeader header = new SAMFileHeader(); SAMRecord record = new SAMRecord(header); Assert.assertNull(record.getUnsignedIntegerAttribute(tag));