Need help with this code in C++ using only string functions and the simplest as
ID: 3705197 • Letter: N
Question
Need help with this code in C++ using only string functions and the simplest as possible
As well as using namespace std;
Biologists use a sequence of letters A, C, T, and G to model a genome. A gene is a substring of a genome that starts after a triplet ATG and ends before a triplet TAG, TAA, or TGA. Furthermore, the length of a gene string is a multiple of 3 and the gene does not contain any of the triplets ATG, TAG, TAA, and TGA. Write a program that prompts the user to enter a genome and dis- plays all genes in the genome. If no gene is found in the input sequence, the pro- gram displays no gene is found
- The first gene has to be 3 long
- The second has to be 6 long
(Bioinformatics:find genes) Biologists use a sequence of letters A,C, T, and G to modela genome. A gene is a substring of a genome that starts after a triplet ATG and ends before a triplet TAG, TAA, or TGA. Furthermore, the length of a gene string is a multiple of 3 and the gene does not contain any of the triplets ATG,TAG, TAA, and TGA. Write a program that prompts the user to enter a genome and displays all genes in the genome. If no gene is found in the input sequence, displays no gene. Here are the sample runs: Enter a genome string: TTATGTTTTAACGATCCGGCGTTAGTT e GGGCGT Enter a genome string: TGTGTGTATAT t no gene is foundExplanation / Answer
Solution:
Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
string genome;
cout << "Enter a genome string: ";
cin >> genome;
int count = 0, s = 0, i;
do{
int start = -1, end = -1;
for(i = s; i < genome.size(); i++){
if(genome.substr(i, 3).compare("TAG") == 0 || genome.substr(i, 3).compare("TAA") == 0 || genome.substr(i, 3).compare("TGA") == 0){
start = i;
break;
}
}
for(int j = i + 6; j < genome.size(); j += 3){
if(genome.substr(j, 3).compare("TAG") == 0 || genome.substr(j, 3).compare("TAA") == 0 || genome.substr(j, 3).compare("TGA") == 0){
end = j;
s = j;
break;
}
}
if(start != -1 && end != -1){
for(int k = start + 3; k < end; k++){
cout << genome[k];
}
cout << " ";
count++;
}
else{
break;
}
}while(i < genome.size());
if(count == 0) cout << "No gene is found ";
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)