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 // ----------------------------------------
23 FLPs::setup(string type, int win_size, int hard_thres, int len1, int len2)
25 list<match> empty_match_list;
28 window_size = win_size;
29 hard_threshold = hard_thres;
33 seq1_win_num = seq1_length - win_size + 1;
34 seq2_win_num = seq2_length - win_size + 1;
35 all_matches.reserve(seq1_win_num);
37 empty_match_list.clear();
38 for(i = 0; i < seq1_win_num; i++)
39 all_matches.push_back(empty_match_list);
50 FLPs::match_less(match *match1, match *match2)
52 if (match1->score < match2->score)
54 else if ( (match1->score == match2->score) &&
55 (match1->index < match2->index) )
66 for(i = 0; i < seq1_win_num; i++)
67 if (!all_matches[i].empty())
68 all_matches[i].sort(&FLPs::match_less);
73 FLPs::matches(int index)
75 list<int> these_matches;
76 list<match>::iterator list_i, list_end;
79 list_i = all_matches[index].begin();
80 list_end = all_matches[index].end();
81 //if (list_i == list_end)
82 //cout << "its fuckin empty!!!!";
83 while (list_i != list_end)
85 these_matches.push_back(list_i->index);
86 //cout << list_i->index << " ";
95 FLPs::thres_matches(int index, int thres)
97 list<int> thres_matches;
98 list<match>::iterator list_i, list_end;
101 list_i = all_matches[index].begin();
102 list_end = all_matches[index].end();
103 thres_matches.clear();
105 //if (list_i == list_end)
106 //cout << "its fuckin empty!!!!";
107 while (list_i != list_end)
109 if (list_i->score >= thres)
110 thres_matches.push_back(list_i->index);
111 //cout << list_i->index << " ";
117 return thres_matches;
122 FLPs::file_save(string save_file_path)
125 list<match>::iterator match_i, match_list_end;
128 save_file.open(save_file_path.c_str(), ios::out);
130 save_file << "<Seqcomp type=" << ana_type << " win=" << window_size;
131 save_file << " thres=" << hard_threshold << ">\n";
133 for(i = 0; i < seq1_win_num; i++)
135 if (!all_matches[i].empty())
137 match_i = all_matches[i].begin();
138 match_list_end = all_matches[i].end();
139 while (match_i != match_list_end)
141 save_file << match_i->index << "," << match_i->score << " ";
148 save_file << "</Seqcomp>\n";
154 FLPs::file_load(string file_path)
157 string file_data, file_data_line, pair_data, index_data, score_data;
158 int type, window, hard_thres;
160 string::size_type split_index, comma_index;
161 bool tag_open = false;
162 list<match> a_match_list;
170 data_file.open(file_path.c_str(), ios::in);
172 getline(data_file,file_data_line);
173 // parse seqcomp open tag and parameters
174 // eg <Seqcomp type=mussa win=30 thres=21>
175 // if parse successful...
178 while ((!data_file.eof()) && tag_open)
180 // intialize list to empty
181 a_match_list.clear();
183 getline(data_file,file_data_line);
185 if (file_data_line == "</Seqcomp>")
187 // parse line of matches
188 else if (file_data_line == "")
190 //cout << "empty line\n";
191 all_matches.push_back(a_match_list);
195 split_index = file_data_line.find(" ");
197 while (split_index != string::npos)
199 pair_data = file_data_line.substr(0,split_index);
200 file_data_line = file_data_line.substr(split_index+1);
201 //cout << "pair_data = " << pair_data << "...";
202 // parse out the 2 pieces of data, index and score of pair match
203 comma_index = pair_data.find(",");
204 index_data = pair_data.substr(0, comma_index);
205 a_match.index = atoi(index_data.c_str() );
206 score_data = pair_data.substr(comma_index+1);
207 a_match.score = atoi(score_data.c_str() );
209 //cout << a_match.index << "," << a_match.score << " ";
211 a_match_list.push_back(a_match);
213 split_index = file_data_line.find(" ");
216 all_matches.push_back(a_match_list);
219 seq1_win_num = all_matches.size();
220 cout << "windows in flp = " << all_matches.size() << endl;