rmi != mapping . references . end( ); rmi ++ )
rmi != mapping . references . end( ); ++ rmi )
void RefineConflicts (Mapping_t & mapping){  ReadMap_t temprm;  temprm . place = new ReadAlignChain_t( );  temprm . place -> head = new ReadAlign_t( );  long int cpos, beg, end;  Reference_t * rp;  ReadAlign_t * rap;  list<Conflict_t *>::iterator cpi, locpi, hicpi, bcpi, ecpi;  map<string, Reference_t>::iterator rmi;  vector<ReadMap_t *>::iterator rmpi, rmpie, ri;  pair<    vector<ReadMap_t *>::iterator,    vector<ReadMap_t *>::iterator    > rmpip;  vector<ReadMap_t *> heap;  vector<Conflict_t *> breaks;  vector<Conflict_t *>::iterator bi;  //-- For each reference and its conflicts  for ( rmi  = mapping . references . begin( );	rmi != mapping . references . end( ); rmi ++ )    {      rp = &(rmi -> second);      bcpi = rp -> conflicts . begin( );      ecpi = rp -> conflicts . end( );      //-- Find the read mapping range      temprm . place -> head -> ref = rp;      rmpip = equal_range (mapping . reads . begin( ), mapping . reads . end( ),			   &temprm, ReadReferenceCmp_t( ));      rmpi = rmpip . first;      rmpie = rmpip . second;      //-- For each *BREAK*, collect nay counts      for ( cpi = bcpi; cpi != ecpi; cpi ++ )	{	  if ( (*cpi) -> type == Conflict_t::INDEL )	    continue;	  cpos = (*cpi) -> pos;	  //-- Update the heap to current conflict pos	  while ( !heap . empty( )  &&  heap . front( ) -> place -> end < cpos )	    PopHeap (heap);	  //-- Load up the heap with reads that overlap the conflict	  for ( ; rmpi != rmpie  &&  (*rmpi) -> place -> beg <= cpos; rmpi ++ )	    if ( (*rmpi) -> place -> end >= cpos )	      PushHeap (heap, *rmpi);	  //-- Collect the nay counts, i.e. reads that do not agree on break	  for ( ri = heap . begin( ); ri != heap . end( ); ri ++ )	    for ( rap = (*ri) -> place -> head; rap != NULL; rap = rap->from )	      if ( rap -> loR < cpos - FUZZY  &&  rap -> hiR > cpos + FUZZY )		{		  (*cpi) -> discount . push_back (*ri);		  break;		}	  //-- Sort and unique-ify the support vectors	  sort ((*cpi) -> support . begin( ), (*cpi) -> support . end( ));	  ri = unique ((*cpi)->support . begin( ), (*cpi)-> support . end( ));	  if ( ri != (*cpi) -> support . end( ) )	    (*cpi) -> support . erase (ri, (*cpi) -> support . end( ));	  sort ((*cpi) -> discount . begin( ), (*cpi) -> discount . end( ));	  ri = unique ((*cpi)->discount . begin( ), (*cpi)-> discount . end( ));	  if ( ri != (*cpi) -> discount . end( ) )	    (*cpi) -> discount . erase (ri, (*cpi) -> discount .end( ));	  //-- Decide whether or not BREAK is real	  if ( (*cpi) -> support . size( ) > (*cpi) -> discount . size( ) )	    (*cpi) -> status = Conflict_t::SUPPORTED;	  else	    (*cpi) -> status = Conflict_t::UNSUPPORTED;	}      heap . clear( );      //-- For each *INDEL*, sum yay/nay counts from its break counts      for ( cpi = bcpi; cpi != ecpi; cpi ++ )	{	  if ( (*cpi) -> type != Conflict_t::INDEL )	    continue;	  //-- The reference breaks for the gap	  beg = (*cpi) -> pos;	  end = (*cpi) -> pos + (*cpi) -> gapR + 1;	  hicpi = locpi = cpi;	  while ( hicpi != bcpi  &&  beg - (*hicpi) -> pos <= FUZZY )	    hicpi --;	  while ( locpi != bcpi  &&  end - (*locpi) -> pos <= FUZZY )	    locpi --;	  //-- Find hang conflicts corresponding to the reference HIBREAK	  for ( ; hicpi != ecpi  &&  (*hicpi) -> pos - beg <= FUZZY; hicpi ++ )	    if ( hicpi != cpi  &&  labs (beg - (*hicpi) -> pos) <= FUZZY )	      {		breaks . push_back (*hicpi);		if ( (*hicpi) -> type == Conflict_t::HIBREAK )		  {		    //-- Add to INDEL support if hang isn't too large		    if ( (*cpi)->support.size( ) >= (unsigned int)MININDELS )		      for ( ri  = (*hicpi) -> support . begin( );			    ri != (*hicpi) -> support . end( ); ri ++ )			if ( (*ri) -> place -> end - beg <			     (*cpi) -> gapQ + OPT_MaxTrimLen )			  (*cpi) -> support . push_back (*ri);		    //-- Add to INDEL discount		    for ( ri  = (*hicpi) -> discount . begin( );			  ri != (*hicpi) -> discount . end( ); ri ++ )		      (*cpi) -> discount . push_back (*ri);		  }	      }	  //-- Find hang conflicts corresponding to the reference LOBREAK	  for ( ; locpi != ecpi  &&  (*locpi) -> pos - end <= FUZZY; locpi ++ )	    if ( locpi != cpi  &&  labs (end - (*locpi) -> pos) <= FUZZY )	      {		breaks . push_back (*locpi);		if ( (*locpi) -> type == Conflict_t::LOBREAK )		  {		    //-- Add to INDEL support if hang isn't too large		    if ( (*cpi)->support.size( ) >= (unsigned int)MININDELS )		      for ( ri  = (*locpi) -> support . begin( );			    ri != (*locpi) -> support . end( ); ri ++ )			if ( end - (*ri) -> place -> beg <			     (*cpi) -> gapQ + OPT_MaxTrimLen )			  (*cpi) -> support . push_back (*ri);		    		    //-- Add to INDEL discount		    for ( ri  = (*locpi) -> discount . begin( );			  ri != (*locpi) -> discount . end( ); ri ++ )		      (*cpi) -> discount . push_back (*ri);		  }	      }	  //-- Sort and unique-ify the support vectors	  sort ((*cpi) -> support . begin( ), (*cpi) -> support . end( ));	  ri = unique ((*cpi)->support . begin( ), (*cpi)-> support . end( ));	  if ( ri != (*cpi) -> support . end( ) )	    (*cpi) -> support . erase (ri, (*cpi) -> support . end( ));	  sort ((*cpi) -> discount . begin( ), (*cpi) -> discount . end( ));	  ri = unique ((*cpi)->discount . begin( ), (*cpi)-> discount . end( ));	  if ( ri != (*cpi) -> discount . end( ) )	    (*cpi) -> discount . erase (ri, (*cpi) -> discount .end( ));	  //-- Decide whether or not INDEL is real	  if ( (*cpi) -> support . size( ) > (*cpi) -> discount . size( ) )	    (*cpi) -> status = Conflict_t::SUPPORTED;	  else	    (*cpi) -> status = Conflict_t::UNSUPPORTED;	  //-- If INDEL is real, flag its BREAKS as artificial	  if ( (*cpi) -> status == Conflict_t::SUPPORTED )	    for ( bi = breaks . begin( ); bi != breaks . end( ); bi ++ )	      {		//TODO - CHECK FOR BEST INDEL IF BREAK==INDEL		if ( (*bi) -> type == Conflict_t::INDEL )		  (*bi) -> status = Conflict_t::UNSUPPORTED;		else		  (*bi) -> status = Conflict_t::ARTIFICIAL;	      }	  breaks . clear( );	}      //-- EXCLUDE all "inconsistent" reads      for ( cpi = bcpi; cpi != ecpi; cpi ++ )	if ( (*cpi) -> status == Conflict_t::ARTIFICIAL )	  for ( ri  = (*cpi) -> support . begin( );		ri != (*cpi) -> support . end( ); ri ++ )	    (*ri) -> exclude = true;      for ( cpi = bcpi; cpi != ecpi; cpi ++ )	if ( (*cpi) -> status == Conflict_t::SUPPORTED )	  {	    for ( ri  = (*cpi) -> discount . begin( );		  ri != (*cpi) -> discount . end( ); ri ++ )	      (*ri) -> exclude = true;	    for ( ri  = (*cpi) -> support . begin( );		  ri != (*cpi) -> support . end( ); ri ++ )	      (*ri) -> exclude = false;	  }      for ( cpi = bcpi; cpi != ecpi; cpi ++ )	if ( (*cpi) -> status == Conflict_t::UNSUPPORTED )	  for ( ri  = (*cpi) -> support . begin( );		ri != (*cpi) -> support . end( ); ri ++ )	    (*ri) -> exclude = true;    }  delete temprm . place -> head;  delete temprm . place;}