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 #include "mussa_nway.hh"
14 Nway_Paths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
17 int win_i, sp_i, sp_depth, window_num;
18 bool some_matches, still_paths, not_advanced;
20 vector<list<int> > all_matches;
21 vector<list<int>::iterator> sp_nodes, sp_nodes_end;
22 list<int>::iterator debug_i;
25 window_num = all_comparisons[0][1].win_num();
26 cout << window_num << endl; // just a sanity check
28 sp_nodes.reserve(species_num);
29 sp_nodes_end.reserve(species_num);
31 // loop thru all windows in first species
32 for (win_i = 0; win_i < window_num; win_i++)
34 // first we see if the first seq has matches to all other seqs at this win
38 while ( (sp_i < species_num) && (some_matches) )
41 new_nodes = all_comparisons[0][sp_i].matches(win_i);
42 if (new_nodes.empty())
45 all_matches.push_back(new_nodes);
52 cout << win_i << " plrf" << endl;
53 for (sp_i = 0; sp_i < species_num-1; sp_i++)
55 debug_i = all_matches[sp_i].begin();
56 while (debug_i != all_matches[sp_i].end())
58 cout << *debug_i << " ";
61 cout << "plrfff"<< endl;
65 // if 1st seq does match to all others, make all possible paths
66 // out of all these matches
71 // set each species list of matches to beginning
72 for (sp_i = 0; sp_i < species_num-1; sp_i++)
74 sp_nodes.push_back(all_matches[sp_i].begin());
75 sp_nodes_end.push_back(all_matches[sp_i].end());
79 sp_depth = species_num - 2; // this roves up & down species list
83 // add path that each species iterator is pointing to
85 path.push_back(win_i);
88 for (sp_i = 0; sp_i < species_num-1; sp_i++)
90 //cout << ", " << *(sp_nodes[sp_i]);
91 path.push_back(*(sp_nodes[sp_i]));
95 pathz.push_back(path);
97 // now advance the right iterator
99 while ( (not_advanced) && (sp_depth != -1) )
102 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
103 (sp_nodes[sp_depth])++; // advance iter at current depth
104 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
106 // if we reached the end of the list, reset iter & go up one depth
107 if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
110 sp_nodes[sp_depth] = all_matches[sp_depth].begin();
112 //cout << "depth = " << sp_depth << endl;
115 not_advanced = false;
118 if (sp_depth == -1) // jumped up to first species, all paths searched
120 else // otherwise just reset to max depth and continue
121 sp_depth = species_num - 2;
131 Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
134 int win_i, sp_i, sp_depth, window_num, i, cur_node;
135 bool some_matches, still_paths, not_advanced, trans_good;
136 list<int> new_nodes, trans_check_nodes;
137 vector<list<int> > all_matches;
138 vector<list<int>::iterator> sp_nodes, sp_nodes_end;
139 list<int>::iterator debug_i;
141 cout << "trans: softhres = " << soft_thres;
142 cout << ", window = " << win_size << ", ";
145 window_num = all_comparisons[0][1].win_num();
146 cout << "window number = " << window_num << endl; // just a sanity check
147 cout << "trans: species_num = " << species_num << endl;
148 sp_nodes.reserve(species_num);
149 cout << "trans: fie\n";
150 sp_nodes_end.reserve(species_num);
151 cout << "trans: foe\n";
152 // loop thru all windows in first species
153 for (win_i = 0; win_i < window_num; win_i++)
155 // first we see if the first seq has matches to all other seqs at this win
159 while ( (sp_i < species_num) && (some_matches) )
163 //new_nodes = all_comparisons[0][sp_i].matches(win_i);
164 new_nodes = all_comparisons[0][sp_i].thres_matches(win_i, soft_thres);
165 if (new_nodes.empty())
166 some_matches = false;
168 all_matches.push_back(new_nodes);
175 cout << win_i << " plrf" << endl;
176 for (sp_i = 0; sp_i < species_num-1; sp_i++)
178 debug_i = all_matches[sp_i].begin();
179 while (debug_i != all_matches[sp_i].end())
181 cout << *debug_i << " ";
184 cout << "plrfff"<< endl;
188 // if 1st seq does match to all others, make all possible paths
189 // out of all these matches
193 sp_nodes_end.clear();
194 // set each species list of matches to beginning
195 for (sp_i = 0; sp_i < species_num-1; sp_i++)
197 sp_nodes.push_back(all_matches[sp_i].begin());
198 sp_nodes_end.push_back(all_matches[sp_i].end());
205 // add path that each species iterator is pointing to
207 path.push_back(win_i);
210 for (sp_i = 0; sp_i < species_num-1; sp_i++)
212 //cout << ", " << *(sp_nodes[sp_i]);
213 path.push_back(*(sp_nodes[sp_i]));
217 // check transitivity
220 while ( (sp_depth != species_num-1) && (trans_good) )
222 cur_node = path[sp_depth];
223 for(i = sp_depth+1; i < species_num; i++)
226 //trans_check_nodes = all_comparisons[sp_depth][i].matches(cur_node);
228 all_comparisons[sp_depth][i].thres_matches(cur_node, soft_thres);
230 if ( (trans_check_nodes.end() == find(trans_check_nodes.begin(),
231 trans_check_nodes.end(),
233 (trans_check_nodes.end() == find(trans_check_nodes.begin(),
234 trans_check_nodes.end(),
243 pathz.push_back(path);
245 // now advance the right iterator
247 sp_depth = species_num - 2; // this roves up & down species list
248 while ( (not_advanced) && (sp_depth != -1) )
251 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
252 (sp_nodes[sp_depth])++; // advance iter at current depth
253 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
255 // if we reached the end of the list, reset iter & go up one depth
256 if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
259 sp_nodes[sp_depth] = all_matches[sp_depth].begin();
261 //cout << "depth = " << sp_depth << endl;
264 not_advanced = false;
267 if (sp_depth == -1) // jumped up to first species, all paths searched
269 else // otherwise just reset to max depth and continue
270 sp_depth = species_num - 2;
280 // loop thru all windows in first species
281 for (win_i = 0; win_i < window_num; win_i++)
284 path.push_back(win_i);
285 cur_nodes = all_comparisons[0][1].matches(path[0]);
286 cur_nodes_i = cur_nodes.begin();
287 cur_nodes_end = cur_nodes.end();
289 for (sp_i = 2; sp_i < species_num; sp_i++)
291 new_nodes = all_comparisons[0][sp_i].matches(path[0]);
292 new_nodes_i = new_nodes.begin();
293 new_nodes_end = new_nodes.end();
295 while(cur_nodes_i != cur_nodes_end)
297 intersect_bad = false;
298 if ( (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
300 (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
301 *cur_nodes_i * -1) ) )
302 intersect_bad = true;
304 // if no matches to this sequence, we don't need to check this node
305 // against any of the remaining ones
307 cur_nodes_i = cur_nodes.erase(cur_nodes_i); // this advances the iter
309 ++cur_nodes_i; // just advance normally
319 while(new_nodes_i != new_nodes_end)
322 path[1] = *new_nodes_i;
323 path_search(all_comparisons, path, 2);
326 //if (new_nodes_i != new_nodes_end)
327 //cout << "* species 0 node: " << win_i << endl;
328 // cout << "foookin hell\n";
330 //cout << " * species 1 node: " << *new_nodes_i << endl;
332 //cout << " * species " << depth << " node: " << *new_nodes_i << endl;
333 // check transitivity with previous nodes in path
337 Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path, int depth)
339 list<int> new_nodes, trans_check_nodes;
340 list<int>::iterator new_nodes_i, new_nodes_end;
343 new_nodes = all_comparisons[depth - 1][depth].matches(path[depth-1]);
344 new_nodes_i = new_nodes.begin();
345 new_nodes_end = new_nodes.end();
347 if (trans_check_good)
349 // this makes sure path nodes are recorded with RC status relative to
351 if ( path[depth-1] >= 0)
352 path.push_back(*new_nodes_i);
354 path.push_back(*new_nodes_i * -1);
356 if (depth < species_num - 1)
357 path_search(all_comparisons, path, depth + 1);
359 pathz.push_back(path);
366 // cout << " ****I have the power...\n";
368 /* use this if I ever get the friggin seqcomp match lists to sort...
369 if (binary_search(trans_check_nodes.begin(), trans_check_nodes.end(),