确定核苷酸序列的补体。
/* ** DNAUtils ** (c) Copyright 1997, Neomorphic Sofware, Inc. ** All Rights Reserved ** ** CONFIDENTIAL ** DO NOT DISTRIBUTE ** ** File: DNAUtils.java ** */ import java.util.List;/**来 自 N o w J a v a . c o m - 时 代 Java**/ import java.util.ArrayList; public class Main{ /** * 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();/* 来 自 NowJava.com - 时 代 Java*/ } /** * 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 if (base == 'G') { complement = 'C'; }