deps/kb_meme/meme-5.0.1/src/seq.c
/**************************************************************************
 * Convert a sequence to an indexed version. This is a one-way conversion
 * but you can choose to keep the source sequence if you need it
 *
 * With no options, ambiguous characters are encoded as numbers > 0, and
 * any unrecognized letters get encoded the same as the wildcard character.
 * With SEQ_NOAMBIG, ambiguous characters and unknown characters are encoded
 * as -1.
 **************************************************************************/
Convert a sequence to an indexed version. This is a one-way conversion
but you can choose to keep the source sequence if you need it

With no options, ambiguous characters are encoded as numbers > 0, and
any unrecognized letters get encoded the same as the wildcard character.
With SEQ_NOAMBIG, ambiguous characters and unknown characters are encoded
as -1.
Convert a sequence to an indexed version . This is a one - way conversion but you can choose to keep the source sequence if you need it With no options ambiguous characters are encoded as numbers > 0 and any unrecognized letters get encoded the same as the wildcard character . With SEQ_NOAMBIG ambiguous characters and unknown characters are encoded as - 1 .
void index_sequence(SEQ_T* seq, ALPH_T* alph, int options) {
  char *in;
  int8_t *out;
  in = seq->sequence;
  if ((options & SEQ_KEEP) != 0 || sizeof(char) != sizeof(int8_t)) {
    out = mm_malloc(sizeof(int8_t) * seq->length);
    seq->isequence = out;
  } else {
    out = (int8_t*)seq->sequence;
    seq->isequence = out;
    seq->sequence = NULL;
  }
  if ((options & SEQ_NOAMBIG) != 0) {
    for (; *in != '\0'; in++, out++) {
      *out = alph_indexc(alph, *in);
    }
  } else {
    for (; *in != '\0'; in++, out++) {
      *out = alph_index(alph, *in);
    }
  }
}
void index_sequence ( SEQ_T * seq , ALPH_T * alph , int options ) { char * in ; int8_t * out ; in = seq -> sequence ; if ( ( options & SEQ_KEEP ) != 0 || sizeof ( char ) != sizeof ( int8_t ) ) { out = mm_malloc ( sizeof ( int8_t ) * seq -> length ) ; seq -> isequence = out ; } else { out = ( int8_t * ) seq -> sequence ; seq -> isequence = out ; seq -> sequence = NULL ; } if ( ( options & SEQ_NOAMBIG ) != 0 ) { for ( ; * in != ' \0 ' ; in ++ , out ++ ) { * out = alph_indexc ( alph , * in ) ; } } else { for ( ; * in != ' \0 ' ; in ++ , out ++ ) { * out = alph_index ( alph , * in ) ; } } }
Convert a sequence to an indexed version.
Convert a sequence to an indexed version .
// use the same memory and overwrite the sequence with the indexed version