/***************************************************************************** # 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 "rwctokenizer.h" #include #include #include "nSystemReadALine.h" #include "someOtherProgramSentACommandToConsed.h" #include "contig.h" #include "assembly.h" #include "contigwin.h" #include "consed.h" #include "bIsNumericMaybeWithWhitespace.h" #include "locatedFragment.h" #include "popupErrorMessage.h" #include #include "socketConnection.h" void someOtherProgramSentACommandToConsed( XtPointer p, int* pFID, XtInputId* pID ) { socketConnection* pSocket = (socketConnection*) p; int nSocketFD = pSocket->nFileDescriptor_; cout << "some other program sent command to consed" << endl; #define nMaxLine 500 char szLine[nMaxLine]; int n = nSystemReadALine( nSocketFD, szLine, nMaxLine ); if (n == 0 ) { XtRemoveInput( pSocket->xtinputid_ ); close( nSocketFD ); return; /* connection terminated */ } else if (n < 0 ) { cout << "problem from readline since n = " << n << endl; } szLine[n] = '\0'; char szLine2[ nMaxLine ]; sprintf( szLine2, "# of chars = %d %s", strlen( szLine ), szLine ); cout << szLine2 << endl; RWCString soCommandToConsed( szLine ); RWCTokenizer tok( soCommandToConsed ); RWCString soCommandName = tok(); if ( soCommandName.isNull() ) { GuiApp::popupErrorMessage( "Some other program sent a null command to consed: " + soCommandToConsed ); return; } if (soCommandName == "Scroll" ) { RWCString soContigName = tok(); if (soContigName.isNull() ) { GuiApp::popupErrorMessage( "Some other program sent an incomplete scroll command to consed. Should be of form:\nScroll (contig) (base position)" ); return; } Assembly* pAssembly = ConsEd::pGetAssembly(); Contig* pContig = pAssembly->pGetContigByName( soContigName ); if (!pContig ) { GuiApp::popupErrorMessage( "Some other program sent following command but contig not found by consed:\n" + soCommandToConsed ); return; } RWCString soUnpaddedConsPos = tok(); if (soUnpaddedConsPos.isNull() ) { GuiApp::popupErrorMessage( "Some other program sent an incomplete scrol command to consed (missing base position). Should be of form:\nScroll (contig) (base position)" ); return; } int nUnpaddedPos; if (! bIsNumericMaybeWithWhitespace( soUnpaddedConsPos, nUnpaddedPos ) ) { GuiApp::popupErrorMessage( "Some other program sent a message with a non-numeric consensus position:\n" + soCommandToConsed ); return; } if (! pContig->bUnpaddedConsPosInRange( nUnpaddedPos ) ) { RWCString soMessage = "Some other program told consed to scroll to a location that is out of range. Command to consed is\n" + soCommandToConsed + " but range is %d to %d"; GuiApp::popupErrorMessage( soMessage, pContig->nGetUnpaddedStartIndex(), pContig->nGetUnpaddedEndIndex() ); return; } int nConsPos = pContig->nPaddedIndex( nUnpaddedPos ); ContigWin* pContigWin = ConsEd::pGetConsEd()->pScrollExistingContigWinOrMakeNewContigWin( pContig, nConsPos ); pContigWin->moveCursorToConsPos( nConsPos ); // raise the window--Bill Gilliland wanted 02/06/27 pContigWin->raiseWindow(); } // if (soCommandName == "Scroll" ) else if ( soCommandName == "PopupTraces" ) { RWCString soReadName = tok(); RWCString soReadPosition = tok(); if ( soReadName.isNull() ) { popupErrorMessage( "Some other program sent incomplete PopupTraces command to consed. Should be of the form:\nPopupTraces (read name) (read position)" ); return; } Assembly* pAssembly = ConsEd::pGetAssembly(); LocatedFragment* pLocFrag = pAssembly->pGetLocatedFragmentByName( soReadName ); if ( !pLocFrag ) { popupErrorMessage( "Some other program sent command " + soCommandName + " but couldn't find read " + soReadName ); return; } int nReadPosInDirectionOfSequencing; if ( !bIsNumericMaybeWithWhitespace( soReadPosition, nReadPosInDirectionOfSequencing ) ) { popupErrorMessage( "Some other program sent command " + soCommandName + " but read position " + soReadPosition + " wasn't numeric" ); return; } if ( ! ( ( pLocFrag->nGetUnpaddedStartIndex() <= nReadPosInDirectionOfSequencing ) && ( nReadPosInDirectionOfSequencing <= pLocFrag->nGetUnpaddedEndIndex() ) ) ) { popupErrorMessage( "Some other program sent command %s but position must be between %d and %d", (char*) soCommandName.data(), pLocFrag->nGetUnpaddedStartIndex(), pLocFrag->nGetUnpaddedEndIndex() ); return; } int nPaddedConsPos = pLocFrag->nConsPosFromOrientedUnpaddedFragPos( nReadPosInDirectionOfSequencing ); ContigWin* pContigWin = ConsEd::pGetConsEd()->pScrollExistingContigWinOrMakeNewContigWin( pLocFrag->pGetContig(), nPaddedConsPos ); cout << "popupTracesByConsensusPosition " << pLocFrag->soGetName() << " padded consensus position " << nPaddedConsPos << endl; pContigWin->popupTracesByConsensusPosition( pLocFrag, nPaddedConsPos ); } else { popupErrorMessage( "unrecognized command: " + soCommandName + " acceptable commands are Scroll and PopupTraces" ); } }