Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. int currIndex = dnaStr.indexOf(stopCodon, startIndex+3);
  2. while(currIndex != -1){
  3. int diff = currIndex - startIndex;
  4. if(diff%3 ==0){
  5.  
  6. return currIndex;
  7.  
  8.  
  9. } else{
  10. currIndex = dnaStr.indexOf(stopCodon, currIndex);
  11. }
  12.  
  13.  
  14. }
  15. return dnaStr.length();
  16. }
  17.  
  18. public String findGene(String dna, int where){
  19. int startIndex = dna.indexOf("ATG", where);
  20.  
  21. if(startIndex == -1){
  22. return "";
  23.  
  24. }
  25. int taaIndex = findStopCodon(dna, startIndex, "TAA");
  26. int tagIndex = findStopCodon(dna, startIndex, "TAG");
  27. int tgaIndex = findStopCodon(dna, startIndex, "TGA");
  28. int minIndex = 0;
  29.  
  30. if(taaIndex == -1 ||
  31. (tgaIndex != -1 && tgaIndex < taaIndex)){
  32. minIndex = tgaIndex;
  33.  
  34. }else{
  35. minIndex = taaIndex;
  36.  
  37.  
  38. }
  39. if(minIndex == -1 || (tagIndex !=-1 && tagIndex<minIndex)){
  40. minIndex = tagIndex;
  41.  
  42. }
  43. if(minIndex == -1){
  44.  
  45. return "";
  46. }
  47. if(minIndex+3 > dna.length()){
  48. return "";
  49. }
  50.  
  51. return dna.substring(startIndex, minIndex+3);
  52. }
  53.  
  54. public void printAllGenes(String dna) {
  55.  
  56. int startIndex = 0;
  57.  
  58. while(true){
  59.  
  60. System.out.println("yes");
  61. String currentGene = findGene(dna, startIndex);
  62.  
  63. if(currentGene.isEmpty()){
  64. break;
  65. }
  66.  
  67. System.out.println(currentGene);
  68.  
  69. startIndex = dna.indexOf(currentGene, startIndex) + currentGene.length();
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement