[med-svn] [kraken] 01/05: New upstream version 1.1

Andreas Tille tille at debian.org
Mon Feb 5 08:55:08 UTC 2018


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository kraken.

commit db23a364ea207e6f03ebe16480f24c3e86a8c788
Author: Andreas Tille <tille at debian.org>
Date:   Mon Feb 5 09:49:07 2018 +0100

    New upstream version 1.1
---
 CHANGELOG                  |  10 +++
 docs/MANUAL.html           | 218 +++++++++++++++++++++++++--------------------
 scripts/kraken             |  17 +++-
 scripts/read_merger.pl     |  59 +++++++++---
 scripts/rsync_from_ncbi.pl |   2 +-
 src/classify.cpp           | 200 ++++++++++++++++++++++++++++++++++++-----
 6 files changed, 374 insertions(+), 132 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index c1aaed1..e571f8d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,13 @@
+v1.1:
+* added --out-fmt paired and --out-fmt interleaved to allow paired reads
+  to be separated when using --[un]classified-out options
+* updated MANUAL.html to reflect additional options. 
+
+v1.0:
+* removed dependence on GI numbers
+* using taxonomy nucl_*.accession2taxid maps to create seqid2taxid maps
+* changed kraken-build --download method to use rsync
+
 v0.10.6-beta:
 * fixed overflow bug in command line parsing
 * fixed GRCh38.p2 bug in human genome downloads
diff --git a/docs/MANUAL.html b/docs/MANUAL.html
index 4ac90d2..642fa38 100644
--- a/docs/MANUAL.html
+++ b/docs/MANUAL.html
@@ -4,7 +4,7 @@
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <meta http-equiv="Content-Style-Type" content="text/css" />
   <meta name="generator" content="pandoc" />
-  <title>Kraken Manual – </title>
+  <title>Kraken Manual - </title>
   <style type="text/css">code{white-space: pre;}</style>
   <link rel="stylesheet" href="kraken.css" type="text/css" />
   <link href='http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic' rel='stylesheet' type='text/css'>
@@ -26,33 +26,35 @@
 <li><a href="#installation">Installation</a></li>
 <li><a href="#kraken-databases">Kraken Databases</a></li>
 <li><a href="#standard-kraken-database">Standard Kraken Database</a></li>
+<li><a href="#custom-databases">Custom Databases</a></li>
 <li><a href="#classification">Classification</a></li>
 <li><a href="#output-format">Output Format</a></li>
-<li><a href="#custom-databases">Custom Databases</a></li>
+<li><a href="#paired-reads">Paired Reads</a></li>
 <li><a href="#memory-usage-and-efficiency">Memory Usage and Efficiency</a></li>
 <li><a href="#sample-reports">Sample Reports</a></li>
 <li><a href="#confidence-scoring">Confidence Scoring</a></li>
 <li><a href="#kraken-environment-variables">Kraken Environment Variables</a></li>
 <li><a href="#upgrading-databases-to-v0.10">Upgrading Databases to v0.10+</a></li>
+<li><a href="#upgrading-databases-to-v1.0">Upgrading Databases to v1.0</a></li>
 </ul>
 </div>
-<h1 id="introduction">Introduction</h1>
-<p><a href="http://ccb.jhu.edu/software/kraken/">Kraken</a> is a taxonomic sequence classifier that assigns taxonomic labels to short DNA reads. It does this by examining the <span class="math inline"><em>k</em></span>-mers within a read and querying a database with those <span class="math inline"><em>k</em></span>-mers. This database contains a mapping of every <span class="math inline"><em>k</em></span>-mer in <a href="http://ccb.jhu.edu/software/kraken/">Kraken</a>'s genomic library t [...]
+<h1 id="introduction"><a href="#introduction">Introduction</a></h1>
+<p><a href="http://ccb.jhu.edu/software/kraken/">Kraken</a> is a taxonomic sequence classifier that assigns taxonomic labels to short DNA reads. It does this by examining the <span class="math"><em>k</em></span>-mers within a read and querying a database with those <span class="math"><em>k</em></span>-mers. This database contains a mapping of every <span class="math"><em>k</em></span>-mer in <a href="http://ccb.jhu.edu/software/kraken/">Kraken</a>'s genomic library to the lowest common a [...]
 <p>The latest released version of Kraken will be available at the <a href="http://ccb.jhu.edu/software/kraken/">Kraken website</a>, and the latest updates to the Kraken source code are available at the <a href="https://github.com/DerrickWood/kraken">Kraken GitHub repository</a>.</p>
 <p>If you use <a href="http://ccb.jhu.edu/software/kraken/">Kraken</a> in your research, please cite the <a href="http://genomebiology.com/2014/15/3/R46">Kraken paper</a>. Thank you!</p>
-<h1 id="system-requirements">System Requirements</h1>
+<h1 id="system-requirements"><a href="#system-requirements">System Requirements</a></h1>
 <p>Note: Users concerned about the disk or memory requirements should read the paragraph about MiniKraken, below.</p>
 <ul>
-<li><p><strong>Disk space</strong>: Construction of Kraken's standard database will require at least 500 GB of disk space. Customized databases may require more or less space. Disk space used is linearly proportional to the number of distinct <span class="math inline"><em>k</em></span>-mers; as of Oct. 2017, Kraken's default database contains just over 14.4 billion (1.44e10) distinct <span class="math inline"><em>k</em></span>-mers.</p>
+<li><p><strong>Disk space</strong>: Construction of Kraken's standard database will require at least 500 GB of disk space as of Oct. 2017. Customized databases may require more or less space. After construction, the minimum required database files require approximately 200 GB of disk space. Disk space used is linearly proportional to the number of distinct <span class="math"><em>k</em></span>-mers; as of Oct. 2017, Kraken's default database contains approximately 14 billion (1.4e9) disti [...]
 <p>In addition, the disk used to store the database should be locally-attached storage. Storing the database on a network filesystem (NFS) partition can cause Kraken's operation to be very slow, or to be stopped completely. As NFS accesses are much slower than local disk accesses, both preloading and database building will be slowed by use of NFS.</p></li>
-<li><p><strong>Memory</strong>: To run efficiently, Kraken requires enough free memory to hold the database in RAM. While this can be accomplished using a ramdisk, Kraken supplies a utility for loading the database into RAM via the OS cache. The default database size is 170 GB (as of Oct. 2017), and so you will need at least that much RAM if you want to build or run with the default database.</p></li>
+<li><p><strong>Memory</strong>: To run efficiently, Kraken requires enough free memory to hold the database in RAM. While this can be accomplished using a ramdisk, Kraken supplies a utility for loading the database into RAM via the OS cache. The default database size is 174 GB (as of Oct. 2017), and so you will need at least that much RAM if you want to build or run with the default database.</p></li>
 <li><p><strong>Dependencies</strong>: Kraken currently makes extensive use of Linux utilities such as sed, find, and wget. Many scripts are written using the Bash shell, and the main scripts are written using Perl. Core programs needed to build the database and run the classifier are written in C++, and need to be compiled using g++. Multithreading is handled using OpenMP. Downloads of NCBI data are performed by wget and in some cases, by rsync. Most Linux systems that have any sort of d [...]
-<p>Finally, if you want to build your own database, you will need to install the <a href="http://www.cbcb.umd.edu/software/jellyfish/">Jellyfish</a> <span class="math inline"><em>k</em></span>-mer counter. Note that Kraken only supports use of Jellyfish version 1. Jellyfish version 2 is not yet compatible with Kraken.</p></li>
+<p>Finally, if you want to build your own database, you will need to install the <a href="http://www.cbcb.umd.edu/software/jellyfish/">Jellyfish</a> <span class="math"><em>k</em></span>-mer counter. Note that Kraken only supports use of Jellyfish version 1. Jellyfish version 2 is not compatible with Kraken.</p></li>
 <li><p><strong>Network connectivity</strong>: Kraken's standard database build and download commands expect unfettered FTP and rsync access to the NCBI FTP server. If you're working behind a proxy, you may need to set certain environment variables (such as <code>ftp_proxy</code> or <code>RSYNC_PROXY</code>) in order to get these commands to work properly.</p></li>
 <li><p><strong>MiniKraken</strong>: To allow users with low-memory computing environments to use Kraken, we supply a reduced standard database that can be downloaded from the Kraken web site. When Kraken is run with a reduced database, we call it MiniKraken.</p>
-<p>The database we make available is only 4 GB in size, and should run well on computers with as little as 8 GB of RAM. Disk space required for this database is also only 4 GB.</p></li>
+<p>The databases we make available are only 4 GB and 8 GB in size, and should run well on computers with as little as 8 GB and 16 GB of RAM (respectively). Disk space required for each MiniKraken database is also only 4 GB or 8 GB.</p></li>
 </ul>
