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
|
2022-01-27 11:16:32 +01:00
|
|
|
#' @importFrom adegenet read.genepop .readExt
|
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
|
2023-08-09 10:54:48 +02:00
|
|
|
#' @examples
|
|
|
|
|
#' data <- system.file("extdata", "FASTA_clustering_haploid.fasta", package = "rBAPS")
|
2023-08-09 13:13:16 +02:00
|
|
|
#' greedyMix(data, "fasta")
|
2023-08-09 12:06:09 +02:00
|
|
|
greedyMix <- function(
|
2023-08-09 13:13:50 +02:00
|
|
|
data, format, partitionCompare, ninds, rowsFromInd, noalle,
|
2023-08-09 12:50:29 +02:00
|
|
|
adjprior, priorTerm, alleleCodesinp, popnames, fixedK = FALSE,
|
|
|
|
|
partition_compare = FALSE, verbose = TRUE
|
2023-08-09 12:06:09 +02:00
|
|
|
) {
|
|
|
|
|
# Importing and handling data ================================================
|
2023-08-09 12:50:29 +02:00
|
|
|
data <- importFile(data, format, verbose)
|
2023-08-09 11:26:29 +02:00
|
|
|
|
2023-08-09 12:06:09 +02:00
|
|
|
if (partition_compare) {
|
|
|
|
|
logmls <- comparePartitions(
|
2023-08-09 13:13:50 +02:00
|
|
|
data, nrows(data), partitionCompare[["partitions"]], ninds, rowsFromInd,
|
|
|
|
|
noalle, adjprior
|
2023-08-09 12:06:09 +02:00
|
|
|
)
|
2023-08-09 11:26:29 +02:00
|
|
|
}
|
2023-08-09 13:13:50 +02:00
|
|
|
|
|
|
|
|
|
2023-08-09 12:06:09 +02:00
|
|
|
# Generating partition summary ===============================================
|
2023-08-09 13:12:18 +02:00
|
|
|
logml_npops_partitionSummary <- indMixWrapper(data, npops, fixedK);
|
2023-08-09 12:06:09 +02:00
|
|
|
logml <- logml_npops_partitionSummary[["logml"]]
|
|
|
|
|
npops <- logml_npops_partitionSummary[["npops"]]
|
|
|
|
|
partitionSummary <- logml_npops_partitionSummary[["partitionSummary"]]
|
2023-08-09 11:26:29 +02:00
|
|
|
stopifnot(logml != 1)
|
|
|
|
|
|
2023-08-09 12:06:09 +02:00
|
|
|
# Writing mixture info =======================================================
|
|
|
|
|
changesInLogml <- writeMixtureInfo(
|
|
|
|
|
logml, rowsFromInd, data, adjprior, priorTerm, NULL, inp, partitionSummary,
|
|
|
|
|
popnames, fixedK
|
|
|
|
|
)
|
2023-08-09 11:26:29 +02:00
|
|
|
|
2023-08-09 12:06:09 +02:00
|
|
|
# Returning results ==========================================================
|
|
|
|
|
return(
|
|
|
|
|
list(
|
|
|
|
|
"alleleCodes" = alleleCodes, "adjprior" = adjprior, "popnames" = popnames,
|
|
|
|
|
"rowsFromInd" = rowsFromInd, "data" = data, "npops" = npops,
|
|
|
|
|
"noalle" = noalle, "mixtureType" = "mix", "logml" = logml,
|
|
|
|
|
"changesInLogml" = changesInLogml
|
|
|
|
|
)
|
|
|
|
|
)
|
2023-08-09 11:26:29 +02:00
|
|
|
|
2021-11-10 14:02:35 +01:00
|
|
|
}
|