Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run admixture #67

Merged
merged 41 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7c68a0b
initial implementation of gt_admixture
dramanica Oct 10, 2024
e2dda72
clean up
dramanica Oct 19, 2024
29db179
clean up
dramanica Oct 19, 2024
06ade82
draft code to update bim and fam according to gen_tibble
dramanica Nov 20, 2024
5aed539
updates to gt_as_plink
eviecarter33 Nov 22, 2024
033a892
add reticulate to suggests
eviecarter33 Nov 22, 2024
2b901d8
Merge branch 'main' into run_admixture
dramanica Nov 22, 2024
bcd0c7a
admixture functionality
dramanica Nov 22, 2024
f0286e9
draft working admixture implementation
dramanica Nov 22, 2024
5f8ad25
format admixture output
dramanica Nov 25, 2024
3cb5486
fix typo
dramanica Nov 26, 2024
eec4d28
Change q_matrix to a read_q_files and as_q_matrix to q_matrix, change…
eviecarter33 Nov 27, 2024
88ea01f
update .yml for site
eviecarter33 Nov 27, 2024
cec2eea
extract cv if we run crossvalidation
dramanica Nov 29, 2024
73a2751
allow for multiple k and repeats in gt_admixture
dramanica Dec 5, 2024
e0452bf
autoplot for gt_admix object
dramanica Dec 5, 2024
07d6b3a
respect metadata
dramanica Dec 6, 2024
d3b2e9d
minor edits
dramanica Dec 6, 2024
56cec3d
make gt_admixture self-standing
dramanica Dec 7, 2024
49d0125
download admixture in linux ci
dramanica Dec 8, 2024
8e8ca08
run CI
dramanica Dec 8, 2024
04e069d
Merge branch 'main' into run_admixture
dramanica Dec 8, 2024
6ae2c2a
fix multiline
dramanica Dec 8, 2024
4933251
debug ci
dramanica Dec 8, 2024
c56c1d0
diagnostics
dramanica Dec 8, 2024
7a298a2
Use magic command for path
dramanica Dec 8, 2024
f436c6f
fix warnings
dramanica Dec 8, 2024
38eaab7
more testing
dramanica Dec 8, 2024
507dbf8
testing ci
dramanica Dec 8, 2024
227d147
ci
dramanica Dec 8, 2024
e82839a
fix path
dramanica Dec 8, 2024
95a44ab
fix man page
dramanica Dec 8, 2024
af315ca
fix manpage
dramanica Dec 8, 2024
5c8f8bc
path diagnostics
dramanica Dec 9, 2024
40efed1
copy to directory in path
dramanica Dec 9, 2024
44fca73
create missing dir
dramanica Dec 9, 2024
53aa873
fix pkgdown
dramanica Dec 9, 2024
26da9b7
fix website
dramanica Dec 9, 2024
a92f614
fix test condition
dramanica Dec 9, 2024
891c595
test admixture with coverage
dramanica Dec 9, 2024
a2c1302
fix typo
dramanica Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
^\.github$
pkgdown/
_pkgdown.yml
admixture/
13 changes: 12 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main]
branches: [main, run_admixture]
pull_request:
branches: [main]

Expand Down Expand Up @@ -46,6 +46,17 @@ jobs:
extra-packages: any::rcmdcheck
needs: check

- name: Get ADMIXTURE for linux
if: matrix.config.os == 'ubuntu-latest'
run: |
mkdir admixture
cd admixture
wget https://dalexander.github.io/admixture/binaries/admixture_linux-1.3.0.tar.gz
tar -xvzf admixture_linux-1.3.0.tar.gz
cd ..
echo "$PWD/admixture/dist/admixture_linux-1.3.0" >> "$GITHUB_PATH"


- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ jobs:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Get ADMIXTURE for linux
run: |
mkdir admixture
cd admixture
wget https://dalexander.github.io/admixture/binaries/admixture_linux-1.3.0.tar.gz
tar -xvzf admixture_linux-1.3.0.tar.gz
cd ..
echo "$PWD/admixture/dist/admixture_linux-1.3.0" >> "$GITHUB_PATH"


