コード例 #1
0
ファイル: gpath_save.c プロジェクト: mcveanlab/mccortex
/**
 * Generate a JSON header object for a .ctp file
 * @param path        path to output file
 * @param cmdstr      name of the command being run, to be used to add @cmdhdr
 * @param cmdhdr      JSON header to add under current command->@cmdstr
 *                    If cmdstr and cmdhdr are both NULL they are ignored
 * @param contig_hist histgram of read contig lengths
 * @param hist_len    length of array contig_hist
 */
cJSON* gpath_save_mkhdr(const char *path,
                        const char *cmdstr, cJSON *cmdhdr,
                        cJSON **hdrs, size_t nhdrs,
                        const ZeroSizeBuffer *contig_hists, size_t ncols,
                        const dBGraph *db_graph)
{
  ctx_assert(!cmdstr == !cmdhdr);

  const GPathStore *gpstore = &db_graph->gpstore;
  const GPathSet *gpset = &gpstore->gpset;

  // using json_hdr_make_std() assumes the following
  ctx_assert(gpset->ncols == db_graph->num_of_cols);

  // Construct cJSON
  cJSON *jsonhdr = cJSON_CreateObject();

  cJSON_AddStringToObject(jsonhdr, "file_format", "ctp");
  cJSON_AddNumberToObject(jsonhdr, "format_version", CTP_FORMAT_VERSION);

  // Add standard cortex header info, including the command being run
  json_hdr_make_std(jsonhdr, path, hdrs, nhdrs, db_graph,
                    hash_table_nkmers(&db_graph->ht));

  // Get first command (this one), and command specific extra info
  if(cmdstr) {
    cJSON *cmd = json_hdr_get_curr_cmd(jsonhdr, path);
    cJSON_AddItemToObject(cmd, cmdstr, cmdhdr);
  }

  // Paths info
  cJSON *paths = cJSON_CreateObject();
  cJSON_AddItemToObject(jsonhdr, "paths", paths);

  // Add command specific header fields
  cJSON_AddNumberToObject(paths, "num_kmers_with_paths", gpstore->num_kmers_with_paths);
  cJSON_AddNumberToObject(paths, "num_paths", gpstore->num_paths);
  cJSON_AddNumberToObject(paths, "path_bytes", gpstore->path_bytes);

  // Add size distribution
  cJSON *json_hists = cJSON_CreateArray();
  cJSON_AddItemToObject(paths, "contig_hists", json_hists);

  size_t i;
  for(i = 0; i < ncols; i++)
    _gpath_save_contig_hist2json(json_hists, contig_hists[i].b, contig_hists[i].len);

  return jsonhdr;
}
コード例 #2
0
ファイル: bubble_caller.c プロジェクト: ambarrio/mccortex
// Print JSON header to gzout
static void bubble_caller_print_header(gzFile gzout, const char* out_path,
                                       BubbleCallingPrefs prefs,
                                       cJSON **hdrs, size_t nhdrs,
                                       const dBGraph *db_graph)
{
  size_t i;

  // Construct cJSON
  cJSON *json = cJSON_CreateObject();

  cJSON_AddStringToObject(json, "file_format", "CtxBubbles");
  cJSON_AddNumberToObject(json, "format_version", BUBBLE_FORMAT_VERSION);

  // Add standard cortex headers
  json_hdr_make_std(json, out_path, hdrs, nhdrs, db_graph);

  // Add parameters used in bubble calling to the header
  json_hdr_augment_cmd(json, "bubbles", "max_flank_kmers",  cJSON_CreateInt(prefs.max_flank_len));
  json_hdr_augment_cmd(json, "bubbles", "max_allele_kmers", cJSON_CreateInt(prefs.max_allele_len));
  cJSON *haploids = cJSON_CreateArray();
  for(i = 0; i < prefs.num_haploid; i++)
    cJSON_AddItemToArray(haploids, cJSON_CreateInt(prefs.haploid_cols[i]));
  json_hdr_augment_cmd(json, "bubbles", "haploid_colours", haploids);

  // Write header to file
  json_hdr_gzprint(json, gzout);

  // Print comments about the format
  gzputs(gzout, "\n");
  gzputs(gzout, "# This file was generated with McCortex\n");
  gzputs(gzout, "#   written by Isaac Turner <*****@*****.**>\n");
  gzputs(gzout, "#   url: "CORTEX_URL"\n");
  gzputs(gzout, "# \n");
  gzputs(gzout, "# Comment lines begin with a # and are ignored, but must come after the header\n");
  gzputs(gzout, "\n");

  cJSON_Delete(json);
}