deps/kb_meme/meme-5.0.1/src/spamo-scan.c
/**************************************************************************
 * Scan all the sequences with the secondary motif and store the best match
 * for each in matches list.
 **************************************************************************/
Scan all the sequences with the secondary motif and store the best match
for each in matches list.
Scan all the sequences with the secondary motif and store the best match for each in matches list .
void scan_spamo_secondary(
  int margin, 
  double score_threshold,
  bool use_best_secondary,
  ARRAY_T *background, 
  MOTIF_T *motif,
  RBTREE_T *sequences, 
  ARRAY_T **matches,
  int *hits,
  int hits_size
) {
  MOTIF_T *motif_rc;
  PSSM_T *pssm, *pssm_rc;
  RBNODE_T *node;
  SEQUENCE_T *sequence;
  int regions[5];
  bool revcomp;
  revcomp = alph_has_complement(get_motif_alph(motif));
  if ((node = rbtree_first(sequences)) == NULL) return;
  sequence = (SEQUENCE_T*)rbtree_value(node);
  regions[0] = 0; 
  regions[1] = margin - 1;
  regions[2] = sequence->length - margin;
  regions[3] = sequence->length - 1;
  regions[4] = -1; 
  motif_rc = (revcomp ? dup_rc_motif(motif) : NULL);
  pssm = build_motif_pssm(motif, background, background, NULL, 0, PSSM_RANGE, 0, false);
  pssm_rc = (revcomp ? build_motif_pssm(motif_rc, background, background, NULL, 0, PSSM_RANGE, 0, false) : NULL);
  if (score_threshold < 0 && score_threshold >= -1) {
    score_threshold = pssm_best_match_score(pssm) * (-score_threshold);
  }
  for (node = rbtree_first(sequences); node != NULL; node = rbtree_next(node)) {
    sequence = (SEQUENCE_T*)rbtree_value(node);
    matches[sequence->index] = best_in_region(pssm, pssm_rc, sequence, regions, score_threshold, hits, hits_size, use_best_secondary);
  }
  free_pssm(pssm);
  free_pssm(pssm_rc);
  destroy_motif(motif_rc);
}
void scan_spamo_secondary ( int margin , double score_threshold , bool use_best_secondary , ARRAY_T * background , MOTIF_T * motif , RBTREE_T * sequences , ARRAY_T * * matches , int * hits , int hits_size ) { MOTIF_T * motif_rc ; PSSM_T * pssm , * pssm_rc ; RBNODE_T * node ; SEQUENCE_T * sequence ; int regions [ 5 ] ; bool revcomp ; revcomp = alph_has_complement ( get_motif_alph ( motif ) ) ; if ( ( node = rbtree_first ( sequences ) ) == NULL ) return ; sequence = ( SEQUENCE_T * ) rbtree_value ( node ) ; regions [ 0 ] = 0 ; regions [ 1 ] = margin - 1 ; regions [ 2 ] = sequence -> length - margin ; regions [ 3 ] = sequence -> length - 1 ; regions [ 4 ] = -1 ; motif_rc = ( revcomp ? dup_rc_motif ( motif ) : NULL ) ; pssm = build_motif_pssm ( motif , background , background , NULL , 0 , PSSM_RANGE , 0 , false ) ; pssm_rc = ( revcomp ? build_motif_pssm ( motif_rc , background , background , NULL , 0 , PSSM_RANGE , 0 , false ) : NULL ) ; if ( score_threshold < 0 && score_threshold >= -1 ) { score_threshold = pssm_best_match_score ( pssm ) * ( - score_threshold ) ; } for ( node = rbtree_first ( sequences ) ; node != NULL ; node = rbtree_next ( node ) ) { sequence = ( SEQUENCE_T * ) rbtree_value ( node ) ; matches [ sequence -> index ] = best_in_region ( pssm , pssm_rc , sequence , regions , score_threshold , hits , hits_size , use_best_secondary ) ; } free_pssm ( pssm ) ; free_pssm ( pssm_rc ) ; destroy_motif ( motif_rc ) ; }
Scan all the sequences with the secondary motif and store the best match
 for each in matches list.
Scan all the sequences with the secondary motif and store the best match for each in matches list .
// set up the two regions flanking the primary motif // first valid index to scan // terminate list with negative 1 // prepare a reverse complement of the motif // convert the motif and the reverse complement into PSSMs // if the score threshold is between 0 and -1 then compute a threshold from the pssm // scan all the sequences //clean up the PSSMs //clean up the motif