r/programminghelp • • 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

Here's the link to the provided input file: https://cdn.inst-fs-iad-prod.inscloudgate.net/e66a4acc-30b5-41b7-834d-2b775ad25c74/covid19sequence.txt?token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6ImNkbiJ9.eyJyZXNvdXJjZSI6Ii9lNjZhNGFjYy0zMGI1LTQxYjctODM0ZC0yYjc3NWFkMjVjNzQvY292aWQxOXNlcXVlbmNlLnR4dCIsInRlbmFudCI6ImNhbnZhcyIsInVzZXJfaWQiOm51bGwsImlhdCI6MTYwMjc2MjA4OSwiZXhwIjoxNjAyODQ4NDg5fQ.cHtCH9cfW7D4VmjZkAPwS9OnV_HQ676FxsJr9LvnfopCnUaJVwgpTVLrYmMsbk5-ZIOva7dUzeujcrEBsN-UGQ&content_type=text%2Fplain

5 Upvotes

4 comments sorted by

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?

2

u/b00lian Oct 15 '20

I think I fixed it. Does that look better? I also put a link to Pastebin at the bottom if you need a link.

2

u/[deleted] Oct 15 '20

The link is great, thanks. As for if the code here looks better, almost. All you need to do now is highlight it and then select the Code Block option from the editor (click the 3 dots and you should see it, if you don't see it now). That will put the format the code as ... well, code :) But since I have the link I'll take a look.

3

u/[deleted] 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.