集册 Java实例教程 确定核苷酸序列的反补体。

确定核苷酸序列的反补体。

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

495
确定核苷酸序列的反补体。

/*

 **  DNAUtils

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

 **  All Rights Reserved

 **

 **  CONFIDENTIAL

 **  DO NOT DISTRIBUTE

 **

 **  File: DNAUtils.java

 **

 */

import java.util.List;

import java.util.ArrayList;

/** from 
N o w J a v a . c o m**/

public class Main{

    /**

     * determines the reverse complement of a sequence of nucleotides.

     *

     * @param s a string of nucleotide codes.

     * @return the complementary codes in reverse order.

     */

    public static String reverseComplement(String s) {

        if (s == null) {

            return null;

        }

        StringBuffer buf = new StringBuffer(s.length());

        int j = 0;

        for (int i = s.length() - 1; i >= 0; i--) {

            buf.append(s.charAt(i));
            /*
            来 自*
             时代Java - nowjava.com
            */

            j++;

        }

        complementBuffer(buf);

        return buf.toString();

    }

    /**

     * determines the complement of a sequence of nucleotides.

     *

     * @param buf a string of nucleotide codes

     *            each of which is replaced

     *            with it's complementary code.

     * @see #complement

     */

    protected static void complementBuffer(StringBuffer buf) {

        char base;

        for (int i = 0; i < buf.length(); i++) {

            base = buf.charAt(i);

            buf.setCharAt(i, complement(base));

        }

    }

    /**

     * determines the complement of a sequence of nucleotides.

     *

     * @param s a string of nucleotide codes.

     * @return the complementary codes.

     */

    public static String complement(String s) {

        if (s == null) {

            return null;

        }

        StringBuffer buf = new StringBuffer(s);

        DNAUtils.complementBuffer(buf);

        return buf.toString();

    }

    /**

     * determines the complement of a nucleotide

     * 

     * @param base a character reperesenting a nucleotide

     * @return the character which represents the complement to the input base

     */

    public static char complement(char base) {

        char complement = base;

        if (base == 'a') {

            complement = 't';

        } else if (base == 'c') {

            complement = 'g';

        } else if (base == 'g') {

            complement = 'c';

        } else if (base == 't') {

            complement = 'a';

        } else if (base == 'A') {

            complement = 'T';

        } else if (base == 'C') {

            complement = 'G';

        } else 
展开阅读全文