Пример #1
0
  public String translate(Sequence s, GeneticCode gncode) {
    String AA = "";
    Sequence n = new Sequence();
    n.setSequence(s.getSequence().toUpperCase());
    int pos = 0;
    boolean found = false;
    // --Find start codon

    //        while(!found&&pos<n.getLen()-2) {
    //            String start=n.getSequence().substring(pos, pos+3);
    //            if (gncode.getStart_code().get(start)!=null) {
    //                AA+=""+gncode.getStart_code().get(start);
    //                pos+=3;
    //                found=true;
    //            }
    //            pos++;
    //        }
    // --return empty string if not found
    //        if (!found) {
    //            Config.log("No Start");
    //            return AA;
    //        }
    pos = start;
    // --Continue
    n.Remove(0, pos); // remove till start

    String codon = n.Remove(0, 3);
    // Config.log(n.getSequence());
    while (!codon.isEmpty() && n.getLen() > 0) {
      // Config.log(codon+" "+gncode.getCode().get(codon));
      String aa = gncode.getCode().get(codon);
      // Config.log(aa);
      if (aa != null) {
        AA += aa;
      } else {
        if (codon.length() == 3) AA += "-";
      }
      codon = n.Remove(0, 3);
    }
    // --Remove ending "*" if found
    if (AA.endsWith("*")) {
      AA = AA.substring(0, AA.length() - 1);
    }
    return AA;
  }
Пример #2
0
  public String aa_to_dna(Sequence original_dna, Sequence protein, GeneticCode gncode) {
    LinkedList<String> codons = new LinkedList<String>();
    String AA = "";
    String dna = "";
    Sequence n = new Sequence();
    n.setSequence(original_dna.getSequence().toUpperCase());
    int pos = 0;
    boolean found = false;
    // --Find start codon

    //        while(!found&&pos<n.getLen()-2) {
    //            String start=n.getSequence().substring(pos, pos+3);
    //            if (gncode.getStart_code().get(start)!=null) {
    //                AA+=""+gncode.getStart_code().get(start);
    //                codons.add(start);
    //                pos+=3;
    //                found=true;
    //            }
    //            pos++;
    //        }
    // --return empty string if not found
    //        if (!found) {
    //            Config.log("No Start");
    //            return AA;
    //        }

    pos = start;
    // --MAKE THE ORIGINAL TRANSLATION
    n.Remove(0, pos); // remove till start
    String codon = n.Remove(0, 3);
    // --Debug
    // Config.log(n.getSequence());
    while (!codon.isEmpty() && n.getLen() > 0) {
      // Config.log(codon+" "+gncode.getCode().get(codon));
      String aa = gncode.getCode().get(codon);
      // --Debug
      // Config.log(aa);
      if (aa != null) {
        AA += aa;
        codons.add(codon);
      } else {
        if (codon.length() == 3) AA += "-";
      }
      codon = n.Remove(0, 3);
    }
    // --MAKE THE REAL cDNA
    for (int i = 0; i < protein.getLen(); i++) {
      char c = protein.getSequence().charAt(i);
      // Config.log(c);
      if (c == '-' || c == '.') {
        dna += "---";
      } else {
        // --remove stop codon
        String codon_to_add = codons.poll();
        if (codon_to_add != null) {
          if (gncode.getCode().get(codon_to_add).equals("*")) codon_to_add = "---";
          dna += codon_to_add;
        }
      }
    }
    return dna;
  }