trapper.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *                                                                             *
00003  *   Copyright (C) 2003  Erik Sjolund,  (<html>Erik Sj&ouml;lund</html>)       *
00004  *                       Center for Genomics and Bioinformatics,               *
00005  *                       Karolinska Institutet,                                *
00006  *                       Stockholm,                                            *
00007  *                       Sweden                                                *
00008  *                                                                             *
00009  *  Author: Erik Sjolund                                                       *
00010  *  Email: erik.sjolund@adivo.se                                               *
00011  *                                                                             *
00012  *******************************************************************************
00013  */
00014 
00015 
00016 // Qt includes
00017 #include <qvbox.h>
00018 #include <qaccel.h>
00019 #include <qinputdialog.h>
00020 #include <qstring.h>
00021 #include <qtextview.h>
00022 #include <qdir.h>
00023 #include <qlayout.h>
00024 #include <qtooltip.h>
00025 
00026 //stl
00027 #include <iostream>
00028 #include <set>
00029 #include <fstream>
00030 
00031 // application specific includes
00032 #include "trapperview.h"
00033 #include "trapperdoc.h"
00034 #include "trapper.h"
00035 #include "showmodesdlg.h"
00036 #include "trapperconf.h"
00037 #include "trapperparser.h"
00038 #include "macsimparser.h"
00039 #include "ChunkedXMLInputSource.h"
00040 
00041 #include "filenew.xpm"
00042 #include "fileopen.xpm"
00043 #include "filesave.xpm"
00044 #include "editselectall.xpm"
00045 // #include "zoom_plus.xpm"
00046 // #include "zoom_minus.xpm"
00047 #include "zoom_in.xpm"
00048 #include "zoom_out.xpm"
00049 #include "zoom_in_x.xpm"
00050 #include "zoom_out_x.xpm"
00051 #include "zoom_in_y.xpm"
00052 #include "zoom_out_y.xpm"
00053 #include "dbflush.xpm"
00054 #include "dragbutton.xpm"
00055 #include "pointerbutton.xpm"
00056 #include "tcview.xpm"
00057 #include "tcnorm.xpm"
00058 #include "left_arrow.xpm"
00059 #include "right_arrow.xpm"
00060 
00061 
00062 
00063 TrapperApp::TrapperApp()
00064 {
00065 //   qDebug("in TrapperApp::TrapperApp()");
00066   setCaption(tr("NGSView " "0.90" ) );
00067   dbenv = new DbEnv( DB_CXX_NO_EXCEPTIONS );
00068   
00069   //Should set these parameters more carefully, got them off the internet...
00070   //     dbenv->set_cachesize(0, 1000000, 0);
00071   dbenv->set_cachesize(0, 8388608, 8);
00072   dbenv->set_lg_regionmax(524288);
00073   dbenv->set_lg_bsize(2097152);
00074   
00075   //     printer = new QPrinter;
00076   untitledCount=0;
00077   pDocList = new QList<TrapperDoc>();
00078   pDocList->setAutoDelete(true);
00079   
00080   ///////////////////////////////////////////////////////////////////
00081   // call inits to invoke all other construction parts
00082   initView();
00083   initActions();
00084   initMenuBar();
00085   initToolBar();
00086   initStatusBar();
00087 //   resize( 450, 400 );
00088   showMaximized();
00089   
00090   viewToolBar->setOn(true);
00091   viewStatusBar->setOn(true);
00092   
00093   projectDir = QString::null;
00094   
00095   
00096   connect(pWorkspace, SIGNAL(windowActivated(QWidget*)), this, SLOT(slotActivatedWindow(QWidget*)));
00097   
00098   
00099 }
00100 
00101 TrapperApp::~TrapperApp()
00102 {
00103   //    delete printer;
00104   dbenv->close(0);
00105 }
00106 
00107 void TrapperApp::initActions()
00108 {
00109     QPixmap openIcon, saveIcon, newIcon, selectAllIcon, zoomPlusIcon, zoomMinusIcon,
00110       zoomPlusIconX, zoomPlusIconY, zoomMinusIconX, zoomMinusIconY, flushIcon, dragIcon, pointerIcon,
00111       tcViewIcon, tcNormIcon, leftArrowIcon, rightArrowIcon;
00112 
00113     newIcon = QPixmap(filenew);
00114     openIcon = QPixmap(fileopen);
00115     saveIcon = QPixmap(filesave);
00116     selectAllIcon = QPixmap( editselectall );
00117     zoomPlusIcon = QPixmap( zoom_in );
00118     zoomPlusIconX = QPixmap( zoom_in_x );
00119     zoomPlusIconY = QPixmap( zoom_in_y );
00120     zoomMinusIcon = QPixmap( zoom_out );
00121     zoomMinusIconX = QPixmap( zoom_out_x);
00122     zoomMinusIconY = QPixmap( zoom_out_y);
00123     flushIcon = QPixmap( dbflush );
00124     pointerIcon = QPixmap(pointerbutton);
00125     dragIcon = QPixmap(dragbutton);
00126     tcViewIcon = QPixmap(tcview);
00127     tcNormIcon = QPixmap(tcnorm);
00128     leftArrowIcon = QPixmap(left_arrow);
00129     rightArrowIcon = QPixmap(right_arrow);
00130 
00131 
00132     fileNew = new QAction(tr("New Project"), newIcon, tr("&New"), QAccel::stringToKey(tr("Ctrl+N")), this);
00133     fileNew->setStatusTip(tr("Creates a new project"));
00134     fileNew->setWhatsThis(tr("New Project\n\nCreates a new project"));
00135     connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
00136 
00137     fileOpen = new QAction(tr("Open Contig"), openIcon, tr("&Open..."), QAccel::stringToKey(tr("Ctrl+O")), this);
00138     fileOpen->setStatusTip(tr("Opens an existing contig or creates a new one"));
00139     fileOpen->setWhatsThis(tr("Open Contig\n\nOpens an existing contig or creates a new one. To create a new contig, simply create a new directory in the file dialog and choose it"));
00140     connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
00141 
00142     fileSave = new QAction(tr("Save File"), saveIcon, tr("&Save"), QAccel::stringToKey(tr("Ctrl+S")), this);
00143     fileSave->setStatusTip(tr("Saves the actual document"));
00144     fileSave->setWhatsThis(tr("Save File.\n\nSaves the actual document"));
00145     connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
00146 
00147     fileSaveAs = new QAction(tr("Save File As"), tr("Save &as..."), 0, this);
00148     fileSaveAs->setStatusTip(tr("Saves the actual document under a new filename"));
00149     fileSaveAs->setWhatsThis(tr("Save As\n\nSaves the actual document under a new filename"));
00150     connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSave()));
00151 
00152     fileClose = new QAction(tr("Close Project"), tr("&Close"), QAccel::stringToKey(tr("Ctrl+W")), this);
00153     fileClose->setStatusTip(tr("Closes the actual project"));
00154     fileClose->setWhatsThis(tr("Close Project\n\nCloses the actual project"));
00155     connect(fileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));
00156 
00157     filePrint = new QAction(tr("Print File"), tr("&Print"), QAccel::stringToKey(tr("Ctrl+P")), this);
00158     filePrint->setStatusTip(tr("Prints out the actual document"));
00159     filePrint->setWhatsThis(tr("Print File\n\nPrints out the actual document"));
00160     connect(filePrint, SIGNAL(activated()), this, SLOT(slotFilePrint()));
00161 
00162     fileQuit = new QAction(tr("Exit"), tr("E&xit"), QAccel::stringToKey(tr("Ctrl+Q")), this);
00163     fileQuit->setStatusTip(tr("Quits the application"));
00164     fileQuit->setWhatsThis(tr("Exit\n\nQuits the application"));
00165     connect(fileQuit, SIGNAL(activated()), this, SLOT(slotFileQuit()));
00166 
00167     fileFlush = new QAction(tr("Flush"), flushIcon, tr("&Flush"), QAccel::stringToKey(tr("Ctrl+F")), this);
00168     fileFlush->setStatusTip(tr("Flushes cached data"));
00169     fileFlush->setWhatsThis(tr("Flush\n\nFlushes cached data to database"));
00170 //     connect(fileFlush, SIGNAL(activated()), this, SLOT(slotFileFlush()));
00171 
00172     editCut = new QAction(tr("Cut"), tr("Cu&t"), QAccel::stringToKey(tr("Ctrl+X")), this);
00173     editCut->setStatusTip(tr("Cuts the selected section and puts it to the clipboard"));
00174     editCut->setWhatsThis(tr("Cut\n\nCuts the selected section and puts it to the clipboard"));
00175     connect(editCut, SIGNAL(activated()), this, SLOT(slotEditCut()));
00176 
00177     editCopy = new QAction(tr("Copy"), tr("&Copy"), QAccel::stringToKey(tr("Ctrl+C")), this);
00178     editCopy->setStatusTip(tr("Copies the selected section to the clipboard"));
00179     editCopy->setWhatsThis(tr("Copy\n\nCopies the selected section to the clipboard"));
00180     connect(editCopy, SIGNAL(activated()), this, SLOT(slotEditCopy()));
00181 
00182     editUndo = new QAction(tr("Undo last move"), tr("&Undo last move"), QAccel::stringToKey(tr("Ctrl+Z")), this);
00183     editUndo->setStatusTip(tr("Reverts the last move"));
00184     editUndo->setWhatsThis(tr("Undo\n\nReverts the last read moving action"));
00185     connect(editUndo, SIGNAL(activated()), this, SLOT(slotEditUndo()));
00186 
00187     editPaste = new QAction(tr("Paste"), tr("&Paste"), QAccel::stringToKey(tr("Ctrl+V")), this);
00188     editPaste->setStatusTip(tr("Pastes the clipboard contents to actual position"));
00189     editPaste->setWhatsThis(tr("Paste\n\nPastes the clipboard contents to actual position"));
00190     connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
00191 
00192     editSelectAll = new QAction(tr("Select All"), selectAllIcon, tr("Select &All"), QAccel::stringToKey(tr("Ctrl+A")), this);
00193     editSelectAll->setStatusTip(tr("Selects all reads"));
00194     editSelectAll->setWhatsThis(tr("Select All\n\nSelects all reads"));
00195     connect(editSelectAll, SIGNAL(activated()), this, SLOT(slotEditSelectAll()));
00196 
00197     editSelectBetween = new QAction(tr("Select Between rows"), tr("Select &Between rows"), 0, this);
00198     editSelectBetween->setStatusTip(tr("Selects all reads between two rows"));
00199     editSelectBetween->setWhatsThis(tr("Select Between rows\n\nSelects all reads between two rows"));
00200     connect(editSelectBetween, SIGNAL(activated()), this, SLOT(slotEditSelectBetween()));
00201 
00202     editSelectBetweenCols = new QAction(tr("Select Between cols"), tr("Select Between cols"), 0, this);
00203     editSelectBetweenCols->setStatusTip(tr("Selects all reads between two cols"));
00204     editSelectBetweenCols->setWhatsThis(tr("Select Between rows\n\nSelects all reads between two cols"));
00205     connect(editSelectBetweenCols, SIGNAL(activated()), this, SLOT(slotEditSelectBetweenCols()));
00206 
00207     editFindRead = new QAction(tr("Find Read"), tr("Find Read"), 0, this);
00208     editFindRead->setStatusTip(tr("Selects a specific read"));
00209     editFindRead->setWhatsThis(tr("Find Read\n\nSelects a specific read"));
00210     connect(editFindRead, SIGNAL(activated()), this, SLOT(slotEditFindRead()));
00211 
00212     editFindTag = new QAction(tr("Find Tag"), tr("Find Tag"), 0, this);
00213     editFindTag->setStatusTip(tr("Selects a specific tag"));
00214     editFindTag->setWhatsThis(tr("Find Tag\n\nSelects a specific tag"));
00215     connect(editFindTag, SIGNAL(activated()), this, SLOT(slotEditFindTag()));
00216 
00217     viewToolBar = new QAction(tr("Toolbar"), tr("Tool&bar"), 0, this, 0, true);
00218     viewToolBar->setStatusTip(tr("Enables/disables the toolbar"));
00219     viewToolBar->setWhatsThis(tr("Toolbar\n\nEnables/disables the toolbar"));
00220     connect(viewToolBar, SIGNAL(toggled(bool)), this, SLOT(slotViewToolBar(bool)));
00221 
00222     viewStatusBar = new QAction(tr("Statusbar"), tr("&Statusbar"), 0, this, 0, true);
00223     viewStatusBar->setStatusTip(tr("Enables/disables the statusbar"));
00224     viewStatusBar->setWhatsThis(tr("Statusbar\n\nEnables/disables the statusbar"));
00225     connect(viewStatusBar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
00226 
00227     windowNewWindow = new QAction(tr("New Wiew"), tr("&New Wiew"), 0, this);
00228     windowNewWindow->setStatusTip(tr("Opens a new view for the current document"));
00229     windowNewWindow->setWhatsThis(tr("New Wiew\n\nOpens a new view for the current document"));
00230     connect(windowNewWindow, SIGNAL(activated()), this, SLOT(slotWindowNewWindow()));
00231 
00232     windowCascade = new QAction(tr("Cascade"), tr("&Cascade"), 0, this);
00233     windowCascade->setStatusTip(tr("Cascades all windows"));
00234     windowCascade->setWhatsThis(tr("Cascade\n\nCascades all windows"));
00235     connect(windowCascade, SIGNAL(activated()), pWorkspace, SLOT(cascade()));
00236 
00237     windowTile = new QAction(tr("Tile"), tr("&Tile"), 0, this);
00238     windowTile->setStatusTip(tr("Tiles all windows"));
00239     windowTile->setWhatsThis(tr("Tile\n\nTiles all windows"));
00240     connect(windowTile, SIGNAL(activated()), pWorkspace, SLOT(tile()));
00241 
00242     windowAction = new QActionGroup(this, 0, false);
00243     windowAction->add(windowNewWindow);
00244     windowAction->add(windowCascade);
00245     windowAction->add(windowTile);
00246     
00247     normalModeAction = new QAction(tr("Normal mode"), pointerIcon, tr("Normal mode"), 0, this);
00248     normalModeAction->setStatusTip(tr("Sets mode to normal"));
00249     normalModeAction->setWhatsThis(tr("Normal mode\n\nFor selection of reads, normal moving etc"));
00250     normalModeAction->setToggleAction(true);
00251     normalModeAction->setOn(true);
00252     connect(normalModeAction, SIGNAL(activated()), this, SLOT(slotNormalMode()));
00253     
00254     dragModeAction = new QAction(tr("Drag mode"), dragIcon, tr("Drag mode"), 0, this);
00255     dragModeAction->setStatusTip(tr("Sets mode to drag mode"));
00256     dragModeAction->setWhatsThis(tr("Drag mode\n\nFor moving reads between contigs, and sideways moving"));
00257     dragModeAction->setToggleAction(true);
00258     connect(dragModeAction, SIGNAL(activated()), this, SLOT(slotDragMode()));
00259 
00260     modeActionGroup = new QActionGroup(this, 0, true);
00261     modeActionGroup->add(normalModeAction);
00262     modeActionGroup->add(dragModeAction);
00263 
00264     timecourseAction = new QAction(tr("View Time Course data"), tcViewIcon, tr("Time Course"), 0, this);
00265     timecourseAction->setStatusTip(tr("Enables Time Course viewing"));
00266     timecourseAction->setWhatsThis(tr("Time Course\n\nFor viewing of time course data"));
00267     timecourseAction->setToggleAction(true);
00268     timecourseAction->setOn(false);
00269     connect(timecourseAction, SIGNAL(toggled(bool)), this, SLOT(slotViewTimeCourse(bool)));
00270     
00271     normalizeAction = new QAction(tr("View Time Course data normalized"), tcNormIcon, tr("Normalized Time Course"), 0, this);
00272     normalizeAction->setStatusTip(tr("Normalize Time Course viewing"));
00273     normalizeAction->setWhatsThis(tr("Normalize Time Course\n\nFor viewing of time course data normalized for each individual read"));
00274     normalizeAction->setToggleAction(true);
00275     normalizeAction->setOn(false);
00276     normalizeAction->setEnabled(false);
00277     connect(normalizeAction, SIGNAL(toggled(bool)), this, SLOT(slotNormalizeTimeCourse(bool)));
00278     connect(timecourseAction, SIGNAL(toggled(bool)), normalizeAction, SLOT(setEnabled(bool)));
00279             
00280     timecourseActionGroup = new QActionGroup(this, 0, false);
00281     timecourseActionGroup->add(timecourseAction);
00282     timecourseActionGroup->add(normalizeAction);
00283 
00284     clusterScrollForwardAction = new QAction(tr("Scroll Right"), rightArrowIcon, tr("Scroll Right"), ALT + Key_Right, this);
00285     clusterScrollForwardAction->setStatusTip(tr("Scrolls right to next cluster"));
00286     clusterScrollForwardAction->setWhatsThis(tr("Scrolls right to next cluster"));
00287     connect(clusterScrollForwardAction, SIGNAL(activated()), this, SLOT(slotScrollForward()));
00288 
00289     clusterScrollBackwardsAction = new QAction(tr("Scroll Left"), leftArrowIcon, tr("Scroll Left"), ALT + Key_Left, this);
00290     clusterScrollBackwardsAction->setStatusTip(tr("Scrolls left to previous cluster"));
00291     clusterScrollBackwardsAction->setWhatsThis(tr("Scrolls left to previous cluster"));
00292     connect(clusterScrollBackwardsAction, SIGNAL(activated()), this, SLOT(slotScrollBackwards()));
00293 
00294 //     clusterWindowBox = new QSpinBox(1, numeric_limits<int>::max(), 1, this);
00295 //     clusterWindowBox->setValue(100);
00296 //     connect(clusterWindowBox, SIGNAL(valueChanged(int)), this, SLOT(slotClusterWindowChanged(int)));
00297 
00298 //     clusterMinNumBox = new QSpinBox(1, numeric_limits<int>::max(), 1, this);
00299 //     clusterMinNumBox->setValue(10);
00300 //     connect(clusterMinNumBox, SIGNAL(valueChanged(int)), this, SLOT(slotClusterNumChanged(int)));
00301     
00302     helpAboutApp = new QAction(tr("About"), tr("&About..."), 0, this);
00303     helpAboutApp->setStatusTip(tr("About the application"));
00304     helpAboutApp->setWhatsThis(tr("About\n\nAbout the application"));
00305     connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
00306 
00307 //     helpManualApp = new QAction(tr("Manual"), tr("&Manual"), 0, this);
00308 //     helpManualApp->setStatusTip(tr("Trapper Manual"));
00309 //     helpManualApp->setWhatsThis(tr("Trapper Manual\n\nManual decribing how to use Trapper"));
00310 //     connect(helpManualApp, SIGNAL(activated()), this, SLOT(slotHelpManual()));
00311 
00312 //     importAction = new QAction(tr("Import project"), tr("&Import project"), 0, this);
00313 //     importAction->setStatusTip(tr("Imports project data"));
00314 //     importAction->setWhatsThis(tr("Imports project data"));
00315 //     connect(importAction, SIGNAL(activated()), this, SLOT(slotImport()));
00316 
00317     importNewAction = new QAction(tr("Import project"), tr("&Import project"), 0, this);
00318     importNewAction->setStatusTip(tr("Imports project data"));
00319     importNewAction->setWhatsThis(tr("Imports project data"));
00320     connect(importNewAction, SIGNAL(activated()), this, SLOT(slotNewImport()));
00321 
00322     importChromatAction = new QAction(tr("Import Chromatograms"), tr("Import Chromatograms"), 0, this);
00323     importChromatAction->setStatusTip(tr("Imports chromatogram data"));
00324     importChromatAction->setWhatsThis(tr("Imports chromatogram data"));
00325     connect(importChromatAction, SIGNAL(activated()), this, SLOT(slotChromatImport()));
00326 
00327     importMateAction = new QAction(tr("Import Mate pairs"), tr("Import Mate Pairs"), 0, this);
00328     importMateAction->setStatusTip(tr("Imports mate pair data"));
00329     importMateAction->setWhatsThis(tr("Imports mate pair data"));
00330     connect(importMateAction, SIGNAL(activated()), this, SLOT(slotMateImport()));
00331 
00332     importTcAction = new QAction(tr("Import Time Course Data"), tr("Import Time Course"), 0, this);
00333     importTcAction->setStatusTip(tr("Imports Time Course Data"));
00334     importTcAction->setWhatsThis(tr("Imports Time Course Data"));
00335     connect(importTcAction, SIGNAL(activated()), this, SLOT(slotTcImport()));
00336 
00337     importPhdAction = new QAction(tr("Import phd data"), tr("Import phd data"), 0, this);
00338     importPhdAction->setStatusTip(tr("Imports phd data"));
00339     importPhdAction->setWhatsThis(tr("Imports phd data"));
00340     connect(importPhdAction, SIGNAL(activated()), this, SLOT(slotPhdImport()));
00341 
00342     exportAction = new QAction(tr("Export"), tr("&Export"), 0, this);
00343     exportAction->setStatusTip(tr("Exports data"));
00344     exportAction->setWhatsThis(tr("Exports data"));
00345     connect(exportAction, SIGNAL(activated()), this, SLOT(slotExport()));
00346 
00347     zoomInAction = new QAction(tr("Zoom in"), zoomPlusIcon, tr("Zoom in"), Key_Plus, this);
00348     zoomInAction->setStatusTip(tr("Zooms in"));
00349     zoomInAction->setWhatsThis(tr("Zooms in"));
00350     connect(zoomInAction, SIGNAL(activated()), this, SLOT(slotZoomIn()));
00351 
00352     zoomInXAction = new QAction(tr("Zoom in X"), zoomPlusIconX, tr("Zoom in X"),CTRL + Key_Plus, this);
00353     zoomInXAction->setStatusTip(tr("Zooms in X"));
00354     zoomInXAction->setWhatsThis(tr("Zooms in X direction"));
00355     connect(zoomInXAction, SIGNAL(activated()), this, SLOT(slotZoomInX()));
00356 
00357     zoomInYAction = new QAction(tr("Zoom in Y"), zoomPlusIconY, tr("Zoom in Y"), CTRL + ALT + Key_Plus, this);
00358     zoomInYAction->setStatusTip(tr("Zooms in Y"));
00359     zoomInYAction->setWhatsThis(tr("Zooms in Y direction"));
00360     connect(zoomInYAction, SIGNAL(activated()), this, SLOT(slotZoomInY()));
00361 
00362     zoomOutAction = new QAction(tr("Zoom out"), zoomMinusIcon, tr("&Zoom out"), Key_Minus, this);
00363     zoomOutAction->setStatusTip(tr("Zooms out"));
00364     zoomOutAction->setWhatsThis(tr("Zooms out"));
00365     connect(zoomOutAction, SIGNAL(activated()), this, SLOT(slotZoomOut()));
00366 
00367     zoomOutXAction = new QAction(tr("Zoom out X"), zoomMinusIconX, tr("Zoom out X"), CTRL + Key_Minus, this);
00368     zoomOutXAction->setStatusTip(tr("Zooms out X"));
00369     zoomOutXAction->setWhatsThis(tr("Zooms out in X direction"));
00370     connect(zoomOutXAction, SIGNAL(activated()), this, SLOT(slotZoomOutX()));
00371 
00372     zoomOutYAction = new QAction(tr("Zoom out Y"), zoomMinusIconY, tr("Zoom out Y"), CTRL + ALT + Key_Minus, this);
00373     zoomOutYAction->setStatusTip(tr("Zooms out Y"));
00374     zoomOutYAction->setWhatsThis(tr("Zooms out in Y direction"));
00375     connect(zoomOutYAction, SIGNAL(activated()), this, SLOT(slotZoomOutY()));
00376 
00377     enlargeAction = new QAction(tr("Enlarge"), tr("&Enlarge"), 0, this);
00378     enlargeAction->setStatusTip(tr("Adds more viewable rows"));
00379     enlargeAction->setWhatsThis(tr("Enlarges view, so that more rows and columns can be displayed"));
00380     connect(enlargeAction, SIGNAL(activated()), this, SLOT(slotEnlarge()));
00381 
00382     shrinkAction = new QAction(tr("Shrink"), tr("&Shrink"), 0, this);
00383     shrinkAction->setStatusTip(tr("Removes viewable rows. Does not affect data."));
00384     shrinkAction->setWhatsThis(tr("Shrinks view, displaying fewer rows and columns. Does not affect data."));
00385     connect(shrinkAction, SIGNAL(activated()), this, SLOT(slotShrink()));
00386 
00387     showStatisticsAction = new QAction(tr("Show statistics"), tr("Show statistics"), 0, this);
00388     showStatisticsAction->setStatusTip(tr("Show statistics about contig"));
00389     showStatisticsAction->setWhatsThis(tr("Show underlying berkeley db statistics for this contig"));
00390     connect(showStatisticsAction, SIGNAL(activated()), this, SLOT(slotShowStatistics()));
00391 
00392     configureViewModesAction = new QAction(tr("Configure view modes"), tr("&Configure modes"), 0, this);
00393     configureViewModesAction->setStatusTip(tr("Configure view modes"));
00394     configureViewModesAction->setWhatsThis(tr("Configure view modes"));
00395     connect(configureViewModesAction, SIGNAL(activated()), this, SLOT(slotConfigureViewModes()));
00396 
00397     
00398 }
00399 
00400 void TrapperApp::initMenuBar()
00401 {
00402     ///////////////////////////////////////////////////////////////////
00403     // MENUBAR
00404 
00405     ///////////////////////////////////////////////////////////////////
00406     // menuBar entry pFileMenu
00407     pFileMenu=new QPopupMenu();
00408 //     fileNew->addTo(pFileMenu);
00409     fileOpen->addTo(pFileMenu);
00410     fileClose->addTo(pFileMenu);
00411 //     pFileMenu->insertSeparator();
00412 //     fileFlush->addTo( pFileMenu );//DANGEROUS??
00413     //    fileSave->addTo(pFileMenu);
00414     // fileSaveAs->addTo(pFileMenu);
00415 //     pFileMenu->insertSeparator();
00416 //     filePrint->addTo(pFileMenu);
00417     pFileMenu->insertSeparator();
00418     fileQuit->addTo(pFileMenu);
00419 
00420 
00421 
00422 
00423     ///////////////////////////////////////////////////////////////////
00424     // menuBar entry editMenu
00425     pEditMenu=new QPopupMenu();
00426     editUndo->addTo(pEditMenu);
00427 //     pEditMenu->insertSeparator();
00428     editCut->addTo(pEditMenu);
00429     editCopy->addTo(pEditMenu);
00430     editPaste->addTo(pEditMenu);
00431     editSelectAll->addTo(pEditMenu);
00432     editSelectBetween->addTo(pEditMenu);
00433     editSelectBetweenCols->addTo(pEditMenu);
00434     editFindRead->addTo(pEditMenu);
00435     editFindTag->addTo(pEditMenu);
00436 
00437     ///////////////////////////////////////////////////////////////////
00438     // menuBar entry viewMenu
00439     pViewMenu=new QPopupMenu();
00440     pViewMenu->setCheckable(true);
00441     viewToolBar->addTo(pViewMenu);
00442     viewStatusBar->addTo(pViewMenu);
00443 
00444     zoomInAction->addTo(pViewMenu);
00445     zoomOutAction->addTo(pViewMenu);
00446     zoomInXAction->addTo(pViewMenu);
00447     zoomOutXAction->addTo(pViewMenu);
00448     zoomInYAction->addTo(pViewMenu);
00449     zoomOutYAction->addTo(pViewMenu);
00450 //     enlargeAction->addTo(pViewMenu);
00451 //     shrinkAction->addTo(pViewMenu);
00452     showStatisticsAction->addTo(pViewMenu);
00453     timecourseActionGroup->addTo(pViewMenu);
00454 //     configureViewModesAction->addTo(pViewMenu);
00455 
00456     ///////////////////////////////////////////////////////////////////
00457     // EDIT YOUR APPLICATION SPECIFIC MENUENTRIES HERE
00458 
00459     pToolsMenu=new QPopupMenu();
00460 //     importAction->addTo(pToolsMenu);
00461     importNewAction->addTo(pToolsMenu);
00462 //     importChromatAction->addTo(pToolsMenu);
00463     importMateAction->addTo(pToolsMenu);
00464     importTcAction->addTo(pToolsMenu);
00465 //     importPhdAction->addTo(pToolsMenu);
00466     modeActionGroup->addTo(pToolsMenu);
00467     exportAction->addTo(pToolsMenu);
00468 
00469     ///////////////////////////////////////////////////////////////////
00470     // menuBar entry windowMenu
00471     pWindowMenu = new QPopupMenu(this);
00472     pWindowMenu->setCheckable(true);
00473     connect(pWindowMenu, SIGNAL(aboutToShow()), this, SLOT(windowMenuAboutToShow()));
00474 
00475     ///////////////////////////////////////////////////////////////////
00476     // menuBar entry helpMenu
00477     pHelpMenu=new QPopupMenu();
00478 //     helpManualApp->addTo(pHelpMenu);
00479     helpAboutApp->addTo(pHelpMenu);
00480     pHelpMenu->insertSeparator();
00481     pHelpMenu->insertItem(tr("What's &This"), this, SLOT(whatsThis()), SHIFT+Key_F1);
00482 
00483     menuBar()->insertItem(tr("&Contig"), pFileMenu);
00484     menuBar()->insertItem(tr("&Edit"), pEditMenu);
00485     menuBar()->insertItem(tr("&View"), pViewMenu);
00486     menuBar()->insertItem(tr("&Window"), pWindowMenu);
00487     menuBar()->insertItem(tr("&Tools"), pToolsMenu);
00488     menuBar()->insertItem(tr("&Help"), pHelpMenu);
00489 
00490 }
00491 
00492 void TrapperApp::initToolBar()
00493 {
00494     ///////////////////////////////////////////////////////////////////
00495     // TOOLBAR
00496     fileToolbar = new QToolBar(this, "file operations");
00497 //     fileNew->addTo(fileToolbar);
00498     fileOpen->addTo(fileToolbar);
00499 //     fileFlush->addTo(fileToolbar);DANGEROUS??
00500 //     fileSave->addTo(fileToolbar);
00501     editSelectAll->addTo(fileToolbar);
00502     zoomInAction->addTo(fileToolbar);
00503     zoomOutAction->addTo(fileToolbar);
00504     zoomInXAction->addTo(fileToolbar);
00505     zoomOutXAction->addTo(fileToolbar);
00506     zoomInYAction->addTo(fileToolbar);
00507     zoomOutYAction->addTo(fileToolbar);
00508     
00509     fileToolbar->addSeparator();
00510     modeActionGroup->addTo(fileToolbar);
00511     fileToolbar->addSeparator();
00512     timecourseActionGroup->addTo(fileToolbar);
00513     fileToolbar->addSeparator();
00514 
00515 
00516     clusterWindowBox = new QSpinBox(1, numeric_limits<int>::max(), 1, fileToolbar);
00517     clusterWindowBox->setValue(100);
00518     connect(clusterWindowBox, SIGNAL(valueChanged(int)), this, SLOT(slotClusterWindowChanged(int)));
00519     QToolTip::add(clusterWindowBox, "Window size for cluster scrolling");
00520 
00521     clusterMinNumBox = new QSpinBox(1, numeric_limits<int>::max(), 1, fileToolbar);
00522     clusterMinNumBox->setValue(10);
00523     connect(clusterMinNumBox, SIGNAL(valueChanged(int)), this, SLOT(slotClusterNumChanged(int)));
00524     QToolTip::add(clusterMinNumBox, "Min number of tags in window for cluster scrolling");
00525 
00526     clusterScrollBackwardsAction->addTo(fileToolbar);
00527     clusterScrollForwardAction->addTo(fileToolbar);
00528     fileToolbar->addSeparator();
00529 
00530     QWhatsThis::whatsThisButton(fileToolbar);
00531 }
00532 
00533 void TrapperApp::initStatusBar()
00534 {
00535     ///////////////////////////////////////////////////////////////////
00536     //STATUSBAR
00537     statusBar()->message(tr("Ready."));
00538 }
00539 
00540 void TrapperApp::initView()
00541 {
00542     ////////////////////////////////////////////////////////////////////
00543     // set the main widget here
00544     QVBox* view_back = new QVBox( this );
00545     view_back->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
00546     pWorkspace = new QWorkspace( view_back );
00547     setCentralWidget(view_back);
00548 }
00549 
00550 void TrapperApp::createClient(TrapperDoc* doc, QString modeView )
00551 {
00552   
00553   TrapperView* w = new TrapperView(doc, pWorkspace, modeView, modeView);
00554   w->installEventFilter(this);
00555   doc->addView(w);
00556   connect( w, SIGNAL( message( const QString& ) ), statusBar(), SLOT( message( const QString& ) ) );
00557   
00558   //The following line doesn't do anything as far as I can tell...?
00559   connect( w, SIGNAL( createView( QString ) ), this, SLOT( slotCreateClient( QString ) ) );
00560   if ( pWorkspace->windowList().isEmpty() ) // show the very first window in maximized mode
00561     w->showMaximized();
00562   else
00563     w->show();
00564 }
00565 
00566 void TrapperApp::slotCreateClient( QString modeView )
00567 {
00568   cerr<<"I suspect I never get called...???"<<endl;
00569     statusBar()->message(tr("Opening new view ..."));
00570 
00571     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00572     if( m )
00573     {
00574         TrapperDoc* doc = m->getDocument();
00575         createClient( doc, modeView );
00576     }
00577     statusBar()->message(tr("Ready."));
00578 }
00579 
00580 void TrapperApp::openDocumentFile(const char* file)
00581 {
00582     statusBar()->message(tr("Opening file..."));
00583 //     cerr<<"file: "<<file<<endl<<flush;
00584     TrapperDoc* doc;
00585     // check, if document already open. If yes, set the focus to the first view
00586     for(doc=pDocList->first(); doc > 0; doc=pDocList->next()) {
00587 //       cerr<<"doc->pathName(): "<<doc->pathName()<<endl;
00588       
00589       if(doc->pathName() == file) {
00590         TrapperView* view=doc->firstView();
00591         view->setFocus();
00592         return;
00593       }
00594     }
00595     doc = new TrapperDoc(dbenv);
00596     pDocList->append(doc);
00597     doc->newDocument();
00598     // Creates an untitled window if file is 0
00599 
00600 
00601     QString fileName;
00602     if(!file)
00603     {
00604       untitledCount+=1;
00605       fileName=QString(tr("%1/Untitled%2")).arg(projectDir).arg(untitledCount);
00606 //         fileName=QString(tr("%1/Contig13")).arg(projectDir);
00607     
00608 
00609     }
00610     else
00611     {
00612         fileName = file;
00613     }
00614 
00615     if(!doc->openDocument(fileName))
00616     {
00617         QMessageBox::critical(this, tr("Error !"),tr("Could not open document !"));
00618         delete doc;
00619         return;
00620     }
00621 
00622     // create the window
00623 
00624     //createClient(doc);
00625 
00626 
00627     createClient(doc, QString("closeup"));
00628 //     createClient(doc, QString("tagTest"));
00629 
00630     statusBar()->message(tr("Ready."));
00631 }
00632 
00633 bool TrapperApp::queryExit()
00634 {
00635     int exit=QMessageBox::information(this, tr("Quit..."),
00636                                       tr("Do your really want to quit?"),
00637                                       QMessageBox::Ok, QMessageBox::Cancel);
00638 
00639     if (exit==1)
00640     {}
00641     else
00642     {}
00643     ;
00644 
00645     return (exit==1);
00646 }
00647 
00648 bool TrapperApp::eventFilter(QObject* object, QEvent* event)
00649 {
00650   if((event->type() == QEvent::Close) && ((TrapperApp*)object!=this) ) {
00651 
00652     QCloseEvent* e = (QCloseEvent*)event;
00653     TrapperView* pView = (TrapperView*)object;
00654     TrapperDoc* pDoc = pView->getDocument();
00655     if(pDoc->canCloseFrame(pView)) {
00656       pDoc->removeView(pView);
00657       if( !pDoc->firstView() ) {
00658         pDocList->remove(pDoc);
00659       }
00660       
00661       e->accept();
00662       
00663     }
00664     else {
00665       e->ignore();
00666     }
00667     return true;
00668   }
00669   else if ( (event->type() == QEvent::KeyPress) ) {
00670     QKeyEvent* e = (QKeyEvent*)event;
00671     int scrollfactor(10);
00672     if ( e->state() == Qt::ControlButton )
00673       scrollfactor *= 10;
00674     
00675     if ( e->key() == Qt::Key_Up ) {
00676       scroll(0, -1*scrollfactor);
00677       e->accept();
00678       return true;
00679     }
00680     else if ( e->key() == Qt::Key_Down ) {
00681       scroll(0, 1*scrollfactor);
00682       e->accept();
00683       return true;
00684     }
00685     else if ( e->key() == Qt::Key_Left ) {
00686       scroll(-1*scrollfactor, 0);
00687       e->accept();
00688       return true;
00689     }
00690     else if ( e->key() == Qt::Key_Right ) {
00691       scroll(1*scrollfactor, 0);
00692       e->accept();
00693       return true;
00694     }
00695     else if ( e->key() == Qt::Key_Tab ) {
00696       pWorkspace->activateNextWindow();
00697       e->accept();
00698       return true;
00699     }
00700     else if ( e->key() == Qt::Key_Backtab ) {
00701       pWorkspace->activatePrevWindow();
00702       e->accept();
00703       return true;
00704     }
00705     
00706     e->ignore();
00707   }
00708   
00709   
00710   return QWidget::eventFilter( object, event );    // standard event processing
00711 }
00712 
00713 /////////////////////////////////////////////////////////////////////
00714 // SLOT IMPLEMENTATION
00715 /////////////////////////////////////////////////////////////////////
00716 
00717 void TrapperApp::slotFileNew()
00718 {
00719   statusBar()->message(tr("Creating new file..."));
00720   
00721   openDocumentFile();
00722   
00723   statusBar()->message(tr("Ready."));
00724 }
00725 
00726 void TrapperApp::slotFileOpen()
00727 {
00728   statusBar()->message(tr("Opening file..."));
00729   
00730   QString dirName = QFileDialog::getExistingDirectory(projectDir,this,"contig dir selection","Choose contig dir");
00731   if (!dirName.isEmpty())
00732     {
00733       QDir d(dirName), projdir(projectDir);
00734       
00735       if ( !d.cdUp() || d!= projdir ) {
00736         QMessageBox::critical(this, tr("Error !"),tr("Contig directory must be a subdirectory of project directory!"));
00737 
00738       }
00739       else {
00740 //         cerr << "opening contig dir=" << dirName<<endl;
00741         openDocumentFile(dirName);
00742       }
00743     }
00744   statusBar()->message(tr("Ready."));
00745 }
00746 
00747 
00748 void TrapperApp::slotFileSave()
00749 {
00750     statusBar()->message(tr("Saving file..."));
00751 
00752     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00753     if( m )
00754     {
00755         TrapperDoc* doc = m->getDocument();
00756         if(doc->title().contains(tr("Untitled")))
00757             slotFileSaveAs();
00758         else
00759             if(!doc->saveDocument(doc->pathName()))
00760                 QMessageBox::critical (this, tr("I/O Error !"), tr("Could not save the current document !"));
00761     }
00762 
00763     statusBar()->message(tr("Ready."));
00764 }
00765 
00766 void TrapperApp::slotFileSaveAs()
00767 {
00768     statusBar()->message(tr("Saving file under new filename..."));
00769     QString fn = QFileDialog::getSaveFileName(0, 0, this);
00770     if (!fn.isEmpty())
00771     {
00772         TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00773         if( m )
00774         {
00775             TrapperDoc* doc = m->getDocument();
00776             if(!doc->saveDocument(fn))
00777             {
00778                 QMessageBox::critical (this, tr("I/O Error !"), tr("Could not save the current document !"));
00779                 return;
00780             }
00781             doc->changedViewList();
00782         }
00783     }
00784     statusBar()->message(tr("Ready."));
00785 }
00786 void TrapperApp::slotFileFlush()
00787 {
00788   statusBar()->message(tr("Flushing database caches..."));
00789   
00790   for(TrapperDoc * doc=pDocList->first(); doc!= 0; doc=pDocList->next())
00791     {
00792       cerr<<"doc->pathName(): "<<doc->pathName()<<endl;
00793       list<string> type_list = GeneralMaker::listRegistered();
00794       for( list<string>::iterator it = type_list.begin(); it != type_list.end(); ++it ) {
00795         TrDb* db = doc->findTrDb( *it );
00796         if ( db ) {
00797           cerr<<"Syncing "<<*it<<endl;
00798           db->sync();
00799           
00800         }
00801       }
00802     }
00803   statusBar()->message(tr("Ready."));  
00804 }
00805 
00806 void TrapperApp::slotFileClose()
00807 {
00808   cerr<<"Hello slotFileClose() "<<endl;
00809  
00810   statusBar()->message(tr("Closing file..."));
00811   
00812   TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00813   if( m )
00814     {
00815       TrapperDoc* doc=m->getDocument();
00816       doc->closeDocument();
00817     }
00818   
00819   statusBar()->message(tr("Ready."));
00820   cerr<<"Bye slotFileClose() "<<endl;
00821 }
00822 
00823 void TrapperApp::slotFilePrint()
00824 {
00825     statusBar()->message(tr("Printing..."));
00826 
00827     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00828     if ( m )
00829         m->print( printer );
00830 
00831     statusBar()->message(tr("Ready."));
00832 }
00833 
00834 void TrapperApp::slotFileQuit()
00835 {
00836     statusBar()->message(tr("Exiting application..."));
00837 
00838     for(TrapperDoc * doc=pDocList->first(); doc > 0; doc=pDocList->next())
00839     {
00840         delete doc;
00841     }
00842 
00843 
00844     ///////////////////////////////////////////////////////////////////
00845     // exits the Application
00846     //  if(doc->isModified())
00847     //  {
00848     //    if(queryExit())
00849     //    {
00850     //      qApp->quit();
00851     //    }
00852     //    else
00853     //    {
00854     //
00855     //    };
00856     //  }
00857     //  else
00858     //  {
00859     qApp->quit();
00860 
00861 
00862     //    TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00863     // if( m )
00864     // {
00865     //    TrapperDoc* doc = m->getDocument();
00866     //    delete doc;
00867     //  }
00868     statusBar()->message(tr("Ready."));
00869 }
00870 
00871 void TrapperApp::slotEditUndo()
00872 {
00873     statusBar()->message(tr("Reverting last move..."));
00874 
00875     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00876     if ( m )   m->undo();
00877 
00878     statusBar()->message(tr("Ready."));
00879 }
00880 
00881 void TrapperApp::slotEditCut()
00882 {
00883     statusBar()->message(tr("Cutting selection..."));
00884 
00885     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00886     if ( m ) m->cut();
00887 
00888     statusBar()->message(tr("Ready."));
00889 }
00890 
00891 void TrapperApp::slotEditCopy()
00892 {
00893     statusBar()->message(tr("Copying selection to clipboard..."));
00894 
00895     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00896     if ( m )  m->copy();
00897 
00898     statusBar()->message(tr("Ready."));
00899 }
00900 
00901 void TrapperApp::slotEditPaste()
00902 {
00903     statusBar()->message(tr("Inserting clipboard contents..."));
00904 
00905     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00906     if ( m )   m->paste();
00907     statusBar()->message(tr("Ready."));
00908 }
00909 
00910 void TrapperApp::slotEditSelectAll()
00911 {
00912     statusBar()->message(tr("Selecting all reads..."));
00913 
00914     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00915     if ( m )   m->selectAll();
00916     statusBar()->message(tr("Ready."));
00917 }
00918 
00919 void TrapperApp::slotEditSelectBetween()
00920 {
00921     statusBar()->message(tr("Selecting all reads between rows..."));
00922 
00923     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00924     if ( m )   m->selectBetween();
00925     statusBar()->message(tr("Ready."));
00926 }
00927 
00928 void TrapperApp::slotEditSelectBetweenCols()
00929 {
00930     statusBar()->message(tr("Selecting all reads between cols..."));
00931 
00932     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00933     if ( m )   m->selectBetweenCols();
00934     statusBar()->message(tr("Ready."));
00935 }
00936 
00937 void TrapperApp::slotEditFindRead()
00938 {
00939     statusBar()->message(tr("Finding read..."));
00940 
00941     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00942     if ( m )   m->findRead();
00943     statusBar()->message(tr("Ready."));
00944 }
00945 
00946 void TrapperApp::slotEditFindTag()
00947 {
00948     statusBar()->message(tr("Finding tag..."));
00949 
00950     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00951     if ( m )   m->findTag();
00952     statusBar()->message(tr("Ready."));
00953 }
00954 
00955 void TrapperApp::slotViewToolBar(bool toggle)
00956 {
00957     statusBar()->message(tr("Toggle toolbar..."));
00958     ///////////////////////////////////////////////////////////////////
00959     // turn Toolbar on or off
00960     if (toggle== false)
00961     {
00962         fileToolbar->hide();
00963     }
00964     else
00965     {
00966         fileToolbar->show();
00967     };
00968     statusBar()->message(tr("Ready."));
00969 }
00970 
00971 void TrapperApp::slotViewStatusBar(bool toggle)
00972 {
00973     statusBar()->message(tr("Toggle statusbar..."));
00974     ///////////////////////////////////////////////////////////////////
00975     //turn Statusbar on or off
00976 
00977     if (toggle == false)
00978     {
00979         statusBar()->hide();
00980     }
00981     else
00982     {
00983         statusBar()->show();
00984     }
00985     statusBar()->message(tr("Ready."));
00986 }
00987 
00988 void TrapperApp::slotWindowNewWindow()
00989 {
00990     statusBar()->message(tr("Opening new document view..."));
00991 
00992     TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00993     if ( m )
00994     {
00995         TrapperDoc* doc = m->getDocument();
00996         createClient(doc);
00997     }
00998     statusBar()->message(tr("Ready."));
00999 }
01000 
01001 void TrapperApp::slotHelpAbout()
01002 {
01003   QMessageBox::about(this,tr("About..."),
01004                      tr("NGSView\nVersion 1.0"
01005                         "\n(c) 2003 - 2009 by Erik Arner, Martti Tammi, and Erik Sjölund"));
01006 }
01007 
01008 void TrapperApp::slotHelpManual()
01009 {
01010   QMessageBox::about(this,tr("Help"),
01011                      tr("Please see documentation included with DNPTrapper release or at http://dnptrapper.sourceforge.net"));
01012   
01013 }
01014 
01015 void TrapperApp::slotStatusHelpMsg(const QString &text)
01016 {
01017     ///////////////////////////////////////////////////////////////////
01018     // change status message of whole statusbar temporary (text, msec)
01019     statusBar()->message(text, 2000);
01020 }
01021 
01022 void TrapperApp::windowMenuAboutToShow()
01023 {
01024     pWindowMenu->clear();
01025     windowNewWindow->addTo(pWindowMenu);
01026     windowCascade->addTo(pWindowMenu);
01027     windowTile->addTo(pWindowMenu);
01028 
01029     if ( pWorkspace->windowList().isEmpty() )
01030     {
01031         windowAction->setEnabled(false);
01032     }
01033     else
01034     {
01035         windowAction->setEnabled(true);
01036     }
01037 
01038     pWindowMenu->insertSeparator();
01039 
01040     QWidgetList windows = pWorkspace->windowList();
01041     for ( int i = 0; i < int(windows.count()); ++i )
01042     {
01043         int id = pWindowMenu->insertItem(QString("&%1 ").arg(i+1)+windows.at(i)->caption(), this, SLOT( windowMenuActivated( int ) ) );
01044         pWindowMenu->setItemParameter( id, i );
01045         pWindowMenu->setItemChecked( id, pWorkspace->activeWindow() == windows.at(i) );
01046     }
01047 }
01048 
01049 void TrapperApp::windowMenuActivated( int id )
01050 {
01051     QWidget* w = pWorkspace->windowList().at( id );
01052     if ( w )
01053         w->setFocus();
01054 }
01055 
01056 void TrapperApp::slotZoomIn()
01057 {
01058     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01059     if( m )
01060     {
01061         m->zoomIn();
01062 //         m->updateContents();
01063     }
01064 }
01065 
01066 void TrapperApp::slotZoomInX()
01067 {
01068     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01069     if( m )
01070     {
01071         m->zoomInX();
01072 //         m->updateContents();
01073     }
01074 }
01075 
01076 void TrapperApp::slotZoomInY()
01077 {
01078     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01079     if( m )
01080     {
01081         m->zoomInY();
01082 //         m->updateContents();
01083     }
01084 }
01085 
01086 void TrapperApp::slotZoomOut()
01087 {
01088     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01089     if( m )
01090     {
01091         m->zoomOut();
01092 //         m->updateContents();
01093     }
01094 }
01095 
01096 void TrapperApp::slotZoomOutX()
01097 {
01098     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01099     if( m )
01100     {
01101         m->zoomOutX();
01102 //         m->updateContents();
01103     }
01104 }
01105 
01106 void TrapperApp::slotZoomOutY()
01107 {
01108     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01109     if( m )
01110     {
01111         m->zoomOutY();
01112 //         m->updateContents();
01113     }
01114 }
01115 
01116 void TrapperApp::slotEnlarge()
01117 {
01118     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01119     if( m )
01120     {
01121         m->enlarge();
01122     }
01123 }
01124 
01125 void TrapperApp::slotShrink()
01126 {
01127     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01128     if( m )
01129     {
01130         m->shrink();
01131     }
01132 }
01133 
01134 void TrapperApp::slotImport()
01135 {
01136   statusBar()->message(tr("Importing data from an xml file..."));
01137   QString fn = QFileDialog::getOpenFileName(0, 0, this,"import from file dialog","Choose your xml file to import from");
01138   if (!fn.isEmpty()) {
01139     QFile f( fn );
01140     if ( !f.open( IO_ReadOnly ) ) {
01141       QMessageBox::warning(this,"","couldn't read file");
01142     }
01143     
01144     QDomDocument domDoc("Trapper");
01145     if ( !domDoc.setContent( &f ) ) {
01146       f.close();
01147       QMessageBox::warning(this,"","couldn't read xml");
01148       return;
01149     }
01150     f.close();
01151     
01152     QDomElement docElem = domDoc.documentElement();
01153     
01154     for( QDomNode node1 = docElem.firstChild(); !node1.isNull() ; node1 = node1.nextSibling()) {
01155       if ( node1.isElement() && node1.nodeName() == "contig" ) {
01156           QDomElement elem1 = node1.toElement();
01157           
01158           Q_ASSERT((elem1.hasAttribute("name")));
01159           QString contigName = elem1.attribute( "name");
01160           
01161           
01162           bool found = false;
01163           /*
01164             TrapperDoc * doc;      
01165             for(doc=pDocList->first(); doc > 0; doc=pDocList->next())
01166             {
01167             
01168             if(doc->pathName()==contigName)
01169             { found = true; }
01170             }
01171             
01172           */
01173           
01174           QStringList contigNamesAlreadyPresent = contigNamesInProjectDir();
01175           if ( contigNamesAlreadyPresent.contains( contigName ) ) {
01176             found = true;
01177           }
01178           if ( found ) {
01179             QString message;
01180             message = QString("The contig name \"%1\" was specified in the import file, but that contig is already present in the project dir. Skipping this one").arg(contigName);
01181             QMessageBox::warning(this,"",message);
01182             continue;
01183           }
01184           QString fName = projectDir + "/" + contigName;
01185           TrapperDoc *  tdoc = new TrapperDoc(dbenv);
01186           tdoc->openDocument(fName);
01187           tdoc->import( elem1 );
01188           delete tdoc;
01189           tdoc = NULL;
01190           cerr << "reached after"<<endl;
01191           
01192       }
01193       //        node1 = node1.nextSibling();
01194     }
01195     
01196     /*
01197       TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01198       if( m )
01199       {
01200       TrapperDoc* doc = m->getDocument();
01201       if(!doc->import(fn))
01202       {
01203       QMessageBox::critical (this, tr("I/O Error !"), tr("Could not import !"));
01204       return;
01205       }
01206       }
01207     */
01208     
01209   }
01210   statusBar()->message(tr("Ready."));
01211 }
01212 
01213 void TrapperApp::slotNewImport()
01214 {
01215   statusBar()->message(tr("Importing data from an xml file..."));
01216   QString fn = QFileDialog::getOpenFileName(0, 0, this,"import from file dialog","Choose trapper xml or macsim file to import from");
01217   if (!fn.isEmpty()) {
01218     QFile f( fn );
01219     if ( !f.open( IO_ReadOnly ) ) {
01220         QMessageBox::warning(this,"","couldn't open file");
01221         return;
01222     }
01223     QXmlDefaultHandler* handler;
01224     
01225     
01226     
01227     if ( fn.endsWith("macsim")) {
01228       handler = new MacsimParser(dbenv, projectDir);
01229     }
01230     else {
01231       handler = new TrapperParser(dbenv, projectDir);
01232     }
01233 
01234     
01235 //     QXmlInputSource source( &f );
01236 //     ChunkedXMLInputSource source( &f );
01237     QXmlInputSource* source = new ChunkedXMLInputSource( &f );
01238     QXmlSimpleReader reader;
01239     reader.setContentHandler( handler );
01240     
01241     
01242 //     if (!reader.parse(source) ) {
01243 //       QMessageBox::warning(this,"","couldn't read file");
01244 //       return;
01245 //     }
01246     int num_chunks(0);
01247     reader.parse( source, true );
01248     while ( reader.parseContinue() ) {
01249       num_chunks++;
01250 //       cerr<<num_chunks<<" parsed"<<endl;
01251     }
01252     delete source;
01253     
01254   }
01255   statusBar()->message(tr("Ready."));
01256 }
01257 
01258 void TrapperApp::slotChromatImport()
01259 {
01260   statusBar()->message(tr("Importing chromatogram data..."));
01261   
01262   QString chromatDirName = QFileDialog::getExistingDirectory(projectDir,this,"chromat dir selection","Choose chromatogram directory");
01263 
01264   if (chromatDirName.isEmpty()) {
01265     return;
01266   }
01267 
01268   //First, open all contigs (docs)
01269   
01270   QPtrList<TrapperDoc> docListNotAlreadyOpen;
01271   docListNotAlreadyOpen.setAutoDelete(true);//Will delete docs itself when function exits
01272 
01273   open_docs_not_already_open( docListNotAlreadyOpen );
01274 
01275   for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01276     doc->importChromat(chromatDirName);
01277   }
01278   for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01279     doc->importChromat(chromatDirName);
01280   }
01281 
01282   //Close all docs that weren't already open - happens automatically with QPtrList
01283   
01284   statusBar()->message(tr("Ready."));
01285 }
01286 
01287 void TrapperApp::slotMateImport()
01288 {
01289   statusBar()->message(tr("Importing mate data..."));
01290   
01291   QString matefile = QFileDialog::getOpenFileName(0, 0, this,"import from file dialog","Choose your mate pair file to import from");
01292 
01293   if (matefile.isEmpty()) {
01294     return;
01295   }
01296 
01297   //First, open all contigs (docs)
01298   
01299   QPtrList<TrapperDoc> docListNotAlreadyOpen;
01300   docListNotAlreadyOpen.setAutoDelete(true);//Will delete docs itself when function exits
01301 
01302   open_docs_not_already_open( docListNotAlreadyOpen );
01303 
01304   for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01305     doc->importMates(matefile);
01306   }
01307   for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01308     doc->importMates(matefile);
01309   }
01310 
01311   
01312   statusBar()->message(tr("Ready."));
01313 }
01314 
01315 void TrapperApp::slotTcImport()
01316 {
01317   statusBar()->message(tr("Importing time course data..."));
01318   
01319   QString tcfile = QFileDialog::getOpenFileName(0, 0, this,"import from file dialog","Choose your time course file to import from");
01320 
01321   if (tcfile.isEmpty()) {
01322     return;
01323   }
01324 
01325   //TC data is imported separately for each document
01326   TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01327   if( m ) {
01328     TrapperDoc* doc = m->getDocument();
01329     if ( doc ) {
01330       doc->importTimeCourse(tcfile);        
01331     }
01332   }
01333   
01334   statusBar()->message(tr("Ready."));
01335   
01336 }
01337 
01338 void TrapperApp::slotPhdImport()
01339 {
01340   statusBar()->message(tr("Importing phd data..."));
01341   
01342   QString phdDirName = QFileDialog::getExistingDirectory(projectDir,this,"phd dir selection","Choose phd directory");
01343 
01344   if (phdDirName.isEmpty()) {
01345     return;
01346   }
01347 
01348   //First, open all contigs (docs)
01349   
01350   QPtrList<TrapperDoc> docListNotAlreadyOpen;
01351   docListNotAlreadyOpen.setAutoDelete(true);//Will delete docs itself when function exits
01352 
01353   open_docs_not_already_open( docListNotAlreadyOpen );
01354 
01355   for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01356     doc->importPhd(phdDirName);
01357   }
01358   for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01359     doc->importPhd(phdDirName);
01360   }
01361 
01362   //Close all docs that weren't already open - happens automatically with QPtrList
01363   
01364   statusBar()->message(tr("Ready."));
01365 }
01366 
01367 void TrapperApp::open_docs_not_already_open(QPtrList<TrapperDoc>& notOpenBefore)
01368 {
01369 
01370   TrapperDoc* doc;
01371   set<QString> alreadyOpen;
01372   
01373   for(doc=pDocList->first(); doc !=0; doc=pDocList->next()) {
01374     
01375     alreadyOpen.insert(doc->pathName().section('/', -2));
01376   }
01377   
01378 
01379   QStringList contigs = contigNamesInProjectDir();
01380   
01381   for ( QStringList::Iterator it = contigs.begin(); it != contigs.end(); ++it ) {
01382     
01383     
01384     if ( *it != "." && *it != ".." && alreadyOpen.find( *it ) == alreadyOpen.end() ) {
01385       
01386       
01387       TrapperDoc* tdoc = new TrapperDoc(dbenv);
01388       tdoc->newDocument();
01389       if ( !tdoc->openDocument(projectDir + "/" + *it ) ) {
01390         QMessageBox::critical(this, tr("Error !"),tr("Could not open document!"));
01391         delete tdoc;
01392       }
01393       else {
01394         notOpenBefore.append( tdoc );
01395       }
01396       
01397     }
01398     
01399 
01400   }
01401   
01402 }
01403 
01404 // void TrapperApp::map_reads_to_docs(str_doc_map& readmap, QPtrList<TrapperDoc>& notOpenBefore)
01405 // {
01406 //   TrapperDoc* doc;
01407   
01408 //   for(doc=pDocList->first(); doc !=0; doc=pDocList->next()) {
01409 //     Database::SecondaryIterator<ReadData> name_it( "name", doc, "ReadData" );
01410 //     assert(name_it.first() == 0);
01411 //     do {
01412 //       readmap.insert(make_pair(QString(name_it.answer()->name()), doc));
01413 //     }while( name_it.next() == 0 );
01414     
01415     
01416 //   }
01417 //   for(doc=notOpenBefore.first(); doc !=0; doc=notOpenBefore.next()) {
01418 //     Database::SecondaryIterator<ReadData> name_it( "name", doc, "ReadData" );
01419 //     assert(name_it.first() == 0);
01420 //     do {
01421 //       readmap.insert(make_pair(name_it.answer()->name(), doc));
01422       
01423 //     }while( name_it.next() == 0 );
01424     
01425     
01426 //   }
01427   
01428 // }
01429 
01430 void TrapperApp::slotExport()
01431 {
01432     statusBar()->message(tr("Exporting data to an xml file..."));
01433     QString fn = QFileDialog::getSaveFileName(0, "Trapper Xml (*.xml)", this,
01434                                               "export to file dialog",
01435                                               "Choose a filename to save the export data under");
01436     if (fn.isEmpty())
01437     {
01438         return;
01439     }
01440     if (  QFile::exists( fn ) &&
01441           QMessageBox::question(
01442                                 0,
01443                                 tr("Overwrite File? -- Trapper"),
01444                                 tr("A file called %1 already exists."
01445                                    "Do you want to overwrite it?")
01446                                 .arg( fn ),
01447                                 tr("&Yes"), tr("&No"),
01448                                 QString::null, 0, 1 ) ) {
01449       
01450       return;
01451     }
01452     
01453     exportToFile(fn);
01454     statusBar()->message(tr("Ready."));
01455 }
01456 
01457 void TrapperApp::exportToFile(QString toXmlFile)
01458 {
01459   statusBar()->message(tr("Exporting contig to file..."));
01460 
01461   //Open file and docs
01462 
01463   ofstream outFile(toXmlFile.ascii());
01464 //   ostream& outFile = cerr;
01465 
01466   outFile<<"<TRAPPER>\n";
01467 //   QPtrList<TrapperDoc> docListNotAlreadyOpen;
01468 //   docListNotAlreadyOpen.setAutoDelete(true);//Will delete docs itself when function exits
01469 
01470 //   open_docs_not_already_open( docListNotAlreadyOpen );
01471 
01472   //For each contig, write it to file
01473   //New deal: just export active window
01474 
01475 //   for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01476 //     doc->saveExport(outFile);
01477 //   }
01478 //   for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01479 //     doc->saveExport(outFile);
01480 //   }
01481 
01482   TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01483   if( m ) {
01484     TrapperDoc* doc = m->getDocument();
01485     if ( doc ) {
01486       doc->saveExport(outFile);
01487     }
01488   }
01489   
01490   //Close file
01491   outFile<<"</TRAPPER>\n";
01492   
01493   outFile.close();
01494   statusBar()->message(tr("Ready."));
01495   
01496 }
01497 
01498 void TrapperApp::setDbHomeDir(QString dir)
01499 {
01500   QDir d(dir);
01501   if ( d.exists() )
01502     {
01503       projectDir = d.absPath();
01504       int ret;
01505       /* Open the environment with full transactional support. */
01506       if ((ret = dbenv->open(projectDir, DB_CREATE |
01507                              DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER , 0)) != 0) {
01508         dbenv->err(ret, "environment open: %s", dir.ascii());
01509         exit( 1);
01510       }
01511 //       cerr<<"DB home dir set"<<endl;
01512     }
01513   else
01514     {
01515       QMessageBox::critical( 0,
01516                              tr( "Critical Error" ),
01517                              tr( "Db home dir \"%1\" doesn't exit" ).arg( dir ) );
01518       
01519       /* todo: instead of exit, ask for a dir with a dialog */
01520       exit(1);
01521     }
01522   
01523 }
01524 
01525 QStringList TrapperApp::contigNamesInProjectDir()
01526 {
01527     QString contigName;
01528     QDir d( projectDir );
01529     Q_ASSERT( d.exists() );
01530     d.setFilter( QDir::Dirs | QDir::NoSymLinks );
01531     d.setSorting( QDir::Name );
01532     QStringList slist = d.entryList();
01533     return slist;
01534 }
01535 
01536 void TrapperApp::slotShowStatistics()
01537 {
01538     statusBar()->message(tr("Opening statistics window ..."));
01539 
01540     TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01541     if( m )
01542     {
01543         TrapperDoc* doc = m->getDocument();
01544         if ( doc )
01545         {
01546             QString statisticsText = doc->getStatistics();
01547             QTextEdit * statView = new QTextEdit( );
01548             statView->setReadOnly( true );
01549             statView->setText( statisticsText );
01550             statView->show();
01551         }
01552     }
01553     statusBar()->message(tr("Ready."));
01554 }
01555 
01556 void TrapperApp::slotConfigureViewModes()
01557 {
01558    ShowModesDlg * dlg = new ShowModesDlg( this, QString::null );
01559 
01560    if ( dlg->exec() == QDialog::Accepted )
01561    {}
01562 }
01563 
01564 
01565 void TrapperApp::setViewModeConfFile( QString filename )
01566 {
01567  viewmodefile.setName( filename );
01568   
01569   if ( ! viewmodefile.open( IO_ReadWrite ) )
01570   {
01571         QMessageBox::critical( 0,
01572                                tr( "Critical Error" ),
01573                                tr( "Cannot open configuration file %1" ).arg( filename ) );
01574 
01575         /* todo: instead of exit, ask for a file with a dialog */
01576         exit(1);
01577   }
01578 
01579   TrapperConf * conf = TrapperConf::instance();
01580   Q_CHECK_PTR( conf );
01581   conf->loadDom( &viewmodefile );
01582 }
01583 
01584 void TrapperApp::scroll(int dx, int dy)
01585 {
01586   
01587   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01588   if ( m )   m->scrollBy(dx, dy);
01589 }
01590 void TrapperApp::slotNormalMode()
01591 {
01592   
01593   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01594   if ( m )   m->setDragMode(false);
01595   
01596 }
01597 
01598 
01599 void TrapperApp::slotDragMode()
01600 {
01601   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01602   if ( m )   m->setDragMode(true);
01603   
01604 }
01605 
01606 void TrapperApp::slotActivatedWindow(QWidget* w)
01607 {
01608   TrapperView* m = (TrapperView*) w;
01609   if ( m ) {
01610     m->setDragMode(dragModeAction->isOn());
01611     m->setViewTimeCourse(timecourseAction->isOn());
01612     m->setNormalizeTimeCourse(normalizeAction->isOn());
01613     m->setClusterWindow(clusterWindowBox->value());
01614     m->setClusterMinNum(clusterMinNumBox->value());
01615   }
01616   
01617 }
01618 
01619 void TrapperApp::slotViewTimeCourse(bool toggle)
01620 {
01621   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01622   if ( m )   m->setViewTimeCourse(toggle);
01623   
01624 }
01625 
01626 void TrapperApp::slotNormalizeTimeCourse(bool toggle)
01627 {
01628   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01629   if ( m )   m->setNormalizeTimeCourse(toggle);
01630 
01631 }
01632 
01633 void TrapperApp::slotScrollForward()
01634 {
01635   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01636   if ( m )   m->scrollToNextCluster(true);
01637   
01638 }
01639 
01640 void TrapperApp::slotScrollBackwards()
01641 {
01642   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01643   if ( m )   m->scrollToNextCluster(false);
01644   
01645 }
01646 
01647 void TrapperApp::slotClusterWindowChanged(int window_size)
01648 {
01649   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01650   if ( m )   m->setClusterWindow(window_size);
01651 }
01652 
01653 void TrapperApp::slotClusterNumChanged(int num)
01654 {
01655   TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01656   if ( m )   m->setClusterMinNum(num);
01657 }
01658 

Generated on Fri Jul 17 20:19:29 2009 for ngsview by  doxygen 1.5.1