Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int currIndex = dnaStr.indexOf(stopCodon, startIndex+3);
- while(currIndex != -1){
- int diff = currIndex - startIndex;
- if(diff%3 ==0){
- return currIndex;
- } else{
- currIndex = dnaStr.indexOf(stopCodon, currIndex);
- }
- }
- return dnaStr.length();
- }
- public String findGene(String dna, int where){
- int startIndex = dna.indexOf("ATG", where);
- if(startIndex == -1){
- return "";
- }
- int taaIndex = findStopCodon(dna, startIndex, "TAA");
- int tagIndex = findStopCodon(dna, startIndex, "TAG");
- int tgaIndex = findStopCodon(dna, startIndex, "TGA");
- int minIndex = 0;
- if(taaIndex == -1 ||
- (tgaIndex != -1 && tgaIndex < taaIndex)){
- minIndex = tgaIndex;
- }else{
- minIndex = taaIndex;
- }
- if(minIndex == -1 || (tagIndex !=-1 && tagIndex<minIndex)){
- minIndex = tagIndex;
- }
- if(minIndex == -1){
- return "";
- }
- if(minIndex+3 > dna.length()){
- return "";
- }
- return dna.substring(startIndex, minIndex+3);
- }
- public void printAllGenes(String dna) {
- int startIndex = 0;
- while(true){
- System.out.println("yes");
- String currentGene = findGene(dna, startIndex);
- if(currentGene.isEmpty()){
- break;
- }
- System.out.println(currentGene);
- startIndex = dna.indexOf(currentGene, startIndex) + currentGene.length();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement