In C++ programming format, create a program that examines both hemoglobin genes
ID: 3703160 • Letter: I
Question
In C++ programming format, create a program that examines both hemoglobin genes for each of four people, with each gene consisting of 444 In C++ programming format, create a program that examines both hemoglobin genes for each of four people, with each gene consisting of 444 Programming Problem DNA analysis is an important part of medical exploration and discovery. In this assignment, we examine both hemoglobin genes for each of four people, with each gene consisting of 444 DNA bases (A,C,T,G) These are the four bases (letters) that make up DNA Sickle-cell anemia is a disorder that is caused by a single mutation in the hemoglobin gene. A sickle hemoglobin gene has a T in the 20th position A person is anemic if he/she has two sickle hemoglobin genes. A person is a carrier if he/she has one sickle hemoglobin gene Otherwise, the person is normal. The input file, called dna.txt and found on UR Courses, contains the DNA of the two hemoglobin genes of four people. The file contains the gene DNA information in this order: geneA1 geneA2 geneB1 geneB2 genec1 genec2 geneD1 geneD2 where 1 and 2 denote the first and second gene, and A, B,C,D denote people. The required information is found in the firstExplanation / Answer
#include<iostream>
#include<string.h>
#include <fstream> // For ifstream
#include <stdlib.h> // For function exit()
#define MAX 444
using namespace std;
// Read file contents and stores it in respective array
void readFile(char dnaA1[], char dnaA2[], char dnaB1[], char dnaB2[], char dnaC1[], char dnaC2[], char dnaD1[], char dnaD2[])
{
// File stream object declared
ifstream fRead;
// Counter variable
int c = 1;
// Open the file dna.txt for reading
fRead.open("dna.txt");
// Check that file can be opened or not
// is_open() function returns true if a file is open and associated with this stream object.
// Otherwise returns false.
if(!fRead.is_open())
{
// Displays error message
cout<<" Error: Unable to open the file!";
// Exit the program
exit(0);
}// End of if condition
// Loops till not end of the file
// eof() function returns true if the stream's eofbit error state flag is set (which signals that the End-of-File has been reached
// by the last input operation). Otherwise returns false.
while(!fRead.eof())
{
// Checks the variable c value and stores it in respective array
switch(c)
{
case 1:
// Stores it in Person A gene 1 array
fRead.getline(dnaA1, MAX);
break;
case 2:
// Stores it in Person A gene 2 array
fRead.getline(dnaA2, MAX);
break;
case 3:
// Stores it in Person B gene 1 array
fRead.getline(dnaB1, MAX);
break;
case 4:
// Stores it in Person B gene 2 array
fRead.getline(dnaB2, MAX);
break;
case 5:
// Stores it in Person C gene 1 array
fRead.getline(dnaC1, MAX);
break;
case 6:
// Stores it in Person C gene 2 array
fRead.getline(dnaC2, MAX);
break;
case 7:
// Stores it in Person D gene 1 array
fRead.getline(dnaD1, MAX);
break;
case 8:
// Stores it in Person D gene 2 array
fRead.getline(dnaD2, MAX);
break;
}// End of switch case
// Increase the counter for next gene
c++;
}// End of while condition
// Close the file
fRead.close();
}// End of function
// Function to check the gene and returns the status
string findStatus(char gene[])
{
string status = "";
// Counter for sickle hemoglogin for each person
int counter = 0;
// Loops till end of the array with iteration gap of 20
for(int x = 19; x < MAX-1; x+=20)
{
// Checks x index position data is 'T' then increase the counter
if(gene[x] == 'T')
// Increase the sickle hemoglogin counter by one
counter++;
}// End of for loop
// Checks if the sickle hemoglogin counter value is 2 return "anemic"
if(counter == 2)
return "anemic";
// Otherwise checks if the sickle hemoglogin counter value is 1 return "carrier"
else if(counter == 1)
return "carrier";
// Otherwise return "normal"
else
return "normal";
}// End of function
// Function to check each person second gene if they are same return true otherwise return false
bool related(char gene1[], char gene2[])
{
// To stores status of match
bool status = true;
// Loops till length of the gene minus 2. Minus 2 for Person alphabet and gene number
for(int x = 0; x < strlen(gene1)-2; x++)
{
// Checks if the current index position of the bother the array is not equal
if(gene1[x] != gene2[x])
{
// Set the status to false
status = false;
// Come out of the loop
break;
}// End of if condition
}// End of for loop
// Returns the status
return status;
}// End of function
// main function definition
int main()
{
// Declares an array of MAX size for each person dna1 and dna2
char dnaA1[MAX], dnaA2[MAX], dnaB1[MAX], dnaB2[MAX], dnaC1[MAX], dnaC2[MAX], dnaD1[MAX], dnaD2[MAX];
// Calls the function to read data from file and stores the dna data
readFile(dnaA1, dnaA2, dnaB1, dnaB2, dnaC1, dnaC2, dnaD1, dnaD2);
// Calls the function to display the status of each person
cout<<" Person A is "<<findStatus(dnaA1)<<". ";
cout<<" Person B is "<<findStatus(dnaB1)<<". ";
cout<<" Person C is "<<findStatus(dnaC1)<<". ";
cout<<" Person D is "<<findStatus(dnaD1)<<". ";
// Calls the function to checks whether each persons dna2 is equal or not
if(related(dnaA2, dnaB2))
cout<<" Person A is related Person B.";
if(related(dnaA2, dnaC2))
cout<<" Person A is related Person C.";
if(related(dnaA2, dnaD2))
cout<<" Person A is related Person D.";
if(related(dnaB2, dnaC2))
cout<<" Person B is related Person C.";
if(related(dnaB2, dnaD2))
cout<<" Person B is related Person D.";
if(related(dnaC2, dnaD2))
cout<<" Person C is related Person D.";
}// End of main function
Sample Output:
Person A is normal.
Person B is carrier.
Person C is anemic.
Person D is normal.
Person A is related Person D.
dna.txt file contents
CCGATAACCCCGAGAACAATACTAACCCGCCGCAGGACGTCCGATAACCCCGAGAACAATACTAACCCGCCGCAGGACGGCCGATAACCCCGATAACCCCA1
CAGAGAACCAAGATAACAATACTAACACGCCGCAGGACGGAAGACCCCCCCGATAACAACCCTAACTCAAAGCAGGGGGGCCAATGGGCCCGATAAAAATA2
CCGGGAACCCCGAAAACAATACAAACTCGTTGCAGGACGGGGGATAACCCCCATAACAACCCCAACTCCCCGCAAAACGGGACTAACCCGCCGCAGGACGB1
AAGATAACGGGGATAACAATACCAACTCGAAGCAATACTAACCCGCCGCAGGAGCAGGACGGAAGACCCCCCCCGAACGGBTACTAACCCGCCGCAGGACG2
GGGATAACCCCCATAAGCAGGACGGAAGACCCCCCCCAATACTAACCCGCCGCAGGACGTCTACTAACCCGCCGCAGGACGCCAACTCCCCGCAAAACGGC1
CCGATGCAGGACGGAAGACCCCCCCAACCCCGATAACCCCACTAACTCGCCGCACTACTAACCCGCCGCAGGACGCACGTACTAACCCGCCGCAGGACGGC2
AAGACTACTAACCCGCCGCAGGACGCCCCCCGATAACAACCCTAACTCAAATACTAACCCGCCGCAGGACGGCGCAGGACGGAAGACCCCCCCAGGGGGGD1
CAGAGAACCAAGATAACAATACTAACACGCCGCAGGACGGAAGACCCCCCCGATAACAACCCTAACTCAAAGCAGGGGGGCCAATGGGCCCGATAAAAATD2