R/clean_barracoda_data.R

clean_barracoda_data = function(x){
  if(!is.tibble(x)){
    stop("Input to clean_barracoda_data is not a tibble")
  }
  x_clean = x %>% filter(str_detect(pep.number,"original") | str_detect(pep.number,"-P\\d{1,2}-\\w{3}$")) %>%
    mutate(count.1 = ifelse(count.1==0,1,count.1))
  # In a mutation scan each position in the 9-mer peptide is substituted with
  # the remaining 19 amino acid residues. Therefore, the number of rows in the
  # cleaned data should be:
  # n_samples * 9 * 19 + n_samples
  #n_samples = x_clean %>% select(sample) %>% distinct %>% nrow
  #if( nrow(x_clean) != (n_samples * 9 * 19 + n_samples) ){
  #  stop("Unexpted number of rows in cleaned barracoda data - Check if you are analysing a mutation scan?")
  #}
  return(x_clean)
}
leonjessen/Barracoda2viz documentation built on May 28, 2019, 12:59 p.m.