deps/kb_meme/meme-5.0.1/src/spamo-scan.c
/**************************************************************************
 * Scan all the sequences with the primary motif and store the best match
 * for each in the sequence data structure.
 **************************************************************************/
Scan all the sequences with the primary motif and store the best match
for each in the sequence data structure.
Scan all the sequences with the primary motif and store the best match for each in the sequence data structure .
void scan_spamo_primary(
  int margin, 
  double score_threshold, 
  ARRAY_T *background, 
  MOTIF_T *motif, 
  RBTREE_T *sequences,
  bool trimmed
) {
  MOTIF_T *motif_rc;
  PSSM_T *pssm, *pssm_rc;
  RBNODE_T *node;
  SEQUENCE_T *sequence;
  int regions[3];
  int *hits, hits_size;
  bool revcomp;
  if ((node = rbtree_first(sequences)) == NULL) return;
  revcomp = alph_has_complement(get_motif_alph(motif));
  sequence = (SEQUENCE_T*)rbtree_value(node);
  hits_size = (sequence->length - 2 * margin) * 2;
  hits = mm_malloc(sizeof(int) * hits_size);
  regions[0] = margin; 
  regions[2] = -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);
    if (((sequence->length - 2 * margin) * 2) > hits_size) {
      hits_size = (sequence->length - 2 * margin) * 2;
      hits = mm_realloc(hits, sizeof(int) * hits_size);
    }
    regions[1] = sequence->length - margin - 1; 
    if (trimmed) {
      sequence->trimmed_primary_matches = best_in_region(pssm, pssm_rc, sequence, regions, score_threshold, hits, hits_size, false);
    } else {
      sequence->primary_matches = best_in_region(pssm, pssm_rc, sequence, regions, score_threshold, hits, hits_size, true);
    }
  }
  free_pssm(pssm);
  free_pssm(pssm_rc);
  destroy_motif(motif_rc);
  free(hits);
}
void scan_spamo_primary ( int margin , double score_threshold , ARRAY_T * background , MOTIF_T * motif , RBTREE_T * sequences , bool trimmed ) { MOTIF_T * motif_rc ; PSSM_T * pssm , * pssm_rc ; RBNODE_T * node ; SEQUENCE_T * sequence ; int regions [ 3 ] ; int * hits , hits_size ; bool revcomp ; if ( ( node = rbtree_first ( sequences ) ) == NULL ) return ; revcomp = alph_has_complement ( get_motif_alph ( motif ) ) ; sequence = ( SEQUENCE_T * ) rbtree_value ( node ) ; hits_size = ( sequence -> length - 2 * margin ) * 2 ; hits = mm_malloc ( sizeof ( int ) * hits_size ) ; regions [ 0 ] = margin ; regions [ 2 ] = -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 ) ; if ( ( ( sequence -> length - 2 * margin ) * 2 ) > hits_size ) { hits_size = ( sequence -> length - 2 * margin ) * 2 ; hits = mm_realloc ( hits , sizeof ( int ) * hits_size ) ; } regions [ 1 ] = sequence -> length - margin - 1 ; if ( trimmed ) { sequence -> trimmed_primary_matches = best_in_region ( pssm , pssm_rc , sequence , regions , score_threshold , hits , hits_size , false ) ; } else { sequence -> primary_matches = best_in_region ( pssm , pssm_rc , sequence , regions , score_threshold , hits , hits_size , true ) ; } } free_pssm ( pssm ) ; free_pssm ( pssm_rc ) ; destroy_motif ( motif_rc ) ; free ( hits ) ; }
Scan all the sequences with the primary motif and store the best match
 for each in the sequence data structure.
Scan all the sequences with the primary motif and store the best match for each in the sequence data structure .
// 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 each sequence // Scan only the margins to find the best hit there. // last valid index to include in scan //clean up the PSSMs //clean up the motif //clean up the hits