1 #include "mussa_nway.hh"
4 Nway_Paths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
7 int win_i, sp_i, sp_depth, window_num;
8 bool some_matches, still_paths, not_advanced;
10 vector<list<int> > all_matches;
11 vector<list<int>::iterator> sp_nodes, sp_nodes_end;
12 list<int>::iterator debug_i;
15 window_num = all_comparisons[0][1].win_num();
16 cout << window_num << endl; // just a sanity check
18 sp_nodes.reserve(species_num);
19 sp_nodes_end.reserve(species_num);
21 // loop thru all windows in first species
22 for (win_i = 0; win_i < window_num; win_i++)
24 // first we see if the first seq has matches to all other seqs at this win
28 while ( (sp_i < species_num) && (some_matches) )
31 new_nodes = all_comparisons[0][sp_i].matches(win_i);
32 if (new_nodes.empty())
35 all_matches.push_back(new_nodes);
42 cout << win_i << " plrf" << endl;
43 for (sp_i = 0; sp_i < species_num-1; sp_i++)
45 debug_i = all_matches[sp_i].begin();
46 while (debug_i != all_matches[sp_i].end())
48 cout << *debug_i << " ";
51 cout << "plrfff"<< endl;
55 // if 1st seq does match to all others, make all possible paths
56 // out of all these matches
61 // set each species list of matches to beginning
62 for (sp_i = 0; sp_i < species_num-1; sp_i++)
64 sp_nodes.push_back(all_matches[sp_i].begin());
65 sp_nodes_end.push_back(all_matches[sp_i].end());
69 sp_depth = species_num - 2; // this roves up & down species list
73 // add path that each species iterator is pointing to
75 path.push_back(win_i);
78 for (sp_i = 0; sp_i < species_num-1; sp_i++)
80 //cout << ", " << *(sp_nodes[sp_i]);
81 path.push_back(*(sp_nodes[sp_i]));
85 pathz.push_back(path);
87 // now advance the right iterator
89 while ( (not_advanced) && (sp_depth != -1) )
92 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
93 (sp_nodes[sp_depth])++; // advance iter at current depth
94 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
96 // if we reached the end of the list, reset iter & go up one depth
97 if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
100 sp_nodes[sp_depth] = all_matches[sp_depth].begin();
102 //cout << "depth = " << sp_depth << endl;
105 not_advanced = false;
108 if (sp_depth == -1) // jumped up to first species, all paths searched
110 else // otherwise just reset to max depth and continue
111 sp_depth = species_num - 2;
121 Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
124 int win_i, sp_i, sp_depth, window_num, i, cur_node;
125 bool some_matches, still_paths, not_advanced, trans_good;
126 list<int> new_nodes, trans_check_nodes;
127 vector<list<int> > all_matches;
128 vector<list<int>::iterator> sp_nodes, sp_nodes_end;
129 list<int>::iterator debug_i;
131 cout << "trans: softhres = " << soft_thres;
132 cout << ", window = " << win_size << ", ";
135 window_num = all_comparisons[0][1].win_num();
136 cout << "window number = " << window_num << endl; // just a sanity check
137 cout << "trans: species_num = " << species_num << endl;
138 sp_nodes.reserve(species_num);
139 cout << "trans: fie\n";
140 sp_nodes_end.reserve(species_num);
141 cout << "trans: foe\n";
142 // loop thru all windows in first species
143 for (win_i = 0; win_i < window_num; win_i++)
145 // first we see if the first seq has matches to all other seqs at this win
149 while ( (sp_i < species_num) && (some_matches) )
153 //new_nodes = all_comparisons[0][sp_i].matches(win_i);
154 new_nodes = all_comparisons[0][sp_i].thres_matches(win_i, soft_thres);
155 if (new_nodes.empty())
156 some_matches = false;
158 all_matches.push_back(new_nodes);
165 cout << win_i << " plrf" << endl;
166 for (sp_i = 0; sp_i < species_num-1; sp_i++)
168 debug_i = all_matches[sp_i].begin();
169 while (debug_i != all_matches[sp_i].end())
171 cout << *debug_i << " ";
174 cout << "plrfff"<< endl;
178 // if 1st seq does match to all others, make all possible paths
179 // out of all these matches
183 sp_nodes_end.clear();
184 // set each species list of matches to beginning
185 for (sp_i = 0; sp_i < species_num-1; sp_i++)
187 sp_nodes.push_back(all_matches[sp_i].begin());
188 sp_nodes_end.push_back(all_matches[sp_i].end());
195 // add path that each species iterator is pointing to
197 path.push_back(win_i);
200 for (sp_i = 0; sp_i < species_num-1; sp_i++)
202 //cout << ", " << *(sp_nodes[sp_i]);
203 path.push_back(*(sp_nodes[sp_i]));
207 // check transitivity
210 while ( (sp_depth != species_num-1) && (trans_good) )
212 cur_node = path[sp_depth];
213 for(i = sp_depth+1; i < species_num; i++)
216 //trans_check_nodes = all_comparisons[sp_depth][i].matches(cur_node);
218 all_comparisons[sp_depth][i].thres_matches(cur_node, soft_thres);
220 if ( (trans_check_nodes.end() == find(trans_check_nodes.begin(),
221 trans_check_nodes.end(),
223 (trans_check_nodes.end() == find(trans_check_nodes.begin(),
224 trans_check_nodes.end(),
233 pathz.push_back(path);
235 // now advance the right iterator
237 sp_depth = species_num - 2; // this roves up & down species list
238 while ( (not_advanced) && (sp_depth != -1) )
241 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
242 (sp_nodes[sp_depth])++; // advance iter at current depth
243 //cout << sp_depth << ".." << *(sp_nodes[sp_depth]) << endl;
245 // if we reached the end of the list, reset iter & go up one depth
246 if (sp_nodes[sp_depth] == sp_nodes_end[sp_depth])
249 sp_nodes[sp_depth] = all_matches[sp_depth].begin();
251 //cout << "depth = " << sp_depth << endl;
254 not_advanced = false;
257 if (sp_depth == -1) // jumped up to first species, all paths searched
259 else // otherwise just reset to max depth and continue
260 sp_depth = species_num - 2;
270 // loop thru all windows in first species
271 for (win_i = 0; win_i < window_num; win_i++)
274 path.push_back(win_i);
275 cur_nodes = all_comparisons[0][1].matches(path[0]);
276 cur_nodes_i = cur_nodes.begin();
277 cur_nodes_end = cur_nodes.end();
279 for (sp_i = 2; sp_i < species_num; sp_i++)
281 new_nodes = all_comparisons[0][sp_i].matches(path[0]);
282 new_nodes_i = new_nodes.begin();
283 new_nodes_end = new_nodes.end();
285 while(cur_nodes_i != cur_nodes_end)
287 intersect_bad = false;
288 if ( (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
290 (new_nodes.end() == find(new_nodes.begin(), new_nodes.end(),
291 *cur_nodes_i * -1) ) )
292 intersect_bad = true;
294 // if no matches to this sequence, we don't need to check this node
295 // against any of the remaining ones
297 cur_nodes_i = cur_nodes.erase(cur_nodes_i); // this advances the iter
299 ++cur_nodes_i; // just advance normally
309 while(new_nodes_i != new_nodes_end)
312 path[1] = *new_nodes_i;
313 path_search(all_comparisons, path, 2);
316 //if (new_nodes_i != new_nodes_end)
317 //cout << "* species 0 node: " << win_i << endl;
318 // cout << "foookin hell\n";
320 //cout << " * species 1 node: " << *new_nodes_i << endl;
322 //cout << " * species " << depth << " node: " << *new_nodes_i << endl;
323 // check transitivity with previous nodes in path
327 Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path, int depth)
329 list<int> new_nodes, trans_check_nodes;
330 list<int>::iterator new_nodes_i, new_nodes_end;
333 new_nodes = all_comparisons[depth - 1][depth].matches(path[depth-1]);
334 new_nodes_i = new_nodes.begin();
335 new_nodes_end = new_nodes.end();
337 if (trans_check_good)
339 // this makes sure path nodes are recorded with RC status relative to
341 if ( path[depth-1] >= 0)
342 path.push_back(*new_nodes_i);
344 path.push_back(*new_nodes_i * -1);
346 if (depth < species_num - 1)
347 path_search(all_comparisons, path, depth + 1);
349 pathz.push_back(path);
356 // cout << " ****I have the power...\n";
358 /* use this if I ever get the friggin seqcomp match lists to sort...
359 if (binary_search(trans_check_nodes.begin(), trans_check_nodes.end(),