-<h1 id="installation">Installation</h1>
+<h1 id="installation"><a href="#installation">Installation</a></h1>
 <p>To begin using Kraken, you will first need to install it, and then either download or create a database.</p>
 <p>Kraken consists of two main scripts ("<code>kraken</code>" and "<code>kraken-build</code>"), along with several programs and smaller scripts. As part of the installation process, all scripts and programs are installed in the same directory. After installation, you can move the main scripts elsewhere, but moving the other scripts and programs requires editing the scripts and changing the "<code>$KRAKEN_DIR</code>" variables.</p>
 <p>Once a directory is selected, you need to run the following command in the directory where you extracted the Kraken source:</p>
@@ -63,40 +65,100 @@
 <pre><code>cp $KRAKEN_DIR/bin/kraken $HOME/bin
 cp $KRAKEN_DIR/bin/kraken-build $HOME/bin</code></pre>
 <p>After installation, you're ready to either create or download a database.</p>
-<h1 id="kraken-databases">Kraken Databases</h1>
+<h1 id="kraken-databases"><a href="#kraken-databases">Kraken Databases</a></h1>
 <p>A Kraken database is a directory containing at least 4 files:</p>
 <ul>
-<li><code>database.kdb</code>: Contains the <span class="math inline"><em>k</em></span>-mer to taxon mappings</li>
+<li><code>database.kdb</code>: Contains the <span class="math"><em>k</em></span>-mer to taxon mappings</li>
 <li><code>database.idx</code>: Contains minimizer offset locations in database.kdb</li>
 <li><code>taxonomy/nodes.dmp</code>: Taxonomy tree structure + ranks</li>
 <li><code>taxonomy/names.dmp</code>: Taxonomy names</li>
 </ul>
 <p>Other files may be present as part of the database build process.</p>
 <p>In interacting with Kraken, you should not have to directly reference any of these files, but rather simply provide the name of the directory in which they are stored. Kraken allows both the use of a standard database as well as custom databases; these are described in the sections <a href="#standard-kraken-database">Standard Kraken Database</a> and <a href="#custom-databases">Custom Databases</a> below, respectively.</p>
-<h1 id="standard-kraken-database">Standard Kraken Database</h1>
+
+<h1 id="standard-kraken-database"><a href="#standard-kraken-database">Standard Kraken Database</a></h1>
+<p>NOTE: Building the standard Kraken database downloads and uses all complete bacterial, archeal, and viral genomes in Refseq at the time of the build. 
+As of October 2017, this includes ~25,000 genomes, requiring 33GB of disk space. 
+The build process will then require approximately 450GB of additional disk space. 
+After building the standard database, usage of the database will require users to keep only the database.idx, database.kdb, and taxonomy/ files, which requires approximately 200GB of disk space. When running a sample against this database, users will need 175 GB of RAM. 
+If you do not have this computational resources or require testing against this Refseq database of ~25,000 genomes, we recommend building a custom database with only the genomes needed for your application. </p> 
 <p>To create the standard Kraken database, you can use the following command:</p>
 <pre><code>kraken-build --standard --db $DBNAME</code></pre>
-<p>(Replace "<code>$DBNAME</code>" above with your preferred database name/location. Please note that the database will use approximately 500 GB of disk space during creation.)</p>
+<p>(Replace "<code>$DBNAME</code>" above with your preferred database name/location.)</p>
 <p>This will download NCBI taxonomic information, as well as the complete genomes in RefSeq for the bacterial, archaeal, and viral domains. After downloading all this data, the build process begins; this is the most time-consuming step. If you have multiple processing cores, you can run this process with multiple threads, e.g.:</p>
 <pre><code>kraken-build --standard --threads 24 --db $DBNAME</code></pre>
-<p>Using 24 threads on a computer (an AWS r4.8xlarge instance) with 244 GB of RAM, the build process took approximately 5 hours (steps with an asterisk have some multi-threading enabled) in October 2017:</p>
-<pre><code> 24m50s  *Step 1 (create set)
-    n/a   Step 2 (reduce database, optional and skipped)
-154m53s  *Step 3 (sort set)
-    n/a   Step 4 (GI number to sequence ID map - now obsolete)
-    <1s   Step 5 (Sequence ID to taxon map)
-127m28s  *Step 6 (set LCA values)
--------
-5h7m11s   Total build time</code></pre>
-<p>This process used the automatically estimated jellyfish hash size of 20170976000.</p>
+<p>Using 24 threads on a computer with 244 GB of RAM, the build process took approximately 5 hours (steps with an asterisk have some multi-threading enabled) in October 2017. Please note that the time required for building the database depends on the number of genomic sequences:</p>
+<pre><code> 
+  24m50s  *Step 1 (create kmer set)
+     n/a  Step 2 (reduce database, optional and skipped)
+2h34m53s  *Step 3 (sort set)
+     n/a  Step 4 (GI number to sequence ID map)
+   0.17s  Step 5 (Sequence ID to taxon map)
+ 2h7m28s  *Step 6 (set LCA values)
+--------
+ 5h7m11s  Total build time</code></pre>
 <p>Note that if any step (including the initial downloads) fails, the build process will abort. However, <code>kraken-build</code> will produce checkpoints throughout the installation process, and will restart the build at the last incomplete step if you attempt to run the same command again on a partially-built database.</p>
+<p>After building the database, to remove any unnecessary files (including the library files no longer needed), run the following:</p>
+<pre><code>kraken-build --db $DBNAME --clean</code></pre>
 <p>To create a custom database, or to use a database from another source, see <a href="#custom-databases">Custom Databases</a>.</p>
 <p>Notes for users with lower amounts of RAM:</p>
 <ol style="list-style-type: decimal">
 <li><p>If you encounter problems with Jellyfish not being able to allocate enough memory on your system to run the build process, you can supply a smaller hash size to Jellyfish using <code>kraken-build</code>'s <code>--jellyfish-hash-size</code> switch. Each space in the hash table uses approximately 6.9 bytes, so using "<code>--jellyfish-hash-size 6400M</code>" will use a hash table size of 6.4 billion spaces and require 44.3 GB of RAM.</p></li>
 <li><p>Kraken's build process will normally attempt to minimize disk writing by allocating large blocks of RAM and operating within them until data needs to be written to disk. However, this extra RAM usage may exceed your capacity. In such cases, you may want to use <code>kraken-build</code>'s <code>--work-on-disk</code> switch. This will minimize the amount of RAM usage and cause Kraken's build programs to perform most operations off of disk files. This switch can also be useful for pe [...]
 </ol>
