deps/kb_meme/meme-5.0.1/src/tomtom.c
/*****************************************************************************
 * Calculate a list of unique motif lengths as well as min, max and total.
 * These help save time later.
 *****************************************************************************/
Calculate a list of unique motif lengths as well as min, max and total.
These help save time later.
Calculate a list of unique motif lengths as well as min max and total . These help save time later .
static MLEN_T* create_mlen(ARRAYLST_T *motifs) {
  int i, nmotifs, len;
  MLEN_T *mlen;
  mlen = mm_malloc(sizeof(MLEN_T));
  mlen->min = 0;
  mlen->max = 0;
  mlen->total = 0;
  nmotifs = arraylst_size(motifs);
  for (i = 0; i < nmotifs; i++) {
    len = get_motif_length((MOTIF_T*)arraylst_get(i, motifs));
    if (mlen->min == 0 || len < mlen->min) {
      mlen->min = len;
    }
    if (mlen->max == 0 || len > mlen->max) {
      mlen->max = len;
    }
    mlen->total += len;
  }
  assert(mlen->min <= mlen->max);
  mlen->unique = 0;
  mlen->lookup = mm_calloc(mlen->max + 1, sizeof(int));
  for (i = 0; i < nmotifs; i++) {
    len = get_motif_length((MOTIF_T*)arraylst_get(i, motifs));
    assert(len >= mlen->min);
    assert(len <= mlen->max);
    if (mlen->lookup[len] == 0) {
      mlen->unique++;
      mlen->lookup[len] = 1;
    }
  }
  mlen->lengths = mm_malloc(mlen->unique * sizeof(int));
  for (i = 0, len = mlen->min; len <= mlen->max; len++) {
    if (mlen->lookup[len] != 0) {
      mlen->lengths[i] = len;
      mlen->lookup[len] = i;
      i++;
    }
  }
  assert(i == mlen->unique);
  return mlen;
}
static MLEN_T * create_mlen ( ARRAYLST_T * motifs ) { int i , nmotifs , len ; MLEN_T * mlen ; mlen = mm_malloc ( sizeof ( MLEN_T ) ) ; mlen -> min = 0 ; mlen -> max = 0 ; mlen -> total = 0 ; nmotifs = arraylst_size ( motifs ) ; for ( i = 0 ; i < nmotifs ; i ++ ) { len = get_motif_length ( ( MOTIF_T * ) arraylst_get ( i , motifs ) ) ; if ( mlen -> min == 0 || len < mlen -> min ) { mlen -> min = len ; } if ( mlen -> max == 0 || len > mlen -> max ) { mlen -> max = len ; } mlen -> total += len ; } assert ( mlen -> min <= mlen -> max ) ; mlen -> unique = 0 ; mlen -> lookup = mm_calloc ( mlen -> max + 1 , sizeof ( int ) ) ; for ( i = 0 ; i < nmotifs ; i ++ ) { len = get_motif_length ( ( MOTIF_T * ) arraylst_get ( i , motifs ) ) ; assert ( len >= mlen -> min ) ; assert ( len <= mlen -> max ) ; if ( mlen -> lookup [ len ] == 0 ) { mlen -> unique ++ ; mlen -> lookup [ len ] = 1 ; } } mlen -> lengths = mm_malloc ( mlen -> unique * sizeof ( int ) ) ; for ( i = 0 , len = mlen -> min ; len <= mlen -> max ; len ++ ) { if ( mlen -> lookup [ len ] != 0 ) { mlen -> lengths [ i ] = len ; mlen -> lookup [ len ] = i ; i ++ ; } } assert ( i == mlen -> unique ) ; return mlen ; }
Calculate a list of unique motif lengths as well as min, max and total.
Calculate a list of unique motif lengths as well as min max and total .
// determine minimum and maximum length // determine total length // count number of unique lengths // create list of possible lengths