/***************************************************************************** # 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 "guiSaveHighlightedReads.h" #include #include #include #include "handleWindowManagerDelete2.h" #include #include #include #include #include "hp_exception_kludge.h" #include "guicontigwin.h" #include "filePopupAndGetFilename.h" #include "bGuiGetAnswerYesNo.h" #include "consed.h" #include "please_wait.h" #include "popupInfoMessage.h" static void cbUserPushedCancel( Widget wid, XtPointer pClientData, XtPointer pCallData ) { TRY_CATCH_WRAPPER( guiSaveHighlightedReads* pGuiSaveHighlightedReads = (guiSaveHighlightedReads*) pClientData; pGuiSaveHighlightedReads->userPushedCancel() ); } static void cbUserPushedOK( Widget wid, XtPointer pClientData, XtPointer pCallData ) { TRY_CATCH_WRAPPER( guiSaveHighlightedReads* pGuiSaveHighlightedReads = (guiSaveHighlightedReads*) pClientData; pGuiSaveHighlightedReads->userPushedOK(); ); } static void cbUserPushedBrowse( Widget wid, XtPointer pClientData, XtPointer pCallData ) { TRY_CATCH_WRAPPER( guiSaveHighlightedReads* pGuiSaveHighlightedReads = (guiSaveHighlightedReads*) pClientData; pGuiSaveHighlightedReads->userPushedBrowse(); ); } void guiSaveHighlightedReads :: createWindow() { widPopupShell_ = XtVaCreatePopupShell( "Save Highlighted Reads", topLevelShellWidgetClass, pGuiContigWin_->widGetGuiContigWinTopLevel(), XmNdeleteResponse, XmDO_NOTHING, NULL ); handleWindowManagerDelete2( widPopupShell_, cbUserPushedCancel, this ); Widget widForm = XtVaCreateManagedWidget( "top form", xmFormWidgetClass, widPopupShell_, XmNshadowThickness, 0, XmNborderWidth, 0, NULL ); // start at bottom widOKButton_ = XtVaCreateManagedWidget( "OK", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 10, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 30, NULL ); XtAddCallback( widOKButton_, XmNactivateCallback, cbUserPushedOK, this ); widCancelButton_ = XtVaCreateManagedWidget( "Cancel", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 70, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 90, NULL ); Widget widBelow = widCancelButton_; XtAddCallback( widCancelButton_, XmNactivateCallback, cbUserPushedCancel, this ); // now work down from top Widget widFileNameLabel = XtVaCreateManagedWidget( "File to save read names:", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 10, XmNleftAttachment, XmATTACH_FORM, NULL ); widFileName_ = XtVaCreateManagedWidget( "filename", xmTextFieldWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widFileNameLabel, XmNleftAttachment, XmATTACH_FORM, XmNcolumns, 60, XmNeditable, True, XmNcursorPositionVisible, True, XmNtraversalOn, True, XmNvalue, pCP->filHighlightedReadsFile_.data(), NULL ); widBrowseButton_ = XtVaCreateManagedWidget( "Browse", xmPushButtonWidgetClass, widForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, widFileName_, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, widFileName_, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, widFileName_, NULL ); XtAddCallback( widBrowseButton_, XmNactivateCallback, cbUserPushedBrowse, this ); Widget widLabel2 = XtVaCreateManagedWidget( "Save reads just in this contig or in all contigs?", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widFileName_, XmNtopOffset, 20, XmNleftAttachment, XmATTACH_FORM, NULL ); Widget widRadioBox = XmCreateRadioBox( widForm, "radioBox", NULL, 0 ); XtVaSetValues( widRadioBox, XmNtraversalOn, True, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widLabel2, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, widBelow, XmNbottomOffset, 20, XmNleftAttachment, XmATTACH_FORM, XmNorientation, XmHORIZONTAL, XmNborderWidth, 0, XmNmarginWidth, 0, NULL ); widAllContigs_ = XtVaCreateManagedWidget( "All Contigs", xmToggleButtonWidgetClass, widRadioBox, XmNset, False, NULL ); Widget widJustThisContig = XtVaCreateManagedWidget( "Just This Contig", xmToggleButtonWidgetClass, widRadioBox, XmNset, True, NULL ); XtManageChild( widRadioBox ); XtPopup( widPopupShell_, XtGrabNone ); } guiSaveHighlightedReads :: ~guiSaveHighlightedReads() { XtPopdown( widPopupShell_ ); XtDestroyWidget( widPopupShell_ ); } void guiSaveHighlightedReads :: userPushedCancel() { delete this; } void guiSaveHighlightedReads :: userPushedBrowse() { FileName filChosenByUser = filePopupAndGetFilename( "*", // szDirMask "", // default filename "Select a file to write read names" ); // message if ( filChosenByUser.bIsNull() ) return; XmTextFieldSetString( widFileName_, filChosenByUser.data() ); } void guiSaveHighlightedReads :: userPushedOK() { char* szFile = XmTextFieldGetString( widFileName_ ); FileName filHighlighted( szFile ); XtFree( szFile ); if ( filHighlighted.bFileByThisNameExists() ) { bool bAppend = bGuiGetAnswerYesNo( "File already exists. Do you want to append (yes) or abort (no)?" ); if ( !bAppend ) return; } FILE* pFile = fopen( filHighlighted.data(), "a" ); if ( !pFile ) { THROW_FILE_ERROR( filHighlighted ); } bool bAllContigs = ( ( XmToggleButtonGetState( widAllContigs_ ) == True ) ? true : false ); PleaseWait* pPleaseWait = new PleaseWait( widPopupShell_ ); int nNumberOfReadsWritten = 0; if ( bAllContigs ) { Assembly* pAssembly = ConsEd::pGetAssembly(); for( int nContig = 0; nContig < pAssembly->nNumContigs(); ++nContig ) { Contig* pContig = pAssembly->pGetContig( nContig ); for( int nRead = 0; nRead < pContig->nGetNumberOfFragsInContig(); ++nRead ) { LocatedFragment* pLocFrag = pContig->pLocatedFragmentGet( nRead ); if ( pLocFrag->bReadCurrentlyHighlighted_ ) { ++nNumberOfReadsWritten; fprintf( pFile, "%s\n", pLocFrag->soGetName().data() ); } } } } else { Contig* pContig = pGuiContigWin_->pContigWin_->pContig_; for( int nRead = 0; nRead < pContig->nGetNumberOfFragsInContig(); ++nRead ) { LocatedFragment* pLocFrag = pContig->pLocatedFragmentGet( nRead ); if ( pLocFrag->bReadCurrentlyHighlighted_ ) { ++nNumberOfReadsWritten; fprintf( pFile, "%s\n", pLocFrag->soGetName().data() ); } } } fclose( pFile ); delete pPleaseWait; popupInfoMessage( pGuiContigWin_->widGetGuiContigWinTopLevel(), "%d reads written to %s\n", nNumberOfReadsWritten, filHighlighted.data() ); delete this; }