Question

C++ Programming help, please include comments to help me understand the code. Thank you for helping....

C++ Programming help, please include comments to help me understand the code. Thank you for helping.

Task C: Substitution and Hamming Distance

For this task, we will explore mutations that occur by substitution. Your task is to write a program called hamming.cpp that calculates the Hamming distance between two strings. Given two strings of equal length, the Hamming distance is the number of positions at which the two strings differ. e. g.: Hamming("aactgc", "atcaga") would output 3. Notice that certain amino acids are encoded by multiple codons. Therefore, not all substitutions result in a change of protein structure. The file mutations.txt contains an even number of lines (zero-indexed). The even-numbered lines contain the original DNA sequence, and the odd-numbered lines contain that same sequence with substitution mutations. For each pair in mutations.txt, output to the console the Hamming distance followed by “yes” or “no” whether the substitution caused a change in structure. Example:

$ ./hamming
0 no
17 yes
4 yes

Remember that translation to proteins does not begin until the first “Start” codon, and stops at the first “Stop” codon, and unlike the “Start” codon, the “Stop” codon is not included in the protein chain translation; it simply signifies the end of translation.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have coded assuming the input is taken only from the file and it is in this format;

mutations.txt

aactgc
atcaga
gctata
gctata

and the file will be in the same folder as hamming.cpp and is not empty.

hamming.cpp

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int main()

{

//file handling using ifstream class object to read the file

ifstream file("mutations.txt");

//String to hold string for comparision

string ham1, ham2;

//To keep count of hamming distance

int hamming_dist = 0;

  //execute the loop if file is not empty

while (getline(file, ham1))   //using getline to read each odd line

{   

//hamming_dist is initialize to zero with each iteration

//so as not to add to previous iteration.

hamming_dist = 0;

  //using getline to read each even line

getline(file, ham2);

  //iterate through both string comparing

for (int i = 0; i < ham1.length(); i++)

{

  //increasing hamming distance by 1 when characters of strings don't match

if (ham1[i] != ham2[i])

++hamming_dist;

}

if (hamming_dist == 0)

cout << "0"<< " "<< "no\n";

else

cout << hamming_dist << " "<< "yes\n";

}

}

Add a comment
Know the answer?
Add Answer to:
C++ Programming help, please include comments to help me understand the code. Thank you for helping....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • where does transcription begin 3. List the major types of RNA and include what they code...

    where does transcription begin 3. List the major types of RNA and include what they code for, their function in the cell and which type is translated. 4. If a bacterial protein has 2,500 amino acids long, how many nucleotide pairs long is the ger sequence that codes for it? 5. Where does transcription begin? 6. What is the template and nontemplate strands of DNA? 7. Why is only one strand transcribed, and is the same strand of DNA always...

  • C++: Translating mRNA sequence help Homework Description Codon 1 You are working in a bioinformatics lab...

    C++: Translating mRNA sequence help Homework Description Codon 1 You are working in a bioinformatics lab studying messenger RNA (mRNA) sequences. mRNA is a sequence of the nucleotide bases (Adenine, Cytosine, Guanine, and Uracil) that conveys information stored in DNA to Ribosomes for translation into proteins. The bases in the sequences are denoted by the first letters of the nucleotide bases (e.g. A, C, G, and U). A sequence of mRNA is made up of hundres to thousands of nucleotide...

  • Hello please please help !! Thank you!! Please and thank you soo much!!! Question Completion Status:...

    Hello please please help !! Thank you!! Please and thank you soo much!!! Question Completion Status: Question 10: The genetic code consists of 64 triplets of nucleotides (called codons). Each codon (with the exception of the 3 stop codons) encodes for one of the 20 amino acids used in the synthesis of proteins. This produces some redundancy in the code as most amino acids are encoded by more than one codon. One codon, AUG serves two related functions: it signals...

  • Overview The purpose of this activity is to help the students to understand how replication, tran...

    TranslationOverview:The purpose of this activity is to help the students to understand how replication, transcription, and translation are connected. Students will use a sequence from a bacterial gene that confers resistance to antibiotics (carbapenems). They will be asked to apply the knowledge obtained in the class lecture to (1) find the promoter in the sequence, (2) determine the amino acid sequence of a fragment of the polypeptide, (3) "reverse translate" a fragment of the polypeptide, and (4) identify mutations in...

  • What are the three functional groups that comprise a nucleotide? What do nucleotides have in common...

    What are the three functional groups that comprise a nucleotide? What do nucleotides have in common with amino acids or simple sugars? When the structure of DNA was first elucidated, many biologists quickly saw how this structure explained the passage of information from one generation to another. How does the structure of DNA explain generation-to-generation flow of information? In other words, give a brief description of the structure of DNA and tell how this structure allows for replication. Which of...

  • C++ Help Task B: Translation While a nucleotide is the basic unit of information, three nucleotid...

    C++ Help Task B: Translation While a nucleotide is the basic unit of information, three nucleotides, or codon, is the basic unit of storage. The reason for this is that each gene codes for a protein, and all proteins are made from 20 amino acids. Recall that there are 4 different bases that make up dna. Thus, three bases can encode for 4x4x4 = 64 different symbols. Two base pairs can only encode for 4x4 = 16 symbols, which is...

  • Please help me to make this c programming code!! Thank you!! Concatenation of two strings using...

    Please help me to make this c programming code!! Thank you!! Concatenation of two strings using pointers Step 1: Ask the user to input ni,n2 and create two character arrays (strings) with ni, n2 size using malloc. Step 2: create a 3rd array using malloc of size(n1+n2). Step 3: Ask the user to input String1 (of size nl) Step 4: Ask the user to input String2 (of size n2) Step 5: concatenate the two arrays and store them in String3...

  • Can someone please help me with this code? I'm writing in C++. Thank you in advance....

    Can someone please help me with this code? I'm writing in C++. Thank you in advance. Complete a program that represents a Magic Eight Ball (a Magic Eight Ball allows you to ask questions and receive one of several random answers). In order to complete this, you will need a couple of new functions. First, in order to get a line of input that can contain spaces, you cannot use cin, but instead will use getline: string question; cout <<...

  • 1 Overview and Background Many of the assignments in this course will introduce you to topics in ...

    1 Overview and Background Many of the assignments in this course will introduce you to topics in computational biology. You do not need to know anything about biology to do these assignments other than what is contained in the description itself. The objective of each assignment is for you to acquire certain particular skills or knowledge, and the choice of topic is independent of that objective. Sometimes the topics will be related to computational problems in biology, chemistry, or physics,...

  • Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And...

    Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And also I have codes but just donot work so make sure that it works. Requested files: CrosswordGenerator.cpp, CrosswordGenerator.h, CrosswordGenerator_test.cpp CrosswordGenerator - Write a program that helps to generate a crossword puzzle by organizing words that share letters.   For this assignment, you will write a program that forms the basis of a crossword puzzle generator. In order to create a crossword puzzle you need to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT