TITLE: Plasmid Sequence Analysis from Long Reads
AUTHORS: David A Eccles

[DESCRIPTION]
This protocol demonstrates how to assemble reads from plasmid DNA, and generate a circularised and non-repetitive consensus sequence
 
At the moment, this protocol uses Canu to de-novo assemble high-quality single-cut reads.

Input(s): 
demultiplexed fastq files (see protocol Demultiplexing Nanopore reads with LAST). I've noticed that the default demultiplexing carried out by Guppy (at least up to v4.2.2, as used in the first version of this protocol) has issues with chimeric reads, which can affect assembly.

Output(s):
Consensus sequence per barcode as a fasta file

[BEFORE_START]
When preparing plasmid DNA for sequencing, I follow one piece of advice that Dr. Divya Mirrington (ONT) gave me about pooling: create a pooled sample with volumes that you're  confident about, then remove an aliquot from that for adding the  remaining reagents [paraphrased]. I don't do any additional cleanup for  purified plasmid DNA; they tend to sequence very well on flow cells  without that cleanup.

My key requirement for plasmid  sequencing is a concentration of >20 ng/μl (ideally by qubit or  quantus). Concentrations over 100 ng/μl should be diluted down. If the  plasmids can be diluted down to all exactly the same concentration (but  at least 20 ng/μl), or they're all similar lengths, then that makes  creating an equimolar pool much easier.

When creating the pools, I  add at least 1 μl of the the sample that I need to add the least for  (might be more if the total volume is less than 11 μl), then add the  corresponding amount of other samples to create an equimolar pool. I  then take 11 μl from the pool to be used for rapid adapter addition.

If samples are equal concentration:
Add  amounts according to the length of the plasmid divided by the length of  the shortest plasmid. For example, if there are two plasmids, one with  length 3kb and another with length 35 kb, then add 1 μl of the 3kb  plasmid, and 35/3 = 11.7 μl of the 35kb plasmid.

If plasmids are roughly equal length (i.e. less than ~10% length difference between plasmids):​
Add  amounts according to the concentration of the highest-concentration  sample divided by the concentration of the plasmid. For example, if  there are three plasmids, one with concentration 50 ng/μl, one with  concentration 35 ng/μl, and one with concentration 20 ng/μl, then add 1  μl of the 50 ng/μl plasmid, 50/35 = 1.4 μl of the 35 ng/μl plasmid, and  2.5 μl of the 20 ng/μl plasmid. The total volume of this pool will be  less than 11 μl (1 + 1.4 + 2.5 = 4.9 μl), so in this case I would triple  these volumes (3 μl; 4.2 μl; 7.5 μl) to create a pool of > 11 μl.

If samples are different concentrations and different lengths:​
Make  the sample prep easier. Use multiple flow cells for different plasmid  length ranges. Dilute higher-concentration samples down to the  lowest-concentration samples. I don't recommend trying to do both  calculations at the same time to determine added volumes because there's  a much higher chance of getting added amounts wrong, leading to wasted  samples or wasted flow cells.

If you have a sufficiently-accurate pipetting robot, a sample sheet, and someone who is comfortable with equations:​
Pre-calculate amount to add assuming 12 μl total pool volume:
ratio = length / max(length) * max(conc) / conc​
volume = ratio * 12 / sum(ratio)

[That's my guess at the right equations; please let me know if there's an error]

[STEPS]
SECTION: Read file preparation
1. Demultiplex reads as per protocol Demultiplexing Nanopore reads with LAST.

If this has been done, then the following command should produce output without errors:

 

Example output:

 

If the barcode_counts.txt file is missing, the output will look like this:

 

If one or more of the barcode-demultiplexed files are missing, the output will look something like this:

 

SECTION: Read file preparation
1.1. If reads have been demultiplexed by MinKNOW, then the following approach should work to create the right input format:


 

SECTION: Read file preparation
2. Create a directory to store results files

 

SECTION: Read file preparation
3. Determine the N50/L50 read length for each barcode. This will be used as the initial guess at the assembly size.

 
This file can be viewed to confirm the assembly lengths:

 
Example output:

 
Note: this file will be used for subsequent downstream processing. If any of these barcodes shouldn't be processed further, feel free to remove the corresponding lines from this file
SECTION: Read filitering
4. Filter out any reads that are less than half of the target read length, and determine the average quality of the remainder, keeping information on (at most) 100 of the highest-quality reads:
 
Check how successful the sequencer was at getting 100X coverage by counting lines:

 
Example output. In this case BC02 has fewer than 100 reads, so the assembly is less likely to be high-quality:

 

SECTION: Read filitering
5. Subset the original read sets to only include the high-quality long reads:

 

SECTION: Choice 1: mapping to a reference sequence
6. This protocol assumes the reference sequence has a name 'refName', and can be found at 'reference/refName.fa'. Change 'refName' here in the likely event that the sequence / file has a different name, then export the variable REFNAME to make subsequent steps easier.


 

SECTION: Choice 1: mapping to a reference sequence
7. Create a LAST index for the reference sequence:

 


SECTION: Choice 1: mapping to a reference sequence
8. 
Prepare a substitution matrix for barcode mapping. I recommend doing this by training LAST, and incorporating quality scores into the trained matrix:

 

Copy the last few lines from the output into a text file called `plasmid.mat`

Here is a matrix that I have created from plasmid reads called using the guppy super-accuracy basecaller, v5.0.13:

 
  

This matrix has a moderate penalty for opening gaps (i.e. insertions and deletions), and a lower penalty for inserting them. Insertions are slightly less likely than deletions. It has a higher penalty for A/G transition variants, and a similar penalty for C/T transition variants as other substitution penalties.
SECTION: Choice 1: mapping to a reference sequence
9. Map reads to the reference and convert to BAM format using maf-convert and samtools:

 

SECTION: Choice 1: mapping to a reference sequence
10. Split reads into forward and reverse-mapped sequences, and tally up base counts at each location:


 

SECTION: Choice 1: mapping to a reference sequence
11. Create a visualisation of the base-stomped output:

 

Example output (`results/BC02_stompPlot_reference_seq.png`):

   

SECTION: Choice 2: De-novo Canu Assembly
12. Run a Canu assembly on each read set, using default options:

 

SECTION: Choice 2: De-novo Canu Assembly
13. Trim the assembled contigs based on Canu's trim recommendations:

 

SECTION: Choice 2: De-novo Canu Assembly
14. After doing this, sometimes there are some samples that fail to assemble, especially if coverage is too low. For these samples, canu can be given a little bit more encouragement by fragmenting reads further. I have created a normalise_seqlengths.pl script that will fragment sequences so that they all have identical lengths, with an overlap length of at least a specified number of bases between the fragments. In this example, sequences are created that are 5000 bases in length (about 1/2 of the original plasmid length), with an overlap of 500 bases. The actual values for this will depend on the original plasmid length:


 
Then re-run canu with the new reads, using the same settings as before:
 
If everything worked, then the assembled contigs should now be available and trimmable: