Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1.  
  2. // section 207
  3. //10-1-2017
  4.  
  5.  
  6.  
  7. #include <iostream>
  8. using namespace std;
  9. #include <string>
  10.  
  11. /*;
  12. Algorithm for part 1.
  13.  
  14. 1. Create the similarityScore function
  15. 2. Create two strings for the sequence inputs.
  16. 3. In the main function, ask the user to input the strings to be tested.
  17. 3. Compare the two strings, first to see if their lengths match, if not, return zero.
  18. 4. Calculate the Hamming distance by comparing the characters in each string , and set it to a float.
  19. 5. Calculate the similarity_score by taking the string length and subtracting the hamming distance,
  20. then dividing by the string length. Output the resultant value.
  21.  
  22. */
  23.  
  24. float similarityScore(string sequence1, string sequence2){
  25.  
  26. float sequence1Length = sequence1.length();
  27. float sequence2Length = sequence2.length();
  28.  
  29.  
  30. if (sequence1Length != sequence2Length){
  31. return 0;
  32. }
  33.  
  34.  
  35. //compare the stings to find mismatches.
  36. float Mismatches = 0.0;
  37.  
  38. for (int i=0; i< sequence1Length; i++){
  39.  
  40. if(!(sequence1[i] == sequence2[i])){
  41. Mismatches+1;
  42. }
  43.  
  44. }
  45.  
  46. //Return the similarity score
  47.  
  48. return (sequence1Length - Mismatches) / (sequence1Length);
  49. }
  50.  
  51. /* Part two
  52.  
  53. 1. Create a function named countMatches
  54. 2. Create two string parameters, one for the inputted genome string, and one for a string containing the sequence to find.
  55. 3. Create a float value to contain the minimum similarity score.
  56. 4. Compare the strings to each other, and compare if the total number of matches results in a score above the minimum score.\
  57. 5. Return the number of matches.
  58.  
  59. */
  60.  
  61. int countMatches(string imputGenome,string sequence, float minimumScore){
  62.  
  63. int matches = 0;
  64.  
  65. int sequenceLength = sequence.length();
  66.  
  67. for (int pos = 0; pos < imputGenome.length() - sequenceLength + 1; pos+1){ //pos refers to the position of the first character in the string.
  68. //Set it to 0 to use the search the whole string.
  69. float score = similarityScore(imputGenome.substr(pos, sequenceLength),sequence);
  70. if(score >= minimumScore){
  71. matches+1;
  72. }
  73.  
  74. return matches;
  75.  
  76. }
  77.  
  78. }
  79. /* Part 3
  80.  
  81. 1. Create a function findBestMatch
  82. 2. Use genome and sequence as parameters, and search for similarities.
  83. 3. Return the best match
  84. */
  85.  
  86. float findBestMatch(string genome, string seq) {
  87. float bestMatch = 0.0;
  88.  
  89. for (int pos = 0; pos < genome.length(); pos+1) {
  90. float score = similarityScore(genome.substr(pos, seq.length()), seq);
  91. if (score > bestMatch) {
  92. bestMatch = score;
  93. }
  94. }
  95.  
  96. return bestMatch;
  97. }
  98.  
  99. /* Part 3
  100. 1. Create a function to compare the three inputted genomes, and output a number to indicate which one is the best match with a given sequence.
  101. 2. Set the first genome, second genome, third genome, and input sequence as floats, calling the earlier function to find the best match.
  102. 4. Compare the score of each function with the other scores of the other functions.
  103. 3. Return 1,2,3 or zero depending on which genome matches the given sequence.
  104. */
  105.  
  106.  
  107. int findBestGenome(string genome1, string genome2, string genome3, string seq) {
  108.  
  109. float genome1Score = findBestMatch(genome1, seq);
  110.  
  111. float genome2Score = findBestMatch(genome2, seq);
  112.  
  113. float genome3Score = findBestMatch(genome3, seq);
  114.  
  115.  
  116.  
  117. if (genome1Score > genome2Score && genome1Score > genome3Score) {
  118. return 1;
  119.  
  120. }
  121. else if (genome2Score > genome1Score && genome2Score > genome3Score) {
  122. return 2;
  123. }
  124.  
  125. else if (genome3Score > genome1Score && genome3Score > genome2Score) {
  126. return 3;
  127.  
  128. }
  129. else {
  130. return 0; //return zero if more than one sequence has the same similarity score.
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement