Debian Codegraph @

README.md

raw symbols SCIP
1 <p align="center"><img src="misc/porechop_logo_knife.png" alt="Porechop" width="600"></p>
2
3 Porechop is a tool for finding and removing adapters from [Oxford Nanopore](https://nanoporetech.com/) reads. Adapters on the ends of reads are trimmed off, and when a read has an adapter in its middle, it is treated as chimeric and chopped into separate reads. Porechop performs thorough alignments to effectively find adapters, even at low sequence identity.
4
5 Porechop also supports demultiplexing of Nanopore reads that were barcoded with the [Native Barcoding Kit](https://store.nanoporetech.com/native-barcoding-kit-1d.html), [PCR Barcoding Kit](https://store.nanoporetech.com/pcr-barcoding-kit-96.html) or [Rapid Barcoding Kit](https://store.nanoporetech.com/rapid-barcoding-sequencing-kit.html).
6
7
8 ### Oct 2018 update: Porechop is officially unsupported
9
10 While I'm happy Porechop has so many users, it has always been a bit klugey and a pain to maintain. I don't have the time to give it the attention it deserves, so I'm going to now officially declare Porechop as abandonware (though the unanswered [issues](https://github.com/rrwick/Porechop/issues) and [pull requests](https://github.com/rrwick/Porechop/pulls) reveal that it already has been for some time). I've added a [known issues](#known-issues) section to the README to outline what I think is wrong with Porechop and how a reimplementation should look. I may someday (no promises though :stuck_out_tongue:) try to rewrite it from a blank canvas to address its faults.
11
12
13
14
15
16 # Table of contents
17
18 * [Requirements](#requirements)
19 * [Installation](#installation)
20 * [Install from source](#install-from-source)
21 * [Build and run without installation](#build-and-run-without-installation)
22 * [Quick usage examples](#quick-usage-examples)
23 * [How it works](#how-it-works)
24 * [Find matching adapter sets](#find-matching-adapter-sets)
25 * [Trim adapters from read ends](#trim-adapters-from-read-ends)
26 * [Split reads with internal adapters](#split-reads-with-internal-adapters)
27 * [Discard reads with internal adapters](#discard-reads-with-internal-adapters)
28 * [Barcode demultiplexing](#barcode-demultiplexing)
29 * [Barcode demultiplexing with Albacore](#barcode-demultiplexing-with-albacore)
30 * [Output](#output)
31 * [Verbose output](#verbose-output)
32 * [Known adapters](#known-adapters)
33 * [Full usage](#full-usage)
34 * [Known issues](#known-issues)
35 * [Acknowledgements](#acknowledgements)
36 * [License](#license)
37
38
39
40 # Requirements
41
42 * Linux or macOS
43 * [Python](https://www.python.org/) 3.4 or later
44 * C++ compiler
45 * If you're using [GCC](https://gcc.gnu.org/), version 4.9.1 or later is required (check with `g++ --version`).
46 * Recent versions of [Clang](http://clang.llvm.org/) and [ICC](https://software.intel.com/en-us/c-compilers) should also work (C++14 support is required).
47
48 I haven't tried to make Porechop run on Windows, but it should be possible. If you have any success on this front, let me know and I'll add instructions to this README!
49
50
51
52 # Installation
53
54 ### Install from source
55
56 Running the `setup.py` script will compile the C++ components of Porechop and install a `porechop` executable:
57
58 ```bash
59 git clone https://github.com/rrwick/Porechop.git
60 cd Porechop
61 python3 setup.py install
62 porechop -h
63 ```
64
65 Notes:
66 * If the last command complains about permissions, you may need to run it with `sudo`.
67 * Install just for your user: `python3 setup.py install --user`
68 * If you get a strange "can't combine user with prefix" error, read [this](http://stackoverflow.com/questions/4495120).
69 * Install to a specific location: `python3 setup.py install --prefix=$HOME/.local`
70 * Install with pip (local copy): `pip3 install path/to/Porechop`
71 * Install with pip (from GitHub): `pip3 install git+https://github.com/rrwick/Porechop.git`
72 * If you'd like to specify which compiler to use, set the `CXX` variable: `export CXX=g++-6; python3 setup.py install`
73 * Porechop includes `ez_setup.py` for users who don't have [setuptools](https://pypi.python.org/pypi/setuptools) installed, though that script is [deprecated](https://github.com/pypa/setuptools/issues/581). So if you run into any installation problems, make sure setuptools is installed on your computer: `pip3 install setuptools`
74
75
76 ### Build and run without installation
77
78 By simply running `make` in Porechop's directory, you can compile the C++ components but not install an executable. The program can then be executed by directly calling the `porechop-runner.py` script.
79
80 ```bash
81 git clone https://github.com/rrwick/Porechop.git
82 cd Porechop
83 make
84 ./porechop-runner.py -h
85 ```
86
87
88 # Quick usage examples
89
90 __Basic adapter trimming:__<br>
91 `porechop -i input_reads.fastq.gz -o output_reads.fastq.gz`
92
93 __Trimmed reads to stdout, if you prefer:__<br>
94 `porechop -i input_reads.fastq.gz > output_reads.fastq`
95
96 __Demultiplex barcoded reads:__<br>
97 `porechop -i input_reads.fastq.gz -b output_dir`
98
99 __Demultiplex barcoded reads, straight from Albacore output directory:__<br>
100 `porechop -i albacore_dir -b output_dir`
101
102 __Also works with FASTA:__<br>
103 `porechop -i input_reads.fasta -o output_reads.fasta`
104
105 __More verbose output:__<br>
106 `porechop -i input_reads.fastq.gz -o output_reads.fastq.gz --verbosity 2`
107
108 __Got a big server?__<br>
109 `porechop -i input_reads.fastq.gz -o output_reads.fastq.gz --threads 40`
110
111
112
113 # How it works
114
115 ### Find matching adapter sets
116
117 Porechop first aligns a subset of reads (default 10000 reads, change with `--check_reads`) to all known adapter sets. Adapter sets with at least one high identity match (default 90%, change with `--adapter_threshold`) are deemed present in the sample.
118
119 Identity in this step is measured over the full length of the adapter. E.g. in order to qualify for a 90% match, an adapter could be present at 90% identity over its full length, or it could be present at 100% identity over 90% of its length, but a 90% identity match over 90% of the adapter length would not be sufficient.
120
121 The [alignment scoring scheme](http://seqan.readthedocs.io/en/master/Tutorial/DataStructures/Alignment/ScoringSchemes.html) used in this and subsequent alignments can be modified using the `--scoring_scheme` option (default: match = 3, mismatch = -6, gap open = -5, gap extend = -2).
122
123
124 ### Trim adapters from read ends
125
126 The first and last bases in each read (default 150 bases, change with `--end_size`) are aligned to each present adapter set. When a long enough (default 4, change with `--min_trim_size`) and strong enough (default 75%, change with `--end_threshold`) match is found, the read is trimmed. A few extra bases (default 2, change with `--extra_end_trim`) past the adapter match are removed as well to ensure it's all removed.
127
128 Identity in this step is measured over the _aligned part_ of the adapter, not its full length. E.g. if the last 5 bases of an adapter exactly match the first 5 bases of a read, that counts as a 100% identity match and those bases will be trimmed off. This allows Porechop to effectively trim partially present barcodes.
129
130 The default `--end_threshold` is low (75%) because false positives (trimming off some sequence that wasn't really an adapter) shouldn't be too much of a problem with long reads, as only a tiny fraction of the read is lost.
131
132
133 ### Split reads with internal adapters
134
135 The entirety of each read is aligned to the present adapter sets to spot cases where an adapter is in the middle of the read, indicating a chimera. When a strong enough match is found (default 85%, change with `--middle_threshold`), the read is split. If the resulting parts are too short (default less than 1000 bp, change with `--min_split_read_size`), they are discarded.
136
137 The default `--middle_threshold` (85%) is higher than the default `--end_threshold` (75%) because false positives in this step (splitting a read that is not chimeric) could be more problematic than false positives in the end trimming step. If false negatives (failing to split a chimera) are worse for you than false positives (splitting a non-chimera), you should reduce this threshold (e.g. `--middle_threshold 75`).
138
139 Extra bases are also removed next to the hit, and how many depends on the side of the adapter. If we find an adapter that's expected at the start of a read, it's likely that what follows is good sequence but what precedes it may not be. Therefore, a few bases are trimmed after the adapter (default 10, change with `--extra_middle_trim_good_side`) and more bases are trimmed before the adapter (default 100, change with `--extra_middle_trim_bad_side`). If the found adapter is one we'd expect at the end of the read, then the "good side" is before the adapter and the "bad side" is after the adapter.
140
141 Here is a real example of the "good" and "bad" sides of an adapter. The adapter is in the middle of this snippet (SQK-NSK007_Y_Top at about 90% identity). The bases to the left are the "bad" side and their repetitive nature is clear. The bases to the right are the "good" side and represent real biological sequence.
142 ```
143 TGTTGTTGTTGTTATTGTTGTTATTGTTGTTGTATTGTTGTTATTGTTGTTGTTGTACATTGTTATTGTTGTATTGTTGTTATTGTTGTTGTATTATCGGTGTACTTCGTTCAGTTACGTATTACTATCGCTATTGTTTGCAGTGAGAGGTGGCGGTGAGCGTTTTCAAATGGCCCTGTACAATCATGGGATAACAACATAAGGAACGGACCATGAAGTCACTTCT
144 ```
145
146
147 ### Discard reads with internal adapters
148
149 If you run Porechop with `--discard_middle`, the reads with internal adapters will be thrown out instead of split.
150
151 If you plan on using your reads with [Nanopolish](https://github.com/jts/nanopolish), then the `--discard_middle` option is required. This is because Nanopolish first runs [`nanopolish index`](https://github.com/jts/nanopolish#data-preprocessing) to find a one-to-one association between FASTQ reads and fast5 files. If you ran Porechop _without_ `--discard_middle`, then you could end up with multiple separate FASTQ reads which are from a single fast5, and this is incompatible with Nanopolish.
152
153 This option is also recommended if you are trimming reads from a demultiplexed barcoded sequencing run. This is because chimeric reads may contain two sequences from two separate barcodes, so throwing them out is the safer option to reduce cross-barcode contamination.
154
155
156 ### Barcode demultiplexing
157
158 Porechop can also demultiplex the reads into bins based on which barcode was found. This is done by using the `-b` option, which specifies an output directory for the trimmed reads (each barcode in a separate file), instead of `-o`.
159
160 Porechop looks for barcodes at the start and end of each read. All barcode matches are found, and if the best match is strong enough (default 75%, change with `--barcode_threshold`) and sufficiently better than the second-best barcode match (default 5% better, change with `--barcode_diff`), then the read is assigned to that barcode bin. E.g. with default settings, if BC01 was found at 79% identity and BC02 was found at 76% identity, the read will not be assigned to a barcode bin because the results were too close. But if you used `--barcode_diff 1`, then that read _would_ be assigned to the BC01 bin.
161
162 By default, Porechop only requires a single barcode match to bin a read. If you use the `--require_two_barcodes` option, then it will be much more stringent and assess the start and end of the read independently. I.e. to be binned, the start of a read must have a good match for a barcode and the end of the read must also have a good match for the same barcode. This will result in far more reads failing to be assigned to a bin, but the reads which are assigned have a very high confidence. Note that for some library preps (e.g. the rapid barcoding kit), barcodes may only be at the start of reads, in which case the `--require_two_barcodes` option is not appropriate.
163
164 Note that the `--discard_middle` option is always active when demultiplexing barcoded reads. This is because a read with a middle adapter is likely chimeric and the pieces of chimeric reads may belong in separate bins.
165
166 Usage examples:
167 * __Default settings__:<br>
168 `porechop -i input_reads.fastq.gz -b output_dir`
169 * __Stringent binning__ (more reads in "none" bin but low risk of misclassified reads):<br>
170 `porechop -i input_reads.fastq.gz -b output_dir --barcode_threshold 85 --require_two_barcodes`
171 * __Lenient binning__ (fewer reads in "none" bin but higher risk of misclassification):<br>
172 `porechop -i input_reads.fastq.gz -b output_dir --barcode_threshold 60 --barcode_diff 1`
173
174
175 ### Barcode demultiplexing with Albacore
176
177 'What about Albacore's barcode demultiplexing?' I hear you say. 'Does this make Porechop's demultiplexing redundant?' Yes, Albacore v1.0 and later can demultiplex Nanopore reads during basecalling, which is a very nice feature. But Albacore and Porechop sometimes disagree on the appropriate bin for a read.
178
179 So if you use Albacore's output directory as input, here's what Porechop will do:
180 * Load reads from all FASTQ files it finds, noting for each read what Albacore's bin was.
181 * Call a barcode for each read using its normal demultiplexing logic.
182 * Take all reads where Porechop and Albacore disagree and put them in the 'none' bin.
183
184 For example, Albacore may have put reads into the `barcode02` directory. When Porechop trims and bins these reads, it may put 95% of them in the BC02 bin, but 4% go in the 'none' bin and 1% go into bins for other barcodes. By keeping only the 95% of reads where Albacore and Porechop agree, the risk of misclassification is reduced.
185
186
187 ### Output
188
189 If Porechop is run with the output file specified using `-o`, it will display progress info to stdout. It will try to deduce the format of the output reads using the output filename (can handle `.fastq`, `.fastq.gz`, `.fasta` and `.fasta.gz`). The `--format` option can be used to override this automatic detection.
190
191 Alternately, you can run Porechop with `-b` which specifies a directory for barcode bins. Porechop will then make separate read files in this directory for each barcode sequence (see [Barcode demultiplexing](#barcode-demultiplexing) for more details on the process). The files will be named using the barcode name or "none" if no barcode call was made (e.g. `BC01.fastq.gz`, `BC02.fastq.gz`, `none.fastq.gz`). The reads will be outputted in either `fasta`, `fastq`, `fasta.gz` or `fastq.gz` format, as determined by the input read format or the `--format` option.
192
193 If Porechop is run without `-o` or `-b`, then it will output the trimmed reads to stdout and print its progress info to stderr. The output format of the reads will be FASTA/FASTQ based on the input reads, or else can be specified using `--format`.
194
195 The `--verbosity` option will change the amount of progress info:
196 * `--verbosity 0` gives no progress output.
197 * `--verbosity 1` (default) gives summary info about end adapter trimming and middle adapter splitting.
198 * `--verbosity 2` shows the actual trimmed/split sequences for each read (described more below).
199 * `--verbosity 3` shows tons of data (mainly for debugging).
200
201
202 ### Verbose output
203
204 If you call Porechop with `--verbosity 2`, then it will display the start/end of each read show the trimming in colour. Red indicates the adapter sequence and yellow indicates additional trimmed bases:
205
206 <p align="center"><img src="misc/end_trimming.png" alt="End trimming"></p>
207
208
209 If you are [demultiplexing barcodes](#barcode-demultiplexing), then this output will also show the barcodes found at the start/end of each read, along with the final call for the read's bin:
210
211 <p align="center"><img src="misc/verbose_barcodes.png" alt="Barcodes"></p>
212
213
214 The same colour scheme is used for middle adapters, but only reads with a positive hit are displayed:
215
216 <p align="center"><img src="misc/middle_adapters.png" alt="Middle adapters"></p>
217
218
219
220 # Known adapters
221
222 The known Nanopore adapters that Porechop looks for are defined in the [adapters.py](../master/porechop/adapters.py) file.
223
224 They are:
225 * Ligation kit adapters
226 * Rapid kit adapters
227 * PCR kit adapters
228 * Barcodes
229 * Native barcoding
230 * Rapid barcoding
231
232 If you want to add your own adapter sequences to Porechop, you can do so by editing the [adapters.py](../master/porechop/adapters.py) file (instructions are in that file). And if you know of any adapter sequences that I've missed, please let me know and I'll add them!
233
234
235
236 # Full usage
237
238 ```
239 usage: porechop -i INPUT [-o OUTPUT] [--format {auto,fasta,fastq,fasta.gz,fastq.gz}] [-v VERBOSITY]
240 [-t THREADS] [-b BARCODE_DIR] [--barcode_threshold BARCODE_THRESHOLD]
241 [--barcode_diff BARCODE_DIFF] [--require_two_barcodes] [--untrimmed]
242 [--discard_unassigned] [--adapter_threshold ADAPTER_THRESHOLD]
243 [--check_reads CHECK_READS] [--scoring_scheme SCORING_SCHEME] [--end_size END_SIZE]
244 [--min_trim_size MIN_TRIM_SIZE] [--extra_end_trim EXTRA_END_TRIM]
245 [--end_threshold END_THRESHOLD] [--no_split] [--discard_middle]
246 [--middle_threshold MIDDLE_THRESHOLD]
247 [--extra_middle_trim_good_side EXTRA_MIDDLE_TRIM_GOOD_SIDE]
248 [--extra_middle_trim_bad_side EXTRA_MIDDLE_TRIM_BAD_SIDE]
249 [--min_split_read_size MIN_SPLIT_READ_SIZE] [-h] [--version]
250
251 Porechop: a tool for finding adapters in Oxford Nanopore reads, trimming them from the ends and
252 splitting reads with internal adapters
253
254 Main options:
255 -i INPUT, --input INPUT FASTA/FASTQ of input reads or a directory which will be
256 recursively searched for FASTQ files (required)
257 -o OUTPUT, --output OUTPUT Filename for FASTA or FASTQ of trimmed reads (if not set, trimmed
258 reads will be printed to stdout)
259 --format {auto,fasta,fastq,fasta.gz,fastq.gz}
260 Output format for the reads - if auto, the format will be chosen
261 based on the output filename or the input read format (default:
262 auto)
263 -v VERBOSITY, --verbosity VERBOSITY
264 Level of progress information: 0 = none, 1 = some, 2 = lots, 3 =
265 full - output will go to stdout if reads are saved to a file and
266 stderr if reads are printed to stdout (default: 1)
267 -t THREADS, --threads THREADS Number of threads to use for adapter alignment (default: 8)
268
269 Barcode binning settings:
270 Control the binning of reads based on barcodes (i.e. barcode demultiplexing)
271
272 -b BARCODE_DIR, --barcode_dir BARCODE_DIR
273 Reads will be binned based on their barcode and saved to separate
274 files in this directory (incompatible with --output)
275 --barcode_threshold BARCODE_THRESHOLD
276 A read must have at least this percent identity to a barcode to be
277 binned (default: 75.0)
278 --barcode_diff BARCODE_DIFF If the difference between a read's best barcode identity and its
279 second-best barcode identity is less than this value, it will not
280 be put in a barcode bin (to exclude cases which are too close to
281 call) (default: 5.0)
282 --require_two_barcodes Reads will only be put in barcode bins if they have a strong match
283 for the barcode on both their start and end (default: a read can
284 be binned with a match at its start or end)
285 --untrimmed Bin reads but do not trim them (default: trim the reads)
286 --discard_unassigned Discard unassigned reads (instead of creating a "none" bin)
287 (default: False)
288
289 Adapter search settings:
290 Control how the program determines which adapter sets are present
291
292 --adapter_threshold ADAPTER_THRESHOLD
293 An adapter set has to have at least this percent identity to be
294 labelled as present and trimmed off (0 to 100) (default: 90.0)
295 --check_reads CHECK_READS This many reads will be aligned to all possible adapters to
296 determine which adapter sets are present (default: 10000)
297 --scoring_scheme SCORING_SCHEME
298 Comma-delimited string of alignment scores: match, mismatch, gap
299 open, gap extend (default: 3,-6,-5,-2)
300
301 End adapter settings:
302 Control the trimming of adapters from read ends
303
304 --end_size END_SIZE The number of base pairs at each end of the read which will be
305 searched for adapter sequences (default: 150)
306 --min_trim_size MIN_TRIM_SIZE Adapter alignments smaller than this will be ignored (default: 4)
307 --extra_end_trim EXTRA_END_TRIM
308 This many additional bases will be removed next to adapters found
309 at the ends of reads (default: 2)
310 --end_threshold END_THRESHOLD Adapters at the ends of reads must have at least this percent
311 identity to be removed (0 to 100) (default: 75.0)
312
313 Middle adapter settings:
314 Control the splitting of read from middle adapters
315
316 --no_split Skip splitting reads based on middle adapters (default: split
317 reads when an adapter is found in the middle)
318 --discard_middle Reads with middle adapters will be discarded (default: reads with
319 middle adapters are split) (required for reads to be used with
320 Nanopolish, this option is on by default when outputting reads
321 into barcode bins)
322 --middle_threshold MIDDLE_THRESHOLD
323 Adapters in the middle of reads must have at least this percent
324 identity to be found (0 to 100) (default: 85.0)
325 --extra_middle_trim_good_side EXTRA_MIDDLE_TRIM_GOOD_SIDE
326 This many additional bases will be removed next to middle adapters
327 on their "good" side (default: 10)
328 --extra_middle_trim_bad_side EXTRA_MIDDLE_TRIM_BAD_SIDE
329 This many additional bases will be removed next to middle adapters
330 on their "bad" side (default: 100)
331 --min_split_read_size MIN_SPLIT_READ_SIZE
332 Post-split read pieces smaller than this many base pairs will not
333 be outputted (default: 1000)
334
335 Help:
336 -h, --help Show this help message and exit
337 --version Show program's version number and exit
338 ```
339
340
341
342 # Known issues
343
344 ### Adapter search
345
346 Porechop tries to automatically determine which adapters are present by looking at the reads, but this approach has a few issues:
347
348 * As the number of kits/barcodes has grown, adapter-search part of the Porechop's pipeline has become increasingly slow.
349 * Porechop only does the adapter search on a subset of reads, which means there can be problems with non-randomly ordered read sets (e.g. all barcode 1 reads at the start of a file, followed by barcode 2 reads, etc).
350 * Many ONT adapters share common sequence with each other, making false positive adapter finds possible.
351
352 A simpler solution (and in hindsight what I should have done) would be to require the kit and/or adapters from the user. E.g. `porechop --sqk-lsk109` or `porechop --start_adapt ACGCTAGCATACGT`.
353
354
355 ### Performance
356
357 Porechop uses [SeqAn](https://github.com/seqan/seqan) to perform its alignments in C++. This library is very flexible, but not as fast as some alternatives, such as [Edlib](https://github.com/Martinsos/edlib).
358
359 Another performance issue is that Porechop uses [ctypes](https://docs.python.org/3/library/ctypes.html) to interface with its C++ code. Function calls with ctypes can have a bit of overhead, which means that Porechop cannot use threads very efficiently (it spends too much of its time in the Python code, which is intrinsically non-parallel).
360
361
362 ### Barcode demultiplexing
363
364 I added demultiplexing to Porechop as an afterthought – it was already looking for barcodes to trim, so why not sort reads by barcodes too? This turned out to be a very useful feature, but in hindsight I think it might be simpler (and easier to maintain) if trimming and demultiplexing functionality were in separate tools.
365
366
367 ### Base-space problems
368
369 I've encountered a couple of issues where adapter sequences are not properly basecalled, resulting in inconsistent sequence. Porechop trims in base-space, so this is a somewhat intractable problem. See [issue #40](https://github.com/rrwick/Porechop/issues/40) for an example.
370
371 These have made me wonder if the adapter trimming should be done in signal-space instead, though that would be a more complex problem to solve. I hope that in the future ONT can integrate this kind of functionality directly into their basecallers.
372
373
374
375
376 # Acknowledgements
377
378 Porechop was inspired by (and largely coded during) [Porecamp Australia 2017](https://porecamp-au.github.io/). Thanks to the organisers and attendees who helped me realise that a Nanopore adapter trimmer might be a useful tool! I later met David Stoddart from Oxford Nanopore at London Calling 2017, and he helped me get many of the adapter sequences right.
379
380 Also I'd like to thank the [SeqAn](https://www.seqan.de/) developers for their great library (Porechop uses SeqAn to perform its alignments).
381
382 And of course, many thanks to [Kat Holt](https://holtlab.net/) and [Louise Judd](https://scholar.google.com.au/citations?user=eO22mYUAAAAJ&hl=en) for keeping me well supplied with Nanopore reads!
383
384
385
386 # License
387
388 [GNU General Public License, version 3](https://www.gnu.org/licenses/gpl-3.0.html)