deps/kb_meme/meme-5.0.1/src/tomtom.c
/**************************************************************************
 * UK: Scores are shifted by shift quantile
 *
 * JIJ:
 * This method shifts the scores by the -median score so the median score
 * becomes zero.
 * The idea here is that we don't want Tomtom to align on uninformative
 * columns when there are better options.
 * To do that we want to give a score to unaligned columns so that failing
 * to align an uninformative column gets a higher score than failing to align
 * an informative one.
 * The suggestion from the paper is that the median of the set of scores from
 * aligning a particular query column to every possible target column will
 * forfill this critera.
 * Paraphrased from the paper...
 * Assuming a target column 'T' from the set 'T_all' of all possible target
 * columns in a database, a query column 'A' which represents strong preference
 * for a single letter, a query column 'U' which represents a uniform
 * preference and a query column 'X' which represents a preference for
 * the letters not preferred by 'A'.
 * Also assuming a scoring function S(C_1,C_2) which compares a
 * column C_1 with a column C_2.
 * Then:
 *  max{S(U, T) : T in T_all} = max{S(A, T) : T in T_all}
 * And:
 *  S(A, X) < S(U, X)
 * So it follows that:
 *  min{S(U, T) : T in T_all} > min{S(A, T) : T in T_all}
 * This explains why the median of the set
 *  {S(Q, T) : T in T_all}
 * will be higher when Q = U (or a uninformative column) then when Q = A (or an
 * informative column).
 * To make things even simple the paper proposes that we can get around having
 * to add scores for each unaligned column by making the score to be added
 * (aka the median score for the column) equal to zero.
 **************************************************************************/
Scores are shifted by shift quantile
JIJ:
This method shifts the scores by the -median score so the median score
becomes zero.
The idea here is that we don't want Tomtom to align on uninformative
columns when there are better options.
To do that we want to give a score to unaligned columns so that failing
to align an uninformative column gets a higher score than failing to align
an informative one.
The suggestion from the paper is that the median of the set of scores from
aligning a particular query column to every possible target column will
forfill this critera.
Scores are shifted by shift quantile JIJ : This method shifts the scores by the - median score so the median score becomes zero . The idea here is that we don ' t want Tomtom to align on uninformative columns when there are better options . To do that we want to give a score to unaligned columns so that failing to align an uninformative column gets a higher score than failing to align an informative one . The suggestion from the paper is that the median of the set of scores from aligning a particular query column to every possible target column will forfill this critera .
static void shift_all_pairwise_scores(MATRIX_T* scores,
    int query_len, int targets_len, double shift_quant) {
  int t, q, index_1, index_2;
  double *one_col, quantile;
  one_col = mm_malloc(targets_len * sizeof(double));
  index_1 = (int) floor(shift_quant * targets_len) - 1;
  index_2 = (int) ceil(shift_quant * targets_len) - 1;
  if (index_1 < 0) index_1 = 0;
  if (index_2 < index_1) index_2 = index_1;
  for (q = 0; q < query_len; ++q) {
    for (t = 0; t < targets_len; ++t) {
      one_col[t] = get_matrix_cell(q, t, scores);
    }
    qsort(one_col, targets_len, sizeof(double), (void *)score_compare);
    quantile = (one_col[index_1] + one_col[index_2]) / 2.0;
    for (t = 0; t < targets_len; ++t) {
      incr_matrix_cell(q, t, -quantile, scores);
    }
  }
  free(one_col);
}
static void shift_all_pairwise_scores ( MATRIX_T * scores , int query_len , int targets_len , double shift_quant ) { int t , q , index_1 , index_2 ; double * one_col , quantile ; one_col = mm_malloc ( targets_len * sizeof ( double ) ) ; index_1 = ( int ) floor ( shift_quant * targets_len ) - 1 ; index_2 = ( int ) ceil ( shift_quant * targets_len ) - 1 ; if ( index_1 < 0 ) index_1 = 0 ; if ( index_2 < index_1 ) index_2 = index_1 ; for ( q = 0 ; q < query_len ; ++ q ) { for ( t = 0 ; t < targets_len ; ++ t ) { one_col [ t ] = get_matrix_cell ( q , t , scores ) ; } qsort ( one_col , targets_len , sizeof ( double ) , ( void * ) score_compare ) ; quantile = ( one_col [ index_1 ] + one_col [ index_2 ] ) / 2.0 ; for ( t = 0 ; t < targets_len ; ++ t ) { incr_matrix_cell ( q , t , - quantile , scores ) ; } } free ( one_col ) ; }
UK: Scores are shifted by shift quantile
 JIJ:
 This method shifts the scores by the -median score so the median score
 becomes zero.
UK : Scores are shifted by shift quantile JIJ : This method shifts the scores by the - median score so the median score becomes zero .
// allocate space // determine the indexes we'll use for calculating the quantile // Note that by default shift_quant is set to 0.5 so we're selecting // the median here (well not quite - it's actually off by 1 position, // but close enough that I don't want to change the behaviour). // handle edge case of very small target length // loop over each query column adjusting scores // copy the scores into a sortable form // There are probably faster ways to find the scores at the indexes, see: // http://en.wikipedia.org/wiki/Selection_algorithm // shift the column // cleanup