# Define some barcodes and inserts
barcodes <- c("AGGT", "TTCC", "CTGA", "GCAA")
insert <- 'ACGCAGGTTGCATATTTTAGGAAGTGAGGAGGAGGCACGGGCTCGAGCTGCGGCTGGGTCTGGGGCGCGG'
# Choose and mutate a couple of thousand barcodes
used_barcodes <- sample(barcodes,10000,replace=TRUE)
mutated_barcodes <- unlist(lapply(strsplit(used_barcodes,""), function(x) { pos <- sample(1:length(x),1); x[pos] <- sample(c("C","G","A","T"),1); return(paste(x,collapse='')) } ))
show(setequal(mutated_barcodes, used_barcodes)) # FALSE
# Construct reads (= barcodes + insert)
reads <- paste(mutated_barcodes, insert, sep='')
# Demultiplex
demultiplexed <- demultiplex(reads,barcodes,metric="hamming")
# Show correctness
show(setequal(demultiplexed, used_barcodes)) # TRUE
Run the code above in your browser using DataLab