R/extractEMBOSS_tsv.R

Defines functions extractEMBOSS_tsv

Documented in extractEMBOSS_tsv

#' A function to convert EMBOSS raw tsv output into a nice & tidy DataFrame.
#'
#' @param table_raw EMBOSS output tsv
#' @param colname  A string with the new variable name (usually the name of the program)
#' @param names A string with the name of the col containing the SeqName
#'
#' @return It returns a DataFrame containing the results in a 'tidy' format.
#' @export
#'
extractEMBOSS_tsv <- function(table_raw, colname, names = "SeqName"){
  ## Check arguments
  if(!is.data.frame(table_raw))
    stop("'table_raw' should be a data.frame")
  if(!is.character(colname))
    stop("'colname' should be character")

  table_raw %>%
    dplyr::group_by(dplyr::across(names))%>%
    dplyr::mutate(row_number = dplyr::row_number()) %>%
    dplyr::ungroup()%>%
    dplyr::mutate(col_tmp = glue::glue("{colname}.{row_number}")) %>%
    dplyr::select(-c("row_number")) %>%
    tidyr::pivot_wider(names_from = col_tmp,
                       values_from = -c(col_tmp, names))
}
currocam/FascinRSCA documentation built on March 21, 2022, 6:29 a.m.