42 lines
1.5 KiB
R
42 lines
1.5 KiB
R
#' @title Clustering of individuals
|
|
#' @param data data file
|
|
#' @param format Data format. Format supported: "FASTA", "VCF" ,"BAM", "GenePop"
|
|
#' @param verbose if \code{TRUE}, prints extra output information
|
|
#' @importFrom utils read.delim
|
|
#' @importFrom vcfR read.vcfR
|
|
#' @importFrom Rsamtools scanBam
|
|
#' @references Samtools: a suite of programs for interacting
|
|
#' with high-throughput sequencing data. <http://www.htslib.org/>
|
|
#' @export
|
|
greedyMix <- function(data, format, verbose = TRUE) {
|
|
# Parsing data format ------------------------------------------------------
|
|
|
|
if (missing(format)) {
|
|
format <- gsub(".*\\.(.+)$", "\\1", data)
|
|
message("Format not provided. Guessing from file extension: ", format)
|
|
}
|
|
format <- tolower(format)
|
|
|
|
# Dispatching to proper loading function -----------------------------------
|
|
|
|
if (format == "fasta") {
|
|
out <- load_fasta(data)
|
|
} else if (format == "vcf") {
|
|
out <- vcfR::read.vcfR(data, verbose = verbose)
|
|
} else if (format == "sam") {
|
|
stop(
|
|
"SAM files not directly supported. ",
|
|
"Install the samtools software and execute\n\n",
|
|
"samtools view -b ", data, " > out_file.bam\n\nto convert to BAM ",
|
|
"and try running this function again with 'format=BAM'"
|
|
)
|
|
} else if (format == "bam") {
|
|
out <- Rsamtools::scanBam(data)
|
|
} else if (format == "genepop") {
|
|
# TODO #19: implement load_genepop()
|
|
stop("GenePop files not yet supported.")
|
|
} else {
|
|
stop("Format not supported.")
|
|
}
|
|
return(out)
|
|
}
|