Debian Codegraph @

ext/bifrost/README.md

raw symbols SCIP
1 # Bifrost
2
3 ### Parallel construction, indexing and querying of colored and compacted de Bruijn graphs
4
5 * **Build**, **index**, **color** and **query** the compacted de Bruijn graph
6 * **No need to build the uncompacted** de Bruijn graph
7 * **Reads** or **assembled genomes** as input
8 * Output **graph in GFA** (can be visualized with [Bandage](https://github.com/rrwick/Bandage))
9 * **Graph cleaning**: short tip clipping, etc.
10 * **No disk** usage (adapted for cluster architectures)
11 * **Multi-threaded** and **SIMD** optimized
12 * **No parameters to estimate** with other tools
13 * **Inexact** *k*-mer search of queries
14 * **C++ API** available:
15 * Associate **your data with vertices**
16 * **Add** or **remove** (sub-)sequences / *k*-mers / colors
17 * **Find unitigs** containing **queried k-mers**
18
19 ## Table of Contents
20
21 * [Requirements](#requirements)
22 * [Installation](#installation)
23 * [Binary usage](#binary-usage)
24 * [API](#api)
25 * [FAQ](#faq)
26 * [Troubleshooting](#troubleshooting)
27 * [Citation](#citation)
28 * [Contact](#contact)
29 * [License](#license)
30
31 ## Requirements
32
33 To install Bifrost using Bioconda or Brew, go directly to Section [Installation](#installation). To install from source, you will need:
34
35 * C++11 compiler:
36 * [GCC](https://gcc.gnu.org/) >= 5.1.0
37 * [Clang](http://clang.llvm.org/) >= 3.5
38 * [Cmake](https://cmake.org/) >= 2.8.12
39 * [Zlib](https://zlib.net/)
40
41 All are probably already installed on your computer as those are installed by default on most operating systems. They can be downloaded and installed by following the instructions on their respective websites. However, it is most likely they are all available via a package manager for your operating system:
42
43 * **Ubuntu/Debian**:
44 ```
45 sudo apt-get install build-essential cmake zlib1g-dev
46 ```
47 * **MacOS** (with [Homebrew](https://brew.sh/)):
48 ```
49 brew install --with-toolchain llvm
50 brew install cmake zlib
51 ```
52 * **Windows 10**:
53
54 1. Open the Windows Store
55 2. Search and install the `Ubuntu` app (from `Canonical Group Limited`)
56 3. Open the Windows main menu and open the `Ubuntu` app (it should open an Ubuntu terminal)
57 4. Use the following command in the Ubuntu terminal:
58 ```
59 sudo apt-get install build-essential cmake zlib1g-dev
60 ```
61 5. Use the opened Ubuntu terminal for compiling, installing and running Bifrost (see next section). See [Troubleshooting](#troubleshooting) if you have any problem during the installation.
62
63 ## Installation
64
65 Compared to the source install, the Conda package do not support *k>31* nor native compilation (including AVX2 instructions). Use the source installation for benchmarking.
66
67 * From [Bioconda](https://bioconda.github.io):
68
69 ```
70 conda -c bioconda bifrost
71 ```
72
73 * From source
74
75 ```
76 git clone https://github.com/pmelsted/bifrost.git
77 cd bifrost && mkdir build && cd build
78 cmake ..
79 make
80 make install
81 ```
82
83 `make install` might require `sudo` (`sudo make install`) to proceed. To install Bifrost in the non-default path `/some/path/`, add the option `-DCMAKE_INSTALL_PREFIX=/some/path/` to the `cmake` command.
84
85 By default, the installation creates:
86 * a binary (*Bifrost*)
87 * a dynamic library (*libbifrost.so* for Unix or *libbifrost.dylib* for MacOS)
88 * a static library (*libbifrost.a*)
89
90 **Advanced options**
91 * Bifrost compiles by default with `-march=native`: the compiler targets architecture instructions specific to the machine Bifrost is compiled on. Hence, the binary and library produced might not work on a different machine. Native compilation can be disabled by adding the option `-DCOMPILATION_ARCH=OFF` to the `cmake` command (disables all AVX2 optimizations too). Alternatively, you can use this option to specify the architecture you want to target: `x86-64`, `knl`, etc. Default is `-DCOMPILATION_ARCH=native`.
92 * Bifrost uses AVX2 instructions during graph construction which can be disabled by adding the option `-DENABLE_AVX2=OFF` to the `cmake` command.
93
94 If you encounter any problem during the installation, see the [Troubleshooting](#troubleshooting) section.
95
96 ### Large *k*-mers
97
98 The default maximum *k*-mer size supported is 31. To work with larger *k* in the binary, you must install Bifrost from source and replace *MAX_KMER_SIZE* with a larger multiple of 32. This can be done in two ways:
99
100 * By adding the following option to the `cmake` command:
101 ```
102 -DMAX_KMER_SIZE=64
103 ```
104
105 * By replacing *MAX_KMER_SIZE* in *CMakeLists.txt*:
106 ```
107 SET(MAX_KMER_SIZE "64" CACHE STRING "MAX_KMER_SIZE")
108 ```
109
110 Actual maximum k-mer size is *MAX_KMER_SIZE-1*, e.g maximum *k* is 63 for *MAX_KMER_SIZE=64*. Increasing *MAX_KMER_SIZE* increases Bifrost memory usage (*k*=31 uses 8 bytes of memory per *k*-mer while *k*=63 uses 16 bytes of memory per *k*-mer).
111
112 The maximum size of minimizers (*g*-mers) *MAX_GMER_SIZE* can be adjusted the same way as *MAX_KMER_SIZE*. This is especially useful if you want to use a large *k*-mer size but a small *g*-mer size. By default, *MAX_GMER_SIZE* is equal to *MAX_KMER_SIZE*.
113
114 To work with larger *k* when using the Bifrost API, the new value *MAX_KMER_SIZE* must be given to the compiler and linker as explained in Section [API](#api)
115
116 ## Binary usage:
117
118 ```
119 Bifrost
120 ```
121
122 displays the command line interface:
123 ```
124 Bifrost x.y
125
126 Highly parallel construction, indexing and querying of colored and compacted de Bruijn graphs
127
128 Usage: Bifrost [COMMAND] [PARAMETERS]
129
130 [COMMAND]:
131
132 build Build a compacted de Bruijn graph, with or without colors
133 update Update a compacted (possible colored) de Bruijn graph with new sequences
134 query Query a compacted (possible colored) de Bruijn graph
135
136 [PARAMETERS]: build
137
138 > Mandatory with required argument:
139
140 -s, --input-seq-file Input sequence file (FASTA/FASTQ possibly gzipped)
141 Multiple files can be provided as a list in a TXT file (one file per line)
142 K-mers with exactly 1 occurrence in the input sequence files will be discarded
143 -r, --input-ref-file Input reference file (FASTA/FASTQ possibly gzipped and GFA)
144 Multiple files can be provided as a list in a TXT file (one file per line)
145 All k-mers of the input reference files are used
146 -o, --output-file Prefix for output file(s)
147
148 > Optional with required argument:
149
150 -t, --threads Number of threads (default is 1)
151 -k, --kmer-length Length of k-mers (default is 31)
152 -m, --min-length Length of minimizers (default is 23)
153 -b, --bloom-bits Number of Bloom filter bits per k-mer with 1+ occurrences in the input files (default is 14)
154 -B, --bloom-bits2 Number of Bloom filter bits per k-mer with 2+ occurrences in the input files (default is 14)
155 -l, --load-mbbf Input Blocked Bloom Filter file, skips filtering step (default is no input)
156 -w, --write-mbbf Output Blocked Bloom Filter file (default is no output)
157 -u, --chunk-size Read chunk size per thread (default is 64)
158
159 > Optional with no argument:
160
161 -c, --colors Color the compacted de Bruijn graph (default is no coloring)
162 -y, --keep-mercy Keep low coverage k-mers connecting tips
163 -i, --clip-tips Clip tips shorter than k k-mers in length
164 -d, --del-isolated Delete isolated contigs shorter than k k-mers in length
165 -a, --fasta Output file is in FASTA format (only sequences) instead of GFA
166 -v, --verbose Print information messages during execution
167
168 [PARAMETERS]: update
169
170 > Mandatory with required argument:
171
172 -g, --input-graph-file Input graph file to update (GFA format)
173 -s, --input-seq-file Input sequence file (FASTA/FASTQ possibly gzipped)
174 Multiple files can be provided as a list in a TXT file (one file per line)
175 K-mers with exactly 1 occurrence in the input sequence files will be discarded
176 -r, --input-ref-file Input reference file (FASTA/FASTQ possibly gzipped and GFA)
177 Multiple files can be provided as a list in a TXT file (one file per line)
178 All k-mers of the input reference files are used
179 -o, --output-file Prefix for output file(s)
180
181 > Optional with required argument:
182
183 -f, --input-color-file Input color file associated with the input graph file to update
184 -t, --threads Number of threads (default is 1)
185 -k, --kmer-length Length of k-mers (default is read from input graph file if built with Bifrost or 31)
186 -m, --min-length Length of minimizers (default is read from input graph file if built with Bifrost or 23)
187
188 > Optional with no argument:
189
190 -i, --clip-tips Clip tips shorter than k k-mers in length
191 -d, --del-isolated Delete isolated contigs shorter than k k-mers in length
192 -v, --verbose Print information messages during execution
193
194 [PARAMETERS]: query
195
196 > Mandatory with required argument:
197
198 -g, --input-graph-file Input graph file to query (GFA format)
199 -q, --input-query-file Input query file (FASTA/FASTQ possibly gzipped)
200 Multiple files can be provided as a list in a TXT file (one file per line)
201 -o, --output-file Prefix for output file
202 -e, --ratio-kmers Ratio of k-mers from queries that must occur in the graph (default is 0.8)
203
204 > Optional with required argument:
205
206 -f, --input-color-file Input color file associated with the input graph file to query
207 Presence/absence of queries will be output for each color
208 -t, --threads Number of threads (default is 1)
209 -k, --kmer-length Length of k-mers (default is read from input graph file if built with Bifrost or 31)
210 -m, --min-length Length of minimizers (default is read from input graph file if built with Bifrost or 23)
211
212 > Optional with no argument:
213
214 -n, --inexact Graph is searched with exact and inexact k-mers (1 substitution or indel) from queries
215 -v, --verbose Print information messages during execution
216 ```
217
218 ### Examples
219
220 - **Build**
221
222 1. **Build a compacted de Bruijn graph from read files and clean the graph**
223 ```
224 Bifrost build -t 4 -k 31 -i -d -s A.fastq -s B.fastq -o AB_graph
225 ```
226 The compacted de Bruijn graph is built (`build`) with 4 threads (`-t 4`) from the 31-mers (`-k 31`) of files *A.fastq* and *B.fastq* (`-s A.fastq -s B.fastq`). By using parameter `-s`, files *A.fastq* and *B.fastq* are filtered: 31-mers occurring exactly once in *A* and *B* are discarded from the construction. Graph simplification steps are performed after building (`-i -d`) and the graph is written to file *AB_graph.gfa* (`-o AB_graph`).
227
228 2. **Build a compacted de Bruijn graph from a reference genome file**
229 ```
230 Bifrost build -t 4 -k 31 -r C.fasta -o C_graph
231 ```
232 The compacted de Bruijn graph is built (`build`) with 4 threads (`-t 4`) from the 31-mers (`-k 31`) of file *C.fasta* (`-r C.fasta`). By using parameter `-r`, file *C.fasta* is NOT filtered: all 31-mers occurring in *C* are used during the construction. The graph is written to file *C_graph.gfa* (`-o C_graph`).
233
234 3. **Build a compacted and colored de Bruijn graph from read files and reference genome files, clean the graph**
235 ```
236 Bifrost build -t 4 -k 31 -c -i -d -s A.fastq -s B.fastq -r C.fasta -o ABC
237 ```
238 Combining the two previous examples, the compacted de Bruijn graph is built (`build`) with 4 threads (`-t 4`) from the 31-mers (`-k 31`) of files *A.fastq*, *B.fastq* (`-s A.fastq -s B.fastq`) and file *C.fasta* (`-r C.fasta`). Graph simplification steps are performed after building (`-i -d`). The graph is colored (`-c`), meaning that each k-mer of the graph unitigs keeps track of whether it occurs in *A*, *B* or *C*. The graph is written to file *ABC.gfa* and the colors are written to file *ABC.bfg_colors* (`-o ABC`).
239
240 - **Update**
241
242 1. **Update a compacted de Bruijn graph with a reference genome file**
243 ```
244 Bifrost update -t 4 -r D.fasta -g C_graph.gfa -o CD_graph
245 ```
246 The compacted de Bruijn graph *C* (`-g C_graph.gfa`) is updated (`update`) with 4 threads (`-t 4`) from the *k*-mers of file *D.fasta* (`-r D.fasta`). By using parameter `-r`, file *D.fasta* is NOT filtered: all *k*-mers occurring in *D* are used during the merging. The graph is written to file *CD_graph.gfa* (`-o CD_graph`).
247
248 2. **Update a compacted and colored de Bruijn graph with read files and clean the graph**
249 ```
250 Bifrost update -t 4 -i -d -s E.fastq -s F.fastq -g ABC.gfa -f ABC.bfg_colors -o ABCEF
251 ```
252 The compacted and colored de Bruijn graph *ABC* (`-g ABC.gfa -f ABC.bfg_colors`) is updated (`update`) with 4 threads (`-t 4`) from the *k*-mers of files *E.fastq* and *F.fastq* (`-s E.fastq -s F.fastq`). Graph simplification steps are performed after merging (`-i -d`). The graph is written to file *ABCEF.gfa* and the colors are written to file *ABCEF.bfg_colors* (`-o ABCEF`).
253
254 - **Query**
255
256 1. **Query a compacted de Bruijn graph for presence/absence of queries in the graph**
257 ```
258 Bifrost query -t 4 -e 0.8 -g ABCEF.gfa -q queries.fasta -o presence_queries
259 ```
260 The compacted de Bruijn graph *ABCEF* (`-g ABCEF.gfa`) is queried (`query`) with 4 threads (`-t 4`) for the presence/absence of sequences from file *queries.fasta* (`-q queries.fasta`). At least 80% of each query *k*-mers must be found in the graph to have the query reported as present (`-e 0.8`). The results are stored in a binary matrix written to file *presence_queries.tsv* (`-o presence_queries`): rows are the queries, column is presence/absence in graph, intersection of a row and a column is a binary value indicating presence/absence of the query in graph (1 is present, 0 is not present).
261
262 2. **Query a compacted de Bruijn graph for presence/absence of queries in the graph in inexact mode**
263 ```
264 Bifrost query -t 4 -e 0.8 -n -g ABCEF.gfa -q queries.fasta -o presence_queries
265 ```
266 The compacted de Bruijn graph *ABCEF* (`-g ABCEF.gfa`) is queried (`query`) with 4 threads (`-t 4`) for the presence/absence of sequences from file *queries.fasta* (`-q queries.fasta`). At least 80% of each query *k*-mers must be found in the graph to have the query reported as present (`-e 0.8`). Queries are searched for exact and inexact *k*-mers (`-n`): *k*-mers with up to one substitution or indel. The results are stored in a binary matrix written to file *presence_queries.tsv* (`-o presence_queries`): rows are the queries, column is presence/absence in graph, intersection of a row and a column is a binary value indicating presence/absence of the query in graph (1 is present, 0 is not present).
267
268 3. **Query a colored and compacted de Bruijn graph for presence/absence of queries in each color of the graph**
269 ```
270 Bifrost query -t 4 -e 0.8 -g ABCEF.gfa -f ABCEF.bfg_colors -q queries.fasta -o presence_queries
271 ```
272 The compacted and colored de Bruijn graph *ABCEF* (`-g ABCEF.gfa -f ABCEF.bfg_colors`) is queried (`query`) with 4 threads (`-t 4`) for the sequences of file *queries.fasta* (`-q queries.fasta`). At least 80% of each query *k*-mers must be found in a color of the graph to have the query reported as present for that color (`-e 0.8`). The results are stored in a binary matrix written to file *presence_queries.tsv* (`-o presence_queries`): rows are the queries, columns are the colors, intersection of a row and a column is a binary value indicating presence/absence of the query in the color of the graph (1 is present, 0 is not present).
273
274 ## API
275
276 Changes in the API are reported in the [Changelog](https://github.com/pmelsted/bifrost/blob/master/Changelog.md).
277
278 ### Tutorial
279
280 The [API tutorial](doc/tutorial/Intro.md) should help you get started with the C++ API.
281
282 ### Documentation
283
284 Documentation for the Bifrost library is available in the */doc/doxygen* folder (HTML version, open *html/index.html*).
285
286 The following command regenerates the documentation:
287 ```
288 cd <bifrost_directory>
289 doxygen Doxyfile
290 ```
291
292 The documentation contains a description of all the functions and structures of the library.
293
294 ### Usage
295
296 The Bifrost C++ API can be used by adding
297 ```
298 #include <bifrost/CompactedDBG.hpp>
299 ```
300 for uncolored compacted de Bruijn graphs and
301 ```
302 #include <bifrost/ColoredCDBG.hpp>
303 ```
304 for colored compacted de Bruijn graphs in your C++ headers.
305
306 To compile, we recommend using the following compile flags:
307 ```
308 -O3 -std=c++11
309 ```
310 Furthermore, Bifrost compiles by default with flag `-march=native` so unless native compilation was disabled when installing Bifrost, use flag `-march=native` too.
311
312 Finally, use the following flags for linking:
313 ```
314 -lbifrost -pthread -lz
315 ```
316
317 You can also link to the Bifrost static library (*libbifrost.a*) for better performance:
318 ```
319 <path_to_lib_folder>/libbifrost.a -pthread -lz
320 ```
321
322 The default maximum *k*-mer size supported is 31. To work with larger *k*, the code using the Bifrost C++ API must be compiled and linked with the flag `-DMAX_KMER_SIZE=x` for compiling and linking where `x` is a larger multiple of 32, such as:
323 ```
324 -DMAX_KMER_SIZE=64
325 ```
326 Actual maximum k-mer size is *MAX_KMER_SIZE-1*, e.g maximum *k* is 63 for *MAX_KMER_SIZE=64*. Increasing *MAX_KMER_SIZE* increases Bifrost memory usage (*k*=31 uses 8 bytes of memory per *k*-mer while *k*=63 uses 16 bytes of memory per *k*-mer).
327
328 ## FAQ
329
330 **Can I provide in input multiple files?**
331
332 Yes, use parameter `-r` or `-s` for each file to input.
333
334 **Can I provide in input a file which is a list of files?**
335
336 Yes, a text file containing one input filename per line with no empty lines can be given in input.
337
338 **What are the accepted input file formats?**
339
340 FASTA, FASTQ and GFA. Input FASTA and FASTQ files can be compressed with gzip (extension .gz). If you input a GFA file for the construction, you probably want to use the `-r` parameter for that file.
341
342 **Can I mix different file formats in input?**
343
344 Yes, as long as they are FASTA, FASTQ and GFA.
345
346 **If I input a GFA file for building the de Bruijn graph, does it need to contain an already compacted de Bruijn graph?**
347
348 No, it can contain any type of sequence graph (like an uncompacted de Bruijn graph or a sequence graph).
349
350 **Can I build a compacted (colored) de Bruijn graph from assembled genomes and reads?**
351
352 Yes. Input your assembled genomes with parameter `-r` and your reads with parameter `-s`.
353
354 **Can I use the graph file without its color file ?**
355
356 Yes. Just do not input the color file and Bifrost will consider it is an **un**colored compacted de Bruijn graph.
357
358 **In which order are inserted the colors?**
359
360 A color corresponds to an input file the graph was built/updated from. The order in which the colors are inserted is the same as the order of the files given by parameter `-r` and parameter `-s`. However, in case both parameters `-r` and `-s` are used, no assumption can be made on whether the files given by parameter `-s` will be inserted before or after the ones given by parameter `-r`.
361
362 **Different runs of Bifrost on the same dataset with the same parameters produces graphs with different unitigs. Which graph is correct?**
363
364 All of them. The difference between the graphs resides in circular unitigs (unitigs connecting to themselves) which are their own connected components ("isolated"). These unitigs can have a different sequence from one run to another because the starting position will be different, yet they represent exactly the same sequence. As an example, circular unitig ATAT composed of 3-mers can also be represented with sequence TATA. The number of unitigs will remain the same from one graph to another.
365
366 ## Troubleshooting
367
368 * compilation (`make`) fails because some header files (*.h*) are not found
369
370 Assuming the header files (*.h*) are located at the path */usr/local/include/*, the following command set the environment variables *C_INCLUDE_PATH* and *CPLUS_INCLUDE_PATH* correctly for the time of the session:
371 ```
372 export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include/
373 export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/
374 ```
375
376 * executing the binary of Bifrost fails because *libbifrost.so* or *libbifrost.a* is not found
377
378 Assuming that *libbifrost*.(*so*|*dylib*|*a*) is located at the path */usr/local/lib/*, the following command set the environment variables *LD_LIBRARY_PATH*, *LIBRARY_PATH* and *PATH* correctly for the time of the session:
379 ```
380 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
381 export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib/
382 export PATH=$PATH:/usr/local/lib/
383 ```
384
385 * Bifrost crashes right at the beginning with error `Illegal instruction`
386
387 You are most likely running Bifrost on a different machine than the one used to compile it. By default, Bifrost is compiled in native mode such to target architecture instructions specific to the machine it is compiled on. Using Bifrost on a different machine with a different architecture might result in this error. To solve this issue, Bifrost must be recompiled with native architecture compilation disabled, as explained in the Advanced options of Section [Installation](#installation).
388
389 ## Citation
390
391 ```
392 @article {holley2019bifrost,
393 author = {Holley, Guillaume and Melsted, P{\'a}ll},
394 title = "{Bifrost - Highly parallel construction and indexing of colored and compacted de Bruijn graphs}",
395 elocation-id = {695338},
396 doi = {10.1101/695338},
397 journal = {bioRxiv},
398 year = {2019}
399 }
400 ```
401
402 ## Contact
403
404 For any question, feedback or problem, please feel free to file an issue on this GitHub repository and we will get back to you as soon as possible.
405
406 ## License
407
408 * Bifrost is BSD2 licensed (https://github.com/pmelsted/bifrost/blob/master/LICENSE)
409 * The wyhash library is Unlicense licensed (https://github.com/wangyi-fudan/wyhash)
410 * The popcount library is BSD licensed (https://github.com/kimwalisch/libpopcnt)
411 * The libdivide library is zlib licensed (https://github.com/ridiculousfish/libdivide)
412 * The kseq library is copyrighted by Heng Li and released under the MIT license (http://lh3lh3.users.sourceforge.net/kseq.shtml)
413 * The CRoaring library is Apache 2.0 licensed (https://github.com/RoaringBitmap/CRoaring)
414 * The zstr library is MIT licensed (https://github.com/mateidavid/zstr)
415 * The GetRSS library is Creative Commons Attribution 3.0 licensed