rcpi != rmp -> best . end( ); rcpi ++ )
rcpi != rmp -> best . end( ); ++ rcpi )
void PlaceHappyMates (Mapping_t & mapping){  ReadMap_t * rmp, * mrmp;  ReadAlignChain_t * rcp, * mrcp;  int i;  vector< pair<ReadAlignChain_t *, ReadAlignChain_t *> > places;  vector<ReadMap_t *>::iterator rmpi;  list<ReadAlignChain_t *>::iterator rcpi, mrcpi;  //-- For each read in the mapping  for ( rmpi  = mapping . reads . begin( );	rmpi != mapping . reads . end( ); rmpi ++ )    {      rmp = *rmpi;      //-- Get the matepair      mrmp = rmp -> mate . read;      //-- If the read has already been placed, or no mate, skip      if ( rmp -> place != NULL  ||  mrmp == NULL )	continue;      //-- Find all the happy placements      places . clear( );      for ( mrcpi  = mrmp -> best . begin( );	    mrcpi != mrmp -> best . end( ); mrcpi ++ )	{	  //-- If mate not placed, search through all its best	  if ( mrmp -> place == NULL )	    mrcp = *mrcpi;	  else	    {	      mrcp = mrmp -> place;	      mrcpi = mrmp -> best . end( );	      mrcpi --;                        // last loop iteration	    }	  for ( rcpi  = rmp -> best . begin( );		rcpi != rmp -> best . end( ); rcpi ++ )	    	    {	      rcp = *rcpi;	      //-- Skip if constraints are not satisfied	      if ( rcp -> head -> ref != mrcp -> head -> ref )		continue;	      if ( mrcp -> head -> ori == FORWARD_CHAR )		{		  if (rcp -> head -> ori != REVERSE_CHAR		      ||		      rcp  -> end < mrcp -> beg + mrmp -> mate . minoff		      ||		      rcp  -> end > mrcp -> beg + mrmp -> mate . maxoff )		    continue;		}	      else		{		  if (rcp -> head -> ori != FORWARD_CHAR		      ||		      rcp  -> beg < mrcp -> end - mrmp -> mate . maxoff		      ||		      rcp  -> beg > mrcp -> end - mrmp -> mate . minoff )		    continue;		}	      //-- Happy link! Add the matepair if valid	      if ( IsValidChain (rcp, rmp)  &&  IsValidChain (mrcp, mrmp) )		places . push_back (make_pair (rcp, mrcp));	    }	}      //-- If 1 happy link was found, place the matepair      //   or many happy links and OPT_Random, randomly place the matepair      if ( !places . empty( )	   &&	   (OPT_Random  ||  places . size( ) == 1) )	{	  i = (int)((double)places . size( ) * rand( ) / (RAND_MAX + 1.0));	  rmp  -> place = places [i] . first;	  mrmp -> place = places [i] . second;	}    }}