7 #include "qui/MussaAlignedWindow.hpp"
8 #include "alg/sequence.hpp"
12 MussaAlignedWindow::MussaAlignedWindow(Mussa& m,
13 const set<int>& sel_paths,
17 //selected_paths(sel_paths)
20 browser.setSequences(analysis.sequences(), analysis.colorMapper());
21 setSelectedPaths(m, sel_paths);
23 browser.zoomToSequence();
26 QVBoxLayout *layout = new QVBoxLayout;
27 layout->addWidget(&browser);
28 layout->addWidget(&status);
31 ostringstream message;
32 message << "Selected " << selected_paths.size() << " paths";
33 status.showMessage(message.str().c_str(), 5000);
37 void MussaAlignedWindow::setSelectedPaths(Mussa &m, const set<int>& sel_paths)
40 set<int>::iterator sel_i = sel_paths.begin();
41 list<ExtendedConservedPath>::const_iterator path_i = m.paths().rpbegin();
42 list<ExtendedConservedPath>::const_iterator path_end = m.paths().rpend();
43 size_t path_size = m.paths().refined_pathz.size();
46 selected_paths.reserve(sel_paths.size());
47 while (pathid != path_size and sel_i != sel_paths.end())
50 size_t sel_pathid = (size_t)(*sel_i);
51 if (pathid == sel_pathid) {
52 cout << "found one " << *path_i << endl;
53 selected_paths.push_back(*path_i);
57 } else if (pathid < sel_pathid) {
60 } else if (pathid > sel_pathid) {
66 void MussaAlignedWindow::setAlignment(size_t alignment_index)
68 if (selected_paths.size() > 0) {
69 browser.centerOnPath(selected_paths[alignment_index].track_indexes);
73 void MussaAlignedWindow::computeMatchLines()
75 const vector<Sequence>& raw_sequence = analysis.sequences();
76 vector<int> aligned_path;
79 int window_length, win_i;
89 for(vector<ExtendedConservedPath >::iterator pathz_i=selected_paths.begin();
90 pathz_i != selected_paths.end();
93 if (true /* show_aligns[align_counter] */)
95 ExtendedConservedPath& a_path = *pathz_i;
96 window_length = a_path.window_size;
97 // determine which parts of the path are RC relative to first species
98 rc_list = a_path.reverseComplimented();
100 // loop over each bp in the conserved region for all sequences
101 for(win_i = 0; win_i < window_length; win_i++)
103 aligned_path.clear();
104 // determine which exact base pairs match between the sequences
106 for(i2 = 0; i2 < a_path.size()-1; i2++)
108 // assume not rc as most likely, adjust below
111 // no matter the case, any RC node needs adjustments
113 rc_1 = window_length-1;
114 if (a_path[i2+1] < 0)
115 rc_2 = window_length-1;
117 x_start = (abs(a_path[i2]-rc_1+win_i));
118 x_end = (abs(a_path[i2+1]-rc_2+win_i));
121 // ugh, and xor...only want rc coloring if just one of the nodes is rc
122 // if both nodes are rc, then they are 'normal' relative to each other
123 if ( ( rc_list[i2] || rc_list[i2+1] ) &&
124 !(rc_list[i2] && rc_list[i2+1] ) )
125 { //the hideous rc matching logic - not complex, but annoying
126 if ( !( ( (raw_sequence[i2][x_start] == 'A') &&
127 (raw_sequence[i2+1][x_end] == 'T') ) ||
128 ( (raw_sequence[i2][x_start] == 'T') &&
129 (raw_sequence[i2+1][x_end] == 'A') ) ||
130 ( (raw_sequence[i2][x_start] == 'G') &&
131 (raw_sequence[i2+1][x_end] == 'C') ) ||
132 ( (raw_sequence[i2][x_start] == 'C') &&
133 (raw_sequence[i2+1][x_end] == 'G') ) ) )
138 if (!( (raw_sequence[i2][x_start] == raw_sequence[i2+1][x_end]) &&
139 (raw_sequence[i2][x_start] != 'N') &&
140 (raw_sequence[i2+1][x_end] != 'N') ) )
145 // draw for matches stretching across all sequences
148 //fl_line_style(FL_SOLID, 1, NULL);
150 // now can draw the line for each bp in this window that matches
151 // grrr, need to ask if anyone cares if I switch the seq
155 for(i2 = 0; i2 < a_path.size()-1; i2++)
157 // assume not rc as most likely, adjust below
160 // no matter the case, any RC node needs adjustments
163 rc_1 = window_length;
167 rc_2 = window_length;
170 // set offset based on current alignment for which bp to show
171 //offset1 = seq_align_offsets[i2];
172 //offset2 = seq_align_offsets[i2+1];
174 if ( ( rc_list[i2] || rc_list[i2+1] ) &&
175 !(rc_list[i2] && rc_list[i2+1] ) ) {
183 // maybe shouldn't recalc these, but store values from first loop
184 x_start = (abs((int) (a_path[i2]-rc_1+win_i)));
185 x_end = (abs((int) (a_path[i2+1]-rc_2+win_i)));
186 aligned_path.push_back(x_start);
187 // if we're on the last time through the loop, save x_end too
188 if (i2 == a_path.size()-2) {
189 aligned_path.push_back(x_end);
193 if (aligned_path.size() > 0) {
194 browser.link(aligned_path, rc_list,1);