2020-05-20 15:34:40 +02:00
|
|
|
#' @title Clustering of individuals
|
2021-09-03 08:43:37 +02:00
|
|
|
#' @param data data file
|
2021-09-03 13:08:40 +02:00
|
|
|
#' @param format Data format. Format supported: "FASTA", "VCF" ,"BAM", "GenePop"
|
2021-09-03 11:10:06 +02:00
|
|
|
#' @param verbose if \code{TRUE}, prints extra output information
|
2020-06-24 11:48:23 +02:00
|
|
|
#' @importFrom utils read.delim
|
2021-09-03 11:17:00 +02:00
|
|
|
#' @importFrom vcfR read.vcfR
|
2021-09-03 12:56:00 +02:00
|
|
|
#' @importFrom Rsamtools scanBam
|
2021-09-03 12:50:11 +02:00
|
|
|
#' @references Samtools: a suite of programs for interacting
|
|
|
|
|
#' with high-throughput sequencing data. <http://www.htslib.org/>
|
2020-05-20 15:34:40 +02:00
|
|
|
#' @export
|
2021-09-03 11:10:06 +02:00
|
|
|
greedyMix <- function(data, format, verbose = TRUE) {
|
2021-11-10 14:02:35 +01:00
|
|
|
# Parsing data format ------------------------------------------------------
|
2021-09-03 13:08:40 +02:00
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
if (missing(format)) {
|
|
|
|
|
format <- gsub(".*\\.(.+)$", "\\1", data)
|
|
|
|
|
message("Format not provided. Guessing from file extension: ", format)
|
|
|
|
|
}
|
|
|
|
|
format <- tolower(format)
|
2021-09-03 13:08:40 +02:00
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
# Dispatching to proper loading function -----------------------------------
|
2021-09-03 13:08:40 +02:00
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
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)
|
|
|
|
|
}
|