library(vegan) # load the vegan library dists<-read.table(file="~/Downloads/Geo-Gen_Matrix_Cuning.txt",header=FALSE,sep="\t") # load the square matrix with both triangular distance matrices clusters<-as.dist(read.table(file="~/Downloads/amova_clusters.txt",header=TRUE,sep="\t"),upper=FALSE,diag=FALSE) # load the cluster matrix View(dists) geogdist<-as.dist(dists,upper=FALSE,diag=FALSE) # assign the lower geographic distance matrix to geogdist phist<-as.dist(t(dists),upper=FALSE,diag=FALSE) # take the transpose of the matrix and assign the new lower genetic distance matrix to phist plot(geogdist,phist) # plot the distance matrices mantel(phist,geogdist) # run the mantel test with all the default arguments # So, we should find that a mantel over the whole region is significant. # Now we want to see if there is any bias due to either IBD or hierarchical structuring with a partial mantel. mantel.partial(phist,geogdist,clusters) # run the partial mantel with geographic distances, correcting for the two clusters # We should see a partial mantel of phist and geogdist is not significant when clusters are considered. mantel.partial(phist,clusters,geogdist) # run the partial mantel with clusters, correcting for geographic distances (IBD signature) # Now we find that a partial mantel of phist on clusters is MUCH more correlated! This suggests that most of the signal is from hierarchical structure rather than IBD. # Let's make a mantel correlogram mc<-mantel.correlog(phist,geogdist,n.class=10) plot(mc,alpha=0.05) # We can also check if mantel is significant within AMOVA regions. Let's look at central Indonesia: centindodists<-dists[1:17,1:17] geogdist<-as.dist(centindodists,upper=FALSE,diag=FALSE) phist<-as.dist(t(centindodists),upper=FALSE,diag=FALSE) mantel(phist,geogdist)