can anybody please help me with this project?

In this project, my input will be 2 strings consisting of the characters A, G, C, and T. For instance:
agatgctagatttcg
agcctcccgatagcc

and Count the number of positions at which 2 sequences (of equal length) differ.

truly appreciated .
inner_product works great for this kind of thing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <numeric>
#include <functional>

int main()
{
    std::string s1 = "agatgctagatttcg";
    std::string s2 = "agcctcccgatagcc";

    int diffs = std::inner_product(s1.begin(), s1.end(), s2.begin(), 0,
                                   std::plus<int>(), std::not_equal_to<char>());

    std::cout << "The number of pairwise mismatches: " << diffs << '\n';
}

online live demo: http://ideone.com/SV4MK5

(although, depending on what you're studying you may be expected to write a loop, for example, for(size_t n = 0; n < s1.size(); ++n), which increments a counter whenever s1[n] != s2[n])
Last edited on
cubbi, you re the best!! thank you so much for the help.

hey, cubby ,
one more question,
how do I Allow the strings to be of different lengths. In this case, it works as follows:

GCCGTAA
GCCG
These have a Hamming Distance of 3, because the "TAA" at the end is not matched in the 2nd string.

TGGC
TAGCAGG
These have a Hamming Distance of 4: Positions 1,4,5,6 don't match.
Topic archived. No new replies allowed.