Added SAM/BAM support (closes #18)
This commit is contained in:
parent
15f2cbcf08
commit
0cfd13b006
4 changed files with 27 additions and 6 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
#' @title Clustering of individuals
|
#' @title Clustering of individuals
|
||||||
#' @param data data file
|
#' @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
|
#' @param verbose if \code{TRUE}, prints extra output information
|
||||||
#' @importFrom utils read.delim
|
#' @importFrom utils read.delim
|
||||||
#' @importFrom vcfR read.vcfR
|
#' @importFrom vcfR read.vcfR
|
||||||
|
#' @references Samtools: a suite of programs for interacting
|
||||||
|
#' with high-throughput sequencing data. <http://www.htslib.org/>
|
||||||
#' @export
|
#' @export
|
||||||
greedyMix <- function(data, format, verbose = TRUE) {
|
greedyMix <- function(data, format, verbose = TRUE) {
|
||||||
format <- tolower(format)
|
format <- tolower(format)
|
||||||
|
|
@ -12,8 +14,14 @@ greedyMix <- function(data, format, verbose = TRUE) {
|
||||||
} else if (format == "vcf") {
|
} else if (format == "vcf") {
|
||||||
out <- vcfR::read.vcfR(data, verbose = verbose)
|
out <- vcfR::read.vcfR(data, verbose = verbose)
|
||||||
} else if (format == "sam") {
|
} else if (format == "sam") {
|
||||||
stop("SAM files not yet supported." )
|
stop(
|
||||||
# TODO #18: implement load_sam()
|
"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") {
|
} else if (format == "genepop") {
|
||||||
# TODO #19: implement load_genepop()
|
# TODO #19: implement load_genepop()
|
||||||
stop("GenePop files not yet supported." )
|
stop("GenePop files not yet supported." )
|
||||||
|
|
|
||||||
BIN
inst/ext/bam_example.bam
Normal file
BIN
inst/ext/bam_example.bam
Normal file
Binary file not shown.
|
|
@ -9,10 +9,14 @@ greedyMix(data, format, verbose = TRUE)
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{data}{data file}
|
\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}
|
\item{verbose}{if \code{TRUE}, prints extra output information}
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Clustering of individuals
|
Clustering of individuals
|
||||||
}
|
}
|
||||||
|
\references{
|
||||||
|
Samtools: a suite of programs for interacting
|
||||||
|
with high-throughput sequencing data. <http://www.htslib.org/>
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,12 +46,21 @@ df_vcf <- greedyMix(
|
||||||
format = "VCF",
|
format = "VCF",
|
||||||
verbose = FALSE
|
verbose = FALSE
|
||||||
)
|
)
|
||||||
# TODO #17: add example reading VCF
|
df_bam <- greedyMix(
|
||||||
# TODO #18: add example reading SAM
|
data = file.path(path_inst, "bam_example.bam"),
|
||||||
|
format = "BAM",
|
||||||
|
)
|
||||||
# TODO #19: add example reading Genpop
|
# TODO #19: add example reading Genpop
|
||||||
test_that("Files are imported correctly", {
|
test_that("Files are imported correctly", {
|
||||||
expect_equal(dim(df_fasta), c(5, 99))
|
expect_equal(dim(df_fasta), c(5, 99))
|
||||||
expect_equal(dim(df_vcf), c(variants = 2, fix_cols = 8, gt_cols = 3))
|
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")
|
context("Linkage")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue