Question

Function 2. Find Best Match (40 points) We will use the term genome to refer 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. Write a function called findBestMatch that takes a genome and a sequence and returns the similarity score of the best match found in the genome as a float. HINT: Problem 3 from Recitation 5 is very similar to this function. We encourage you to write that function before attempting to write this one. Your function should take two parameters in this order: · a string parameter for the genome a string parameter for the sequence o Your function should return the highest similarity score as a float. Your function should not print anything. Your function MUST be named findBestMatch. · o Edge Cases: sequence is empty genome is empty sequence is longer than genome → return-1 → return-1 -return-2 · · Examples: ATACGC, ACT → 0.66 ·

In C++ please!

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

#include <iostream>

#include <string>

#include <iostream>

#include <vector>

using namespace std;

float findBestMatch(string sequence1 , string sequence2){

  

if(sequence1.size() ==0 || sequence2.size()==0)

return -1;

if(sequence1.size() < sequence2.size())

return 0;

float count = 0.0;

int j = 0, max = -1;

for(int i = 0;i<sequence1.size();++i ){

count = 0;

for(j = 0;j<sequence2.size();++j, ++i ){

if(sequence1.at(i) != sequence2.at(j))

break;

  

++count;

}

if(j ==sequence2.size()){

count = sequence2.size();

}

if(max < count)

max = count;

}

return 1.0*max/sequence2.size();

  

}

int main()

{

string str1, str2;

cout<<"Enter string 1: "<<endl;

getline(cin,str1);

cout<<"Enter string 2: "<<endl;

getline(cin,str2);

  

cout<<"Similarity Score is: "<<findBestMatch(str1, str2)<<endl;

return 0;

}


=========================================================================
See Output
Enter string 1: ATACGC main.cpp Enter string 2: ACT Similarity Score is: 0.666667 9 float findBestMatch(string sequence1, str


Thanks, PLEASE RATE

Add a comment
Know the answer?
Add Answer to:
In C++ please! Function 2. Find Best Match (40 points) We will use the term genome...
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
  • Python Write a function index_last(elem, seq) that takes as inputs an element elem and a sequence...

    Python Write a function index_last(elem, seq) that takes as inputs an element elem and a sequence seq, and that uses recursion (i.e., that calls itself recursively) to find and return the index of the last occurrence of elem in seq. The sequence seq can be either a list or a string. If seq is a string, elem will be a single-character string; if seq is a list, elem can be any value. Don’t forget that the index of the first...

  • Just do program 6 using c++ which are printf and scanf. Please don’t use cout and...

    Just do program 6 using c++ which are printf and scanf. Please don’t use cout and cin. Program 4: A slot machine has three windows. A random fruit is picked for each window from cherry apple, lemon, and orange. If all three windows match, the user wins 8 times the bet amount. If the first two windows only are cherries, the user wins 3 times the bet amount. If the first window is a cherry and the second window is...

  • Coding for Python – don’t need it to be complex: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is locate...

    Coding for Python – don’t need it to be complex: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. This type of problem is common in many health disciplines. For example, identifying treatment pathways. The goal is to detect whether a certain pattern appears in the data series. In the following example, the pattern to be...

  • Write a python function score_formatter() that takes one parameter, which is a formatted string that contains...

    Write a python function score_formatter() that takes one parameter, which is a formatted string that contains information about the score received by a student in a particular subject. The function analyzes the string and returns a reformatted string for the score. You will need to use the function re.sub that is discussed in the lecture notes. If the string does not match the pattern, the function returns the string "error". The input string is always given in the format specified...

  • Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....

    Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you. Phase 1 You must design 3 algorithms, and provide both a flow chart and pseudo code for the algorithms.    Algorithm descriptions: Given an integer parameter named current_number and two constant global variables: const int MIN_NUMBER = 1; const int MAX_NUMBER = 8; Create an algorithm named forward, that will advance ONE value through a sequence of numbers 1, 2, 3 ... MAX_NUMBER. In...

  • Question 2 (10 points) (quality.py): We are provided with data from a quality control process in...

    Question 2 (10 points) (quality.py): We are provided with data from a quality control process in a manufacturing firm. The data file, "data.csv", contains several measurements. Each measurement is written in a separate line and each line contains two elements, the area where the measurement is made, and the measured value. These two values are separated with a comma (.). We are tasked to process this data in the following forms. a. First, we need to read the data from...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...

    Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining *   if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: *    result = is_palindrome(str, first_index, last_index) * * parameters - *    str - the string to test *    first_index -...

  • Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignme...

    Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the given...

  • Please use Java only. Write the class TopResult, which keeps track of the best (highest numbered ...

    Please use Java only. Write the class TopResult, which keeps track of the best (highest numbered or highest ordered) result it has seen so far. The class will be a generic type, so the type of results it sees depends on how it is declared. TopResult Task: There are a number of situations in which we want to keep track of the highest value we've seen so far - a highest score, a most recent entry, a name which is...

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