#' Multispecies Coalescent Model Quartet Package
#'
#' A package for analyzing quartets displayed on gene trees, under the
#' multispecies coalescent (MSC) model and network multispecies coalescet model (NMSC).
#'
#' @details
#' This package contains routines to analyze a collection of gene trees through the displayed
#' quartets on them.
#'
#' A quartet count concordance factor (qcCF) for a set of 4 taxa is the triple of counts of the three
#' possible resolved quartet trees on those taxa across some set of gene trees. The major routines in this package can:
#' \enumerate{
#' \item Tabulate all qcCFs for a collection of gene trees.
#' \item Perform hypothesis tests of whether one or more qcCFs are consistent with the MSC model on
#' a species tree \insertCite{MAR19}{MSCquartets}.
#' \item Produce simplex plots showing all estimated CFs as well as results of hypothesis tests \insertCite{AMR2020}{MSCquartets}.
#' \item Infer a species tree using the qcCFs via the QDC and WQDC methods \insertCite{Rho19,YR19}{MSCquartets}.
#' \item Infer a level-1 species network via the NANUQ method \insertCite{ABR19}{MSCquartets}.
#' \item Infer the tree of blobs for a species network via the TINNiK or ECToBlob methods \insertCite{ABMR22}{MSCquartets},\insertCite{ABMR24}{MSCquartets}\insertCite{ECTo2026}{MSCquartets}.
#' \item Resolove multifurcations in a tree of blobs to cycles via NANUQ+ routines \insertCite{ABRW25}{MSCquartets}.
#' }
#'As discussed in the cited works, the inference methods for species trees and networks are
#'statistically consistent under the MSC and Network MSC respectively.
#'
#'This package, and the theory on which it is based, allows gene trees to have
#'missing taxa (i.e., not all gene trees display all the taxa). It does require
#'that each subset of 4 taxa is displayed on at least one of the gene trees.
#'
#'
#' Several gene tree data sets, simulated and empirical, are included.
#'
#' In publications please cite the software announcement \insertCite{RBMA2020}{MSCquartets}, as well as the
#' appropriate paper(s) above developing the theory behind the routines you used.
#'
#' @references
#'
#' \insertRef{RBMA2020}{MSCquartets}
#'
#' \insertRef{MAR19}{MSCquartets}
#'
#' \insertRef{AMR2020}{MSCquartets}
#'
#' \insertRef{Rho19}{MSCquartets}
#'
#' \insertRef{YR19}{MSCquartets}
#'
#' \insertRef{ABR19}{MSCquartets}
#'
#' \insertRef{ABMR22}{MSCquartets}
#'
#' \insertRef{ABMR24}{MSCquartets}
#'
#' \insertRef{ABRW25}{MSCquartets}
#'
#' \insertRef{ECTo2026}{MSCquartets}
#'
#' @importFrom graphics hist legend mtext par plot points segments text
#' @importFrom stats chisq.test dmultinom pchisq qnorm var na.omit pcauchy
#' @importFrom Rdpack reprompt
#' @importFrom Rcpp sourceCpp
#'
#' @useDynLib MSCquartets
#'
"_PACKAGE"
NULL





#' Yeast gene tree dataset
#'
#' A text file dataset for Yeast containing 106 gene trees on 8 taxa  (7 Saccharomyces and 1 Candida outgroup). This is a subset of the data
#' of \insertCite{Rokas03;textual}{MSCquartets}.
#'
#' @docType data
#'
#' @name dataYeastRokas
#'
#' @references \insertRef{Rokas03}{MSCquartets}
#'
#' @details File is accessed as \code{system.file("extdata","dataYeastRokas",package="MSCquartets")}, for example
#' via the \code{ape} command:
#'
#' \code{ gts=read.tree(file = system.file("extdata","dataYeastRokas",package="MSCquartets"))}
#'
#' @format A text file with 106 topological Newick gene trees on the taxa:
#'  Sbay, Scas, Scer, Sklu, Skud, Smik, Spar, and Calb (outgroup).
#'
#' @source from L. Nakhleh's website at Rice U., link no longer available as of 2026
NULL

#' pTable for Yeast dataset
#'
#' An .rda file dataset for the "dataYeastRokas" dataset. This is a subset of the data
#' of \insertCite{Rokas03;textual}{MSCquartets}.
#'
#' @docType data
#'
#' @name pTableYeastRokas
#'
#' @usage data(pTableYeastRokas)
#'
#' @references \insertRef{Rokas03}{MSCquartets}
#'
#' @details This is provided primarily so that examples of other functions run more quickly. It can be reproduced by the following
#' example code below.
#'
#' @examples
#' \donttest{
#' gtrees=read.tree(file = system.file("extdata","dataYeastRokas",package="MSCquartets"))
#' QT=quartetTable(gtrees)
#' RQT=quartetTableResolved(QT)
#' pTable=quartetCutTestInd(RQT)
#' pTable=quartetTreeTestInd(pTable)
#' pTableYeastRokas=quartetStarTestInd(pTable)
#' }
#' @format an R data file
#'
#' @source from L. Nakhleh's website at Rice U., link no longer available as of 2026
"pTableYeastRokas"



