This document gives an overview of the DNABarcodeCompatibility R package with a brief description of the set of tools that it contains. The package includes six main functions that are briefly described below with examples. These functions allow one to load a list of DNA barcodes (such as the Illumina TruSeq small RNA kits), to filter these barcodes according to distance and nucleotide content criteria, to generate sets of compatible barcode combinations out of the filtered barcode list, and finally to generate an optimized selection of barcode combinations for multiplex sequencing experiments. In particular, the package provides an optimizer function to favour the selection of compatible barcode combinations with least heterogeneity in the frequencies of DNA barcodes, and allows one to keep barcodes that are robust against substitution and insertion/deletion errors, thereby facilitating the demultiplexing step.
The DNABarcodeCompatibility package also contains:
experiment_design() allowing one to
perform all steps in one go.IlluminaIndexesRaw and
IlluminaIndexes for running and testing examples.The package deals with the three existing sequencing-by-synthesis chemistries from Illumina:
# This function is created for the purpose of the documentation
export_dataset_to_file =
function(dataset = DNABarcodeCompatibility::IlluminaIndexesRaw) {
if ("data.frame" %in% is(dataset)) {
write.table(dataset,
textfile <- tempfile(),
row.names = FALSE, col.names = FALSE, quote=FALSE)
return(textfile)
} else print(paste("The input dataset isn't a data.frame:",
"NOT exported into file"))
}The function experiment_design() uses a Shannon-entropy
maximization approach to identify a set of compatible barcode
combinations in which the frequencies of occurrences of the various DNA
barcodes are as uniform as possible. The optimization can be performed
in the contexts of single and dual barcoding. It performs either an
exhaustive or a random search of compatible DNA-barcode combinations,
depending on the size of the DNA-barcode set used, and on the number of
samples to be multiplexed.
txtfile <- export_dataset_to_file (
dataset = DNABarcodeCompatibility::IlluminaIndexesRaw
)
experiment_design(file1=txtfile,
sample_number=12,
mplex_level=3,
platform=4)
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## sample Lane Id sequence
## 1 1 1 RPI11 GGCTAC
## 2 2 1 RPI26 ATGAGC
## 3 3 1 RPI30 CACCGG
## 4 4 2 RPI22 CGTACG
## 5 5 2 RPI45 TCATTC
## 6 6 2 RPI47 TCGAAG
## 7 7 3 RPI12 CTTGTA
## 8 8 3 RPI23 GAGTGG
## 9 9 3 RPI28 CAAAAG
## 10 10 4 RPI10 TAGCTT
## 11 11 4 RPI37 CGGAAT
## 12 12 4 RPI39 CTATACtxtfile <- export_dataset_to_file (
dataset = DNABarcodeCompatibility::IlluminaIndexesRaw
)
experiment_design(file1=txtfile,
sample_number=12,
mplex_level=3,
platform=2)
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## sample Lane Id sequence
## 1 1 1 RPI13 AGTCAA
## 2 2 1 RPI36 CCAACA
## 3 3 1 RPI38 CTAGCT
## 4 4 2 RPI14 AGTTCC
## 5 5 2 RPI37 CGGAAT
## 6 6 2 RPI43 TACAGC
## 7 7 3 RPI15 ATGTCA
## 8 8 3 RPI29 CAACTA
## 9 9 3 RPI35 CATTTT
## 10 10 4 RPI19 GTGAAA
## 11 11 4 RPI27 ATTCCT
## 12 12 4 RPI28 CAAAAGtxtfile <- export_dataset_to_file (
dataset = DNABarcodeCompatibility::IlluminaIndexesRaw
)
experiment_design(file1=txtfile,
sample_number=12,
mplex_level=3,
platform=1)
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## sample Lane Id sequence
## 1 1 1 RPI13 AGTCAA
## 2 2 1 RPI16 CCGTCC
## 3 3 1 RPI39 CTATAC
## 4 4 2 RPI14 AGTTCC
## 5 5 2 RPI25 ACTGAT
## 6 6 2 RPI43 TACAGC
## 7 7 3 RPI12 CTTGTA
## 8 8 3 RPI35 CATTTT
## 9 9 3 RPI48 TCGGCA
## 10 10 4 RPI36 CCAACA
## 11 11 4 RPI41 GACGAC
## 12 12 4 RPI42 TAATCGtxtfile <- export_dataset_to_file (
dataset = DNABarcodeCompatibility::IlluminaIndexesRaw
)
experiment_design(file1=txtfile,
sample_number=12,
mplex_level=3,
platform=4,
metric = "hamming",
d = 3)
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## sample Lane Id sequence
## 1 1 1 RPI12 CTTGTA
## 2 2 1 RPI41 GACGAC
## 3 3 1 RPI44 TATAAT
## 4 4 2 RPI01 ATCACG
## 5 5 2 RPI10 TAGCTT
## 6 6 2 RPI45 TCATTC
## 7 7 3 RPI07 CAGATC
## 8 8 3 RPI18 GTCCGC
## 9 9 3 RPI21 GTTTCG
## 10 10 4 RPI05 ACAGTG
## 11 11 4 RPI20 GTGGCC
## 12 12 4 RPI29 CAACTA# Select the first half of barcodes from the dataset
txtfile1 <- export_dataset_to_file (
DNABarcodeCompatibility::IlluminaIndexesRaw[1:24,]
)
# Select the second half of barcodes from the dataset
txtfile2 <- export_dataset_to_file (
DNABarcodeCompatibility::IlluminaIndexesRaw[25:48,]
)
# Get compatibles combinations of least redundant barcodes
experiment_design(file1=txtfile1,
sample_number=12,
mplex_level=3,
platform=4,
file2=txtfile2)
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## Id Lane
## 1 RPI06 1
## 2 RPI12 1
## 3 RPI24 1
## 4 RPI05 2
## 5 RPI09 2
## 6 RPI14 2
## 7 RPI01 3
## 8 RPI08 3
## 9 RPI21 3
## 10 RPI03 4
## 11 RPI07 4
## 12 RPI22 4
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## Id Lane
## 1 RPI33 1
## 2 RPI38 1
## 3 RPI46 1
## 4 RPI37 2
## 5 RPI41 2
## 6 RPI43 2
## 7 RPI26 3
## 8 RPI42 3
## 9 RPI44 3
## 10 RPI31 4
## 11 RPI40 4
## 12 RPI47 4
## Id Lane sequence
## 1 RPI06 1 GCCAAT
## 2 RPI12 1 CTTGTA
## 3 RPI24 1 GGTAGC
## 4 RPI05 2 ACAGTG
## 5 RPI09 2 GATCAG
## 6 RPI14 2 AGTTCC
## 7 RPI01 3 ATCACG
## 8 RPI08 3 ACTTGA
## 9 RPI21 3 GTTTCG
## 10 RPI03 4 TTAGGC
## 11 RPI07 4 CAGATC
## 12 RPI22 4 CGTACG
## Id Lane sequence
## 1 RPI33 1 CAGGCG
## 2 RPI38 1 CTAGCT
## 3 RPI46 1 TCCCGA
## 4 RPI37 2 CGGAAT
## 5 RPI41 2 GACGAC
## 6 RPI43 2 TACAGC
## 7 RPI26 3 ATGAGC
## 8 RPI42 3 TAATCG
## 9 RPI44 3 TATAAT
## 10 RPI31 4 CACGAT
## 11 RPI40 4 CTCAGA
## 12 RPI47 4 TCGAAG
## sample Lane Id1 sequence1 Id2 sequence2
## 1 1 1 RPI06 GCCAAT RPI33 CAGGCG
## 2 2 1 RPI12 CTTGTA RPI38 CTAGCT
## 3 3 1 RPI24 GGTAGC RPI46 TCCCGA
## 4 4 2 RPI05 ACAGTG RPI37 CGGAAT
## 5 5 2 RPI09 GATCAG RPI41 GACGAC
## 6 6 2 RPI14 AGTTCC RPI43 TACAGC
## 7 7 3 RPI01 ATCACG RPI26 ATGAGC
## 8 8 3 RPI08 ACTTGA RPI42 TAATCG
## 9 9 3 RPI21 GTTTCG RPI44 TATAAT
## 10 10 4 RPI03 TTAGGC RPI31 CACGAT
## 11 11 4 RPI07 CAGATC RPI40 CTCAGA
## 12 12 4 RPI22 CGTACG RPI47 TCGAAG# Select the first half of barcodes from the dataset
txtfile1 <- export_dataset_to_file (
DNABarcodeCompatibility::IlluminaIndexesRaw[1:24,]
)
# Select the second half of barcodes from the dataset
txtfile2 <- export_dataset_to_file (
DNABarcodeCompatibility::IlluminaIndexesRaw[25:48,]
)
# Get compatibles combinations of least redundant barcodes
experiment_design(file1=txtfile1, sample_number=12, mplex_level=3, platform=4,
file2=txtfile2, metric="hamming", d=3)
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## Id Lane
## 1 RPI05 1
## 2 RPI16 1
## 3 RPI24 1
## 4 RPI03 2
## 5 RPI10 2
## 6 RPI15 2
## 7 RPI13 3
## 8 RPI18 3
## 9 RPI23 3
## 10 RPI02 4
## 11 RPI06 4
## 12 RPI14 4
## [1] "Theoretical max entropy: 2.48491"
## [1] "Entropy of the optimized set: 2.48491"
## Id Lane
## 1 RPI29 1
## 2 RPI38 1
## 3 RPI44 1
## 4 RPI26 2
## 5 RPI42 2
## 6 RPI46 2
## 7 RPI33 3
## 8 RPI39 3
## 9 RPI43 3
## 10 RPI27 4
## 11 RPI31 4
## 12 RPI45 4
## Id Lane sequence
## 1 RPI05 1 ACAGTG
## 2 RPI16 1 CCGTCC
## 3 RPI24 1 GGTAGC
## 4 RPI03 2 TTAGGC
## 5 RPI10 2 TAGCTT
## 6 RPI15 2 ATGTCA
## 7 RPI13 3 AGTCAA
## 8 RPI18 3 GTCCGC
## 9 RPI23 3 GAGTGG
## 10 RPI02 4 CGATGT
## 11 RPI06 4 GCCAAT
## 12 RPI14 4 AGTTCC
## Id Lane sequence
## 1 RPI29 1 CAACTA
## 2 RPI38 1 CTAGCT
## 3 RPI44 1 TATAAT
## 4 RPI26 2 ATGAGC
## 5 RPI42 2 TAATCG
## 6 RPI46 2 TCCCGA
## 7 RPI33 3 CAGGCG
## 8 RPI39 3 CTATAC
## 9 RPI43 3 TACAGC
## 10 RPI27 4 ATTCCT
## 11 RPI31 4 CACGAT
## 12 RPI45 4 TCATTC
## sample Lane Id1 sequence1 Id2 sequence2
## 1 1 1 RPI05 ACAGTG RPI29 CAACTA
## 2 2 1 RPI16 CCGTCC RPI38 CTAGCT
## 3 3 1 RPI24 GGTAGC RPI44 TATAAT
## 4 4 2 RPI03 TTAGGC RPI26 ATGAGC
## 5 5 2 RPI10 TAGCTT RPI42 TAATCG
## 6 6 2 RPI15 ATGTCA RPI46 TCCCGA
## 7 7 3 RPI13 AGTCAA RPI33 CAGGCG
## 8 8 3 RPI18 GTCCGC RPI39 CTATAC
## 9 9 3 RPI23 GAGTGG RPI43 TACAGC
## 10 10 4 RPI02 CGATGT RPI27 ATTCCT
## 11 11 4 RPI06 GCCAAT RPI31 CACGAT
## 12 12 4 RPI14 AGTTCC RPI45 TCATTCThis section guides you through the detailed API of the package with
the aim to help you build your own workflow. The package is designed to
be flexible and should be easily adaptable to most experimental
contexts, using the experiment_design() function as a
template, or building your own workflow from scratch.
The file_loading_and_checking() function loads the file
containing the DNA barcodes set and analyzes its content. In particular,
it checks that each barcode in the set is unique and uniquely identified
(removing any repetition that occurs). It also checks the homogeneity of
size of the barcodes, calculates their GC content and detects the
presence of homopolymers of length >= 3.
file_loading_and_checking(
file = export_dataset_to_file(
dataset = DNABarcodeCompatibility::IlluminaIndexesRaw
)
)
## Id sequence GC_content homopolymer
## 1 RPI01 ATCACG 50.00 FALSE
## 2 RPI02 CGATGT 50.00 FALSE
## 3 RPI03 TTAGGC 50.00 FALSE
## 4 RPI04 TGACCA 50.00 FALSE
## 5 RPI05 ACAGTG 50.00 FALSE
## 6 RPI06 GCCAAT 50.00 FALSE
## 7 RPI07 CAGATC 50.00 FALSE
## 8 RPI08 ACTTGA 33.33 FALSE
## 9 RPI09 GATCAG 50.00 FALSE
## 10 RPI10 TAGCTT 33.33 FALSE
## 11 RPI11 GGCTAC 66.67 FALSE
## 12 RPI12 CTTGTA 33.33 FALSE
## 13 RPI13 AGTCAA 33.33 FALSE
## 14 RPI14 AGTTCC 50.00 FALSE
## 15 RPI15 ATGTCA 33.33 FALSE
## 16 RPI16 CCGTCC 83.33 FALSE
## 17 RPI17 GTAGAG 50.00 FALSE
## 18 RPI18 GTCCGC 83.33 FALSE
## 19 RPI19 GTGAAA 33.33 TRUE
## 20 RPI20 GTGGCC 83.33 FALSE
## 21 RPI21 GTTTCG 50.00 TRUE
## 22 RPI22 CGTACG 66.67 FALSE
## 23 RPI23 GAGTGG 66.67 FALSE
## 24 RPI24 GGTAGC 66.67 FALSE
## 25 RPI25 ACTGAT 33.33 FALSE
## 26 RPI26 ATGAGC 50.00 FALSE
## 27 RPI27 ATTCCT 33.33 FALSE
## 28 RPI28 CAAAAG 33.33 TRUE
## 29 RPI29 CAACTA 33.33 FALSE
## 30 RPI30 CACCGG 83.33 FALSE
## 31 RPI31 CACGAT 50.00 FALSE
## 32 RPI32 CACTCA 50.00 FALSE
## 33 RPI33 CAGGCG 83.33 FALSE
## 34 RPI34 CATGGC 66.67 FALSE
## 35 RPI35 CATTTT 16.67 TRUE
## 36 RPI36 CCAACA 50.00 FALSE
## 37 RPI37 CGGAAT 50.00 FALSE
## 38 RPI38 CTAGCT 50.00 FALSE
## 39 RPI39 CTATAC 33.33 FALSE
## 40 RPI40 CTCAGA 50.00 FALSE
## 41 RPI41 GACGAC 66.67 FALSE
## 42 RPI42 TAATCG 33.33 FALSE
## 43 RPI43 TACAGC 50.00 FALSE
## 44 RPI44 TATAAT 0.00 FALSE
## 45 RPI45 TCATTC 33.33 FALSE
## 46 RPI46 TCCCGA 66.67 TRUE
## 47 RPI47 TCGAAG 50.00 FALSE
## 48 RPI48 TCGGCA 66.67 FALSEThe total number of combinations depends on the number of available
barcodes and of the multiplex level. For 48 barcodes and a multiplex
level of 3, the total number of combinations (compatible or not) can be
calculated using choose(48,3), which gives 17296
combinations. In many cases the total number of combinations can become
much larger (even gigantic), and one cannot perform an exhaustive search
(see get_random_combinations() below).
# Total number of combinations
choose(48,2)
## [1] 1128
# Load barcodes
barcodes <- DNABarcodeCompatibility::IlluminaIndexes
# Time for an exhaustive search
system.time(m <- get_all_combinations(index_df = barcodes,
mplex_level = 2,
platform = 4))
## user system elapsed
## 0.160 0.001 0.159
# Each line represents a compatible combination of barcodes
head(m)
## [,1] [,2]
## [1,] "RPI04" "RPI35"
## [2,] "RPI05" "RPI19"
## [3,] "RPI06" "RPI12"
## [4,] "RPI07" "RPI17"
## [5,] "RPI10" "RPI39"
## [6,] "RPI18" "RPI25"# Total number of combinations
choose(48,3)
## [1] 17296
# Load barcodes
barcodes <- DNABarcodeCompatibility::IlluminaIndexes
# Time for an exhaustive search
system.time(m <- get_all_combinations(index_df = barcodes,
mplex_level = 3,
platform = 4))
## user system elapsed
## 3.191 0.000 3.191
# Each line represents a compatible combination of barcodes
head(m)
## [,1] [,2] [,3]
## [1,] "RPI01" "RPI02" "RPI48"
## [2,] "RPI01" "RPI03" "RPI07"
## [3,] "RPI01" "RPI03" "RPI08"
## [4,] "RPI01" "RPI03" "RPI09"
## [5,] "RPI01" "RPI03" "RPI10"
## [6,] "RPI01" "RPI03" "RPI16"When the total number of combinations is too high, it is recommended to pick combinations at random and then select those that are compatible.
# Total number of combinations
choose(48,3)
## [1] 17296
# Load barcodes
barcodes <- DNABarcodeCompatibility::IlluminaIndexes
# Time for a random search
system.time(m <- get_random_combinations(index_df = barcodes,
mplex_level = 2,
platform = 4))
## user system elapsed
## 0.097 0.000 0.097
# Each line represents a compatible combination of barcodes
head(m)
## [,1] [,2]
## [1,] "RPI06" "RPI12"
## [2,] "RPI18" "RPI33"
## [3,] "RPI20" "RPI30"
## [4,] "RPI22" "RPI45"
## [5,] "RPI26" "RPI42"# Total number of combinations
choose(48,4)
## [1] 194580
# Load barcodes
barcodes <- DNABarcodeCompatibility::IlluminaIndexes
# Time for a random search
system.time(m <- get_random_combinations(index_df = barcodes,
mplex_level = 4,
platform = 4))
## user system elapsed
## 0.654 0.000 0.654
# Each line represents a compatible combination of barcodes
head(m)
## [,1] [,2] [,3] [,4]
## [1,] "RPI01" "RPI08" "RPI22" "RPI45"
## [2,] "RPI01" "RPI04" "RPI12" "RPI41"
## [3,] "RPI01" "RPI30" "RPI38" "RPI48"
## [4,] "RPI01" "RPI03" "RPI16" "RPI30"
## [5,] "RPI01" "RPI16" "RPI18" "RPI26"
## [6,] "RPI01" "RPI02" "RPI26" "RPI43"# Total number of combinations
choose(48,6)
## [1] 12271512
# Load barcodes
barcodes <- DNABarcodeCompatibility::IlluminaIndexes
# Time for a random search
system.time(m <- get_random_combinations(index_df = barcodes,
mplex_level = 6,
platform = 4))
## user system elapsed
## 1.123 0.000 1.124
# Each line represents a compatible combination of barcodes
head(m)
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] "RPI01" "RPI07" "RPI18" "RPI25" "RPI32" "RPI45"
## [2,] "RPI01" "RPI12" "RPI14" "RPI22" "RPI35" "RPI42"
## [3,] "RPI01" "RPI19" "RPI29" "RPI36" "RPI42" "RPI45"
## [4,] "RPI01" "RPI09" "RPI13" "RPI17" "RPI19" "RPI43"
## [5,] "RPI01" "RPI05" "RPI10" "RPI13" "RPI14" "RPI35"
## [6,] "RPI01" "RPI19" "RPI25" "RPI26" "RPI33" "RPI39"# Load barcodes
barcodes <- DNABarcodeCompatibility::IlluminaIndexes
# Perform a random search of compatible combinations
m <- get_random_combinations(index_df = barcodes,
mplex_level = 3,
platform = 4)
# Keep barcodes that are robust against one substitution error
filtered_m <- distance_filter(index_df = barcodes,
combinations_m = m,
metric = "hamming",
d = 3)
# Each line represents a compatible combination of barcodes
head(filtered_m)
## V1 V2 V3
## [1,] "RPI01" "RPI09" "RPI45"
## [2,] "RPI01" "RPI03" "RPI25"
## [3,] "RPI01" "RPI04" "RPI34"
## [4,] "RPI01" "RPI11" "RPI35"
## [5,] "RPI01" "RPI05" "RPI20"
## [6,] "RPI01" "RPI19" "RPI45"# Keep set of compatible barcodes that are robust against one substitution
# error
filtered_m <- distance_filter(
index_df = DNABarcodeCompatibility::IlluminaIndexes,
combinations_m = get_random_combinations(index_df = barcodes,
mplex_level = 3,
platform = 4),
metric = "hamming", d = 3)
# Use a Shannon-entropy maximization approach to reduce barcode redundancy
df <- optimize_combinations(combination_m = filtered_m,
nb_lane = 12,
index_number = 48)
## [1] "Theoretical max entropy: 3.58352"
## [1] "Entropy of the optimized set: 3.58352"
# Each line represents a compatible combination of barcodes and each row a lane
# of the flow cell
df
## V1 V2 V3
## [1,] "RPI09" "RPI12" "RPI46"
## [2,] "RPI04" "RPI08" "RPI17"
## [3,] "RPI02" "RPI20" "RPI30"
## [4,] "RPI27" "RPI44" "RPI45"
## [5,] "RPI33" "RPI37" "RPI43"
## [6,] "RPI01" "RPI11" "RPI23"
## [7,] "RPI07" "RPI38" "RPI42"
## [8,] "RPI06" "RPI14" "RPI40"
## [9,] "RPI03" "RPI22" "RPI31"
## [10,] "RPI18" "RPI21" "RPI34"
## [11,] "RPI24" "RPI25" "RPI29"
## [12,] "RPI05" "RPI39" "RPI47"# Keep set of compatible barcodes that are robust against multiple substitution
# and insertion/deletion errors
filtered_m <- distance_filter(
index_df = DNABarcodeCompatibility::IlluminaIndexes,
combinations_m = get_random_combinations(index_df = barcodes,
mplex_level = 3,
platform = 4),
metric = "seqlev", d = 4)
# Use a Shannon-entropy maximization approach to reduce barcode redundancy
df <- optimize_combinations(combination_m = filtered_m,
nb_lane = 12,
index_number = 48)
## [1] "Theoretical max entropy: 3.58352"
## [1] "Entropy of the optimized set: 2.12263"
# Each line represents a compatible combination of barcodes and each row a
# lane of the flow cell
df
## V1 V2 V3
## [1,] "RPI03" "RPI16" "RPI28"
## [2,] "RPI19" "RPI38" "RPI45"
## [3,] "RPI19" "RPI38" "RPI45"
## [4,] "RPI08" "RPI11" "RPI28"
## [5,] "RPI08" "RPI11" "RPI28"
## [6,] "RPI19" "RPI38" "RPI45"
## [7,] "RPI08" "RPI11" "RPI28"
## [8,] "RPI11" "RPI23" "RPI28"
## [9,] "RPI03" "RPI16" "RPI28"
## [10,] "RPI19" "RPI38" "RPI45"
## [11,] "RPI11" "RPI23" "RPI28"
## [12,] "RPI03" "RPI16" "RPI28"