Skip to content

Commit

Permalink
Moved plotting maps to archive, added a new buffer map
Browse files Browse the repository at this point in the history
  • Loading branch information
ekschumacher committed Sep 28, 2021
1 parent 3e937df commit 409ad08
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ coord_df_proj <- spTransform(coord_df, proj_out)
setwd(butternut_drive)
butternut_buffer <- readOGR(dsn = paste0(butternut_drive,"\\Genetic_Analyses\\data_files\\geographic_files") ,
layer = "butternut_buffer")
butternut_buffer_trans <- sp::spTransform(na_shp, proj_out)
butternut_buffer_trans <- sp::spTransform(butternut_buffer, "+proj=longlat +ellps=WGS84 +datum=WGS84")

##calculate dist2line
butternut_dist <- dist2Line(coord_df, butternut_buffer_trans)

##list of 24 colors for populations
butternut_col <- c("darkmagenta", "darkorchid3", "deeppink3", "darkviolet", "deeppink","lightpink",
Expand Down
Binary file modified Images/geographic_images/pop_map_allind.pdf
Binary file not shown.
11 changes: 11 additions & 0 deletions SDMs/1_create_pop_buffer.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ max_lat <- max(butternut_range$Latitude)
coordinates(butternut_range2) <- c('Longitude', 'Latitude')
proj4string(butternut_range2) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")

##set working directory
setwd(butternut_drive)

##Lon lat files
butternut_reorg_lonlat <- read.csv("Genetic_Analyses\\data_files\\after_reorg\\reorg_lon_lat.csv")

##population names document
butternut_24pop_names <- unique(butternut_reorg_lonlat$Pop)

#########################################
########## Calculate Buffer #############
#########################################
Expand Down Expand Up @@ -64,3 +73,5 @@ butternut_buff <- gBuffer(crop, width = 100000)

##write out buffer file
shapefile(butternut_buff,"butternut_buffer")


59 changes: 51 additions & 8 deletions genetic_analyses/3_sum_stats_geneticdiversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#First, we tested linkage disequilibrium, null alleles,
#and Hardy Weinberg equilibrium.
#Next, a data frame including expected heterozygosity, allelic richness,
#number of alleles, mean longtiude and latitude by population, and
#number of alleles, mean longtiude and latitude by population, distance to range edge, and
#individual numbers. This table is included in full in the supplemental text
#of this manuscript.

Expand All @@ -17,6 +17,9 @@ library(poppr)
library(hierfstat)
library(PopGenReport)
library(pegas)
library(geosphere)
library(sp)
library(rgdal)

##########################################
############# Set directories ############
Expand All @@ -41,15 +44,19 @@ butternut_reorg_lonlat <- read.csv("Genetic_Analyses\\data_files\\after_reorg\\r
##load in mean lon and lat document
butternut_mean_lon_lat <- read.csv("Genetic_Analyses\\data_files\\geographic_files\\butternut_coord_df.csv")

##create population name doc
butternut_24pop_names <- unique(butternut_reorg_lonlat$Pop)

##name individuals in genind doc
rownames(butternutgen_reorg@tab) <- butternut_reorg_lonlat$Ind

##name populations in genind doc
##population names document
butternut_24pop_names <- unique(butternut_reorg_lonlat$Pop)

##name populations in genind
levels(butternutgen_reorg@pop) <- butternut_24pop_names

##load range buffer for butternut
butternut_buffer <- readOGR(dsn = paste0(butternut_drive,"\\Genetic_Analyses\\data_files\\geographic_files") ,
layer = "butternut_buffer")

############################################################################
####### Run Genetic Diversity Checks like LD, HWE, Null Alleles ###########
############################################################################
Expand Down Expand Up @@ -101,12 +108,48 @@ BN_ind <- BN_poppr[1:24, 2:3]
BN_alleles <-bn_sumstats$pop.n.all/length(butternutgen_reorg@loc.n.all)
BN_all_rich <- colMeans(allelic.richness(butternutgen_reorg)$Ar)

####Geographic analyses for each population
##calculate mean longitude and latitude for each population
butternut_mean_lon <- matrix()
butternut_mean_lat <- matrix()

##loops for mean lat/lon
for(pop in butternut_24pop_names){

butternut_mean_lon[pop] <- mean(butternut_reorg_lonlat[butternut_reorg_lonlat$Pop == pop,][,3])

}

for(pop in butternut_24pop_names){

butternut_mean_lat[pop] <- mean(butternut_reorg_lonlat[butternut_reorg_lonlat$Pop == pop,][,4])

}
##now combine into dataframes
butternut_coords_df <- cbind(butternut_mean_lon, butternut_mean_lat)[-1,]

#project range extent buffer to the same extent as population lon/lat
butternut_buffer_trans <- sp::spTransform(butternut_buffer, "+proj=longlat +ellps=WGS84 +datum=WGS84")

##now calculate distance to butternut range edge
butternut_dist <- dist2Line(butternut_coords_df, butternut_buffer_trans)

##add regional names
butternut_regions <- c("New Brunswick","New Brunswick", "New Brunswick", "New Brunswick", "New Brunswick",
"New Brunswick","New Brunswick", "Ontario","Quebec","Ontario","Ontario","Quebec",
"United States", "United States", "United States", "United States", "United States",
"United States", "United States", "United States", "United States", "United States",
"United States", "United States")

##create data frame
butternut_stat_df <- signif(cbind(butternut_mean_lon_lat[,2:3], BN_ind, BN_nall, BN_all_rich, BN_hexp),3)
butternut_stat_df <- cbind(butternut_regions, signif(cbind(butternut_coords_df[,c(1:2)], (butternut_dist[,1]/1000),
BN_ind, BN_nall, BN_all_rich, BN_hexp),3))

##name columns and rows
rownames(butternut_stat_df) <- butternut_24pop_names
colnames(butternut_stat_df) <- c("Mean Longitude", "Mean Latitude", "Number of Individuals", "MLG","Number of Alleles", "Allelic Richness", "Expected Heterozygosity")
rownames(butternut_stat_df) <- c(1:24)
colnames(butternut_stat_df) <- c("Region","Mean Longitude", "Mean Latitude", "Distance to Range Edge (km)",
"Number of Individuals",
"MLG","Number of Alleles", "Allelic Richness", "Expected Heterozygosity")

##write out csv
write.csv(butternut_stat_df, "Genetic_Analyses\\genetic_analyses_results\\butternut_stat_df.csv")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANSI 1252
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 25 additions & 25 deletions genetic_analyses/genetic_analyses_results/butternut_stat_df.csv
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
"","Mean Longitude","Mean Latitude","Number of Individuals","MLG","Number of Alleles","Allelic Richness","Expected Heterozygosity"
"31",-66.1,46.6,92,91,122,7.26,0.79
"568",-67.7,46.7,110,109,131,7.89,0.83
"1014",-65.6,45.7,112,112,143,8.19,0.821
"7917",-67.7,46.1,102,102,139,8.15,0.835
"9101113a",-66.4,45.9,227,225,144,7.71,0.819
"9101113b",-66.7,46,126,126,140,7.99,0.828
"151",-78.5,44.6,24,24,112,8.51,0.839
"170",-77.1,45.4,20,20,90,7.36,0.78
"125147",-79.4,44.1,35,35,131,9.18,0.852
"126147",-80.1,44,55,55,143,8.91,0.848
"171188",-75.5,45,61,61,135,8.33,0.834
"APA12PACb",-79.3,41.6,114,114,168,9.16,0.846
"BV",-85.9,35.9,136,136,157,8.41,0.835
"BVT",-73,44.4,21,21,101,8.05,0.818
"BVTGMVT2",-72.7,44,33,33,126,8.74,0.841
"CNF",-88.6,45.5,27,27,86,6.7,0.774
"FKN",-79.4,38.6,28,28,121,8.73,0.837
"GMVT1",-72.6,43,21,21,105,8.31,0.815
"MC",-86.1,37.2,61,61,155,9.31,0.851
"OZ12",-91.3,37.1,121,121,165,8.74,0.83
"SFNF12",-90.7,34.6,30,30,117,8.34,0.798
"WHWI",-88.8,42.8,39,39,94,6.47,0.751
"WWI",-89.1,44.5,18,18,83,6.8,0.757
"VSH123",-78.5,38.4,22,22,121,9.23,0.839
"","Region","Mean Longitude","Mean Latitude","Distance to Range Edge (km)","Number of Individuals","MLG","Number of Alleles","Allelic Richness","Expected Heterozygosity"
"1","New Brunswick",-66.1,46.6,95.8,92,91,130,7.51,0.799
"2","New Brunswick",-67.7,46.7,110,24,24,112,8.51,0.839
"3","New Brunswick",-65.6,45.7,161,20,20,90,7.36,0.78
"4","New Brunswick",-67.7,46.1,168,110,109,138,8.07,0.834
"5","New Brunswick",-66.4,45.9,168,112,112,151,8.49,0.826
"6","New Brunswick",-66.7,46,160,102,102,146,8.32,0.838
"7","New Brunswick",-78.5,44.6,285,35,35,135,9.41,0.857
"8","Ontario",-77.1,45.4,180,55,55,151,9.22,0.857
"9","Quebec",-79.4,44.1,359,61,61,141,8.53,0.837
"10","Ontario",-80.1,44,373,227,225,152,8.03,0.829
"11","Ontario",-75.5,45,257,126,126,148,8.34,0.834
"12","Quebec",-79.3,41.6,517,114,114,170,9.19,0.846
"13","United States",-85.9,35.9,451,136,136,159,8.42,0.835
"14","United States",-73,44.4,316,21,21,101,8.05,0.818
"15","United States",-72.7,44,273,33,33,126,8.74,0.841
"16","United States",-88.6,45.5,186,27,27,86,6.7,0.774
"17","United States",-79.4,38.6,353,28,28,123,8.8,0.838
"18","United States",-72.6,43,237,21,21,105,8.31,0.815
"19","United States",-86.1,37.2,573,61,61,155,9.31,0.851
"20","United States",-91.3,37.1,328,121,121,167,8.76,0.83
"21","United States",-90.7,34.6,278,30,30,118,8.37,0.798
"22","United States",-88.8,42.8,454,39,39,94,6.47,0.751
"23","United States",-89.1,44.5,291,18,18,84,6.88,0.758
"24","United States",-78.5,38.4,274,22,22,121,9.23,0.839

0 comments on commit 409ad08

Please sign in to comment.