/*********************************************************************** * Apply a pseudocount to the motif pspm. ***********************************************************************/ void apply_pseudocount_to_motif (MOTIF_T* motif, ARRAY_T *background, double pseudocount) { int pos, letter, len, asize, sites; double prob, count, total; ARRAY_T *temp; // no point in doing work when it makes no difference if (pseudocount == 0) return; assert(pseudocount > 0); // motif dimensions asize = alph_size(motif->alph, ALPH_SIZE); len = motif->length; // create a uniform background if none is given temp = NULL; if (background == NULL) { temp = allocate_array(asize); get_uniform_frequencies(motif->alph, temp); background = temp; } // calculate the counts sites = (motif->num_sites > 0 ? motif->num_sites : DEFAULT_SITE_COUNT); total = sites + pseudocount; for (pos = 0; pos < len; ++pos) { for (letter = 0; letter < asize; ++letter) { prob = get_matrix_cell(pos, letter, motif->freqs); count = (prob * sites) + (pseudocount * get_array_item(letter, background)); prob = count / total; set_matrix_cell(pos, letter, prob, motif->freqs); } } if (temp) free_array(temp); }
/* * When the parser has been selected do some processing */ static void parser_selected(MREAD_T *mread) { ALPH_T alph; MFORMAT_T* format; format = mread->formats; // get the alphabet alph = format->get_alphabet(mread->formats->data); // get the background if (format->get_bg(format->data, &(mread->motif_bg))) { normalize_subarray(0, alph_size(alph, ALPH_SIZE), 0.0, mread->motif_bg); resize_array(mread->motif_bg, alph_size(alph, ALL_SIZE)); calc_ambigs(alph, FALSE, mread->motif_bg); } else { mread->motif_bg = get_uniform_frequencies(alph, mread->motif_bg); } set_pseudo_bg(mread); }
/* * Sets the background for the pseudo-counts * but requires the alphabet to do it. */ static void set_pseudo_bg(MREAD_T *mread) { ALPH_T alph; alph = mread->formats->get_alphabet(mread->formats->data); assert(alph != INVALID_ALPH); if (!mread->other_bg) { // no change to other_bg if (mread->other_bg_src == NULL || strcmp(mread->other_bg_src, "--nrdb--") == 0) { mread->other_bg = get_nrdb_frequencies(alph, NULL); } else if (strcmp(mread->other_bg_src, "--uniform--") == 0) { mread->other_bg = get_uniform_frequencies(alph, NULL); } else if (strcmp(mread->other_bg_src, "--motif--") == 0 || strcmp(mread->other_bg_src, "motif-file") == 0) { // motif_bg is loaded elsewhere } else { mread->other_bg = get_file_frequencies(&(alph), mread->other_bg_src, NULL); } } if (mread->other_bg) mread->pseudo_bg = mread->other_bg; else mread->pseudo_bg = mread->motif_bg; }
ARRAY_T* ramen_load_background() { ALPH_T alph = DNA_ALPH; ARRAY_T* freqs; switch (args.bg_format) { case UNIFORM_BG: freqs = get_uniform_frequencies(alph, NULL); break; case MOTIF_BG: //We've previously read in the freqs when we read the motif list freqs = motifs.bg_freqs; //so we're just copying a pointer address so that we use them. break; case FILE_BG: freqs = get_file_frequencies(&alph, args.bg_filename, NULL); break; default: die("Illegal background option"); freqs = NULL; // make compiler happy } return freqs; }