Skip to content

Commit

Permalink
add gif to README
Browse files Browse the repository at this point in the history
  • Loading branch information
AnushaPB committed Mar 13, 2023
1 parent a8d5e85 commit 66d1858
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ knitr::opts_chunk$set(

Generate continuous maps of genetic diversity using moving windows with options for rarefaction, interpolation, and masking ([Bishop et al. 2023](http://doi.org/10.1111/2041-210X.14090)).

## ![](wingen.gif)

## Installation

Install the development version from [GitHub](https://github.com/) with:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Generate continuous maps of genetic diversity using moving windows with
options for rarefaction, interpolation, and masking ([Bishop et
al. 2023](http://doi.org/10.1111/2041-210X.14090)).

## ![](wingen.gif)

## Installation

Install the development version from [GitHub](https://github.com/) with:
Expand Down
Binary file added wingen.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions wingen_gif.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: "wingen_gif"
output: html_document
date: "2022-08-26"
editor_options:
chunk_output_type: inline
---
```{r}
library(vcfR)
library(here)
library(wingen)
library(animation)
devtools::load_all()
```


```{r, fig.width = 6, fig.height = 3}
load_middle_earth_ex()
lyr = lotr_lyr
wdim = 7
fact = 3
rarify = FALSE
min_n = 2
L <- 100
# replace stat with function to calculate diversity statistic
stat <- return_stat("pi")
# format coords
coords <- lotr_coords
# format gen
gen <- vcf_to_dosage(lotr_vcf)
# make neighbor matrix
nmat <- wdim_to_mat(wdim)
# make aggregated raster
if (fact != 0) lyr <- terra::aggregate(lyr, fact, fun = mean)
# get cell index for each coordinate
coord_cells <- terra::extract(lyr, coords, cell = TRUE)[, "cells"]
ani.options(
convert = shQuote('C:/Program Files (x86)/ImageMagick-6.8.1-Q16/convert.exe')
)
saveGIF(
{
# make raster lyr copy with all NA
lyr <- terra::mask(lyr, lotr_range)
lyrg <- lyr/0
for(i in 1:999){
if(is.na(lyr[i])) next
# get adjacent cells to center cell
adjc <- raster::adjacent(lyr, i, directions = nmat)
# get list of indices of coords in that set of cells
adjci <- purrr::map_dbl(adjc, 1, function(x) {
seq(x[1], x[2])
})
lyrw <- lyr * 0
lyrw[adjci] <- 1
lyrw[i] <- 2
subc <- coords[get_adj(i, lyr, nmat, coord_cells),]
lyrg[i] <- window_helper(i = i, lyr = lyr, x = gen,
coord_cells = coord_cells,
min_n = 2,
nmat = nmat,
rarify = FALSE,
stat_function = calc_pi, L = L,
rarify_n = NULL, rarify_nit = NULL,
fun = mean)$gd
par(mfrow = c(1,2), mar = rep(0,4), oma = rep(0,4), bg = "white")
plot_gd(lyrw, col = viridis::mako(3, direction = 1), main = "Landscape", legend = FALSE)
points(coords, pch = 3, cex = 1, col = rgb(0.3,0.3,0.3))
points(subc, pch = 3, cex = 1, col = "orange")
plot_gd(lyrg, lyr, range = c(0, 0.32), breaks = 100, legend = FALSE, main = "Genetic Diversity")
}
},
movie.name = "wingen.gif",
interval = 0.08,
ani.width = 600,
ani.height = 300,
outdir = getwd()
)
```

0 comments on commit 66d1858

Please sign in to comment.