```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

Install the stable version of adegenet with dependencies

```{r}
install.packages("adegenet", dep=TRUE)
install.packages("hierfstat", dep=TRUE)
install.packages("poppr", dep=TRUE)
```

Load the useful packages

```{r, echo=FALSE}
library("adegenet")
library("hierfstat")
library("poppr")
```


Convert PLINK binary files to .ped with plink --recode.
Then convert .ped to STRUCTURE format by PGDSpider.
Load STRUCTURE .stru file.

```{r}
data_local_stru <- read.structure("../additional_files/locality_grants.stru", n.ind=95, n.loc=7566, onerowperind=FALSE, col.lab=1, col.pop=2, row.marknames=1, ask=FALSE)
popNames(data_local_stru)<-c("Amboseli", "Mkomazi_E", "Burigi", "Ikiri-Rungwa", "Aruba_Dam", "Ugalla", "Masai_Mara",	"Nairobi",	"Samburu",	"Tsavo",	"Sibiloi",	"Monduli", "Maswa","Mkomazi_W")
```


## pairwise Fst
```{r}
dist_WC84 <- genet.dist(data_local_stru, method = "WC84")
```





## pairwise genetic distance

```{r}
pop_local_stru <- genind2genpop(data_local_stru)

pw_dist_stru <- dist.genpop(pop_local_stru, method = 1, diag = TRUE, upper = TRUE)
```


## Produce a basic summary table for population genetic analyses including Nei's gene diversity (expected heterozygosity)

```{r}
summary <- poppr(data_local_stru)

```
