Convert an array of bytes, in which each byte is a binary phred quality score, to printable ASCII representation of the quality scores. - Java Data Structure

Java examples for Data Structure:DNA

Description

Convert an array of bytes, in which each byte is a binary phred quality score, to printable ASCII representation of the quality scores.

Demo Code

/*//from  w ww  .  j a v  a 2s . c om
 * Copyright (c) 2014. Real Time Genomics Limited.
 *
 * Use of this source code is bound by the Real Time Genomics Limited Software Licence Agreement
 * for Academic Non-commercial Research Purposes only.
 *
 * If you did not receive a license accompanying this file, a copy must first be obtained by email
 * from support@realtimegenomics.com.  On downloading, using and/or continuing to use this source
 * code you accept the terms of that license agreement and any amendments to those terms that may
 * be made from time to time by Real Time Genomics Limited.
 */
//package com.java2s;

public class Main {
    /**
     * Convert an array of bytes, in which each byte is a binary phred quality
     * score, to printable ASCII representation of the quality scores.
     * @param buffer Array of bytes in which each byte is a binary phred score.
     * @param offset Where in buffer to start conversion.
     * @param length How many bytes of buffer to convert.
     * @param reverse if the binary phred score is to be reversed
     * @return String with ASCII representation of those quality scores.
     */
    public static String phredToFastq(final byte[] buffer,
            final int offset, final int length, final boolean reverse) {
        final char[] chars = new char[length];
        for (int i = 0; i < length; i++) {
            chars[reverse ? length - i - 1 : i] = (char) ((buffer[offset
                    + i]) + 33);
        }
        return new String(chars);
    }
}

Related Tutorials