dna to rna do not understand the question

DNA is made up from 4 different bases (nucleotides), adenine (A), thymine (T), guanine (G) and
cytosine (C). This is true for plants, animals, bacteria, in fact it is true all life forms on earth that
contain DNA.
In an incredible molecular feat called transcription, your cells create molecules of messenger
RNA that mirror the sequence of nucleotides in your DNA. The RNA then creates proteins that
do the work of the cell.
Create a function called dna_to_rna, which should take as input a string which will have DNA
nucleotides (capital letter As, Cs, Gs, and Ts). There may be other characters, too; they should be
ignored by your transcribe function and disappear from the output. These might be spaces or
other characters that are not DNA nucleotides.
Then, dna_to_rna should output the messenger RNA that would be produced from that DNA
string. The correct output simply uses replacement:
 As in the input become Us in the output.
 Cs in the input become Gs in the output.
 Gs in the input become Cs in the output.
 Ts in the input become As in the output.
 any other input characters should disappear from the output altogether
Not quite working? One common problem that can arise is that dna_to_rna needs to have an
ELSE to capture all of the non-legal characters. All non-nucleotide characters should be dropped.
Here are the tests to check:
ACGTTGCA should be transformed into UGCAACGU
ACG TGCA should be transformed into UGCACGU // note that the space disappears
GATTACA should be transformed into CUAAUGU
A42% should be transformed into U
I am confused on how to set up
As in the input become Us in the output.
 Cs in the input become Gs in the output.
 Gs in the input become Cs in the output.
 Ts in the input become As in the output. and how to make the other characters dissappear
... do not understand the question

target is the function dna_to_rna along the following lines:
1
2
3
4
5
6
7
8
9

std::string dna_to_ran(const std::string& dna)
{
	// check the dna string and remove all non A, T, G and C characters
	// hint: erase_remove idiom or std::regex
	// map A -> U, etc
	// hint: switch-case or std::regex_replace
	// add up the chars from the previous step which becomes the return value string
} 
Last edited on
Create a function taking string DNA as argument and returning string RNA

Create an empty RNA string

Go through chars of DNA one by one (either simple for loop or range-based for-loop)

If the char is one of ACGT do the conversion and add to the RNA string. (If it's not, just do nothing).

Return the RNA string at the end.



Lots of ways of doing the conversion; e.g. any of:
- Simple if-else if blocks (probably the simplest)
- Switch blocks (similar to above)
- Use a map<char,char>
- Use strings DNAbases="ACGT" and RNAbases="UGCA" and use find / same string index
- Regex
- .....
etc.


thanks
Topic archived. No new replies allowed.