/***************************************************************************** # Copyright (C) 1994-2008 by David Gordon. # All rights reserved. # # This software is part of a beta-test version of the Consed/Autofinish # package. It should not be redistributed or # used for any commercial purpose, including commercially funded # sequencing, without written permission from the author and the # University of Washington. # # This software is provided ``AS IS'' and any express or implied # warranties, including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose, are disclaimed. # In no event shall the authors or the University of Washington be # liable for any direct, indirect, incidental, special, exemplary, or # consequential damages (including, but not limited to, procurement of # substitute goods or services; loss of use, data, or profits; or # business interruption) however caused and on any theory of liability, # whether in contract, strict liability, or tort (including negligence # or otherwise) arising in any way out of the use of this software, even # if advised of the possibility of such damage. # # Building Consed from source is error prone and not simple which is # why I provide executables. Due to time limitations I cannot # provide any assistance in building Consed. Even if you do not # modify the source, you may introduce errors due to using a # different version of the compiler, a different version of motif, # different versions of other libraries than I used, etc. For this # reason, if you discover Consed bugs, I can only offer help with # those bugs if you first reproduce those bugs with an executable # provided by me--not an executable you have built. # # Modifying Consed is also difficult. Although Consed is modular, # some modules are used by many other modules. Thus making a change # in one place can have unforeseen effects on many other features. # It may takes months for you to notice these other side-effects # which may not seen connected at all. It is not feasable for me to # provide help with modifying Consed sources because of the # potentially huge amount of time involved. # #*****************************************************************************/ #include "guiReorientContigs.h" #include "handleWindowManagerDelete2.h" #include "hp_exception_kludge.h" #include "guiapp.h" #include #include #include #include #include #include #include "assembly.h" #include "consed.h" #include "breakIntoShorterLines.h" #include #include "assemblyView.h" #include "clScaffold.h" #include "popupErrorMessage2.h" static void cbUserPushedDismiss( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiReorientContigs* pGuiReorientContigs = (guiReorientContigs*) pClientData; TRY_CATCH_WRAPPER( delete pGuiReorientContigs ); } static void cbUserPushedApplyAndRestartAssemblyView( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiReorientContigs* pGuiReorientContigs = (guiReorientContigs*) pClientData; TRY_CATCH_WRAPPER( pGuiReorientContigs->userPushedApplyAndRestartAssemblyView() ); } void guiReorientContigs :: createWindow() { Assembly* pAssembly = ConsEd::pGetAssembly(); pAssembly->getScaffolds( aScaffolds_ ); widPopupShell_ = XtVaCreatePopupShell( "Reorient Contigs", topLevelShellWidgetClass, GAPP->widGetTopLevel(), XmNtransient, False, XmNdeleteResponse, XmDO_NOTHING, NULL ); handleWindowManagerDelete2( widPopupShell_, cbUserPushedDismiss, this ); Widget widForm = XtVaCreateManagedWidget( "form", xmFormWidgetClass, widPopupShell_, NULL ); // start with widgets above the scaffolds list Widget widScaffoldLabel = XtVaCreateManagedWidget( "Select a scaffold:", xmLabelWidgetClass, widForm, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 10, NULL ); Widget widAbove = widScaffoldLabel; // build up from the bottom widApplyAndRestartAssemblyView_ = XtVaCreateManagedWidget( "Apply and Restart Assembly View", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 10, NULL ); XtAddCallback( widApplyAndRestartAssemblyView_, XmNactivateCallback, cbUserPushedApplyAndRestartAssemblyView, this ); Widget widBelow = widApplyAndRestartAssemblyView_; widDismiss_ = XtVaCreateManagedWidget( "Dismiss", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, widApplyAndRestartAssemblyView_, XmNleftOffset, 10, NULL ); XtAddCallback( widDismiss_, XmNactivateCallback, cbUserPushedDismiss, this ); RWCString soNote( "(Note: if you want to do more than one of these \noperations, you must click \"Apply and Restart \nAssembly View\" after each one.)" ); XmString xmsNote = XmStringCreateLtoR( soNote.data(), XmFONTLIST_DEFAULT_TAG ); Widget widNote = XtVaCreateManagedWidget( "note", xmLabelWidgetClass, widForm, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, widBelow, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNlabelString, xmsNote, XmNalignment, XmALIGNMENT_BEGINNING, NULL ); widBelow = widNote; XmStringFree( xmsNote ); // radio box Widget widRadioBox = XmCreateRadioBox( widForm, "radio", NULL, 0 ); XtVaSetValues( widRadioBox, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, widBelow, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNorientation, XmVERTICAL, NULL ); widBelow = widRadioBox; RWCString soRemoveCs( "Make all contigs the same orientation as the scaffold (remove each 'c' ) and retain the scaffold orientation and the new orientations of all its contigs" ); breakIntoShorterLines( soRemoveCs, 50 ); XmString xmsRemoveCs = XmStringCreateLtoR( soRemoveCs.data(), XmFONTLIST_DEFAULT_TAG ); widRemoveCs_ = XtVaCreateManagedWidget( "removecs", xmToggleButtonWidgetClass, widRadioBox, XmNset, True, // default XmNlabelString, xmsRemoveCs, NULL ); XmStringFree( xmsRemoveCs ); RWCString soFlip( "Flip scaffold, and then do above" ); breakIntoShorterLines( soFlip, 50 ); XmString xmsFlip = XmStringCreateLtoR( soFlip.data(), XmFONTLIST_DEFAULT_TAG ); widFlipScaffold_ = XtVaCreateManagedWidget( "flip", xmToggleButtonWidgetClass, widRadioBox, XmNset, False, XmNlabelString, xmsFlip, NULL ); XmStringFree( xmsFlip ); XtManageChild( widRadioBox ); RWCString soUnfixOrientation( "Unfix orientation (allow phrap and consed to modify orientations)" ); breakIntoShorterLines( soUnfixOrientation, 50 ); XmString xmsUnfixOrientation = XmStringCreateLtoR( soUnfixOrientation.data(), XmFONTLIST_DEFAULT_TAG ); widUnfixOrientation_ = XtVaCreateManagedWidget( "unfixorientation", xmToggleButtonWidgetClass, widRadioBox, XmNset, False, XmNlabelString, xmsUnfixOrientation, NULL ); XmStringFree( xmsUnfixOrientation ); // end of radio box RWCString soWarning( "( All scaffolds and contigs may have their orientations changed by phrap and consed unless you do one of these operations)" ); breakIntoShorterLines( soWarning, 50 ); XmString xmsWarning = XmStringCreateLtoR( soWarning.data(), XmFONTLIST_DEFAULT_TAG ); Widget widWarning = XtVaCreateManagedWidget( "warning", xmLabelWidgetClass, widForm, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, widBelow, XmNlabelString, xmsWarning, XmNalignment, XmALIGNMENT_BEGINNING, NULL ); widBelow = widWarning; XmStringFree( xmsWarning ); XmString xmsWhatToDo = XmStringCreateLocalized( "What to do with scaffold selected above:" ); Widget widWhatToDo = XtVaCreateManagedWidget( "whatToDo", xmLabelWidgetClass, widForm, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, widBelow, XmNlabelString, xmsWhatToDo, NULL ); widBelow = widWhatToDo; XmStringFree( xmsWhatToDo ); // start of scrolled list of scaffolds Arg aArg[500]; int nArgs = 0; XtSetArg( aArg[nArgs], XmNselectionPolicy, XmEXTENDED_SELECT ); ++nArgs; XtSetArg( aArg[nArgs], XmNtopAttachment, XmATTACH_WIDGET ); ++nArgs; XtSetArg( aArg[nArgs], XmNtopWidget, widAbove ); ++nArgs; XtSetArg( aArg[nArgs], XmNbottomAttachment, XmATTACH_WIDGET ); ++nArgs; XtSetArg( aArg[nArgs], XmNleftAttachment, XmATTACH_FORM ); ++nArgs; XtSetArg( aArg[nArgs], XmNrightAttachment, XmATTACH_FORM ); ++nArgs; XtSetArg( aArg[nArgs], XmNbottomWidget, widBelow ); ++nArgs; XtSetArg( aArg[nArgs], XmNvisibleItemCount, 10 ); ++nArgs; widScaffoldList_ = XmCreateScrolledList( widForm, "list", aArg, nArgs ); XtManageChild( widScaffoldList_ ); displayScaffolds(); XtPopup( widPopupShell_, XtGrabNone ); } guiReorientContigs :: ~guiReorientContigs() { XtPopdown( widPopupShell_ ); XtDestroyWidget( widPopupShell_ ); if ( pAssemblyView_ ) { pAssemblyView_->pGuiReorientContigs_ = NULL; } } void guiReorientContigs :: displayScaffolds() { XmStringTable ppXtString = (XmStringTable) XtMalloc( aScaffolds_.length() * sizeof( XmString ) ); int nScaffold; for( nScaffold = 0; nScaffold < aScaffolds_.length(); ++nScaffold ) { clScaffold* pScaffold = aScaffolds_[ nScaffold ]; RWCString soScaffold = pScaffold->soGetDescription(); ppXtString[ nScaffold ] = XmStringCreateLocalized( soScaffold.data() ); } XtVaSetValues( widScaffoldList_, XmNitems, ppXtString, XmNitemCount, aScaffolds_.length(), NULL ); // free memory for( nScaffold = 0; nScaffold < aScaffolds_.length(); ++nScaffold ) { XmStringFree( ppXtString[ nScaffold ] ); } XtFree( (char*) ppXtString ); } const char cREMOVE_THE_CS = 'r'; const char cFLIP_SCAFFOLD = 'f'; const char cUNFIX_ORIENTATION = 'u'; void guiReorientContigs :: userPushedApplyAndRestartAssemblyView() { char cWhatToDo = ' '; if ( XmToggleButtonGetState( widRemoveCs_ ) == True ) cWhatToDo = cREMOVE_THE_CS; else if ( XmToggleButtonGetState( widFlipScaffold_ ) == True ) cWhatToDo = cFLIP_SCAFFOLD; else if ( XmToggleButtonGetState( widUnfixOrientation_ ) == True ) cWhatToDo = cUNFIX_ORIENTATION; else assert( false ); int nWhichScaffoldIsSelected = -666; int* pPositionList; int nNumberOfSelectedItems = 0; if ( !XmListGetSelectedPos( widScaffoldList_, &pPositionList, &nNumberOfSelectedItems ) || nNumberOfSelectedItems == 0 ) { popupErrorMessage2( widPopupShell_, "First select a scaffold" ); return; } pAssemblyView_->bDoNotDeleteGuiReorientContigs_ = true; delete pAssemblyView_; // changed April 2010 to allow multiple scaffolds to be // selected for( int nScaffold = 0; nScaffold < nNumberOfSelectedItems; ++nScaffold ) { int nZeroBasedIndex = pPositionList[nScaffold] - 1; clScaffold* pScaffold = aScaffolds_[ nZeroBasedIndex ]; if ( cWhatToDo == cUNFIX_ORIENTATION ) { pScaffold->unfixOrientation(); // not sure I need to restart assemblyView, but I'll // do so to be consistent } else { if ( cWhatToDo == cREMOVE_THE_CS ) { pScaffold->removeTheCs(); } else if ( cWhatToDo == cFLIP_SCAFFOLD ) { pScaffold->flipScaffold(); pScaffold->removeTheCs(); } RWCString soErrorMessage; pScaffold->fixOrientation( soErrorMessage ); if ( !soErrorMessage.isNull() ) { popupErrorMessage2( widPopupShell_, soErrorMessage ); } } } // for( int nScaffold = 0; nScaffold < nNumberOfSelectedItems; delete this; // restart assembly view ConsEd::pGetConsEd()->pAssemblyView_ = new assemblyView( ); ConsEd::pGetConsEd()->pAssemblyView_->createWindow( ConsEd::pGetAssembly() ); } void guiReorientContigs :: raiseWindow() { XtMapWidget( widPopupShell_ ); XRaiseWindow( XtDisplay( widPopupShell_ ), XtWindow( widPopupShell_ ) ); }