R/get_mapped_barcode_indices.R

#' Find Indices of Potential Barcode Mappings
#'
#' \code{get_mapped_barcode_indices} takes a vector of barcodes and a single read, then
#' returns the indices of the barcodes that were within two hamming distance units
#' from the read.
#'
#' @param barcodes Character vector of reference sequences
#' @param read Character string with the same length as each barcode in \code{barcodes}
#' @param distance_threshold Integer specifying the Hamming distance threshold for which we want to filter barcodes
#' @return Returns a vector of integers which are the indices of barcodes within 2 Hamming distance of the read

get_mapped_barcode_indices <- function(barcodes, read, distance_threshold = 2){
  filtered_barcodes <- NULL
  for(j in 1:length(barcodes)){
    barcode <- barcodes[j]
    if(hamming(barcode, read) <= distance_threshold){
      filtered_barcodes <- c(filtered_barcodes, j)
    }
  }
  return(filtered_barcodes)
}
Benji-Wagner/SequenceMapper documentation built on June 6, 2019, 1:08 p.m.