-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from EvolEcolGroup/run_admixture
Run admixture
- Loading branch information
Showing
39 changed files
with
877 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
^\.github$ | ||
pkgdown/ | ||
_pkgdown.yml | ||
admixture/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ Suggests: | |
LEA, | ||
rmarkdown, | ||
readr, | ||
reticulate, | ||
testthat (>= 3.0.0), | ||
vcfR | ||
Remotes: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' Autoplots for `gt_admix` objects | ||
#' | ||
#' For `gt_admix`, the following types of plots are available: | ||
#' - `cv`: the cross-validation error for each value of `k` | ||
#' - `barplot` a standard barplot of the admixture proportions | ||
#' | ||
#' `autoplot` produces simple plots to quickly inspect an object. They are | ||
#' not customisable; we recommend that you use `ggplot2` to produce publication | ||
#' ready plots. | ||
#' | ||
#' @param object an object of class `gt_admixture` | ||
#' @param type the type of plot (one of "cv", and "boxplot") | ||
#' @param k the value of `k` to plot (for `barplot` type only) | ||
#' param repeat the repeat to plot (for `barplot` type only) | ||
#' @param run the run to plot (for `barplot` type only) | ||
#' @param ... not used. | ||
#' @returns a `ggplot2` object | ||
#' @name autoplot_gt_admix | ||
#' @export | ||
autoplot.gt_admix <- function(object, | ||
type=c("cv", "barplot"), | ||
k = NULL, | ||
run = NULL, | ||
...) | ||
{ | ||
type <- match.arg(type) | ||
if (type== "cv") { | ||
if (is.null(object$cv)){ | ||
stop("No cross validation error available") | ||
} | ||
ggplot2::ggplot(data.frame(k=object$k, cv=object$cv), ggplot2::aes(x=.data$k, y=.data$cv)) + | ||
ggplot2::geom_point() + | ||
ggplot2::geom_line() + | ||
ggplot2::labs(x="k", y="Cross validation error") | ||
} else if (type == "barplot") { | ||
# check that k is specified | ||
if (is.null(k)){ | ||
stop("You must specify a value for k") | ||
} | ||
# check that run is specified | ||
if (is.null(run)){ | ||
stop("You must specify a value for repeat") | ||
} | ||
# get the Q matrix for the specified k and repeat | ||
Q <- get_q_matrix(object, k = k, run = run) | ||
autoplot(Q) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#' Combine method for gt_admix objects | ||
#' | ||
#' @param ... A list of `gt_admix` objects | ||
#' @return A `gt_admix` object with the combined data | ||
#' @export | ||
|
||
c.gt_admix <- function(...) { | ||
# check that all the objects are of class gt_admix | ||
if (!all(sapply(list(...), function(x) inherits(x, "gt_admix")))) { | ||
stop("All the objects must be of class gt_admix") | ||
} | ||
|
||
combined_obj <- list() | ||
# combine all the elements from each list | ||
combined_obj$k <- sapply(list(...), function(x) x$k) | ||
combined_obj$Q <- sapply(list(...), function(x) x$Q) | ||
# if we have a P element in any of the objects, combine it | ||
if (all(sapply(list(...), function(x) !is.null(x$P)))) { | ||
combined_obj$P <- sapply(list(...), function(x) x$P) | ||
} | ||
# if we have a log_lik element in any of the objects, combine it | ||
if (all(sapply(list(...), function(x) !is.null(x$loglik)))) { | ||
combined_obj$loglik <- unlist(sapply(list(...), function(x) x$loglik)) | ||
} | ||
|
||
# if we have a log element in any of the objects, combine it | ||
if (all(sapply(list(...), function(x) !is.null(x$log)))) { | ||
combined_obj$log <- sapply(list(...), function(x) x$log) | ||
} | ||
# if we have a cv element in any of the objects, combine it | ||
if (all(sapply(list(...), function(x) !is.null(x$cv)))) { | ||
combined_obj$cv <- unlist(sapply(list(...), function(x) x$cv)) | ||
} | ||
# if the first object has an id element, use it in the combined object | ||
if (!is.null(list(...)[[1]]$id)) { | ||
combined_obj$id <- list(...)[[1]]$id | ||
} | ||
# if the first object has a group element, use it in the combined object | ||
if (!is.null(list(...)[[1]]$group)) { | ||
combined_obj$group <- list(...)[[1]]$group | ||
} | ||
# set the class of the object | ||
class(combined_obj) <- c("gt_admix", "list") | ||
return(combined_obj) | ||
} | ||
|
||
#' Summary method for gt_admix objects | ||
#' | ||
#' @param object a `gt_admix` object | ||
#' @param ... unused (necessary for compatibility with generic function) | ||
#' @return A summary of the `gt_admix` object | ||
#' @export | ||
summary.gt_admix <- function(object, ...) { | ||
cat("Admixture results") | ||
# if we only have one element, give the k | ||
if (length(object$k) == 1) { | ||
cat(" for k = ", object$k, "\n") | ||
} else { | ||
tab_sum <- table(object$k) | ||
tab_sum <- rbind(as.numeric(names(tab_sum)),tab_sum) | ||
rownames(tab_sum) <- c("k", "n") | ||
colnames(tab_sum) <- rep("", ncol(tab_sum)) | ||
cat(" for multiple runs:") | ||
print(tab_sum) | ||
} | ||
cat("with slots:\n") | ||
cat("$Q for Q matrices\n") | ||
# if there is a lot P in the object, print it | ||
if ("P" %in% names(object)){ | ||
cat("$P for matrices\n") | ||
} | ||
# if there is a slot log in the object, print it | ||
if ("log" %in% names(object)){ | ||
cat("$log for logs from the algorithm\n") | ||
} | ||
# if there is a slot cv in the object, print it | ||
if ("cv" %in% names(object)){ | ||
cat("$cv for cross validation error\n") | ||
} | ||
} |
Oops, something went wrong.