void fillArr( vector<int> &arr, MSVS &mp ){ arr.push_back( 0 ); for( MSVS::iterator p = mp.begin(); p != mp.end() ; ++p ){ string key; key = p->first; arr.push_back( getStart( key ) ); arr.push_back( getEnd( key ) ); } }
// MSVS:map(START$END, set<Gene> ) , there is only one Gene in set void block ( MSVS &mp ){ MSVS::iterator p, pNext, pTmp; int pStart, pEnd, nextStart, nextEnd ; // two old int leftEnd, midStart, midEnd, rightStart; // three new string leftKey, midKey, rightKey; stringstream ss; if( mp.size() < 2 ) return; p = mp.begin(); pNext = p; ++pNext ; while( pNext != mp.end() ) { pStart = getStart( p->first ); pEnd = getEnd( p->first ); nextStart = getStart( pNext->first ); nextEnd = getEnd( pNext->first ); //cout << "Enter loop: p is ( " << pStart << ", " << pEnd << "), pNext is ( " << nextStart << ", " << nextEnd << " )." << endl; if( nextStart > pEnd ){ //cout << "no overlap " << endl; // (3,8 ) (9, 12 ) 9 > 8 p = pNext; ++pNext; continue; } if( nextStart > pStart ){ //cout << "insert left " << endl; leftEnd = nextStart - 1; ss.str(""); ss << pStart << "$" << leftEnd; leftKey = ss.str(); //cout << "leftKey is : " << leftKey << endl; mp.insert( MSVS::value_type ( leftKey, p->second ) ); } if( nextEnd > pEnd ){ // ( 3,10) (3,7) 10 > 7 //cout << "insert right" << endl; rightStart = pEnd + 1; ss.str(""); ss << rightStart << "$" << nextEnd ; rightKey = ss.str(); //cout << "rightKey is : " << rightKey << endl; pTmp = mp.find( rightKey ); if ( pTmp != mp.end() ) pTmp->second.insert( pNext->second.begin(), pNext->second.end() ); else mp.insert( MSVS::value_type( rightKey, pNext->second ) ); if( nextStart > pStart ){ //cout << "insert middle" << endl; midStart = nextStart; midEnd = pEnd; ss.str(""); ss << midStart << "$" << midEnd ; midKey = ss.str(); //cout << "midKey is : " << midKey << endl; mp.insert( MSVS::value_type( midKey, p->second ) ); mp.erase( p ); pTmp = mp.find( midKey ); pTmp->second.insert( pNext->second.begin(), pNext->second.end() ); p = pTmp; } else if ( nextStart == pStart ) p->second.insert( pNext->second.begin(), pNext->second.end() ); mp.erase( pNext ); pNext = p; ++pNext; } // when nextEnd <= pEnd else { pNext->second.insert( p->second.begin(), p->second.end() ); // nextStart > pStart , nextEnd <= pEnd, pNext is middle if ( nextEnd < pEnd ){ // (4,6 ) (3,8) //cout << "insert right " << endl; rightStart = nextEnd + 1; ss.str(""); ss << rightStart << "$" << pEnd ; rightKey = ss.str(); //cout << "rightKey is : " << rightKey << endl; pTmp = mp.find( rightKey ); if( pTmp != mp.end() ) pTmp->second.insert( p->second.begin(),p->second.end() ); else mp.insert( MSVS::value_type ( rightKey, p->second ) ); } mp.erase ( p ) ; p = pNext; ++pNext; } } }