Question

In: Computer Science

In C++ Write a function called findBestSimScore that takes a genome and a sequence and returns...

In C++

Write a function called findBestSimScore that takes a genome and a sequence and returns the highest similarity score found in the genome as a double.

Note: the term genome refers to the string that represents the complete set of genes in an organism, and sequence to refer to some substring or sub-sequence in the genome.

  • Your function MUST be named findBestSimScore

  • Your function should take two parameters in this order:

    • a string parameter for the genome (complete set of genes)

    • a string parameter for the sequence (sub-sequence of the genome)

  • Your function should return the highest similarity score as a double.

  • Your function should not print anything.

The best similarity scores is [0.0,1.0]

Our sequence is "ACT", which is a string of length 3. That means we need to compare our sequence with all the 3 character long sub-sequences (substrings) in the genome.

Examples:

genome sub-sequence

sequence

similarity score

ATACGC

ACT

0.33

ATACGC

ACT

0

ATACGC

ACT

0.66

← findBestMatch returns 0.66, since that is the highest similarity score found

ATACGC

ACT

0

Solutions

Expert Solution

NOTE: The complete program code is given to implement findBestSimScore() function. Please ignore the complete program code, if you want function code only.


Function Code to Copy:

double findBestSimScore(string genome, string seq)

{

    // Declare a variable count to find the number of

    // matching of a sequence.

    // Declare and initialize a variable max to 0 to

    // hold maximum number of a matching sequence.

    int count, max=0;

    // Check whether the length of genome is less than

    // sequence, then return 0.

    if(genome.length()<seq.length())

    {

        return 0;

    }

   

    // Use for loop to traverse through elements of

    // genome and sequence to find number of matchings.

    for(int i=0;i<genome.length()-seq.length()+1;i++)

    {

        // Initialize count variable to 0.

        count=0;

        // Inner for loop is used to compare all

        // character of sequence with same number of

        // genome string.

        for(int j=0;j<seq.length();j++)

        {

            // Check genome character is equal to sequence

            // character or not.

            if(genome[i+j]==seq[j])

                // Increment the count variable by 1.

                count++;

        }

        // Check if current count of matching is greater

        // than previous one.

        // Assign highest count value to max variable.

        if(count>max)

        {

            max=count;

        }

    }

    // Return a double type highest similarity score by

    // dividing max value with length of sequence string.

    return max/double(seq.length());

}

_________________________________________________________________________________

NOTE : PLEASE IGNORE COMPLETE PROGRAM CODE, IF YOU WANT FUNCTION CODE ONLY.

_________________________________________________________________________________

Complete Program Code to Copy:

// Include the required header files.

#include <iostream>

#include <string>

#include <iomanip>

#include <cmath>

using namespace std;

// Define a double type function findBestSimScore() to

// take genome and sequence as arguments and returns

// the highest similarity score.

double findBestSimScore(string genome, string seq)

{

    // Declare a variable count to find the number of

    // matching of a sequence.

    // Declare and initialize a variable max to 0 to

    // hold maximum number of a matching sequence.

    int count, max=0;

    // Check whether the length of genome is less than

    // sequence, then return 0.

    if(genome.length()<seq.length())

    {

        return 0;

    }

   

    // Use for loop to traverse through elements of

    // genome and sequence to find number of matchings.

    for(int i=0;i<genome.length()-seq.length()+1;i++)

    {

        // Initialize count variable to 0.

        count=0;

        // Inner for loop is used to compare all

        // character of sequence with same number of

        // genome string.

        for(int j=0;j<seq.length();j++)

        {

            // Check genome character is equal to sequence

            // character or not.

            if(genome[i+j]==seq[j])

                // Increment the count variable by 1.

                count++;

        }

        // Check if current count of matching is greater

        // than previous one.

        // Assign highest count value to max variable.

        if(count>max)

        {

            max=count;

        }

    }

    // Return a double type highest similarity score by

    // dividing max value with length of sequence string.

    return max/double(seq.length());

}

// Start the main() function

int main()

{

    // Declare two string type variable to hold genome

    // and sequence value.

    string genome, seq;

    // Declare variables to hold the highest similarity

    // score.

    double s, score;

    // Prompt the user to input genome string and sequence

    // string.

    cout<<"Enter a genome sub-sequence : ";

    getline(cin,genome);

    cout<<"Enter a sub-sequence to be searched : ";

    getline(cin,seq);

    // Call the findBestSimScore() function and store the

    // returned highest similarity score by function.

    s=findBestSimScore(genome,seq);

    // Store the highest similarity score without rounding

    // off the last digit.

    score=floor(100*s)/100;

    // Display the highest similarity score up to 2 decimal

    // points by using fixed and setprecision.

    cout<<"Highest similarity score : ";

    cout<<fixed<<setprecision(2)<<score<<endl;

    // Return 0 to the main() function.

    return 0;

// End of the main() function.

}


Related Solutions

In C++ Write a function called findMatchedGenome that takes three genomes and a sequence and prints...
In C++ Write a function called findMatchedGenome that takes three genomes and a sequence and prints the list of matched genomes The function must be named findMatchedGenome The function will take in 4 string input parameters in the order Genome 1, a string Genome 2, a string Genome 3, a string sequence (sub-sequence of the genomes), a string The function should not return anything. Unexpected values might be passed into a function and your function should be able to handle...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
write an algorithm function called balance() in javascript that takes in a string and returns a...
write an algorithm function called balance() in javascript that takes in a string and returns a strinf with balanced parantheses only. the string should be able to contain only parantheses, numbers, and letters. include comments of each portion of your code balance(“()()”) should return “()()” balance(“())”) should return “()” balance(“a(b)c”) should return “a(b)c” balance(“a(b)c())”) should return “a(b)c()”
C++ The minimum function. (a) Write a function that takes two integers and returns the value...
C++ The minimum function. (a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of...
Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at...
C++ Write a function called linearSearch that takes an array as a parameter and search for...
C++ Write a function called linearSearch that takes an array as a parameter and search for a specific value inside this parameter. The function returns the frequency of a specific value in the array. In the main function: 1. Define an array called salaries of length 5. 2. Initialize the array by asking the user to input the values of its elements. 3. Define a variable called key and ask the user to enter a value for this variable. 4....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT