コード例 #1
0
ファイル: centrimo.c プロジェクト: CPFL/gmeme
/*************************************************************************
 * 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);
}
コード例 #2
0
ファイル: centrimo.c プロジェクト: CPFL/gmeme
/*************************************************************************
 * Output motif site counts
 *************************************************************************/
static void output_site_counts(FILE* fh, int sequence_length, 
    MOTIF_DB_T* db, MOTIF_T* motif, SITE_COUNTS_T* counts) {
  // vars
  int i, w, end;
  char *alt;
  fprintf(fh, "DB %d MOTIF\t%s", db->id, get_motif_id(motif));
  alt = get_motif_id2(motif);
  if (alt[0]) fprintf(fh, "\t%s", alt);
  fprintf(fh, "\n");
  w = get_motif_length(motif);
  end = counts->allocated - (w - 1);
  for (i = (w - 1); i < end; i += 2) {
    fprintf(fh, "% 6.1f\t%g\n", 
        ((double)(i - sequence_length + 1)) / 2.0, 
        counts->sites[i]);
  }
}
コード例 #3
0
/**************************************************************************
 * Outputs txt for the spacings
 **************************************************************************/
void output_secondary_motif_txt(FILE *txt_output, 
    MOTIF_DB_T *primary_db, MOTIF_T *primary_motif, 
    SECONDARY_MOTIF_T *parent, SECONDARY_MOTIF_T *smotif, 
    int n_secondary_motifs, LINKLST_T *rmotifs) {
  LINK_T *node;
  SIGSPACE_T sig;
  int i, quad;
  char* orient_names[NORIENTS];
  // this maintains the previous definition of orientation but actual names would be better
  orient_names[LEFT | SAME] = "0";
  orient_names[LEFT | OPPO] = "1";
  orient_names[RIGHT | SAME] = "2";
  orient_names[RIGHT | OPPO] = "3";
  orient_names[UP_SEC_PAL] = "4";
  orient_names[UP_PRI_PAL] = "5";
  orient_names[DOWN_PRI_PAL] = "6";
  orient_names[DOWN_SEC_PAL] = "7";
  orient_names[BOTH_PAL] = "8";

  for (i = 0; i < smotif->sig_count; ++i) {
    sig = smotif->sigs[i];
    // Output txt line.
    fprintf(txt_output, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t%s\t%s\t%s\t%.2e\t%d\t%s\t%d\t%d\t%.2e\t%.2e\n",
      primary_db->name,
      get_motif_id(primary_motif),
      strcmp(get_motif_id2(primary_motif), "") ? get_motif_id2(primary_motif) : ".",
      get_motif_consensus(primary_motif),
      smotif->db->name,
      get_motif_id(smotif->motif),
      strcmp(get_motif_id2(smotif->motif), "") ? get_motif_id2(smotif->motif) : ".",
      get_motif_consensus(smotif->motif),
      get_motif_trim_left(smotif->motif),
      get_motif_trim_right(smotif->motif),
      parent ? smotif->db->name : ".",
      parent ? get_motif_id(parent->motif) : ".",
      parent && strcmp(get_motif_id2(parent->motif), "") ? get_motif_id2(parent->motif) : ".",
      smotif->min_pvalue * n_secondary_motifs, // E-value
      sig.bin, // gap
      orient_names[sig.orient], // orientation
      smotif->spacings[sig.orient].count[sig.bin], // count
      smotif->total_spacings, // total occurrences of secondary in margins
      sig.pvalue < 1e-10 ? sig.pvalue/NORIENTS : 1-pow((1-sig.pvalue),1.0/NORIENTS),
      sig.pvalue
    );
  }

  if (rmotifs != NULL && linklst_size(rmotifs) > 0) {
    for (node = linklst_first(rmotifs); node != NULL; node = linklst_next(node)) {
      SECONDARY_MOTIF_T *rmotif = linklst_get(node);
      output_secondary_motif_txt(txt_output, primary_db, primary_motif, smotif, rmotif, n_secondary_motifs, NULL);
    }
  }
}
コード例 #4
0
ファイル: centrimo.c プロジェクト: CPFL/gmeme
/*************************************************************************
 * Output CentriMo text output
 *************************************************************************/
static void output_centrimo_text(CENTRIMO_OPTIONS_T *options, int motifN,
    ARRAYLST_T *stats_list) {
  MOTIF_STATS_T *stats;
  char *file_path;
  int i, pad;
  double log_motifN;
  FILE *text_file;
  MOTIF_T *motif;
  // find the evalue conversion factor
  log_motifN = log(motifN);
  // Sort and write centrimo.txt
  arraylst_qsort(motif_stats_compar, stats_list);
  // open centrimo text file
  file_path = make_path_to_file(options->output_dirname, TEXT_FILENAME);
  text_file = fopen(file_path, "w");
  free(file_path);
  fputs("# motif             \tE-value\tadj_p-value\tlog_adj_p-value\t"
      "bin_width\ttotal_width\tsites_in_bin\ttotal_sites\tp_success\t"
      "p-value\tmult_tests\n", text_file);
  fprintf(text_file, "# Found %d motifs with E-values <= %g\n", 
      arraylst_size(stats_list), options->evalue_thresh);
  // write centrimo text output
  for (i = 0; i < arraylst_size(stats_list); i++) {
    stats = arraylst_get(i, stats_list);
    motif = stats->motif;
    pad = 19 - strlen(get_motif_id(motif));
    fprintf(text_file, "%s %-*s\t", get_motif_id(motif), 
        pad, get_motif_id2(motif));
    print_log_value(text_file, stats->log_adj_pvalue + log_motifN, 1);
    fputs("\t", text_file);
    print_log_value(text_file, stats->log_adj_pvalue, 1);
    fprintf(text_file, "\t%.2f\t%d\t%d\t%.0f\t%ld\t%.5f\t", 
        stats->log_adj_pvalue, stats->central_window+1, stats->all_window, 
        stats->central_sites, stats->total_sites, 
        stats->central_prob);
    print_log_value(text_file, stats->log_pvalue, 1);
    fprintf(text_file, "\t%d\n", stats->n_win_tested);
  }
  fclose(text_file);
}