Class 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 Detail

      • BASES_SIZE

        public static final int BASES_SIZE
    • Constructor Detail

      • 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 Detail

      • 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