R/read.breseq.gd.R

Defines functions read.breseq.gd

#'
#' @export
#' @author Alessandro Brozzi
#' @param a file with extension .gd
#' @return a list of one item "SNP" containing a dataframe with data extracted from SNP lines
#' @example read.breseq.gd("inst/SNP.gd")
#'
read.breseq.gd <- function(file.gd) {

  RES = list()

  types = c("SNP", "SUB", "DEL", "INS", "MOB", "AMP", "CON", "INV", "RA", "MC", "JC", "UN", "TSEQ", "PFLP", "RFLP", "PFGE", "PHYL", "CURA")

  fileOuts = c()

    for (ty in types) {

      fileOut = paste0(tempfile(), "_", ty)

      system(paste0("grep ^", ty, " ", file.gd, " > ", fileOut))

      fileOuts = c(fileOuts,fileOut)
  }

  for ( file in fileOuts ) {

    type = unlist(strsplit(basename(file),"_"))[2]

    if(type=="SNP") {

      RES[["SNP"]] = readSNP(file)

    } else { RES[[type]] = NULL}

  }

  return(RES)

}
abrozzi/microbio documentation built on Feb. 8, 2021, 11:34 a.m.