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"
17 Nway_Paths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
20 int win_i, sp_i, sp_depth, window_num;
21 bool some_matches, still_paths, not_advanced;
23 vector<list<int> > all_matches;
24 vector<list<int>::iterator> sp_nodes, sp_nodes_end;
25 list<int>::iterator debug_i;
28 window_num = all_comparisons[0][1].win_num();
29 cout << window_num << endl; // just a sanity check
31 sp_nodes.reserve(species_num);
32 sp_nodes_end.reserve(species_num);
34 // loop thru all windows in first species
35 for (win_i = 0; win_i < window_num; win_i++)
37 // first we see if the first seq has matches to all other seqs at this win
41 while ( (sp_i < species_num) && (some_matches) )
44 new_nodes = all_comparisons[0][sp_i].matches(win_i);
45 if (new_nodes.empty())
48 all_matches.push_back(new_nodes);
55 cout << win_i << " plrf" << endl;
56 for (sp_i = 0; sp_i < species_num-1; sp_i++)
58 debug_i = all_matches[sp_i].begin();
59 while (debug_i != all_matches[sp_i].end())
61 cout << *debug_i << " ";
64 cout << "plrfff"<< endl;
68 // if 1st seq does match to all others, make all possible paths
69 // out of all these matches
74 // set each species list of matches to beginning
75 for (sp_i = 0; sp_i < species_num-1; sp_i++)
77 sp_nodes.push_back(all_matches[sp_i].begin());
78 sp_nodes_end.push_back(all_matches[sp_i].end());
82 sp_depth = species_num - 2; // this roves up & down species list
86 // add path that each species iterator is pointing to
88 path.push_back(win_i);
91 for (sp_i = 0; sp_i < species_num-1; sp_i++)
93 //cout << ", " << *(sp_nodes[sp_i]);
94 path.push_back(*(sp_nodes[sp_i]));
98 pathz.push_back(path);
100 // now advance the right iterator
102 while ( (not_advanced) && (sp_depth != -1) )
105 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
106 (sp_nodes[sp_depth])++; // advance iter at current depth
107 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
109 // if we reached the end of the list, reset iter & go up one depth
110 if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
113 sp_nodes[sp_depth] = all_matches[sp_depth].begin();
115 //cout << "depth = " << sp_depth << endl;
118 not_advanced = false;
121 if (sp_depth == -1) // jumped up to first species, all paths searched
123 else // otherwise just reset to max depth and continue
124 sp_depth = species_num - 2;
134 Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
137 int win_i, sp_i, sp_depth, window_num, i, cur_node;
138 bool some_matches, still_paths, not_advanced, trans_good;
139 list<int> new_nodes, trans_check_nodes;
140 vector<list<int> > all_matches;
141 vector<list<int>::iterator> sp_nodes, sp_nodes_end;
142 list<int>::iterator debug_i;
144 cout << "trans: softhres = " << soft_thres;
145 cout << ", window = " << win_size << ", ";
148 window_num = all_comparisons[0][1].win_num();
149 cout << "window number = " << window_num << endl; // just a sanity check
150 cout << "trans: species_num = " << species_num << endl;
151 sp_nodes.reserve(species_num);
152 cout << "trans: fie\n";
153 sp_nodes_end.reserve(species_num);
154 cout << "trans: foe\n";
155 // loop thru all windows in first species
156 for (win_i = 0; win_i < window_num; win_i++)
158 // first we see if the first seq has matches to all other seqs at this win
162 while ( (sp_i < species_num) && (some_matches) )
166 //new_nodes = all_comparisons[0][sp_i].matches(win_i);
167 new_nodes = all_comparisons[0][sp_i].thres_matches(win_i, soft_thres);
168 if (new_nodes.empty())
169 some_matches = false;
171 all_matches.push_back(new_nodes);
178 cout << win_i << " plrf" << endl;
179 for (sp_i = 0; sp_i < species_num-1; sp_i++)
181 debug_i = all_matches[sp_i].begin();
182 while (debug_i != all_matches[sp_i].end())
184 cout << *debug_i << " ";
187 cout << "plrfff"<< endl;
191 // if 1st seq does match to all others, make all possible paths
192 // out of all these matches
196 sp_nodes_end.clear();
197 // set each species list of matches to beginning
198 for (sp_i = 0; sp_i < species_num-1; sp_i++)
200 sp_nodes.push_back(all_matches[sp_i].begin());
201 sp_nodes_end.push_back(all_matches[sp_i].end());
208 // add path that each species iterator is pointing to
210 path.push_back(win_i);
213 for (sp_i = 0; sp_i < species_num-1; sp_i++)
215 //cout << ", " << *(sp_nodes[sp_i]);
216 path.push_back(*(sp_nodes[sp_i]));
220 // check transitivity
223 while ( (sp_depth != species_num-1) && (trans_good) )
225 cur_node = path[sp_depth];
226 for(i = sp_depth+1; i < species_num; i++)
229 //trans_check_nodes = all_comparisons[sp_depth][i].matches(cur_node);
231 all_comparisons[sp_depth][i].thres_matches(cur_node, soft_thres);
233 if ( (trans_check_nodes.end() == find(trans_check_nodes.begin(),
234 trans_check_nodes.end(),
236 (trans_check_nodes.end() == find(trans_check_nodes.begin(),
237 trans_check_nodes.end(),
246 pathz.push_back(path);
248 // now advance the right iterator
250 sp_depth = species_num - 2; // this roves up & down species list
251 while ( (not_advanced) && (sp_depth != -1) )
254 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
255 (sp_nodes[sp_depth])++; // advance iter at current depth
256 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
258 // if we reached the end of the list, reset iter & go up one depth
259 if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
262 sp_nodes[sp_depth] = all_matches[sp_depth].begin();
264 //cout << "depth = " << sp_depth << endl;
267 not_advanced = false;
270 if (sp_depth == -1) // jumped up to first species, all paths searched
272 else // otherwise just reset to max depth and continue
273 sp_depth = species_num - 2;
283 // loop thru all windows in first species
284 for (win_i = 0; win_i < window_num; win_i++)
287 path.push_back(win_i);
288 cur_nodes = all_comparisons[0][1].matches(path[0]);
289 cur_nodes_i = cur_nodes.begin();
290 cur_nodes_end = cur_nodes.end();
292 for (sp_i = 2; sp_i < species_num; sp_i++)
294 new_nodes = all_comparisons[0][sp_i].matches(path[0]);
295 new_nodes_i = new_nodes.begin();
296 new_nodes_end = new_nodes.end();
298 while(cur_nodes_i != cur_nodes_end)
300 intersect_bad = false;
301 if ( (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
303 (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
304 *cur_nodes_i * -1) ) )
305 intersect_bad = true;
307 // if no matches to this sequence, we don't need to check this node
308 // against any of the remaining ones
310 cur_nodes_i = cur_nodes.erase(cur_nodes_i); // this advances the iter
312 ++cur_nodes_i; // just advance normally
322 while(new_nodes_i != new_nodes_end)
325 path[1] = *new_nodes_i;
326 path_search(all_comparisons, path, 2);
329 //if (new_nodes_i != new_nodes_end)
330 //cout << "* species 0 node: " << win_i << endl;
331 // cout << "foookin hell\n";
333 //cout << " * species 1 node: " << *new_nodes_i << endl;
335 //cout << " * species " << depth << " node: " << *new_nodes_i << endl;
336 // check transitivity with previous nodes in path
340 Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path, int depth)
342 list<int> new_nodes, trans_check_nodes;
343 list<int>::iterator new_nodes_i, new_nodes_end;
346 new_nodes = all_comparisons[depth - 1][depth].matches(path[depth-1]);
347 new_nodes_i = new_nodes.begin();
348 new_nodes_end = new_nodes.end();
350 if (trans_check_good)
352 // this makes sure path nodes are recorded with RC status relative to
354 if ( path[depth-1] >= 0)
355 path.push_back(*new_nodes_i);
357 path.push_back(*new_nodes_i * -1);
359 if (depth < species_num - 1)
360 path_search(all_comparisons, path, depth + 1);
362 pathz.push_back(path);
369 // cout << " ****I have the power...\n";
371 /* use this if I ever get the friggin seqcomp match lists to sort...
372 if (binary_search(trans_check_nodes.begin(), trans_check_nodes.end(),