deps/kb_meme/meme-5.0.1/src/spamo.c
/**************************************************************************
 * Loads the secondary motifs filtering them with the information in the
 * options structure.  Returs a list of MOTIF_DB_T.
 **************************************************************************/
Loads the secondary motifs filtering them with the information in the
options structure.  Returs a list of MOTIF_DB_T.
Loads the secondary motifs filtering them with the information in the options structure . Returs a list of MOTIF_DB_T .
static ARRAYLST_T *load_secondary_motifs(
  SPAMO_OPTIONS_T *options, 
  ALPH_T *alph,
  ARRAY_T *background, 
  RBTREE_T **secondary_motifs,	
  bool *stdin_used		 check or set if path is "-"
) {
  int i;
  ARRAYLST_T *secondary_dbs = arraylst_create_sized(arraylst_size(options->secondary_files));
  *secondary_motifs = rbtree_create(secondary_key_compare, secondary_key_copy, free, NULL, destroy_secondary_motif);
  RBTREE_T *secondary_names = rbtree_create(rbtree_strcmp, NULL, NULL, NULL, NULL);
  for (i = 0; i < arraylst_size(options->secondary_files); ++i) { 
    char *secondary_file = (char*)arraylst_get(i, options->secondary_files);
    DEBUG_FMT(NORMAL_VERBOSE, "Loading Secondary Motifs from file '%s'\n", secondary_file);
    MOTIF_DB_T *secondary_db = read_motifs_and_background(
      i+1, 			
      secondary_file,		
      "Secondary motif",	
      NULL,			
      NULL,			
      options->include_patterns,
      options->exclude_patterns,
      true,			
      false,			
      options->pseudocount,	
      true,			
      options->trim_bit_threshold,
      NULL,			
      true, 			
      &background,		
      NULL,			
      alph,			
      options->xalph,		
      false,			
      true,			
      false,			
      stdin_used		 check and set if path is "-"
    );
    int i;
    int warn_type = NO_WARNING;
    for (i=0; i<arraylst_size(secondary_db->motifs); i++) {
      MOTIF_T *motif = arraylst_get(i, secondary_db->motifs);
      if ((options->margin - get_motif_trimmed_length(motif) + 1) < 1) {
        clump_motif_db_warning(&warn_type, MARGIN_WARNING, "Warning: The following "
	  "secondary motifs in '%s' were excluded as they didn't fit in "
	  "the margin:\n  ", secondary_file, get_motif_id(motif));
        destroy_motif(motif);
        secondary_db->loaded--;
        secondary_db->excluded++;
        continue;
      }
      SECONDARY_KEY_T key;
      key.db_id = 0;
      key.motif_id = get_motif_id(motif);
      bool created;
      RBNODE_T *node = rbtree_lookup(secondary_names, get_motif_id(motif), true, &created);
      if (!created) {
        clump_motif_db_warning(&warn_type, DUPLICATE_WARNING, "Warning: The following "
          "duplicate secondary motifs in '%s' were excluded:\n  ", secondary_file, get_motif_id(motif));
        destroy_motif(motif);
        secondary_db->loaded--;
        secondary_db->excluded++;
        continue;
      }
      key.db_id = secondary_db->id;
      key.motif_id = get_motif_id(motif);
      node = rbtree_lookup(*secondary_motifs, &key, true, &created);
      rbtree_set(*secondary_motifs, node, create_secondary_motif(options->margin, options->bin, secondary_db, motif));
    }
    arraylst_add(secondary_db, secondary_dbs);
    if (warn_type && verbosity >= NORMAL_VERBOSE) fprintf(stderr, "\n");
  } 
  rbtree_destroy(secondary_names);
  if (rbtree_size(*secondary_motifs) == 0) die("No acceptable secondary motifs found.");
  return(secondary_dbs);
}
static ARRAYLST_T * load_secondary_motifs ( SPAMO_OPTIONS_T * options , ALPH_T * alph , ARRAY_T * background , RBTREE_T * * secondary_motifs , bool * stdin_used ) { int i ; ARRAYLST_T * secondary_dbs = arraylst_create_sized ( arraylst_size ( options -> secondary_files ) ) ; * secondary_motifs = rbtree_create ( secondary_key_compare , secondary_key_copy , free , NULL , destroy_secondary_motif ) ; RBTREE_T * secondary_names = rbtree_create ( rbtree_strcmp , NULL , NULL , NULL , NULL ) ; for ( i = 0 ; i < arraylst_size ( options -> secondary_files ) ; ++ i ) { char * secondary_file = ( char * ) arraylst_get ( i , options -> secondary_files ) ; DEBUG_FMT ( NORMAL_VERBOSE , " \n " , secondary_file ) ; MOTIF_DB_T * secondary_db = read_motifs_and_background ( i + 1 , secondary_file , " " , NULL , NULL , options -> include_patterns , options -> exclude_patterns , true , false , options -> pseudocount , true , options -> trim_bit_threshold , NULL , true , & background , NULL , alph , options -> xalph , false , true , false , stdin_used ) ; int i ; int warn_type = NO_WARNING ; for ( i = 0 ; i < arraylst_size ( secondary_db -> motifs ) ; i ++ ) { MOTIF_T * motif = arraylst_get ( i , secondary_db -> motifs ) ; if ( ( options -> margin - get_motif_trimmed_length ( motif ) + 1 ) < 1 ) { clump_motif_db_warning ( & warn_type , MARGIN_WARNING , " " " " " \n " , secondary_file , get_motif_id ( motif ) ) ; destroy_motif ( motif ) ; secondary_db -> loaded -- ; secondary_db -> excluded ++ ; continue ; } SECONDARY_KEY_T key ; key . db_id = 0 ; key . motif_id = get_motif_id ( motif ) ; bool created ; RBNODE_T * node = rbtree_lookup ( secondary_names , get_motif_id ( motif ) , true , & created ) ; if ( ! created ) { clump_motif_db_warning ( & warn_type , DUPLICATE_WARNING , " " " \n " , secondary_file , get_motif_id ( motif ) ) ; destroy_motif ( motif ) ; secondary_db -> loaded -- ; secondary_db -> excluded ++ ; continue ; } key . db_id = secondary_db -> id ; key . motif_id = get_motif_id ( motif ) ; node = rbtree_lookup ( * secondary_motifs , & key , true , & created ) ; rbtree_set ( * secondary_motifs , node , create_secondary_motif ( options -> margin , options -> bin , secondary_db , motif ) ) ; } arraylst_add ( secondary_db , secondary_dbs ) ; if ( warn_type && verbosity >= NORMAL_VERBOSE ) fprintf ( stderr , " \n " ) ; } rbtree_destroy ( secondary_names ) ; if ( rbtree_size ( * secondary_motifs ) == 0 ) die ( " " ) ; return ( secondary_dbs ) ; }
Loads the secondary motifs filtering them with the information in the
 options structure.
Loads the secondary motifs filtering them with the information in the options structure .
// IN/OUT // IN/OUT check or set if path is "-" //loop over the motif db files // Get the file name of the next motif db. // Load the motifs from this file. // start the id at 1 because we use 0 for the primary // motif file name (or special word) // type of database for error messages // get one motif by name // get one motif by index // get set of motifs by name (or NULL) // exclude this set of motifs by name (or NULL) // allow motifs with zero probability entries // create RC copies, appended // multiply times background model // set_trim // trim_bit_threshold // background source // make bg symmetrical if alph complementable // will be set if id==0 // sequence file name // primary motif alphabet // set motif conversion alphabet // don't remove extension from name // remove ".meme" extension from name // don't replace underscores in name // IN/OUT check and set if path is "-" // Post-process the motifs to make them the secondary motif type. // Reset the warning type for the warning clumping. // Check that the motif fits in the sequence margin. // Check for motif name uniqueness across all DBs. // secondary_files // Clean up. // Check that we found suitable motifs.