if ( olap2 < -(OPT_MaxGap) )
if ( OPT_MaxGap >= 0  &&  olap2 < -(OPT_MaxGap) )
void ChainAligns (Mapping_t & mapping){  struct ScoreLAS  {    ReadAlign_t * a;    long int score;    long int from;  };  ScoreLAS * las = NULL;  bool olapflag;  long int i, j, n, best;  long int olap1, olap2, olap, len;  vector<ReadMap_t *>::iterator rmpi;  list<ReadAlignChain_t *>::iterator rcpi;  ReadAlignChain_t * bestchain, * currchain;  //-- For each read in the mapping  for ( rmpi  = mapping . reads . begin( );	rmpi != mapping . reads . end( ); ++ rmpi )    {      //-- Initialize the dynamic programming matrix      n = (*rmpi) -> all . size( );      las = (ScoreLAS *) AMOS::SafeRealloc (las, sizeof (ScoreLAS) * n);      for ( i = 0; i < n; i ++ )	{	  las [i] . a = (*rmpi) -> all[i];	  las [i] . score = las [i] . a -> hi - las [i] . a -> lo + 1;	  las [i] . from = -1;	}      //-- Isn't it dynamic?      for ( i = 0; i < n; i ++ )	for ( j = 0; j < i; j ++ )	  {	    if ( las [i] . a -> ref != las [j] . a -> ref  ||		 las [i] . a -> ori != las [j] . a -> ori )	      continue;	    olap1 = las [j] . a -> hiR - las [i] . a -> loR + 1;	    if ( OPT_Circular  &&		 olap1 > las [j] . a -> ref -> len / 2 )	      {		olap1 = (las [j] . a -> hiR - las [j] . a -> ref -> len) +		  (1 - las [i] . a -> loR);	      }	    if ( olap1 < -(OPT_MaxGap) )	      continue;	    olap = olap1 > 0 ? olap1 : 0;	    olap2 = las [j] . a -> hi - las [i] . a -> lo + 1;	    if ( olap2 < -(OPT_MaxGap) )	      continue;	    olap = olap > olap2 ? olap : olap2;	    len = las [i] . a -> hi - las [i] . a -> lo + 1;	    if ( las [j] . score + len - olap > las [i] . score )	      {		las [i] . from = j;		las [i] . score = las [j] . score + len - olap;	      }	  }      //-- Store all the non-redundant chains and store sorted by score      bestchain = NULL;      while (true)	{	  best = 0;	  for ( i = 1; i < n; i ++ )	    if ( las [i] . score > las [best] . score )	      best = i;	  if ( las [best] . score <= 0 )	    break;	  olapflag = false;	  for ( i = best; las [i] . from >= 0; i = las [i] . from )	    {	      if ( las [i] . score == 0 )		olapflag = true;	      las [i] . score = 0;	      las [i] . a -> from = las [las [i] . from] . a;	    }	  if ( las [i] . score == 0 )	    olapflag = true;	  las [i] . score = 0;	  las [i] . a -> from = NULL;	  if ( !olapflag )	    {	      currchain = new ReadAlignChain_t (*rmpi, las [best] . a);	      (*rmpi) -> best . push_back (currchain);	      if ( bestchain == NULL )		bestchain = currchain;	      else if ( IsBetterChain (currchain, bestchain, *rmpi) )		bestchain = currchain;	    }	}      //-- Keep only the 'best' chains, thus best . size > 0 == ambiguity      //   i.e. within OPT_MaxCoverageDiff of the longest and within      //   OPT_MaxIdentityDiff of the longest (with the higest idy)      rcpi = (*rmpi) -> best . begin( );      while ( rcpi != (*rmpi) -> best . end( ) )	{	  if ( IsEqualChain (*rcpi, bestchain, *rmpi) )	    ++ rcpi;	  else	    {	      delete (*rcpi);	      rcpi = (*rmpi) -> best . erase (rcpi);	    }	}    }  free (las);}