#' Papionini gene tree dataset
#'
#' A text file dataset for Papionini containing 1730 gene trees on 7 taxa. This is a subset of the data of \insertCite{Vanderpool2020;textual}{MSCquartets}.
#'
#' @references \insertRef{Vanderpool2020}{MSCquartets}
#'
#' @docType data
#'
#' @name dataPapioniniVanderpool
#'
#' @details File is accessed as \code{system.file("extdata","dataPapioniniVanderpool",package="MSCquartets")}, for
#' example via the \code{ape} command:
#'
#' \code{gts = read.tree(file=system.file("extdata","dataPapioniniVanderpool",package="MSCquartets"))}
#'
#' @format A text file with 1703 metric Newick gene trees each with 7 leaves labelled:\cr
#' Cercocebus_atys, Mandrillus_leucophaeus, Papio_anubis, Theropithecus_gelada,
#' Macaca_fascicularis, Macaca_mulatta, Macaca_nemestrina
#'
#' @source \doi{10.5061/dryad.rfj6q577d}
#'
NULL

#' Simulated gene tree dataset from species tree
#'
#' A text file dataset containing 1000 gene trees on 9 taxa simulated under the MSC on a species tree
#'
#' @details This simulated dataset was produced by SimPhy \insertCite{simphy}{MSCquartets}, using the species tree
#'
#' ((((t5:5000,t6:5000):5000,t4:10000):2500,t7:12500):7500,((t8:3000,t9:3000):5000,\cr
#' ((t1:4000,t2:4000):2500,t3:6500):1500):12000);
#'
#' with a population size of 10,000 throughout the tree.
#'
#' @docType data
#'
#' @name dataGeneTreeSample
#'
#' @details File is accessed as  \code{system.file("extdata","dataGeneTreeSample",package="MSCquartets")}, for example
#' via the ape command:
#'
#' \code{gts=read.tree(file = system.file("extdata","dataGeneTreeSample",package="MSCquartets") )}
#'
#' @format A text file with 1000 metric Newick gene trees on the taxa t1-t9
#'
#' @references
#' \insertRef{simphy}{MSCquartets}
#'
NULL



#' Quartet table for Heliconius gene tree dataset
#'
#' An .rda file containing a quartet table summarizing the "Heliconius" gene trees
#' of \insertCite{Martin2013;textual}{MSCquartets}. This table contains quartet counts
#' from 2909 gene trees on 7 taxa, with 4 individuals sampled for each of 3 of the taxa,
#' for a total of 16 leaves per gene tree.
#'
#' @docType data
#'
#' @name tableHeliconiusMartin
#'
#' @usage data(tableHeliconiusMartin)
#'
#' @references \insertRef{Martin2013}{MSCquartets}
#'
#' @details This table is provided rather than the original gene trees to save storage space.
#' If used, please cite \insertCite{Martin2013;textual}{MSCquartets}.
#'
#' @source \doi{10.5061/dryad.dk712}
#'
#' @format an R data file
"tableHeliconiusMartin"


#' Quartet table for Leopardus dataset
#'
#' An .rda file containing a quartet table summarizing the "Leopardus" gene trees
#' of \insertCite{Lescroart2023;textual}{MSCquartets}. This table contains quartet counts
#' for 16,338 "gene" trees for 16 taxa, inferred from sliding widows across
#' genomic sequences.
#'
#' @docType data
#'
#' @name tableLeopardusLescroart
#'
#' @usage data(tableLeopardusLescroart)
#'
#' @references \insertRef{Lescroart2023}{MSCquartets}
#'
#' @details This table is provided rather than the original gene trees to save storage space.
#' If used, please cite \insertRef{Lescroart2023}{MSCquartets}.
#'
#' @format an R data file
"tableLeopardusLescroart"

#' ASTRAL tree for Leopardus dataset
#'
#' An .rda file containing the tree produced by ASTRAL from the "Leopardus" gene trees
#' of \insertCite{Lescroart2023;textual}{MSCquartets}. By the theory of \insertCite{ECTo2026}{MSCquartets}, 
#' this is a putative resolution of the tree of blobs for the unknown network, 
#' and can be used by \code{ECToBlob} to infer the network's tree of blobs.
#'
#' @docType data
#'
#' @name ASTRALtreeLeopardusLescroart
#'
#' @usage data(ASTRALtreeLeopardusLescroart)
#'
#' @references \insertRef{Lescroart2023}{MSCquartets}, \insertRef{ECTo2026}{MSCquartets}
#'
#' @details If used for purposes other than learning software, please cite \insertRef{Lescroart2023}{MSCquartets}.
#'
#' @format an R data file
"ASTRALtreeLeopardusLescroart"
