3rd_party/hmmer-3.1b2-linux-intel-x86_64/src/fm_general.c
/* Function:  fm_convertRange2DSQ()
 * Synopsis:  Convert the BWT range into a DSQ.
 *
 * Purpose:   The input value of <first> is the 0-based position at which
 *            the requested range starts on either FM->T or revcomp(FM->T),
 *            depending on <complementarity>. Since only FM->T is stored,
 *            the necessary work is done to correct positions in the case
 *            that the positions are relative to the revcomp.
 */
fm_convertRange2DSQ()
Synopsis:  Convert the BWT range into a DSQ.

The input value of  is the 0-based position at which
the requested range starts on either FM->T or revcomp(FM->T),
depending on . Since only FM->T is stored,
the necessary work is done to correct positions in the case
that the positions are relative to the revcomp.
fm_convertRange2DSQ () Synopsis : Convert the BWT range into a DSQ . The input value of is the 0 - based position at which the requested range starts on either FM - > T or revcomp ( FM - > T ) depending on . Since only FM - > T is stored the necessary work is done to correct positions in the case that the positions are relative to the revcomp .
int
fm_convertRange2DSQ(const FM_DATA *fm, const FM_METADATA *meta, uint64_t first, int length, int complementarity, ESL_SQ *sq, int fix_ambiguities)
{
  uint64_t i, j;
  if (complementarity == p7_COMPLEMENT)
    first = fm->N-(first+length)-1;
  esl_sq_GrowTo(sq, length);
  sq->n = length;
  if (meta->alph_type == fm_DNA ) {
    for (i = first; i <= first+length-1; i++)
      sq->dsq[i-first+1] = (fm->T[i/4] >> ( 0x6 - ((i&0x3)*2) ) & 0x3);
    sq->dsq[length+1] = eslDSQ_SENTINEL;
    if (fix_ambiguities) {
      int32_t pos = fm_findOverlappingAmbiguityBlock (fm, meta, first, first+length-1 );
      if (pos != -1) {
        while (pos <= fm->ambig_offset + fm->ambig_cnt -1 && meta->ambig_list->ranges[pos].lower <= first+length-1) {
          int start = ESL_MAX(first,          meta->ambig_list->ranges[pos].lower);
          int end =   ESL_MIN(first+length-1, meta->ambig_list->ranges[pos].upper);
          for (j= start; j<=end; j++)
              sq->dsq[j-first+1] = sq->abc->Kp-3; 
          pos++;
        }
      }
    }
  } else { 
    for (i = first; i<= first+length-1; i++)
      sq->dsq[i-first+1] = fm->T[i] + (fm->T[i] < 20 ? 0 : 1); 
    sq->dsq[length+1] = eslDSQ_SENTINEL;
  }
  if (complementarity == p7_COMPLEMENT)
    esl_sq_ReverseComplement(sq);
  return eslOK;
}
int fm_convertRange2DSQ ( const FM_DATA * fm , const FM_METADATA * meta , uint64_t first , int length , int complementarity , ESL_SQ * sq , int fix_ambiguities ) { uint64_t i , j ; if ( complementarity == p7_COMPLEMENT ) first = fm -> N - ( first + length ) - 1 ; esl_sq_GrowTo ( sq , length ) ; sq -> n = length ; if ( meta -> alph_type == fm_DNA ) { for ( i = first ; i <= first + length - 1 ; i ++ ) sq -> dsq [ i - first + 1 ] = ( fm -> T [ i / 4 ] >> ( 0x6 - ( ( i & 0x3 ) * 2 ) ) & 0x3 ) ; sq -> dsq [ length + 1 ] = eslDSQ_SENTINEL ; if ( fix_ambiguities ) { int32_t pos = fm_findOverlappingAmbiguityBlock ( fm , meta , first , first + length - 1 ) ; if ( pos != -1 ) { while ( pos <= fm -> ambig_offset + fm -> ambig_cnt - 1 && meta -> ambig_list -> ranges [ pos ] . lower <= first + length - 1 ) { int start = ESL_MAX ( first , meta -> ambig_list -> ranges [ pos ] . lower ) ; int end = ESL_MIN ( first + length - 1 , meta -> ambig_list -> ranges [ pos ] . upper ) ; for ( j = start ; j <= end ; j ++ ) sq -> dsq [ j - first + 1 ] = sq -> abc -> Kp - 3 ; pos ++ ; } } } } else { for ( i = first ; i <= first + length - 1 ; i ++ ) sq -> dsq [ i - first + 1 ] = fm -> T [ i ] + ( fm -> T [ i ] < 20 ? 0 : 1 ) ; sq -> dsq [ length + 1 ] = eslDSQ_SENTINEL ; } if ( complementarity == p7_COMPLEMENT ) esl_sq_ReverseComplement ( sq ) ; return eslOK ; }
Function:  fm_convertRange2DSQ()
 Synopsis:  Convert the BWT range into a DSQ.
Function : fm_convertRange2DSQ () Synopsis : Convert the BWT range into a DSQ .
//All the "+1" dsq offsets below are because the dsq characters are 1-based. /*
     *  B[j>>2] is the byte of B in which j is found (j/4)
     *
     *  Let j' be the final two bits of j (j&0x2)
     *  The char bits are the two starting at position 2*j'.
     *  Without branching, grab them by shifting B[j/4] right 6-2*j' bits,
     *  then masking to keep the final two bits
     */ /*  Account for the fact that in the DNA alphabet without ambiguity codes,
       *  makehmmerdb turns ambiguity codes into one of the nucleotides. Need
       *  to replace with an N.
       */ //'N' /*
  } else if (meta->alph_type == fm_DNA_full) {
    for (i = first; i<= first+length-1; i++) {
      c = (fm->T[i/2] >> (((i&0x1)^0x1)*4) ) & 0xf;  //unpack the char: shift 4 bits right if it's odd, then mask off left bits in any case
      sq->dsq[i-first+1] = c + (c < 4 ? 0 : 1); //increment by one for ambiguity codes
    }
    sq->dsq[length+1] = eslDSQ_SENTINEL;
*/ // amino //increment by one for ambiguity codes