deps/kb_meme/meme-5.0.1/src/momo-input.c
/**
 * Given a peptide (modless), we want to see if we can find the protein
 * it originated from. If not, result is not changed.
 */
Given a peptide (modless), we want to see if we can find the protein
it originated from. If not, result is not changed.
Given a peptide ( modless ) we want to see if we can find the protein it originated from . If not result is not changed .
void find_fasta( 
   SUMMARY_T* summary,
   MOMO_OPTIONS_T* options,
   SEQ_T **all_sequences,
   int num_sequences,
   char* modless,
   KMER_LOC_T* result 
) { 
  int i;
  int hash_fasta_width = options->hash_fasta_width;
  HASH_TABLE hash_fasta_table = summary->hash_fasta_table;
  if (options->hash_fasta && options->protein_database_filename && strlen(modless) >= hash_fasta_width) {
    char c_save = modless[hash_fasta_width];
    modless[hash_fasta_width] = '\0';
    HASH_TABLE_ENTRY *hash_entry = hash_lookup_str(modless, hash_fasta_table);
    modless[hash_fasta_width] = c_save;	
    if (hash_entry) {
      ARRAYLST_T *kmerloclist = (ARRAYLST_T*) hash_get_entry_value(hash_entry);
      for (i = 0; i < arraylst_size(kmerloclist); ++i) {
	KMER_LOC_T *kmerloc = arraylst_get(i, kmerloclist);
	char* protein = get_raw_sequence(all_sequences[kmerloc->seqidx]);
	char* peptide = protein + kmerloc->kmeridx;
	if (strncmp(modless, peptide, strlen(modless)) == 0) {
	  result->seqidx = kmerloc->seqidx;
            result->kmeridx = kmerloc->kmeridx;
            break;		
        }
      }
    }
  } else {
    for (i = 0; i < num_sequences; i++) {
      char* raw_sequence = get_raw_sequence(all_sequences[i]);
      char* found = strstr(raw_sequence, modless);
      if (found) {
	result->seqidx = i;
	result->kmeridx = found - raw_sequence;
	break;			
      }
    }
  }
}
void find_fasta ( SUMMARY_T * summary , MOMO_OPTIONS_T * options , SEQ_T * * all_sequences , int num_sequences , char * modless , KMER_LOC_T * result ) { int i ; int hash_fasta_width = options -> hash_fasta_width ; HASH_TABLE hash_fasta_table = summary -> hash_fasta_table ; if ( options -> hash_fasta && options -> protein_database_filename && strlen ( modless ) >= hash_fasta_width ) { char c_save = modless [ hash_fasta_width ] ; modless [ hash_fasta_width ] = ' \0 ' ; HASH_TABLE_ENTRY * hash_entry = hash_lookup_str ( modless , hash_fasta_table ) ; modless [ hash_fasta_width ] = c_save ; if ( hash_entry ) { ARRAYLST_T * kmerloclist = ( ARRAYLST_T * ) hash_get_entry_value ( hash_entry ) ; for ( i = 0 ; i < arraylst_size ( kmerloclist ) ; ++ i ) { KMER_LOC_T * kmerloc = arraylst_get ( i , kmerloclist ) ; char * protein = get_raw_sequence ( all_sequences [ kmerloc -> seqidx ] ) ; char * peptide = protein + kmerloc -> kmeridx ; if ( strncmp ( modless , peptide , strlen ( modless ) ) == 0 ) { result -> seqidx = kmerloc -> seqidx ; result -> kmeridx = kmerloc -> kmeridx ; break ; } } } } else { for ( i = 0 ; i < num_sequences ; i ++ ) { char * raw_sequence = get_raw_sequence ( all_sequences [ i ] ) ; char * found = strstr ( raw_sequence , modless ) ; if ( found ) { result -> seqidx = i ; result -> kmeridx = found - raw_sequence ; break ; } } } }
Given a peptide (modless), we want to see if we can find the protein
 it originated from.
Given a peptide ( modless ) we want to see if we can find the protein it originated from .
// Use hash search if possible, otherwise linear search to find // the peptide in the protein database. // Use the O(1) lookup table to find the location of the peptide within the protein database // First, see if the prefix of the string is in the hash table. // Temporarily truncate the string at the hash width. // restore string // Then, see if the whole string matches one of the places beginning with its prefix. // protein found // Use linear search to find the location of a peptide within // the protein database. Returns a kmer info object if found. // protein found