//-------------------------------------------------------------------------------------- void ImplProfile::__save( std::ostream & output, MagicNumberType type ) const { debug_func_cerr(5); if (type == MNNoType ) { type = MNImplProfile; output.write( (char*)&type, sizeof(MagicNumberType ) ); } ImplAlignandum::__save( output, type ); output.write( (char*)&mProfileWidth, sizeof(Residue) ); size_t size = getFullLength() * mProfileWidth; if ( mStorageType == Full ) { output.write( (char*)mWeightedCountMatrix->getData(), sizeof(WeightedCount) * size); if (isPrepared() ) { output.write( (char*)mFrequencyMatrix->getData(), sizeof(Frequency) * size); output.write( (char*)mScoreMatrix->getData(), sizeof(Score) * size ); } } else if ( mStorageType == Sparse ) { saveSparseMatrix<WeightedCount>( output, mWeightedCountMatrix ); if (isPrepared() ) { saveSparseMatrix<Frequency>( output, mFrequencyMatrix ); // can only compress counts and frequencies output.write( (char*)mScoreMatrix->getData(), sizeof(Score) * size ); } } }
Matrix<T> * ImplProfile::allocateSegment( Matrix<T> * data ) const { debug_func_cerr(5); if (data != NULL) delete data; data = new Matrix<T>( getFullLength(), mProfileWidth, 0 ); return data; }
//--------------------------------------------------------------------------------------------------------------- void ImplProfile::allocateCounts() const { debug_func_cerr(5); mProfileWidth = getToolkit()->getEncoder()->getAlphabetSize(); debug_cerr( 3, "allocating counts for a profile of size " << getFullLength() << " x " << (int)mProfileWidth ); mWeightedCountMatrix = allocateSegment<WeightedCount>( mWeightedCountMatrix ); }
QByteArray DeBruijnNode::getGfaSegmentLine() const { QByteArray gfaSegmentLine = "S\t"; gfaSegmentLine += getNameWithoutSign() + "\t"; gfaSegmentLine += getFullSequence() + "\t"; gfaSegmentLine += "LN:i:" + QString::number(getFullLength()) + "\t"; gfaSegmentLine += "RC:i:" + QString::number(int(getReadDepth() * getLength() + 0.5)); gfaSegmentLine += "\n"; return gfaSegmentLine; }
//-------------------------------------------------------------------------------------- void ImplProfile::load( std::istream & input) { debug_func_cerr(5); ImplAlignandum::load( input ); input.read( (char*)&mProfileWidth, sizeof( Residue ) ); size_t size = getFullLength() * mProfileWidth; if ( mStorageType == Full ) { allocateCounts(); input.read( (char*)mWeightedCountMatrix->getData(), sizeof( WeightedCount) * size ); if (input.fail() ) throw AlignlibException( "incomplete profile in stream."); if (isPrepared() ) { allocateFrequencies(); input.read( (char*)mFrequencyMatrix->getData(), sizeof( Frequency) * size ); allocateScores(); input.read( (char*)mScoreMatrix->getData(), sizeof(Score) * size ); } } else if ( mStorageType == Sparse ) { allocateCounts(); loadSparseMatrix<WeightedCount>( input, mWeightedCountMatrix ); if (input.fail() ) throw AlignlibException( "incomplete profile in stream."); if (isPrepared() ) { allocateFrequencies(); loadSparseMatrix<Frequency>( input, mFrequencyMatrix ); allocateScores(); input.read( (char*)mScoreMatrix->getData(), sizeof(Score) * size ); } } }
//------------------------------------------------------------------------------------------ void ImplProfile::add( const HAlignandum & source, const HAlignment & map_source2dest, bool is_reverse ) { debug_func_cerr(5); debug_cerr( 3, "adding to profile: is_reverse=" << is_reverse << " this=" << map_source2dest->getRowFrom() << "-" << map_source2dest->getRowTo() << " len=" << getFullLength() << " other=" << map_source2dest->getColFrom() << "-" << map_source2dest->getColTo() << " len=" << source->getFullLength() ); assert( source->getToolkit()->getEncoder()->getAlphabetSize() == getToolkit()->getEncoder()->getAlphabetSize()); if (is_reverse) { assert (map_source2dest->getColTo() <= source->getFullLength() ); assert (map_source2dest->getRowTo() <= getFullLength() ); } else { assert (map_source2dest->getRowTo() <= source->getFullLength() ); assert (map_source2dest->getColTo() <= getFullLength() ); } const HSequence sequence(toSequence( source )); if (sequence) { AlignmentIterator it(map_source2dest->begin()); AlignmentIterator it_end(map_source2dest->end()); if (is_reverse) { for (; it != it_end; ++it) { Position row = it->mCol; Position col = it->mRow; Residue i = sequence->asResidue(row); mWeightedCountMatrix->addValue(col,i,1); } } else { for (; it != it_end; ++it) { Position row = it->mRow; Position col = it->mCol; Residue i = sequence->asResidue(row); mWeightedCountMatrix->addValue(col,i,1); } } } else { const HProfile profile(toProfile(source)); if (profile) { AlignmentIterator it(map_source2dest->begin()); AlignmentIterator it_end(map_source2dest->end()); HWeightedCountMatrix m(profile->getWeightedCountMatrix()); if (is_reverse) { for (; it != it_end; ++it) { Position row = it->mCol; Position col = it->mRow; for (Residue i = 0; i < mProfileWidth; i++) mWeightedCountMatrix->addValue(col,i,(*m)[row][i]); } } else { for (; it != it_end; ++it) { Position row = it->mRow; Position col = it->mCol; for (Residue i = 0; i < mProfileWidth; i++) mWeightedCountMatrix->addValue(col,i,(*m)[row][i]); } } } else throw AlignlibException( "can not guess type of src - neither profile nor sequence"); } if (isPrepared()) { release(); // first release, otherwise it won't calculate anew prepare(); } }