r/programminghelp • u/b00lian • Oct 15 '20
C++ Help with college assignment in C++.
Here's what the assignment asks for.
Your goal is to do basic analysis on the COVID-19 virus (technical name: severe acute
respiratory syndrome coronavirus 2 (SARS-CoV-2)).
Every DNA sequence is made up of one of four nucleotides: a, t, c, or g (Adenine, Thymine,
Cytosine, or Guanine). I have provided the entire DNA sequence for COVID-19 in the file
covid19sequence.txt available on Canvas (pulled from the NCBI database here:
https://www.ncbi.nlm.nih.gov/nuccore/MW001284). This strain was sequenced in
Philadelphia, PA in late June 2020.
You will provide a report of the number of each nucleotide within the sequence, as well as the
percent each nucleotide makes up of the total. You will need to determine the total number
of nucleotides in the file within your code in order to do this calculation.
• 3 comment lines (description of the program, author, and date created)
• Variables for the counts for each type of nucleotide and a total (1.5 points)
• Open the file for input and read in each nucleotide (3 points)
• Calculate counts for each nucleotide that is read from the file (2 points)
• Calculate the total number of nucleotides in the file (1 point)
• Display a report matching the output below with total number of nucleotides, the
number of each individual nucleotide, as well its percentage (to two decimal places)
(4.5 points)
Turn in a .txt file to Canvas with your output and source code.
Example Output:
COVID-19 sequence analysis:29883 nucleotides in the sequence. Sequence breakdown:
a: 8931 29.89%
t: 9606 32.15%
c: 5485 18.35%
g: 5861 19.61%
-------------------------------------------------------------------------------------------------------------------------------------
Here is what I have so far.
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char a = 'A'; //Adenine (Nucleotides)
char t = 'T'; //Thymine
char c = 'C'; //Cytosine
char g = 'G'; //Guanine
int totalAdenine;
int totalThymine;
int totalCytosine;
int totalGuanine;
int totalNucleotides;
ofstream outfile; //writing out to a file
outfile.open("numbers.txt");//open a file for input
outfile << a << " " << endl << t << " " << endl << c << " " << endl << g << " " << endl;
ifstream infile;
infile.open ("numbers.txt");
if (infile)
{
cout << a << " " << endl << t << " " << endl << c << " " << endl << g << " " << endl;
}
}
----------------------------------------------------------------------------------------------------------------------------------------
I have no how to get through the rest of this. I've been trying to figure it out for hours rewriting code for hours. It's due in 3 days.
Link to code : https://pastebin.pl/view/af71b8bf
3
Oct 15 '20
Since your input is one letter per line, all you need to do is loop through each line in the file and check if it's one of the 4 nucleotides. If it is, then you increment the specific counter.
When you reach the end, to get the total, just add the 4 groups together then to get your percentages, just divide by the total.
2
u/[deleted] Oct 15 '20
Would you do me a favor and either clean up the formatting (it's shattered beyond belief) or just upload the file to something like pastebin so we can see the source without it being mangled by reddit?