├── .Rbuildignore ├── .devcontainer ├── devcontainer.json ├── setup.sh └── welcome.sh ├── .github ├── .gitignore └── workflows │ ├── build-test.yml │ ├── docker-image.yml │ └── pkgdown.yaml ├── .gitignore ├── DESCRIPTION ├── Dockerfile ├── LICENSE.md ├── NAMESPACE ├── R ├── GDM.R ├── Gen_dist.R ├── LFMM.R ├── MMRR.R ├── RDA.R ├── SNP_LD.R ├── TESS.R ├── alazygtr.R ├── ascii.R ├── check_vars.R ├── coords_convert.R ├── crs_check.R ├── data.R ├── dist.R ├── format_data.R ├── get_worldclim.R ├── imputation.R ├── load_example.R ├── masks.R ├── package_installs.R ├── utils-pipe.R ├── utils.R ├── vcf_to_dosage.R ├── warnings.R └── wingen.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── algatr.Rproj ├── data-raw └── DATASET.R ├── data ├── .DS_Store ├── CA_env.rda ├── liz_coords.rda ├── liz_gendist.rda ├── liz_vcf.rda └── wclim.RData ├── inst ├── .DS_Store ├── CITATION └── extdata │ ├── .DS_Store │ ├── CA_env.tif │ ├── PC_layers │ ├── CA_rPCA1.tif │ ├── CA_rPCA2.tif │ └── CA_rPCA3.tif │ ├── Scelop.coord │ ├── liz_test.dist │ ├── liz_test.dist.id │ ├── liz_test.vcf │ ├── populations_r20.haplotypes.filtered_m70_randomSNP.map │ ├── populations_r20.haplotypes.filtered_m70_randomSNP.ped │ └── populations_r20.haplotypes.filtered_m70_randomSNP.vcf ├── man ├── CA_env.Rd ├── MMRR.Rd ├── alazygatr_packages.Rd ├── allK_plot_helper.Rd ├── bestK.Rd ├── check_dists.Rd ├── check_env.Rd ├── check_vals.Rd ├── coords_to_sf.Rd ├── coords_to_sp.Rd ├── cor_df_helper.Rd ├── data_processing_packages.Rd ├── do_everything_for_me.Rd ├── env_dist.Rd ├── envirodata_packages.Rd ├── extrap_mask.Rd ├── figures │ ├── README-RGB plot-1.pdf │ ├── README-RGB plot-1.png │ ├── README-RGB-1.png │ ├── README-plot rasters-1.pdf │ ├── README-plot rasters-1.png │ ├── README-rasters-1.png │ ├── README-unnamed-chunk-2-1.png │ ├── README-unnamed-chunk-2-2.png │ ├── README-unnamed-chunk-2-3.png │ ├── README-unnamed-chunk-3-1.png │ ├── README-unnamed-chunk-3-2.png │ ├── README-unnamed-chunk-3-3.png │ ├── README-unnamed-chunk-3-4.png │ ├── README-unnamed-chunk-3-5.png │ ├── README-unnamed-chunk-3-6.png │ ├── README-unnamed-chunk-4-1.png │ ├── README-unnamed-chunk-4-2.png │ ├── README-unnamed-chunk-4-3.png │ ├── README-unnamed-chunk-4-4.png │ ├── README-unnamed-chunk-4-5.png │ ├── README-unnamed-chunk-4-6.png │ ├── README-unnamed-chunk-5-1.png │ ├── README-unnamed-chunk-5-2.png │ ├── README-unnamed-chunk-5-3.png │ ├── README-unnamed-chunk-5-4.png │ ├── README-unnamed-chunk-5-5.png │ ├── README-unnamed-chunk-5-6.png │ ├── README-unnamed-chunk-6-1.png │ ├── README-unnamed-chunk-6-2.png │ ├── README-unnamed-chunk-6-3.png │ ├── README-unnamed-chunk-6-4.png │ ├── README-unnamed-chunk-6-5.png │ ├── README-unnamed-chunk-7-1.png │ ├── README-unnamed-chunk-7-2.png │ ├── README-unnamed-chunk-7-3.png │ ├── README-unnamed-chunk-7-4.png │ ├── README-unnamed-chunk-7-5.png │ ├── README-unnamed-chunk-8-1.png │ ├── README-unnamed-chunk-8-2.png │ ├── README-unnamed-chunk-9-1.png │ ├── README-unnamed-chunk-9-2.png │ └── logo.png ├── gdm_coeffs.Rd ├── gdm_df.Rd ├── gdm_do_everything.Rd ├── gdm_format.Rd ├── gdm_map.Rd ├── gdm_packages.Rd ├── gdm_plot_diss.Rd ├── gdm_plot_isplines.Rd ├── gdm_plot_vars.Rd ├── gdm_run.Rd ├── gdm_table.Rd ├── gdm_var_sel.Rd ├── gdm_varimp_table.Rd ├── gen_dist.Rd ├── gen_dist_corr.Rd ├── gen_dist_hm.Rd ├── gen_dist_packages.Rd ├── gen_to_geno.Rd ├── geno_to_dosage.Rd ├── geo_dist.Rd ├── geom_tess.Rd ├── get_worldclim.Rd ├── ggbarplot_helper.Rd ├── krig_agg_helper.Rd ├── krig_helper.Rd ├── ld_prune.Rd ├── lfmm_df.Rd ├── lfmm_do_everything.Rd ├── lfmm_manhattanplot.Rd ├── lfmm_packages.Rd ├── lfmm_qqplot.Rd ├── lfmm_run.Rd ├── lfmm_table.Rd ├── lfmm_test_tidy.Rd ├── liz_coords.Rd ├── liz_gendist.Rd ├── liz_vcf.Rd ├── load_algatr_example.Rd ├── masking_packages.Rd ├── mmrr_df.Rd ├── mmrr_do_everything.Rd ├── mmrr_packages.Rd ├── mmrr_plot.Rd ├── mmrr_run.Rd ├── mmrr_table.Rd ├── mmrr_var_sel.Rd ├── pipe.Rd ├── plot_crossent.Rd ├── plot_extrap_mask.Rd ├── pops_helper.Rd ├── quick_elbow.Rd ├── rda_cor.Rd ├── rda_do_everything.Rd ├── rda_getoutliers.Rd ├── rda_packages.Rd ├── rda_plot.Rd ├── rda_run.Rd ├── rda_table.Rd ├── rda_varpart.Rd ├── rda_varpart_table.Rd ├── rm_islands.Rd ├── scale01.Rd ├── scaleRGB.Rd ├── select_K.Rd ├── simple_impute.Rd ├── snmf_bestK.Rd ├── snmf_crossent_helper.Rd ├── str_impute.Rd ├── tess_barplot.Rd ├── tess_col_default.Rd ├── tess_do_everything.Rd ├── tess_ggbarplot.Rd ├── tess_ggplot.Rd ├── tess_krig.Rd ├── tess_ktest.Rd ├── tess_legend.Rd ├── tess_packages.Rd ├── tess_plot_allK.Rd ├── unfold.Rd ├── vcf_to_dosage.Rd ├── wingen_do_everything.Rd └── wingen_packages.Rd ├── package_setup.qmd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── renv.lock ├── renv ├── .gitignore ├── activate.R └── settings.json ├── scan_dependencies.R └── vignettes ├── .gitignore ├── GDM_vignette.Rmd ├── LFMM_vignette.Rmd ├── MMRR_vignette.Rmd ├── RDA_vignette.Rmd ├── TESS_vignette.Rmd ├── alazygatr_vignette.Rmd ├── data_processing_vignette.Rmd ├── enviro_data_vignette.Rmd ├── gen_dist_vignette.Rmd ├── masking_vignette.Rmd └── wingen_vignette.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^renv$ 2 | ^renv\.lock$ 3 | ^algatr\.Rproj$ 4 | ^\.Rproj\.user$ 5 | ^package_setup\.qmd$ 6 | ^data-raw$ 7 | ^README\.Rmd$ 8 | ^LICENSE\.md$ 9 | ^knit_everything_for_me\.R$ 10 | ^doc$ 11 | ^Meta$ 12 | ^scan_dependencies\.R$ 13 | ^_pkgdown\.yml$ 14 | ^docs$ 15 | ^pkgdown$ 16 | ^\.github$ 17 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "The Swamp", 3 | "image": "ghcr.io/thewanglab/algatr:latest", 4 | "runArgs": [ "--security-opt", "seccomp=unconfined" ], 5 | "waitFor": "onCreateCommand", 6 | "customizations": { 7 | "codespaces": { 8 | "openFiles": ["README.md"] 9 | }, 10 | "vscode": { 11 | "settings": { 12 | "r.rterm.linux": "/usr/local/bin/radian", 13 | "r.bracketedPaste": true, 14 | "r.plot.useHttpgd": true, 15 | "[r]": { 16 | "editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?" 17 | } 18 | }, 19 | "extensions": [ 20 | "reditorsupport.r", 21 | "rdebugger.r-debugger" 22 | ] 23 | } 24 | }, 25 | // Forward Jupyter and RStudio ports 26 | "forwardPorts": [8787], 27 | "portsAttributes": { 28 | "8787": { 29 | "label": "Rstudio", 30 | "requireLocalPort": true, 31 | "onAutoForward": "ignore" 32 | } 33 | }, 34 | 35 | // Use 'postCreateCommand' to run commands after the container is created. 36 | "postCreateCommand": "bash .devcontainer/setup.sh", 37 | "postAttachCommand": "sudo rstudio-server start &> /dev/null && bash .devcontainer/welcome.sh", 38 | "remoteUser": "rstudio" 39 | } 40 | -------------------------------------------------------------------------------- /.devcontainer/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Taken from: https://github.com/boettiger-lab/nasa-topst-env-justice/blob/main/.devcontainer/setup.sh 3 | sudo cp /etc/rstudio/disable_auth_rserver.conf /etc/rstudio/rserver.conf 4 | sudo sudo bash -c 'echo "USER=rstudio" >>/etc/environment' 5 | sudo /init &> /dev/null & 6 | -------------------------------------------------------------------------------- /.devcontainer/welcome.sh: -------------------------------------------------------------------------------- 1 | # Modified from: https://github.com/boettiger-lab/nasa-topst-env-justice/blob/main/.devcontainer/welcome.sh 2 | mkdir -p ~/.local/share/rstudio/projects_settings 3 | export RPROJ"=$(ls ${CODESPACE_VSCODE_FOLDER}/*.Rproj)" 4 | echo ${RPROJ} > ~/.local/share/rstudio/projects_settings/last-project-path 5 | 6 | 7 | # Construct the message 8 | message="## [Open in RStudio](https://$CODESPACE_NAME-8787.app.github.dev) 9 | " 10 | # Echo the message to the terminal 11 | echo " 12 | 👋 Welcome to Codespaces! You are on our custom image. 13 | - It includes runtimes and tools for Python & R using Jupyter, Quarto, or RStudio 14 | 15 | 🌐 Open the RStudio editor here: https://$CODESPACE_NAME-8787.app.github.dev 16 | - (This may take a few seconds to load, retry if necessary) 17 | " 18 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/build-test.yml: -------------------------------------------------------------------------------- 1 | name: build-test 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | paths: 7 | - "R/**.R" 8 | - .github/workflows/build-test.yml 9 | - "vignettes/**.Rmd" 10 | - "renv.lock" 11 | branches: [ "main" ] 12 | pull_request: 13 | paths: 14 | - "R/**.R" 15 | - .github/workflows/build-test.yml 16 | - "vignettes/**.Rmd" 17 | - "renv.lock" 18 | branches: [ "main" ] 19 | 20 | jobs: 21 | container-test-job: 22 | runs-on: ubuntu-latest 23 | container: 24 | image: ghcr.io/thewanglab/algatr:latest 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - name: Restore renv Environment 29 | env: 30 | GITHUB_PAT: ${{ secrets.GITPAT }} 31 | run: | 32 | R -e 'options(repos = c(CRAN = "https://cloud.r-project.org")); renv::restore()' 33 | 34 | - name: Build R Package 35 | env: 36 | GITHUB_PAT: ${{ secrets.GITPAT }} 37 | run: | 38 | R -e 'options(repos = c(CRAN = "https://cloud.r-project.org")); devtools::build()' 39 | 40 | -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: docker-build 2 | on: 3 | workflow_dispatch: 4 | push: 5 | paths: 6 | - "R/**.R" 7 | - "vignettes/**.Rmd" 8 | - .github/workflows/docker-image.yml 9 | - renv.lock 10 | - Dockerfile 11 | - "man/*" 12 | - "man/figures/*" 13 | branches: [ "main" ] 14 | # Publish semver tags as releases. 15 | tags: [ 'v*.*.*' ] 16 | 17 | jobs: 18 | build: 19 | runs-on: ubuntu-latest 20 | permissions: write-all 21 | steps: 22 | - uses: actions/checkout@v4 23 | - name: Login to GitHub Container Registry 24 | uses: docker/login-action@v3 25 | with: 26 | registry: ghcr.io 27 | username: ${{github.actor}} 28 | password: ${{secrets.GITHUB_TOKEN}} 29 | - name: Build the Docker image 30 | run: docker build . --file Dockerfile --tag ghcr.io/thewanglab/algatr:latest 31 | - name: Publish 32 | run: docker push ghcr.io/thewanglab/algatr:latest 33 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | paths: 6 | - "R/**.R" 7 | - "vignettes/**.Rmd" 8 | - .github/workflows/pkgdown.yaml 9 | - renv.lock 10 | - inst/CITATION 11 | - README.md 12 | - _pkgdown.yml 13 | - man/* 14 | - man/figures/* 15 | - Dockerfile 16 | branches: [ "main" ] 17 | name: pkgdown 18 | 19 | jobs: 20 | pkgdown: 21 | runs-on: ubuntu-latest 22 | concurrency: 23 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 24 | env: 25 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 26 | # Pin R user lib so every step uses the same place 27 | R_LIBS_USER: /usr/local/lib/R/site-library 28 | permissions: 29 | contents: write 30 | container: 31 | image: ghcr.io/thewanglab/algatr:latest 32 | 33 | steps: 34 | - uses: actions/checkout@v4 35 | 36 | - name: System deps for source builds 37 | run: | 38 | apt-get update 39 | apt-get install -y --no-install-recommends \ 40 | build-essential gfortran libcurl4-openssl-dev libssl-dev libxml2-dev \ 41 | libbz2-dev liblzma-dev rsync gdebi-core 42 | # sanity: create user lib if missing 43 | mkdir -p "$R_LIBS_USER" 44 | 45 | - name: Setup Pandoc 46 | uses: r-lib/actions/setup-pandoc@v2 47 | 48 | - name: Install pkgdown + devtools 49 | shell: Rscript {0} 50 | run: | 51 | install.packages(c("pkgdown","devtools")) 52 | 53 | - name: Install algatr (from source) 54 | shell: Rscript {0} 55 | run: | 56 | devtools::install(dependencies = FALSE) # you install deps yourself next 57 | 58 | - name: Install deps via helper (should pull AssocTests) 59 | shell: Rscript {0} 60 | run: | 61 | library(algatr) 62 | alazygatr_packages() 63 | 64 | # Belt-and-suspenders: ensure AssocTests from CRAN archive and fail fast if missing 65 | - name: Ensure AssocTests present 66 | shell: Rscript {0} 67 | run: | 68 | options(warn = 2) 69 | if (!"AssocTests" %in% rownames(installed.packages())) { 70 | install.packages( 71 | "https://cran.r-project.org/src/contrib/Archive/AssocTests/AssocTests_1.0-1.tar.gz", 72 | repos = NULL, type = "source" 73 | ) 74 | } 75 | stopifnot("AssocTests" %in% rownames(installed.packages())) 76 | cat("LibPaths:\n"); print(.libPaths()) 77 | ip <- installed.packages() 78 | print(ip[ip[, "Package"] %in% c("AssocTests","adegenet"), c("Package","Version","LibPath")]) 79 | 80 | - name: Build site 81 | shell: Rscript {0} 82 | run: | 83 | pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 84 | 85 | - name: Deploy to GitHub pages 🚀 86 | if: github.event_name != 'pull_request' 87 | uses: JamesIves/github-pages-deploy-action@v4.4.1 88 | with: 89 | clean: false 90 | branch: gh-pages 91 | folder: docs 92 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Rprofile (!needed for codespaces to ignore renv) 2 | .Rprofile 3 | 4 | # History files 5 | .Rhistory 6 | .Rapp.history 7 | 8 | # Session Data files 9 | .RData 10 | 11 | # User-specific files 12 | .Ruserdata 13 | 14 | # Example code in package build process 15 | *-Ex.R 16 | 17 | # Output files from R CMD build 18 | /*.tar.gz 19 | 20 | # Output files from R CMD check 21 | /*.Rcheck/ 22 | 23 | # RStudio files 24 | .Rproj.user/ 25 | 26 | # produced vignettes 27 | vignettes/*.html 28 | vignettes/*.pdf 29 | vignettes/*.tif 30 | 31 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 32 | .httr-oauth 33 | 34 | # knitr and R markdown default cache directories 35 | *_cache/ 36 | /cache/ 37 | 38 | # Temporary files created by R markdown 39 | *.utf8.md 40 | *.knit.md 41 | 42 | # R Environment Variables 43 | .Renviron 44 | .Rproj.user 45 | inst/doc 46 | IGNORE_test.R 47 | /doc/ 48 | /Meta/ 49 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: algatr 2 | Title: A Landscape Genomic Analysis Toolkit in R 3 | Version: 1.0.0 4 | Authors@R: c( 5 | person("Anusha", "Bishop", , email = "anusha.bishop@berkeley.edu", role = c("aut", "cre"), 6 | comment = c(ORCID="0000-0003-1731-8683")), 7 | person("Anne", "Chambers", , email = "eachambers@berkeley.edu", role = c("aut"), 8 | comment = c(ORCID="0000-0002-7369-0108")), 9 | person("Ian", "Wang", , email = "ianwang@berkeley.edu", role = "aut", 10 | comment = c(ORCID = "0000-0003-2554-9414")) 11 | ) 12 | Description: What the package does (one paragraph). 13 | License: MIT + file LICENSE 14 | Encoding: UTF-8 15 | Roxygen: list(markdown = TRUE) 16 | RoxygenNote: 7.3.3 17 | Suggests: 18 | knitr, 19 | rmarkdown, 20 | adegenet, 21 | AssocTests, 22 | automap, 23 | BiocManager, 24 | corrplot, 25 | cowplot, 26 | devtools, 27 | ecodist, 28 | fansi, 29 | gdistance, 30 | gdm, 31 | gdsfmt, 32 | geodata, 33 | GGally, 34 | ggrepel, 35 | graphics, 36 | LEA, 37 | lfmm, 38 | qvalue, 39 | readr, 40 | renv, 41 | rmapshaper, 42 | robust, 43 | RStoolbox, 44 | SeqArray, 45 | SNPRelate, 46 | tess3r, 47 | tibble, 48 | topoDistance, 49 | usethis, 50 | vegan, 51 | wingen 52 | VignetteBuilder: knitr 53 | Depends: 54 | R (>= 3.5.0) 55 | LazyData: true 56 | Imports: 57 | crayon, 58 | dplyr, 59 | ggplot2, 60 | gt, 61 | gtExtras, 62 | here, 63 | purrr, 64 | raster, 65 | sf, 66 | sp, 67 | stats, 68 | terra, 69 | tidyr, 70 | utils, 71 | vcfR, 72 | viridis 73 | URL: https://thewanglab.github.io/algatr/ 74 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Start from the geospatial base image 2 | FROM ghcr.io/rocker-org/devcontainer/geospatial:4.5 3 | 4 | # Default CRAN 5 | RUN echo 'options(repos = c(CRAN = "https://cloud.r-project.org"))' >> /usr/local/lib/R/etc/Rprofile.site 6 | 7 | # Toolchain & headers commonly needed by CRAN packages 8 | RUN apt-get update && apt-get install -y \ 9 | build-essential \ 10 | libcurl4-openssl-dev \ 11 | libssl-dev \ 12 | libxml2-dev \ 13 | libgit2-dev \ 14 | libicu-dev libharfbuzz-dev libfribidi-dev \ 15 | pandoc && \ 16 | apt-get clean && rm -rf /var/lib/apt/lists/* 17 | 18 | # Relax compiler warnings (avoid -Werror issues) 19 | ENV CFLAGS="-O2" 20 | ENV CXXFLAGS="-O2" 21 | 22 | # Avoid sandbox hiccups; always compile if needed 23 | ENV RENV_CONFIG_SANDBOX_ENABLED=false 24 | ENV R_COMPILE_AND_INSTALL_PACKAGES=always 25 | 26 | # Preinstall remotes (optional convenience) 27 | RUN Rscript -e 'install.packages("remotes", quiet = TRUE)' 28 | 29 | # (Optional) Prewarm cache with your package/deps; skip vignettes first 30 | RUN Rscript -e 'remotes::install_github("TheWangLab/algatr", build_vignettes = FALSE)' 31 | RUN Rscript -e 'algatr::alazygatr_packages()' 32 | RUN Rscript -e 'remotes::install_github("TheWangLab/algatr", build_vignettes = TRUE)' -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2022 algatr authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(MMRR) 5 | export(alazygatr_packages) 6 | export(algatr_col_default) 7 | export(allK_plot_helper) 8 | export(bestK) 9 | export(buffer_mask) 10 | export(check_dists) 11 | export(check_env) 12 | export(check_vals) 13 | export(chull_mask) 14 | export(coords_to_sf) 15 | export(coords_to_sp) 16 | export(create_rgb_vec) 17 | export(crs_check) 18 | export(data_processing_packages) 19 | export(do_everything_for_me) 20 | export(env_dist) 21 | export(env_dist_helper) 22 | export(envirodata_packages) 23 | export(extrap_mask) 24 | export(gdm_coeffs) 25 | export(gdm_df) 26 | export(gdm_do_everything) 27 | export(gdm_format) 28 | export(gdm_map) 29 | export(gdm_packages) 30 | export(gdm_plot_diss) 31 | export(gdm_plot_isplines) 32 | export(gdm_plot_vars) 33 | export(gdm_run) 34 | export(gdm_table) 35 | export(gdm_var_sel) 36 | export(gdm_varimp_table) 37 | export(gen_dist) 38 | export(gen_dist_corr) 39 | export(gen_dist_hm) 40 | export(gen_dist_packages) 41 | export(gen_to_geno) 42 | export(genetic_distance_packages) 43 | export(geno_to_dosage) 44 | export(geo_dist) 45 | export(geom_tess) 46 | export(get_worldclim) 47 | export(ggbarplot_helper) 48 | export(impute_helper) 49 | export(krig_K) 50 | export(krig_agg_helper) 51 | export(krig_helper) 52 | export(ld_prune) 53 | export(lfmm_df) 54 | export(lfmm_do_everything) 55 | export(lfmm_manhattanplot) 56 | export(lfmm_packages) 57 | export(lfmm_qqplot) 58 | export(lfmm_run) 59 | export(lfmm_table) 60 | export(lfmm_test_tidy) 61 | export(load_algatr_example) 62 | export(make_plot_col) 63 | export(make_stat_vec) 64 | export(masking_packages) 65 | export(mmrr_df) 66 | export(mmrr_do_everything) 67 | export(mmrr_packages) 68 | export(mmrr_plot) 69 | export(mmrr_plot_cov) 70 | export(mmrr_plot_fitted) 71 | export(mmrr_plot_vars) 72 | export(mmrr_run) 73 | export(mmrr_table) 74 | export(mmrr_var_sel) 75 | export(outliers) 76 | export(p_outlier_method) 77 | export(plot_crossent) 78 | export(plot_extrap_mask) 79 | export(pops_helper) 80 | export(quick_elbow) 81 | export(range_mask) 82 | export(raster_to_grid) 83 | export(raster_to_rgb) 84 | export(rda_biplot) 85 | export(rda_cor) 86 | export(rda_cor_env_helper) 87 | export(rda_cor_helper) 88 | export(rda_do_everything) 89 | export(rda_getoutliers) 90 | export(rda_ggtidy) 91 | export(rda_hist) 92 | export(rda_manhattan) 93 | export(rda_packages) 94 | export(rda_plot) 95 | export(rda_run) 96 | export(rda_table) 97 | export(rda_varpart) 98 | export(rda_varpart_helper) 99 | export(rda_varpart_table) 100 | export(rdadapt) 101 | export(rm_islands) 102 | export(scale01) 103 | export(scaleRGB) 104 | export(sd_mask) 105 | export(select_K) 106 | export(select_K_elbow) 107 | export(select_K_fc) 108 | export(select_K_tess) 109 | export(select_K_tw) 110 | export(simple_impute) 111 | export(snmf_bestK) 112 | export(snmf_crossent_helper) 113 | export(stack_to_rgb) 114 | export(str_impute) 115 | export(tess_barplot) 116 | export(tess_col_default) 117 | export(tess_do_everything) 118 | export(tess_ggbarplot) 119 | export(tess_ggplot) 120 | export(tess_krig) 121 | export(tess_ktest) 122 | export(tess_legend) 123 | export(tess_packages) 124 | export(tess_plot_allK) 125 | export(vcf_check) 126 | export(vcf_to_dosage) 127 | export(wingen_do_everything) 128 | export(wingen_packages) 129 | export(z_outlier_helper) 130 | export(z_outlier_method) 131 | importFrom(ggplot2,'%+replace%') 132 | importFrom(magrittr,"%>%") 133 | importFrom(vegan,rda) 134 | -------------------------------------------------------------------------------- /R/SNP_LD.R: -------------------------------------------------------------------------------- 1 | #' ld_prune prunes SNPs based on linkage disequilibrium using `SNPRelate` and `SeqArray` packages 2 | #' 3 | #' @param vcf is the path to the vcf file containing all SNPs 4 | #' @param nodes is the number of parallel processors (numeric) 5 | #' @param ld.threshold is the threshold for LD pruning (numeric; 0 - 1; defaults to 0.6) 6 | #' @param slide.max.n is the maximum number of SNPs in a sliding window (numeric; defaults to 100) 7 | #' @param maf is the minor allele frequency cutoff (numeric; defaults to 0.05) 8 | #' @param seed is the random starting seed (defaults to 1234) 9 | #' @param method is the LD threshold method; default to corr which is r2 correlation coefficient 10 | #' @param out_name prefix name of output files (will append with param settings) 11 | #' @param out_format output file format ("plink" will produce ped and map files while "vcf" will produce a vcf and a GDS) 12 | #' @param save_output if TRUE, saves SNP GDS and ped (plink) files with retained SNPs in new directory; if FALSE returns object (defaults to TRUE) 13 | #' 14 | #' @details 15 | #' `SNPRelate` package citation: Zheng et al. (2012): https://doi.org/10.1093/bioinformatics/bts606 16 | #' 17 | #' @return LD-pruned vcf-type object 18 | #' @export 19 | ld_prune <- function(vcf, out_name, out_format, nodes = 1, ld.threshold = 0.6, slide.max.n = 100, 20 | maf = 0.05, seed = 1234, method = c("corr"), save_output = TRUE) { 21 | dir.create(here(paste(out_name, "_LDpruned", sep = ""))) 22 | dir_name <- here(paste(out_name, "_LDpruned/", sep = "")) 23 | 24 | # Specify output file name 25 | outfile_name <- paste(out_name, "_LDpruned_r", ld.threshold, "_n", slide.max.n, sep = "") 26 | 27 | # Write log file to track output 28 | sink(file = paste(dir_name, outfile_name, "_LOGFILE.txt", sep = "")) 29 | 30 | # Convert vcf to GDS file 31 | SNPRelate::snpgdsVCF2GDS(vcf, paste(dir_name, out_name, ".gds", sep = "")) 32 | 33 | # Open GDS file 34 | genofile <- SNPRelate::snpgdsOpen(paste(dir_name, out_name, ".gds", sep = ""), allow.duplicate = FALSE) 35 | 36 | set.seed(seed) 37 | 38 | # Define set of SNPs based on MAF, LD threshold, and window size 39 | snpset <- SNPRelate::snpgdsLDpruning(genofile, 40 | ld.threshold = ld.threshold, 41 | slide.max.n = slide.max.n, 42 | maf = maf, 43 | autosome.only = FALSE, 44 | method = method 45 | ) 46 | 47 | snp.id <- unlist(snpset) 48 | 49 | # Prune GDS based on the LD-pruned SNP set 50 | SNPRelate::snpgdsCreateGenoSet( 51 | src.fn = paste(dir_name, out_name, ".gds", sep = ""), dest.fn = paste(dir_name, outfile_name, ".gds", sep = ""), 52 | snp.id = snp.id 53 | ) 54 | 55 | if (out_format == "plink") { 56 | # Open LD-pruned SNP set 57 | LDgenofile <- SNPRelate::snpgdsOpen(paste(dir_name, outfile_name, ".gds", sep = ""), 58 | allow.duplicate = FALSE 59 | ) 60 | # Convert LD-pruned GDS to ped file 61 | SNPRelate::snpgdsGDS2PED(LDgenofile, 62 | ped.fn = paste(dir_name, outfile_name, ".gds", sep = ""), 63 | sample.id = NULL, snp.id = NULL, use.snp.rsid = FALSE, verbose = TRUE 64 | ) 65 | } 66 | 67 | if (out_format == "vcf") { 68 | # Convert from SNP GDS to GDS 69 | SeqArray::seqSNP2GDS(paste(dir_name, outfile_name, ".gds", sep = ""), paste(dir_name, outfile_name, "seqarray.gds", sep = "")) 70 | # Convert GDS to vcf 71 | SeqArray::seqGDS2VCF(paste(dir_name, outfile_name, "seqarray.gds", sep = ""), paste(dir_name, outfile_name, ".vcf", sep = ""), 72 | info.var = NULL, fmt.var = NULL, chr_prefix = "", 73 | use_Rsamtools = TRUE, verbose = TRUE 74 | ) 75 | } 76 | 77 | gdsfmt::showfile.gds(closeall = TRUE) 78 | 79 | sink() 80 | 81 | if (save_output == FALSE) { 82 | pruned_vcf <- vcfR::read.vcfR(paste(dir_name, outfile_name, ".vcf", sep = "")) 83 | unlink(dir_name, recursive = TRUE) 84 | return(pruned_vcf) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /R/alazygtr.R: -------------------------------------------------------------------------------- 1 | 2 | #' Lazy run of all landscape genomic analyses contained within `algatr` 3 | #' 4 | #' Disclaimer: this is probably a bad idea... 5 | #' 6 | #' @param gen path to vcf file, a `vcfR` type object, or a dosage matrix 7 | #' @param coords dataframe with x (i.e., longitude) and y (i.e., latitude) coordinates; must be in this order 8 | #' @param envlayers SpatRaster or Raster* for mapping (if env is provided, the dataframe column names and envlayers layer names should be the same) 9 | #' @param quiet whether to operate quietly and suppress the output of tables and figures (defaults to FALSE) 10 | #' @param gators set to TRUE to see some gators... 11 | #' 12 | #' @return results from all six analyses contained within algatr 13 | #' @export 14 | do_everything_for_me <- function(gen, coords, envlayers, quiet = FALSE, gators = FALSE) { 15 | 16 | message("Please be aware: the do_everything functions are meant to be exploratory. We do not recommend their use for final analyses unless certain they are properly parameterized.") 17 | 18 | # Data processing --------------------------------------------------------- 19 | 20 | gendist <- gen_dist(gen, dist_type = "euclidean") 21 | 22 | lyr <- wingen::coords_to_raster(coords, res = 0.25, buffer = 5) 23 | 24 | # Run algatr methods ------------------------------------------------------ 25 | 26 | wingen <- wingen_do_everything(gen, lyr, coords, kriged = TRUE, grd = lyr, masked = TRUE, mask = envlayers, quiet = quiet) 27 | 28 | if (gators & !quiet) ascii_alligator("wingen") 29 | 30 | tess <- tess_do_everything(gen, coords, raster::aggregate(envlayers[[1]], 10), Kvals = 1:10, K_selection = "auto", quiet = quiet) 31 | 32 | if (gators & !quiet) ascii_alligator("TESS") 33 | 34 | mmrr <- mmrr_do_everything(gendist, coords, envlayers, model = "best", nperm = 100, quiet = quiet) 35 | 36 | if (is.null(mmrr)) { 37 | warning("MMRR model = \"best\" did not find a significant model, running a full model instead") 38 | mmrr <- quiet_mmrr(gendist, coords, envlayers, model = "full", nperm = 100, quiet = quiet) 39 | } 40 | 41 | if (gators & !quiet) ascii_alligator("MMRR") 42 | 43 | gdm <- gdm_do_everything(gendist, coords, envlayers, model = "best", scale_gendist = TRUE, quiet = quiet) 44 | 45 | if (is.null(gdm)) { 46 | warning("GDM model = \"best\" did not find a significant model, running a full model instead") 47 | gdm <- gdm_do_everything(gendist, coords, envlayers, model = "full", scale_gendist = TRUE, quiet = quiet) 48 | } 49 | 50 | if (gators & !quiet) ascii_alligator("GDM") 51 | 52 | rda <- rda_do_everything(gen, envlayers, coords, quiet = quiet) 53 | 54 | if (gators & !quiet) ascii_alligator("RDA") 55 | 56 | lfmm <- lfmm_do_everything(gen, envlayers, coords, quiet = quiet) 57 | 58 | if (gators & !quiet) ascii_alligator("LFMM") 59 | 60 | return(list(wingen = wingen, tess = tess, gdm = gdm, mmrr = mmrr, rda = rda, lfmm = lfmm)) 61 | } 62 | -------------------------------------------------------------------------------- /R/ascii.R: -------------------------------------------------------------------------------- 1 | ascii_alligator <- function(i) { 2 | cat(crayon::green(alligator(i)), sep = "\n") 3 | } 4 | 5 | alligator <- function(x) { 6 | a <- c( 7 | "", 8 | " .lxk: ", 9 | " 'x0kXXc ", 10 | " .;dXMMMMMO. ", 11 | " .,lkXWMMMWNWO' ", 12 | paste0(" .;clool:. ..,clox0NMMMWXXXo", crayon::white("\\/")), 13 | paste0(" dXWK", crayon::black("xx"), "WKKKxoodkOKNWMMMMMMXO0k", crayon::white("\\/")), 14 | paste0(" MM0", crayon::black("xx"), crayon::white("O"), crayon::black("x"), "MMMMMMMMMMMMMWOdkc", crayon::white("\\/")), 15 | paste0( 16 | " MMX", crayon::black("xxxx"), "MMMMMMMWMXdldkc", crayon::white("\\/"), " ", 17 | crayon::bold(crayon::red(paste0(x, " done!")), " ") 18 | ), 19 | paste0(" MMMMMMMMMMMN0xooo;", crayon::white("\\/")), 20 | paste0(" MMMMMMMMMMWOoc", crayon::white("/\\ /\\ /\\ /\\ /\\ /\\ /\\ /\\ /\\")), 21 | " MMAPBMMMMMMMMMMEACMMMWWMWWWMIJWWWWWWKXWX", 22 | paste0(crayon::blue("~~~ "), "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW ", crayon::blue("~~~")), 23 | crayon::blue(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"), 24 | crayon::blue(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "), 25 | "" 26 | ) 27 | return(a) 28 | } 29 | -------------------------------------------------------------------------------- /R/check_vars.R: -------------------------------------------------------------------------------- 1 | 2 | #' Check environmental layers for collinearity 3 | #' 4 | #' @param envlayers SpatRaster or Raster* object 5 | #' @param threshold the cutoff correlation coefficient for flagging variables as collinear (numeric; defaults to 0.7) 6 | #' 7 | #' @return a matrix of correlation coefficients 8 | #' 9 | #' @export 10 | check_env <- function(envlayers, threshold = 0.7) { 11 | if (!inherits(envlayers, "Raster")) envlayers <- raster::stack(envlayers) 12 | cors <- raster::layerStats(envlayers, stat = "pearson", na.rm = TRUE) 13 | cors <- cors$`pearson correlation coefficient` 14 | cor_df <- cor_df_helper(cors, threshold) 15 | return(list(cor_df = cor_df, cor_matrix = cors)) 16 | } 17 | 18 | 19 | #' Check extracted values for collinearity 20 | #' 21 | #' @param envlayers SpatRaster or Raster* object 22 | #' @param coords dataframe with x and y sample coordinates 23 | #' @param threshold the cutoff correlation coefficient for flagging variables as collinear (numeric) 24 | #' 25 | #' @return a matrix of correlation coefficients 26 | #' 27 | #' @export 28 | check_vals <- function(envlayers, coords, threshold = 0.7) { 29 | if (!inherits(envlayers, "SpatRaster")) envlayers <- terra::rast(envlayers) 30 | 31 | crs_check(coords, envlayers) 32 | 33 | vals <- terra::extract(envlayers, coords) 34 | if (length(which(is.na(vals))) > 0) warning("NA values detected in extracted variables.") 35 | cors <- cor(vals, use = "na.or.complete", method = "pearson") 36 | cor_df <- cor_df_helper(cors, threshold) 37 | corrplot::corrplot.mixed(cors, upper = "ellipse", tl.pos = "lt") 38 | return(list(cor_df = cor_df, cor_matrix = cors)) 39 | } 40 | 41 | 42 | #' Check geographic and environmental distances for collinearity 43 | #' 44 | #' @param envlayers SpatRaster or Raster* object 45 | #' @param coords dataframe with x and y sample coordinates 46 | #' @param sig significance threshold for Mantel test 47 | #' @param type the type of geographic distance to be calculated; options are "Euclidean" for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances 48 | #' @param lyr DEM raster for calculating topographic distances or resistance raster for calculating resistance distances 49 | #' 50 | #' @return a list with (1) a dataframe of significantly correlated variables, (2) a matrix of p-values, (3) a matrix of Mantel's r 51 | #' 52 | #' @export 53 | check_dists <- function(envlayers, coords, type = "Euclidean", lyr = NULL, sig = 0.05) { 54 | if (!inherits(envlayers, "SpatRaster")) envlayers <- terra::rast(envlayers) 55 | 56 | crs_check(coords, envlayers) 57 | 58 | vals <- terra::extract(envlayers, coords) 59 | 60 | if (sum(!complete.cases(vals))) { 61 | warning("removing ", sum(!complete.cases(vals)), " locations with environmental NA values for Mantel test") 62 | coords <- coords[complete.cases(vals), ] 63 | vals <- vals[complete.cases(vals), ] 64 | } 65 | 66 | edists <- env_dist(vals) 67 | gdist <- geo_dist(coords, type = type, lyr = lyr) 68 | gdist <- list(geo = gdist) 69 | all_dists <- c(gdist, edists) 70 | p <- r <- matrix(nrow = length(all_dists), ncol = length(all_dists)) 71 | rownames(p) <- rownames(r) <- names(all_dists) 72 | 73 | for (i in 1:(length(all_dists) - 1)) { 74 | for (j in (i + 1):length(all_dists)) { 75 | mantel_result <- vegan::mantel(all_dists[[i]], all_dists[[j]], permutations = 99) 76 | p[i, j] <- mantel_result$signif 77 | r[i, j] <- mantel_result$statistic 78 | } 79 | } 80 | 81 | mantel_df <- 82 | data.frame( 83 | var1 = rownames(p)[row(p)[upper.tri(p)]], 84 | var2 = rownames(p)[col(p)[upper.tri(p)]], 85 | p = p[upper.tri(p)], 86 | r = r[upper.tri(r)] 87 | ) %>% 88 | dplyr::filter(p < sig) 89 | 90 | if (nrow(mantel_df) == 1) { 91 | message(paste0("Warning: The distances for 1 pair of variables are significantly correlated. algatr recommends reducing collinearity by removing correlated variables or performing a PCA before proceeeding.")) 92 | } else if (nrow(mantel_df) > 1) message(paste0("Warning: The distances for ", nrow(mantel_df), " pairs of variables are significantly correlated. algatr recommends reducing collinearity by removing correlated variables or performing a PCA before proceeeding.")) 93 | return(list(mantel_df = mantel_df, p = p, r = r)) 94 | } 95 | 96 | 97 | #' Helper function to create correlation dataframe from matrix and filter based on threshold 98 | #' 99 | #' @keywords internal 100 | cor_df_helper <- function(cors, threshold) { 101 | cor_df <- 102 | data.frame( 103 | var1 = rownames(cors)[row(cors)[upper.tri(cors)]], 104 | var2 = colnames(cors)[col(cors)[upper.tri(cors)]], 105 | r = cors[upper.tri(cors)] 106 | ) %>% 107 | dplyr::filter(r > threshold) 108 | 109 | if (nrow(cor_df) == 1) { 110 | message(paste0("Warning: The extracted values for 1 pair of variables had a correlation coefficient > ", threshold, ". algatr recommends reducing collinearity by removing correlated variables or performing a PCA before proceeeding.")) 111 | } else if (nrow(cor_df) > 1) message(paste0("Warning: The extracted values for ", nrow(cor_df), " pairs of variables had correlation coefficients > ", threshold, ". algatr recommends reducing collinearity by removing correlated variables or performing a PCA before proceeeding.")) 112 | 113 | return(cor_df) 114 | } 115 | -------------------------------------------------------------------------------- /R/coords_convert.R: -------------------------------------------------------------------------------- 1 | #' Convert from matrix, data frame, or sf to sf (sf is a pass through) 2 | #' 3 | #' @param coords sf object, data frame, or matrix representing coordinates 4 | #' 5 | #' @return converted coords in sf format 6 | #' @export 7 | #' 8 | coords_to_sf <- function(coords) { 9 | if (inherits(coords, "sf")) { 10 | return(coords) 11 | } 12 | if (is.matrix(coords)) coords <- data.frame(coords) 13 | colnames(coords) <- c("x", "y") 14 | coords <- sf::st_as_sf(coords, coords = c("x", "y")) 15 | return(coords) 16 | } 17 | 18 | #' Convert from matrix, data frame, or sf to formatted sp 19 | #' 20 | #' @param coords sf object, data frame, or matrix representing coordinates 21 | #' 22 | #' @return converted coords in sp format 23 | #' @export 24 | #' 25 | coords_to_sp <- function(coords) { 26 | coords <- coords_to_sf(coords) 27 | coords <- sf::as_Spatial(coords) 28 | # Needs to be x + y for kriging 29 | colnames(coords@coords) <- c("x", "y") 30 | return(coords) 31 | } 32 | 33 | # convert from matrix/data.frame/sf to formatted df 34 | coords_to_df <- function(coords) { 35 | if (inherits(coords, "sf")) coords <- sf::st_coordinates(coords) 36 | if (is.matrix(coords)) coords <- data.frame(coords) 37 | colnames(coords) <- c("x", "y") 38 | return(coords) 39 | } 40 | 41 | # convert from matrix/data.frame/sf to formatted matrix 42 | coords_to_matrix <- function(coords) { 43 | coords <- coords_to_df(coords) 44 | coords <- as.matrix(coords) 45 | return(coords) 46 | } 47 | -------------------------------------------------------------------------------- /R/crs_check.R: -------------------------------------------------------------------------------- 1 | #' Check CRS of coords and layer 2 | #' 3 | #' @param coords sf object, data frame, or matrix representing coordinates 4 | #' @param lyr SpatRaster or Raster* object 5 | #' 6 | #' @return NULL 7 | #' @export 8 | #' 9 | #' @noRd 10 | crs_check <- function(coords = NULL, lyr = NULL) { 11 | if (!is.null(coords)) { 12 | # convert coords to sf 13 | coords <- coords_to_sf(coords) 14 | # get CRS 15 | coords_crs <- sf::st_crs(coords) 16 | if (is.na(coords_crs)) warning("No CRS found for the provided coordinates. Make sure the coordinates and the raster have the same projection (see function details or vignette)") 17 | } 18 | 19 | if (!is.null(lyr)) { 20 | lyr_crs <- sf::st_crs(lyr) 21 | if (is.na(lyr_crs)) warning("No CRS found for the provided raster. Make sure the coordinates and the raster have the same projection (see function details or vignette)") 22 | } 23 | 24 | if (!is.null(lyr) & !is.null(coords)) { 25 | if (!is.na(lyr_crs) & !is.na(coords_crs)) { 26 | if (coords_crs != lyr_crs) stop("CRS of the provided coordinates and raster do not match") 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Example VCF from Bouzid et al. 2022 2 | #' 3 | #' @format A vcfR object with 1000 loci and 53 samples 4 | #' 5 | #' @source \url{https://doi.org/10.1111/mec.15836} 6 | "liz_vcf" 7 | 8 | #' Example coordinates from Bouzid et al. 2022 9 | #' 10 | #' @format A dataframe with x and y coordinates for 53 samples 11 | #' 12 | #' @source \url{https://doi.org/10.1111/mec.15836} 13 | "liz_coords" 14 | 15 | #' Example genetic distance matrix, calculated with Plink using data from Bouzid et al. 2022 16 | #' 17 | #' @format A dataframe with genetic distances for 53 samples 18 | #' 19 | #' @source \url{https://doi.org/10.1111/mec.15836} 20 | "liz_gendist" 21 | 22 | #' Example environmental data, calculated by performing a raster PCA on 18 bioclimatic variables for state of California 23 | #' 24 | #' @format A RasterStack object with three environmental PC layers 25 | "CA_env" 26 | -------------------------------------------------------------------------------- /R/dist.R: -------------------------------------------------------------------------------- 1 | #' Calculate distance between environmental vars 2 | #' 3 | #' @param env dataframe or vector of environmental variables for locations 4 | #' @param stdz if TRUE then environmental values will be standardized (default = TRUE) 5 | #' 6 | #' @return list of environmental distances between samples (for each environmental variable) 7 | #' @export 8 | env_dist <- function(env, stdz = TRUE) { 9 | if (!is.null(dim)) distmat <- dplyr::as_tibble(env) %>% purrr::map(env_dist_helper, stdz = stdz) 10 | if (is.null(dim)) distmat <- env_dist_helper(env, stdz) 11 | return(distmat) 12 | } 13 | 14 | #' Helper function to convert an environmental vector to a distance matrix 15 | #' 16 | #' @inheritParams env_dist 17 | #' 18 | #' @export 19 | #' @noRd 20 | env_dist_helper <- function(env, stdz = TRUE) { 21 | # Standardize environmental variables 22 | if (stdz) env <- scale(env, center = TRUE, scale = TRUE) 23 | 24 | distmat <- as.matrix(dist(env, diag = TRUE, upper = TRUE)) 25 | 26 | return(distmat) 27 | } 28 | 29 | #' Calculate geographic distance between coordinates 30 | #' 31 | #' @param coords dataframe with x and y coordinates 32 | #' @param type the type of geographic distance to be calculated; options are "Euclidean" for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances. 33 | #' @param lyr SpatRaster or Raster* DEM for calculating topographic distances or resistance raster for calculating resistance distances (RasterLayer or SpatRaster object) 34 | #' @details 35 | #' Euclidean, or linear, distances are calculated using the geodist package: Padgham M, Sumner M (2021). geodist: Fast, Dependency-Free Geodesic Distance Calculations. R package version 0.0.7, Available: https://CRAN.R-project.org/package=geodist. 36 | #' Topographic distances are calculated using the topoDistance package: Wang I.J. (2020) Topographic path analysis for modeling dispersal and functional connectivity: calculating topographic distances using the TOPODISTANCE R package. Methods in Ecology and Evolution, 11: 265-272. 37 | #' Resistance distances are calculated using the gdistance package: van Etten, J. (2017). R package gdistance: Distances and routes on geographical grids. Journal of Statistical Software, 76(1), 1–21. 38 | #' 39 | #' @return geographic distance matrix 40 | #' @export 41 | geo_dist <- function(coords, type = "Euclidean", lyr = NULL) { 42 | if (type == "Euclidean" | type == "euclidean" | type == "linear") { 43 | # Format coordinates 44 | coords <- coords_to_sf(coords) 45 | # Calculate geodesic distance between points 46 | distmat <- sf::st_distance(coords) 47 | } else if (type == "topo" | type == "topographic") { 48 | # Format coordinates 49 | coords <- coords_to_df(coords) 50 | 51 | if (is.null(lyr)) stop("Calculating topographic distances requires a DEM layer for argument lyr.") 52 | message("Calculating topo distances... This can be time consuming with many points and large rasters.") 53 | 54 | # Convert to RasterLayer if SpatRaster object 55 | if (inherits(lyr, "SpatRaster")) lyr <- raster::raster(lyr) 56 | 57 | distmat <- topoDistance::topoDist(lyr, coords, paths = FALSE) 58 | } else if (type == "resistance" | type == "cost" | type == "res") { 59 | if (is.null(lyr)) stop("Calculating resistance distances requires a resistance surface for argument lyr.") 60 | message("Calculating resistance distances... This can be time consuming with many points and large rasters.") 61 | 62 | # Format coordinates 63 | coords <- coords_to_df(coords) 64 | 65 | # Convert to RasterLayer if SpatRaster object 66 | if (inherits(lyr, "SpatRaster")) lyr <- raster::raster(lyr) 67 | 68 | # Convert resistance surface to conductance surface 69 | cond.r <- 1 / lyr 70 | trSurface <- gdistance::transition(cond.r, transitionFunction = mean, directions = 8) # Create transition surface 71 | trSurface <- gdistance::geoCorrection(trSurface, type = "c", scl = FALSE) 72 | sp <- sp::SpatialPoints(coords = coords) 73 | distmat <- as.matrix(gdistance::commuteDistance(trSurface, sp)) # Calculate circuit distances 74 | } 75 | 76 | return(distmat) 77 | } 78 | 79 | #' convert coordinates to sf 80 | #' @noRd 81 | coords_to_sf <- function(coords) { 82 | if (inherits(coords, "sf")) { 83 | return(coords) 84 | } 85 | if (inherits(coords, "SpatVector")) { 86 | return(sf::st_as_sf(coords)) 87 | } 88 | if (is.matrix(coords)) coords <- data.frame(coords) 89 | if (is.data.frame(coords)) colnames(coords) <- c("x", "y") 90 | return(sf::st_as_sf(coords, coords = c("x", "y"))) 91 | } 92 | -------------------------------------------------------------------------------- /R/format_data.R: -------------------------------------------------------------------------------- 1 | #' Check if an object is a vcf or a path to a vcf 2 | #' 3 | #' @param x vcfR object or path to vcf 4 | #' 5 | #' @return vcf object 6 | #' @export 7 | #' 8 | #' @noRd 9 | vcf_check <- function(x) { 10 | if (class(x)[1] == "vcfR") { 11 | vcf <- x 12 | } else if (is.character(x)) { 13 | if (file.exists(x)) { 14 | vcf <- vcfR::read.vcfR(x) 15 | } else { 16 | stop("Cannot open file: No such file or directory") 17 | } 18 | } else { 19 | stop("Input is expected to be an object of class 'vcfR' or a path to a .vcf file") 20 | } 21 | 22 | return(vcf) 23 | } 24 | 25 | #' Remove islands from mapping 26 | #' 27 | #' @param input raster (SpatRaster or Raster*) or coordinates (sf or two column dataframe) to mask or remove island points from 28 | #' @param shape SpatialPolygons, sf, or sf object to create island mask 29 | #' @param min_vertices minimum number of vertices in polygons to retain (defaults to 10000) 30 | #' 31 | #' @return object (of input type) with islands removed 32 | #' @export 33 | 34 | rm_islands <- function(input, shape, min_vertices = 10000) { 35 | # Convert if SpatVector provided ------------------------------------------ 36 | if (inherits(shape, "SpatVector")) shape <- sf::st_as_sf(shape) 37 | 38 | no_island <- rmapshaper::ms_filter_islands(shape, min_vertices = min_vertices) 39 | 40 | # convert SpatRaster to Raster 41 | if (inherits(input, "Raster")) input <- terra::rast(input) 42 | 43 | if (inherits(input, "SpatRaster")) { 44 | raster_noIsland <- terra::mask(input, no_island) 45 | return(raster_noIsland) 46 | } 47 | 48 | if (inherits(input, "data.frame") & !inherits(input, "sf")) { 49 | if (ncol(input) != 2) stop("Expected two columns (x and y)") 50 | colnames(input) <- c("x", "y") 51 | input <- sf::st_as_sf(input, coords = c("x", "y"), crs = sf::st_crs(shape)) 52 | } 53 | 54 | if (inherits(input, "sf")) { 55 | input <- sf::st_transform(input, sf::st_crs(shape)) 56 | coords_noIsland <- sf::st_intersection(input, no_island) 57 | return(coords_noIsland) 58 | } 59 | 60 | } 61 | 62 | #' Scale three layers of environmental data to R, G, and B for mapping 63 | #' 64 | #' @param env SpatRaster or Raster* with three layers 65 | #' 66 | #' @return RGB-scaled values 67 | #' @export 68 | scaleRGB <- function(env) { 69 | # Convert to SpatRaster if RasterStack provided --------------------------- 70 | if (!inherits(env, "SpatRaster")) env <- terra::rast(env) 71 | 72 | # Assign RGB values to each layer ----------------------------------------- 73 | for (layer in 1:3) { 74 | minval <- terra::minmax(env[[layer]])[1, ] 75 | maxval <- terra::minmax(env[[layer]])[2, ] 76 | env[[layer]] <- ((env[[layer]] - minval) / (maxval - minval)) * 255 77 | } 78 | 79 | return(env) 80 | } 81 | -------------------------------------------------------------------------------- /R/get_worldclim.R: -------------------------------------------------------------------------------- 1 | #' Download and merge WorldClim data for study area 2 | #' 3 | #' @param coords Dataframe with x and y sample coordinates. 4 | #' @param res The resolution of WorldClim data to download; options are 0.5, 2.5, 5, and 10 arc-minutes (default = 0.5). 5 | #' @param save_output Whether to save downloaded worldclim data in a tmp folder in the working directory (default = FALSE). 6 | #' @param buff A buffer area around sample points for cropping the data layers, expressed as a proportion of the spatial extent for the coordinates (default = 0.01). 7 | #' 8 | #' @details 9 | #' If res = 0.5 then the individual WorldClim tiles that cover the sample coordinates are downloaded and merged. If res > 2.5 then global layers are downloaded. 10 | #' The buffer area maintains a large extent for the final cropped data layers around the sample coordinates. e.g. buff = 0.01 creates a 1% buffer area around the coordinates. 11 | #' @return A SpatRaster of WorldClim layers. 12 | #' @export 13 | get_worldclim <- function(coords, res = 0.5, buff = 0.01, save_output = FALSE) { 14 | # Raster of worldclim tiles 15 | r <- terra::rast(vals = 1:72, nrows = 6, ncols = 12, ext = terra::ext(c(-180, 180, -90, 90))) 16 | 17 | # Make sf object with convex hull of coords 18 | coords <- coords_to_sf(coords) 19 | ch_sf <- sf::st_convex_hull(sf::st_union(coords)) 20 | 21 | # Identify WorldClim tiles to download 22 | r_nums <- terra::extract(r, terra::vect(ch_sf), ID = FALSE) 23 | r_xy <- terra::xyFromCell(r, r_nums[[1]]) 24 | 25 | folder <- paste0(getwd(), "/tmp") 26 | # Download and merge tiles 27 | if (res == 0.5) { 28 | message("Downloading WorldClim tile 1...") 29 | wclim <- geodata::worldclim_tile(var = "bio", lon = r_xy[1, 1], lat = r_xy[1, 2], path = folder) 30 | if (length(r_nums[[1]]) > 1) { 31 | for (i in 2:length(r_nums[[1]])) { 32 | message(paste0("Downloading WorldClim tile ", i, "...")) 33 | wc <- geodata::worldclim_tile(var = "bio", lon = r_xy[i, 1], lat = r_xy[i, 2], path = folder) 34 | wclim <- terra::merge(wclim, wc) 35 | } 36 | } 37 | } else { 38 | wclim <- geodata::worldclim_global(var = "bio", res = res, path = folder) 39 | } 40 | 41 | # Define crop area based on buffer size 42 | buff_ext <- as.vector(terra::ext(coords)) 43 | ext_vals <- c() 44 | if (buff_ext["xmin"] < 0) { 45 | ext_vals[1] <- buff_ext["xmin"] * (1 + buff) 46 | } else { 47 | ext_vals[1] <- buff_ext["xmin"] * (1 - buff) 48 | } 49 | if (buff_ext["xmax"] < 0) { 50 | ext_vals[2] <- buff_ext["xmax"] * (1 - buff) 51 | } else { 52 | ext_vals[2] <- buff_ext["xmax"] * (1 + buff) 53 | } 54 | if (buff_ext["ymin"] < 0) { 55 | ext_vals[3] <- buff_ext["ymin"] * (1 + buff) 56 | } else { 57 | ext_vals[3] <- buff_ext["ymin"] * (1 - buff) 58 | } 59 | if (buff_ext["ymax"] < 0) { 60 | ext_vals[4] <- buff_ext["ymax"] * (1 - buff) 61 | } else { 62 | ext_vals[4] <- buff_ext["ymax"] * (1 + buff) 63 | } 64 | buff_ext <- terra::ext(ext_vals) 65 | 66 | # Crop raster stack to buffered area 67 | wclim <- terra::crop(wclim, buff_ext) 68 | 69 | # Assign names to bioclim vars 70 | names(wclim) <- c( 71 | "bio1", "bio2", "bio3", "bio4", "bio5", "bio6", "bio7", "bio8", "bio9", "bio10", 72 | "bio11", "bio12", "bio13", "bio14", "bio15", "bio16", "bio17", "bio18", "bio19" 73 | ) 74 | 75 | if (save_output == FALSE) { 76 | unlink(folder, recursive = TRUE) 77 | } 78 | 79 | return(wclim) 80 | } 81 | -------------------------------------------------------------------------------- /R/load_example.R: -------------------------------------------------------------------------------- 1 | #' Load example data 2 | #' 3 | #' Example dataset from [Bouzid et al. 2022](https://doi.org/10.1111/mec.15836). The code used to create this dataset can be found under data-raw/DATASET 4 | #' 5 | #' @param quiet whether to operate quietly and suppress messages (defaults to FALSE) 6 | #' 7 | #' @return loads liz_vcf, liz_gendist, liz_coords, and CA_env objects 8 | #' @export 9 | load_algatr_example <- function(quiet = FALSE) { 10 | # Load all data 11 | utils::data(list = c("liz_vcf", "liz_coords", "liz_gendist", "CA_env")) 12 | 13 | if (!quiet) { 14 | # Give message with information about objects 15 | return(message(cat( 16 | crayon::cyan(crayon::bold("\n---------------- example dataset ----------------\n")), 17 | crayon::blue("\nObjects loaded:"), 18 | crayon::yellow(crayon::bold("\n*liz_vcf*")), 19 | crayon::yellow(paste0("vcfR object (1000 loci x 53 samples)")), 20 | crayon::yellow(crayon::bold("\n*liz_gendist*")), 21 | crayon::yellow(paste0("genetic distance matrix (Plink Distance)")), 22 | crayon::green(crayon::bold("\n*liz_coords*")), crayon::green("dataframe with x and y coordinates"), 23 | crayon::magenta(crayon::bold("\n*CA_env*")), crayon::magenta("RasterStack with example environmental layers"), 24 | crayon::cyan(crayon::bold("\n\n-------------------------------------------------\n")) 25 | ))) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | #' @param lhs A value or the magrittr placeholder. 12 | #' @param rhs A function call using the magrittr semantics. 13 | #' @return The result of calling `rhs(lhs)`. 14 | NULL 15 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | #' Helper function to create statistic vector for gt() tables 2 | #' 3 | #' @param stat_name name of statistic 4 | #' @param stat value of statistic 5 | #' @param df dataframe you will eventually add statistic to 6 | #' 7 | #' @return vector with statistic value and name and NA fillers for remaining columns 8 | #' @export 9 | #' @noRd 10 | #' 11 | make_stat_vec <- function(stat_name, stat, df) { 12 | stat_vec <- rep(NA, ncol(df)) 13 | stat_vec[1] <- stat_name 14 | stat_vec[2] <- stat 15 | names(stat_vec) <- colnames(df) 16 | return(stat_vec) 17 | } 18 | -------------------------------------------------------------------------------- /R/vcf_to_dosage.R: -------------------------------------------------------------------------------- 1 | 2 | #' Convert a vcf to a dosage matrix 3 | #' 4 | #' @param x can either be an object of class `vcfR` or a path to a .vcf file 5 | #' 6 | #' @return dosage matrix 7 | #' @export 8 | vcf_to_dosage <- function(x) { 9 | if (!inherits(x, "vcfR")) { 10 | x <- vcfR::read.vcfR(x) 11 | } 12 | genlight <- vcfR::vcfR2genlight(x) 13 | gen <- as.matrix(genlight) 14 | return(gen) 15 | } 16 | -------------------------------------------------------------------------------- /R/warnings.R: -------------------------------------------------------------------------------- 1 | # Internal environment to track warnings (not exported) 2 | .my_pkg_env <- new.env(parent = emptyenv()) 3 | 4 | # Function to emit a DPS warning once per session 5 | dps_warning <- function() { 6 | if (isTRUE(getOption("wingen.quiet_dps_warning", FALSE))) { 7 | return(invisible(NULL)) # User opted out of warning 8 | } 9 | 10 | if (!isTRUE(.my_pkg_env$dps_warning)) { 11 | warning( 12 | paste0( 13 | "Prior to May 2025, this function incorrectly returned the proportion of shared alleles (PS) ", 14 | "instead of the genetic distance measure: DPS = 1 - PS. ", 15 | "Please review results from prior versions accordingly. ", 16 | "This warning will appear once per session. ", 17 | "To suppress, set options(wingen.quiet_dps_warning = TRUE)." 18 | ), 19 | call. = FALSE 20 | ) 21 | .my_pkg_env$dps_warning <- TRUE 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://thewanglab.github.io/algatr/ 2 | template: 3 | bootstrap: 5 4 | navbar: 5 | components: 6 | articles: 7 | text: Vignettes 8 | menu: 9 | - text: Genetic data processing 10 | href: articles/data_processing_vignette.html 11 | - text: Environmental data processing 12 | href: articles/enviro_data_vignette.html 13 | - text: Masking 14 | href: articles/masking_vignette.html 15 | - text: Genetic distances 16 | href: articles/gen_dist_vignette.html 17 | - text: TESS 18 | href: articles/TESS_vignette.html 19 | - text: MMRR 20 | href: articles/MMRR_vignette.html 21 | - text: GDM 22 | href: articles/GDM_vignette.html 23 | - text: RDA 24 | href: articles/RDA_vignette.html 25 | - text: LFMM 26 | href: articles/LFMM_vignette.html 27 | - text: Wingen 28 | href: articles/wingen_vignette.html 29 | - text: Alazygatr 30 | href: articles/alazygatr_vignette.html 31 | reference: 32 | text: "Reference Manual" 33 | href: reference/index.html 34 | 35 | reference: 36 | - title: Genetic data processing 37 | - contents: 38 | - starts_with("data_processing") 39 | - gen_to_geno 40 | - geno_to_dosage 41 | - ld_prune 42 | - simple_impute 43 | - str_impute 44 | - vcf_to_dosage 45 | - title: Environmental data processing 46 | - contents: 47 | - starts_with("envirodata") 48 | - starts_with("check") 49 | - env_dist 50 | - geo_dist 51 | - get_worldclim 52 | - rm_islands 53 | - title: Masking 54 | - contents: 55 | - ends_with("mask") 56 | - plot_extrap_mask 57 | - starts_with("masking") 58 | - title: Genetic distances 59 | - contents: 60 | - starts_with("gen_dist") 61 | - title: TESS 62 | - contents: 63 | - starts_with("tess") 64 | - bestK 65 | - geom_tess 66 | - title: MMRR 67 | - contents: 68 | - starts_with("mmrr") 69 | - MMRR 70 | - unfold 71 | - title: GDM 72 | - contents: 73 | - starts_with("gdm") 74 | - scale01 75 | - scaleRGB 76 | - title: RDA 77 | - contents: 78 | - starts_with("rda") 79 | - title: LFMM 80 | - contents: 81 | - starts_with("lfmm") 82 | - starts_with("select_K") 83 | - quick_elbow 84 | - title: Wingen 85 | - contents: 86 | - starts_with("wingen") 87 | - title: Alazygatr 88 | - contents: 89 | - starts_with("alazygatr") 90 | - do_everything_for_me 91 | - title: Data 92 | - contents: 93 | - load_algatr_example 94 | - CA_env 95 | - starts_with("liz_") 96 | - title: Other 97 | - contents: 98 | - starts_with("coords") 99 | -------------------------------------------------------------------------------- /algatr.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | LineEndingConversion: Posix 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /data-raw/DATASET.R: -------------------------------------------------------------------------------- 1 | # Code to create example data ------------------------------------------------------------- 2 | 3 | # Raw Sceloporus data files from: 4 | # Bouzid N, Archie JW, Anderson RA, Grummer JA, Leaché AD (2022) 5 | # Evidence for ephemeral ring species formation during the diversification history of western fence lizards (Sceloporus occidentalis) 6 | # Molecular Ecology, 31: 620-631. doi: https://doi.org/10.1111/mec.15836 7 | 8 | # liz_vcf ----------------------------------------------------------------- 9 | 10 | # Load and save vcf subset 11 | liz_vcf <- vcfR::read.vcfR("inst/extdata/populations_r20.haplotypes.filtered_m70_randomSNP.vcf") 12 | # Subsample 1000 SNPs 13 | liz_vcf <- liz_vcf[1:1000, ] 14 | 15 | 16 | # CA shapefile ------------------------------------------------------------ 17 | 18 | # Get CA shapefile 19 | # Download states from tigris 20 | states <- tigris::states(cb = TRUE) 21 | # Reproject into WGS84 to match coordinates 22 | states <- sf::st_transform(states, 4326) 23 | # Convert to SPDF 24 | states <- sf::as_Spatial(states) 25 | # Subset out CA 26 | CA <- states[which(states$NAME == "California"), "STUSPS"] 27 | 28 | 29 | # liz_coords -------------------------------------------------------------- 30 | 31 | # Load and save coords 32 | liz_coords <- read.table("inst/extdata/Scelop.coord") 33 | # Rename cols 34 | colnames(liz_coords) <- c("x", "y") 35 | # Get sample IDs from vcf data 36 | liz_coords$ID <- colnames(liz_vcf@gt)[-1] 37 | # Create spatial coordinates 38 | sp::coordinates(liz_coords) <- ~ x + y 39 | # Add CRS 40 | raster::crs(liz_coords) <- raster::crs(CA) 41 | # Only include coordinates within CA 42 | liz_coords <- liz_coords[CA, ] 43 | # Get IDS of coordinates within CA (to use to subset VCF) 44 | IDS <- liz_coords$ID 45 | # Create dataframe 46 | liz_coords <- data.frame(liz_coords) 47 | # Only keep x and y 48 | liz_coords <- liz_coords[, c("x", "y")] 49 | usethis::use_data(liz_coords, overwrite = TRUE) 50 | 51 | # Subset vcf to match coords 52 | index <- colnames(liz_vcf@gt) %in% IDS 53 | # First col is format col 54 | index[1] <- TRUE 55 | # Subset vcf to match coords 56 | liz_vcf <- liz_vcf[, index] 57 | usethis::use_data(liz_vcf, overwrite = TRUE) 58 | 59 | # Check IDs match (remember first col is format) 60 | stopifnot(colnames(liz_vcf@gt)[-1] == IDS) 61 | 62 | 63 | # CA_env ------------------------------------------------------------------ 64 | 65 | # Load env data 66 | CA_env <- raster::stack(list.files("inst/extdata/PC_layers/", full.names = TRUE)) 67 | raster::writeRaster(CA_env, "inst/extdata/CA_env.tif", overwrite = TRUE) 68 | CA_env <- raster::readAll(CA_env) 69 | usethis::use_data(CA_env, overwrite = TRUE) 70 | 71 | CA_env <- raster::stack(list.files("inst/extdata/PC_layers/", full.names = TRUE)) 72 | raster::writeRaster(CA_env, "inst/extdata/CA_env.tif", overwrite = TRUE) 73 | CA_env <- raster::readAll(CA_env) 74 | usethis::use_data(CA_env, overwrite = TRUE) 75 | 76 | 77 | dos <- dos[complete.cases(dos), ] 78 | prcomp(~., data.frame(dos)) 79 | 80 | 81 | # liz_gendist ------------------------------------------------------------- 82 | 83 | # Process plink genetic distances 84 | liz_gendist <- as.data.frame(readr::read_tsv("inst/extdata/liz_test.dist", col_names = FALSE)) 85 | plink_names <- readr::read_tsv("inst/extdata/liz_test.dist.id", col_names = FALSE) %>% 86 | dplyr::select(-`X1`) %>% 87 | as.matrix() 88 | 89 | # Assign row and col names according to sampleID 90 | rownames(liz_gendist) <- plink_names 91 | colnames(liz_gendist) <- plink_names 92 | usethis::use_data(liz_gendist, overwrite = TRUE) 93 | -------------------------------------------------------------------------------- /data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/data/.DS_Store -------------------------------------------------------------------------------- /data/CA_env.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/data/CA_env.rda -------------------------------------------------------------------------------- /data/liz_coords.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/data/liz_coords.rda -------------------------------------------------------------------------------- /data/liz_gendist.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/data/liz_gendist.rda -------------------------------------------------------------------------------- /data/liz_vcf.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/data/liz_vcf.rda -------------------------------------------------------------------------------- /data/wclim.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/data/wclim.RData -------------------------------------------------------------------------------- /inst/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/inst/.DS_Store -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry( 2 | bibtype = "Article", 3 | title = "Individual-based landscape genomics for conservation: An analysis pipeline", 4 | author = c( 5 | person("E. Anne", "Chambers", , email = "eachambers@berkeley.edu", role = c("aut"), 6 | comment = c(ORCID="0000-0002-7369-0108")), 7 | person("Anusha P.", "Bishop", , email = "anusha.bishop@berkeley.edu", role = c("aut"), 8 | comment = c(ORCID="0000-0003-1731-8683")), 9 | person("Ian J.", "Wang", , email = "ianwang@berkeley.edu", role = "aut", 10 | comment = c(ORCID = "0000-0003-2554-9414")) 11 | ), 12 | journal = "Molecular Ecology Resources", 13 | year = "2023", 14 | volume = "00", 15 | number = "", 16 | pages = "1–12", 17 | doi = "10.1111/1755-0998.13884" 18 | ) 19 | -------------------------------------------------------------------------------- /inst/extdata/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/inst/extdata/.DS_Store -------------------------------------------------------------------------------- /inst/extdata/CA_env.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/inst/extdata/CA_env.tif -------------------------------------------------------------------------------- /inst/extdata/PC_layers/CA_rPCA1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/inst/extdata/PC_layers/CA_rPCA1.tif -------------------------------------------------------------------------------- /inst/extdata/PC_layers/CA_rPCA2.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/inst/extdata/PC_layers/CA_rPCA2.tif -------------------------------------------------------------------------------- /inst/extdata/PC_layers/CA_rPCA3.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/inst/extdata/PC_layers/CA_rPCA3.tif -------------------------------------------------------------------------------- /inst/extdata/Scelop.coord: -------------------------------------------------------------------------------- 1 | -120.3972 41.5612 2 | -115.0246 41.0444 3 | -116.8923 34.1694 4 | -114.2881 38.2219 5 | -124.0408 40.9045 6 | -114.1127 37.4009 7 | -118.5614 37.7883 8 | -119.71942 37.72386 9 | -121.8467 36.3544 10 | -117.8515 39.4968 11 | -119.7972 35.0723 12 | -114.922 39.909 13 | -114.6068 38.0485 14 | -119.881 37.7587 15 | -120.9191 35.4894 16 | -114.6856 37.5927 17 | -119.0071 43.7161 18 | -117.9283 34.1546 19 | -120.7937 45.8479 20 | -116.7229 38.3105 21 | -122.0512 37.6487 22 | -119.80966 37.90945 23 | -117.4551 36.6001 24 | -123.0269 38.9719 25 | -115.3688 41.3688 26 | -116.6993 40.3369 27 | -117.544 41.6001 28 | -120.983 40.038 29 | -120.983 40.038 30 | -117.577 38.952 31 | -117.577 38.952 32 | -118.4764 41.2662 33 | -119.5209 36.4919 34 | -121.8005 42.2155 35 | -118.804 35.437 36 | -118.0962 33.7735 37 | -118.039 37.1609 38 | -120.6775 47.5888 39 | -119.5833 38.3093 40 | -119.6094 40.8862 41 | -115.4655 40.6747 42 | -120.2805 40.4301 43 | -120.2805 40.4301 44 | -122.3604 48.11957 45 | -116.4182 32.872 46 | -116.4182 32.872 47 | -121.265 37.451 48 | -115.517 35.987 49 | -118.766 36.54644 50 | -115.3776 37.6083 51 | -115.3776 37.6083 52 | -115.0881 36.6914 53 | -115.0881 36.6914 54 | -122.302 48.072 55 | -118.0596 36.2429 56 | -118.0596 36.2429 57 | -118.2342 40.31 58 | -118.2342 40.31 59 | -115.673 39.405 60 | -115.673 39.405 61 | -119.41233 37.87863 62 | -118.7434 34.6164 63 | -118.7434 34.6164 64 | -120.815 36.1878 65 | -119.342 34.597 66 | -117.0572 36.0111 67 | -117.0572 36.0111 68 | -122.32632 48.09322 69 | -119.7282 34.4295 70 | -120.9357 44.8948 71 | -120.9357 44.8948 72 | -121.0729 44.4075 73 | -121.0729 44.4075 74 | -122.0953 37.2304 75 | -122.0953 37.2304 76 | -114.7908 42.5125 77 | -123.741 42.2953 78 | -123.741 42.2953 79 | -117.18098 43.69493 80 | -123.1022 43.9909 81 | -116.51434 33.5624 82 | -116.51434 33.5624 83 | -121.7913 39.1855 84 | -122.344886 48.105321 85 | -114.2213 40.591 86 | -114.2213 40.591 87 | -122.322 48.088 88 | -119.72763 37.95932 89 | -119.72763 37.95932 90 | -119.64165 37.54785 91 | -120.4329 37.9409 92 | -120.4329 37.9409 93 | -122.7133 38.1629 94 | -118.929 43.437 95 | -117.602 34.3846 96 | -117.602 34.3846 97 | -120.8275 46.7277 98 | -120.8275 46.7277 99 | -116.4493 34.0929 100 | -118.81443 34.04187 101 | -118.81443 34.04187 -------------------------------------------------------------------------------- /inst/extdata/liz_test.dist.id: -------------------------------------------------------------------------------- 1 | ALT3 ALT3 2 | BAR360 BAR360 3 | BLL5 BLL5 4 | BNT5 BNT5 5 | BOF1 BOF1 6 | BOT3 BOT3 7 | CAR1 CAR1 8 | CTR7 CTR7 9 | CYR26 CYR26 10 | FCT13 FCT13 11 | HAY2 HAY2 12 | HHR2 HHR2 13 | HNT18 HNT18 14 | HOP1 HOP1 15 | INK1 INK1 16 | INK6 INK6 17 | KBG6 KBG6 18 | KRV3 KRV3 19 | LBH40 LBH40 20 | LCV19 LCV19 21 | LFV10 LFV10 22 | LTF1 LTF1 23 | LTF6 LTF6 24 | MLG2 MLG2 25 | MLG5 MLG5 26 | MNR2 MNR2 27 | MRO3 MRO3 28 | OLA14 OLA14 29 | OLA9 OLA9 30 | POT1 POT1 31 | PRU1 PRU1 32 | PRU6 PRU6 33 | PT8 PT8 34 | REY5 REY5 35 | RPS38 RPS38 36 | RPS9 RPS9 37 | SBR10 SBR10 38 | SKY3 SKY3 39 | SKY5 SKY5 40 | SRM1 SRM1 41 | SRM7 SRM7 42 | SUT7 SUT7 43 | TTC1 TTC1 44 | TTC2 TTC2 45 | WAW1 WAW1 46 | WDC1 WDC1 47 | WDC2 WDC2 48 | WHR2 WHR2 49 | WTW14 WTW14 50 | WTW3 WTW3 51 | YUC3 YUC3 52 | ZUM18 ZUM18 53 | ZUM20 ZUM20 54 | -------------------------------------------------------------------------------- /inst/extdata/liz_test.vcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/inst/extdata/liz_test.vcf -------------------------------------------------------------------------------- /man/CA_env.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{CA_env} 5 | \alias{CA_env} 6 | \title{Example environmental data, calculated by performing a raster PCA on 18 bioclimatic variables for state of California} 7 | \format{ 8 | A RasterStack object with three environmental PC layers 9 | } 10 | \usage{ 11 | CA_env 12 | } 13 | \description{ 14 | Example environmental data, calculated by performing a raster PCA on 18 bioclimatic variables for state of California 15 | } 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/MMRR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{MMRR} 4 | \alias{MMRR} 5 | \title{MMRR performs Multiple Matrix Regression with Randomization analysis} 6 | \usage{ 7 | MMRR(Y, X, nperm = 999, scale = TRUE) 8 | } 9 | \arguments{ 10 | \item{Y}{is a dependent distance matrix} 11 | 12 | \item{X}{is a list of independent distance matrices (with optional names)} 13 | 14 | \item{nperm}{is the number of permutations to be used in significance tests. Default = 999.} 15 | 16 | \item{scale}{if TRUE then matrices will be standardized. Default = TRUE.} 17 | } 18 | \description{ 19 | MMRR performs Multiple Matrix Regression with Randomization analysis 20 | } 21 | \details{ 22 | When using MMRR, please cite the original citation: 23 | Wang I.J. (2013) Examining the full effects of landscape heterogeneity on spatial genetic variation: a multiple matrix regression approach for quantifying geographic and ecological isolation. Evolution, 67: 3403-3411. 24 | } 25 | \seealso{ 26 | Other MMRR functions: 27 | \code{\link{mmrr_df}()}, 28 | \code{\link{mmrr_do_everything}()}, 29 | \code{\link{mmrr_plot}()}, 30 | \code{\link{mmrr_run}()}, 31 | \code{\link{mmrr_table}()}, 32 | \code{\link{mmrr_var_sel}()}, 33 | \code{\link{unfold}()} 34 | } 35 | \concept{MMRR functions} 36 | -------------------------------------------------------------------------------- /man/alazygatr_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{alazygatr_packages} 4 | \alias{alazygatr_packages} 5 | \title{Install alazygatr packages} 6 | \usage{ 7 | alazygatr_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for running alazygatr. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \examples{ 17 | \dontrun{alazygatr_packages()} 18 | } 19 | -------------------------------------------------------------------------------- /man/allK_plot_helper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{allK_plot_helper} 4 | \alias{allK_plot_helper} 5 | \title{Helper function for all K plotting} 6 | \usage{ 7 | allK_plot_helper(K, krig_admix, coords = NULL, col, col_breaks, ...) 8 | } 9 | \arguments{ 10 | \item{K}{K value} 11 | 12 | \item{krig_admix}{RasterStack returned by \link[algatr]{tess_krig}} 13 | 14 | \item{coords}{dataframe with x and y coordinates for plotting (optional)} 15 | 16 | \item{col}{single color code} 17 | 18 | \item{col_breaks}{number of breaks for plotting (defaults to 20)} 19 | 20 | \item{...}{Graphical parameters. Any argument that can be passed to image.plot and to base plot} 21 | } 22 | \description{ 23 | Helper function for all K plotting 24 | } 25 | \seealso{ 26 | Other TESS functions: 27 | \code{\link{bestK}()}, 28 | \code{\link{geom_tess}()}, 29 | \code{\link{ggbarplot_helper}()}, 30 | \code{\link{pops_helper}()}, 31 | \code{\link{tess_barplot}()}, 32 | \code{\link{tess_col_default}()}, 33 | \code{\link{tess_do_everything}()}, 34 | \code{\link{tess_ggbarplot}()}, 35 | \code{\link{tess_ggplot}()}, 36 | \code{\link{tess_krig}()}, 37 | \code{\link{tess_ktest}()}, 38 | \code{\link{tess_legend}()}, 39 | \code{\link{tess_plot_allK}()} 40 | } 41 | \concept{TESS functions} 42 | \keyword{internal} 43 | -------------------------------------------------------------------------------- /man/bestK.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{bestK} 4 | \alias{bestK} 5 | \title{Best K Selection based on cross entropy} 6 | \usage{ 7 | bestK(tess3_obj, Kvals) 8 | } 9 | \arguments{ 10 | \item{tess3_obj}{list produced by \code{\link{tess3}}} 11 | 12 | \item{Kvals}{vector of K values for testing} 13 | } 14 | \description{ 15 | Best K Selection based on cross entropy 16 | } 17 | \note{ 18 | (source: https://chazhyseni.github.io/NALgen/post/determining_bestk/) 19 | } 20 | \seealso{ 21 | Other TESS functions: 22 | \code{\link{allK_plot_helper}()}, 23 | \code{\link{geom_tess}()}, 24 | \code{\link{ggbarplot_helper}()}, 25 | \code{\link{pops_helper}()}, 26 | \code{\link{tess_barplot}()}, 27 | \code{\link{tess_col_default}()}, 28 | \code{\link{tess_do_everything}()}, 29 | \code{\link{tess_ggbarplot}()}, 30 | \code{\link{tess_ggplot}()}, 31 | \code{\link{tess_krig}()}, 32 | \code{\link{tess_ktest}()}, 33 | \code{\link{tess_legend}()}, 34 | \code{\link{tess_plot_allK}()} 35 | } 36 | \concept{TESS functions} 37 | -------------------------------------------------------------------------------- /man/check_dists.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_vars.R 3 | \name{check_dists} 4 | \alias{check_dists} 5 | \title{Check geographic and environmental distances for collinearity} 6 | \usage{ 7 | check_dists(envlayers, coords, type = "Euclidean", lyr = NULL, sig = 0.05) 8 | } 9 | \arguments{ 10 | \item{envlayers}{SpatRaster or Raster* object} 11 | 12 | \item{coords}{dataframe with x and y sample coordinates} 13 | 14 | \item{type}{the type of geographic distance to be calculated; options are "Euclidean" for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances} 15 | 16 | \item{lyr}{DEM raster for calculating topographic distances or resistance raster for calculating resistance distances} 17 | 18 | \item{sig}{significance threshold for Mantel test} 19 | } 20 | \value{ 21 | a list with (1) a dataframe of significantly correlated variables, (2) a matrix of p-values, (3) a matrix of Mantel's r 22 | } 23 | \description{ 24 | Check geographic and environmental distances for collinearity 25 | } 26 | -------------------------------------------------------------------------------- /man/check_env.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_vars.R 3 | \name{check_env} 4 | \alias{check_env} 5 | \title{Check environmental layers for collinearity} 6 | \usage{ 7 | check_env(envlayers, threshold = 0.7) 8 | } 9 | \arguments{ 10 | \item{envlayers}{SpatRaster or Raster* object} 11 | 12 | \item{threshold}{the cutoff correlation coefficient for flagging variables as collinear (numeric; defaults to 0.7)} 13 | } 14 | \value{ 15 | a matrix of correlation coefficients 16 | } 17 | \description{ 18 | Check environmental layers for collinearity 19 | } 20 | -------------------------------------------------------------------------------- /man/check_vals.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_vars.R 3 | \name{check_vals} 4 | \alias{check_vals} 5 | \title{Check extracted values for collinearity} 6 | \usage{ 7 | check_vals(envlayers, coords, threshold = 0.7) 8 | } 9 | \arguments{ 10 | \item{envlayers}{SpatRaster or Raster* object} 11 | 12 | \item{coords}{dataframe with x and y sample coordinates} 13 | 14 | \item{threshold}{the cutoff correlation coefficient for flagging variables as collinear (numeric)} 15 | } 16 | \value{ 17 | a matrix of correlation coefficients 18 | } 19 | \description{ 20 | Check extracted values for collinearity 21 | } 22 | -------------------------------------------------------------------------------- /man/coords_to_sf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coords_convert.R 3 | \name{coords_to_sf} 4 | \alias{coords_to_sf} 5 | \title{Convert from matrix, data frame, or sf to sf (sf is a pass through)} 6 | \usage{ 7 | coords_to_sf(coords) 8 | } 9 | \arguments{ 10 | \item{coords}{sf object, data frame, or matrix representing coordinates} 11 | } 12 | \value{ 13 | converted coords in sf format 14 | } 15 | \description{ 16 | Convert from matrix, data frame, or sf to sf (sf is a pass through) 17 | } 18 | -------------------------------------------------------------------------------- /man/coords_to_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coords_convert.R 3 | \name{coords_to_sp} 4 | \alias{coords_to_sp} 5 | \title{Convert from matrix, data frame, or sf to formatted sp} 6 | \usage{ 7 | coords_to_sp(coords) 8 | } 9 | \arguments{ 10 | \item{coords}{sf object, data frame, or matrix representing coordinates} 11 | } 12 | \value{ 13 | converted coords in sp format 14 | } 15 | \description{ 16 | Convert from matrix, data frame, or sf to formatted sp 17 | } 18 | -------------------------------------------------------------------------------- /man/cor_df_helper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_vars.R 3 | \name{cor_df_helper} 4 | \alias{cor_df_helper} 5 | \title{Helper function to create correlation dataframe from matrix and filter based on threshold} 6 | \usage{ 7 | cor_df_helper(cors, threshold) 8 | } 9 | \description{ 10 | Helper function to create correlation dataframe from matrix and filter based on threshold 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/data_processing_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{data_processing_packages} 4 | \alias{data_processing_packages} 5 | \title{Install data processing packages} 6 | \usage{ 7 | data_processing_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for genetic data processing. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following packages will be installed if not already present: 18 | \itemize{ 19 | \item "gdsfmt" (from Bioconductor repository) 20 | \item "SeqArray" (from Bioconductor repository) 21 | \item "SNPRelate" (from Bioconductor repository) 22 | } 23 | } 24 | \examples{ 25 | \dontrun{data_processing_packages()} 26 | } 27 | -------------------------------------------------------------------------------- /man/do_everything_for_me.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/alazygtr.R 3 | \name{do_everything_for_me} 4 | \alias{do_everything_for_me} 5 | \title{Lazy run of all landscape genomic analyses contained within \code{algatr}} 6 | \usage{ 7 | do_everything_for_me(gen, coords, envlayers, quiet = FALSE, gators = FALSE) 8 | } 9 | \arguments{ 10 | \item{gen}{path to vcf file, a \code{vcfR} type object, or a dosage matrix} 11 | 12 | \item{coords}{dataframe with x (i.e., longitude) and y (i.e., latitude) coordinates; must be in this order} 13 | 14 | \item{envlayers}{SpatRaster or Raster* for mapping (if env is provided, the dataframe column names and envlayers layer names should be the same)} 15 | 16 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 17 | 18 | \item{gators}{set to TRUE to see some gators...} 19 | } 20 | \value{ 21 | results from all six analyses contained within algatr 22 | } 23 | \description{ 24 | Disclaimer: this is probably a bad idea... 25 | } 26 | -------------------------------------------------------------------------------- /man/env_dist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dist.R 3 | \name{env_dist} 4 | \alias{env_dist} 5 | \title{Calculate distance between environmental vars} 6 | \usage{ 7 | env_dist(env, stdz = TRUE) 8 | } 9 | \arguments{ 10 | \item{env}{dataframe or vector of environmental variables for locations} 11 | 12 | \item{stdz}{if TRUE then environmental values will be standardized (default = TRUE)} 13 | } 14 | \value{ 15 | list of environmental distances between samples (for each environmental variable) 16 | } 17 | \description{ 18 | Calculate distance between environmental vars 19 | } 20 | -------------------------------------------------------------------------------- /man/envirodata_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{envirodata_packages} 4 | \alias{envirodata_packages} 5 | \title{Install environmental and geographic data processing packages} 6 | \usage{ 7 | envirodata_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for environmental and geographic data processing. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following packages will be installed if not already present: 18 | \itemize{ 19 | \item "RStoolbox" (from GitHub repository bleutner/RStoolbox) 20 | \item "geodata" 21 | \item "corrplot" 22 | \item "vegan" 23 | \item "gdistance" 24 | \item "topoDistance" 25 | \item "rmapshaper" 26 | \item "wingen" 27 | } 28 | } 29 | \examples{ 30 | \dontrun{envirodata_packages()} 31 | } 32 | -------------------------------------------------------------------------------- /man/extrap_mask.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/masks.R 3 | \name{extrap_mask} 4 | \alias{extrap_mask} 5 | \alias{range_mask} 6 | \alias{sd_mask} 7 | \alias{buffer_mask} 8 | \alias{chull_mask} 9 | \title{Create raster mask based on coordinates} 10 | \usage{ 11 | extrap_mask(coords, envlayers, method = "range", nsd = 2, buffer_width = NULL) 12 | 13 | range_mask(coords, envlayers) 14 | 15 | sd_mask(coords, envlayers, nsd) 16 | 17 | buffer_mask(coords, envlayers, buffer_width = 0.8) 18 | 19 | chull_mask(coords, envlayers, buffer_width = NULL) 20 | } 21 | \arguments{ 22 | \item{coords}{data frame of coordinates (first column should be x and second should be y)} 23 | 24 | \item{envlayers}{SpatRaster or Raster* object with environmental values to base mask on} 25 | 26 | \item{method}{method to create mask (can be "range", "sd", "buffer", defaults to "range"). See details for more information.} 27 | 28 | \item{nsd}{number of standard deviations to use if using the "sd" method} 29 | 30 | \item{buffer_width}{buffer width to supply to \code{gBuffer} if using "buffer" method} 31 | } 32 | \value{ 33 | SpatRaster where values of 1 indicate areas that fall outside of observation range 34 | } 35 | \description{ 36 | Creates a raster that can be used to mask areas falling outside the observation range of a dataset, as defined by coordinates and corresponding raster values 37 | } 38 | \details{ 39 | method can either be: 40 | \enumerate{ 41 | \item range - uses \code{\link{range_mask}}, mask all areas with values outside of the range of any of the values of the coords 42 | \item sd - uses \code{\link{sd_mask}}, mask all areas outside the mean +/- stdev*nsd of any of the values of the coords (\code{nsd} defaults to 2) 43 | \item buffer - uses \code{\link{buffer_mask}}, mask all areas outside of the buffer_width around the coords (\code{buffer_width} defaults to 0.8) 44 | \item chull - uses \code{\link{chull_mask}}, mask all areas outside a convex hull of the points 45 | } 46 | } 47 | \section{Functions}{ 48 | \itemize{ 49 | \item \code{range_mask()}: mask based on range of data 50 | 51 | \item \code{sd_mask()}: mask based on mean and standard deviation of data 52 | 53 | \item \code{buffer_mask()}: mask based on buffers around points 54 | 55 | \item \code{chull_mask()}: mask based on range of data 56 | 57 | }} 58 | -------------------------------------------------------------------------------- /man/figures/README-RGB plot-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-RGB plot-1.pdf -------------------------------------------------------------------------------- /man/figures/README-RGB plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-RGB plot-1.png -------------------------------------------------------------------------------- /man/figures/README-RGB-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-RGB-1.png -------------------------------------------------------------------------------- /man/figures/README-plot rasters-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-plot rasters-1.pdf -------------------------------------------------------------------------------- /man/figures/README-plot rasters-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-plot rasters-1.png -------------------------------------------------------------------------------- /man/figures/README-rasters-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-rasters-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-2-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-2-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-2-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-3-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-3-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-3-4.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-3-5.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-3-6.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-4-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-4-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-4-4.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-4-5.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-4-6.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-5-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-5-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-5-4.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-5-5.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-5-6.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-6-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-6-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-6-4.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-6-5.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-7-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-7-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-7-4.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-7-5.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-8-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-8-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-9-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/README-unnamed-chunk-9-2.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/man/figures/logo.png -------------------------------------------------------------------------------- /man/gdm_coeffs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_coeffs} 4 | \alias{gdm_coeffs} 5 | \title{Get coefficients for each predictor} 6 | \usage{ 7 | gdm_coeffs(gdm_model) 8 | } 9 | \arguments{ 10 | \item{gdm_model}{model of type \code{gdm}} 11 | } 12 | \value{ 13 | dataframe of coefficients for GDM 14 | } 15 | \description{ 16 | Get coefficients for each predictor 17 | } 18 | \seealso{ 19 | Other GDM functions: 20 | \code{\link{gdm_df}()}, 21 | \code{\link{gdm_do_everything}()}, 22 | \code{\link{gdm_format}()}, 23 | \code{\link{gdm_map}()}, 24 | \code{\link{gdm_plot_diss}()}, 25 | \code{\link{gdm_plot_isplines}()}, 26 | \code{\link{gdm_plot_vars}()}, 27 | \code{\link{gdm_run}()}, 28 | \code{\link{gdm_table}()}, 29 | \code{\link{gdm_var_sel}()}, 30 | \code{\link{scale01}()} 31 | } 32 | \concept{GDM functions} 33 | -------------------------------------------------------------------------------- /man/gdm_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_df} 4 | \alias{gdm_df} 5 | \title{Create dataframe of GDM results} 6 | \usage{ 7 | gdm_df(gdm_result) 8 | } 9 | \arguments{ 10 | \item{gdm_result}{output of \link[algatr]{gdm_run}} 11 | } 12 | \value{ 13 | dataframe of gdm model coefficients 14 | } 15 | \description{ 16 | Create dataframe of GDM results 17 | } 18 | \seealso{ 19 | Other GDM functions: 20 | \code{\link{gdm_coeffs}()}, 21 | \code{\link{gdm_do_everything}()}, 22 | \code{\link{gdm_format}()}, 23 | \code{\link{gdm_map}()}, 24 | \code{\link{gdm_plot_diss}()}, 25 | \code{\link{gdm_plot_isplines}()}, 26 | \code{\link{gdm_plot_vars}()}, 27 | \code{\link{gdm_run}()}, 28 | \code{\link{gdm_table}()}, 29 | \code{\link{gdm_var_sel}()}, 30 | \code{\link{scale01}()} 31 | } 32 | \concept{GDM functions} 33 | -------------------------------------------------------------------------------- /man/gdm_do_everything.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_do_everything} 4 | \alias{gdm_do_everything} 5 | \title{GDM function to do everything (fit model, get coefficients, make and save raster)} 6 | \usage{ 7 | gdm_do_everything( 8 | gendist, 9 | coords, 10 | envlayers = NULL, 11 | env = NULL, 12 | model = "full", 13 | sig = 0.05, 14 | nperm = 50, 15 | geodist_type = "Euclidean", 16 | dist_lyr = NULL, 17 | scale_gendist = FALSE, 18 | plot_vars = TRUE, 19 | quiet = FALSE 20 | ) 21 | } 22 | \arguments{ 23 | \item{gendist}{matrix of genetic distances (must range between 0 and 1 or set scale_gendist = TRUE)} 24 | 25 | \item{coords}{dataframe with x (i.e., longitude) and y (i.e., latitude) coordinates; must be in this order} 26 | 27 | \item{envlayers}{SpatRaster or Raster* object for mapping (if \verb{env`` is provided, the dataframe column names and }envlayers`` layer names should be the same)} 28 | 29 | \item{env}{dataframe or raster object with environmental values for each coordinate; if not provided, it will be calculated based on coords/envlayers} 30 | 31 | \item{model}{whether to fit the model with all variables ("full") or to perform variable selection to determine the best set of variables ("best"); defaults to "full"} 32 | 33 | \item{sig}{alpha value for significance threshold (defaults to 0.05); only used if model = "best"} 34 | 35 | \item{nperm}{number of permutations to use to calculate variable importance; only used if model = "best" (defaults to 50)} 36 | 37 | \item{geodist_type}{the type of geographic distance to be calculated; options are "Euclidean" (default) for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances. Note: creation and plotting of the GDM raster is only possible for "Euclidean" distances} 38 | 39 | \item{dist_lyr}{DEM raster for calculating topographic distances or resistance raster for calculating resistance distances} 40 | 41 | \item{scale_gendist}{whether to scale genetic distance data from 0 to 1 (defaults to FALSE)} 42 | 43 | \item{plot_vars}{whether to create PCA plot to help in variable and map interpretation (defaults to TRUE)} 44 | 45 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 46 | } 47 | \value{ 48 | list with final model, predictor coefficients, and PCA RGB map 49 | } 50 | \description{ 51 | GDM function to do everything (fit model, get coefficients, make and save raster) 52 | } 53 | \details{ 54 | GDM is run using the gdm package: Fitzpatrick, M., Mokany, K., Manion, G., Nieto-Lugilde, D., & Ferrier, S. (2022). gdm: Generalized dissimilarity modeling. R package version 1.5.0-3. 55 | } 56 | \seealso{ 57 | Other GDM functions: 58 | \code{\link{gdm_coeffs}()}, 59 | \code{\link{gdm_df}()}, 60 | \code{\link{gdm_format}()}, 61 | \code{\link{gdm_map}()}, 62 | \code{\link{gdm_plot_diss}()}, 63 | \code{\link{gdm_plot_isplines}()}, 64 | \code{\link{gdm_plot_vars}()}, 65 | \code{\link{gdm_run}()}, 66 | \code{\link{gdm_table}()}, 67 | \code{\link{gdm_var_sel}()}, 68 | \code{\link{scale01}()} 69 | } 70 | \concept{GDM functions} 71 | -------------------------------------------------------------------------------- /man/gdm_format.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_format} 4 | \alias{gdm_format} 5 | \title{Format Data for Generalized Dissimilarity Modeling (GDM)} 6 | \usage{ 7 | gdm_format( 8 | gendist, 9 | coords, 10 | env, 11 | scale_gendist = FALSE, 12 | geodist_type = "Euclidean", 13 | distPreds = NULL, 14 | dist_lyr = NULL, 15 | gdmPred = FALSE, 16 | gdmGen = FALSE 17 | ) 18 | } 19 | \arguments{ 20 | \item{gendist}{matrix of genetic distances (must range between 0 and 1 or set scale_gendist = TRUE)} 21 | 22 | \item{coords}{dataframe with x (i.e., longitude) and y (i.e., latitude) coordinates; must be in this order} 23 | 24 | \item{env}{dataframe or raster object with environmental values for each coordinate; if not provided, it will be calculated based on coords/envlayers} 25 | 26 | \item{scale_gendist}{whether to scale genetic distance data from 0 to 1 (defaults to FALSE)} 27 | 28 | \item{geodist_type}{the type of geographic distance to be calculated; options are "Euclidean" (default) for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances. Note: creation and plotting of the GDM raster is only possible for "Euclidean" distances} 29 | 30 | \item{dist_lyr}{DEM raster for calculating topographic distances or resistance raster for calculating resistance distances} 31 | 32 | \item{gdmPred}{whether to include the gdm formatted predictor data seperately (defaults to FALSE). This dataframe contains the site number, coordinates, and environmental values at each site} 33 | 34 | \item{gdmGen}{whether to include the gdm formatted genetic data seperately (defaults to FALSE). This dataframe contains the genetic distance matrix with an additional column for site number.} 35 | } 36 | \value{ 37 | either a gdmData object if gdmGen and gdmPred are FALSE or a list of gdm data objects 38 | } 39 | \description{ 40 | Format Data for Generalized Dissimilarity Modeling (GDM) 41 | } 42 | \seealso{ 43 | Other GDM functions: 44 | \code{\link{gdm_coeffs}()}, 45 | \code{\link{gdm_df}()}, 46 | \code{\link{gdm_do_everything}()}, 47 | \code{\link{gdm_map}()}, 48 | \code{\link{gdm_plot_diss}()}, 49 | \code{\link{gdm_plot_isplines}()}, 50 | \code{\link{gdm_plot_vars}()}, 51 | \code{\link{gdm_run}()}, 52 | \code{\link{gdm_table}()}, 53 | \code{\link{gdm_var_sel}()}, 54 | \code{\link{scale01}()} 55 | } 56 | \concept{GDM functions} 57 | -------------------------------------------------------------------------------- /man/gdm_map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_map} 4 | \alias{gdm_map} 5 | \title{Make map from model} 6 | \usage{ 7 | gdm_map( 8 | gdm_model, 9 | envlayers, 10 | coords, 11 | plot_vars = TRUE, 12 | scl = 1, 13 | display_axes = FALSE, 14 | quiet = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{gdm_model}{GDM model} 19 | 20 | \item{envlayers}{SpatRaster or Raster* object (LAYER NAMES MUST CORRESPOND WITH GDM MODEL)} 21 | 22 | \item{coords}{data frame with x and y coordinates} 23 | 24 | \item{plot_vars}{whether to create PCA plot to help in variable and map interpretation (defaults to TRUE)} 25 | 26 | \item{scl}{constant for rescaling variable vectors for plotting (defaults to 1)} 27 | 28 | \item{display_axes}{display PC axes text, labels, and ticks (defaults to FALSE)} 29 | 30 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 31 | } 32 | \value{ 33 | GDM RGB map 34 | } 35 | \description{ 36 | Make map from model 37 | } 38 | \seealso{ 39 | Other GDM functions: 40 | \code{\link{gdm_coeffs}()}, 41 | \code{\link{gdm_df}()}, 42 | \code{\link{gdm_do_everything}()}, 43 | \code{\link{gdm_format}()}, 44 | \code{\link{gdm_plot_diss}()}, 45 | \code{\link{gdm_plot_isplines}()}, 46 | \code{\link{gdm_plot_vars}()}, 47 | \code{\link{gdm_run}()}, 48 | \code{\link{gdm_table}()}, 49 | \code{\link{gdm_var_sel}()}, 50 | \code{\link{scale01}()} 51 | } 52 | \concept{GDM functions} 53 | -------------------------------------------------------------------------------- /man/gdm_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{gdm_packages} 4 | \alias{gdm_packages} 5 | \title{Install GDM packages} 6 | \usage{ 7 | gdm_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for GDM. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following packages will be installed if not already present: 18 | \itemize{ 19 | \item "cowplot" 20 | \item "gdm" 21 | } 22 | } 23 | \examples{ 24 | \dontrun{gdm_packages()} 25 | } 26 | -------------------------------------------------------------------------------- /man/gdm_plot_diss.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_plot_diss} 4 | \alias{gdm_plot_diss} 5 | \title{Plot compositional dissimilarity spline plots} 6 | \usage{ 7 | gdm_plot_diss(gdm_model) 8 | } 9 | \arguments{ 10 | \item{gdm_model}{GDM model} 11 | } 12 | \value{ 13 | two spline plots of compositional dissimilarity 14 | } 15 | \description{ 16 | generates two plots: a plot of the observed response data against raw ecological distance from the model, and a plot of the observed response against the predicted response from the model (after link function is applied) 17 | } 18 | \details{ 19 | code is modified from the \code{plot.gdm()} function in the gdm package (Fitzpatrick et al. 2022) 20 | } 21 | \seealso{ 22 | Other GDM functions: 23 | \code{\link{gdm_coeffs}()}, 24 | \code{\link{gdm_df}()}, 25 | \code{\link{gdm_do_everything}()}, 26 | \code{\link{gdm_format}()}, 27 | \code{\link{gdm_map}()}, 28 | \code{\link{gdm_plot_isplines}()}, 29 | \code{\link{gdm_plot_vars}()}, 30 | \code{\link{gdm_run}()}, 31 | \code{\link{gdm_table}()}, 32 | \code{\link{gdm_var_sel}()}, 33 | \code{\link{scale01}()} 34 | } 35 | \concept{GDM functions} 36 | -------------------------------------------------------------------------------- /man/gdm_plot_isplines.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_plot_isplines} 4 | \alias{gdm_plot_isplines} 5 | \title{Plot I-splines for each variable} 6 | \usage{ 7 | gdm_plot_isplines(gdm_model, scales = "free", nrow = NULL, ncol = NULL) 8 | } 9 | \arguments{ 10 | \item{gdm_model}{GDM model} 11 | 12 | \item{scales}{Whether scales should be free ("free"; default), free in one dimension ("free_x", "free_y") or fixed ("fixed"). We recommend setting this to "free_x" to allow the x-axis to vary while keeping the y-axis fixed across all plots such that relative importance can be visualized.} 13 | 14 | \item{nrow}{Number of rows} 15 | 16 | \item{ncol}{Number of cols} 17 | } 18 | \value{ 19 | plot for each I-spline 20 | } 21 | \description{ 22 | Plot I-splines for each variable 23 | } 24 | \seealso{ 25 | Other GDM functions: 26 | \code{\link{gdm_coeffs}()}, 27 | \code{\link{gdm_df}()}, 28 | \code{\link{gdm_do_everything}()}, 29 | \code{\link{gdm_format}()}, 30 | \code{\link{gdm_map}()}, 31 | \code{\link{gdm_plot_diss}()}, 32 | \code{\link{gdm_plot_vars}()}, 33 | \code{\link{gdm_run}()}, 34 | \code{\link{gdm_table}()}, 35 | \code{\link{gdm_var_sel}()}, 36 | \code{\link{scale01}()} 37 | } 38 | \concept{GDM functions} 39 | -------------------------------------------------------------------------------- /man/gdm_plot_vars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_plot_vars} 4 | \alias{gdm_plot_vars} 5 | \title{Create a PCA plot for GDM} 6 | \usage{ 7 | gdm_plot_vars( 8 | pcaSamp, 9 | pcaRast, 10 | pcaRastRGB, 11 | coords, 12 | x = "PC1", 13 | y = "PC2", 14 | scl = 1, 15 | display_axes = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{pcaSamp}{PCA results from running prcomp()} 20 | 21 | \item{pcaRast}{raster PCA} 22 | 23 | \item{pcaRastRGB}{raster PCA rescaled to RGB} 24 | 25 | \item{coords}{dataframe with x and y coordinates} 26 | 27 | \item{x}{x-axis PC} 28 | 29 | \item{y}{y-axis PC} 30 | 31 | \item{scl}{constant for rescaling variable vectors for plotting} 32 | 33 | \item{display_axes}{whether to display axes} 34 | } 35 | \value{ 36 | GDM PCA plot 37 | } 38 | \description{ 39 | Create a PCA plot for GDM 40 | } 41 | \seealso{ 42 | Other GDM functions: 43 | \code{\link{gdm_coeffs}()}, 44 | \code{\link{gdm_df}()}, 45 | \code{\link{gdm_do_everything}()}, 46 | \code{\link{gdm_format}()}, 47 | \code{\link{gdm_map}()}, 48 | \code{\link{gdm_plot_diss}()}, 49 | \code{\link{gdm_plot_isplines}()}, 50 | \code{\link{gdm_run}()}, 51 | \code{\link{gdm_table}()}, 52 | \code{\link{gdm_var_sel}()}, 53 | \code{\link{scale01}()} 54 | } 55 | \concept{GDM functions} 56 | -------------------------------------------------------------------------------- /man/gdm_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_run} 4 | \alias{gdm_run} 5 | \title{Run GDM and return model object} 6 | \usage{ 7 | gdm_run( 8 | gendist, 9 | coords, 10 | env, 11 | model = "full", 12 | sig = 0.05, 13 | nperm = 50, 14 | scale_gendist = FALSE, 15 | geodist_type = "Euclidean", 16 | distPreds = NULL, 17 | dist_lyr = NULL 18 | ) 19 | } 20 | \arguments{ 21 | \item{gendist}{matrix of genetic distances (must range between 0 and 1 or set scale_gendist = TRUE)} 22 | 23 | \item{coords}{dataframe with x (i.e., longitude) and y (i.e., latitude) coordinates; must be in this order} 24 | 25 | \item{env}{dataframe or raster object with environmental values for each coordinate; if not provided, it will be calculated based on coords/envlayers} 26 | 27 | \item{model}{whether to fit the model with all variables ("full") or to perform variable selection to determine the best set of variables ("best"); defaults to "full"} 28 | 29 | \item{sig}{alpha value for significance threshold (defaults to 0.05); only used if model = "best"} 30 | 31 | \item{nperm}{number of permutations to use to calculate variable importance; only used if model = "best" (defaults to 50)} 32 | 33 | \item{scale_gendist}{whether to scale genetic distance data from 0 to 1 (defaults to FALSE)} 34 | 35 | \item{geodist_type}{the type of geographic distance to be calculated; options are "Euclidean" (default) for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances. Note: creation and plotting of the GDM raster is only possible for "Euclidean" distances} 36 | 37 | \item{dist_lyr}{DEM raster for calculating topographic distances or resistance raster for calculating resistance distances} 38 | } 39 | \value{ 40 | GDM model 41 | } 42 | \description{ 43 | Run GDM and return model object 44 | } 45 | \seealso{ 46 | Other GDM functions: 47 | \code{\link{gdm_coeffs}()}, 48 | \code{\link{gdm_df}()}, 49 | \code{\link{gdm_do_everything}()}, 50 | \code{\link{gdm_format}()}, 51 | \code{\link{gdm_map}()}, 52 | \code{\link{gdm_plot_diss}()}, 53 | \code{\link{gdm_plot_isplines}()}, 54 | \code{\link{gdm_plot_vars}()}, 55 | \code{\link{gdm_table}()}, 56 | \code{\link{gdm_var_sel}()}, 57 | \code{\link{scale01}()} 58 | } 59 | \concept{GDM functions} 60 | -------------------------------------------------------------------------------- /man/gdm_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_table} 4 | \alias{gdm_table} 5 | \title{Create \code{gt} table of GDM results} 6 | \usage{ 7 | gdm_table(gdm_result, digits = 2, summary_stats = TRUE, footnote = TRUE) 8 | } 9 | \arguments{ 10 | \item{gdm_result}{output of \link[algatr]{gdm_run} or \link[algatr]{gdm_do_everything} or a GDM model object} 11 | 12 | \item{digits}{number of digits to include (defaults to 2)} 13 | } 14 | \value{ 15 | An object of class \code{gt_tbl} 16 | } 17 | \description{ 18 | Create \code{gt} table of GDM results 19 | } 20 | \seealso{ 21 | Other GDM functions: 22 | \code{\link{gdm_coeffs}()}, 23 | \code{\link{gdm_df}()}, 24 | \code{\link{gdm_do_everything}()}, 25 | \code{\link{gdm_format}()}, 26 | \code{\link{gdm_map}()}, 27 | \code{\link{gdm_plot_diss}()}, 28 | \code{\link{gdm_plot_isplines}()}, 29 | \code{\link{gdm_plot_vars}()}, 30 | \code{\link{gdm_run}()}, 31 | \code{\link{gdm_var_sel}()}, 32 | \code{\link{scale01}()} 33 | } 34 | \concept{GDM functions} 35 | -------------------------------------------------------------------------------- /man/gdm_var_sel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_var_sel} 4 | \alias{gdm_var_sel} 5 | \title{Get best set of variables from a GDM model} 6 | \usage{ 7 | gdm_var_sel(gdmData, sig = 0.05, nperm = 10) 8 | } 9 | \arguments{ 10 | \item{gdmData}{data formatted using GDM package} 11 | 12 | \item{sig}{sig level for determining variable significance} 13 | 14 | \item{nperm}{number of permutations to run for variable testing} 15 | } 16 | \description{ 17 | Get best set of variables from a GDM model 18 | } 19 | \seealso{ 20 | Other GDM functions: 21 | \code{\link{gdm_coeffs}()}, 22 | \code{\link{gdm_df}()}, 23 | \code{\link{gdm_do_everything}()}, 24 | \code{\link{gdm_format}()}, 25 | \code{\link{gdm_map}()}, 26 | \code{\link{gdm_plot_diss}()}, 27 | \code{\link{gdm_plot_isplines}()}, 28 | \code{\link{gdm_plot_vars}()}, 29 | \code{\link{gdm_run}()}, 30 | \code{\link{gdm_table}()}, 31 | \code{\link{scale01}()} 32 | } 33 | \concept{GDM functions} 34 | -------------------------------------------------------------------------------- /man/gdm_varimp_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{gdm_varimp_table} 4 | \alias{gdm_varimp_table} 5 | \title{Generate a Variable Importance Table for GDM Models} 6 | \usage{ 7 | gdm_varimp_table( 8 | varimp, 9 | digits = 2, 10 | summary_stats = TRUE, 11 | nPerm = 50, 12 | geo = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{varimp}{a \code{gdmData} object or a variable importance object created by running \link[gdm]{gdm.varImp}.} 17 | 18 | \item{digits}{number of digits to include (defaults to 2)} 19 | 20 | \item{summary_stats}{whether to add summary statistics to bottom of table (defaults to TRUE).} 21 | 22 | \item{nPerm}{number of permutations to use if \code{varimp} is a \code{gdmData} object. Default is 50.} 23 | 24 | \item{geo}{whether to include geographic distance in the GDM model. Default is TRUE.} 25 | } 26 | \value{ 27 | A \code{gt} table object displaying the variable importance. 28 | } 29 | \description{ 30 | This function generates a table displaying the variable importance for Generalized Dissimilarity Models (GDM). 31 | It can take either a \code{gdmData} object or a precomputed variable importance object and outputs a formatted table. 32 | } 33 | -------------------------------------------------------------------------------- /man/gen_dist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Gen_dist.R 3 | \name{gen_dist} 4 | \alias{gen_dist} 5 | \title{Calculate genetic distances} 6 | \usage{ 7 | gen_dist( 8 | gen = NULL, 9 | dist_type = "euclidean", 10 | plink_file = NULL, 11 | plink_id_file = NULL, 12 | npc_selection = "auto", 13 | criticalpoint = 2.0234 14 | ) 15 | } 16 | \arguments{ 17 | \item{gen}{path to vcf file, a \code{vcfR} type object, or a dosage matrix} 18 | 19 | \item{dist_type}{the type of genetic distance to calculate (options: \code{"euclidean"} (default), \code{"bray_curtis"}, \code{"dps"} for proportion of shared alleles (requires vcf), \code{"plink"}, or \code{"pc"} for PC-based)} 20 | 21 | \item{plink_file}{if \code{"plink"} dist_type is used, path to plink distance file (typically ".dist"; required only for calculating plink distance). File must be a \strong{square} distance matrix.} 22 | 23 | \item{plink_id_file}{if \code{"plink"} dist_type is used, path to plink id file (typically ".dist.id"; required only for calculating plink distance)} 24 | 25 | \item{npc_selection}{if \code{dist_type = "pc"}, how to perform K selection (options: \code{"auto"} for automatic selection based on significant eigenvalues from Tracy-Widom test (default), or \code{"manual"} to examine PC screeplot and enter no. PCs into console)} 26 | 27 | \item{criticalpoint}{if \code{dist_type = "pc"} used with \code{npc_selection = "auto"}, the critical point for the significance threshold for the Tracy-Widom test within the PCA (defaults to 2.0234 which corresponds to an alpha of 0.01)} 28 | } 29 | \value{ 30 | pairwise distance matrix for given distance metric 31 | } 32 | \description{ 33 | Calculate genetic distances 34 | } 35 | \details{ 36 | Euclidean and Bray-Curtis distances calculated using the ecodist package: Goslee, S.C. and Urban, D.L. 2007. The ecodist package for dissimilarity-based analysis of ecological data. Journal of Statistical Software 22(7):1-19. DOI:10.18637/jss.v022.i07. 37 | Proportions of shared alleles calculated using the adegenet package: Jombart T. and Ahmed I. (2011) adegenet 1.3-1: new tools for the analysis of genome-wide SNP data. Bioinformatics. doi:10.1093/bioinformatics/btr521. 38 | For calculating proportions of shared alleles, missing values are ignored (i.e., prop shared alleles calculated from present values; no scaling performed) 39 | } 40 | -------------------------------------------------------------------------------- /man/gen_dist_corr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Gen_dist.R 3 | \name{gen_dist_corr} 4 | \alias{gen_dist_corr} 5 | \title{Plot the relationship between two distance metrics} 6 | \usage{ 7 | gen_dist_corr(dist_x, dist_y, metric_name_x, metric_name_y) 8 | } 9 | \arguments{ 10 | \item{dist_x}{df containing square distance matrix for x axis} 11 | 12 | \item{dist_y}{df containing square distance matrix for y axis} 13 | 14 | \item{metric_name_x}{name of distance metric for x axis; if DPS used, must be \code{"dps"}} 15 | 16 | \item{metric_name_y}{name of distance metric for y axis; if DPS used, must be \code{"dps"}} 17 | } 18 | \value{ 19 | scatterplot comparing two user-defined genetic distance metrics 20 | } 21 | \description{ 22 | Plot the relationship between two distance metrics 23 | } 24 | -------------------------------------------------------------------------------- /man/gen_dist_hm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Gen_dist.R 3 | \name{gen_dist_hm} 4 | \alias{gen_dist_hm} 5 | \title{Make heatmap of genetic distances} 6 | \usage{ 7 | gen_dist_hm(dist) 8 | } 9 | \arguments{ 10 | \item{dist}{Matrix of genetic distances} 11 | } 12 | \value{ 13 | heatmap of genetic distances 14 | } 15 | \description{ 16 | Make heatmap of genetic distances 17 | } 18 | -------------------------------------------------------------------------------- /man/gen_dist_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{gen_dist_packages} 4 | \alias{gen_dist_packages} 5 | \title{Install genetic distance packages} 6 | \usage{ 7 | gen_dist_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for genetic distance calculations. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following packages will be installed if not already present: 18 | \itemize{ 19 | \item "adegenet" 20 | \item "AssocTests" (from CRAN archive) 21 | \item "readr" 22 | \item "tibble" 23 | \item "ecodist" 24 | \item "cowplot" 25 | } 26 | } 27 | \examples{ 28 | \dontrun{gen_dist_packages()} 29 | } 30 | -------------------------------------------------------------------------------- /man/gen_to_geno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imputation.R 3 | \name{gen_to_geno} 4 | \alias{gen_to_geno} 5 | \title{Convert dosage matrix or vcf to geno type object (N.B.: this only works for diploids!)} 6 | \usage{ 7 | gen_to_geno(gen) 8 | } 9 | \arguments{ 10 | \item{gen}{a dosage matrix, an object of class 'vcfR', or an object of type snmfProject} 11 | } 12 | \value{ 13 | matrix encoded as geno type object 14 | } 15 | \description{ 16 | Convert dosage matrix or vcf to geno type object (N.B.: this only works for diploids!) 17 | } 18 | \seealso{ 19 | Other Imputation functions: 20 | \code{\link{geno_to_dosage}()}, 21 | \code{\link{simple_impute}()}, 22 | \code{\link{snmf_bestK}()}, 23 | \code{\link{snmf_crossent_helper}()}, 24 | \code{\link{str_impute}()} 25 | } 26 | \concept{Imputation functions} 27 | -------------------------------------------------------------------------------- /man/geno_to_dosage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imputation.R 3 | \name{geno_to_dosage} 4 | \alias{geno_to_dosage} 5 | \title{Convert lfmm/geno matrix to dosage matrix (N.B.: this only works for diploids!)} 6 | \usage{ 7 | geno_to_dosage(geno) 8 | } 9 | \arguments{ 10 | \item{geno}{matrix of LEA geno or lfmm format (i.e., 0 corresponds to zero reference alleles)} 11 | } 12 | \value{ 13 | matrix encoded as dosage type object (0 corresponds to two reference alleles) 14 | } 15 | \description{ 16 | Convert lfmm/geno matrix to dosage matrix (N.B.: this only works for diploids!) 17 | } 18 | \seealso{ 19 | Other Imputation functions: 20 | \code{\link{gen_to_geno}()}, 21 | \code{\link{simple_impute}()}, 22 | \code{\link{snmf_bestK}()}, 23 | \code{\link{snmf_crossent_helper}()}, 24 | \code{\link{str_impute}()} 25 | } 26 | \concept{Imputation functions} 27 | -------------------------------------------------------------------------------- /man/geo_dist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dist.R 3 | \name{geo_dist} 4 | \alias{geo_dist} 5 | \title{Calculate geographic distance between coordinates} 6 | \usage{ 7 | geo_dist(coords, type = "Euclidean", lyr = NULL) 8 | } 9 | \arguments{ 10 | \item{coords}{dataframe with x and y coordinates} 11 | 12 | \item{type}{the type of geographic distance to be calculated; options are "Euclidean" for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances.} 13 | 14 | \item{lyr}{SpatRaster or Raster* DEM for calculating topographic distances or resistance raster for calculating resistance distances (RasterLayer or SpatRaster object)} 15 | } 16 | \value{ 17 | geographic distance matrix 18 | } 19 | \description{ 20 | Calculate geographic distance between coordinates 21 | } 22 | \details{ 23 | Euclidean, or linear, distances are calculated using the geodist package: Padgham M, Sumner M (2021). geodist: Fast, Dependency-Free Geodesic Distance Calculations. R package version 0.0.7, Available: https://CRAN.R-project.org/package=geodist. 24 | Topographic distances are calculated using the topoDistance package: Wang I.J. (2020) Topographic path analysis for modeling dispersal and functional connectivity: calculating topographic distances using the TOPODISTANCE R package. Methods in Ecology and Evolution, 11: 265-272. 25 | Resistance distances are calculated using the gdistance package: van Etten, J. (2017). R package gdistance: Distances and routes on geographical grids. Journal of Statistical Software, 76(1), 1–21. 26 | } 27 | -------------------------------------------------------------------------------- /man/geom_tess.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{geom_tess} 4 | \alias{geom_tess} 5 | \title{Create geom of TESS results that can be added to a ggplot object} 6 | \usage{ 7 | geom_tess(krig_admix, plot_method = "maxQ", minQ = 0.1) 8 | } 9 | \arguments{ 10 | \item{krig_admix}{SpatRaster returned by \link[algatr]{tess_krig}} 11 | 12 | \item{plot_method}{method for making rainbow map of kriged layers (options: "maxQ" to only plot the max Q value for each cell (default), "allQ" to plot all Q values greater than \code{minQ}, "maxQ_poly" or "allQ_poly" to create the plots as previously described, but as polygons for each K instead of continuous Q values)} 13 | 14 | \item{minQ}{threshold for minimum Q-value for rainbow plotting if \code{plot_method = "allQ"} or \code{plot_method = "allQ_poly"} is used (defaults to 0.10)} 15 | } 16 | \value{ 17 | A list containing ggplot2 geom objects for plotting. 18 | } 19 | \description{ 20 | This function creates a ggplot2 geom object for visualizing TESS plots based on kriging admixture data. 21 | } 22 | \seealso{ 23 | Other TESS functions: 24 | \code{\link{allK_plot_helper}()}, 25 | \code{\link{bestK}()}, 26 | \code{\link{ggbarplot_helper}()}, 27 | \code{\link{pops_helper}()}, 28 | \code{\link{tess_barplot}()}, 29 | \code{\link{tess_col_default}()}, 30 | \code{\link{tess_do_everything}()}, 31 | \code{\link{tess_ggbarplot}()}, 32 | \code{\link{tess_ggplot}()}, 33 | \code{\link{tess_krig}()}, 34 | \code{\link{tess_ktest}()}, 35 | \code{\link{tess_legend}()}, 36 | \code{\link{tess_plot_allK}()} 37 | } 38 | \concept{TESS functions} 39 | -------------------------------------------------------------------------------- /man/get_worldclim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_worldclim.R 3 | \name{get_worldclim} 4 | \alias{get_worldclim} 5 | \title{Download and merge WorldClim data for study area} 6 | \usage{ 7 | get_worldclim(coords, res = 0.5, buff = 0.01, save_output = FALSE) 8 | } 9 | \arguments{ 10 | \item{coords}{Dataframe with x and y sample coordinates.} 11 | 12 | \item{res}{The resolution of WorldClim data to download; options are 0.5, 2.5, 5, and 10 arc-minutes (default = 0.5).} 13 | 14 | \item{buff}{A buffer area around sample points for cropping the data layers, expressed as a proportion of the spatial extent for the coordinates (default = 0.01).} 15 | 16 | \item{save_output}{Whether to save downloaded worldclim data in a tmp folder in the working directory (default = FALSE).} 17 | } 18 | \value{ 19 | A SpatRaster of WorldClim layers. 20 | } 21 | \description{ 22 | Download and merge WorldClim data for study area 23 | } 24 | \details{ 25 | If res = 0.5 then the individual WorldClim tiles that cover the sample coordinates are downloaded and merged. If res > 2.5 then global layers are downloaded. 26 | The buffer area maintains a large extent for the final cropped data layers around the sample coordinates. e.g. buff = 0.01 creates a 1\% buffer area around the coordinates. 27 | } 28 | -------------------------------------------------------------------------------- /man/ggbarplot_helper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{ggbarplot_helper} 4 | \alias{ggbarplot_helper} 5 | \title{Helper function for TESS barplots using ggplot} 6 | \usage{ 7 | ggbarplot_helper(dat) 8 | } 9 | \arguments{ 10 | \item{dat}{Q matrix} 11 | } 12 | \value{ 13 | barplot with Q-values and individuals, colorized by K-value 14 | } 15 | \description{ 16 | Helper function for TESS barplots using ggplot 17 | } 18 | \seealso{ 19 | Other TESS functions: 20 | \code{\link{allK_plot_helper}()}, 21 | \code{\link{bestK}()}, 22 | \code{\link{geom_tess}()}, 23 | \code{\link{pops_helper}()}, 24 | \code{\link{tess_barplot}()}, 25 | \code{\link{tess_col_default}()}, 26 | \code{\link{tess_do_everything}()}, 27 | \code{\link{tess_ggbarplot}()}, 28 | \code{\link{tess_ggplot}()}, 29 | \code{\link{tess_krig}()}, 30 | \code{\link{tess_ktest}()}, 31 | \code{\link{tess_legend}()}, 32 | \code{\link{tess_plot_allK}()} 33 | } 34 | \concept{TESS functions} 35 | \keyword{internal} 36 | -------------------------------------------------------------------------------- /man/krig_agg_helper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wingen.R 3 | \name{krig_agg_helper} 4 | \alias{krig_agg_helper} 5 | \title{Helper function for krig_helper; calculates aggregated/disaggregated raster cell size} 6 | \usage{ 7 | krig_agg_helper(to_krig, agg_disagg, agg_spec = "agg") 8 | } 9 | \arguments{ 10 | \item{to_krig}{object to create grid for kriging, \code{grd} or \code{r} from \link[wingen]{krig_gd}} 11 | 12 | \item{agg_disagg}{aggregation or disaggregation parameter, one of agg_grd, disagg_grd, agg_r, or disagg_r from \link[wingen]{krig_gd}} 13 | 14 | \item{agg_spec}{whether aggregation or disaggregation is performed, options are \code{"disagg"} or \code{"agg"} (defaults to \code{"agg"})} 15 | } 16 | \value{ 17 | number of cells contained in final (aggregated or disaggregated) raster layer 18 | } 19 | \description{ 20 | Helper function for krig_helper; calculates aggregated/disaggregated raster cell size 21 | } 22 | \seealso{ 23 | Other wingen functions: 24 | \code{\link{krig_helper}()}, 25 | \code{\link{wingen_do_everything}()} 26 | } 27 | \concept{wingen functions} 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/krig_helper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wingen.R 3 | \name{krig_helper} 4 | \alias{krig_helper} 5 | \title{Helper function for kriging wingen moving window; checks raster resolution and runs kriging} 6 | \usage{ 7 | krig_helper( 8 | map, 9 | grd = NULL, 10 | index = 1, 11 | agg_grd = NULL, 12 | disagg_grd = NULL, 13 | agg_r = NULL, 14 | disagg_r = NULL 15 | ) 16 | } 17 | \arguments{ 18 | \item{map}{RasterLayer or RasterStack produced by \code{window_gd()}} 19 | 20 | \item{grd}{object to create grid for kriging; inherits from \link[wingen]{krig_gd} (defaults to NULL)} 21 | 22 | \item{index}{integer indices of layers in raster stack to krige; inherits from \link[wingen]{krig_gd} (defaults to 1)} 23 | 24 | \item{agg_grd}{factor to use for aggregation of \code{grd}; inherits from \link[wingen]{krig_gd} (defaults to NULL)} 25 | 26 | \item{disagg_grd}{factor to use for disaggregation of \code{grd}; inherits from \link[wingen]{krig_gd} (defaults to NULL)} 27 | 28 | \item{agg_r}{factor to use for aggregation of \code{r}; inherits from \link[wingen]{krig_gd} (defaults to NULL)} 29 | 30 | \item{disagg_r}{factor to use for disaggregation of \code{r}; inherits from \link[wingen]{krig_gd} (defaults to NULL)} 31 | } 32 | \value{ 33 | kriged map 34 | } 35 | \description{ 36 | Helper function for kriging wingen moving window; checks raster resolution and runs kriging 37 | } 38 | \seealso{ 39 | Other wingen functions: 40 | \code{\link{krig_agg_helper}()}, 41 | \code{\link{wingen_do_everything}()} 42 | } 43 | \concept{wingen functions} 44 | \keyword{internal} 45 | -------------------------------------------------------------------------------- /man/ld_prune.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SNP_LD.R 3 | \name{ld_prune} 4 | \alias{ld_prune} 5 | \title{ld_prune prunes SNPs based on linkage disequilibrium using \code{SNPRelate} and \code{SeqArray} packages} 6 | \usage{ 7 | ld_prune( 8 | vcf, 9 | out_name, 10 | out_format, 11 | nodes = 1, 12 | ld.threshold = 0.6, 13 | slide.max.n = 100, 14 | maf = 0.05, 15 | seed = 1234, 16 | method = c("corr"), 17 | save_output = TRUE 18 | ) 19 | } 20 | \arguments{ 21 | \item{vcf}{is the path to the vcf file containing all SNPs} 22 | 23 | \item{out_name}{prefix name of output files (will append with param settings)} 24 | 25 | \item{out_format}{output file format ("plink" will produce ped and map files while "vcf" will produce a vcf and a GDS)} 26 | 27 | \item{nodes}{is the number of parallel processors (numeric)} 28 | 29 | \item{ld.threshold}{is the threshold for LD pruning (numeric; 0 - 1; defaults to 0.6)} 30 | 31 | \item{slide.max.n}{is the maximum number of SNPs in a sliding window (numeric; defaults to 100)} 32 | 33 | \item{maf}{is the minor allele frequency cutoff (numeric; defaults to 0.05)} 34 | 35 | \item{seed}{is the random starting seed (defaults to 1234)} 36 | 37 | \item{method}{is the LD threshold method; default to corr which is r2 correlation coefficient} 38 | 39 | \item{save_output}{if TRUE, saves SNP GDS and ped (plink) files with retained SNPs in new directory; if FALSE returns object (defaults to TRUE)} 40 | } 41 | \value{ 42 | LD-pruned vcf-type object 43 | } 44 | \description{ 45 | ld_prune prunes SNPs based on linkage disequilibrium using \code{SNPRelate} and \code{SeqArray} packages 46 | } 47 | \details{ 48 | \code{SNPRelate} package citation: Zheng et al. (2012): https://doi.org/10.1093/bioinformatics/bts606 49 | } 50 | -------------------------------------------------------------------------------- /man/lfmm_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{lfmm_df} 4 | \alias{lfmm_df} 5 | \title{Convert LFMM results into a tidy dataframe for downstream processing} 6 | \usage{ 7 | lfmm_df(x) 8 | } 9 | \arguments{ 10 | \item{x}{lfmm_test_result element from \code{\link{lfmm_run}} results} 11 | } 12 | \value{ 13 | tidy dataframe with LFMM results with each SNP, its p-value, association with env var and other relevant statistics 14 | } 15 | \description{ 16 | Convert LFMM results into a tidy dataframe for downstream processing 17 | } 18 | \seealso{ 19 | Other LFMM functions: 20 | \code{\link{lfmm_do_everything}()}, 21 | \code{\link{lfmm_manhattanplot}()}, 22 | \code{\link{lfmm_qqplot}()}, 23 | \code{\link{lfmm_run}()}, 24 | \code{\link{lfmm_table}()}, 25 | \code{\link{lfmm_test_tidy}()}, 26 | \code{\link{quick_elbow}()}, 27 | \code{\link{select_K}()} 28 | } 29 | \concept{LFMM functions} 30 | -------------------------------------------------------------------------------- /man/lfmm_do_everything.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{lfmm_do_everything} 4 | \alias{lfmm_do_everything} 5 | \title{LFMM function to do everything} 6 | \usage{ 7 | lfmm_do_everything( 8 | gen, 9 | env, 10 | coords = NULL, 11 | impute = "structure", 12 | K_impute = 3, 13 | entropy = TRUE, 14 | repetitions = 10, 15 | project = "new", 16 | quiet_impute = TRUE, 17 | save_output = FALSE, 18 | output_filename = NULL, 19 | K = NULL, 20 | lfmm_method = "ridge", 21 | K_selection = "tracy_widom", 22 | Kvals = 1:10, 23 | sig = 0.05, 24 | p_adj = "fdr", 25 | calibrate = "gif", 26 | criticalpoint = 2.0234, 27 | low = 0.08, 28 | max.pc = 0.9, 29 | perc.pca = 90, 30 | max.n.clust = 10, 31 | quiet = FALSE 32 | ) 33 | } 34 | \arguments{ 35 | \item{gen}{genotype dosage matrix (rows = individuals & columns = SNPs) or \code{vcfR} object} 36 | 37 | \item{env}{dataframe with environmental data or a Raster* type object from which environmental values for the coordinates can be extracted} 38 | 39 | \item{coords}{dataframe with coordinates (only needed if K selection is performed with TESS or if environmental values are not provided)} 40 | 41 | \item{impute}{if NAs in \code{gen}, imputation will be performed on missing values; options are "structure" which uses the \code{str_impute()} function to impute based on population structure inferred with \code{LEA::snmf} (default); other option is "simple" based on \code{simple_impute()} which imputes to the median} 42 | 43 | \item{K_impute}{if \code{impute = "structure"}, an integer vector (range or single value) corresponding to the number of ancestral populations for which the sNMF algorithm estimates have to be calculated (defaults to 3)} 44 | 45 | \item{entropy}{ 46 | A boolean value. If true, the cross-entropy criterion is calculated 47 | (see \code{\link[LEA]{create.dataset}} and 48 | \code{\link[LEA]{cross.entropy.estimation}}). 49 | } 50 | 51 | \item{repetitions}{ 52 | An integer corresponding with the number of repetitions for each value of 53 | \code{K}. 54 | } 55 | 56 | \item{project}{ 57 | A character string among "continue", "new", and "force". If "continue", 58 | the results are stored in the current project. If "new", the current 59 | project is removed and a new one is created to store the result. If 60 | "force", the results are stored in the current project even if the input 61 | file has been modified since the creation of the project. 62 | } 63 | 64 | \item{quiet_impute}{if \code{impute = "structure"}, whether to suppress the results of cross-entropy scores (defaults to TRUE; only does so if K is range of values); only displays run with minimum cross-entropy} 65 | 66 | \item{save_output}{if \code{impute = "structure"}, if TRUE, saves SNP GDS and ped (plink) files with retained SNPs in new directory; if FALSE returns object (defaults to FALSE)} 67 | 68 | \item{output_filename}{if \code{impute = "structure"} and \code{save_output = TRUE}, name prefix for saved .geno file, SNMF project file, and SNMF output file results (defaults to FALSE, in which no files are saved)} 69 | 70 | \item{K}{number of latent factors (if left as NULL (default), K value selection will be conducted)} 71 | 72 | \item{lfmm_method}{lfmm method (either \code{"ridge"} (default) or \code{"lasso"})} 73 | 74 | \item{K_selection}{method for performing k selection (can either by "tracy_widom" (default), "quick_elbow", "tess", or "find_clusters")} 75 | 76 | \item{Kvals}{values of K to test for "tess"} 77 | 78 | \item{sig}{alpha level for determining candidate SNPs (defaults to 0.05)} 79 | 80 | \item{p_adj}{method to use for p-value correction (defaults to "fdr"); other options can be found in \code{\link{p.adjust}}} 81 | 82 | \item{calibrate}{a character string, "gif" or "median+MAD". If the "gif" option is set (default), 83 | significance values are calibrated by using the genomic control method. Genomic control 84 | uses a robust estimate of the variance of z-scores called "genomic inflation factor". 85 | If the "median+MAD" option is set, the pvalues are calibrated by computing the median and MAD of the zscores. If \code{NULL}, the 86 | pvalues are not calibrated.} 87 | 88 | \item{criticalpoint}{if \code{K_selection = "tracy_widom"}, a numeric value corresponding to the significance level. If the significance level is 0.05, 0.01, 0.005, or 0.001, the criticalpoint should be set to be 0.9793, 2.0234, 2.4224, or 3.2724, respectively (defaults to 2.0234)} 89 | 90 | \item{low}{if \code{K_selection = "quick_elbow"}, numeric, between zero and one, the threshold that defines whether a principal component explains 'much' of the variance (defaults to 0.08).} 91 | 92 | \item{max.pc}{if \code{K_selection = "quick_elbow"}, maximum percentage of the variance to capture before the elbow (cumulative sum to PC 'n'; defaults to 0.90).} 93 | 94 | \item{perc.pca}{if \code{K_selection = "find_clusters"}, a numeric value between 0 and 100 indicating the minimal percentage of the total variance of the data to be expressed by the retained axes of PCA (defaults to 90).} 95 | 96 | \item{max.n.clust}{if \code{K_selection = "find_clusters"}, an integer indicating the maximum number of clusters to try. Values of 'k' will be picked up between 1 and max.n.clust (defaults to 10)} 97 | 98 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 99 | } 100 | \value{ 101 | list with candidate SNPs, model results, and K-value 102 | } 103 | \description{ 104 | LFMM function to do everything 105 | } 106 | \details{ 107 | LFMM is run using the lfmm package: Jumentier, B. (2021). lfmm: Latent Factor Mixed Models. R package version 1.1. 108 | See also: Caye, K., Jumentier, B., Lepeule, J., & François, O. (2019). LFMM 2: Fast and accurate inference of gene-environment associations in genome-wide studies. Mol. Biol. Evol. 36(4):852-860. doi: https://doi.org/10.1093/molbev/msz008 109 | } 110 | \seealso{ 111 | Other LFMM functions: 112 | \code{\link{lfmm_df}()}, 113 | \code{\link{lfmm_manhattanplot}()}, 114 | \code{\link{lfmm_qqplot}()}, 115 | \code{\link{lfmm_run}()}, 116 | \code{\link{lfmm_table}()}, 117 | \code{\link{lfmm_test_tidy}()}, 118 | \code{\link{quick_elbow}()}, 119 | \code{\link{select_K}()} 120 | } 121 | \concept{LFMM functions} 122 | -------------------------------------------------------------------------------- /man/lfmm_manhattanplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{lfmm_manhattanplot} 4 | \alias{lfmm_manhattanplot} 5 | \title{LFMM Manhattan Plot} 6 | \usage{ 7 | lfmm_manhattanplot(df, sig, group = NULL, var = NULL) 8 | } 9 | \arguments{ 10 | \item{df}{dataframe of lfmm test results produced by \code{lfmm_df}} 11 | 12 | \item{sig}{significance cutoff} 13 | } 14 | \value{ 15 | Manhattan plot 16 | } 17 | \description{ 18 | LFMM Manhattan Plot 19 | } 20 | \seealso{ 21 | Other LFMM functions: 22 | \code{\link{lfmm_df}()}, 23 | \code{\link{lfmm_do_everything}()}, 24 | \code{\link{lfmm_qqplot}()}, 25 | \code{\link{lfmm_run}()}, 26 | \code{\link{lfmm_table}()}, 27 | \code{\link{lfmm_test_tidy}()}, 28 | \code{\link{quick_elbow}()}, 29 | \code{\link{select_K}()} 30 | } 31 | \concept{LFMM functions} 32 | -------------------------------------------------------------------------------- /man/lfmm_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{lfmm_packages} 4 | \alias{lfmm_packages} 5 | \title{Install LFMM packages} 6 | \usage{ 7 | lfmm_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for LFMM. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following packages will be installed if not already present: 18 | \itemize{ 19 | \item "adegenet" 20 | \item "AssocTests" (from CRAN archive) 21 | \item "lfmm" 22 | \item "tess3r" (from GitHub repository bcm-uga/TESS3_encho_sen) 23 | \item "LEA" (from Bioconductor repository) 24 | } 25 | } 26 | \examples{ 27 | \dontrun{lfmm_packages()} 28 | } 29 | -------------------------------------------------------------------------------- /man/lfmm_qqplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{lfmm_qqplot} 4 | \alias{lfmm_qqplot} 5 | \title{LFMM QQplot} 6 | \usage{ 7 | lfmm_qqplot(df) 8 | } 9 | \arguments{ 10 | \item{df}{dataframe of LFMM test results produced by \code{lfmm_df}} 11 | } 12 | \value{ 13 | a QQ-plot 14 | } 15 | \description{ 16 | LFMM QQplot 17 | } 18 | \seealso{ 19 | Other LFMM functions: 20 | \code{\link{lfmm_df}()}, 21 | \code{\link{lfmm_do_everything}()}, 22 | \code{\link{lfmm_manhattanplot}()}, 23 | \code{\link{lfmm_run}()}, 24 | \code{\link{lfmm_table}()}, 25 | \code{\link{lfmm_test_tidy}()}, 26 | \code{\link{quick_elbow}()}, 27 | \code{\link{select_K}()} 28 | } 29 | \concept{LFMM functions} 30 | -------------------------------------------------------------------------------- /man/lfmm_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{lfmm_run} 4 | \alias{lfmm_run} 5 | \title{Run LFMM} 6 | \usage{ 7 | lfmm_run( 8 | gen, 9 | env, 10 | K, 11 | lfmm_method = "ridge", 12 | p_adj = "fdr", 13 | sig = 0.05, 14 | calibrate = "gif" 15 | ) 16 | } 17 | \arguments{ 18 | \item{gen}{genotype dosage matrix (rows = individuals & columns = SNPs) or \code{vcfR} object} 19 | 20 | \item{env}{dataframe with environmental data or a Raster* type object from which environmental values for the coordinates can be extracted} 21 | 22 | \item{K}{number of latent factors (if left as NULL (default), K value selection will be conducted)} 23 | 24 | \item{lfmm_method}{lfmm method (either \code{"ridge"} (default) or \code{"lasso"})} 25 | 26 | \item{p_adj}{method to use for p-value correction (defaults to "fdr"); other options can be found in \code{\link{p.adjust}}} 27 | 28 | \item{sig}{alpha level for determining candidate SNPs (defaults to 0.05)} 29 | 30 | \item{calibrate}{a character string, "gif" or "median+MAD". If the "gif" option is set (default), 31 | significance values are calibrated by using the genomic control method. Genomic control 32 | uses a robust estimate of the variance of z-scores called "genomic inflation factor". 33 | If the "median+MAD" option is set, the pvalues are calibrated by computing the median and MAD of the zscores. If \code{NULL}, the 34 | pvalues are not calibrated.} 35 | } 36 | \description{ 37 | Run LFMM 38 | } 39 | \seealso{ 40 | Other LFMM functions: 41 | \code{\link{lfmm_df}()}, 42 | \code{\link{lfmm_do_everything}()}, 43 | \code{\link{lfmm_manhattanplot}()}, 44 | \code{\link{lfmm_qqplot}()}, 45 | \code{\link{lfmm_table}()}, 46 | \code{\link{lfmm_test_tidy}()}, 47 | \code{\link{quick_elbow}()}, 48 | \code{\link{select_K}()} 49 | } 50 | \concept{LFMM functions} 51 | -------------------------------------------------------------------------------- /man/lfmm_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{lfmm_table} 4 | \alias{lfmm_table} 5 | \title{Create \code{gt} table of LFMM results} 6 | \usage{ 7 | lfmm_table( 8 | df, 9 | sig = 0.05, 10 | sig_only = TRUE, 11 | top = FALSE, 12 | order = FALSE, 13 | var = NULL, 14 | rows = NULL, 15 | digits = 2, 16 | footnotes = TRUE 17 | ) 18 | } 19 | \arguments{ 20 | \item{df}{df element from \code{\link{lfmm_run}} results} 21 | 22 | \item{sig}{alpha level for determining candidate snps (defaults to 0.5)} 23 | 24 | \item{sig_only}{only include SNPs that exceeded the significance threshold in the table (defaults to TRUE)} 25 | 26 | \item{top}{if there are SNPs that are significantly associated with multiple environmental variables, only display the top association (i.e., variable with the maximum B value; defaults to FALSE)} 27 | 28 | \item{order}{if TRUE, will order rows by decreasing B value (defaults to FALSE and orders rows based on variable)} 29 | 30 | \item{var}{display significant SNPs associated with particular environmental variable (defaults to NULL)} 31 | 32 | \item{rows}{number of rows to include in table (defaults to NULL)} 33 | 34 | \item{digits}{number of decimal points to include (defaults to 2)} 35 | } 36 | \value{ 37 | table of LFMM results 38 | } 39 | \description{ 40 | Create \code{gt} table of LFMM results 41 | } 42 | \seealso{ 43 | Other LFMM functions: 44 | \code{\link{lfmm_df}()}, 45 | \code{\link{lfmm_do_everything}()}, 46 | \code{\link{lfmm_manhattanplot}()}, 47 | \code{\link{lfmm_qqplot}()}, 48 | \code{\link{lfmm_run}()}, 49 | \code{\link{lfmm_test_tidy}()}, 50 | \code{\link{quick_elbow}()}, 51 | \code{\link{select_K}()} 52 | } 53 | \concept{LFMM functions} 54 | -------------------------------------------------------------------------------- /man/lfmm_test_tidy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{lfmm_test_tidy} 4 | \alias{lfmm_test_tidy} 5 | \title{Helper function to tidy LFMM test results} 6 | \usage{ 7 | lfmm_test_tidy(colname, lfmm_test_result) 8 | } 9 | \arguments{ 10 | \item{colname}{names of elements within lfmm_test_result} 11 | 12 | \item{lfmm_test_result}{LFMM test results} 13 | } 14 | \description{ 15 | Helper function to tidy LFMM test results 16 | } 17 | \seealso{ 18 | Other LFMM functions: 19 | \code{\link{lfmm_df}()}, 20 | \code{\link{lfmm_do_everything}()}, 21 | \code{\link{lfmm_manhattanplot}()}, 22 | \code{\link{lfmm_qqplot}()}, 23 | \code{\link{lfmm_run}()}, 24 | \code{\link{lfmm_table}()}, 25 | \code{\link{quick_elbow}()}, 26 | \code{\link{select_K}()} 27 | } 28 | \concept{LFMM functions} 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/liz_coords.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{liz_coords} 5 | \alias{liz_coords} 6 | \title{Example coordinates from Bouzid et al. 2022} 7 | \format{ 8 | A dataframe with x and y coordinates for 53 samples 9 | } 10 | \source{ 11 | \url{https://doi.org/10.1111/mec.15836} 12 | } 13 | \usage{ 14 | liz_coords 15 | } 16 | \description{ 17 | Example coordinates from Bouzid et al. 2022 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/liz_gendist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{liz_gendist} 5 | \alias{liz_gendist} 6 | \title{Example genetic distance matrix, calculated with Plink using data from Bouzid et al. 2022} 7 | \format{ 8 | A dataframe with genetic distances for 53 samples 9 | } 10 | \source{ 11 | \url{https://doi.org/10.1111/mec.15836} 12 | } 13 | \usage{ 14 | liz_gendist 15 | } 16 | \description{ 17 | Example genetic distance matrix, calculated with Plink using data from Bouzid et al. 2022 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/liz_vcf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{liz_vcf} 5 | \alias{liz_vcf} 6 | \title{Example VCF from Bouzid et al. 2022} 7 | \format{ 8 | A vcfR object with 1000 loci and 53 samples 9 | } 10 | \source{ 11 | \url{https://doi.org/10.1111/mec.15836} 12 | } 13 | \usage{ 14 | liz_vcf 15 | } 16 | \description{ 17 | Example VCF from Bouzid et al. 2022 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/load_algatr_example.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_example.R 3 | \name{load_algatr_example} 4 | \alias{load_algatr_example} 5 | \title{Load example data} 6 | \usage{ 7 | load_algatr_example(quiet = FALSE) 8 | } 9 | \arguments{ 10 | \item{quiet}{whether to operate quietly and suppress messages (defaults to FALSE)} 11 | } 12 | \value{ 13 | loads liz_vcf, liz_gendist, liz_coords, and CA_env objects 14 | } 15 | \description{ 16 | Example dataset from \href{https://doi.org/10.1111/mec.15836}{Bouzid et al. 2022}. The code used to create this dataset can be found under data-raw/DATASET 17 | } 18 | -------------------------------------------------------------------------------- /man/masking_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{masking_packages} 4 | \alias{masking_packages} 5 | \title{Install masking packages} 6 | \usage{ 7 | masking_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for masking. 14 | If the package is not already installed, it will automatically install it. 15 | } 16 | \details{ 17 | The following package will be installed if not already present: 18 | \itemize{ 19 | \item "geodata" 20 | } 21 | } 22 | \examples{ 23 | \dontrun{masking_packages()} 24 | } 25 | -------------------------------------------------------------------------------- /man/mmrr_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{mmrr_df} 4 | \alias{mmrr_df} 5 | \title{Make nice dataframe from MMRR results} 6 | \usage{ 7 | mmrr_df(mod) 8 | } 9 | \arguments{ 10 | \item{mod}{the fitted MMRR model} 11 | } 12 | \value{ 13 | dataframe of MMRR results 14 | } 15 | \description{ 16 | Make nice dataframe from MMRR results 17 | } 18 | \seealso{ 19 | Other MMRR functions: 20 | \code{\link{MMRR}()}, 21 | \code{\link{mmrr_do_everything}()}, 22 | \code{\link{mmrr_plot}()}, 23 | \code{\link{mmrr_run}()}, 24 | \code{\link{mmrr_table}()}, 25 | \code{\link{mmrr_var_sel}()}, 26 | \code{\link{unfold}()} 27 | } 28 | \concept{MMRR functions} 29 | -------------------------------------------------------------------------------- /man/mmrr_do_everything.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{mmrr_do_everything} 4 | \alias{mmrr_do_everything} 5 | \title{MMRR function to do everything} 6 | \usage{ 7 | mmrr_do_everything( 8 | gendist, 9 | coords, 10 | env, 11 | geo = TRUE, 12 | model = "full", 13 | geodist_type = "Euclidean", 14 | dist_lyr = NULL, 15 | nperm = 999, 16 | stdz = TRUE, 17 | quiet = FALSE, 18 | plot_type = "all" 19 | ) 20 | } 21 | \arguments{ 22 | \item{gendist}{matrix of genetic distances} 23 | 24 | \item{coords}{dataframe with x and y coordinates} 25 | 26 | \item{env}{dataframe with environmental data or a Raster* type object from which environmental values for the coordinates can be extracted} 27 | 28 | \item{geo}{whether to include geographic, topographic, or resistance distance as an independent variable (defaults to TRUE)} 29 | 30 | \item{model}{whether to fit the model with all variables (\code{"full"}) or to perform variable selection to determine the best set of variables (\code{"best"}); defaults to "full"} 31 | 32 | \item{geodist_type}{if \code{geo = TRUE}, the type of geographic distance to be calculated; options are "Euclidean" (default) for direct distance, "topographic" for topographic distances, and "resistance" for resistance distances} 33 | 34 | \item{dist_lyr}{if \code{geodist_type = "topographic"}, DEM raster for calculating topographic distances or if \code{geodist_type = "resistance"}, resistance raster for calculating resistance distances} 35 | 36 | \item{nperm}{number of permutations to be used in significance tests (default = 999)} 37 | 38 | \item{stdz}{if TRUE then matrices will be standardized (default = TRUE)} 39 | 40 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 41 | 42 | \item{plot_type}{if \code{quiet = FALSE}, which plots to produce (options: (1) "vars" to plot single variable relationships, (2) "fitted" to plot the fitted relationship, (3) "cov" to plot covariances between the predictor variables, (4) "all" to produce all plots (default))} 43 | } 44 | \value{ 45 | list with final model results and regression coefficients 46 | } 47 | \description{ 48 | MMRR function to do everything 49 | } 50 | \details{ 51 | The MMRR method is described here: Wang, I.J. (2013). Examining the full effects of landscape heterogeneity on spatial genetic variation: a multiple matrix regression approach for quantifying geographic and ecological isolation. Evolution 67(12):3403-3411. doi: https://doi.org/10.1111/evo.12134 52 | } 53 | \seealso{ 54 | Other MMRR functions: 55 | \code{\link{MMRR}()}, 56 | \code{\link{mmrr_df}()}, 57 | \code{\link{mmrr_plot}()}, 58 | \code{\link{mmrr_run}()}, 59 | \code{\link{mmrr_table}()}, 60 | \code{\link{mmrr_var_sel}()}, 61 | \code{\link{unfold}()} 62 | } 63 | \concept{MMRR functions} 64 | -------------------------------------------------------------------------------- /man/mmrr_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{mmrr_packages} 4 | \alias{mmrr_packages} 5 | \title{Install MMRR packages} 6 | \usage{ 7 | mmrr_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for MMRR. 14 | If the package is not already installed, it will automatically install it. 15 | } 16 | \details{ 17 | The following package will be installed if not already present: 18 | \itemize{ 19 | \item "GGally" 20 | } 21 | } 22 | \examples{ 23 | \dontrun{mmrr_packages()} 24 | } 25 | -------------------------------------------------------------------------------- /man/mmrr_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{mmrr_plot} 4 | \alias{mmrr_plot} 5 | \title{Plot MMRR results} 6 | \usage{ 7 | mmrr_plot( 8 | Y = NULL, 9 | X, 10 | mod = NULL, 11 | plot_type = "all", 12 | stdz = TRUE, 13 | var_names = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{Y}{the dependent variable in the form of a distance matrix} 18 | 19 | \item{X}{a list of independent variables in the form of distance matrices (required if \code{plot_type = "fitted"}, \code{vars} or \code{"all"})} 20 | 21 | \item{mod}{the fitted MMRR model (required if \code{plot_type = "fitted"} or \code{"all"})} 22 | 23 | \item{plot_type}{which plots to produce (options: (1) "vars" to plot single variable relationships, (2) "fitted" to plot the fitted relationship, (3) "cov" to plot covariances between the predictor variables, (4) "all" to produce all plots (default))} 24 | 25 | \item{stdz}{if TRUE then matrices will be standardized (default = TRUE)} 26 | 27 | \item{var_names}{add variable names to plot (defaults to NULL)} 28 | } 29 | \value{ 30 | plots of MMRR single variable relationships, the fitted relationship, and the covariances between predictor variables 31 | } 32 | \description{ 33 | Plot MMRR results 34 | } 35 | \seealso{ 36 | Other MMRR functions: 37 | \code{\link{MMRR}()}, 38 | \code{\link{mmrr_df}()}, 39 | \code{\link{mmrr_do_everything}()}, 40 | \code{\link{mmrr_run}()}, 41 | \code{\link{mmrr_table}()}, 42 | \code{\link{mmrr_var_sel}()}, 43 | \code{\link{unfold}()} 44 | } 45 | \concept{MMRR functions} 46 | -------------------------------------------------------------------------------- /man/mmrr_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{mmrr_run} 4 | \alias{mmrr_run} 5 | \title{Run MMRR and return model object} 6 | \usage{ 7 | mmrr_run(Y, X, nperm = 999, stdz = TRUE, model = "full") 8 | } 9 | \arguments{ 10 | \item{Y}{dependent distance matrix} 11 | 12 | \item{X}{list of independent distance matrices (with optional names)} 13 | 14 | \item{nperm}{number of permutations to be used in significance tests (default = 999)} 15 | 16 | \item{stdz}{if TRUE then matrices will be standardized (default = TRUE)} 17 | 18 | \item{model}{whether to fit the model with all variables (\code{"full"}) or to perform variable selection to determine the best set of variables (\code{"best"}); defaults to "full"} 19 | } 20 | \value{ 21 | list with final model results and regression coefficients 22 | } 23 | \description{ 24 | Run MMRR and return model object 25 | } 26 | \seealso{ 27 | Other MMRR functions: 28 | \code{\link{MMRR}()}, 29 | \code{\link{mmrr_df}()}, 30 | \code{\link{mmrr_do_everything}()}, 31 | \code{\link{mmrr_plot}()}, 32 | \code{\link{mmrr_table}()}, 33 | \code{\link{mmrr_var_sel}()}, 34 | \code{\link{unfold}()} 35 | } 36 | \concept{MMRR functions} 37 | -------------------------------------------------------------------------------- /man/mmrr_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{mmrr_table} 4 | \alias{mmrr_table} 5 | \title{Create \code{gt} table of MMRR results} 6 | \usage{ 7 | mmrr_table(mmrr_results, digits = 2, summary_stats = TRUE) 8 | } 9 | \arguments{ 10 | \item{mmrr_results}{results from MMRR} 11 | 12 | \item{digits}{the number of decimal places to round to} 13 | 14 | \item{summary_stats}{whether to add summary statistics (R-squared, F-statistic, F p-value) to bottom of table (defaults to TRUE)} 15 | } 16 | \value{ 17 | an object of class \code{gt_tbl} 18 | } 19 | \description{ 20 | Create \code{gt} table of MMRR results 21 | } 22 | \seealso{ 23 | Other MMRR functions: 24 | \code{\link{MMRR}()}, 25 | \code{\link{mmrr_df}()}, 26 | \code{\link{mmrr_do_everything}()}, 27 | \code{\link{mmrr_plot}()}, 28 | \code{\link{mmrr_run}()}, 29 | \code{\link{mmrr_var_sel}()}, 30 | \code{\link{unfold}()} 31 | } 32 | \concept{MMRR functions} 33 | -------------------------------------------------------------------------------- /man/mmrr_var_sel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{mmrr_var_sel} 4 | \alias{mmrr_var_sel} 5 | \title{mmrr_var_sel performs MMRR with backward elimination variable selection} 6 | \usage{ 7 | mmrr_var_sel(Y, X, nperm = 999, stdz = TRUE) 8 | } 9 | \arguments{ 10 | \item{Y}{is a dependent distance matrix} 11 | 12 | \item{X}{is a list of independent distance matrices (with optional names)} 13 | 14 | \item{nperm}{number of permutations to be used in significance tests (default = 999)} 15 | 16 | \item{stdz}{if TRUE then matrices will be standardized (default = TRUE)} 17 | } 18 | \description{ 19 | mmrr_var_sel performs MMRR with backward elimination variable selection 20 | } 21 | \seealso{ 22 | Other MMRR functions: 23 | \code{\link{MMRR}()}, 24 | \code{\link{mmrr_df}()}, 25 | \code{\link{mmrr_do_everything}()}, 26 | \code{\link{mmrr_plot}()}, 27 | \code{\link{mmrr_run}()}, 28 | \code{\link{mmrr_table}()}, 29 | \code{\link{unfold}()} 30 | } 31 | \concept{MMRR functions} 32 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \arguments{ 10 | \item{lhs}{A value or the magrittr placeholder.} 11 | 12 | \item{rhs}{A function call using the magrittr semantics.} 13 | } 14 | \value{ 15 | The result of calling \code{rhs(lhs)}. 16 | } 17 | \description{ 18 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/plot_crossent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imputation.R 3 | \name{plot_crossent} 4 | \alias{plot_crossent} 5 | \title{Helper function to plot cross entropy scores from SNMF} 6 | \usage{ 7 | plot_crossent(ce_values) 8 | } 9 | \arguments{ 10 | \item{ce_values}{df with run, K-value, and cross entropy created in \link[algatr]{snmf_bestK}} 11 | } 12 | \value{ 13 | ggplots of cross entropy values compared to K-values (and across runs) 14 | } 15 | \description{ 16 | Helper function to plot cross entropy scores from SNMF 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/plot_extrap_mask.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/masks.R 3 | \name{plot_extrap_mask} 4 | \alias{plot_extrap_mask} 5 | \title{Plot mask on top of map} 6 | \usage{ 7 | plot_extrap_mask( 8 | map_r, 9 | map_mask, 10 | RGB_cols = TRUE, 11 | mask_col = rgb(0, 0, 0, alpha = 0.9) 12 | ) 13 | } 14 | \arguments{ 15 | \item{map_r}{SpatRaster or Raster* object to be masked} 16 | 17 | \item{map_mask}{SpatRaster or Raster* object with 1s where you want to mask and NA everywhere else (i.e., what you want to keep, as produced by \code{\link{extrap_mask}})} 18 | 19 | \item{RGB_cols}{whether the plot should be RGB-based or not} 20 | 21 | \item{mask_col}{color and transparency of mask (defaults to black and alpha = 0.9)} 22 | } 23 | \value{ 24 | plot \code{map} with areas masked based on \code{map_mask} 25 | } 26 | \description{ 27 | Plots a raster with another raster "mask" on top of it 28 | } 29 | \seealso{ 30 | \code{\link{extrap_mask}} 31 | } 32 | -------------------------------------------------------------------------------- /man/pops_helper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{pops_helper} 4 | \alias{pops_helper} 5 | \title{Helper function to get population assignments for best K} 6 | \usage{ 7 | pops_helper(gen, tess3_obj, K) 8 | } 9 | \arguments{ 10 | \item{gen}{genotype dosage matrix (rows = individuals & columns = SNPs) or \code{vcfR} object} 11 | 12 | \item{tess3_obj}{list produced by \code{\link{tess3}}} 13 | 14 | \item{K}{K value} 15 | } 16 | \value{ 17 | population assignments for each individual based on max Q values 18 | } 19 | \description{ 20 | Helper function to get population assignments for best K 21 | } 22 | \seealso{ 23 | Other TESS functions: 24 | \code{\link{allK_plot_helper}()}, 25 | \code{\link{bestK}()}, 26 | \code{\link{geom_tess}()}, 27 | \code{\link{ggbarplot_helper}()}, 28 | \code{\link{tess_barplot}()}, 29 | \code{\link{tess_col_default}()}, 30 | \code{\link{tess_do_everything}()}, 31 | \code{\link{tess_ggbarplot}()}, 32 | \code{\link{tess_ggplot}()}, 33 | \code{\link{tess_krig}()}, 34 | \code{\link{tess_ktest}()}, 35 | \code{\link{tess_legend}()}, 36 | \code{\link{tess_plot_allK}()} 37 | } 38 | \concept{TESS functions} 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /man/quick_elbow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{quick_elbow} 4 | \alias{quick_elbow} 5 | \title{Quickly choose an elbow for a PC} 6 | \usage{ 7 | quick_elbow(varpc, low = 0.08, max.pc = 0.9) 8 | } 9 | \arguments{ 10 | \item{varpc}{numeric, vector of eigenvalues, or 'percentage of variance' explained by datapoints for each principal component. If only using a partial set of components, should first pass to \code{estimate.eig.vpcs()} to estimate any missing eigenvalues} 11 | 12 | \item{low}{numeric (between zero and one); the threshold that defines whether a principal component explains 'much' of the variance} 13 | 14 | \item{max.pc}{maximum percentage of the variance to capture before the elbow (cumulative sum to PC 'n')} 15 | } 16 | \value{ 17 | the number of principal components to keep, prior to the determined elbow cutoff 18 | } 19 | \description{ 20 | At variance below 5\% per component, choose the largest \% drop. 21 | Designed for variance percentages, but will also work given a full set of Evalues. 22 | Quickly estimate the 'elbow' of a scree plot (PCA) 23 | } 24 | \details{ 25 | This function uses a rough algorithm to estimate a sensible 'elbow' to 26 | choose for a PCA screeplot of eigenvalues. The function looks at an initial arbitrarily 'low' 27 | level of variance and looks for the first eigenvalue lower than this. If the very first eigenvalue 28 | is actually lower than this (i.e, when the PCs are not very explanatory) then this 'low' value is 29 | iteratively halved until this is no longer the case. After starting below this arbitrary threshold 30 | the drop in variance explained by each pair of consecutive PCs is standardized by dividing over the 31 | larger of the pair. The largest percentage drop in the series below 'low' \% is selected as the 'elbow'. 32 | } 33 | \examples{ 34 | # correlated data 35 | mat <- sim.cor(100, 50) 36 | result <- princomp(mat) 37 | eig <- result$sdev^2 38 | elb.a <- quick_elbow(eig) 39 | pca.scree.plot(eig, elbow = elb.a, M = mat) 40 | elb.b <- quick_elbow(eig, low = .05) # decrease 'low' to select more components 41 | pca.scree.plot(eig, elbow = elb.b, M = mat) 42 | # random (largely independent) data, usually higher elbow # 43 | mat2 <- generate.test.matrix(5, 3) 44 | result2 <- princomp(mat2) 45 | eig2 <- result2$sdev^2 46 | elb2 <- quick_elbow(result2$sdev^2) 47 | pca.scree.plot(eig2, elbow = elb2, M = mat2) 48 | } 49 | \seealso{ 50 | \code{\link{estimate.eig.vpcs}} 51 | 52 | Other LFMM functions: 53 | \code{\link{lfmm_df}()}, 54 | \code{\link{lfmm_do_everything}()}, 55 | \code{\link{lfmm_manhattanplot}()}, 56 | \code{\link{lfmm_qqplot}()}, 57 | \code{\link{lfmm_run}()}, 58 | \code{\link{lfmm_table}()}, 59 | \code{\link{lfmm_test_tidy}()}, 60 | \code{\link{select_K}()} 61 | } 62 | \author{ 63 | Nicholas Cooper 64 | } 65 | \concept{LFMM functions} 66 | -------------------------------------------------------------------------------- /man/rda_cor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RDA.R 3 | \name{rda_cor} 4 | \alias{rda_cor} 5 | \title{Genotype-environment correlation test} 6 | \usage{ 7 | rda_cor(gen, var) 8 | } 9 | \arguments{ 10 | \item{gen}{dosage matrix} 11 | 12 | \item{var}{dataframe with predictor variables} 13 | } 14 | \value{ 15 | dataframe with r and p-values from correlation test 16 | } 17 | \description{ 18 | Genotype-environment correlation test 19 | } 20 | \seealso{ 21 | Other RDA functions: 22 | \code{\link{rda_do_everything}()}, 23 | \code{\link{rda_getoutliers}()}, 24 | \code{\link{rda_plot}()}, 25 | \code{\link{rda_run}()}, 26 | \code{\link{rda_table}()}, 27 | \code{\link{rda_varpart}()}, 28 | \code{\link{rda_varpart_table}()} 29 | } 30 | \concept{RDA functions} 31 | -------------------------------------------------------------------------------- /man/rda_getoutliers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RDA.R 3 | \name{rda_getoutliers} 4 | \alias{rda_getoutliers} 5 | \title{Get significant outliers from RDA model} 6 | \usage{ 7 | rda_getoutliers( 8 | mod, 9 | naxes = "all", 10 | outlier_method = "p", 11 | p_adj = "fdr", 12 | sig = 0.05, 13 | z = 3, 14 | plot = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{naxes}{number of RDA axes to use (defaults to "all" to use all axes), if set to "manual" a selection option with a terminal prompt will be given, otherwise can be any integer that is less than or equal to the total number of axes} 19 | 20 | \item{outlier_method}{method to determine outliers. Can either be "p" to use the p-value method from \href{https://github.com/Capblancq/RDA-landscape-genomics}{here} or "z" to use the z-score based method from \href{https://popgen.nescent.org/2018-03-27_RDA_GEA.html}{here}} 21 | 22 | \item{p_adj}{if \code{outlier_method = "p"}, method to use for p-value correction (defaults to "fdr"); other options can be found in \code{\link[=p.adjust]{p.adjust()}}} 23 | 24 | \item{sig}{if \code{outlier_method = "p"}, the significance level to use to identify SNPs (defaults to 0.05)} 25 | 26 | \item{z}{if \code{outlier_method = "z"}, the number of standard deviations to use to identify SNPs (defaults to 3)} 27 | 28 | \item{plot}{whether to produce scree plot of RDA axes (defaults to TRUE)} 29 | } 30 | \value{ 31 | results from outlier tests. If \code{outlier_method = "p"}, a list of outlier SNPs, p-values, and results from rdadapt (see \href{https://onlinelibrary.wiley.com/doi/abs/10.1111/1755-0998.12906}{Capblancq et al. 2018}). If \code{outlier_method = "z"}, a dataframe with outlier SNP Z-scores for each axis 32 | } 33 | \description{ 34 | Get significant outliers from RDA model 35 | } 36 | \seealso{ 37 | Other RDA functions: 38 | \code{\link{rda_cor}()}, 39 | \code{\link{rda_do_everything}()}, 40 | \code{\link{rda_plot}()}, 41 | \code{\link{rda_run}()}, 42 | \code{\link{rda_table}()}, 43 | \code{\link{rda_varpart}()}, 44 | \code{\link{rda_varpart_table}()} 45 | } 46 | \concept{RDA functions} 47 | -------------------------------------------------------------------------------- /man/rda_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{rda_packages} 4 | \alias{rda_packages} 5 | \title{Install RDA packages} 6 | \usage{ 7 | rda_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for RDA. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following packages will be installed if not already present: 18 | \itemize{ 19 | \item "ggrepel" 20 | \item "qvalue" (from Bioconductor repository) 21 | \item "robust" 22 | \item "tibble" 23 | \item "vegan" 24 | } 25 | } 26 | \examples{ 27 | \dontrun{rda_packages()} 28 | } 29 | -------------------------------------------------------------------------------- /man/rda_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RDA.R 3 | \name{rda_plot} 4 | \alias{rda_plot} 5 | \title{Plot RDA results} 6 | \usage{ 7 | rda_plot( 8 | mod, 9 | rda_snps = NULL, 10 | pvalues = NULL, 11 | axes = "all", 12 | biplot_axes = NULL, 13 | sig = 0.05, 14 | manhattan = NULL, 15 | rdaplot = NULL, 16 | binwidth = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{mod}{model object of class \code{rda}; if this is all that's provided, histograms with loadings will be generated} 21 | 22 | \item{rda_snps}{vector of outlier SNPs (defaults to NULL)} 23 | 24 | \item{pvalues}{if creating a Manhattan plot (i.e., \code{manhattan = TRUE}), a matrix of p-values (defaults to NULL)} 25 | 26 | \item{axes}{which RDA axes to include while plotting (defaults to \code{"all"})} 27 | 28 | \item{biplot_axes}{if creating an RDA biplot (i.e., \code{rdaplot = TRUE}), which pairs of axes to plot. Defaults to plotting all pairs of axes possible, otherwise can be set to a single pair of axes (e.g., c(1,2)) or a list of axes pairs (e.g., list(c(1,2), c(2,3))))} 29 | 30 | \item{sig}{if creating a Manhattan plot, significance threshold for y axis (defaults to 0.05)} 31 | 32 | \item{manhattan}{whether to produce Manhattan plot (defaults to \code{TRUE})} 33 | 34 | \item{rdaplot}{whether to produce an RDA biplot (defaults to \code{TRUE}). If only one axis is provided, instead of a biplot, a histogram will be created} 35 | 36 | \item{binwidth}{width of bins for histograms (defaults to NULL)} 37 | } 38 | \description{ 39 | Plot RDA results 40 | } 41 | \seealso{ 42 | Other RDA functions: 43 | \code{\link{rda_cor}()}, 44 | \code{\link{rda_do_everything}()}, 45 | \code{\link{rda_getoutliers}()}, 46 | \code{\link{rda_run}()}, 47 | \code{\link{rda_table}()}, 48 | \code{\link{rda_varpart}()}, 49 | \code{\link{rda_varpart_table}()} 50 | } 51 | \concept{RDA functions} 52 | -------------------------------------------------------------------------------- /man/rda_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RDA.R 3 | \name{rda_run} 4 | \alias{rda_run} 5 | \title{Run RDA} 6 | \usage{ 7 | rda_run( 8 | gen, 9 | env, 10 | coords = NULL, 11 | model = "full", 12 | correctGEO = FALSE, 13 | correctPC = FALSE, 14 | nPC = 3, 15 | Pin = 0.05, 16 | R2permutations = 1000, 17 | R2scope = T 18 | ) 19 | } 20 | \arguments{ 21 | \item{gen}{genotype dosage matrix (rows = individuals & columns = SNPs) or \code{vcfR} object} 22 | 23 | \item{env}{dataframe with environmental data or a Raster* type object from which environmental values for the coordinates can be extracted} 24 | 25 | \item{coords}{dataframe with coordinates (only needed if correctGEO = TRUE) or if env is a Raster* from which values should be extracted} 26 | 27 | \item{model}{whether to fit the model with all variables ("full") or to perform variable selection to determine the best set of variables ("best"); defaults to "full"} 28 | 29 | \item{correctGEO}{whether to condition on geographic coordinates} 30 | 31 | \item{correctPC}{whether to condition on PCs from PCA of genotypes} 32 | 33 | \item{nPC}{number of PCs to use if correctPC = TRUE (defaults to 3); if set to "manual" a selection option with a terminal prompt will be provided} 34 | 35 | \item{Pin}{if \code{model = "best"}, limits of permutation P-values for adding (\code{Pin}) a term to the model, or dropping (\code{Pout}) from the model. Term is added if\code{ P <= Pin}, and removed if \code{P > Pout} (see \link[vegan]{ordiR2step}) (defaults to 0.05)} 36 | 37 | \item{R2permutations}{if \code{model = "best"}, number of permutations used in the estimation of adjusted R2 for cca using RsquareAdj (see \link[vegan]{ordiR2step}) (defaults to 1000)} 38 | 39 | \item{R2scope}{if \code{model = "best"} and set to TRUE (default), use adjusted R2 as the stopping criterion: only models with lower adjusted R2 than scope are accepted (see \link[vegan]{ordiR2step})} 40 | } 41 | \value{ 42 | RDA model 43 | } 44 | \description{ 45 | Run RDA 46 | } 47 | \seealso{ 48 | Other RDA functions: 49 | \code{\link{rda_cor}()}, 50 | \code{\link{rda_do_everything}()}, 51 | \code{\link{rda_getoutliers}()}, 52 | \code{\link{rda_plot}()}, 53 | \code{\link{rda_table}()}, 54 | \code{\link{rda_varpart}()}, 55 | \code{\link{rda_varpart_table}()} 56 | } 57 | \concept{RDA functions} 58 | -------------------------------------------------------------------------------- /man/rda_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RDA.R 3 | \name{rda_table} 4 | \alias{rda_table} 5 | \title{Create \code{gt} table of RDA results} 6 | \usage{ 7 | rda_table( 8 | cor_df, 9 | sig = 0.05, 10 | sig_only = TRUE, 11 | top = FALSE, 12 | order = FALSE, 13 | var = NULL, 14 | nrow = NULL, 15 | digits = 2 16 | ) 17 | } 18 | \arguments{ 19 | \item{cor_df}{dataframe of correlation results output from \link[algatr]{rda_cor}} 20 | 21 | \item{sig}{if \code{outlier_method = "p"}, the significance level to use to identify SNPs (defaults to 0.05)} 22 | 23 | \item{sig_only}{whether to only include loci with p-values less than \code{sig} (defaults to TRUE)} 24 | 25 | \item{top}{whether to only include only keep the top variable for each snp in the table by the strength of the correlation (defaults to FALSE)} 26 | 27 | \item{order}{whether to order by the magnitude of the correlation (defaults to FALSE)} 28 | 29 | \item{var}{which variables to include (defaults to including all variables)} 30 | 31 | \item{nrow}{number of rows to display (defaults to displaying all rows)} 32 | 33 | \item{digits}{number of digits to include (defaults to 2)} 34 | } 35 | \value{ 36 | An object of class \code{gt_tbl} 37 | } 38 | \description{ 39 | Create \code{gt} table of RDA results 40 | } 41 | \seealso{ 42 | Other RDA functions: 43 | \code{\link{rda_cor}()}, 44 | \code{\link{rda_do_everything}()}, 45 | \code{\link{rda_getoutliers}()}, 46 | \code{\link{rda_plot}()}, 47 | \code{\link{rda_run}()}, 48 | \code{\link{rda_varpart}()}, 49 | \code{\link{rda_varpart_table}()} 50 | } 51 | \concept{RDA functions} 52 | -------------------------------------------------------------------------------- /man/rda_varpart.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RDA.R 3 | \name{rda_varpart} 4 | \alias{rda_varpart} 5 | \title{Partial RDA variance partitioning} 6 | \usage{ 7 | rda_varpart(gen, env, coords, Pin, R2permutations, R2scope, nPC) 8 | } 9 | \arguments{ 10 | \item{gen}{genotype dosage matrix (rows = individuals & columns = SNPs) or \code{vcfR} object} 11 | 12 | \item{env}{dataframe with environmental data or a Raster* type object from which environmental values for the coordinates can be extracted} 13 | 14 | \item{coords}{dataframe with coordinates (only needed if correctGEO = TRUE) or if env is a Raster* from which values should be extracted} 15 | 16 | \item{Pin}{if \code{model = "best"}, limits of permutation P-values for adding (\code{Pin}) a term to the model, or dropping (\code{Pout}) from the model. Term is added if\code{ P <= Pin}, and removed if \code{P > Pout} (see \link[vegan]{ordiR2step}) (defaults to 0.05)} 17 | 18 | \item{R2permutations}{if \code{model = "best"}, number of permutations used in the estimation of adjusted R2 for cca using RsquareAdj (see \link[vegan]{ordiR2step}) (defaults to 1000)} 19 | 20 | \item{R2scope}{if \code{model = "best"} and set to TRUE (default), use adjusted R2 as the stopping criterion: only models with lower adjusted R2 than scope are accepted (see \link[vegan]{ordiR2step})} 21 | 22 | \item{nPC}{number of PCs to use if correctPC = TRUE (defaults to 3); if set to "manual" a selection option with a terminal prompt will be provided} 23 | } 24 | \value{ 25 | df with relevant statistics from variance partitioning analysis 26 | } 27 | \description{ 28 | Partial RDA variance partitioning 29 | } 30 | \seealso{ 31 | Other RDA functions: 32 | \code{\link{rda_cor}()}, 33 | \code{\link{rda_do_everything}()}, 34 | \code{\link{rda_getoutliers}()}, 35 | \code{\link{rda_plot}()}, 36 | \code{\link{rda_run}()}, 37 | \code{\link{rda_table}()}, 38 | \code{\link{rda_varpart_table}()} 39 | } 40 | \concept{RDA functions} 41 | -------------------------------------------------------------------------------- /man/rda_varpart_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RDA.R 3 | \name{rda_varpart_table} 4 | \alias{rda_varpart_table} 5 | \title{Create \code{gt} table with RDA variance partitioning results} 6 | \usage{ 7 | rda_varpart_table(df, digits = 2, call_col = FALSE) 8 | } 9 | \arguments{ 10 | \item{df}{dataframe of variance partitioning results output from \link[algatr]{rda_varpart}} 11 | 12 | \item{digits}{number of digits to include (defaults to 2)} 13 | 14 | \item{call_col}{whether to include column with RDA call (defaults to FALSE)} 15 | } 16 | \value{ 17 | object of class \code{gt} with RDA variance partitioning results 18 | } 19 | \description{ 20 | Create \code{gt} table with RDA variance partitioning results 21 | } 22 | \seealso{ 23 | Other RDA functions: 24 | \code{\link{rda_cor}()}, 25 | \code{\link{rda_do_everything}()}, 26 | \code{\link{rda_getoutliers}()}, 27 | \code{\link{rda_plot}()}, 28 | \code{\link{rda_run}()}, 29 | \code{\link{rda_table}()}, 30 | \code{\link{rda_varpart}()} 31 | } 32 | \concept{RDA functions} 33 | -------------------------------------------------------------------------------- /man/rm_islands.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/format_data.R 3 | \name{rm_islands} 4 | \alias{rm_islands} 5 | \title{Remove islands from mapping} 6 | \usage{ 7 | rm_islands(input, shape, min_vertices = 10000) 8 | } 9 | \arguments{ 10 | \item{input}{raster (SpatRaster or Raster*) or coordinates (sf or two column dataframe) to mask or remove island points from} 11 | 12 | \item{shape}{SpatialPolygons, sf, or sf object to create island mask} 13 | 14 | \item{min_vertices}{minimum number of vertices in polygons to retain (defaults to 10000)} 15 | } 16 | \value{ 17 | object (of input type) with islands removed 18 | } 19 | \description{ 20 | Remove islands from mapping 21 | } 22 | -------------------------------------------------------------------------------- /man/scale01.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GDM.R 3 | \name{scale01} 4 | \alias{scale01} 5 | \title{Scale genetic distances from 0 to 1} 6 | \usage{ 7 | scale01(x) 8 | } 9 | \arguments{ 10 | \item{x}{genetic distance matrix} 11 | } 12 | \value{ 13 | genetic distance matrix scaled from 0 to 1 14 | } 15 | \description{ 16 | Scale genetic distances from 0 to 1 17 | } 18 | \seealso{ 19 | Other GDM functions: 20 | \code{\link{gdm_coeffs}()}, 21 | \code{\link{gdm_df}()}, 22 | \code{\link{gdm_do_everything}()}, 23 | \code{\link{gdm_format}()}, 24 | \code{\link{gdm_map}()}, 25 | \code{\link{gdm_plot_diss}()}, 26 | \code{\link{gdm_plot_isplines}()}, 27 | \code{\link{gdm_plot_vars}()}, 28 | \code{\link{gdm_run}()}, 29 | \code{\link{gdm_table}()}, 30 | \code{\link{gdm_var_sel}()} 31 | } 32 | \concept{GDM functions} 33 | -------------------------------------------------------------------------------- /man/scaleRGB.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/format_data.R 3 | \name{scaleRGB} 4 | \alias{scaleRGB} 5 | \title{Scale three layers of environmental data to R, G, and B for mapping} 6 | \usage{ 7 | scaleRGB(env) 8 | } 9 | \arguments{ 10 | \item{env}{SpatRaster or Raster* with three layers} 11 | } 12 | \value{ 13 | RGB-scaled values 14 | } 15 | \description{ 16 | Scale three layers of environmental data to R, G, and B for mapping 17 | } 18 | -------------------------------------------------------------------------------- /man/select_K.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LFMM.R 3 | \name{select_K} 4 | \alias{select_K} 5 | \alias{select_K_tw} 6 | \alias{select_K_elbow} 7 | \alias{select_K_tess} 8 | \alias{select_K_fc} 9 | \title{K selection} 10 | \usage{ 11 | select_K( 12 | gen, 13 | K_selection = "tracy_widom", 14 | coords = NULL, 15 | Kvals = 1:10, 16 | criticalpoint = 2.023, 17 | low = 0.08, 18 | max.pc = 0.9, 19 | perc.pca = 90, 20 | max.n.clust = 10 21 | ) 22 | 23 | select_K_tw(gen, criticalpoint = 2.0234) 24 | 25 | select_K_elbow(gen, low = 0.08, max.pc = 0.9) 26 | 27 | select_K_tess( 28 | gen, 29 | coords, 30 | Kvals = 1:10, 31 | tess_method = "projected.ls", 32 | ploidy = 2 33 | ) 34 | 35 | select_K_fc(gen, perc.pca, max.n.clust) 36 | } 37 | \arguments{ 38 | \item{gen}{a genotype matrix} 39 | 40 | \item{K_selection}{method for performing K selection (options: "tracy_widom" (default), "quick_elbow", or "tess")} 41 | 42 | \item{coords}{coordinates for "tess"} 43 | 44 | \item{Kvals}{values of K to test for "tess"} 45 | 46 | \item{criticalpoint}{if \code{K_selection = "tracy_widom"}, a numeric value corresponding to the significance level. If the significance level is 0.05, 0.01, 0.005, or 0.001, the criticalpoint should be set to be 0.9793, 2.0234, 2.4224, or 3.2724, respectively (defaults to 2.0234)} 47 | 48 | \item{low}{if \code{K_selection = "quick_elbow"}, numeric, between zero and one, the threshold that defines whether a principal component explains 'much' of the variance (defaults to 0.08).} 49 | 50 | \item{max.pc}{if \code{K_selection = "quick_elbow"}, maximum percentage of the variance to capture before the elbow (cumulative sum to PC 'n'; defaults to 0.90).} 51 | 52 | \item{perc.pca}{if \code{K_selection = "find_clusters"}, a numeric value between 0 and 100 indicating the minimal percentage of the total variance of the data to be expressed by the retained axes of PCA (defaults to 90).} 53 | 54 | \item{max.n.clust}{if \code{K_selection = "find_clusters"}, an integer indicating the maximum number of clusters to try. Values of 'k' will be picked up between 1 and max.n.clust (defaults to 10)} 55 | 56 | \item{tess_method}{method to use for "tess"} 57 | 58 | \item{ploidy}{ploidy for "tess"} 59 | } 60 | \value{ 61 | prints the best K value given the specified K selection procedure 62 | } 63 | \description{ 64 | K selection 65 | } 66 | \section{Functions}{ 67 | \itemize{ 68 | \item \code{select_K_tw()}: select K using Tracy-Widom Test 69 | 70 | \item \code{select_K_elbow()}: select K using PCA and \code{quick_elbow} method 71 | 72 | \item \code{select_K_tess()}: select K using TESS and \code{bestK} method 73 | 74 | \item \code{select_K_fc()}: select K using find.clusters method 75 | 76 | }} 77 | \note{ 78 | uses the \link[AssocTests]{tw} function 79 | 80 | uses the \link[adegenet]{find.clusters} function 81 | } 82 | \seealso{ 83 | Other LFMM functions: 84 | \code{\link{lfmm_df}()}, 85 | \code{\link{lfmm_do_everything}()}, 86 | \code{\link{lfmm_manhattanplot}()}, 87 | \code{\link{lfmm_qqplot}()}, 88 | \code{\link{lfmm_run}()}, 89 | \code{\link{lfmm_table}()}, 90 | \code{\link{lfmm_test_tidy}()}, 91 | \code{\link{quick_elbow}()} 92 | 93 | Other LFMM functions: 94 | \code{\link{lfmm_df}()}, 95 | \code{\link{lfmm_do_everything}()}, 96 | \code{\link{lfmm_manhattanplot}()}, 97 | \code{\link{lfmm_qqplot}()}, 98 | \code{\link{lfmm_run}()}, 99 | \code{\link{lfmm_table}()}, 100 | \code{\link{lfmm_test_tidy}()}, 101 | \code{\link{quick_elbow}()} 102 | 103 | Other LFMM functions: 104 | \code{\link{lfmm_df}()}, 105 | \code{\link{lfmm_do_everything}()}, 106 | \code{\link{lfmm_manhattanplot}()}, 107 | \code{\link{lfmm_qqplot}()}, 108 | \code{\link{lfmm_run}()}, 109 | \code{\link{lfmm_table}()}, 110 | \code{\link{lfmm_test_tidy}()}, 111 | \code{\link{quick_elbow}()} 112 | 113 | Other LFMM functions: 114 | \code{\link{lfmm_df}()}, 115 | \code{\link{lfmm_do_everything}()}, 116 | \code{\link{lfmm_manhattanplot}()}, 117 | \code{\link{lfmm_qqplot}()}, 118 | \code{\link{lfmm_run}()}, 119 | \code{\link{lfmm_table}()}, 120 | \code{\link{lfmm_test_tidy}()}, 121 | \code{\link{quick_elbow}()} 122 | 123 | Other LFMM functions: 124 | \code{\link{lfmm_df}()}, 125 | \code{\link{lfmm_do_everything}()}, 126 | \code{\link{lfmm_manhattanplot}()}, 127 | \code{\link{lfmm_qqplot}()}, 128 | \code{\link{lfmm_run}()}, 129 | \code{\link{lfmm_table}()}, 130 | \code{\link{lfmm_test_tidy}()}, 131 | \code{\link{quick_elbow}()} 132 | } 133 | \concept{LFMM functions} 134 | -------------------------------------------------------------------------------- /man/simple_impute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imputation.R 3 | \name{simple_impute} 4 | \alias{simple_impute} 5 | \title{Impute NA values 6 | NOTE: use extreme caution when using this form of simplistic imputation. We mainly provide this code for creating test datasets and highly discourage its use in analyses.} 7 | \usage{ 8 | simple_impute(x, FUN = median) 9 | } 10 | \arguments{ 11 | \item{x}{matrix} 12 | 13 | \item{f}{function to use for imputation (defaults to median)} 14 | } 15 | \value{ 16 | matrix of values with missing values imputed 17 | } 18 | \description{ 19 | Impute NA values 20 | NOTE: use extreme caution when using this form of simplistic imputation. We mainly provide this code for creating test datasets and highly discourage its use in analyses. 21 | } 22 | \seealso{ 23 | Other Imputation functions: 24 | \code{\link{gen_to_geno}()}, 25 | \code{\link{geno_to_dosage}()}, 26 | \code{\link{snmf_bestK}()}, 27 | \code{\link{snmf_crossent_helper}()}, 28 | \code{\link{str_impute}()} 29 | } 30 | \concept{Imputation functions} 31 | -------------------------------------------------------------------------------- /man/snmf_bestK.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imputation.R 3 | \name{snmf_bestK} 4 | \alias{snmf_bestK} 5 | \title{Helper function to select "best" K based on minimizing cross-entropy criteria from sNMF results} 6 | \usage{ 7 | snmf_bestK(snmf_proj, K, quiet) 8 | } 9 | \arguments{ 10 | \item{snmf_proj}{object of type snmfProject} 11 | 12 | \item{K}{integer corresponding to K-value} 13 | 14 | \item{quiet}{whether to operate quietly and suppress the results of cross-entropy scores (defaults to TRUE; only does so if more than one K-value); only displays run with minimum cross-entropy} 15 | } 16 | \value{ 17 | list with best K-value and run number and all cross-entropy scores 18 | } 19 | \description{ 20 | Helper function to select "best" K based on minimizing cross-entropy criteria from sNMF results 21 | } 22 | \seealso{ 23 | Other Imputation functions: 24 | \code{\link{gen_to_geno}()}, 25 | \code{\link{geno_to_dosage}()}, 26 | \code{\link{simple_impute}()}, 27 | \code{\link{snmf_crossent_helper}()}, 28 | \code{\link{str_impute}()} 29 | } 30 | \concept{Imputation functions} 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/snmf_crossent_helper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imputation.R 3 | \name{snmf_crossent_helper} 4 | \alias{snmf_crossent_helper} 5 | \title{Helper function to retrieve cross entropy scores from SNMF project} 6 | \usage{ 7 | snmf_crossent_helper(snmf_proj, K, select_min = TRUE) 8 | } 9 | \arguments{ 10 | \item{snmf_proj}{object of type snmfProject} 11 | 12 | \item{K}{K-value(s)} 13 | 14 | \item{select_min}{whether to return minimum} 15 | } 16 | \value{ 17 | cross entropy scores for given K 18 | } 19 | \description{ 20 | Helper function to retrieve cross entropy scores from SNMF project 21 | } 22 | \seealso{ 23 | Other Imputation functions: 24 | \code{\link{gen_to_geno}()}, 25 | \code{\link{geno_to_dosage}()}, 26 | \code{\link{simple_impute}()}, 27 | \code{\link{snmf_bestK}()}, 28 | \code{\link{str_impute}()} 29 | } 30 | \concept{Imputation functions} 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/str_impute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/imputation.R 3 | \name{str_impute} 4 | \alias{str_impute} 5 | \title{Imputation of missing values using population structure inferred with \code{LEA::snmf}} 6 | \usage{ 7 | str_impute( 8 | gen, 9 | K, 10 | entropy = TRUE, 11 | repetitions = 10, 12 | project = "new", 13 | quiet = TRUE, 14 | save_output = FALSE, 15 | output_filename = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{gen}{a dosage matrix, an object of class 'vcfR', or an object of type snmfProject} 20 | 21 | \item{K}{ 22 | An integer vector corresponding to the number of ancestral populations for 23 | which the snmf algorithm estimates have to be calculated. 24 | } 25 | 26 | \item{entropy}{ 27 | A boolean value. If true, the cross-entropy criterion is calculated 28 | (see \code{\link[LEA]{create.dataset}} and 29 | \code{\link[LEA]{cross.entropy.estimation}}). 30 | } 31 | 32 | \item{repetitions}{ 33 | An integer corresponding with the number of repetitions for each value of 34 | \code{K}. 35 | } 36 | 37 | \item{project}{ 38 | A character string among "continue", "new", and "force". If "continue", 39 | the results are stored in the current project. If "new", the current 40 | project is removed and a new one is created to store the result. If 41 | "force", the results are stored in the current project even if the input 42 | file has been modified since the creation of the project. 43 | } 44 | 45 | \item{quiet}{whether to operate quietly and suppress the results of cross-entropy scores (defaults to TRUE; only does so if more than one K-value); only displays run with minimum cross-entropy} 46 | 47 | \item{save_output}{if TRUE, saves SNP GDS and ped (plink) files with retained SNPs in new directory; if FALSE returns object (defaults to FALSE)} 48 | 49 | \item{output_filename}{if \code{save_output = TRUE}, name prefix for saved .geno file, sNMF project file, and sNMF output file results (defaults to FALSE, in which no files are saved)} 50 | } 51 | \value{ 52 | dosage matrix with imputed missing values 53 | } 54 | \description{ 55 | Imputation of missing values using population structure inferred with \code{LEA::snmf} 56 | } 57 | \seealso{ 58 | Other Imputation functions: 59 | \code{\link{gen_to_geno}()}, 60 | \code{\link{geno_to_dosage}()}, 61 | \code{\link{simple_impute}()}, 62 | \code{\link{snmf_bestK}()}, 63 | \code{\link{snmf_crossent_helper}()} 64 | } 65 | \concept{Imputation functions} 66 | -------------------------------------------------------------------------------- /man/tess_barplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_barplot} 4 | \alias{tess_barplot} 5 | \title{Create TESS barplot} 6 | \usage{ 7 | tess_barplot( 8 | qmat, 9 | col_pal = algatr_col_default("base"), 10 | sort_by_Q = TRUE, 11 | legend = TRUE, 12 | legend_position = "bottomright", 13 | border = NA, 14 | space = 0, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{qmat}{Q matrix} 20 | 21 | \item{sort_by_Q}{whether to sort bars by Q value (equivalent to \link[tess3r]{barplot} sort.by.Q)} 22 | 23 | \item{legend}{whether to display legend (defaults to TRUE)} 24 | 25 | \item{legend_position}{the x and y coordinates or keyword to determine legend position (defaults to bottom right)} 26 | 27 | \item{border}{the color to be used for the border of the bars. 28 | Use \code{border = NA} to omit borders. If there are shading 29 | lines, \code{border = TRUE} means use the same colour for 30 | the border as for the shading lines.} 31 | 32 | \item{space}{the amount of space (as a fraction of the average bar 33 | width) left before each bar. May be given as a single number or 34 | one number per bar. If \code{height} is a matrix and 35 | \code{beside} is \code{TRUE}, \code{space} may be specified by 36 | two numbers, where the first is the space between bars in the 37 | same group, and the second the space between the groups. If not 38 | given explicitly, it defaults to \code{c(0,1)} if \code{height} 39 | is a matrix and \code{beside} is \code{TRUE}, and to 0.2 40 | otherwise.} 41 | 42 | \item{...}{other parameters of the function \code{\link{barplot.default}}.} 43 | } 44 | \value{ 45 | STRUCTURE-style bar plot of TESS results 46 | } 47 | \description{ 48 | Based on code from: https://github.com/bcm-uga/TESS3_encho_sen/blob/master/R/plotQ.R 49 | } 50 | \seealso{ 51 | Other TESS functions: 52 | \code{\link{allK_plot_helper}()}, 53 | \code{\link{bestK}()}, 54 | \code{\link{geom_tess}()}, 55 | \code{\link{ggbarplot_helper}()}, 56 | \code{\link{pops_helper}()}, 57 | \code{\link{tess_col_default}()}, 58 | \code{\link{tess_do_everything}()}, 59 | \code{\link{tess_ggbarplot}()}, 60 | \code{\link{tess_ggplot}()}, 61 | \code{\link{tess_krig}()}, 62 | \code{\link{tess_ktest}()}, 63 | \code{\link{tess_legend}()}, 64 | \code{\link{tess_plot_allK}()} 65 | } 66 | \concept{TESS functions} 67 | -------------------------------------------------------------------------------- /man/tess_col_default.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_col_default} 4 | \alias{tess_col_default} 5 | \title{Create default TESS color palette} 6 | \usage{ 7 | tess_col_default(n, alpha = 1) 8 | } 9 | \arguments{ 10 | \item{n}{number of colors to generate (must be less than 9)} 11 | } 12 | \description{ 13 | Create default TESS color palette 14 | } 15 | \seealso{ 16 | Other TESS functions: 17 | \code{\link{allK_plot_helper}()}, 18 | \code{\link{bestK}()}, 19 | \code{\link{geom_tess}()}, 20 | \code{\link{ggbarplot_helper}()}, 21 | \code{\link{pops_helper}()}, 22 | \code{\link{tess_barplot}()}, 23 | \code{\link{tess_do_everything}()}, 24 | \code{\link{tess_ggbarplot}()}, 25 | \code{\link{tess_ggplot}()}, 26 | \code{\link{tess_krig}()}, 27 | \code{\link{tess_ktest}()}, 28 | \code{\link{tess_legend}()}, 29 | \code{\link{tess_plot_allK}()} 30 | } 31 | \concept{TESS functions} 32 | -------------------------------------------------------------------------------- /man/tess_do_everything.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_do_everything} 4 | \alias{tess_do_everything} 5 | \title{TESS function to do everything} 6 | \usage{ 7 | tess_do_everything( 8 | gen, 9 | coords, 10 | grid = NULL, 11 | Kvals = 1:10, 12 | K_selection = "manual", 13 | plot_method = "maxQ", 14 | col_breaks = 20, 15 | minQ = 0.1, 16 | tess_method = "projected.ls", 17 | lambda = 1, 18 | ploidy = 2, 19 | correct_kriged_Q = TRUE, 20 | quiet = FALSE 21 | ) 22 | } 23 | \arguments{ 24 | \item{gen}{genotype dosage matrix (rows = individuals & columns = snps) or \code{vcfR} object} 25 | 26 | \item{coords}{coordinates of samples as sf points, a two-column matrix, or a data.frame representing x and y coordinates (see Details for important information about projections)} 27 | 28 | \item{grid}{SpatRaster for kriging} 29 | 30 | \item{Kvals}{vector of K values to test} 31 | 32 | \item{K_selection}{how to perform K selection ("manual" to enter into console (default) or "auto" for automatic selection based on \link[algatr]{bestK})} 33 | 34 | \item{plot_method}{method for making rainbow map of kriged layers (options: "maxQ" to only plot the max Q value for each cell (default), "allQ" to plot all Q values greater than \code{minQ}, "maxQ_poly" or "allQ_poly" to create the plots as previously described, but as polygons for each K instead of continuous Q values)} 35 | 36 | \item{col_breaks}{number of breaks for plotting (defaults to 20)} 37 | 38 | \item{minQ}{threshold for minimum Q value for rainbow plotting if \code{method = "all"} is used (defaults to 0.10)} 39 | 40 | \item{tess_method}{the type of TESS method to be run ("projected.ls" for projected least squares algorithm (default) or "qp" for quadratic programming algorithm)} 41 | 42 | \item{lambda}{numeric value for the spatial regularization parameter. The default value lambda = 1 attributes equal weights to the loss function and to the penalty function.} 43 | 44 | \item{ploidy}{ploidy of data (defaults to 2)} 45 | 46 | \item{correct_kriged_Q}{whether to correct kriged Q values so values greater than 1 are set to 1 and values less than 0 are set to 0 (defaults to TRUE)} 47 | 48 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 49 | } 50 | \value{ 51 | list with all TESS results, final K value, and final kriged raster 52 | } 53 | \description{ 54 | TESS function to do everything 55 | } 56 | \details{ 57 | TESS is run using the tess3r package: Caye, K., François, O. (2016). tess3r: Inference of Spatial Population Genetic Structure. R package version 1.1.0. 58 | See also: Caye, K., Deist, T.M., Martins, H., Michel, O., François, O. (2016). TESS3: fast inference of spatial population structure and genome scans for selection. Mol. Ecol. Res. 16(2):540-548. https://doi.org/10.1111/1755-0998.12471 59 | 60 | Coordinates and rasters should be in a projected (planar) coordinate system. 61 | Therefore, spherical systems (including latitute-longitude coordinate systems) should be projected prior to use. 62 | Transformation can be performed using \link[sf]{st_set_crs} for coordinates or \link[terra]{project} for rasters (see vignette for more details). 63 | } 64 | \seealso{ 65 | Other TESS functions: 66 | \code{\link{allK_plot_helper}()}, 67 | \code{\link{bestK}()}, 68 | \code{\link{geom_tess}()}, 69 | \code{\link{ggbarplot_helper}()}, 70 | \code{\link{pops_helper}()}, 71 | \code{\link{tess_barplot}()}, 72 | \code{\link{tess_col_default}()}, 73 | \code{\link{tess_ggbarplot}()}, 74 | \code{\link{tess_ggplot}()}, 75 | \code{\link{tess_krig}()}, 76 | \code{\link{tess_ktest}()}, 77 | \code{\link{tess_legend}()}, 78 | \code{\link{tess_plot_allK}()} 79 | } 80 | \concept{TESS functions} 81 | -------------------------------------------------------------------------------- /man/tess_ggbarplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_ggbarplot} 4 | \alias{tess_ggbarplot} 5 | \title{Create TESS barplot using ggplot2} 6 | \usage{ 7 | tess_ggbarplot( 8 | qmat, 9 | ggplot_fill = algatr_col_default("ggplot"), 10 | sort_by_Q = TRUE, 11 | legend = TRUE 12 | ) 13 | } 14 | \arguments{ 15 | \item{qmat}{Q matrix} 16 | 17 | \item{ggplot_fill}{any ggplot2 scale fill discrete function (default: \link[algatr]{scale_fill_viridis_d}, \code{option = "turbo"})} 18 | 19 | \item{sort_by_Q}{whether to sort bars by Q value (equivalent to \link[tess3r]{barplot} sort.by.Q)} 20 | 21 | \item{legend}{whether to display legend (defaults to TRUE)} 22 | } 23 | \value{ 24 | ggplot object of TESS results as a barplot 25 | } 26 | \description{ 27 | Create TESS barplot using ggplot2 28 | } 29 | \seealso{ 30 | Other TESS functions: 31 | \code{\link{allK_plot_helper}()}, 32 | \code{\link{bestK}()}, 33 | \code{\link{geom_tess}()}, 34 | \code{\link{ggbarplot_helper}()}, 35 | \code{\link{pops_helper}()}, 36 | \code{\link{tess_barplot}()}, 37 | \code{\link{tess_col_default}()}, 38 | \code{\link{tess_do_everything}()}, 39 | \code{\link{tess_ggplot}()}, 40 | \code{\link{tess_krig}()}, 41 | \code{\link{tess_ktest}()}, 42 | \code{\link{tess_legend}()}, 43 | \code{\link{tess_plot_allK}()} 44 | } 45 | \concept{TESS functions} 46 | -------------------------------------------------------------------------------- /man/tess_ggplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_ggplot} 4 | \alias{tess_ggplot} 5 | \title{ggplot of TESS results} 6 | \usage{ 7 | tess_ggplot( 8 | krig_admix, 9 | coords = NULL, 10 | plot_method = "maxQ", 11 | ggplot_fill = algatr_col_default("ggplot"), 12 | minQ = 0.1, 13 | plot_axes = FALSE, 14 | rel_widths = c(3, 1), 15 | list = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{krig_admix}{SpatRaster returned by \link[algatr]{tess_krig}} 20 | 21 | \item{coords}{dataframe with x and y coordinates for plotting (optional)} 22 | 23 | \item{plot_method}{method for making rainbow map of kriged layers (options: "maxQ" to only plot the max Q value for each cell (default), "allQ" to plot all Q values greater than \code{minQ}, "maxQ_poly" or "allQ_poly" to create the plots as previously described, but as polygons for each K instead of continuous Q values)} 24 | 25 | \item{ggplot_fill}{any ggplot2 scale fill discrete function (default: \link[algatr]{scale_fill_viridis_d}, \code{option = "turbo"})} 26 | 27 | \item{minQ}{threshold for minimum Q-value for rainbow plotting if \code{plot_method = "allQ"} or \code{plot_method = "allQ_poly"} is used (defaults to 0.10)} 28 | 29 | \item{plot_axes}{whether to plot axes or not (defaults to FALSE)} 30 | 31 | \item{rel_widths}{if \code{plot_method = "maxQ"} or \code{plot_method = "allQ"} is used, sets relative widths of kriged TESS map and legend (defaults to 3:1), from \link[cowplot]{plot_grid}} 32 | 33 | \item{list}{if \code{plot_method = "maxQ"} or \code{"allQ"}, whether to output list of ggplots (i.e., the base plot and legend; TRUE) or a single plot (FALSE; default). Use \code{list = TRUE} if you would like to add additional ggplot2 functions to the plot} 34 | } 35 | \value{ 36 | ggplot object of TESS results 37 | } 38 | \description{ 39 | ggplot of TESS results 40 | } 41 | \seealso{ 42 | Other TESS functions: 43 | \code{\link{allK_plot_helper}()}, 44 | \code{\link{bestK}()}, 45 | \code{\link{geom_tess}()}, 46 | \code{\link{ggbarplot_helper}()}, 47 | \code{\link{pops_helper}()}, 48 | \code{\link{tess_barplot}()}, 49 | \code{\link{tess_col_default}()}, 50 | \code{\link{tess_do_everything}()}, 51 | \code{\link{tess_ggbarplot}()}, 52 | \code{\link{tess_krig}()}, 53 | \code{\link{tess_ktest}()}, 54 | \code{\link{tess_legend}()}, 55 | \code{\link{tess_plot_allK}()} 56 | } 57 | \concept{TESS functions} 58 | -------------------------------------------------------------------------------- /man/tess_krig.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_krig} 4 | \alias{tess_krig} 5 | \title{Krige admixture values} 6 | \usage{ 7 | tess_krig(qmat, coords, grid = NULL, correct_kriged_Q = TRUE) 8 | } 9 | \arguments{ 10 | \item{qmat}{qmatrix} 11 | 12 | \item{coords}{coordinates of samples as sf points, a two-column matrix, or a data.frame representing x and y coordinates (see Details for important information about projections)} 13 | 14 | \item{grid}{SpatRaster for kriging} 15 | 16 | \item{correct_kriged_Q}{whether to correct kriged Q values so values greater than 1 are set to 1 and values less than 0 are set to 0 (defaults to TRUE)} 17 | } 18 | \value{ 19 | Raster\* type object of kriged Q values 20 | } 21 | \description{ 22 | Krige admixture values 23 | } 24 | \seealso{ 25 | Other TESS functions: 26 | \code{\link{allK_plot_helper}()}, 27 | \code{\link{bestK}()}, 28 | \code{\link{geom_tess}()}, 29 | \code{\link{ggbarplot_helper}()}, 30 | \code{\link{pops_helper}()}, 31 | \code{\link{tess_barplot}()}, 32 | \code{\link{tess_col_default}()}, 33 | \code{\link{tess_do_everything}()}, 34 | \code{\link{tess_ggbarplot}()}, 35 | \code{\link{tess_ggplot}()}, 36 | \code{\link{tess_ktest}()}, 37 | \code{\link{tess_legend}()}, 38 | \code{\link{tess_plot_allK}()} 39 | } 40 | \concept{TESS functions} 41 | -------------------------------------------------------------------------------- /man/tess_ktest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_ktest} 4 | \alias{tess_ktest} 5 | \title{Test multiple K values} 6 | \usage{ 7 | tess_ktest( 8 | gen, 9 | coords, 10 | Kvals = 1:10, 11 | grid = NULL, 12 | tess_method = "projected.ls", 13 | lambda = 1, 14 | K_selection = "manual", 15 | ploidy = 2, 16 | quiet = FALSE 17 | ) 18 | } 19 | \arguments{ 20 | \item{gen}{genotype dosage matrix (rows = individuals & columns = snps) or \code{vcfR} object} 21 | 22 | \item{coords}{coordinates of samples as sf points, a two-column matrix, or a data.frame representing x and y coordinates (see Details for important information about projections)} 23 | 24 | \item{Kvals}{vector of K values to test} 25 | 26 | \item{grid}{SpatRaster for kriging} 27 | 28 | \item{tess_method}{the type of TESS method to be run ("projected.ls" for projected least squares algorithm (default) or "qp" for quadratic programming algorithm)} 29 | 30 | \item{lambda}{numeric value for the spatial regularization parameter. The default value lambda = 1 attributes equal weights to the loss function and to the penalty function.} 31 | 32 | \item{K_selection}{how to perform K selection ("manual" to enter into console (default) or "auto" for automatic selection based on \link[algatr]{bestK})} 33 | 34 | \item{ploidy}{ploidy of data (defaults to 2)} 35 | 36 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 37 | } 38 | \value{ 39 | list with results from testing different K-values 40 | } 41 | \description{ 42 | Test multiple K values 43 | } 44 | \seealso{ 45 | Other TESS functions: 46 | \code{\link{allK_plot_helper}()}, 47 | \code{\link{bestK}()}, 48 | \code{\link{geom_tess}()}, 49 | \code{\link{ggbarplot_helper}()}, 50 | \code{\link{pops_helper}()}, 51 | \code{\link{tess_barplot}()}, 52 | \code{\link{tess_col_default}()}, 53 | \code{\link{tess_do_everything}()}, 54 | \code{\link{tess_ggbarplot}()}, 55 | \code{\link{tess_ggplot}()}, 56 | \code{\link{tess_krig}()}, 57 | \code{\link{tess_legend}()}, 58 | \code{\link{tess_plot_allK}()} 59 | } 60 | \concept{TESS functions} 61 | -------------------------------------------------------------------------------- /man/tess_legend.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_legend} 4 | \alias{tess_legend} 5 | \title{Create a custom legend for TESS maps} 6 | \usage{ 7 | tess_legend(krig_admix, plot_method = "maxQ", minQ = 0.1) 8 | } 9 | \arguments{ 10 | \item{krig_admix}{SpatRaster returned by \link[algatr]{tess_krig}} 11 | 12 | \item{plot_method}{method for making rainbow map of kriged layers (options: "maxQ" to only plot the max Q value for each cell (default), "allQ" to plot all Q values greater than \code{minQ}, "maxQ_poly" or "allQ_poly" to create the plots as previously described, but as polygons for each K instead of continuous Q values)} 13 | 14 | \item{minQ}{threshold for minimum Q-value for rainbow plotting if \code{plot_method = "allQ"} or \code{plot_method = "allQ_poly"} is used (defaults to 0.10)} 15 | } 16 | \value{ 17 | legend for kriged map from TESS 18 | } 19 | \description{ 20 | Create a custom legend for TESS maps 21 | } 22 | \seealso{ 23 | Other TESS functions: 24 | \code{\link{allK_plot_helper}()}, 25 | \code{\link{bestK}()}, 26 | \code{\link{geom_tess}()}, 27 | \code{\link{ggbarplot_helper}()}, 28 | \code{\link{pops_helper}()}, 29 | \code{\link{tess_barplot}()}, 30 | \code{\link{tess_col_default}()}, 31 | \code{\link{tess_do_everything}()}, 32 | \code{\link{tess_ggbarplot}()}, 33 | \code{\link{tess_ggplot}()}, 34 | \code{\link{tess_krig}()}, 35 | \code{\link{tess_ktest}()}, 36 | \code{\link{tess_plot_allK}()} 37 | } 38 | \concept{TESS functions} 39 | -------------------------------------------------------------------------------- /man/tess_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{tess_packages} 4 | \alias{tess_packages} 5 | \title{Install TESS packages} 6 | \usage{ 7 | tess_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | Checks for the presence of packages required for TESS. 14 | If any of these packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following packages will be installed if not already present: 18 | \itemize{ 19 | \item "automap" 20 | \item "graphics" 21 | \item "LEA" (from Bioconductor repository) 22 | \item "tess3r" (from GitHub repository bcm-uga/TESS3_encho_sen) 23 | \item "fields" 24 | \item "rworldmap" 25 | \item "cowplot" 26 | } 27 | } 28 | \examples{ 29 | \dontrun{tess_packages()} 30 | } 31 | -------------------------------------------------------------------------------- /man/tess_plot_allK.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TESS.R 3 | \name{tess_plot_allK} 4 | \alias{tess_plot_allK} 5 | \title{Plot all kriged Q values for each K} 6 | \usage{ 7 | tess_plot_allK( 8 | krig_admix, 9 | coords = NULL, 10 | col_pal = algatr_col_default("base"), 11 | col_breaks = 20, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{krig_admix}{RasterStack returned by \link[algatr]{tess_krig}} 17 | 18 | \item{coords}{dataframe with x and y coordinates for plotting (optional)} 19 | 20 | \item{col_breaks}{number of breaks for plotting (defaults to 20)} 21 | 22 | \item{...}{Graphical parameters. Any argument that can be passed to image.plot and to base plot} 23 | } 24 | \description{ 25 | Plot all kriged Q values for each K 26 | } 27 | \seealso{ 28 | Other TESS functions: 29 | \code{\link{allK_plot_helper}()}, 30 | \code{\link{bestK}()}, 31 | \code{\link{geom_tess}()}, 32 | \code{\link{ggbarplot_helper}()}, 33 | \code{\link{pops_helper}()}, 34 | \code{\link{tess_barplot}()}, 35 | \code{\link{tess_col_default}()}, 36 | \code{\link{tess_do_everything}()}, 37 | \code{\link{tess_ggbarplot}()}, 38 | \code{\link{tess_ggplot}()}, 39 | \code{\link{tess_krig}()}, 40 | \code{\link{tess_ktest}()}, 41 | \code{\link{tess_legend}()} 42 | } 43 | \concept{TESS functions} 44 | -------------------------------------------------------------------------------- /man/unfold.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MMRR.R 3 | \name{unfold} 4 | \alias{unfold} 5 | \title{unfold converts the lower diagonal elements of a matrix into a vector} 6 | \usage{ 7 | unfold(X, scale = TRUE) 8 | } 9 | \arguments{ 10 | \item{X}{is a distance matrix} 11 | 12 | \item{scale}{if TRUE then matrices will be standardized (defaults to TRUE)} 13 | } 14 | \description{ 15 | unfold converts the lower diagonal elements of a matrix into a vector 16 | } 17 | \seealso{ 18 | Other MMRR functions: 19 | \code{\link{MMRR}()}, 20 | \code{\link{mmrr_df}()}, 21 | \code{\link{mmrr_do_everything}()}, 22 | \code{\link{mmrr_plot}()}, 23 | \code{\link{mmrr_run}()}, 24 | \code{\link{mmrr_table}()}, 25 | \code{\link{mmrr_var_sel}()} 26 | } 27 | \concept{MMRR functions} 28 | -------------------------------------------------------------------------------- /man/vcf_to_dosage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vcf_to_dosage.R 3 | \name{vcf_to_dosage} 4 | \alias{vcf_to_dosage} 5 | \title{Convert a vcf to a dosage matrix} 6 | \usage{ 7 | vcf_to_dosage(x) 8 | } 9 | \arguments{ 10 | \item{x}{can either be an object of class \code{vcfR} or a path to a .vcf file} 11 | } 12 | \value{ 13 | dosage matrix 14 | } 15 | \description{ 16 | Convert a vcf to a dosage matrix 17 | } 18 | -------------------------------------------------------------------------------- /man/wingen_do_everything.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wingen.R 3 | \name{wingen_do_everything} 4 | \alias{wingen_do_everything} 5 | \title{wingen function to do everything (preview and generate moving window maps, krige, and mask)} 6 | \usage{ 7 | wingen_do_everything( 8 | gen, 9 | lyr, 10 | coords, 11 | wdim = 3, 12 | fact = 0, 13 | sample_count = TRUE, 14 | min_n = 2, 15 | preview = FALSE, 16 | stat = "pi", 17 | rarify = FALSE, 18 | kriged = FALSE, 19 | grd = NULL, 20 | index = 1, 21 | agg_grd = NULL, 22 | disagg_grd = NULL, 23 | agg_r = NULL, 24 | disagg_r = NULL, 25 | masked = FALSE, 26 | mask = NULL, 27 | bkg = NULL, 28 | plot_count = FALSE, 29 | quiet = FALSE 30 | ) 31 | } 32 | \arguments{ 33 | \item{gen}{Genetic data either as an object of type vcf or a path to a vcf file (\emph{note:} order matters! The coordinate and genetic data should be in the same order; there are currently no checks for this).} 34 | 35 | \item{lyr}{SpatRaster or RasterLayer to slide the window across (see Details for important information about projections). For \code{method = "resist"} this should also be the conductivity layer (see \link[wingen]{resist_gd}).} 36 | 37 | \item{coords}{Coordinates of samples as sf points, a two-column matrix, or a data.frame representing x and y coordinates (see Details for important information about projections).} 38 | 39 | \item{wdim}{If \code{method = "window"}, dimensions (height x width) of window; if only one value is provided, a square window is created (defaults to 3 x 3 window).} 40 | 41 | \item{fact}{Aggregation factor to apply to \code{lyr} (defaults to 0; \emph{note:} increasing this value reduces computational time).} 42 | 43 | \item{sample_count}{Whether to create plot of sample counts for each cell (defaults to TRUE).} 44 | 45 | \item{min_n}{Minimum number of samples to use in calculations (any focal cell with a window containing less than this number of samples will be assigned a value of NA).} 46 | 47 | \item{preview}{whether to produce preview of raster layer, window and focal cell size using \link[wingen]{preview_gd} (default = FALSE)} 48 | 49 | \item{stat}{Genetic diversity statistic(s) to calculate (see Details, defaults to \code{"pi"}). Can be a single statistic or a vector of statistics.} 50 | 51 | \item{rarify}{If rarify = TRUE, rarefaction is performed (defaults to FALSE).} 52 | 53 | \item{kriged}{whether to smooth out mapped values using kriging using \link[wingen]{krig_gd} (default = FALSE)} 54 | 55 | \item{grd}{Object to create grid for kriging; can be a SpatRaster or RasterLayer. If undefined, will use \code{r} to create a grid.} 56 | 57 | \item{index}{Integer indices of layers in raster stack to krige (defaults to 1; i.e., the first layer).} 58 | 59 | \item{agg_grd}{Factor to use for aggregation of \code{grd}, if provided (this will decrease the resolution of the final kriged raster; defaults to NULL).} 60 | 61 | \item{disagg_grd}{Factor to use for disaggregation of \code{grd}, if provided (this will increase the resolution of the final kriged raster; defaults to NULL).} 62 | 63 | \item{agg_r}{Factor to use for aggregation of \code{r}, if provided (this will decrease the number of points used in the kriging model; defaults to NULL).} 64 | 65 | \item{disagg_r}{Factor to use for disaggregation of \code{r}, if provided (this will increase the number of points used in the kriging model; defaults to NULL).} 66 | 67 | \item{masked}{whether to mask out areas outside region of interest using \link[wingen]{mask_gd} (default = FALSE)} 68 | 69 | \item{plot_count}{if TRUE, whether to visualize sample counts using \link[wingen]{plot_count} (default = FALSE)} 70 | 71 | \item{quiet}{whether to operate quietly and suppress the output of tables and figures (defaults to FALSE)} 72 | } 73 | \value{ 74 | RasterBrick object final raster 75 | } 76 | \description{ 77 | wingen function to do everything (preview and generate moving window maps, krige, and mask) 78 | } 79 | \details{ 80 | When using wingen, please cite the original citation: Bishop, A.P., Chambers, E.A., Wang, I.J. (2023). Generating continuous maps of genetic diversity using moving windows. Methods Ecol. Evol. doi: https://doi.org/10.1111/2041-210X.14090 81 | N.B.: Be aware that this function sets \emph{many} of the wingen function arguments to defaults, which my result in sub optimal results. We highly advise researchers to run each wingen function separately for best results. 82 | } 83 | \seealso{ 84 | Other wingen functions: 85 | \code{\link{krig_agg_helper}()}, 86 | \code{\link{krig_helper}()} 87 | } 88 | \concept{wingen functions} 89 | -------------------------------------------------------------------------------- /man/wingen_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package_installs.R 3 | \name{wingen_packages} 4 | \alias{wingen_packages} 5 | \title{Install wingen packages} 6 | \usage{ 7 | wingen_packages() 8 | } 9 | \value{ 10 | None 11 | } 12 | \description{ 13 | This function checks for the presence of packages required for wingen. 14 | If the packages are not already installed, it will automatically install them. 15 | } 16 | \details{ 17 | The following package will be installed if not already present: 18 | \itemize{ 19 | \item "wingen" 20 | } 21 | } 22 | \examples{ 23 | \dontrun{wingen_packages()} 24 | } 25 | -------------------------------------------------------------------------------- /package_setup.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "package_setup" 3 | format: html 4 | editor: visual 5 | --- 6 | 7 | ```{r} 8 | library(usethis) 9 | library(here) 10 | library(devtools) 11 | ``` 12 | 13 | ```{r} 14 | use_build_ignore("package_setup.qmd") 15 | ``` 16 | 17 | ```{r} 18 | # Creates and modifies external data for use in package 19 | usethis::use_data_raw() 20 | usethis::use_pipe() 21 | ``` 22 | 23 | ```{r} 24 | usethis::use_logo("logo.png") 25 | usethis::use_readme_rmd() 26 | ``` 27 | 28 | ```{r} 29 | # Run once to configure package to use pkgdown 30 | #usethis::use_pkgdown() 31 | # Run to build the website 32 | pkgdown::build_site() 33 | usethis::use_pkgdown_github_pages() 34 | ``` 35 | 36 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheWangLab/algatr/21c69cbc11b3b1aefb798ee61cf85164c385be9c/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /renv/.gitignore: -------------------------------------------------------------------------------- 1 | library/ 2 | local/ 3 | cellar/ 4 | lock/ 5 | python/ 6 | sandbox/ 7 | staging/ 8 | -------------------------------------------------------------------------------- /renv/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "bioconductor.version": null, 3 | "external.libraries": [], 4 | "ignored.packages": [], 5 | "package.dependency.fields": [ 6 | "Imports", 7 | "Depends", 8 | "LinkingTo" 9 | ], 10 | "r.version": null, 11 | "snapshot.type": "implicit", 12 | "use.cache": true, 13 | "vcs.ignore.cellar": true, 14 | "vcs.ignore.library": true, 15 | "vcs.ignore.local": true, 16 | "vcs.manage.ignores": true 17 | } 18 | -------------------------------------------------------------------------------- /scan_dependencies.R: -------------------------------------------------------------------------------- 1 | library(tidyr) 2 | library(dplyr) 3 | d <- renv::dependencies() 4 | unique(d$Source) 5 | 6 | # / in front of dist because otherwise Gen_dist packages get counted for dist 7 | methods <- c("LFMM", "RDA", "GDM", "MMRR", "TESS", "wingen", "masks", "get_worldclim", "Gen_dist", "SNP_LD", "check_vars", "/dist", "format_data") 8 | methods_d <- purrr::map(methods, \(x) { 9 | return(d %>% filter(grepl(x, Source)) %>% dplyr::select(Package) %>% distinct() %>% mutate(method = x)) 10 | }) %>% bind_rows() 11 | 12 | general_packages <- 13 | d %>% 14 | dplyr::select(Package) %>% 15 | group_by(Package) %>% 16 | count() %>% 17 | filter(n > 4) %>% 18 | dplyr::select(Package) %>% 19 | # remove non-general packages 20 | filter(!(Package %in% c("wingen"))) %>% 21 | arrange(Package) 22 | 23 | methods_d <- methods_d %>% filter(!(Package %in% general_packages$Package)) 24 | view(methods_d) 25 | 26 | leftovers <- 27 | d %>% 28 | filter(!(Package %in% c("algatr", "wingen", "knitr", "rmarkdown"))) %>% 29 | filter(!(Package %in% c(general_packages$Package, methods_d$Package))) %>% 30 | distinct(Package) 31 | 32 | print(leftovers) 33 | 34 | # tigris - used only in DATASET 35 | # fansi - used only in alazygatr 36 | # usethis, crayon, devtools, renv, BiocManager - all SUGGESTS 37 | # RStoolbox - only used in the enviro_data_vignette 38 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | *.rds 4 | *.DS_Store 5 | -------------------------------------------------------------------------------- /vignettes/alazygatr_vignette.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Alazygatr" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Alazygatr} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r color, echo = FALSE, results = FALSE} 11 | options(crayon.enabled = TRUE) 12 | 13 | old_hooks <- fansi::set_knit_hooks(knitr::knit_hooks, 14 | which = c("output", "message", "error") 15 | ) 16 | ``` 17 | 18 | ```{r, warning = FALSE, message = FALSE} 19 | library(algatr) 20 | ``` 21 | 22 | Install all of the required packages: 23 | ```{r, eval = FALSE} 24 | alazygatr_packages() 25 | ``` 26 | 27 | Are you a lazy algatr? The `do_everything_for_me()` function runs all six landscape genomic methods in the algatr package (wingen, TESS, GDM, MMRR, RDA, and LFMM) and provides limited options for customizability. This function primarily exists for fun and to demonstrate that algatr really can be run using on a vcf and sampling coordinates; we **do not** encourage researchers to actually perform analyses on their data using this function! 28 | 29 | The main arguments within this function are simple: `vcf` specifies the vcf, `coords` specifies the sampling coordinates, and `envlayers` specifies the environmental layers (not required). As usual, make sure your samples are in the same order between your data file and coordinates file and that your CRS is consistent! 30 | 31 | First, let's load our test data. For the sake of things running quickly, let's run this function on only 20 individuals from the test dataset. 32 | 33 | ```{r load data} 34 | load_algatr_example() 35 | gen <- liz_vcf[, 1:21] 36 | coords <- liz_coords[1:20, ] 37 | envlayers <- CA_env 38 | ``` 39 | 40 | Now, let's run the function: 41 | 42 | ```{r alazygatr, warning = FALSE, message = FALSE, results = 'asis', fig.width = 6, fig.height = 6} 43 | lazy_results <- do_everything_for_me(gen, coords, envlayers, quiet = FALSE) 44 | ``` 45 | 46 | The `do_everything_for_me()` function returns a list with each analysis's results as objects named according to the method. These formats are identical to those obtained when running respective "do_everything" functions (e.g., `tess_do_everything()` function output is identical to that within the `tess` object). 47 | 48 | For methods with model selection (e.g., GDM and MMRR), the default of `do_everything_for_me()` is to run with model selection (`"best"`), and if no significant variables are found, the function will revert to running the `"full"` model for these methods. 49 | --------------------------------------------------------------------------------