Esempio n. 1
0
void _test_add_paths(dBGraph *graph,
                     AsyncIOData *iodata, CorrectAlnInput *task,
                     GenPathWorker *wrkrs, char *seq,
                     size_t exp_npaths, size_t exp_nkmers, size_t exp_pbytes)
{
  size_t npaths = graph->pstore.num_of_paths;
  size_t nkmers = graph->pstore.num_kmers_with_paths;
  uint8_t *next = graph->pstore.next;

  // Set up asyncio input data
  seq_read_set(&iodata->r1, seq);
  seq_read_reset(&iodata->r2);
  iodata->fq_offset1 = iodata->fq_offset2 = 0;
  iodata->ptr = NULL;
  // Add paths
  gen_paths_worker_seq(wrkrs, iodata, task);

  // Check we added the right number of paths
  TASSERT(graph->pstore.num_of_paths == npaths + exp_npaths);
  TASSERT(graph->pstore.num_kmers_with_paths == nkmers + exp_nkmers);

  // Check memory used
  size_t path_mem = sizeof(PathIndex) + graph->pstore.colset_bytes +
                    sizeof(PathLen) + graph->pstore.extra_bytes;
  size_t exp_mem = path_mem * exp_npaths + exp_pbytes;
  TASSERT(graph->pstore.next == next + exp_mem);
}
Esempio n. 2
0
void all_tests_add_paths_multi(dBGraph *graph, const char **seqs, size_t nseqs,
                               CorrectAlnParam params,
                               int exp_npaths, int exp_nkmers)
{
  size_t npaths = graph->gpstore.num_paths;
  size_t nkmers = graph->gpstore.num_kmers_with_paths;

  size_t i, nworkers = 1;
  GenPathWorker *wrkrs = gen_paths_workers_alloc(nworkers, graph);

  // Set up asyncio input data
  AsyncIOInput io = {.file1 = NULL, .file2 = NULL,
                     .fq_offset = 0, .interleaved = false};

  CorrectAlnInput task = {.files = io, .fq_cutoff = 0, .hp_cutoff = 0,
                          .matedir = READPAIR_FR, .crt_params = params,
                          .out_base = NULL, .output = NULL};

  AsyncIOData iodata;
  asynciodata_alloc(&iodata);
  seq_read_reset(&iodata.r2);
  iodata.fq_offset1 = iodata.fq_offset2 = 0;
  iodata.ptr = NULL;

  // Add paths
  for(i = 0; i < nseqs; i++) {
    seq_read_set(&iodata.r1, seqs[i]);
    gen_paths_worker_seq(wrkrs, &iodata, &task);
  }

  asynciodata_dealloc(&iodata);
  gen_paths_workers_dealloc(wrkrs, nworkers);

  // Check we added the right number of paths
  if(exp_npaths >= 0) {
    TASSERT2(graph->gpstore.num_paths == npaths + (size_t)exp_npaths, "%zu %zu %zu",
             (size_t)graph->gpstore.num_paths, (size_t)npaths, (size_t)exp_npaths);
  }

  if(exp_nkmers >= 0) {
    TASSERT(graph->gpstore.num_kmers_with_paths == nkmers + (size_t)exp_nkmers);
  }
}

void all_tests_add_paths(dBGraph *graph, const char *seq,
                         CorrectAlnParam params,
                         int exp_npaths, int exp_nkmers)
{
  all_tests_add_paths_multi(graph, &seq, 1, params, exp_npaths, exp_nkmers);
}

void all_tests_construct_graph(dBGraph *graph,
                               size_t kmer_size, size_t ncols,
                               const char **seqs, size_t nseqs,
                               CorrectAlnParam path_params)
{
  size_t i;
  db_graph_alloc(graph, kmer_size, ncols, ncols, 1024,
                 DBG_ALLOC_EDGES | DBG_ALLOC_COVGS |
                 DBG_ALLOC_NODE_IN_COL | DBG_ALLOC_BKTLOCKS);

  // Path data
  gpath_store_alloc(&graph->gpstore, ncols, graph->ht.capacity,
                    0, ONE_MEGABYTE, true, false);

  // Don't use links to add new links
  gpath_store_split_read_write(&graph->gpstore);

  // Allocate path hash table just in case
  gpath_hash_alloc(&graph->gphash, &graph->gpstore, ONE_MEGABYTE);

  // Build graph
  for(i = 0; i < nseqs; i++)
    build_graph_from_str_mt(graph, 0, seqs[i], strlen(seqs[i]), false);

  gpath_store_merge_read_write(&graph->gpstore);

  graph->num_of_cols_used = MAX2(graph->num_of_cols_used, 1);

  all_tests_add_paths_multi(graph, seqs, nseqs, path_params, -1, -1);
}