Home > other >  encoding binary to DNA sequencing in java
encoding binary to DNA sequencing in java

Time:08-10

strong textI would like to encode binary sequence to DNA sequence by truth table : 00=A 01=C 10=G 11=T For example:11000110=``TACG By using java, and I haven't Does someone can help me PLEASE ?

my code that half I have done String ddna=" ";

    Dictionary phoneBook = new Hashtable();//creating dictionary in java we can use hashtable

    // put() method
    phoneBook.put("00", "A");
    phoneBook.put("01", "G");
    phoneBook.put("10", "C");
    phoneBook.put("11", "T");

CodePudding user response:

If your table is fixed you can simply use if statements to determine the correct letter like this:

public static String convert(String input) {
    if (input.length() % 2 == 1) {
        return "";
    }

    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < input.length(); i  = 2) {
        if (input.charAt(i) == '0') {
            if (input.charAt(i   1) == '0') {
                sb.append("A");
            } else {
                sb.append("G");
            }
        } else {
            if (input.charAt(i   1) == '0') {
                sb.append("C");
            } else {
                sb.append("T");
            }
        }
    }

    return sb.toString();
}

CodePudding user response:

Because it is an other field:

/**
 * @param length in "letters"
 */
String dna(byte[] data, int length) {
    if (data.length * 4 < length || length < 0) {
        throw new IllegalArgumentException("Insufficient data ("
              (data.length * 4)   " for length "   length);
    }
    StringBuilder sb = new StringBuilder(length);
    int byteI = -1;
    int b;
    for (int i = 0; i < length;   i) {
        int j = i % 4;
        if (j == 0) {
              byteI;
            b = (int) date[byteI];
        }
        int n = (b >> (6 - 2*j)) & 3;
        sb,append("AGCT".charAt(n));
    } 
    return sb.toString();
}
  •  Tags:  
  • java
  • Related