Class ReadTag

java.lang.Object
htsjdk.samtools.cram.structure.ReadTag
All Implemented Interfaces:
Comparable<ReadTag>

public class ReadTag extends Object implements Comparable<ReadTag>
CRAM counterpart of SAMTag.
  • Field Details

    • keyType3Bytes

      public String keyType3Bytes
    • keyType3BytesAsInt

      public int keyType3BytesAsInt
  • Constructor Details

    • ReadTag

      public ReadTag(int id, byte[] dataAsByteArray, ValidationStringency validationStringency)
      Construct a ReadTag from a 3-byte tag ID and raw value bytes.
      Parameters:
      id - the tag ID packed as an int (2 bytes tag name + 1 byte type)
      dataAsByteArray - the raw tag value bytes
      validationStringency - validation stringency for parsing
    • ReadTag

      public ReadTag(TagKeyCache.TagKeyInfo cached, byte[] dataAsByteArray, ValidationStringency validationStringency)
      Construct a ReadTag using pre-cached key metadata to avoid repeated String allocation.
      Parameters:
      cached - pre-computed key metadata from the TagKeyCache
      dataAsByteArray - the raw tag value bytes
      validationStringency - validation stringency for parsing
  • Method Details

    • name3BytesToInt

      public static int name3BytesToInt(byte[] name)
      Pack a 3-byte tag ID (2 bytes name + 1 byte type) into an int.
      Parameters:
      name - byte array of length 3 (tag name char 1, char 2, type char)
      Returns:
      the packed int representation
    • nameType3BytesToInt

      public static int nameType3BytesToInt(String name, char type)
      Pack a 2-character tag name and a type character into a 3-byte int.
      Parameters:
      name - two-character tag name (e.g. "NM")
      type - single-character type code (e.g. 'i', 'Z')
      Returns:
      the packed int representation
    • intToNameType

      public static String intToNameType(int value, boolean withColon)
      Unpack a 3-byte tag ID int into a String. If withColon is false, returns a 3-character string like "NMi"; if true, returns a 4-character string like "NM:i".
      Parameters:
      value - the packed int
      withColon - if true, insert ':' between the 2-char name and the type char
      Returns:
      unpacked tag ID string
    • intToNameType3Bytes

      public static String intToNameType3Bytes(int value)
    • intToNameType4Bytes

      public static String intToNameType4Bytes(int value)
    • createSAMTag

      public SAMRecord.SAMTagAndValue createSAMTag()
      Create a SAMRecord.SAMTagAndValue from this ReadTag's key and value.
    • deriveTypeFromKeyAndType

      public static ReadTag deriveTypeFromKeyAndType(String keyAndType, Object value)
      Create a ReadTag from a 4-character "XX:T" key-and-type string and a value.
      Parameters:
      keyAndType - 4-character string in "XX:T" format (e.g. "NM:i")
      value - the tag value
      Returns:
      a new ReadTag
    • deriveTypeFromValue

      public static ReadTag deriveTypeFromValue(String key, Object value)
      Create a ReadTag by inferring the CRAM type code from the Java type of the value.
      Parameters:
      key - two-character tag name (e.g. "NM")
      value - the tag value (String, Character, Number, or array)
      Returns:
      a new ReadTag
    • getKey

      public String getKey()
    • compareTo

      public int compareTo(ReadTag o)
      Specified by:
      compareTo in interface Comparable<ReadTag>
    • getValue

      public Object getValue()
    • getKeyAndType

      public String getKeyAndType()
    • getValueAsByteArray

      public byte[] getValueAsByteArray()
      Serialize this tag's value to a byte array using CRAM/BAM binary encoding.
    • setIndex

      public void setIndex(byte i)
    • getIndex

      public byte getIndex()
    • writeSingleValue

      public static byte[] writeSingleValue(byte tagType, Object value, boolean isUnsignedArray)
      Serialize a single tag value to a byte array in BAM binary format.
      Parameters:
      tagType - the BAM type code (e.g. 'i', 'Z', 'B')
      value - the value to serialize
      isUnsignedArray - if true and the value is an array, use unsigned array sub-type codes
      Returns:
      the serialized bytes
    • readSingleValue

      public static Object readSingleValue(byte tagType, ByteBuffer byteBuffer, ValidationStringency validationStringency)
      Read a single tag value from a ByteBuffer in BAM binary format.
      Parameters:
      tagType - the BAM type code (e.g. 'i', 'Z', 'B')
      byteBuffer - little-endian ByteBuffer positioned at the start of the value
      validationStringency - validation stringency for error handling
      Returns:
      the deserialized value as the appropriate Java type
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object