Step One
The DNA molecule is a double-helix. You can think of this double helix as two parallel sequences of DNA with nucleotides or bases (A,C,G,Ts) on one strand matched with their associated nucleotide on the other strand according to the following rules:
A matched with T
C matched with G
For example, imagine we have removed the double-helix and show the two strands in parallel; notice that every base ‘A’ on one strand matches a ‘T’ on the other strand and that every ‘C’ on one strand is matched with a ‘G’ on the other strand:
Strand 1: Read left to right
A C G T C C C G G A
T G C A G G G C C T
Strand 2 : read right to left
Databases that store the DNA sequence of an organism typically only store one of the two strands of the DNA to save room. Since the two DNA strands are complements of one another, it is “easy” to get the second complementary strand if you have the original strand. If a base on strand 1 is an ‘A’, then the base on the other strand must be a ‘T’. Note however, that strand 1 begins at the left and is read from the left to the right: “ACGTC…” but strand #2 begins at the right and is read from the right to the left: “TCCGG…”. Because the strands are read in “reverse” order and they have bases that are “complements” of one another, the strands are commonly called “reverse complements”.
This exercise involves writing a C++ program to accept a file of DNA sequence via prompt input. The aim is to produce the reverse complement strand of DNA.
For example, if the starting file called ecoli.fna contained the sequence:
ACTTGGCC<newline>
GGTAC<newline>
your C++ program, when run as shown below, should produce the reverse complement of this sequence to standard output:
$ ./revComp
Enter Filename to read: ecoli.fna
GTACCGGCCAAGT
Notice that the reverse complement should be written to standard output without any newlines. You can assume that the input file will have only uppercase letters (A, C, G, or T) and will not have a starting header line.
To implement this, write a function called reverse and place its implementation in the source file dna.cpp and prototype in dna.h. The function should take an open input file stream and print the compliment to standard output.
Write a suitable main function (driver) in main.cpp which prompts the user for a filename, as illustrated above, opens the file and invokes the reverse function. Once complete the main function should close the stream. If for some reason the input file stream cannot be opened the main function should terminate with an error message. You can assume a DNA strand is no more than 3000 characters long.
Step Two
In the first step, your program computed the reverse compliment of the DNA strand. Add another function called write in the source file dna.cpp (along with appropriate prototype in dna.h) that writes the reverse compliment back to a file. The function just like reverse should take an open output file stream and write the reverse compliment to the file. You should modify the program so that main prompts for the filename to output the reverse compliment to. If for some reason the file cannot be written, print an appropriate error message. You need not write newlines out to the file.
An example of what should happen if everything work:
$ ./revComp
Enter Filename to read: ecoli.fna
GTACCGGCCAAGT
Enter Filename to write: ecoli-rev.fna
File written – done.
An example of what would happen on an error:
$ ./revComp
Enter Filename to read: ecoli.fna
GTACCGGCCAAGT
Enter Filename to write: ecoli-rev.fna
File can not be opened for writing – exiting.
My codes for main.cpp
#include <iostream>
#include <fstream>
#include <cstring>
#include "dna.h"
using namespace std;
void reverse( char x [3000],char y [10]);
int main()
{
char words[3000];
char filename[10];
cout<<"Enter filename : ";
cin>>filename;
reverse(words,filename);
return 0;
}
This is my code for dna.cpp
#include <iostream>
#include <fstream>
#include "dna.h"
using namespace std;
void reverse(char x[3000] , char y[10] )
{
int i = 0;
ifstream infile;
infile.open(y,ios::in);
if(!infile)
{
cout<<"File not found "<<endl;
}
while(!infile.eof())
{
infile.getline(x,3000);
i++;
cout<<x<<endl;
}
infile.close();
)
}
And lastly this is my header files
void reverse(char x[3000],char y[10])
Fa
Reply
l be appreciated, best with example codes and proper explanation to solve this question, ^_^!