Class ReadTag
java.lang.Object
htsjdk.samtools.cram.structure.ReadTag
- All Implemented Interfaces:
Comparable<ReadTag>
CRAM counterpart of
SAMTag.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReadTag(int id, byte[] dataAsByteArray, ValidationStringency validationStringency) Construct a ReadTag from a 3-byte tag ID and raw value bytes.ReadTag(TagKeyCache.TagKeyInfo cached, byte[] dataAsByteArray, ValidationStringency validationStringency) Construct a ReadTag using pre-cached key metadata to avoid repeated String allocation. -
Method Summary
Modifier and TypeMethodDescriptionintCreate aSAMRecord.SAMTagAndValuefrom this ReadTag's key and value.static ReadTagderiveTypeFromKeyAndType(String keyAndType, Object value) Create a ReadTag from a 4-character "XX:T" key-and-type string and a value.static ReadTagderiveTypeFromValue(String key, Object value) Create a ReadTag by inferring the CRAM type code from the Java type of the value.booleanbytegetIndex()getKey()getValue()byte[]Serialize this tag's value to a byte array using CRAM/BAM binary encoding.inthashCode()static StringintToNameType(int value, boolean withColon) Unpack a 3-byte tag ID int into a String.static StringintToNameType3Bytes(int value) Shorthand forintToNameType(value, false).static StringintToNameType4Bytes(int value) Shorthand forintToNameType(value, true).static intname3BytesToInt(byte[] name) Pack a 3-byte tag ID (2 bytes name + 1 byte type) into an int.static intnameType3BytesToInt(String name, char type) Pack a 2-character tag name and a type character into a 3-byte int.static ObjectreadSingleValue(byte tagType, ByteBuffer byteBuffer, ValidationStringency validationStringency) Read a single tag value from a ByteBuffer in BAM binary format.voidsetIndex(byte i) static byte[]writeSingleValue(byte tagType, Object value, boolean isUnsignedArray) Serialize a single tag value to a byte array in BAM binary format.
-
Field Details
-
keyType3Bytes
-
keyType3BytesAsInt
public int keyType3BytesAsInt
-
-
Constructor Details
-
ReadTag
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 bytesvalidationStringency- 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 theTagKeyCachedataAsByteArray- the raw tag value bytesvalidationStringency- 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
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
Unpack a 3-byte tag ID int into a String. IfwithColonis false, returns a 3-character string like "NMi"; if true, returns a 4-character string like "NM:i".- Parameters:
value- the packed intwithColon- if true, insert ':' between the 2-char name and the type char- Returns:
- unpacked tag ID string
-
intToNameType3Bytes
Shorthand forintToNameType(value, false). -
intToNameType4Bytes
Shorthand forintToNameType(value, true). -
createSAMTag
Create aSAMRecord.SAMTagAndValuefrom this ReadTag's key and value. -
deriveTypeFromKeyAndType
-
deriveTypeFromValue
-
getKey
-
compareTo
- Specified by:
compareToin interfaceComparable<ReadTag>
-
getValue
-
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
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 serializeisUnsignedArray- 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 valuevalidationStringency- validation stringency for error handling- Returns:
- the deserialized value as the appropriate Java type
-
equals
-
hashCode
-