R/decode_quality_scores.R

Defines functions decode_quality_scores

Documented in decode_quality_scores

#' Decode DNA Sequence Quality Scores
#'
#' Decodes Phred quality scores in Sanger format from symbols to numeric values.
#' @param symbols A string containing quality scores encoded as symbols in Sanger format.
#' @returns A numeric vector of Phred quality scores.
#' @examples
#' decode_quality_scores(symbols="989!.C;F@\"")
#' @export
decode_quality_scores<-function(symbols){
  # Throw an error if symbols is not a character string.
  if(!is.character(symbols)) stop("Symbols must be a character string.")
  # Throw an error if the length of the symbols character string is not one.
  if(length(symbols)!=1) stop("Symbols must be a character string of length 1.")
  # Decode quality scores from symbols to numeric values.
  scores_numeric<-as.numeric(charToRaw(x=symbols))-33
  # Return the numeric quality scores.
  return(scores_numeric)
}

Try the LocaTT package in your browser

Any scripts or data that you put into this service are public.

LocaTT documentation built on Nov. 2, 2023, 6:09 p.m.