1 // ----------------------------------------
2 // ---------- mussa_nway.cc -----------
3 // ----------------------------------------
5 #include "mussa_nway.hh"
14 Nway_Paths::Nway_Paths()
19 Nway_Paths::setup(int sp_num)
27 Nway_Paths::path_search(vector<vector<FLPs> > all_comparisons, vector<int> path, int depth)
29 list<int> new_nodes, trans_check_nodes;
30 list<int>::iterator new_nodes_i, new_nodes_end;
32 bool trans_check_good;
34 new_nodes = all_comparisons[depth - 1][depth].matches(path[depth-1]);
35 new_nodes_i = new_nodes.begin();
36 new_nodes_end = new_nodes.end();
37 while(new_nodes_i != new_nodes_end)
39 //cout << " * species " << depth << " node: " << *new_nodes_i << endl;
40 // check transitivity with previous nodes in path
41 for(i = 0; i < depth - 1; i++)
43 trans_check_good = true;
44 trans_check_nodes = all_comparisons[i][depth].matches(path[i]);
45 if ( (trans_check_nodes.end() == find(trans_check_nodes.begin(),
46 trans_check_nodes.end(),
48 (trans_check_nodes.end() == find(trans_check_nodes.begin(),
49 trans_check_nodes.end(),
50 *new_nodes_i * -1) ) )
51 trans_check_good = false;
56 if ( path[depth-1] >= 0)
57 path.push_back(*new_nodes_i);
59 path.push_back(*new_nodes_i * -1);
60 if (depth < species_num - 1)
61 path_search(all_comparisons, path, depth + 1);
63 pathz.push_back(path);
69 // cout << " ****I have the power...\n";
71 /* use this if I ever get the friggin seqcomp match lists to sort...
72 if (binary_search(trans_check_nodes.begin(), trans_check_nodes.end(),
77 Nway_Paths::find_paths_r(vector<vector<FLPs> > all_comparisons)
80 int win_i, window_num;
82 list<int>::iterator new_nodes_i, new_nodes_end;
85 window_num = all_comparisons[0][1].win_num();
86 cout << window_num << endl;
87 // loop thru all windows in first species
88 for (win_i = 0; win_i < window_num; win_i++)
91 path.push_back(win_i);
92 new_nodes = all_comparisons[0][1].matches(path[0]);
93 new_nodes_i = new_nodes.begin();
94 new_nodes_end = new_nodes.end();
95 //if (new_nodes_i != new_nodes_end)
96 //cout << "* species 0 node: " << win_i << endl;
97 // cout << "foookin hell\n";
99 while(new_nodes_i != new_nodes_end)
101 //cout << " * species 1 node: " << *new_nodes_i << endl;
102 path[1] = *new_nodes_i;
103 path_search(all_comparisons, path, 2);
111 Nway_Paths::add_path(vector<int> loaded_path)
113 pathz.push_back(loaded_path);
118 Nway_Paths::save(string save_file_path)
121 list<vector<int> >::iterator path_i, paths_end;
125 save_file.open(save_file_path.c_str(), ios::out);
127 //save_file << "<Seqcomp type=" << ana_type << " win=" << window_size;
128 //save_file << " thres=" << hard_threshold << ">\n";
130 path_i = pathz.begin();
131 paths_end = pathz.end();
132 if (path_i == paths_end)
133 cout << "Arrrrrrgggghhhhhh\n";
134 while(path_i != paths_end)
137 //cout << a_path.size() << endl;
138 for(i = 0; i < species_num; ++i)
139 save_file << i << "," << a_path[i] << " ";
144 //save_file << "</Mussa>\n";
149 Nway_Paths::save_old(string save_file_path)
152 list<vector<int> >::iterator path_i, paths_end;
156 save_file.open(save_file_path.c_str(), ios::app);
158 path_i = pathz.begin();
159 paths_end = pathz.end();
160 while(path_i != paths_end)
163 //cout << a_path.size() << endl;
164 for(i = 0; i < species_num; ++i)
165 save_file << i << "," << a_path[i] << " ";
175 Nway_Paths::find_paths(vector<vector<FLPs> > all_comparisons)
178 vector<list<list<int> > > path_src_tree;
180 list<int>::iterator node_i, node_end;
181 <list<list<int> > >::iterator branch_i, branch_end;
184 path_src_tree.reserve(species_num - 1);
187 // loop thru all windows in first species
188 for (win_i = 0; win_i < window_num; win_i++)
190 // clear the path search tree
191 for(i = 0; i < species_num; i++)
192 path_src_tree[i].clear();
194 // top level kept empty even tho implicity has one entry of the first
195 // species at this window - why bother, adds a little speed
197 // get connection list for first species, creating a list of nodes
198 // of second species connected to the first species at this window
199 new_nodes = all_comparisons[0][1];
200 path_src_tree[1].push_back(new_nodes);
202 // loop thru rest of species for this window to see if any paths of matches
203 // go across all species
204 // if path search tree becomes empty, break out of loop, no reason to search further
206 while ((sp_i < species_num) && (path tree not empty))
208 branch_i = path_src_tree[1].begin();
209 branch_end = path_src_tree[1].end();
210 while (branch_i != branch_end)
212 node_i = branch_i->begin();
213 node_end = branch_i->end();
217 // loop over all current nodes
218 // get connection list for each node
219 // loop over each previous node in list
220 // get those nodes connection list
221 // intersect previous node connections with current
226 // insert any of the paths found into the master list of paths
228 // add no paths if tmp_pathz is empty...
232 void Nway_Paths::refine()
236 void Nway_Paths::print()
238 list<list<int> >::iterator pathz_i;
240 cout << "printing list of lists\n";
241 for (pathz_i = pathz.begin(); pathz_i != pathz.end(); ++pathz_i)
243 for (path_i = pathz_i->begin(); path_i != pathz_i->end(); ++path_i)
244 cout << *path_i << " ";