Java examples for Data Structure:DNA
determines the reverse of a part of a sequence of nucleotides.
/*/*from ww w . j a va 2 s. c o m*/ ** DNAUtils ** (c) Copyright 1997, Neomorphic Sofware, Inc. ** All Rights Reserved ** ** CONFIDENTIAL ** DO NOT DISTRIBUTE ** ** File: DNAUtils.java ** */ //package com.java2s; public class Main { /** * determines the reverse of a part of a sequence of nucleotides. * * @param s a string of nucleotide codes. * @param offset the number of characters to skip * at the beginning of s. * @param chunk_size the number of characters in the portion * to be reversed * @return the codes of the specified chunk, in reverse order. */ public static String chunkReverse(String s, int offset, int chunk_size) { if (s == null) { return null; } int reverse_offset = (s.length() - offset) % chunk_size; // System.out.println(reverse_offset); StringBuffer buf = new StringBuffer(s.length()); for (int i = 0; i < reverse_offset; i++) { buf.append(' '); } int max = s.length() - reverse_offset - chunk_size; // System.out.println("Max: " + max); String chunk; for (int i = max; i >= 0; i -= chunk_size) { // System.out.println(i + ", " + chunk_size); // chunk = s.substring(i-chunk_size+1, i+1); chunk = s.substring(i, i + chunk_size); buf.append(chunk); } int end_spaces = s.length() - buf.length(); for (int i = 0; i < end_spaces; i++) { buf.append(' '); } return buf.toString(); } }