# Class SubstitutionMatrix

java.lang.Object
htsjdk.samtools.cram.structure.SubstitutionMatrix

public class SubstitutionMatrix extends Object
Substitution matrix, used to represent base substitutions for reference-based CRAM compression. The matrix is stored internally in two forms; the packed/encoded form used for serialization, and an expanded in-memory form used for fast bi-directional interconversion between bases and substitution codes during read and write. This implementation allows both upper and lower case versions of a given reference base to be substituted with the same (upper case) substitute base (except for 'N', which is only handled for upper case) although it does not *generate* substitutions for lower case reference bases.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`BASES_SIZE`

## Constructor Summary

Constructors
Constructor
Description
`SubstitutionMatrix(byte[] matrix)`
Create a SubstitutionMatrix from a serialized byte array
`SubstitutionMatrix(List<CRAMCompressionRecord> records)`
Create a SubstitutionMatrix given a list of CramCompressionRecord

## Method Summary

Modifier and Type
Method
Description
`byte`
`base(byte refBase, byte code)`
Given a reference base and a substitution code, return the corresponding substitution base.
`byte`
`code(byte refBase, byte readBase)`
Given a reference base and a read base, find the corresponding substitution code
`byte[]`
`getEncodedMatrix()`
Return this substitution matrix as a byte array in a form suitable for serialization.
`String`
`toString()`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### BASES_SIZE

public static final int BASES_SIZE

## Constructor Details

### SubstitutionMatrix

public SubstitutionMatrix(List<CRAMCompressionRecord> records)
Create a SubstitutionMatrix given a list of CramCompressionRecord

Parameters:
  `records` - array of CramCompressionRecord with Substitutions

### SubstitutionMatrix

public SubstitutionMatrix(byte[] matrix)
Create a SubstitutionMatrix from a serialized byte array

Parameters:
  `matrix` - serialized substitution matrix from a CRAM stream

## Method Details

### code

public byte code(byte refBase, byte readBase)
Given a reference base and a read base, find the corresponding substitution code

Parameters:
  `refBase` - reference base being substituted
  `readBase` - read base to substitute for the reference base
Returns:
  code to be used for this refBase/readBase pair

### base

public byte base(byte refBase, byte code)
Given a reference base and a substitution code, return the corresponding substitution base.

Parameters:
  `refBase` - reference base being substituted
  `code` - substitution code
Returns:
  base to be substituted for this (refBase, code) pair

### getEncodedMatrix

public byte[] getEncodedMatrix()
Return this substitution matrix as a byte array in a form suitable for serialization.

Returns:
  the encoded matrix in serialized form

### toString

public String toString()

Overrides:
  `toString` in class `Object`