View the step-by-step solution to:

Need help fixing C++ code. Will attach the assigment description and necessary file to test code. What the code is supposed to do is read from a file...

Need help fixing C++ code. Will attach the assigment description and necessary file to test code. What the code is supposed to do is read from a file and with DNA sequences in it (A=0, C=1, G=2, and T=3) and convert it into ASCII to decode it and output the message in a text file. This is what I have so far:


#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>

using namespace std;

float decode(float*, int, int&, int&, int&, int&);

int main(void) {

char codon[5];
fin >> codon;

char c;
c = decode(codon);

ifstream fin("dna.seq");

ofstream fout("decoded.txt");

return 0;

float decode(float* codon, int n, int& A, int& C, int& G, int& T){

for(int i=0; i 
if (codon[i] == 'A') val = 0;
else if (codon[i] == 'C') val = 1;
else if (codon[i] == 'G') val = 2;
else if (codon[i] == 'T') val = 3;
}
}

}

283 CACT CTAG CGCC CGAC CTCA AGAC CCTT CCGC CGTT CTCC AGCT CTCG CGCC CCTT CGTC CGAC CTAT CTCA CGCC CTAG CGCC CGCA CCTT CTCA CGGA CGCC CCTT CGCC CGAC CTAT CTGC CCTT CTAA CGAC CTAG CTCA AGTG CCTT CATG CGTT CTCT CCTT CGAT CGAC CGTG CCTT CTGC CGTT CTCC CCTT CGCG CGGC CGTG CGCA CCTT CTCA CGGA CGCC CCTT CGGT CGCC CTGC CCTT CTCA CGTT CCTT CTCC CGTG CGTA CGTT CGAT CGGT CCTT CTCA CGGA CGCC CCTT CTAG CGCC CTAT CTCA CCTT CGTT CGCG CCTT CTCA CGGA CGCC CCTT CTCA CGCC CTGA CTCA ATTT ATTT CCTT AGGG AGGG AGGG ATAT ATAG ATCA CAAG ATAG ATAC AGGG AGGG AGGG CACA CTGC CGAC CGCA CCTT CAGC CGTG CTAT CTCA CGGC CTCA CTCC CTCA CGCC CCTT CCAA CTAG CGTT CTAA CTAG CGGC CGCC CTCA CGAC CTAG CTGC CCTT CCAT CGCC CTAC CTCC CGCC CGTG CGAT CGCC CCTT AGGA ACGC ATGC ACGT ATAA ATGA ATCA ATTA ATCT ATAC ATGC ATCC ATCA ATAA ACGC ATGA ATGC ACGT ATCC ACGC ACGC ACAG ATTG ATAA ACGC ATTC ACTA GTCT AGTA ACAG ATTG ATGA ACGC ATTG ATGA ACGG ACGG ATAA ATCT ATAA ATAG ATGT ATAA ATAT ATCC ACGT ATAA GTCG ATGT ACAA ACAG ACAG ATTG ATAA ACGT ATAA ATTA ACGC ATCT ATCC ACAG ATTG ATTA ATCT ATAC ACAG ATCC ATGC ATCC ATCA ACGG ATGA ACGT ATAA ATTA ACAG ACAG ATCC ATCT ATCC ACAC GTCT AGTA ACAG ATTA ACGC ACAG ATCC ATCC ATCG ATGA ACAG ATAA GTCT AAAG ATTG ATAA AGAA ACAT ATGA ATGC ACAA ATGA ACAG ATTA ATCC ATCT ACGC ACAG ATTA ATCG ATCG ACGG ACGT ATCC ATGC ATAA ATAA ATAG ACGC GTCG ATGT ACAA ACAG ATTA ACAG GTAC ACGC ATGA ATCG ATCG ACAG ATTG ATAA ATGA ACAG ACGT ATAA GTCT
Background image of page 1
University of Maryland at College Park Dept. of Aerospace Engineering ENAE 202: Aerospace Computing C++ Homework #5 Background Warning: Wall of text follows. But it is a really interesting wall of text which in- troduces, and motivates, this week’s homework. Don’t skip over; take the time to read it through. Computers, as we know, encode information using a binary (on/off; 1/0) standard. With N binary digits (bits) there are 2 N possible 1/0 patterns, which the computer can interpret as an equivalent number of distinct symbols or instructions. Computers typically read bits in groups of 8 at a time (1 byte = 8 bits), although for more complex operations/symbols multiple bytes may also be used (for example, float uses 4 bytes, 32 bits, to represent decimal numbers). One of the first international standards for computers was an agreed mapping from the 2 8 = 256 possible 8 bit patterns to the letters of the english (latin) alphabet, the arabic numerals, and the typical punctuation and textual formatting symbols (periods, spaces, tabs, new lines, etc). This is known as the ASCII standard. Google it and you can see the specific mapping from bit patterns (or equivalently integers from 0-255) and the corresponding symbols. Strictly speaking, the ASCII standard only uses the first half of this range; the 128-255 range is “extended ASCII”, used for simple graphics or alternate alphabetic characters. Moreover, ASCII has been partly superceded by the more modern Unicode system, which uses far more bits to provide encodings for the symbols used in all of the world’s languages and number systems. Virtually every computer language recognizes the original ASCII encoding system, however, and C++ is no exception. The variable type char in C++ has dual purpose. It is a variable that can hold exactly 1 byte of information, with its values interpreted as integers in the range 0-255. However, C++ also recognizes the ASCII equivalences to alphabetic symbols when using this data type, so that sending such a variable to the screen (or a file) will result in the corresponding symbol appearing. Consider the following snippet of code: char c=’a’; // initialize c to hold the character ’a’ cout << "c = " << c << endl; char ch = 97; // initialize ch to hold the integer 97 cout << "ch = " << ch << endl; Both c and ch will print out on the screen as the letter “a” (try it!) This is because C++ recognizes 97 as the (decimal) ASCII equivalent for the bit pattern corresponding to the letter “a”. This equivalence in the char data type between integers and printed symbols is quite useful, and makes some aspects of text processing in C++ effectively into number manipulation. Complete words are “strings” of such symbols, and C++ represents these as arrays of char variables. You can, for example, read a complete word from the keyboard, then display it on the screen or write it to a file like so: char w[10]; cin >> w;
Background image of page 1
cout << "You entered: " << w << endl; cout << "The third character in w is: " << w[2] << endl; Try this too! The above will work even if the word entered is less than 10 characters long. (What happens if more than 10 characters is typed in? Bad things – array overruns, segfaults, stack smashes, and other kinds of nastiness can result. Making sure strings don’t overflow their declared length is a headache, since you don’t have direct control over what is typed into the program. C++ provides a <string> library to help manage that aspect, but we won’t need it here or subsequently in the course). Note that arrays of char behave differently than arrays of numbers. You can load the entire array of char from a single cin , without a loop, and you can send an entire array of char to the screen with a single cout , also without a loop. C++ recognizes that such arrays are special, used to contain the long strings of characters which make words or even sentences, so the rules are different for these arrays. Note also that you can access each individual character in a string by indexing into the array. Back to bits for a moment. There is nothing particularly natural about using a binary (1/0) standard to encode information. It just happens to be the easiest thing to do given the electrical (on/off) nature of the hardware we use in computers. Nature, however, uses a quaternary system for encoding information, at least in DNA molecules. One of 4 bases A, C, G, T, can appear at each position in a DNA molecule. A string of N bases can therefore have any of 4 N distinct base patterns which can be assigned some kind of meaning. Much of biological “information processing” acts by reading DNA bases 3 at a time ( N = 3); such triplets are called codons . Each codon corresponds to an amino acid, and chains of amino acids are stiched together in the order specified by the codons (mostly) to create the proteins from which all life springs. Some of the codons act as “start” and “stop” markers, to distinguish the boundaries between encodings for different proteins. Loosely speaking, such segments are what we call genes . (OK – very loosely speaking. The start/stop segment is really just the “reading frame” of the gene. There are promoter/enchancer/silencer sequences, introns and exons, and lot of other complicated stuff. But this isn’t a biology class; I think we’ve got the gist of the analogy to computation at this point). Our ability to read and manipulate DNA has progressed to the point where we can now synthesize DNA molecules with any desired sequence of bases. These can, of course, be used therapeutically, but they can also be put to more whimsical uses. By creating artificial codons 4 base pairs in length, for example, the possible symbols represented by each such “codon”, 4 4 = 256, just happens to exactly match the number of symbols which can be represented by one byte in a digital computer. This suggests that we could, for example, encode the entire contents of a book in a DNA sequence. The molecular biologist George Church at Harvard has done exactly this with one of his textbooks (although he used a slightly different encoding system). He created 70 billion copies of the entire textbook in a few milligrams of synthetic DNA! (Wonder if he got royalties on each copy? – sorry, I digress). To see how our proposed mapping from DNA sequences to ASCII text might work, we need to first decide on a mapping from the four DNA “letters” A, C, G, T, to the numbers 0-3 used in a base 4 representation of integers. Let’s take them in this “alphabetical” order, so A=0, C=1, G=2, and T=3. Then the ASCII decimal equivalent for the character “c”, which is 99, can be represented in base 4 as 99 = 1 * 4 3 + 2 * 4 2 + 0 * 4 1 + 3 * 4 0 which, using the above mapping to DNA bases, could be represented as the sequence CGAT. Conversely, the sequence TCGA would decode to the integer 216. Check this by hand to make sure you see how it works; you’ll need to use it below.
Background image of page 2
Show entire document
Sign up to view the entire interaction

Top Answer

I am posting the answer which you... View the full answer

decoded.txt

UэYIHe]؝YyIYY)YYIm
IIm]i)YYm9)YY)YY-̌LmIaiY
iYImYM]YY(dl ,&lt;Ll\ d,l\dd d|48,d, \  &lt;d\&lt;L\l\, &lt;\\D8&lt;d\\, ހ ,l,&lt;\d&lt;\l d&lt;Nd, ,

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online