-<h1 id="classification">Classification</h1>
+<h1 id="custom-databases"><a href="#custom-databases">Custom Databases</a></h1>
+<p>We realize the standard database may not suit everyone's needs. Kraken also allows creation of customized databases.</p>
+<p>To build a custom database:</p>
+<ol style="list-style-type: decimal">
+<li><p>Install a taxonomy. Usually, you will just use the NCBI taxonomy, which you can easily download using:</p>
+<pre><code>kraken-build --download-taxonomy --db $DBNAME</code></pre>
+<p>This will download the sequence ID to taxon map, as well as the taxonomic name and tree information from NCBI. These files can be found in <code>$DBNAME/taxonomy/</code> . If you need to modify the taxonomy, edits can be made to the <code>names.dmp</code> and <code>nodes.dmp</code> files in this directory; the <code>gi_taxid_nucl.dmp</code> file will also need to be updated appropriately.</p></li>
+<li><p>Install a genomic library. Four sets of standard genomes are made easily available through <code>kraken-build</code>:</p>
+<ul>
+<li>bacteria: RefSeq complete bacterial/archaeal genomes</li>
+<li>plasmids: RefSeq plasmid sequences</li>
+<li>viruses: RefSeq complete viral genomes</li>
+<li>human: GRCh38 human genome</li>
+</ul>
+<p>To download and install any one of these, use the <code>--download-library</code> switch, e.g.:</p>
+<pre><code>kraken-build --download-library bacteria --db $DBNAME</code></pre>
+<p>Other genomes in a FASTA/multi-FASTA file can also be added:
+<ul>
+<li>If downloaded from NCBI, the genomes can be added directly using the <code>--add-to-library</code> switch, e.g.:</p>
+<pre><code>kraken-build --add-to-library chr1.fa --db $DBNAME
+kraken-build --add-to-library chr2.fa --db $DBNAME</code></pre>
+</li>
+ 
+Note that if you have a list of files to add, you can do something like this in <code>bash</code>:
+<pre><code>for file in chr*.fa
+do
+    kraken-build --add-to-library $file --db $DBNAME
+done</code></pre>
+Or even add all <code>*.fa</code> files found in the directory <code>genomes</code>:
+<pre><code>find genomes/ -name '*.fa' -print0 | \
+    xargs -0 -I{} -n1 kraken-build --add-to-library {} --db $DBNAME</code></pre>
+(You may also find the <code>-P</code> option to <code>xargs</code> useful to add many files in parallel if you have multiple processors.)
+<br><br></li>
+<li>Replicons not downloaded from NCBI may need their taxonomy information assigned explicitly. This can be done using the string <code>kraken:taxid|XXX</code> in the sequence ID, with <code>XXX</code> replaced by the desired taxon ID. For example, to put a known adapter sequence in taxon 32630 ("synthetic construct"), you could use the following:
+<pre><code>>sequence16|kraken:taxid|32630  Adapter sequence
+CAAGCAGAAGACGGCATACGAGATCTTCGAGTGACTGGAGTTCCTTGGCACCCGAGAATTCCA</code></pre>
+<p>The <code>kraken:taxid</code> string must begin the sequence ID or be immediately preceded by a pipe character (<code>|</code>). 
+Explicit assignment of taxonomy IDs in this manner will override the sequence ID mapping provided by NCBI.</p>
+</li></ul>
+<li><p>Once your library is finalized, you need to build the database. Depending on your size requirements, you may want to adjust the <span class="math"><em>k</em></span>-mer and/or minimizer lengths from the defaults. Except for some small bookkeeping fields, a Kraken database will use <span class="math"><em>s</em><em>D</em></span> + <span class="math">8(4<sup><em>M</em></sup>)</span> bytes, where <span class="math"><em>s</em></span> is the number of bytes used to store the <span class [...]
+<p>The minimizers serve to keep <span class="math"><em>k</em></span>-mers that are adjacent in query sequences close to each other in the database, which allows Kraken to exploit the CPU cache. Changing the value of <span class="math"><em>M</em></span> can significantly affect the speed of Kraken, and neither increasing or decreasing <span class="math"><em>M</em></span> will guarantee faster or slower speed.</p>
+<p>To build the database, you'll use the <code>--build</code> switch:</p>
+<pre><code>kraken-build --build --db $DBNAME</code></pre>
+<p>As noted above, you may want to also use any of <code>--threads</code>, <code>--kmer-len</code>, or <code>--minimizer-len</code> to adjust the database build time and/or final size.</p></li>
+<li><p>Shrinking the database: The "--shrink" task allows you to take an existing Kraken database and create a smaller MiniKraken database from it. The use of this option removes all but a specified number of <span class="math"><em>k</em></span>-mer/taxon pairs to create a new, smaller database. For example:</p>
+<pre><code>kraken-build --shrink 10000 --db $DBNAME --new-db minikraken</code></pre>
+<p>This will create a new database named <code>minikraken</code> that contains 10000 <span class="math"><em>k</em></span>-mers selected from across the original database (<code>$DBNAME</code>).</p>
+<p>The <code>--shrink</code> task is only meant to be run on a completed database. However, if you know before you create a database that you will only be able to use a certain amount of memory, you can use the <code>--max-db-size</code> switch for the <code>--build</code> task to provide a maximum size (in GB) for the database. This allows you to create a MiniKraken database without having to create a full Kraken database first.</p></li>
+</ol>
+<p>A full list of options for <code>kraken-build</code> can be obtained using <code>kraken-build --help</code>.</p>
+<p>After building a database, if you want to reduce the disk usage of the database you can use <code>kraken-build</code>'s <code>--clean</code> switch to remove all intermediate files from the database directory.</p>
+
+<h1 id="classification"><a href="#classification">Classification</a></h1>
 <p>To classify a set of sequences (reads), use the <code>kraken</code> command:</p>
 <pre><code>kraken --db $DBNAME seqs.fa</code></pre>
 <p>Output will be sent to standard output by default. The files containing the sequences to be classified should be specified on the command line. Sequences can also be provided through standard input using the special filename <code>/dev/fd/0</code>.</p>
@@ -106,29 +168,30 @@ cp $KRAKEN_DIR/bin/kraken-build $HOME/bin</code></pre>
 <p>The <code>kraken</code> program allows several different options:</p>
 <ul>
 <li><p><strong>Multithreading</strong>: Use the <code>--threads NUM</code> switch to use multiple threads.</p></li>
