9 #include "qui/MussaAlignedWindow.hpp"
10 #include "alg/sequence.hpp"
15 MussaAlignedWindow::MussaAlignedWindow(MussaRef m,
16 boost::shared_ptr<QDir> default_dir_,
17 const set<int>& sel_paths,
18 SubanalysisWindowRef window,
20 : QMainWindow(parent),
22 default_dir(default_dir_),
23 subanalysis_window(window),
25 pick_align_menu(tr("Choose Alignment")),
26 view_align_menu(tr("View Alignment")),
32 connect(&browser, SIGNAL(basepairsCopied(size_t)),
33 this, SLOT(showBasePairsCopied(size_t)));
34 browser.setSequences(analysis->sequences(), analysis->colorMapper());
35 setSelectedPaths(analysis, sel_paths);
37 double zoom_level = browser.zoomToSequence();
39 zoom = new ZoomWidget();
40 connect(zoom, SIGNAL(valueChanged(double)),
41 &browser, SLOT(setZoom(double)));
42 zoom->setValue(zoom_level);
45 setupAlignmentMenus();
47 setCentralWidget(&browser);
49 // Add a threhold widget set to our current threshold and make it readonly
50 threshold_widget = new ThresholdWidget;
51 threshold_widget->setRange(analysis->get_threshold(),analysis->get_window());
52 threshold_widget->setBasepairThreshold(analysis->get_soft_threshold());
53 threshold_widget->setReadOnly(true);
55 alignTB = new QToolBar();
56 alignTB->addWidget(zoom);
57 alignTB->addWidget(threshold_widget);
60 ostringstream message;
61 message << "Selected " << selected_paths.size() << " paths";
62 statusBar()->showMessage(message.str().c_str(), 5000);
63 browser.updatePosition();
68 void MussaAlignedWindow::setupActions()
70 // more cut-n-paste from MussaWindow
71 createSubAnalysisAction = new QAction(tr("Add to Subanalysis"), this);
72 connect(createSubAnalysisAction, SIGNAL(triggered()),
73 this, SLOT(createSubAnalysis()));
75 //Save pixel map action
76 saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
77 connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
78 &browser, SLOT(promptSaveBrowserPixmap()));
79 saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png"));
82 void MussaAlignedWindow::setupMenus()
84 QMenu *newMenu = menuBar()->addMenu(tr("&File"));
85 newMenu->addAction(saveBrowserPixmapAction);
87 newMenu = menuBar()->addMenu(tr("&Edit"));
88 newMenu->addAction(browser.getCopySelectedSequenceAsStringAction());
89 newMenu->addAction(browser.getCopySelectedSequenceAsFastaAction());
90 newMenu->addAction(createSubAnalysisAction);
92 // add some extra features to the context menu
93 QMenu *popupMenu = browser.getPopupMenu();
95 popupMenu->addAction(createSubAnalysisAction);
99 void MussaAlignedWindow::setupAlignmentMenus()
101 pick_align_menu.clear();
102 view_align_menu.clear();
103 pick_actions.clear();
104 view_actions.clear();
106 for(vector<ConservedPath >::iterator pathz_i=selected_paths.begin();
107 pathz_i != selected_paths.end();
110 ConservedPath::path_type normalized_path = pathz_i->normalizedIndexes();
111 ostringstream menu_text;
112 menu_text << pathz_i->window_size << ":";
113 ConservedPath::iterator element_i = normalized_path.begin();
114 menu_text << *element_i++;
116 element_i != normalized_path.end();
120 menu_text << *element_i;
122 int index = pathz_i - selected_paths.begin();
123 IntAction *pick = new IntAction(QString(menu_text.str().c_str()), index, this);
124 connect(pick, SIGNAL(triggered(int)), this, SLOT(setAlignment(int)));
125 pick_actions.push_back(pick);
126 pick_align_menu.addAction(pick);
127 IntAction *view = new IntAction(QString(menu_text.str().c_str()), index, this);
128 connect(view, SIGNAL(triggered(int)), this, SLOT(toggleViewAlignment(int)));
129 view->setCheckable(true);
130 view->setChecked(true);
131 view_actions.push_back(view);
132 view_align_menu.addAction(view);
135 menuBar()->addMenu(&pick_align_menu);
136 menuBar()->addMenu(&view_align_menu);
140 void MussaAlignedWindow::setSelectedPaths(MussaRef m, const set<int>& sel_paths)
143 set<int>::iterator sel_i = sel_paths.begin();
144 list<ConservedPath>::const_iterator path_i = m->paths().refined_pathz.begin();
145 list<ConservedPath>::const_iterator path_end = m->paths().refined_pathz.end();
146 size_t path_size = m->paths().refined_pathz.size();
149 selected_paths.reserve(sel_paths.size());
150 view_paths.reserve(sel_paths.size());
151 while (pathid != path_size and sel_i != sel_paths.end())
153 assert (*sel_i >= 0);
154 size_t sel_pathid = (size_t)(*sel_i);
155 if (pathid == sel_pathid) {
156 selected_paths.push_back(*path_i);
157 view_paths.push_back(true);
161 } else if (pathid < sel_pathid) {
164 } else if (pathid > sel_pathid) {
170 // FIXME: this is a cut-n-paste from MussaWindow, perhaps they should be refactored to
172 void MussaAlignedWindow::createSubAnalysis()
174 list<SequenceLocation> result;
175 SequenceLocationModel& model = subanalysis_window->getModel();
176 browser.copySelectedTracksAsSeqLocation(result);
177 for(list<SequenceLocation>::iterator result_itor = result.begin();
178 result_itor != result.end();
181 model.push_back(*result_itor);
184 if (not subanalysis_window->isVisible()) {
185 subanalysis_window->show();
189 void MussaAlignedWindow::setAlignment(int alignment_index)
191 if (selected_paths.size() > 0) {
192 browser.centerOnPath(selected_paths[alignment_index].normalizedIndexes());
196 void MussaAlignedWindow::showBasePairsCopied(size_t bp_copied)
198 QString msg("Copied ");
200 num.setNum(bp_copied);
201 msg += num + " base pairs";
202 statusBar()->showMessage(msg, 5000);
205 void MussaAlignedWindow::toggleViewAlignment(int alignment_index)
207 view_paths[alignment_index]= not view_paths[alignment_index];
208 // perhaps it'd be better if we could erase specific sets
209 // of matches instead of erasing them all and recomputing them all
210 // but this is easier
214 void MussaAlignedWindow::update()
219 void MussaAlignedWindow::updateTitle()
221 std::string title("Sequence View: ");
223 title += analysis->get_title();
225 setWindowTitle(title.c_str());
228 void MussaAlignedWindow::computeMatchLines()
230 browser.clear_links();
232 // filter out conserved paths
233 list<ConservedPath> filtered_paths;
234 vector<ConservedPath>::iterator path_i = selected_paths.begin();
235 list<ConservedPath::path_type> result;
236 list<vector<bool> > reversed;
238 for(vector<ConservedPath>::size_type count = 0;
239 count != selected_paths.size();
242 if (view_paths[count])
243 filtered_paths.push_back(*path_i);
245 analysis->createLocalAlignment(filtered_paths.begin(),
246 filtered_paths.end(),
250 list<ConservedPath::path_type>::const_iterator result_i = result.begin();
251 list<vector<bool> >::const_iterator reversed_i = reversed.begin();
252 for(int i = 0; i != result.size(); ++i, ++result_i, ++reversed_i)
254 // make 1 base long links
255 browser.link(*result_i, *reversed_i, 1);