data <- read.table("O://Genetik//MA//Silke//RCode//TestData//2pop.txt", header=T) # read data; change path name according to where you saved the file "2pop.txt" data[1,] Loci <- data[,3:8] Pop <- data[,9] #### witout resampling ##### source("O:\\Genetik\\MA\\Silke\\RCode\\GeneticDistance//genetic_dist_source_v3.R") #change path name according to the location on your computer gen.dist <- genetic.dist(Data=Loci, Pop) gen.dist$D.Nei.Min #Nei's minimum genetic distance # Reference: Takesaki,N.&Nei,M.(1996)Genetics144:389-399. # Consult the "ReadMe.txt" file for finding out which formulae # contain bugs and thus should _NOT_ be used. #### with resampling ##### attach(data) source("O:\\Genetik\\MA\\Silke\\RCode\\GeneticDistance//genetic_dist_source_v3.R") source("O:\\Genetik\\MA\\Silke\\RCode\\Resampling//Code_Resampling.R") #change path names according to the location on your computer nr.res <- 3 # enter the number of resamplings data.res <- list() for(i in 1:nr.res) { data.res[[i]] <- resample(data) } #Assign "Loci.1" and "Pop.1" to each resampled data set Loci.1 <- list() Pop.1 <- list() for(n in 1:nr.res) { Loci.1[[n]] <- data.res[[n]][,3:8] #change the columns if your data file differs Pop.1[[n]] <- data.res[[n]][,9] #change the columns if your data file differs } test1 <- list() n <- 1 for(i in 1:nr.res) { Loci <- Loci.1[[i]] Pop <- Pop.1[[i]] test1[[n]] <- genetic.dist(Data=Loci, Pop) n <- n+1 } test1[[1]]$D.Nei.Min # returns Nei's minimum genetic distance of the first # resampled data set. ## Calculate the mean genetic distance over resamplings Dm <- matrix(NA,length(unique(Pop)),length(unique(Pop)),dimnames=list(unique(Pop),unique(Pop))) a <- test1[[1]]$D.Nei.Min ##change if necessary for(k in 2:nr.res) { for(i in 1:(length(unique(Pop))-1)) { for(j in (i+1):length(unique(Pop))) { Dm[j,i] <- a[j,i] + test1[[k]]$D.Nei.Min[j,i] } } } Dm <- Dm/nr.res Dm