/************************************************************************* * Output JSON data for a motif *************************************************************************/ static void output_motif_json(JSONWR_T* json, MOTIF_STATS_T* stats, SITE_COUNTS_T* counts) { //vars MOTIF_T *motif; MATRIX_T *freqs; int i, j, mlen, asize, end; motif = stats->motif; freqs = get_motif_freqs(motif); asize = alph_size(get_motif_alph(motif), ALPH_SIZE); jsonwr_start_object_value(json); jsonwr_lng_prop(json, "db", stats->db->id); jsonwr_str_prop(json, "id", get_motif_id(motif)); if (*(get_motif_id2(motif))) { jsonwr_str_prop(json, "alt", get_motif_id2(motif)); } mlen = get_motif_length(motif); jsonwr_lng_prop(json, "len", mlen); jsonwr_dbl_prop(json, "motif_evalue", get_motif_evalue(motif)); jsonwr_dbl_prop(json, "motif_nsites", get_motif_nsites(motif)); if (get_motif_url(motif) && *get_motif_url(motif)) { jsonwr_str_prop(json, "url", get_motif_url(motif)); } jsonwr_property(json, "pwm"); jsonwr_start_array_value(json); for (i = 0; i < mlen; i++) { jsonwr_start_array_value(json); for (j = 0; j < asize; j++) { jsonwr_dbl_value(json, get_matrix_cell(i, j, freqs)); } jsonwr_end_array_value(json); } jsonwr_end_array_value(json); jsonwr_lng_prop(json, "bin_width", stats->central_window+1); jsonwr_dbl_prop(json, "bin_sites", stats->central_sites); jsonwr_lng_prop(json, "total_sites", counts->total_sites); jsonwr_dbl_prop(json, "log_pvalue", stats->log_adj_pvalue); jsonwr_dbl_prop(json, "max_prob", stats->max_prob); jsonwr_property(json, "sites"); jsonwr_start_array_value(json); end = counts->allocated - (mlen - 1); for (i = (mlen - 1); i < end; i += 2) { jsonwr_dbl_value(json, counts->sites[i]); } jsonwr_end_array_value(json); jsonwr_end_object_value(json); }
/*********************************************************************** * Should the given motif be inserted into the model? * FIXME: These tests needn't be mutually exclusive. ***********************************************************************/ static BOOLEAN_T retain_motif( STRING_LIST_T* requested_motifs, // IDs of motifs to include. double e_threshold, // E-value to include motifs. double complexity_threshold, // Complexity threshold to include. ORDER_T* order_spacing, // Motif order and spacing (linear HMM). MOTIF_T* motif // The motif. ) { int num_requested; int i; char* motif_id; /* Method 1: Select motifs by index. */ num_requested = get_num_strings(requested_motifs); if (num_requested > 0) { motif_id = get_motif_id(motif); for (i = 0; i < num_requested; i++) { if (strcmp(get_nth_string(i, requested_motifs), motif_id) == 0) { return(TRUE); } } return(FALSE); } /* Method 2: Select motifs below a certain E-value threshold. */ else if (e_threshold != 0.0) { return (get_motif_evalue(motif) <= e_threshold); } /* Method 3: Select motifs that are included in the order string. */ else if (order_spacing != NULL) { return order_contains(get_motif_id(motif), order_spacing); } // Method 4: Select motifs by their complexity score. else if (complexity_threshold != 0.0) { return(motif->complexity >= complexity_threshold); } /* Default is to include all motifs. */ return(TRUE); }