diff --git a/R/greedyMix.R b/R/greedyMix.R
index 0b7baab..2e2b552 100644
--- a/R/greedyMix.R
+++ b/R/greedyMix.R
@@ -1,9 +1,11 @@
#' @title Clustering of individuals
#' @param data data file
-#' @param format Format of the data c("FASTA", "VCF" ,"SAM", or "GenePop")
+#' @param format Format of the data c("FASTA", "VCF" ,"BAM", or "GenePop")
#' @param verbose if \code{TRUE}, prints extra output information
#' @importFrom utils read.delim
#' @importFrom vcfR read.vcfR
+#' @references Samtools: a suite of programs for interacting
+#' with high-throughput sequencing data.
#' @export
greedyMix <- function(data, format, verbose = TRUE) {
format <- tolower(format)
@@ -12,8 +14,14 @@ greedyMix <- function(data, format, verbose = TRUE) {
} else if (format == "vcf") {
out <- vcfR::read.vcfR(data, verbose = verbose)
} else if (format == "sam") {
- stop("SAM files not yet supported." )
- # TODO #18: implement load_sam()
+ stop(
+ "SAM files not directly supported. ",
+ "Install the samtools software and execute ",
+ "'samtools view -b in_file.sam > out_file.bam' to 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." )
diff --git a/inst/ext/bam_example.bam b/inst/ext/bam_example.bam
new file mode 100644
index 0000000..853843d
Binary files /dev/null and b/inst/ext/bam_example.bam differ
diff --git a/man/greedyMix.Rd b/man/greedyMix.Rd
index 3d5fc15..b4d6bce 100644
--- a/man/greedyMix.Rd
+++ b/man/greedyMix.Rd
@@ -9,10 +9,14 @@ greedyMix(data, format, verbose = TRUE)
\arguments{
\item{data}{data file}
-\item{format}{Format of the data c("FASTA", "VCF" ,"SAM", or "GenePop")}
+\item{format}{Format of the data c("FASTA", "VCF" ,"BAM", or "GenePop")}
\item{verbose}{if \code{TRUE}, prints extra output information}
}
\description{
Clustering of individuals
}
+\references{
+Samtools: a suite of programs for interacting
+with high-throughput sequencing data.
+}
diff --git a/tests/testthat/test-greedyMix.R b/tests/testthat/test-greedyMix.R
index 9104176..490b9ec 100644
--- a/tests/testthat/test-greedyMix.R
+++ b/tests/testthat/test-greedyMix.R
@@ -46,12 +46,21 @@ df_vcf <- greedyMix(
format = "VCF",
verbose = FALSE
)
-# TODO #17: add example reading VCF
-# TODO #18: add example reading SAM
+df_bam <- greedyMix(
+ data = file.path(path_inst, "bam_example.bam"),
+ format = "BAM",
+)
# TODO #19: add example reading Genpop
test_that("Files are imported correctly", {
expect_equal(dim(df_fasta), c(5, 99))
expect_equal(dim(df_vcf), c(variants = 2, fix_cols = 8, gt_cols = 3))
+ expect_error(
+ greedyMix(
+ data = paste(path_inst, "sam_example.sam", sep="/"),
+ format = "SAM",
+ )
+ )
+ expect_equal(length(df_bam[[1]]), 13)
})
context("Linkage")