- name: Test coverage
run: |
cov <- covr::package_coverage(
Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Suggests:
LEA,
rmarkdown,
readr,
reticulate,
testthat (>= 3.0.0),
vcfR
Remotes:
Expand Down
6 changes: 5 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ S3method(augment,gt_dapc)
S3method(augment,gt_pca)
S3method(augment,q_matrix)
S3method(augment_loci,gt_pca)
S3method(autoplot,gt_admix)
S3method(autoplot,gt_cluster_pca)
S3method(autoplot,gt_dapc)
S3method(autoplot,gt_pca)
S3method(autoplot,gt_pcadapt)
S3method(autoplot,q_matrix)
S3method(autoplot,qc_report_indiv)
S3method(autoplot,qc_report_loci)
S3method(c,gt_admix)
S3method(count_loci,tbl_df)
S3method(count_loci,vctrs_bigSNP)
S3method(dplyr_col_modify,grouped_gen_tbl)
Expand Down Expand Up @@ -72,7 +74,7 @@ S3method(show_loci,tbl_df)
S3method(show_loci,vctrs_bigSNP)
S3method(show_ploidy,tbl_df)
S3method(show_ploidy,vctrs_bigSNP)
S3method(summary,q_matrix_list)
S3method(summary,gt_admix)
S3method(summary,rbind_report)
S3method(summary,vctrs_bigSNP)
S3method(tbl_sum,gen_tbl)
Expand All @@ -90,6 +92,7 @@ export(filter_high_relatedness)
export(gen_tibble)
export(get_p_matrix)
export(get_q_matrix)
export(gt_admixture)
export(gt_as_genind)
export(gt_as_genlight)
export(gt_as_geno_lea)
Expand Down Expand Up @@ -140,6 +143,7 @@ export(q_matrix)
export(qc_report_indiv)
export(qc_report_loci)
export(rbind_dry_run)
export(read_q_files)
export(scale_fill_distruct)
export(select_loci)
export(select_loci_if)
Expand Down
48 changes: 48 additions & 0 deletions R/autoplot_gt_admix.R
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")

Check warning on line 29 in R/autoplot_gt_admix.R

View check run for this annotation

Codecov / codecov/patch

R/autoplot_gt_admix.R#L29

Added line #L29 was not covered by tests
}
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)
}
}
4 changes: 2 additions & 2 deletions R/autoplot_gt_pcadapt.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Autoplots for `gt_pcadapt` objects
#'
#' For `gt_pcadapt`, the following types of plots are available:
#' - `qq`: a qunatile-quantile plot of the p-values from pcadapt
#' - `qq`: a qunatile-quantile plot of the p-values from `pcadapt`
#' (wrapping [bigsnpr::snp_qq()])
#' - `manhattan` a manhattan plot of the p-values from pcadapt
#' - `manhattan` a manhattan plot of the p-values from `pcadapt`
#' (wrapping [bigsnpr::snp_manhattan()])
#'
#' `autoplot` produces simple plots to quickly inspect an object. They are
Expand Down
80 changes: 80 additions & 0 deletions R/gt_admix_methods.R
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")

Check warning on line 10 in R/gt_admix_methods.R

View check run for this annotation

Codecov / codecov/patch

R/gt_admix_methods.R#L10

Added line #L10 was not covered by tests
}

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

Check warning on line 40 in R/gt_admix_methods.R

View check run for this annotation

Codecov / codecov/patch

R/gt_admix_methods.R#L40

Added line #L40 was not covered by tests
}
# 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")

Check warning on line 57 in R/gt_admix_methods.R

View check run for this annotation

Codecov / codecov/patch

R/gt_admix_methods.R#L57

Added line #L57 was not covered by tests
} 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")

Check warning on line 70 in R/gt_admix_methods.R

View check run for this annotation

Codecov / codecov/patch

R/gt_admix_methods.R#L70

Added line #L70 was not covered by tests
}
# if there is a slot log in the object, print it
if ("log" %in% names(object)){
cat("$log for logs from the algorithm\n")

Check warning on line 74 in R/gt_admix_methods.R

View check run for this annotation

Codecov / codecov/patch

R/gt_admix_methods.R#L74

Added line #L74 was not covered by tests
}
# if there is a slot cv in the object, print it
if ("cv" %in% names(object)){
cat("$cv for cross validation error\n")

Check warning on line 78 in R/gt_admix_methods.R

View check run for this annotation

Codecov / codecov/patch

R/gt_admix_methods.R#L78

Added line #L78 was not covered by tests
}
}
Loading
Loading