Program not completing all the function calls.

My code is as follows:


#include <iostream>
#include <string>

using namespace std;

/*
Compares two strings together and calculates their similarity
Parameters: first sequence, second sequence
Returns: similarity score for the two sequences
*/

float similarityScore(string sequence1, string sequence2)
{
cout << "Enter first sequence: ";
cin >> sequence1;
cout << "Enter second sequence: ";
cin >> sequence2;
float sequence1Length = sequence1.length();
float sequence2Length = sequence2.length();
float score = 0.0;
if (sequence1Length != sequence2Length)
{
return 0;
}

float mismatches = 0.0;

for (int i = 0; i < sequence1Length; i++)

{
if (!(sequence1[i] == sequence2[i]))
{
mismatches++;
}
}
score = (sequence1Length - mismatches) / sequence1Length;
return score;

}

/*
Counts all matches of a sequence in a genome with a minimun score consideration
Parameters: genome, sequence, minScore
Returns: all matches within the min score boundary
*/

int countMatches(string genome, string sequence, float minScore)
{

int matches = 0;
int sequenceLength = sequence.length();

for (int pos = 0; pos < genome.length() - sequenceLength + 1; pos++)

{
float score = similarityScore(genome.substr(pos, sequenceLength), sequence);
if (score >= minScore)
{
matches++;
}
}

return matches;
}

/*
Finds the best match in terms of similarity for a genome and a sequence
Parameters: genome, sequence
Returns: best match
*/

float findBestMatch(string genome, string seq)

{
float bestMatch = 0.0;

for (int pos = 0; pos < genome.length(); pos++)

{
float score = similarityScore(genome.substr(pos, seq.length()), seq);
if (score > bestMatch)
{
bestMatch = score;
}
}

return bestMatch;
}

/*
Compares three genomes and returns the index number of the one with the best match for a sequence
Parameters: first genome, second genome, third genome, sequence
Returns: best matching genome for given sequence
*/

int findBestGenome(string genome1, string genome2, string genome3, string seq)
{
float genome1Score = findBestMatch(genome1, seq);
float genome2Score = findBestMatch(genome2, seq);
float genome3Score = findBestMatch(genome3, seq);

if (genome1Score > genome2Score && genome1Score > genome3Score)
{
return 1;
}
else if (genome2Score > genome1Score && genome2Score > genome3Score)
{
return 2;
}
else if (genome3Score > genome1Score && genome3Score > genome2Score)
{
return 3;
}
else
{
return 0;
}
}


int countMatches(string genome, string sequence, float minScore);
float findBestMatch(string genome, string seq);

float similarityScore(string sequence1, string sequence2);


int main()
{
string humanDNA = "CGCAAATTTGCCGGATTTCCTTTGCTGTTCCTGCATGTAGTTTAAACGAGATTGCCAGCACCGGGTATCATTCACCATTTTTCTTTTCGTTAACTTGCCGTCAGCCTTTTCTTTGACCTCTTCTTTCTGTTCATGTGTATTTGCTGTCTCTTAGCCCAGACTTCCCGTGTCCTTTCCACCGGGCCTTTGAGAGGTCACAGGGTCTTGATGCTGTGGTCTTCATCTGCAGGTGTCTGACTTCCAGCAACTGCTGGCCTGTGCCAGGGTGCAGCTGAGCACTGGAGTGGAGTTTTCCTGTGGAGAGGAGCCATGCCTAGAGTGGGATGGGCCATTGTTCATG";
string mouseDNA = "CGCAATTTTTACTTAATTCTTTTTCTTTTAATTCATATATTTTTAATATGTTTACTATTAATGGTTATCATTCACCATTTAACTATTTGTTATTTTGACGTCATTTTTTTCTATTTCCTCTTTTTTCAATTCATGTTTATTTTCTGTATTTTTGTTAAGTTTTCACAAGTCTAATATAATTGTCCTTTGAGAGGTTATTTGGTCTATATTTTTTTTTCTTCATCTGTATTTTTATGATTTCATTTAATTGATTTTCATTGACAGGGTTCTGCTGTGTTCTGGATTGTATTTTTCTTGTGGAGAGGAACTATTTCTTGAGTGGGATGTACCTTTGTTCTTG";
string unkownDNA = "CGCATTTTTGCCGGTTTTCCTTTGCTGTTTATTCATTTATTTTAAACGATATTTATATCATCGGGTTTCATTCACTATTTTTCTTTTCGATAAATTTTTGTCAGCATTTTCTTTTACCTCTTCTTTCTGTTTATGTTAATTTTCTGTTTCTTAACCCAGTCTTCTCGATTCTTATCTACCGGACCTATTATAGGTCACAGGGTCTTGATGCTTTGGTTTTCATCTGCAAGAGTCTGACTTCCTGCTAATGCTGTTCTGTGTCAGGGTGCATCTGAGCACTGATGTGGAGTTTTCTTGTGGATATGAGCCATTCATAGTGTGGGATGTGCCATAGTTCATG";

cout << similarityScore(humanDNA, mouseDNA) << endl;
cout << countMatches(humanDNA, "GCC", 0.5) << endl;
cout << findBestMatch(mouseDNA, "ACT") << endl;
cout << findBestGenome("GGAACACA", "CGATATGA", "GGAGTA", "CAATC") << endl;

}



The issue I see to be having is after my code completes the first function call to similarityScore it seems to be stuck in that function and does not call the other functions within the main(). Have I called the functions incorrectly within main()?

Or .... if the functions are being called and executed, why do they not display the results?


Any possible help would be greatly appreciated, thank you.
Last edited on
1
2
3
4
5
float similarityScore(string sequence1, string sequence2) {
  cout << "Enter first sequence: ";
  cin >> sequence1;
  cout << "Enter second sequence: ";
  cin >> sequence2;
explain why do you override your parameters.
Those kind of errors can be detected early when you develop correctly and look for mistakes within your code.
You have a lot of tutorials on the web to help you do that. It also looks like you can use some programs to help you do that.
I got an advise once to use Checkmarx to detect vulnerabilities in the code, you can try it out.
Good luck.
Registered users can post here. Sign in or register to post.