Java String Unpad unPad(byte[] src, int start, byte[] dest)

Here you can find the source of unPad(byte[] src, int start, byte[] dest)

Description

Strip single padding base that Complete Genomics v2 reads contain, if present.

License

Open Source License

Parameter

Parameter Description
src input data to remove padding from. May be either DNA or quality data.
start start position within the source array to begin copying from
dest destination array where unpadded data is copied

Declaration

public static void unPad(byte[] src, int start, byte[] dest) 

Method Source Code

//package com.java2s;

public class Main {
    /** Raw length of Complete Genomics v2 reads */
    public static final int CG2_RAW_READ_LENGTH = 29;
    /** Length of Complete Genomics v2 reads, when it contains the single padding N */
    public static final int CG2_PADDED_LENGTH = CG2_RAW_READ_LENGTH + 1;
    /** The position of the padding N base in padded v2 reads */
    public static final int CG2_PAD_POSITION = 19;
    private static final int CG2_PAD_POSITION_REV = 10;

    /**//from  w  ww  .j a  va  2s . c  om
     * Strip single padding base that Complete Genomics v2 reads contain, if present.
     * @param seq input data to remove padding from. May be either DNA or quality data.
     * @param forward true if the data is in the normal, forward orientation
     * @return the data with any padding removed. If the data is not v2, returns the original array.
     */
    public static byte[] unPad(byte[] seq, boolean forward) {
        if (seq != null && seq.length == CG2_PADDED_LENGTH) {
            final int pos = forward ? CG2_PAD_POSITION
                    : CG2_PAD_POSITION_REV;
            //      assert seq[pos] == 0 || seq[pos] == 'N' || seq[pos] == FastaUtils.asciiToRawQuality('!');
            final byte[] result = new byte[seq.length - 1];
            System.arraycopy(seq, 0, result, 0, pos);
            System.arraycopy(seq, pos + 1, result, pos, seq.length - pos
                    - 1);
            return result;
        } else {
            return seq;
        }
    }

    /**
     * Strip single padding base that Complete Genomics v2 reads contain, if present.
     * @param src input data to remove padding from. May be either DNA or quality data.
     * @param start start position within the source array to begin copying from
     * @param dest destination array where unpadded data is copied
     */
    public static void unPad(byte[] src, int start, byte[] dest) {
        System.arraycopy(src, start, dest, 0, CG2_PAD_POSITION);
        System.arraycopy(src, start + CG2_PAD_POSITION + 1, dest,
                CG2_PAD_POSITION, CG2_RAW_READ_LENGTH - CG2_PAD_POSITION);
    }
}

Related

  1. unPad(byte[] bytes)
  2. unPadLeft(String s, char c)
  3. unPadRight(String s, char c)
  4. unpadZeroString(String string)