示例#1
0
// Returns sorted array of hkey_t from the hash table
hkey_t* hash_table_sorted(const HashTable *htable)
{
  ctx_assert(sizeof(hkey_t) == sizeof(BinaryKmer*));
  ctx_assert(sizeof(hkey_t) == sizeof(BkmerPtrHkeyUnion));
  BkmerPtrHkeyUnion *kmers, *nxt, *end;
  nxt = kmers = ctx_malloc(sizeof(BkmerPtrHkeyUnion) * htable->num_kmers);
  end = kmers + htable->num_kmers;
  HASH_ITERATE(htable, _fetch_kmer_union, htable, &nxt);
  // Can sort ignoring that the top flag bit is set on all kmers
  qsort(kmers, htable->num_kmers, sizeof(BinaryKmer*), binary_kmers_qcmp_ptrs);
  for(nxt = kmers; nxt < end; nxt++) nxt->h = nxt->bptr - htable->table;
  return (hkey_t*)kmers;
}
示例#2
0
static void pull_out_supernodes(const char **seq, const char **ans, size_t n,
                                const dBGraph *graph)
{
  dBNodeBuffer nbuf;
  db_node_buf_alloc(&nbuf, 1024);

  // 1. Check pulling out supernodes works for iterating over the graph
  uint64_t *visited;
  visited = ctx_calloc(roundup_bits2words64(graph->ht.capacity), 8);
  HASH_ITERATE(&graph->ht, supernode_from_kmer,
               &nbuf, visited, graph, ans, n);
  ctx_free(visited);

  // 2. Check pulling out supernodes works when we iterate over inputs
  size_t i, j, len;
  dBNode node;
  char tmpstr[SNODEBUF];

  for(i = 0; i < n; i++) {
    len = strlen(seq[i]);
    for(j = 0; j+graph->kmer_size <= len; j++)
    {
      // Find node
      node = db_graph_find_str(graph, seq[i]+j);
      TASSERT(node.key != HASH_NOT_FOUND);

      // Fetch supernode
      db_node_buf_reset(&nbuf);
      supernode_find(node.key, &nbuf, graph);
      supernode_normalise(nbuf.b, nbuf.len, graph);

      // Compare
      TASSERT(nbuf.len < SNODEBUF);
      db_nodes_to_str(nbuf.b, nbuf.len, graph, tmpstr);
      if(strcmp(tmpstr, ans[i]) != 0) {
        test_status("Got: %s from ans[i]:%s\n", tmpstr, ans[i]);
      }
      TASSERT(strcmp(tmpstr, ans[i]) == 0);
    }
  }

  db_node_buf_dealloc(&nbuf);
}
示例#3
0
uint64_t hash_table_count_kmers(const HashTable *const ht)
{
  uint64_t count = 0;
  HASH_ITERATE(ht, increment_count, &count);
  return count;
}