1 // This file is part of the Mussa source distribution.
2 // http://mussa.caltech.edu/
3 // Contact author: Tristan De Buysscher, tristan@caltech.edu
5 // This program and all associated source code files are Copyright (C) 2005
6 // the California Institute of Technology, Pasadena, CA, 91125 USA. It is
7 // under the GNU Public License; please see the included LICENSE.txt
8 // file for more information, or contact Tristan directly.
11 // ----------------------------------------
12 // ---------- flp.cc -----------
13 // ----------------------------------------
27 FLPs::setup(string type, int win_size, int hard_thres, int len1, int len2)
29 list<match> empty_match_list;
32 window_size = win_size;
33 hard_threshold = hard_thres;
37 seq1_win_num = seq1_length - win_size + 1;
38 seq2_win_num = seq2_length - win_size + 1;
39 all_matches.reserve(seq1_win_num);
41 empty_match_list.clear();
42 for(i = 0; i < seq1_win_num; i++)
43 all_matches.push_back(empty_match_list);
54 FLPs::match_less(match *match1, match *match2)
56 if (match1->score < match2->score)
58 else if ( (match1->score == match2->score) &&
59 (match1->index < match2->index) )
70 for(i = 0; i < seq1_win_num; i++)
71 if (!all_matches[i].empty())
72 all_matches[i].sort(&FLPs::match_less);
77 FLPs::matches(int index)
79 list<int> these_matches;
80 list<match>::iterator list_i, list_end;
83 list_i = all_matches[index].begin();
84 list_end = all_matches[index].end();
85 //if (list_i == list_end)
86 //cout << "its fuckin empty!!!!";
87 while (list_i != list_end)
89 these_matches.push_back(list_i->index);
90 //cout << list_i->index << " ";
99 FLPs::thres_matches(int index, int thres)
101 list<int> thres_matches;
102 list<match>::iterator list_i, list_end;
105 list_i = all_matches[index].begin();
106 list_end = all_matches[index].end();
107 thres_matches.clear();
109 //if (list_i == list_end)
110 //cout << "its fuckin empty!!!!";
111 while (list_i != list_end)
113 if (list_i->score >= thres)
114 thres_matches.push_back(list_i->index);
115 //cout << list_i->index << " ";
121 return thres_matches;
126 FLPs::file_save(string save_file_path)
129 list<match>::iterator match_i, match_list_end;
132 save_file.open(save_file_path.c_str(), ios::out);
134 save_file << "<Seqcomp type=" << ana_type << " win=" << window_size;
135 save_file << " thres=" << hard_threshold << ">\n";
137 for(i = 0; i < seq1_win_num; i++)
139 if (!all_matches[i].empty())
141 match_i = all_matches[i].begin();
142 match_list_end = all_matches[i].end();
143 while (match_i != match_list_end)
145 save_file << match_i->index << "," << match_i->score << " ";
152 save_file << "</Seqcomp>\n";
158 FLPs::file_load(string file_path)
161 string file_data, file_data_line, pair_data, index_data, score_data;
162 int type, window, hard_thres;
164 string::size_type split_index, comma_index;
165 bool tag_open = false;
166 list<match> a_match_list;
174 data_file.open(file_path.c_str(), ios::in);
176 getline(data_file,file_data_line);
177 // parse seqcomp open tag and parameters
178 // eg <Seqcomp type=mussa win=30 thres=21>
179 // if parse successful...
182 while ((!data_file.eof()) && tag_open)
184 // intialize list to empty
185 a_match_list.clear();
187 getline(data_file,file_data_line);
189 if (file_data_line == "</Seqcomp>")
191 // parse line of matches
192 else if (file_data_line == "")
194 //cout << "empty line\n";
195 all_matches.push_back(a_match_list);
199 split_index = file_data_line.find(" ");
201 while (split_index != string::npos)
203 pair_data = file_data_line.substr(0,split_index);
204 file_data_line = file_data_line.substr(split_index+1);
205 //cout << "pair_data = " << pair_data << "...";
206 // parse out the 2 pieces of data, index and score of pair match
207 comma_index = pair_data.find(",");
208 index_data = pair_data.substr(0, comma_index);
209 a_match.index = atoi(index_data.c_str() );
210 score_data = pair_data.substr(comma_index+1);
211 a_match.score = atoi(score_data.c_str() );
213 //cout << a_match.index << "," << a_match.score << " ";
215 a_match_list.push_back(a_match);
217 split_index = file_data_line.find(" ");
220 all_matches.push_back(a_match_list);
223 seq1_win_num = all_matches.size();
224 cout << "windows in flp = " << all_matches.size() << endl;