1 // ----------------------------------------
2 // ---------- flp_seqcomp.cc -----------
3 // ----------------------------------------
7 // Titus thinks the start of an RC window should be its "rear" in the
8 // normal version of the sequence. He's wrong, of course, and in the
9 // future my followers will annihilate his in the Final Battle, but for
10 // now I'll let him have his way.
11 // note seq2_i is actually the index of the leaving bp, so need to +1
14 FLPs::add(int seq1_i, int seq2_i, int a_score, int i2_offset)
19 if (a_score >= hard_threshold)
21 a_match.index = seq2_i + i2_offset;
22 a_match.score = a_score;
24 all_matches[seq1_i].push_back(a_match);
30 FLPs::seqcomp(string sseq1, string sseq2, bool is_RC)
32 int start_i, seq1_i, seq2_i, win_i; // loop variables
33 int matches; // number of matches in to a window
38 seq1 = (char *) sseq1.c_str();
39 seq2 = (char *) sseq2.c_str();
43 i2_offset = window_size - seq2_length;
48 // loop thru the start positions for sequence 1
49 for(start_i = 0; start_i < seq1_win_num; start_i++)
52 // compare initial window
53 for(win_i = 0; win_i < window_size; win_i++)
54 if ((seq1[start_i+win_i] == seq2[win_i]) &&
55 (seq1[start_i+win_i] != 'N')) // N's match nothing **
58 //seq2_i is always 0 for initial win
61 // call inlined function that adds match if it is above threshold
62 add(start_i, seq2_i, matches, i2_offset);
64 // run through rest of seq1 and seq2 with current seq1 offset (ie start_i)
65 // compare the bps leaving and entering the window and modify matches count
67 while( (seq1_i < seq1_win_num-1) && (seq2_i < seq2_win_num-1) )
69 // copmpare the bp leaving the window
70 if ((seq1[seq1_i] == seq2[seq2_i]) &&
71 (seq1[seq1_i] != 'N')) // N's match nothing
74 // compare the bp entering the window
75 if ((seq1[seq1_i+window_size] == seq2[seq2_i+window_size]) &&
76 (seq1[seq1_i+window_size] != 'N')) // N's match nothing
77 matches = matches + 1;
79 add(seq1_i + 1, seq2_i + 1, matches, i2_offset);
81 seq1_i = seq1_i + 1; // increment seq1_i to next window
82 seq2_i = seq2_i + 1; // increment seq2_i to next window
83 } // end of loop thru the current offset sequence
84 } // end of loop thru the start positions of seq1 sequence
86 // loop thru the start positions for sequence 1
87 for(start_i = 1; start_i < seq2_win_num; start_i++)
91 // compare initial window
92 for(win_i = 0; win_i < window_size; win_i++)
93 if ((seq2[start_i+win_i] == seq1[win_i]) &&
94 (seq2[start_i+win_i] != 'N')) // N's match nothing
97 //seq2_i is always start_i for initial window
100 add(0, seq2_i, matches, i2_offset);
102 // run through rest of seq1 and seq2 with current seq1 offset (ie start_i)
103 // compare the bps leaving and entering the window and modify matches count
105 while( (seq1_i < seq1_win_num-1) && (seq2_i < seq2_win_num-1) )
107 // copmpare the bp leaving the window
108 if ((seq1[seq1_i] == seq2[seq2_i]) &&
109 (seq1[seq1_i] != 'N')) // N's match nothing
110 matches = matches - 1;
112 // compare the bp entering the window
113 if ((seq1[seq1_i+window_size] == seq2[seq2_i+window_size]) &&
114 (seq1[seq1_i+window_size] != 'N')) // N's match nothing
115 matches = matches + 1;
117 add(seq1_i + 1, seq2_i + 1, matches, i2_offset);
119 seq1_i = seq1_i + 1; // increment seq1_i to next window
120 seq2_i = seq2_i + 1; // increment seq2_i to next window
121 } // end of loop thru the current offset sequence
122 } // end of loop thru the start positions of seq2 sequence