集册 Java实例教程 确定核苷酸序列中某一部分的倒序。

确定核苷酸序列中某一部分的倒序。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

571
确定核苷酸序列中某一部分的倒序。
/** 来自 nowjava.com**/

/*

 **  DNAUtils

 **  (c) Copyright 1997, Neomorphic Sofware, Inc.

 **  All Rights Reserved

 **

 **  CONFIDENTIAL

 **  DO NOT DISTRIBUTE

 **

 **  File: DNAUtils.java

 **

 */

//package com.nowjava;


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;/** N o w J a v a . c o m 提供 **/

        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, 
展开阅读全文