1 // ----------------------------------------
2 // ---------- flp.cc -----------
3 // ----------------------------------------
13 FLPs::setup(string type, int win_size, int hard_thres, int len1, int len2)
15 list<match> empty_match_list;
18 window_size = win_size;
19 hard_threshold = hard_thres;
23 seq1_win_num = seq1_length - win_size + 1;
24 seq2_win_num = seq2_length - win_size + 1;
25 all_matches.reserve(seq1_win_num);
27 empty_match_list.clear();
28 for(i = 0; i < seq1_win_num; i++)
29 all_matches.push_back(empty_match_list);
40 FLPs::match_less(match *match1, match *match2)
42 if (match1->score < match2->score)
44 else if ( (match1->score == match2->score) &&
45 (match1->index < match2->index) )
56 for(i = 0; i < seq1_win_num; i++)
57 if (!all_matches[i].empty())
58 all_matches[i].sort(&FLPs::match_less);
63 FLPs::matches(int index)
65 list<int> these_matches;
66 list<match>::iterator list_i, list_end;
69 list_i = all_matches[index].begin();
70 list_end = all_matches[index].end();
71 //if (list_i == list_end)
72 //cout << "its fuckin empty!!!!";
73 while (list_i != list_end)
75 these_matches.push_back(list_i->index);
76 //cout << list_i->index << " ";
85 FLPs::thres_matches(int index, int thres)
87 list<int> thres_matches;
88 list<match>::iterator list_i, list_end;
91 list_i = all_matches[index].begin();
92 list_end = all_matches[index].end();
93 thres_matches.clear();
95 //if (list_i == list_end)
96 //cout << "its fuckin empty!!!!";
97 while (list_i != list_end)
99 if (list_i->score >= thres)
100 thres_matches.push_back(list_i->index);
101 //cout << list_i->index << " ";
107 return thres_matches;
112 FLPs::file_save(string save_file_path)
115 list<match>::iterator match_i, match_list_end;
118 save_file.open(save_file_path.c_str(), ios::out);
120 save_file << "<Seqcomp type=" << ana_type << " win=" << window_size;
121 save_file << " thres=" << hard_threshold << ">\n";
123 for(i = 0; i < seq1_win_num; i++)
125 if (!all_matches[i].empty())
127 match_i = all_matches[i].begin();
128 match_list_end = all_matches[i].end();
129 while (match_i != match_list_end)
131 save_file << match_i->index << "," << match_i->score << " ";
138 save_file << "</Seqcomp>\n";
144 FLPs::file_load(string file_path)
147 string file_data, file_data_line, pair_data, index_data, score_data;
148 int type, window, hard_thres;
150 string::size_type split_index, comma_index;
151 bool tag_open = false;
152 list<match> a_match_list;
160 data_file.open(file_path.c_str(), ios::in);
162 getline(data_file,file_data_line);
163 // parse seqcomp open tag and parameters
164 // eg <Seqcomp type=mussa win=30 thres=21>
165 // if parse successful...
168 while ((!data_file.eof()) && tag_open)
170 // intialize list to empty
171 a_match_list.clear();
173 getline(data_file,file_data_line);
175 if (file_data_line == "</Seqcomp>")
177 // parse line of matches
178 else if (file_data_line == "")
180 //cout << "empty line\n";
181 all_matches.push_back(a_match_list);
185 split_index = file_data_line.find(" ");
187 while (split_index != string::npos)
189 pair_data = file_data_line.substr(0,split_index);
190 file_data_line = file_data_line.substr(split_index+1);
191 //cout << "pair_data = " << pair_data << "...";
192 // parse out the 2 pieces of data, index and score of pair match
193 comma_index = pair_data.find(",");
194 index_data = pair_data.substr(0, comma_index);
195 a_match.index = atoi(index_data.c_str() );
196 score_data = pair_data.substr(comma_index+1);
197 a_match.score = atoi(score_data.c_str() );
199 //cout << a_match.index << "," << a_match.score << " ";
201 a_match_list.push_back(a_match);
203 split_index = file_data_line.find(" ");
206 all_matches.push_back(a_match_list);
209 seq1_win_num = all_matches.size();
210 cout << "windows in flp = " << all_matches.size() << endl;