/***************************************************************************** # 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 "basesAndQualitiesAndPeaks.h" #include "mbt_exception.h" #include "complement_so.h" #include "assert.h" void basesAndQualitiesAndPeaks :: appendPointPos( const int nPointPos ) { if ( cWhichPeakPositionsAreUsed_ == cLittle ) { pLittlePeakPositions_->append( nPointPos ); } else if ( cWhichPeakPositionsAreUsed_ == cBig ) { pBigPeakPositions_->append( nPointPos ); } else { RWCString soError = "tried to basesAndQualitiesAndPeaks::appendPointPos when the cWhichPeakPositionsAreUsed_ = "; soError += RWCString( cWhichPeakPositionsAreUsed_ ); THROW_ERROR2( soError ); } } void basesAndQualitiesAndPeaks :: createPointPosArray( const bool bFoundTraceArrayMaxIndex, const int nTraceArrayMaxIndex, const size_t nInitialSizeOfArray, const bool bFillUpArray ) { unsigned short int s = 0; s = ~s; int nMaxNumberInShort = (int) s / 2; // the -10 is just to be on the safe side. short's are good to // about 32,000 if ( bFoundTraceArrayMaxIndex && nTraceArrayMaxIndex < (nMaxNumberInShort - 10 ) ) { createPointPosArray2( cLittle, nInitialSizeOfArray, bFillUpArray ); } else { createPointPosArray2( cBig, nInitialSizeOfArray, bFillUpArray ); } } void basesAndQualitiesAndPeaks :: createPointPosArray2( const char cWhichPeakPositionsAreUsed, const size_t nInitialSizeOfArray, const bool bFillUpArray ) { if ( cWhichPeakPositionsAreUsed == cLittle ) { pLittlePeakPositions_ = new RWTValOrderedVector( (size_t) nInitialSizeOfArray ); pLittlePeakPositions_->soName_ = "basesAndQualitiesAndPeaks::pLittlePeakPositions_"; cWhichPeakPositionsAreUsed_ = cLittle; if ( bFillUpArray ) pLittlePeakPositions_->nCurrentLength_ = nInitialSizeOfArray; } else if ( cWhichPeakPositionsAreUsed == cBig ) { pBigPeakPositions_ = new RWTValOrderedVector( (size_t) nInitialSizeOfArray ); pBigPeakPositions_->soName_ = "basesAndQualitiesAndPeaks::pBigPeakPositions_"; cWhichPeakPositionsAreUsed_ = cBig; if ( bFillUpArray ) pBigPeakPositions_->nCurrentLength_ = nInitialSizeOfArray; } else { RWCString soError = "basesAndQualitiesAndPeaks::createPointPosArray2 and cWhichPeakPositionsAreUsed = "; soError += cWhichPeakPositionsAreUsed; THROW_ERROR2( soError ); } } void basesAndQualitiesAndPeaks :: setPointPosArraySubstring( const basesAndQualitiesAndPeaks* pBigRead, const int n0Start, const int nLength ) { assert( 0 <= n0Start ); assert( 0 < nLength ); // for example, could ask for the entire read: n0Start = 0, // nLength = pBigRead->nCurrentLength_ so need <= below assert( n0Start + nLength <= pBigRead->soBases_.length() ); createPointPosArray2( pBigRead->cWhichPeakPositionsAreUsed_, nLength, true ); // just sets nCurrentLength_ if ( cWhichPeakPositionsAreUsed_ == cLittle ) { for( int n = 0; n < nLength; ++n ) { (*pLittlePeakPositions_)[n] = (*pBigRead->pLittlePeakPositions_)[ n0Start + n]; } } else if ( cWhichPeakPositionsAreUsed_ == cBig ) { for( int n = 0; n < nLength; ++n ) { (*pBigPeakPositions_)[n] = (*(pBigRead->pBigPeakPositions_))[ n0Start + n]; } } else { THROW_ERROR( "setPointPosArraySubstring for " + soSequenceName_ + " but cWhichPeakPositionsAreUsed = " + RWCString( cWhichPeakPositionsAreUsed_ ) ); } } int basesAndQualitiesAndPeaks :: nGetPointPos( const int n0PaddedSeqPos ) const { if ( cWhichPeakPositionsAreUsed_ == cLittle ) { return( (*pLittlePeakPositions_)[ n0PaddedSeqPos ] ); } else if ( cWhichPeakPositionsAreUsed_ == cBig ) { return( (*pBigPeakPositions_)[ n0PaddedSeqPos ] ); } else { RWCString soError = "In sequence "; soError += soSequenceName_; soError += " Sequence::nGetPointPos was called for n0PaddedSeqPos = "; soError += RWCString( (long) n0PaddedSeqPos ); soError += " when cWhichPeakPositionsAreUsed_ = "; soError += cWhichPeakPositionsAreUsed_; THROW_ERROR( soError ); } } void basesAndQualitiesAndPeaks :: reverseComplementThyself() { soBases_ = soComplementSO( soBases_ ); aQualities_.reverseElementOrder(); if ( cWhichPeakPositionsAreUsed_ == cBig ) { pBigPeakPositions_->reverseElementOrder(); for( int nPeak = 0; nPeak < pBigPeakPositions_->length(); ++nPeak ) { (*pBigPeakPositions_)[ nPeak ] = nTraceArrayMaxIndex_ - (*pBigPeakPositions_)[ nPeak ]; } } else if ( cWhichPeakPositionsAreUsed_ == cLittle ) { pLittlePeakPositions_->reverseElementOrder(); for( int nPeak = 0; nPeak < pLittlePeakPositions_->length(); ++nPeak ) { (*pLittlePeakPositions_)[ nPeak ] = nTraceArrayMaxIndex_ - (*pLittlePeakPositions_)[ nPeak ]; } } }