while ( rmpic != reads . end( ) ) {  if ( rmpic == rmpi ) { switch ( (*cpi) -> type ) { case Conflict_t::LOBREAK:  break;  case Conflict_t::HIBREAK:  rmpi = reads . end( ); break;  case Conflict_t::INDEL:  cp -> adjust += (*cpi) -> gapQ - (*cpi) -> gapR; break; } break; }   if ( binary_search ((*cpi) -> support . begin( ), (*cpi) -> support . end( ), *rmpic) ) { tp = new Tile_t (*rmpic, cp);    if ( (*cpi) -> type == Conflict_t::INDEL  && (*rmpic) -> place -> tbeg >= lmin (confbeg, confend) ) { tp -> off += (*cpi) -> gapQ - (*cpi) -> gapR; } else {  if ( ! cp -> tiles . empty( )  && tp -> off > cp -> len - OPT_MinOverlap ) {  cp = new Contig_t( ); assembly . contigs . push_back (cp); (*tp) = Tile_t (*rmpic, cp); } }   cp -> tiles . push_back (tp); currend = tp -> off + labs (tp -> end - tp -> beg) + 1; if ( currend > cp -> len ) cp -> len = currend;   rmpic = reads . erase (rmpic); }  else { ++ rmpic; } }   if ( cpi != confs . end( ) ) cpi = confs . erase (cpi);
cpi = confs . erase (cpi);
void Assemble (Mapping_t & mapping, Assembly_t & assembly){  ReadMap_t temprm;  temprm . place = new ReadAlignChain_t( );  temprm . place -> head = new ReadAlign_t( );  Reference_t * rp;  Contig_t * cp;  Tile_t * tp;  map<string, Reference_t>::iterator rmi;  list<Conflict_t *>::iterator cpi;  list<ReadMap_t *>::iterator rmpi, rmpic;  pair<    vector<ReadMap_t *>::iterator,    vector<ReadMap_t *>::iterator    > rmpip;  long int currend, confbeg, confend;  //-- For each reference  for ( rmi  = mapping . references . begin( );	rmi != mapping . references . end( ); ++ rmi )    {      rp = &(rmi -> second);      //-- Find the read mapping range      temprm . place -> head -> ref = rp;      rmpip = equal_range (mapping . reads . begin( ), mapping . reads . end( ),			   &temprm, ReadReferenceCmp_t( ));      //-- For all reads mapping to the reference      list<ReadMap_t *> reads (rmpip.first, rmpip.second);      reads . remove_if (ReadExcludePredicate_t( ));      //-- For all non-excluded conflicts to this reference      list<Conflict_t *> confs (rp->conflicts.begin( ), rp->conflicts.end( ));      confs . remove_if (ConflictExcludePredicate_t( ));      cp = new Contig_t( );      assembly . contigs . push_back (cp);      rmpi = reads . begin( );      //-- Keep going until all reads have been assembled      while ( ! reads . empty( ) )	{	  //-- If end of list reached, push a new contig and start over	  if ( rmpi == reads . end ( ) )	    {	      if ( !cp -> tiles . empty( ) )		{		  cp = new Contig_t( );		  assembly . contigs . push_back (cp);		}	      rmpi = reads . begin( );	    }	  //-- Jump to the next conflict	  if ( rmpi != reads . end( ) )	    {	      for ( cpi  = confs . begin( ); cpi != confs . end( ); ++ cpi )		if ( (*cpi) -> pos > (*rmpi) -> place -> beg )		  break;	    }	  rmpic = reads . end( );	  //-- Mark the beg and end of the conflict	  if ( cpi != confs . end( ) )	    {	      confbeg = (*cpi) -> pos;	      confend = confbeg + (*cpi) -> gapR;	      //-- If LOBREAK, push a new contig	      if ( (*cpi) -> type == Conflict_t::LOBREAK  &&		   !cp->tiles.empty( ) )		{		  cp = new Contig_t( );		  assembly . contigs . push_back (cp);		}	    }	  //-- Assemble reads up to but not including the current conflict	  while ( rmpi != reads . end( ) )	    {	      //-- Break if past the conflict	      if ( cpi != confs . end( ) )		if ( (*rmpi) -> place -> beg > confend )		  break;	      //-- If clear of the conflict	      if ( cpi == confs.end( )  ||		   ((*cpi) -> type != Conflict_t::LOBREAK  &&		    (*rmpi) -> place -> end <= confbeg) )		{		  tp = new Tile_t (*rmpi, cp);		  //TODO - think about overlap		  //-- 0 coverage forces a new contig		  if ( ! cp -> tiles . empty( )  &&		       tp -> off > cp -> len - OPT_MinOverlap )		    {		      //-- Push a new contig and redo the tile		      cp = new Contig_t( );		      assembly . contigs . push_back (cp);		      (*tp) = Tile_t (*rmpi, cp);		    }		  		  //-- ASSEMBLE the read		  cp -> tiles . push_back (tp);		  currend = tp -> off + labs (tp -> end - tp -> beg) + 1;		  if ( currend > cp -> len )		    cp -> len = currend;		  //-- Read has been assembled, remove from the list		  rmpi = reads . erase (rmpi);		}	      //-- If involved in the conflict, save for later	      else		{		  if ( rmpic == reads . end( ) )		    rmpic = rmpi;		  ++ rmpi;		}	    }	  //TODO - TEMPORARY	  //-- Back up to capture all reads overlapping the conflict	  if ( rmpic != reads . end( ) )	    while ( rmpic != reads . begin( )  &&		    (*rmpic) -> place -> end > confbeg )	      rmpic --;	  //-- Assemble reads overlapping the conflict	  while ( rmpic != reads . end( ) )	    {	      //-- Break if past the conflict	      if ( rmpic == rmpi )		{		  switch ( (*cpi) -> type )		    {		    case Conflict_t::LOBREAK:		      //-- If a LOBREAK, do nothing		      break;		    case Conflict_t::HIBREAK:		      //-- If a HIHANG, start a new contig		      rmpi = reads . end( );		      break;		    case Conflict_t::INDEL:		      //-- If an INDEL, adjust for the reference gap		      cp -> adjust += (*cpi) -> gapQ - (*cpi) -> gapR;		      break;		    }		  break;		}	      //-- If a supporting read	      if ( binary_search ((*cpi) -> support . begin( ),				  (*cpi) -> support . end( ), *rmpic) )		{		  tp = new Tile_t (*rmpic, cp);		  //TODO - THINK ABOUT THIS HARDER		  //-- If a LOBREAK on an INDEL, need to adjust the offset		  if ( (*cpi) -> type == Conflict_t::INDEL  &&		       (*rmpic) -> place -> tbeg >= lmin (confbeg, confend) )		    {		      tp -> off += (*cpi) -> gapQ - (*cpi) -> gapR;		    }		  else		    {		      //-- 0 coverage forces a new contig		      if ( ! cp -> tiles . empty( )  &&			   tp -> off > cp -> len - OPT_MinOverlap )			{			  //-- Push a new contig and redo the tile			  cp = new Contig_t( );			  assembly . contigs . push_back (cp);			  (*tp) = Tile_t (*rmpic, cp);			}		    }		  //-- ASSEMBLE the read		  cp -> tiles . push_back (tp);		  currend = tp -> off + labs (tp -> end - tp -> beg) + 1;		  if ( currend > cp -> len )		    cp -> len = currend;		  //-- Read has been assembled, remove from the list		  rmpic = reads . erase (rmpic);		}	      //-- If overlapping, but not supporting, save for later	      else		{		  ++ rmpic;		}	    }	  //-- Resolved conflict, remove from list	  if ( cpi != confs . end( ) )	    cpi = confs . erase (cpi);	}    }  delete temprm . place -> head;  delete temprm . place;}