debruijn | de Bruijn graph construction tool | Genomics library
kandi X-RAY | debruijn Summary
kandi X-RAY | debruijn Summary
This software is quite old (2011). There are better techniques nowadays. A better de Bruijn graph construction algorithm is BCALM: (readable Python code here: Another is an implementation included in the book Genome-Scale Algorithm Design (Chapter 13.2, Software that constructs the de Bruijn graph of a set of reads (FASTA or FASTQ file). Edges are the (k+1)-mers that appear in the reads, nodes are the k-mers. No distintion is made between a k-mer (resp. (k+1)-mer) and its reverse-complement. It returns a graph in the KisSplice format (ad-hoc) or DOT format (can be opened by most applications, including Zgrviewer and Gephi). The de Bruijn graph is useful for many next-generation sequencing applications, including de novo genome assembly and variant detection. For k 32, this implementation uses.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of debruijn
debruijn Key Features
debruijn Examples and Code Snippets
Community Discussions
Trending Discussions on debruijn
QUESTION
I have a program in which it is necessary to calculate the floor of the log-base-2 of an integer very frequently. As a reuslt, the performance of the standard library's log2 method in my language of choice (floor(std::log2([INT]))
from in C++) is unsatisfactory, and I would like to implement the quickest version of this algorithm possible. I have found versions online which use bitwise operators to calculate this value for 32-bit and 64-bit integers:
ANSWER
Answered 2021-Aug-06 at 12:51I agree with harold that std::countl_zero()
is the way to go. Memory
has gotten a lot slower relative to compute since this bit-twiddling
hack was designed, and processors typically have built-in instructions.
To answer your question, however, this hack combines a couple primitives. (When I talk about bit indexes, I'm counting from most to least significant, starting the count at zero.)
The sequence of lines starting with
v |= v >> 1;
achieves its stated goal of rounding up to the nearest power of two minus one (i.e., a number whose binary representation matches0*1*
) by setting every bit to the right of at least one set bit.- None of these lines clears bits in
v
. - Since there are right shifts only, every bit set by these lines is to the right of at least one set bit.
- Given a set bit at position
i
, we observe that a bit at positioni + delta
will be guaranteed set by the lines matchingdelta
's binary representation, e.g.,delta = 13
(1101 in binary) is handled byv |= v >> 1; v |= v >> 4; v |= v >> 8;
.
- None of these lines clears bits in
Extracting bits
[L, L+delta)
from an unsigned integern
withWIDTH
bits can be accomplished with(n << L) >> (WIDTH - delta)
. The left shift truncates the upper bits that should be discarded, and the right shift, which is logical in C++ for unsigned, truncates the lower bits and fills the truncated upper bits with zeros.Given that the answer is
k
, we want to extract 5 (= log2(32), for 32-bit) or 6 (= log2(64), for 64-bit) bits starting with indexk
from the magic constantn
. We can't shift byk
because we only knowpow2(k)
(sort of, I'll get to that in a second), but we can use the equivalence between multiplying bypow2(k)
and left shifting byk
as a workaround.Actually we only know
pow2(k+1) - 1
. We're going to be greedy and shave the two ops that we'd need to getpow2(k)
. By putting 5 or 6 ones after the initial zeros, we force that minus one to always cause the answer to be one less than it should have been (mod 32 or 64).So the de Bruijn sequence: the idea is that we can uniquely identify our index in the sequence by reading the next 5 or 6 bits. We aren't so lucky as to be able to have these bits be equal to the index, which is where the look-up table comes in.
As an example, I'll adapt this algorithm to 8-bit words. We start with
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install debruijn
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page