# Adegenet code #
library("ape")
library("pegas")
library("seqinr")
library("ggplot2")
library("adegenet")
library("hierfstat")
## Import file ##
```myFile <- import2genind("Puma_Stru.stru")```
### 12444 SNPs and 130 inds
library("ape")
library("pegas")
library("seqinr")
library("ggplot2")
library("adegenet")
library("hierfstat")
?adegenet
myFile <- import2genind("Puma_Stru.stru") #12444 SNPs and 130 inds
## QUESTIONS FOR STRUCTURE FILES:
### How many genotypes are there?
#### answer: 130
### How many markers are there?
#### answer: 12444
### Which column contains the populations factor ('0' if absent)?
#### answer: 1
### Which column contains the population factor ('0' if absent)?
#### answer:2
### Which column contains the population factor ('0' if absent)?
#### answer: 0
### Which other optional columns should be read (press 'return' when done)?
#### just hit enter
### Which row contains the marker names ('0' if absent)?
#### Answer:1
### Are genotypes coded by a single row (y/n)?
#### answer: n
## Look at transformed genind file
```
myFile
```
## Look at shared alleles
```
myFile2 <- propShared(myFile)
genind2df(myFile,sep="|")
write.table(myFile2, file = "Output" )
```
## finding allelic richness
```
myFile3 <- allel.rich(myFile)
write.table(myFile3, file = "allele rich")
```
## Scaling
```
?scaleGen
X <- scaleGen(myFile, NA.method="zero")
X[1:5,1:5]
```
## Create PCA
```
pca1<-dudi.pca(X,cent=FALSE,scale=FALSE,scannf=FALSE,nf=3)
myCol <-c("darkgreen","darkblue")
s.class(pca1$li,pop(myFile), col=myCol)
```
## Making Plot Structure Figures Graph with Q data ###
```
tbl <- read.csv("pumaQdata.csv")
barplot(t(as.matrix(tbl)), col=rainbow(3),
xlab="Individual #", ylab="Ancestry", border=NA)
```
#### File was then edited in paintscape