Scripts/How to use Demultiplexing script

From Taiwan beetles
Jump to navigationJump to search

When using Oxford Nanopore or Illumina, we mix (pool) many samples into a single library. After sequencing, we need to sort the reads (the sequenced DNA pieces) back to the original samples. This is called demultiplexing. To do so, we use short sample-specific 13-letter tags that we attached to the end of each sequeced piece. Hence, for demultiplexing, we need the list of all samples and sequences of their primers and sample-specific tags. This is what this script is preparing.

The script takes the following data:

  • position of each sample (in which plate and where on that plate)
  • forward primer used in that plate
  • position of tagged reverse primers in the plate
  • sequence of each primer and its unique tag

and combines all this data into the list that gives

  • name of the sample
  • sequence and tag of its forward primer
  • sequence and tag of its reverse primer


Script and example files to download

You can download the script here.

Example file with data in a needed format: Data_for_demultiplex_EXAMPLE.xlsx

Example of the final demultiplexing file: Demultiplex_EXAMPLE.txt


Loading data and adapting the script

To load the data in, you can:

  • export the data prepared in Excel to tab-delimited text file and import it using the read.table function with specified file name
  • select the part of the table in Excel and copy it to clipboard by Ctrl+C, and then import the clipboard using the read.table function with file="clipboard"


Demultiplexing needs filtering read by length, so in case you had library combining different amplicon lengths, you need to demultiplex each size separately. This is done by the second row after reading the list of plates, modify the number to the needed size. For such a filtering by size, you need to have the amplicon size indicated for each plate in the colum Length.

List_of_Plates <- read.table(file="clipboard", header=TRUE, sep="\t")
List_of_Plates658 <- List_of_Plates[List_of_Plates$Length==658,]

If you only have one amplicon size, skip the rows with size selection.


Before export, modify the name of the exported file: write.table(demultiplex, file="your_file_name.txt", quote=FALSE, sep=",", row.names=FALSE, col.names=FALSE)


The code has several checks to prevent downstream problems. Pay attantion to each error or conflict, find the reason and resolve it.


Structure of needed files

List of plates

Overview of sequencing plates with their names, amplicon lengths, and assigned forward primers.

Plate maps

Layout of samples across plates, showing which sample code occupies each well position (A1–H12). The plate name in top-left corner or each plate needs to be the same as plate name in the list of plates!

Reverse primer map

Map of tagged reverse primers assigned to each well position across the plate.

List of primers

Full primer list including tag sequences, basic primer sequences, and the combined tagged primer sequences used for demultiplexing.

Structure of the final demultiplexing file

A text file with five columns:

  1. Sample name
  2. fwd primer barcode (= tag)
  3. rev primer barcode (= tag)
  4. fwd primer sequence
  5. rev primer sequence

The file MUST NOT have column names!