-<li><p><strong>Quick operation</strong>: Rather than searching all <span class="math inline"><em>k</em></span>-mers in a sequence, stop classification after the first database hit; use <code>--quick</code> to enable this mode. Note that <code>--min-hits</code> will allow you to require multiple hits before declaring a sequence classified, which can be especially useful with custom databases when testing to see if sequences either do or do not belong to a particular genome.</p></li>
+<li><p><strong>Quick operation</strong>: Rather than searching all <span class="math"><em>k</em></span>-mers in a sequence, stop classification after the first database hit; use <code>--quick</code> to enable this mode. Note that <code>--min-hits</code> will allow you to require multiple hits before declaring a sequence classified, which can be especially useful with custom databases when testing to see if sequences either do or do not belong to a particular genome.</p></li>
 <li><p><strong>Sequence filtering</strong>: Classified or unclassified sequences can be sent to a file for later processing, using the <code>--classified-out</code> and <code>--unclassified-out</code> switches, respectively.</p></li>
 <li><p><strong>Output redirection</strong>: Output can be directed using standard shell redirection (<code>|</code> or <code>></code>), or using the <code>--output</code> switch.</p></li>
 <li><p><strong>FASTQ input</strong>: Input is normally expected to be in FASTA format, but you can classify FASTQ data using the <code>--fastq-input</code> switch.</p></li>
 <li><p><strong>Compressed input</strong>: Kraken can handle gzip and bzip2 compressed files as input by specifying the proper switch of <code>--gzip-compressed</code> or <code>--bzip2-compressed</code>.</p></li>
 <li><p><strong>Input format auto-detection</strong>: If regular files are specified on the command line as input, Kraken will attempt to determine the format of your input prior to classification. You can disable this by explicitly specifying <code>--fasta-input</code>, <code>--fastq-input</code>, <code>--gzip-compressed</code>, and/or <code>--bzip2-compressed</code> as appropriate. Note that use of the character device file <code>/dev/fd/0</code> to read from standard input (aka <code>s [...]
-<li><p><strong>Paired reads</strong>: Kraken does not query <span class="math inline"><em>k</em></span>-mers containing ambiguous nucleotides (non-ACGT). If you have paired reads, you can use this fact to your advantage and increase Kraken's accuracy by concatenating the pairs together with a single <code>N</code> between the sequences. Using the <code>--paired</code> option when running <code>kraken</code> will automatically do this for you; simply specify the two mate pair files on the [...]
+<li><p><strong>Paired reads</strong>: Kraken does not query <span class="math"><em>k</em></span>-mers containing ambiguous nucleotides (non-ACGT). If you have paired reads, you can use this fact to your advantage and increase Kraken's accuracy by concatenating the pairs together with a single <code>N</code> between the sequences. Using the <code>--paired</code> option when running <code>kraken</code> will automatically do this for you; simply specify the two mate pair files on the comman [...]
 </ul>
 <p>To get a full list of options, use <code>kraken --help</code>.</p>
-<h1 id="output-format">Output Format</h1>
+
+<h1 id="output-format"><a href="#output-format">Output Format</a></h1>
 <p>Each sequence classified by Kraken results in a single line of output. Output lines contain five tab-delimited fields; from left to right, they are:</p>
 <ol style="list-style-type: decimal">
 <li>"C"/"U": one letter code indicating that the sequence was either classified or unclassified.</li>
 <li>The sequence ID, obtained from the FASTA/FASTQ header.</li>
 <li>The taxonomy ID Kraken used to label the sequence; this is 0 if the sequence is unclassified.</li>
 <li>The length of the sequence in bp.</li>
-<li>A space-delimited list indicating the LCA mapping of each <span class="math inline"><em>k</em></span>-mer in the sequence. For example, "562:13 561:4 A:31 0:1 562:3" would indicate that:
+<li>A space-delimited list indicating the LCA mapping of each <span class="math"><em>k</em></span>-mer in the sequence. For example, "562:13 561:4 A:31 0:1 562:3" would indicate that:
 <ul>
-<li>the first 13 <span class="math inline"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
-<li>the next 4 <span class="math inline"><em>k</em></span>-mers mapped to taxonomy ID #561</li>
-<li>the next 31 <span class="math inline"><em>k</em></span>-mers contained an ambiguous nucleotide</li>
-<li>the next <span class="math inline"><em>k</em></span>-mer was not in the database</li>
-<li>the last 3 <span class="math inline"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
+<li>the first 13 <span class="math"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
+<li>the next 4 <span class="math"><em>k</em></span>-mers mapped to taxonomy ID #561</li>
+<li>the next 31 <span class="math"><em>k</em></span>-mers contained an ambiguous nucleotide</li>
+<li>the next <span class="math"><em>k</em></span>-mer was not in the database</li>
+<li>the last 3 <span class="math"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
 </ul></li>
 </ol>
 <p>For users who want the full taxonomic name associated with each input sequence, we provide a script named <code>kraken-translate</code> that produces two different output formats for classified sequences. The script operates on the output of <code>kraken</code>, like so:</p>
@@ -142,57 +205,20 @@ kraken-translate --db $DBNAME sequences.kraken > sequences.labels</code></pre
 <p>Alternatively, <code>kraken-translate</code> accepts the option <code>--mpa-format</code> which will report only levels of the taxonomy with standard rank assignments (superkingdom, kingdom, phylum, class, order, family, genus, species), and uses pipes to delimit the various levels of the taxonomy. For example, <code>kraken-translate --mpa-format --db $DBNAME</code> with the above example output from <code>kraken</code> would result in the following line of output:</p>
 <pre><code>SEQ1  d__Bacteria|p__Proteobacteria|c__Gammaproteobacteria|o__Enterobacteriales|f__Enterobacteriaceae|g__Escherichia|s__Escherichia_coli</code></pre>
 <p>Taxonomy assignments above the superkingdom (<code>d__</code>) rank are represented as just "root" when using the <code>--mpa-report</code> option with <code>kraken-translate</code>.</p>
-<h1 id="custom-databases">Custom Databases</h1>
-<p>We realize the standard database may not suit everyone's needs. Kraken also allows creation of customized databases.</p>
-<p>To build a custom database:</p>
-<ol style="list-style-type: decimal">
-<li><p>Install a taxonomy. Usually, you will just use the NCBI taxonomy, which you can easily download using:</p>
-<pre><code>kraken-build --download-taxonomy --db $DBNAME</code></pre>
-<p>This will download the accession number to taxon map, as well as the taxonomic name and tree information from NCBI. These files can be found in <code>$DBNAME/taxonomy/</code> . If you need to modify the taxonomy, edits can be made to the <code>names.dmp</code> and <code>nodes.dmp</code> files in this directory; the <code>gi_taxid_nucl.dmp</code> file will also need to be updated appropriately.</p></li>
-<li><p>Install a genomic library. Four sets of standard genomes are made easily available through <code>kraken-build</code>:</p>
-<ul>
-<li>archaea: RefSeq complete archaeal genomes</li>
-<li>bacteria: RefSeq complete bacterial genomes</li>
-<li>plasmid: RefSeq plasmid sequences</li>
-<li>viral: RefSeq complete viral genomes</li>
-<li>human: GRCh38 human genome</li>
-</ul>
-<p>To download and install any one of these, use the <code>--download-library</code> switch, e.g.:</p>
-<pre><code>kraken-build --download-library bacteria --db $DBNAME</code></pre>
-Other genomes can also be added, but such genomes must meet certain requirements:
+
+<h1 id="paired-reads"><a href="#paired-reads">Paired Reads</a></h1>
+<p>Kraken will classify paired reads when the user specifies the <code>--paired</code> option by first concatenating the reads using <code>|</code> before classifying the combined reads against the Kraken database. </p>
+<p>A number of other options are included in Kraken v1.0 that simplifies analysis of the paired reads. The following describes these options and lists the possible combinations of these options and their behavior when applied. Note that all options require that the <code>--paired</code> option is specified and that two input FASTA/FASTQ files are provided.</p>
 <ul>
-<li>Sequences must be in a FASTA file (multi-FASTA is allowed)</li>
-<li>Each sequence's ID (the string between the <code>></code> and the first whitespace character on the header line) must contain either an NCBI accession number to allow Kraken to lookup the correct taxa, or an explicit assignment of the taxonomy ID using <code>kraken:taxid</code> (see below).</li>
+<li><p><code>--out-fmt legacy</code>: [default] uses <code>N</code> as the sequence delimiter if classified/unclassified reads are printed using the <code>--classified-out</code> or <code>--unclassified-out</code> tags. <code>--out-fmt legacy</code> does not currently support FASTQ output.</p></li>
+<li><p><code>--out-fmt legacy --classified-out C_reads.fa</code>: prints classified paired reads with <code>N</code> concatenating the two paired reads. </p></li>
+<li><p><code>--out-fmt paired</code>: separates paired sequences into two separate FASTA files when using <code>--classified-out</code> or <code>--unclassified-out</code> tags.</p></li>
+<li><p><code>--out-fmt paired --fastq-output</code>: separates paired sequences into two separate FASTQ files when using <code>--classified-out</code> or <code>--unclassified-out</code> tags. FASTQ headers will include everything up to the second whitespace character in the original FASTQ header.</p></li>
+<li><p><code>--out-fmt paired --classified-out C_reads</code>: prints classified paired reads to FASTA files <code>C_reads_R1.fa</code> and <code>C_reads_R2.fa</code></p></li>
+<li><p><code>--out-fmt interleaved</code>: prints paired sequences to a single FASTA file without concatenating the paired reads; paired reads are instead printed one after another. </p></li>
 </ul>
-<p>Replicons not downloaded from NCBI may need their taxonomy information assigned explicitly. This can be done using the string <code>kraken:taxid|XXX</code> in the sequence ID, with <code>XXX</code> replaced by the desired taxon ID. For example, to put a known adapter sequence in taxon 32630 ("synthetic construct"), you could use the following:</p>
-<pre><code>>sequence16|kraken:taxid|32630  Adapter sequence
-CAAGCAGAAGACGGCATACGAGATCTTCGAGTGACTGGAGTTCCTTGGCACCCGAGAATTCCA</code></pre>
-<p>The <code>kraken:taxid</code> string must begin the sequence ID or be immediately preceded by a pipe character (<code>|</code>). Explicit assignment of taxonomy IDs in this manner will override the accession number mapping provided by NCBI.</p>
-<p>If your genomes meet the requirements above, then you can add each replicon to your database's genomic library using the <code>--add-to-library</code> switch, e.g.:</p>
-<pre><code>kraken-build --add-to-library chr1.fa --db $DBNAME
-kraken-build --add-to-library chr2.fa --db $DBNAME</code></pre>
-<p>Note that if you have a list of files to add, you can do something like this in <code>bash</code>:</p>
-<pre><code>for file in chr*.fa
-do
-    kraken-build --add-to-library $file --db $DBNAME
-done</code></pre>
-<p>Or even add all <code>*.fa</code> files found in the directory <code>genomes</code>:</p>
-<pre><code>find genomes/ -name '*.fa' -print0 | \
-    xargs -0 -I{} -n1 kraken-build --add-to-library {} --db $DBNAME</code></pre>
-<p>(You may also find the <code>-P</code> option to <code>xargs</code> useful to add many files in parallel if you have multiple processors.)</p></li>
-<li><p>Once your library is finalized, you need to build the database. Depending on your size requirements, you may want to adjust the <span class="math inline"><em>k</em></span>-mer and/or minimizer lengths from the defaults. Except for some small bookkeeping fields, a Kraken database will use <span class="math inline"><em>s</em><em>D</em></span> + <span class="math inline">8(4<sup><em>M</em></sup>)</span> bytes, where <span class="math inline"><em>s</em></span> is the number of bytes u [...]
-<p>The minimizers serve to keep <span class="math inline"><em>k</em></span>-mers that are adjacent in query sequences close to each other in the database, which allows Kraken to exploit the CPU cache. Changing the value of <span class="math inline"><em>M</em></span> can significantly affect the speed of Kraken, and neither increasing or decreasing <span class="math inline"><em>M</em></span> will guarantee faster or slower speed.</p>
-<p>To build the database, you'll use the <code>--build</code> switch:</p>
-<pre><code>kraken-build --build --db $DBNAME</code></pre>
-<p>As noted above, you may want to also use any of <code>--threads</code>, <code>--kmer-len</code>, or <code>--minimizer-len</code> to adjust the database build time and/or final size.</p></li>
-<li><p>Shrinking the database: The "--shrink" task allows you to take an existing Kraken database and create a smaller MiniKraken database from it. The use of this option removes all but a specified number of <span class="math inline"><em>k</em></span>-mer/taxon pairs to create a new, smaller database. For example:</p>
-<pre><code>kraken-build --shrink 10000 --db $DBNAME --new-db minikraken</code></pre>
-<p>This will create a new database named <code>minikraken</code> that contains 10000 <span class="math inline"><em>k</em></span>-mers selected from across the original database (<code>$DBNAME</code>).</p>
-<p>The <code>--shrink</code> task is only meant to be run on a completed database. However, if you know before you create a database that you will only be able to use a certain amount of memory, you can use the <code>--max-db-size</code> switch for the <code>--build</code> task to provide a maximum size (in GB) for the database. This allows you to create a MiniKraken database without having to create a full Kraken database first.</p></li>
-</ol>
-<p>A full list of options for <code>kraken-build</code> can be obtained using <code>kraken-build --help</code>.</p>
-<p>After building a database, if you want to reduce the disk usage of the database you can use <code>kraken-build</code>'s <code>--clean</code> switch to remove all intermediate files from the database directory.</p>
-<h1 id="memory-usage-and-efficiency">Memory Usage and Efficiency</h1>
+
+<h1 id="memory-usage-and-efficiency"><a href="#memory-usage-and-efficiency">Memory Usage and Efficiency</a></h1>
 <p>Kraken's execution requires many random accesses to a very large file. To obtain maximal speed, these accesses need to be made as quickly as possible. This means that the database must be in physical memory during execution. Although we provide the <code>--preload</code> option to Kraken for users who cannot use a ramdisk, the ramdisk is likely the simplest option, and is well-suited for installations on computers where Kraken is to be run a majority of the time. In addition, using a  [...]
 <p>We also note that in some cases, <code>--preload</code> may not be needed (or even advisable). If you know that your database is already in memory (for example, if it has been recently read or unzipped, then it should be in your operating system cache, which resides in physical memory), then there is no need to perform this step. We have noticed that in low-memory (~8 GB) situations, preloading a MiniKraken DB is actually much slower than simply using <code>cat minikraken/database.* & [...]
 <p>To create a ramdisk, you will need to have superuser (root) permission. As root, you can use the following commands to create a ramdisk:</p>
@@ -205,7 +231,7 @@ mount -t ramfs none /ramdisk</code></pre>
 <pre><code>kraken --db /ramdisk/$DBNAME seqs.fa</code></pre>
 <p>Note that anything copied into a ramdisk will be deleted if the ramdisk is unmounted or the computer is restarted, so make sure that you have a copy of the database on a hard disk (or other non-volatile storage).</p>
 <p>Note that when using the <code>--paired</code> option, Kraken will not (by default) make any attempt to ensure that the two files you specify are indeed matching sets of paired-end reads. To verify that the names of each read do indeed match, you can use the <code>--check-names</code> option in combination with the <code>--paired</code> option.</p>
-<h1 id="sample-reports">Sample Reports</h1>
+<h1 id="sample-reports"><a href="#sample-reports">Sample Reports</a></h1>
 <p>To get an idea as to Kraken's results across an entire sample, we provide the <code>kraken-report</code> script. It is used like this:</p>
 <pre><code>kraken-report --db $DBNAME kraken.output</code></pre>
 <p>Note that the database used must be the same as the one used to generate the output file, or the report script may encounter problems. Output is sent to standard output.</p>
@@ -221,18 +247,18 @@ mount -t ramfs none /ramdisk</code></pre>
 <p>The scientific names are indented using spaces, according to the tree structure specified by the taxonomy.</p>
 <p>By default, taxa with no reads assigned to (or under) them will not have any output produced. However, if you wish to have all taxa displayed, you can use the <code>--show-zeros</code> switch to do so. This can be useful if you are looking to do further downstream analysis of the reports, and want to compare samples. Sorting by the taxonomy ID (using <code>sort -nf5</code>) can provide a consistent line ordering between reports.</p>
 <p>In addition, we also provide the program <code>kraken-mpa-report</code>; this program provides output in a format similar to MetaPhlAn's tab-delimited output. For <code>kraken-mpa-report</code>, multiple Kraken output files can be specified on the command line and each will be treated as a separate sample. For each taxon at the standard ranks (from domain to species), the count of reads in each sample assigned to any node in the clade rooted at that taxon is displayed. <code>kraken-mp [...]
-<h1 id="confidence-scoring">Confidence Scoring</h1>
+<h1 id="confidence-scoring"><a href="#confidence-scoring">Confidence Scoring</a></h1>
 <p>At present, we have not yet developed a confidence score with a solid probabilistic interpretation for Kraken. However, we have developed a simple scoring scheme that has yielded good results for us, and we've made that available in the <code>kraken-filter</code> script. The approach we use allows a user to specify a threshold score in the [0,1] interval; the <code>kraken-filter</code> script then will adjust labels up the tree until the label's score (described below) meets or exceed [...]
-<p>A sequence label's score is a fraction <span class="math inline"><em>C</em></span>/<span class="math inline"><em>Q</em></span>, where <span class="math inline"><em>C</em></span> is the number of <span class="math inline"><em>k</em></span>-mers mapped to LCA values in the clade rooted at the label, and <span class="math inline"><em>Q</em></span> is the number of <span class="math inline"><em>k</em></span>-mers in the sequence that lack an ambiguous nucleotide (i.e., they were queried a [...]
+<p>A sequence label's score is a fraction <span class="math"><em>C</em></span>/<span class="math"><em>Q</em></span>, where <span class="math"><em>C</em></span> is the number of <span class="math"><em>k</em></span>-mers mapped to LCA values in the clade rooted at the label, and <span class="math"><em>Q</em></span> is the number of <span class="math"><em>k</em></span>-mers in the sequence that lack an ambiguous nucleotide (i.e., they were queried against the database). Consider the example [...]
 <p>"562:13 561:4 A:31 0:1 562:3" would indicate that:</p>
 <ul>
-<li>the first 13 <span class="math inline"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
-<li>the next 4 <span class="math inline"><em>k</em></span>-mers mapped to taxonomy ID #561</li>
-<li>the next 31 <span class="math inline"><em>k</em></span>-mers contained an ambiguous nucleotide</li>
-<li>the next <span class="math inline"><em>k</em></span>-mer was not in the database</li>
-<li>the last 3 <span class="math inline"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
+<li>the first 13 <span class="math"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
+<li>the next 4 <span class="math"><em>k</em></span>-mers mapped to taxonomy ID #561</li>
+<li>the next 31 <span class="math"><em>k</em></span>-mers contained an ambiguous nucleotide</li>
+<li>the next <span class="math"><em>k</em></span>-mer was not in the database</li>
+<li>the last 3 <span class="math"><em>k</em></span>-mers mapped to taxonomy ID #562</li>
 </ul>
-<p>In this case, ID #561 is the parent node of #562. Here, a label of #562 for this sequence would have a score of <span class="math inline"><em>C</em></span>/<span class="math inline"><em>Q</em></span> = (13+3)/(13+4+1+3) = 16/21. A label of #561 would have a score of <span class="math inline"><em>C</em></span>/<span class="math inline"><em>Q</em></span> = (13+4+3)/(13+4+1+3) = 20/21. If a user specified a threshold over 16/21, kraken-filter would adjust the original label from #562 to  [...]
+<p>In this case, ID #561 is the parent node of #562. Here, a label of #562 for this sequence would have a score of <span class="math"><em>C</em></span>/<span class="math"><em>Q</em></span> = (13+3)/(13+4+1+3) = 16/21. A label of #561 would have a score of <span class="math"><em>C</em></span>/<span class="math"><em>Q</em></span> = (13+4+3)/(13+4+1+3) = 20/21. If a user specified a threshold over 16/21, kraken-filter would adjust the original label from #562 to #561; if the threshold was g [...]
 <p><code>kraken-filter</code> is used like this:</p>
 <pre><code>kraken-filter --db $DBNAME [--threshold NUM] kraken.output</code></pre>
 <p>If not specified, the threshold will be 0. <code>kraken-filter</code>'s output is similar to <code>kraken</code>'s, but a new field between the length and LCA mapping list is present, indicating the new label's score (or the root label's score if the sequence has become unclassified).</p>
@@ -318,7 +344,7 @@ mount -t ramfs none /ramdisk</code></pre>
 </table>
 </div>
 <p>As can be seen, with no threshold (i.e., Kraken's original labels), Kraken's precision is fairly high, but it does increase with the threshold. Diminishing returns apply, however, and there is a loss in sensitivity that must be taken into account when deciding on the threshold to use for your own project.</p>
-<h1 id="kraken-environment-variables">Kraken Environment Variables</h1>
+<h1 id="kraken-environment-variables"><a href="#kraken-environment-variables">Kraken Environment Variables</a></h1>
 <p>The Kraken programs (with the exception of <code>kraken-build</code>) support the use of some environment variables to help in reducing command line lengths:</p>
 <ul>
 <li><p><strong><code>KRAKEN_NUM_THREADS</code></strong>: this variable is only used by <code>kraken</code>; if the <code>--threads</code> option is not supplied to <code>kraken</code>, then the value of this variable (if it is set) will be used as the number of threads to run <code>kraken</code>.</p></li>
@@ -345,8 +371,8 @@ kraken sequences.fa | kraken-report > sequences.kreport</code></pre>
 kraken sequences.fa</code></pre>
 <p>will use <code>/data/kraken_dbs/mainDB</code> to classify <code>sequences.fa</code>.</p></li>
 </ul>
-<h1 id="upgrading-databases-to-v0.10">Upgrading Databases to v0.10+</h1>
-<p>The minimizer ordering in Kraken versions prior to v0.10.0-beta was a simple lexicographical ordering that provided a suboptimal distribution of k-mers within the bins. Ideally, the bin sizes would be uniform, but simple lexicographical ordering creates a bias toward low-complexity minimizers. To resolve this, the ordering is now "scrambled" by XORing all minimizers with a predefined constant to toggle half of each minimizer's bits before sorting. The more evenly distributed [...]
+<h1 id="upgrading-databases-to-v0.10"><a href="#upgrading-databases-to-v0.10">Upgrading Databases to v0.10+</a></h1>
+<p>The minimizer ordering in Kraken versions prior to v0.10.0-beta was a simple lexicographical ordering that provided a suboptimal distribution of k-mers within the bins. Ideally, the bin sizes would be uniform, but simple lexicographical ordering creates a bias toward low-complexity minimizers. To resolve this, the ordering is now "scrambled" by XORing all minimizers with a predefined constant to toggle half of each minimizer's bits before sorting. The more evenly distributed [...]
 <ol style="list-style-type: decimal">
 <li><p>Build a new database. This is the preferred option, as a newly-created database will have the latest genomes and NCBI taxonomy information.</p></li>
 <li><p>Re-sort an existing database. If you have a custom database, you may want to simply reformat the database to provide you with Kraken's increased speed. To do so, you'll need to do the following:</p>
@@ -356,5 +382,7 @@ kraken sequences.fa</code></pre>
 <p>Sorting the database is step 3 of the build process, so you should expect a database upgrade to take about as long as step 3 took when building the original database.</p></li>
 </ol>
 <p>Note that the rest of Kraken v0.10.0-beta's speed improvements are available without upgrading or changing your database.</p>
+<h1 id="upgrading-databases-to-v1.0"><a href="#upgrading-databases-to-v1.0">Upgrading Databases to v1.0</a></h1>
+<p>Upgrading to the Kraken version 1.0 does not require rebuilding of any existing Kraken databases. The main updates for this version are within the building process itself. Due to the phasing out of NCBI GI numbers, Kraken version 1.0 does not rely on GI numbers and rather uses the sequence ID to taxon ID maps provided in the NCBI taxonomy. The new version of Kraken uses these in the building of the database but the final database files have not changed. Other changes include changes i [...]
 </body>
 </html>
diff --git a/scripts/kraken b/scripts/kraken
index af5f67b..8da8309 100755
--- a/scripts/kraken
+++ b/scripts/kraken
@@ -45,6 +45,7 @@ my $quick = 0;
 my $min_hits = 1;
 my $fasta_input = 0;
 my $fastq_input = 0;
+my $fastq_output = 0;
 my $db_prefix;
 my $threads;
 my $preload = 0;
@@ -55,6 +56,7 @@ my $check_names = 0;
 my $only_classified_output = 0;
 my $unclassified_out;
 my $classified_out;
+my $output_format = "legacy";
 my $outfile;
 
 GetOptions(
@@ -64,10 +66,12 @@ GetOptions(
   "threads=i" => \$threads,
   "fasta-input" => \$fasta_input,
   "fastq-input" => \$fastq_input,
+  "fastq-output" => \$fastq_output,
   "quick" => \$quick,
   "min-hits=i" => \$min_hits,
   "unclassified-out=s" => \$unclassified_out,
   "classified-out=s" => \$classified_out,
+  "out-fmt=s" => \$output_format,
   "output=s" => \$outfile,
   "preload" => \$preload,
   "paired" => \$paired,
@@ -137,14 +141,17 @@ push @flags, "-d", $kdb_file;
 push @flags, "-i", $idx_file;
 push @flags, "-t", $threads if $threads > 1;
 push @flags, "-n", $taxonomy if defined $taxonomy;
-push @flags, "-q" if $quick;
+push @flags, "-q", if $quick;
 push @flags, "-m", $min_hits if $min_hits > 1;
-push @flags, "-f" if $fastq_input && ! $paired;  # merger always outputs FASTA
+push @flags, "-f", if $fastq_input;
+push @flags, "-F", if $fastq_output;
 push @flags, "-U", $unclassified_out if defined $unclassified_out;
 push @flags, "-C", $classified_out if defined $classified_out;
+push @flags, "-O", $output_format if defined $output_format;
 push @flags, "-o", $outfile if defined $outfile;
 push @flags, "-c", if $only_classified_output;
-push @flags, "-M" if $preload;
+push @flags, "-M", if $preload;
+push @flags, "-P", if $paired;
 
 # handle piping for decompression/merging
 my @pipe_argv;
@@ -155,6 +162,7 @@ if ($paired) {
   push @merge_flags, "--gz" if $gunzip;
   push @merge_flags, "--bz2" if $bunzip2;
   push @merge_flags, "--check-names" if $check_names;
+  push @merge_flags, "--output-format", $output_format if defined $output_format;
   @pipe_argv = ("read_merger.pl", @merge_flags, @ARGV);
 }
 elsif ($compressed) {
@@ -210,6 +218,7 @@ Options:
   --threads NUM           Number of threads (default: $def_thread_ct)
   --fasta-input           Input is FASTA format
   --fastq-input           Input is FASTQ format
+  --fastq-output          Output in FASTQ format
   --gzip-compressed       Input is gzip compressed
   --bzip2-compressed      Input is bzip2 compressed
   --quick                 Quick operation (use first hit or hits)
@@ -219,6 +228,8 @@ Options:
                           Print unclassified sequences to filename
   --classified-out FILENAME
                           Print classified sequences to filename
+  --out-fmt FORMAT        Format for [un]classified sequence output. supported 
+                          options are: {legacy, paired, interleaved}
   --output FILENAME       Print output to filename (default: stdout); "-" will
                           suppress normal output
   --only-classified-output
diff --git a/scripts/read_merger.pl b/scripts/read_merger.pl
index 166f21f..1471f4a 100755
--- a/scripts/read_merger.pl
+++ b/scripts/read_merger.pl
@@ -32,13 +32,15 @@ my $fastq_input = 0;
 my $gunzip = 0;
 my $bunzip2 = 0;
 my $check_names = 0;
+my $output_format;
 
 GetOptions(
   "fa" => \$fasta_input,
   "fq" => \$fastq_input,
   "gz" => \$gunzip,
   "bz2" => \$bunzip2,
-  "check-names" => \$check_names
+  "check-names" => \$check_names,
+  "output-format=s" => \$output_format
 );
 
 if (@ARGV != 2) {
@@ -84,16 +86,31 @@ else {
 
 # read/merge/print loop
 # make sure names match before merging
-my ($seq1, $seq2);
+my ($seq1, $seq2, $delimiter);
+if ($output_format eq "legacy") {
+  $delimiter = 'N';
+}
+else {
+  $delimiter = '|';
+}
 while (defined($seq1 = read_sequence($fh1))) {
   $seq2 = read_sequence($fh2);
   if (! defined $seq2) {
     die "$PROG: mismatched sequence counts\n";
   }
-  if ($check_names && $seq1->{id} ne $seq2->{id}) {
-    die "$PROG: mismatched mate pair names ('$seq1->{id}' & '$seq2->{id}')\n";
+  if ($check_names) {
+    my $comparison_id1 = $seq1->{id} =~ /(\S+)/; # Only check up until first whitespace character
+    my $comparison_id2 = $seq2->{id} =~ /(\S+)/;
+    if ($comparison_id1 ne $comparison_id2) {
+        die "$PROG: mismatched mate pair names ('$seq1->{id}' & '$seq2->{id}')\n";
+    }
+  }
+  if ($fastq_input) {
+    print_merged_sequence_fastq($seq1, $seq2, $delimiter);
+  }
+  else {
+    print_merged_sequence($seq1, $seq2, $delimiter);
   }
-  print_merged_sequence($seq1, $seq2);
 }
 if (defined($seq2 = read_sequence($fh2))) {
   die "$PROG: mismatched sequence counts\n";
@@ -107,6 +124,7 @@ close $fh2;
     my $fh = shift;
     my $id;
     my $seq = "";
+    my $qual = "";
     if (! exists $buffers{$fh}) {
       $buffers{$fh} = <$fh>;
     }
@@ -133,7 +151,14 @@ close $fh2;
       }
     }
     elsif ($fastq_input) {
-      if ($buffers{$fh} =~ /^@(\S+)/) {
+      my $fastq_header_regex;
+      if ($output_format eq "legacy") {
+	  $fastq_header_regex = qr/^@(\S+)/;
+      }
+      else {
+	  $fastq_header_regex = qr/^@(\S+\s\S+)/; # Allow one whitespace character in fastq header
+      }
+      if ($buffers{$fh} =~ $fastq_header_regex) {  
         $id = $1;
       }
       else {
@@ -145,20 +170,32 @@ close $fh2;
       delete $buffers{$fh};
       chomp($seq = <$fh>);
       scalar <$fh>;  # quality header
-      scalar <$fh>;  # quality values
+      chomp($qual = <$fh>); # quality values
     }
     else {
       # should never get here
       die "$PROG: I have no idea what kind of input I'm reading!!!\n";
     }
 
-    $id =~ s/[\/_.][12]$//;  # strip /1 (or .1, _1) or /2 to help comparison
-    return { id => $id, seq => $seq };
+    return { id => $id, seq => $seq, qual => $qual };
   }
 }
 
 sub print_merged_sequence {
-  my ($seq1, $seq2) = @_;
+  my ($seq1, $seq2, $delimiter) = @_;
   print ">" . $seq1->{id} . "\n";
-  print $seq1->{seq} . "N" . $seq2->{seq} . "\n";
+  print $seq1->{seq} . $delimiter . $seq2->{seq} . "\n";
+}
+
+sub print_merged_sequence_fastq {
+  my ($seq1, $seq2, $delimiter) = @_;
+  if ($output_format eq "legacy") {
+    print "@" . $seq1->{id} . "\n";
+  }
+  else {
+    print "@" . $seq1->{id} . $delimiter . $seq2->{id} . "\n";
+  }
+  print $seq1->{seq} . $delimiter . $seq2->{seq} . "\n";
+  print "+\n";
+  print $seq1->{qual} . $delimiter . $seq2->{qual} . "\n";
 }
diff --git a/scripts/rsync_from_ncbi.pl b/scripts/rsync_from_ncbi.pl
index 7392991..2da47d8 100755
--- a/scripts/rsync_from_ncbi.pl
+++ b/scripts/rsync_from_ncbi.pl
@@ -82,7 +82,7 @@ my $ch = "bp";
 my $max_out_chars = 0;
 for my $in_filename (keys %manifest) {
   my $taxid = $manifest{$in_filename};
-  open IN, "zcat $in_filename |" or die "$PROG: can't read $in_filename: $!\n";
+  open IN, "gunzip -c $in_filename |" or die "$PROG: can't read $in_filename: $!\n";
   while (<IN>) {
     if (/^>/) {
       s/^>/>kraken:taxid|$taxid|/;
diff --git a/src/classify.cpp b/src/classify.cpp
index 957c8be..1548983 100644
--- a/src/classify.cpp
+++ b/src/classify.cpp
@@ -32,7 +32,8 @@ void parse_command_line(int argc, char **argv);
 void usage(int exit_code=EX_USAGE);
 void process_file(char *filename);
 void classify_sequence(DNASequence &dna, ostringstream &koss,
-                       ostringstream &coss, ostringstream &uoss);
+                       ostringstream &coss, ostringstream &uoss,
+		       ostringstream &coss2, ostringstream &uoss2);
 string hitlist_string(vector<uint32_t> &taxa, vector<uint8_t> &ambig);
 set<uint32_t> get_ancestry(uint32_t taxon);
 void report_stats(struct timeval time1, struct timeval time2);
@@ -41,6 +42,8 @@ int Num_threads = 1;
 string DB_filename, Index_filename, Nodes_filename;
 bool Quick_mode = false;
 bool Fastq_input = false;
+bool Fastq_output = false;
+bool Paired_input = false;
 bool Print_classified = false;
 bool Print_unclassified = false;
 bool Print_kraken = true;
@@ -50,8 +53,11 @@ uint32_t Minimum_hit_count = 1;
 map<uint32_t, uint32_t> Parent_map;
 KrakenDB Database;
 string Classified_output_file, Unclassified_output_file, Kraken_output_file;
+string Output_format;
 ostream *Classified_output;
+ostream *Classified_output2;
 ostream *Unclassified_output;
+ostream *Unclassified_output2;
 ostream *Kraken_output;
 size_t Work_unit_size = DEF_WORK_UNIT_SIZE;
 
@@ -91,15 +97,47 @@ int main(int argc, char **argv) {
   if (Print_classified) {
     if (Classified_output_file == "-")
       Classified_output = &cout;
-    else
-      Classified_output = new ofstream(Classified_output_file.c_str());
+    else {
+      if (Output_format == "paired" && Fastq_output && ! Classified_output_file.empty()) {
+	string Classified_output_filename1 = Classified_output_file + "_R1.fastq";
+	string Classified_output_filename2 = Classified_output_file + "_R2.fastq";
+	Classified_output  = new ofstream(Classified_output_filename1.c_str());
+	Classified_output2 = new ofstream(Classified_output_filename2.c_str());
+      }
+      else if (Output_format == "paired" && ! Fastq_output && ! Classified_output_file.empty()) {
+	string Classified_output_filename1 = Classified_output_file + "_R1.fa";
+	string Classified_output_filename2 = Classified_output_file + "_R2.fa";
+	Classified_output  = new ofstream(Classified_output_filename1.c_str());
+	Classified_output2 = new ofstream(Classified_output_filename2.c_str());
+      }
+      else {
+	Classified_output = new ofstream(Classified_output_file.c_str());
+	Classified_output2 = new ofstream();
+      }
+    }
   }
 
   if (Print_unclassified) {
     if (Unclassified_output_file == "-")
       Unclassified_output = &cout;
-    else
-      Unclassified_output = new ofstream(Unclassified_output_file.c_str());
+    else {
+      if (Output_format == "paired" && Fastq_output && ! Classified_output_file.empty()) {
+	string Unclassified_output_filename1 = Unclassified_output_file + "_R1.fastq";
+	string Unclassified_output_filename2 = Unclassified_output_file + "_R2.fastq";
+	Unclassified_output  = new ofstream(Unclassified_output_filename1.c_str());
+	Unclassified_output2 = new ofstream(Unclassified_output_filename2.c_str());
+      } 
+      else if (Output_format == "paired" && ! Fastq_output && ! Classified_output_file.empty()) {
+	string Unclassified_output_filename1 = Unclassified_output_file + "_R1.fa";
+	string Unclassified_output_filename2 = Unclassified_output_file + "_R2.fa";
+	Unclassified_output  = new ofstream(Unclassified_output_filename1.c_str());
+	Unclassified_output2 = new ofstream(Unclassified_output_filename2.c_str());
+      }
+      else {
+	Unclassified_output = new ofstream(Unclassified_output_file.c_str());
+	Unclassified_output2 = new ofstream();
+      }
+    }
   }
 
   if (! Kraken_output_file.empty()) {
@@ -160,7 +198,7 @@ void process_file(char *filename) {
   #pragma omp parallel
   {
     vector<DNASequence> work_unit;
-    ostringstream kraken_output_ss, classified_output_ss, unclassified_output_ss;
+    ostringstream kraken_output_ss, classified_output_ss, classified_output_ss2, unclassified_output_ss, unclassified_output_ss2;
 
     while (reader->is_valid()) {
       work_unit.clear();
@@ -180,19 +218,28 @@ void process_file(char *filename) {
       
       kraken_output_ss.str("");
       classified_output_ss.str("");
+      classified_output_ss2.str("");
       unclassified_output_ss.str("");
+      unclassified_output_ss2.str("");
       for (size_t j = 0; j < work_unit.size(); j++)
         classify_sequence( work_unit[j], kraken_output_ss,
-                           classified_output_ss, unclassified_output_ss );
+                           classified_output_ss, unclassified_output_ss,
+			   classified_output_ss2, unclassified_output_ss2);
 
       #pragma omp critical(write_output)
       {
         if (Print_kraken)
           (*Kraken_output) << kraken_output_ss.str();
-        if (Print_classified)
+        if (Print_classified) {
           (*Classified_output) << classified_output_ss.str();
-        if (Print_unclassified)
+	  if (Output_format == "paired")
+	    (*Classified_output2) << classified_output_ss2.str();
+	}
+        if (Print_unclassified) {
           (*Unclassified_output) << unclassified_output_ss.str();
+	  if (Output_format == "paired")
+	    (*Unclassified_output2) << unclassified_output_ss2.str();
+	}
         total_sequences += work_unit.size();
         total_bases += total_nt;
         if (isatty(fileno(stderr)))
@@ -204,14 +251,19 @@ void process_file(char *filename) {
   delete reader;
   if (Print_kraken)
     (*Kraken_output) << std::flush;
-  if (Print_classified)
+  if (Print_classified) {
     (*Classified_output) << std::flush;
-  if (Print_unclassified)
+    (*Classified_output2) << std::flush;
+   }
+  if (Print_unclassified) {
     (*Unclassified_output) << std::flush;
+    (*Unclassified_output2) << std::flush;
+  }
 }
 
 void classify_sequence(DNASequence &dna, ostringstream &koss,
-                       ostringstream &coss, ostringstream &uoss) {
+                       ostringstream &coss, ostringstream &uoss,
+		       ostringstream &coss2, ostringstream &uoss2) {
   vector<uint32_t> taxa;
   vector<uint8_t> ambig_list;
   map<uint32_t, uint32_t> hit_counts;
@@ -259,18 +311,94 @@ void classify_sequence(DNASequence &dna, ostringstream &koss,
     total_classified++;
 
   if (Print_unclassified || Print_classified) {
-    ostringstream *oss_ptr = call ? &coss : &uoss;
+    ostringstream *oss_ptr;
+    ostringstream *oss_ptr2;
+    if (call) {
+      oss_ptr = &coss;
+      oss_ptr2 = &coss2;
+    }
+    else {
+      oss_ptr = &uoss;
+      oss_ptr2 = &uoss2;
+    }
     bool print = call ? Print_classified : Print_unclassified;
     if (print) {
-      if (Fastq_input) {
-        (*oss_ptr) << "@" << dna.header_line << endl
-            << dna.seq << endl
-            << "+" << endl
-            << dna.quals << endl;
+      string delimiter = "|";
+      if (Fastq_output && Output_format == "paired") {
+	size_t delimiter_pos = 0;
+	delimiter_pos = dna.header_line.find(delimiter);
+	string header1 = dna.header_line.substr(0, delimiter_pos);
+	string header2 = dna.header_line.substr(delimiter_pos + delimiter.length());
+	delimiter_pos = dna.seq.find(delimiter);
+	string seq1 = dna.seq.substr(0, delimiter_pos);
+	string seq2 = dna.seq.substr(delimiter_pos + delimiter.length());
+	delimiter_pos = dna.quals.find(delimiter);
+	string quals1 = dna.quals.substr(0, delimiter_pos);
+	string quals2 = dna.quals.substr(delimiter_pos + delimiter.length());
+	(*oss_ptr) << "@" << header1 << endl
+		   << seq1 << endl
+		   << "+" << endl
+		   << quals1 << endl;
+	(*oss_ptr2) << "@" << header2 << endl
+		    << seq2 << endl
+		    << "+" << endl
+		    << quals2 << endl;
       }
-      else {
-        (*oss_ptr) << ">" << dna.header_line << endl
-            << dna.seq << endl;
+      else if (! Fastq_output && Output_format == "paired") {
+	size_t delimiter_pos = 0;
+	delimiter_pos = dna.header_line.find(delimiter);
+	string header1 = dna.header_line.substr(0, delimiter_pos);
+	string header2 = dna.header_line.substr(delimiter_pos + delimiter.length());
+	delimiter_pos = dna.seq.find(delimiter);
+	string seq1 = dna.seq.substr(0, delimiter_pos);
+	string seq2 = dna.seq.substr(delimiter_pos + delimiter.length());
+	(*oss_ptr) << ">" << header1 << endl
+		   << seq1 << endl;
+	(*oss_ptr2) << ">" << header2 << endl
+		    << seq2 << endl;
+      }
+      else if (Fastq_output && Output_format == "legacy") {
+	(*oss_ptr) << "@" << dna.header_line << endl
+		   << dna.seq << endl
+		   << "+" << endl
+		   << dna.quals << endl;
+      }
+      else if (Fastq_output && Output_format == "interleaved") {
+	size_t delimiter_pos = 0;
+	delimiter_pos = dna.header_line.find(delimiter);
+	string header1 = dna.header_line.substr(0, delimiter_pos);
+	string header2 = dna.header_line.substr(delimiter_pos + delimiter.length());
+	delimiter_pos = dna.seq.find(delimiter);
+	string seq1 = dna.seq.substr(0, delimiter_pos);
+	string seq2 = dna.seq.substr(delimiter_pos + delimiter.length());
+	delimiter_pos = dna.quals.find(delimiter);
+	string quals1 = dna.quals.substr(0, delimiter_pos);
+	string quals2 = dna.quals.substr(delimiter_pos + delimiter.length());
+	(*oss_ptr) << "@" << header1 << endl
+		   << seq1 << endl
+		   << "+" << endl
+		   << quals1 << endl;
+	(*oss_ptr) << "@" << header2 << endl
+		   << seq2 << endl
+		   << "+" << endl
+		   << quals2 << endl;
+      }
+      else if (! Fastq_output && Output_format == "interleaved") {
+	size_t delimiter_pos = 0;
+	delimiter_pos = dna.header_line.find(delimiter);
+	string header1 = dna.header_line.substr(0, delimiter_pos);
+	string header2 = dna.header_line.substr(delimiter_pos + delimiter.length());
+	delimiter_pos = dna.seq.find(delimiter);
+	string seq1 = dna.seq.substr(0, delimiter_pos);
+	string seq2 = dna.seq.substr(delimiter_pos + delimiter.length());
+	(*oss_ptr) << ">" << header1 << endl
+		   << seq1 << endl;
+	(*oss_ptr) << ">" << header2 << endl
+		   << seq2 << endl;
+      }
+      else if (! Fastq_output && Output_format == "legacy") {
+	(*oss_ptr) << ">" << dna.header_line << endl
+		   << dna.seq << endl;
       }
     }
   }
@@ -354,7 +482,7 @@ void parse_command_line(int argc, char **argv) {
 
   if (argc > 1 && strcmp(argv[1], "-h") == 0)
     usage(0);
-  while ((opt = getopt(argc, argv, "d:i:t:u:n:m:o:qfcC:U:M")) != -1) {
+  while ((opt = getopt(argc, argv, "d:i:t:u:n:m:o:qfFPcC:O:U:M")) != -1) {
     switch (opt) {
       case 'd' :
         DB_filename = optarg;
@@ -388,6 +516,12 @@ void parse_command_line(int argc, char **argv) {
       case 'f' :
         Fastq_input = true;
         break;
+      case 'F' :
+        Fastq_output = true;
+        break;
+      case 'O' :
+	Output_format = optarg;
+	break;
       case 'c' :
         Only_classified_kraken_output = true;
         break;
@@ -408,6 +542,9 @@ void parse_command_line(int argc, char **argv) {
           errx(EX_USAGE, "can't use nonpositive work unit size");
         Work_unit_size = sig;
         break;
+      case 'P' :
+	Paired_input = true;
+	break;
       case 'M' :
         Populate_memory = true;
         break;
@@ -432,6 +569,22 @@ void parse_command_line(int argc, char **argv) {
   if (optind == argc) {
     cerr << "No sequence data files specified" << endl;
   }
+  if (Output_format == "paired" && (Classified_output_file == "-" || Unclassified_output_file == "-")) {
+    cerr << "Can't send paired output to stdout" << endl;
+    usage();
+  }
+  if ((Output_format == "paired" || Output_format == "interleaved") && ! Paired_input) {
+    cerr << "Output format " << Output_format << " requires paired input" << endl;
+    usage();
+  }
+  if (Output_format == "legacy" && Fastq_output) {
+    cerr << "FASTQ output not supported for legacy ('N' delimited) output format. Use '--out-fmt paired'" << endl;
+    usage();
+  }
+  if (Fastq_output && ! Fastq_input) {
+    cerr << "FASTQ output requires FASTQ input" << endl;
+    usage();
+  }
 }
 
 void usage(int exit_code) {
@@ -448,7 +601,10 @@ void usage(int exit_code) {
        << "  -m #             Minimum hit count (ignored w/o -q)" << endl
        << "  -C filename      Print classified sequences" << endl
        << "  -U filename      Print unclassified sequences" << endl
+       << "  -O format        [Un]classified output format {legacy, paired}" << endl
        << "  -f               Input is in FASTQ format" << endl
+       << "  -F               Output in FASTQ format" << endl
+       << "  -P               Input files are paired." << endl
        << "  -c               Only include classified reads in output" << endl
        << "  -M               Preload database files" << endl
        << "  -h               Print this message" << endl

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/kraken.git



More information about the debian-med-commit mailing list