/***************************************************************************** # 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 "guiShowErrorInfoForARegion.h" #include "handleWindowManagerDelete2.h" #include #include #include #include #include #include "popupErrorMessage.h" #include "bIsNumericMaybeWithWhitespace.h" #include #include "contig.h" #include "please_wait.h" #include "hp_exception_kludge.h" static void cbUserPushedDismiss( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiShowErrorInfoForARegion* pGuiShowError = (guiShowErrorInfoForARegion*) pClientData; TRY_CATCH_WRAPPER( delete pGuiShowError; ); } static void cbUserPushedCalculate( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiShowErrorInfoForARegion* pGuiShowError = (guiShowErrorInfoForARegion*) pClientData; TRY_CATCH_WRAPPER( pGuiShowError->calculate(); ); } guiShowErrorInfoForARegion :: ~guiShowErrorInfoForARegion() { XtPopdown( widPopupShell_ ); XtDestroyWidget( widPopupShell_ ); } void guiShowErrorInfoForARegion :: display() { widPopupShell_ = XtVaCreatePopupShell( "show error info for a region", topLevelShellWidgetClass, widParentShell_, XmNtitle, (char*) "Show Error Info For A Region", XmNtransient, False, XmNdeleteResponse, XmDO_NOTHING, NULL ); handleWindowManagerDelete2( widPopupShell_, cbUserPushedDismiss, this ); Widget widForm = XtVaCreateManagedWidget( "form", xmFormWidgetClass, widPopupShell_, XmNancestorSensitive, True, NULL ); widDismissButton_ = XtVaCreateManagedWidget( "Dismiss", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 45, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 55, NULL ); XtAddCallback( widDismissButton_, XmNactivateCallback, cbUserPushedDismiss, this ); const int nLabelPosition = 60; const int nFieldPosition = 65; Widget widLeftPositionLabel = XtVaCreateManagedWidget( "Left Consensus Position of Region:", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, nLabelPosition, XmNalignment, XmALIGNMENT_END, NULL ); widLeftPosition_ = XtVaCreateManagedWidget( "left", xmTextFieldWidgetClass, widForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, widLeftPositionLabel, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, nFieldPosition, XmNcolumns, 10, NULL ); Widget widRightPositionLabel = XtVaCreateManagedWidget( "Right Consensus Position of Region:", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widLeftPosition_, XmNtopOffset, 10, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, nLabelPosition, XmNalignment, XmALIGNMENT_END, NULL ); widRightPosition_ = XtVaCreateManagedWidget( "right", xmTextFieldWidgetClass, widForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, widRightPositionLabel, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, nFieldPosition, XmNcolumns, 10, NULL ); // this allows me to just hit return instead of clicking on calculate XtAddCallback( widRightPosition_, XmNactivateCallback, cbUserPushedCalculate, this ); Widget widCalculateButton = XtVaCreateManagedWidget( "Calculate", xmPushButtonWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widRightPosition_, XmNtopOffset, 20, XmNbottomOffset, 20, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 45, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 55, XmNtraversalOn, False, NULL ); XtAddCallback( widCalculateButton, XmNactivateCallback, cbUserPushedCalculate, this ); Widget widTotalErrorsLabel = XtVaCreateManagedWidget( "Total Errors (ignoring edited bases):", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widCalculateButton, XmNtopOffset, 10, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, nLabelPosition, XmNalignment, XmALIGNMENT_END, NULL ); widTotalErrors_ = XtVaCreateManagedWidget( "total errors", xmTextFieldWidgetClass, widForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, widTotalErrorsLabel, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, nFieldPosition, XmNcolumns, 10, XmNeditable, False, XmNcursorPositionVisible, False, XmNtraversalOn, False, NULL ); Widget widErrorRateLabel = XtVaCreateManagedWidget( "Error Rate (per 10kb):", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widTotalErrors_, XmNtopOffset, 10, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, nLabelPosition, XmNalignment, XmALIGNMENT_END, NULL ); widErrorRate_ = XtVaCreateManagedWidget( "error rate", xmTextFieldWidgetClass, widForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, widErrorRateLabel, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, nFieldPosition, XmNcolumns, 10, XmNeditable, False, XmNcursorPositionVisible, False, XmNtraversalOn, False, NULL ); Widget widSingleSubcloneBasesLabel = XtVaCreateManagedWidget( "Single Subclone Bases:", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widErrorRate_, XmNtopOffset, 10, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, nLabelPosition, XmNalignment, XmALIGNMENT_END, NULL ); widSingleSubcloneBases_ = XtVaCreateManagedWidget( "single subclone bases", xmTextFieldWidgetClass, widForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, widSingleSubcloneBasesLabel, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, nFieldPosition, XmNcolumns, 10, XmNeditable, False, XmNcursorPositionVisible, False, XmNtraversalOn, False, NULL ); XtVaSetValues( widSingleSubcloneBases_, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, widDismissButton_, XmNbottomOffset, 20, NULL ); XtPopup( widPopupShell_, XtGrabNone ); } void guiShowErrorInfoForARegion :: calculate() { char* szValue; RWCString soValue; szValue = XmTextFieldGetString( widLeftPosition_ ); soValue = szValue; XtFree( szValue ); int nLeftPosition; if ( !bIsNumericMaybeWithWhitespace( soValue, nLeftPosition ) ) { popupErrorMessage( "left consensus position must be numeric" ); return; } szValue = XmTextFieldGetString( widRightPosition_ ); soValue = szValue; XtFree( szValue ); int nRightPosition; if ( !bIsNumericMaybeWithWhitespace( soValue, nRightPosition ) ) { popupErrorMessage( "right consensus position must be numeric" ); return; } if ( nLeftPosition > nRightPosition ) { int nTemp = nRightPosition; nRightPosition = nLeftPosition; nLeftPosition = nTemp; } if ( nLeftPosition < pContig_->nGetUnpaddedStartIndex() ) { popupErrorMessage( "left position %d must not be less than %d, the beginning of the consensus", nLeftPosition, pContig_->nGetUnpaddedStartIndex() ); return; } if ( nRightPosition > pContig_->nGetUnpaddedEndIndex() ) { popupErrorMessage( "right position %d must not be more than %d, the end of the consensus", nRightPosition, pContig_->nGetUnpaddedEndIndex() ); return; } // passed all checks PleaseWait* pPleaseWait = new PleaseWait( widPopupShell_ ); double dTotalErrors; int nTotalNonEditedBases; double dErrorRate; pContig_->getErrorInfo( nLeftPosition, nRightPosition, dTotalErrors, nTotalNonEditedBases, dErrorRate ); int nSingleSubcloneBases; pContig_->getSingleSubcloneInfo( nLeftPosition, nRightPosition, nSingleSubcloneBases ); // total errors char szTotalErrors[100]; if ( nTotalNonEditedBases != 0 ) sprintf( szTotalErrors, "%6.4f", dTotalErrors ); else strcpy( szTotalErrors, "???" ); XtVaSetValues( widTotalErrors_, XmNvalue, szTotalErrors, NULL ); // error rate char szErrorRate[100]; if ( nTotalNonEditedBases == 0 ) strcpy( szErrorRate,"???" ); else { double dErrorsPer10Kb = dErrorRate * 10000.0; if ( dErrorsPer10Kb > 999 ) sprintf( szErrorRate, "%6.0f", dErrorsPer10Kb ); else if ( dErrorsPer10Kb < 0 ) strcpy( szErrorRate, "???" ); else sprintf( szErrorRate, "%6.4f", dErrorsPer10Kb ); } XtVaSetValues( widErrorRate_, XmNvalue, szErrorRate, NULL ); // single subclone bases char szSingleSubcloneBases[100]; sprintf( szSingleSubcloneBases, "%d", nSingleSubcloneBases ); XtVaSetValues( widSingleSubcloneBases_, XmNvalue, szSingleSubcloneBases, NULL ); delete pPleaseWait; }