コード例 #1
0
ファイル: graph_info.c プロジェクト: Phelimb/mccortex
static void error_cleaning_init(ErrorCleaning *ec)
{
  ec->cleaned_tips = ec->cleaned_snodes = ec->cleaned_kmers = false;
  ec->clean_snodes_thresh = ec->clean_kmers_thresh = 0;
  ec->is_graph_intersection = false;
  strbuf_set(&ec->intersection_name, "undefined");
}
コード例 #2
0
ファイル: file_util.c プロジェクト: ambarrio/mccortex
// Remember to free the result
void futil_get_strbuf_of_dir_path(const char *path, StrBuf *dir)
{
  char *tmp = strdup(path);
  strbuf_set(dir, dirname(tmp));
  strbuf_append_char(dir, '/');
  ctx_free(tmp);
}
コード例 #3
0
ファイル: graph_info.c プロジェクト: Phelimb/mccortex
void graph_info_init(GraphInfo *ginfo)
{
  strbuf_set(&ginfo->sample_name, "undefined");
  ginfo->total_sequence = 0;
  ginfo->mean_read_length = 0;
  ginfo->seq_err = 0.01;
  error_cleaning_init(&ginfo->cleaning);
}
コード例 #4
0
ファイル: graph_info.c プロジェクト: jeromekelleher/mccortex
void graph_info_cpy(GraphInfo *dst, const GraphInfo *src)
{
  dst->mean_read_length = src->mean_read_length;
  dst->total_sequence = src->total_sequence;
  dst->seq_err = src->seq_err;
  strbuf_set(&dst->sample_name, src->sample_name.buff);
  error_cleaning_cpy(&dst->cleaning, &src->cleaning);
}
コード例 #5
0
ファイル: debug.c プロジェクト: ambarrio/mccortex
int main(int argc, char **argv)
{
  (void)argc; (void)argv;
  cortex_init();
  cmd_init(argc, argv);

  if(argc != 3) die("usage: ./debug <in.ctp> <in.ctx>");

  const char *out_path = argv[2];

  GPathReader pfile;
  memset(&pfile, 0, sizeof(GPathReader));
  gpath_reader_open(&pfile, argv[1], true);
  status("Got file with %zu colours", pfile.ncolours);

  size_t i, kmer_size = 7, ncols = 3;

  gpath_reader_check(&pfile, kmer_size, ncols);
  gzFile gzout = futil_gzopen_create(out_path, "w");

  dBGraph db_graph;
  db_graph_alloc(&db_graph, kmer_size, ncols, 1, 1024, DBG_ALLOC_EDGES);

  // Create a path store that tracks path counts
  gpath_store_alloc(&db_graph.gpstore,
                    db_graph.num_of_cols, db_graph.ht.capacity,
                    ONE_MEGABYTE, true, false);

  // Create path hash table for fast lookup
  gpath_hash_alloc(&db_graph.gphash, &db_graph.gpstore, ONE_MEGABYTE);

  // Set sample names
  for(i = 0; i < pfile.ncolours; i++) {
    const char *sample_name = gpath_reader_get_sample_name(&pfile, i);
    ctx_assert(sample_name != NULL);
    strbuf_set(&db_graph.ginfo[i].sample_name, sample_name);
  }

  // Load path files, add kmers that are missing
  gpath_reader_load(&pfile, GPATH_ADD_MISSING_KMERS, &db_graph);

  hash_table_print_stats(&db_graph.ht);

  // Write output file
  gpath_save(gzout, out_path, 1, true, NULL, NULL, &pfile.json, 1, &db_graph);
  gzclose(gzout);

  // Checks
  // gpath_checks_all_paths(&db_graph, 2); // use two threads
  gpath_checks_counts(&db_graph);

  // Clean up
  gpath_reader_close(&pfile);
  db_graph_dealloc(&db_graph);
  cortex_destroy();

  return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: lwan-lua.c プロジェクト: Abioy/lwan
static int req_set_response_cb(lua_State *L)
{
    lwan_request_t *request = userdata_as_request(L, 1);
    size_t response_str_len;
    const char *response_str = lua_tolstring(L, -1, &response_str_len);

    strbuf_set(request->response.buffer, response_str, response_str_len);

    return 0;
}
コード例 #7
0
ファイル: graph_info.c プロジェクト: jeromekelleher/mccortex
static void error_cleaning_cpy(ErrorCleaning *dst, const ErrorCleaning *src)
{
  dst->cleaned_tips = src->cleaned_tips;
  dst->cleaned_snodes = src->cleaned_snodes;
  dst->cleaned_kmers = src->cleaned_kmers;
  dst->clean_snodes_thresh = src->clean_snodes_thresh;
  dst->clean_kmers_thresh = src->clean_kmers_thresh;
  dst->is_graph_intersection = src->is_graph_intersection;
  strbuf_set(&dst->intersection_name, src->intersection_name.buff);
}
コード例 #8
0
ファイル: graph_info.c プロジェクト: Phelimb/mccortex
void graph_info_append_intersect(ErrorCleaning *cleaning, const char *intersect_name)
{
  if(!cleaning->is_graph_intersection)
  {
    strbuf_set(&cleaning->intersection_name, intersect_name);
  }
  else
  {
    strbuf_append_char(&cleaning->intersection_name, ',');
    strbuf_append_str(&cleaning->intersection_name, intersect_name);
  }
  cleaning->is_graph_intersection = true;
}
コード例 #9
0
ファイル: file_filter.c プロジェクト: Phelimb/mccortex
// Parse path and create FileFilter, calls die() with msg on error
// fltr should be zero'd before call
void file_filter_open(FileFilter *fltr, const char *path)
{
  const char *path_start, *path_end;
  size_t path_len;

  // Duplicate input string and file path
  strbuf_set(&fltr->input, path);
  file_filter_deconstruct_path(path, &path_start, &path_end);
  path_len = path_end - path_start;
  strbuf_ensure_capacity(&fltr->path, path_len);
  memcpy(fltr->path.b, path_start, path_len);
  fltr->path.b[fltr->path.end = path_len] = '\0';
}
コード例 #10
0
ファイル: graph_info.c プロジェクト: jeromekelleher/mccortex
void graph_info_merge(GraphInfo *dst, const GraphInfo *src)
{
  // Update sample name
  if(strcmp(src->sample_name.buff,"undefined") != 0) {
    if(strcmp(dst->sample_name.buff,"undefined") == 0) {
      strbuf_set(&dst->sample_name, src->sample_name.buff);
    } else {
      strbuf_append_char(&dst->sample_name, ',');
      strbuf_append_str(&dst->sample_name, src->sample_name.buff);
    }
  }

  uint64_t total_sequence = dst->total_sequence + src->total_sequence;

  if(total_sequence > 0)
  {
    // Average error rates
    dst->seq_err
      = (dst->seq_err * dst->total_sequence +
         src->seq_err * src->total_sequence) /
        total_sequence;

    // Update mean read length
    size_t src_num_contigs = 0;

    if(src->total_sequence && src->mean_read_length)
       src_num_contigs = ((double)src->total_sequence/src->mean_read_length)+0.5;

    graph_info_update_contigs(dst, src->total_sequence, src_num_contigs);
 }

  // Update error cleaning
  error_cleaning_merge(&dst->cleaning, &src->cleaning);

  dst->total_sequence = total_sequence;
}
コード例 #11
0
// If seq2 is NULL, read pair of entries from first file
// Otherwise read an entry from each
void align_from_file(const char *path1, const char *path2,
                     void (align)(StrBuf*, StrBuf*, const char*, const char*))
{
  SeqFile *sf1 = seq_file_open(path1);
  SeqFile *sf2;

  if(sf1 == NULL)
  {
    fprintf(stderr, "Alignment Error: couldn't open file %s\n", path1);
    fflush(stderr);
    return;
  }

  if(path2 != NULL)
  {
    sf2 = seq_file_open(path2);

    if(sf2 == NULL)
    {
      fprintf(stderr, "Alignment Error: couldn't open file %s\n", path1);
      fflush(stderr);
      return;
    }
  }
  else
  {
    sf2 = sf1;
  }

  StrBuf *entry1_title = strbuf_new();
  StrBuf *entry2_title = strbuf_new();
  StrBuf *entry1_seq = strbuf_new();
  StrBuf *entry2_seq = strbuf_new();

  char *title1 = NULL, *title2 = NULL;

  // Loop while we can read a sequence from the first file
  while(seq_next_read(sf1))
  {
    seq_read_all_bases(sf1, entry1_seq);

    if(seq_file_get_type(sf1) != SEQ_PLAIN)
    {
      strbuf_set(entry1_title, seq_get_read_name(sf1));
      title1 = entry1_title->buff;
    }

    if(!seq_next_read(sf2))
    {
      fprintf(stderr, "Alignment Error: Odd number of sequences - "
                      "I read in pairs!\n");
      fflush(stderr);
      break;
    }

    seq_read_all_bases(sf2, entry2_seq);

    if(seq_file_get_type(sf2) != SEQ_PLAIN)
    {
      strbuf_set(entry2_title, seq_get_read_name(sf2));
      title2 = entry2_title->buff;
    }

    (align)(entry1_seq, entry2_seq, title1, title2);
  }

  // warn if no bases read
  if(seq_total_bases_passed(sf1) == 0)
  {
    fprintf(stderr, "Alignment Warning: empty input\n");
    fflush(stderr);
  }

  // Close files
  seq_file_close(sf1);

  if(path2 != NULL)
    seq_file_close(sf2);

  // Free memory
  strbuf_free(entry1_title);
  strbuf_free(entry2_title);
  strbuf_free(entry1_seq);
  strbuf_free(entry2_seq);
}