void element_initialise(Element * e, BinaryKmer * kmer, short kmer_size) { BinaryKmer tmp_kmer; int i; binary_kmer_initialise_to_zero(&tmp_kmer); binary_kmer_assignment_operator(e->kmer, *(element_get_key(kmer, kmer_size, &tmp_kmer))); for (i=0; i<CONTAMINANT_FIELDS; i++) { e->contaminant_flags[i] = 0; } e->flags = ASSIGNED; #ifdef STORE_FULL_COVERAGE e->coverage[0] = 0; e->coverage[1] = 0; #endif }
dBNode * db_graph_get_next_node(dBNode * current_node, Orientation current_orientation, Orientation * next_orientation, Nucleotide edge, Nucleotide * reverse_edge,dBGraph * db_graph){ BinaryKmer local_copy_of_kmer; binary_kmer_assignment_operator(local_copy_of_kmer, current_node->kmer); BinaryKmer tmp_kmer; dBNode * next_node=NULL; // after the following line tmp_kmer and rev_kmer are pointing to the same B Kmer BinaryKmer* rev_kmer = binary_kmer_reverse_complement(&local_copy_of_kmer,db_graph->kmer_size, &tmp_kmer); if (current_orientation == reverse){ *reverse_edge = binary_kmer_get_last_nucleotide(&local_copy_of_kmer); binary_kmer_assignment_operator(local_copy_of_kmer,*rev_kmer); } else{ *reverse_edge = binary_kmer_get_last_nucleotide(rev_kmer); } binary_kmer_left_shift_one_base_and_insert_new_base_at_right_end(&local_copy_of_kmer, edge, db_graph->kmer_size); //get node from table next_node = hash_table_find(element_get_key(&local_copy_of_kmer,db_graph->kmer_size, &tmp_kmer),db_graph); if (next_node != NULL){ *next_orientation = db_node_get_orientation(&local_copy_of_kmer,next_node,db_graph->kmer_size); } else { // debug char tmpzamseq[db_graph->kmer_size+1]; warn("Cannot find %s so get a NULL node\n", binary_kmer_to_seq(&tmp_kmer, db_graph->kmer_size, tmpzamseq)); } return next_node; }
void test_hash_table_find_or_insert() { short kmer_size; long long max_key_given_kmer_size; //adds binary kmers to a hash, then tries to find them //will go through all possible bin kmers given the kmer_size, stepping // with granulatiry step. Since for kmer_size large (eg 21) it takes to long to try ALL // possible 21-mers, the last argument allows you to specify the largest one to test BinaryKmer tmp_kmer; BinaryKmer tmp_kmer2; void test(short kmer_size, int num_bits, int bucket, int max_tries, int step, long long max_kmer_to_test) { int number_of_bits = num_bits; int bucket_size = bucket; long long bad_reads = 0; int max_retries = max_tries; boolean found = false; HashTable* hash_table = hash_table_new(number_of_bits,bucket_size,max_retries,kmer_size); long long i; for (i=0; i< max_kmer_to_test; i++) { BinaryKmer b; binary_kmer_initialise_to_zero(&b); b[NUMBER_OF_BITFIELDS_IN_BINARY_KMER-1]=(bitfield_of_64bits) i; hash_table_find_or_insert(element_get_key(&b, hash_table->kmer_size, &tmp_kmer),&found, hash_table); if (found==false) { CU_ASSERT(binary_kmer_comparison_operator(b,*(element_get_key(&b, hash_table->kmer_size, &tmp_kmer)) ) ); } } Element* e=NULL; for (i=0; i< max_kmer_to_test; i=i+step) { BinaryKmer b; binary_kmer_initialise_to_zero(&b); b[NUMBER_OF_BITFIELDS_IN_BINARY_KMER-1]=(bitfield_of_64bits) i; e = hash_table_find(element_get_key(&b,hash_table->kmer_size,&tmp_kmer), hash_table); CU_ASSERT(e!=NULL); if (e !=NULL) { CU_ASSERT(binary_kmer_comparison_operator(e->kmer, *element_get_key(&b, hash_table->kmer_size, &tmp_kmer2)) ); } else { die("Error: e is NULL for i=%lld - unable to find\n",i); } } hash_table_free(&hash_table); CU_ASSERT(hash_table == NULL); }