Java ASCII to Binary asciiToRawQuality(char quality)

Here you can find the source of asciiToRawQuality(char quality)

Description

ascii To Raw Quality

License

Open Source License

Parameter

Parameter Description
quality the ASCII quality value

Return

the raw quality value corresponding to the ASCII quality value

Declaration

public static byte asciiToRawQuality(char quality) 

Method Source Code

//package com.java2s;

public class Main {
    /** ASCII PHRED lowest allowed value */
    public static final int PHRED_LOWER_LIMIT_CHAR = '!';

    /**//  w w  w.j av  a  2s.co  m
     * @param quality the ASCII quality value
     * @return the raw quality value corresponding to the ASCII quality value
     */
    public static byte asciiToRawQuality(char quality) {
        return (byte) (quality - PHRED_LOWER_LIMIT_CHAR);
    }

    /**
     * @param qualities the ASCII quality values
     * @return the raw quality values corresponding to the ASCII quality values
     */
    public static byte[] asciiToRawQuality(CharSequence qualities) {
        if (qualities == null) {
            return null;
        }
        return asciiToRawQuality(qualities, 0, qualities.length());
    }

    /**
     * @param qualities the ASCII quality values
     * @param offset Where in buffer to start conversion.
     * @param length the number of bytes from the input buffer to convert
     * @return the raw quality values corresponding to the ASCII quality values
     */
    public static byte[] asciiToRawQuality(CharSequence qualities, int offset, int length) {
        if (qualities == null) {
            return null;
        }
        final byte[] result = new byte[length];
        for (int j = offset, i = 0; i < result.length; i++, j++) {
            result[i] = asciiToRawQuality(qualities.charAt(j));
        }
        return result;
    }

    /**
     * @param qualities the ASCII quality values
     * @return the raw quality values corresponding to the ASCII quality values
     */
    public static byte[] asciiToRawQuality(char[] qualities) {
        if (qualities == null) {
            return null;
        }
        final byte[] result = new byte[qualities.length];
        for (int i = 0; i < qualities.length; i++) {
            result[i] = asciiToRawQuality(qualities[i]);
        }
        return result;
    }

    /**
     * @param qualities the ASCII quality values
     * @return the raw quality values corresponding to the ASCII quality values
     */
    public static byte[] asciiToRawQuality(byte[] qualities) {
        if (qualities == null) {
            return null;
        }
        final byte[] result = new byte[qualities.length];
        for (int i = 0; i < qualities.length; i++) {
            result[i] = asciiToRawQuality((char) qualities[i]);
        }
        return result;
    }
}

Related

  1. ascii2bin(byte[] ascii, int offset, int len, byte[] binary)
  2. AsciiToBinary(String asciiString)