集册 Java实例教程 返回大写的反向补体版本的DNA字符串。

返回大写的反向补体版本的DNA字符串。

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

687
返回大写的反向补体版本的DNA字符串。
/*from N o w  J a v a  .   c o m*/

//package com.nowjava;


public class Main {

    /**

     * Return the reverse complement version of a DNA string in upper case. Note that no checking is done in this code

     * since the parse code checks for valid DNA and upper-cases the input. This code will break if these assumptions

     * are not valid.

     *

     * @param sq

     *            original, upper-case cDNA string

     * @return reverse complement version of the input string sq.

     */

    public static String reverseComplement(String sq) {

        if (sq.equals("-"))

            return sq; // deletion, insertion do not need rc


        StringBuffer sb = new StringBuffer();

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

            char c = sq.charAt(i);

            char match = 0;

            switch (c) {

            case 'A':

                match = 'T';

                break;

            case 'C':/**from N o w  J a v a  . c o m**/

                match = 'G';

                break;

            case 'G':

                match = 'C';

                break;

            case 'T':

                match = 'A';

                
展开阅读全文