deps/kb_meme/meme-5.0.1/src/momo-input.c
/**
 * Sets the O(1) lookup table. This hashes from every unique kmer within
 * the protein database to an arraylist of KMER_LOC_T objects.
 */
Sets the O(1) lookup table. This hashes from every unique kmer within
the protein database to an arraylist of KMER_LOC_T objects.
Sets the O ( 1 ) lookup table . This hashes from every unique kmer within the protein database to an arraylist of KMER_LOC_T objects .
void create_hash_fasta_preprocess_table(MOMO_OPTIONS_T* options,
                                        SUMMARY_T* summary,
                                        SEQ_T** all_sequences,
                                        int num_sequences) {
  int i;
  int j;
  int k;
  if (options->hash_fasta && options->protein_database_filename) {
    HASH_TABLE hash_fasta_table = hash_create(DATA_HASH_SIZE, (void (*)(void*))arraylst_free);	
    int hash_fasta_width = options->hash_fasta_width;
    char* kmer = mm_malloc(hash_fasta_width + 1);
    double n_found = 0;
    double n_test = 0;
    for (i = 0; i < num_sequences; i++) {
      char* raw_sequence = get_raw_sequence(all_sequences[i]);
      int raw_sequence_length = strlen(raw_sequence);
      for (j = 0; j < raw_sequence_length - hash_fasta_width + 1; ++j) {
        n_test++;
        set_kmer(&kmer, raw_sequence, j, hash_fasta_width);
        KMER_LOC_T *kmerloc = mm_malloc(sizeof(KMER_LOC_T));
        kmerloc->seqidx = i;
        kmerloc->kmeridx = j;
        HASH_TABLE_ENTRY *hash_entry;
        char *dptr = 0;
        if (!(hash_entry = hash_lookup_str(kmer, hash_fasta_table))) {
          ARRAYLST_T *locations = arraylst_create();
          arraylst_add(kmerloc, locations);
          hash_insert_str_value(kmer, locations, hash_fasta_table);
        } else {
          n_found++;
          ARRAYLST_T *locations = hash_get_entry_value(hash_entry);
          arraylst_add(kmerloc, locations);
        }
      }
    }
    summary->hash_fasta_table = hash_fasta_table;
    myfree(kmer);
  }
}
void create_hash_fasta_preprocess_table ( MOMO_OPTIONS_T * options , SUMMARY_T * summary , SEQ_T * * all_sequences , int num_sequences ) { int i ; int j ; int k ; if ( options -> hash_fasta && options -> protein_database_filename ) { HASH_TABLE hash_fasta_table = hash_create ( DATA_HASH_SIZE , ( void ( * ) ( void * ) ) arraylst_free ) ; int hash_fasta_width = options -> hash_fasta_width ; char * kmer = mm_malloc ( hash_fasta_width + 1 ) ; double n_found = 0 ; double n_test = 0 ; for ( i = 0 ; i < num_sequences ; i ++ ) { char * raw_sequence = get_raw_sequence ( all_sequences [ i ] ) ; int raw_sequence_length = strlen ( raw_sequence ) ; for ( j = 0 ; j < raw_sequence_length - hash_fasta_width + 1 ; ++ j ) { n_test ++ ; set_kmer ( & kmer , raw_sequence , j , hash_fasta_width ) ; KMER_LOC_T * kmerloc = mm_malloc ( sizeof ( KMER_LOC_T ) ) ; kmerloc -> seqidx = i ; kmerloc -> kmeridx = j ; HASH_TABLE_ENTRY * hash_entry ; char * dptr = 0 ; if ( ! ( hash_entry = hash_lookup_str ( kmer , hash_fasta_table ) ) ) { ARRAYLST_T * locations = arraylst_create ( ) ; arraylst_add ( kmerloc , locations ) ; hash_insert_str_value ( kmer , locations , hash_fasta_table ) ; } else { n_found ++ ; ARRAYLST_T * locations = hash_get_entry_value ( hash_entry ) ; arraylst_add ( kmerloc , locations ) ; } } } summary -> hash_fasta_table = hash_fasta_table ; myfree ( kmer ) ; } }
Sets the O(1) lookup table.
Sets the O ( 1 ) lookup table .
// hash table of kmers // Clean up