#=============================================================================================================# # # Script created by Angelica Cuevas # # Study published in Molecular Ecology : # Cite as : Cuevas et al., 2020. Intraspecific genomic variation and local adaptation in a young hybrid species. Molecular Ecology # # # This script: this script find recombination window on identified FST loci # # Usage notes: run line by line #=============================================================================================================# # script to find recombination window working.directory<-setwd("/path/to/your/working/directory/files.and.scripts") working.directory rm(list = ls()) install.packages('tidyverse') library(tidyverse) ###### Recombination rate v.s FST ##### recomb <- read_csv("./recomb_int.csv") head(recomb) dim(recomb) #-------------------------------------------------------------------------# #---------------------- from individual species vcf ----------------------# #-------------------------------------------------------------------------# # from individual species vcf # FST.House_House_MF.0.01_mod.weir.fst # SNPs=6505 # FST.Ita.global_Ita.only_MF.0.02_NORimini_mod.weir.fst # SNPs=4388 # FST.Spanish_Spanish_MF.0.01_mod.weir.fst # SNPs=1321 #### SPANISH Global Fst #### Spanish_fst<-read_delim("FST.Spanish_Spanish_MF.0.01_mod.weir.fst", delim = " ") head(Spanish_fst) dim(Spanish_fst) # 1320 SNPs # rename colnames(Spanish_fst) <- tolower(names(Spanish_fst)) head(Spanish_fst) Spanish_fst <- filter(Spanish_fst, chrom != "chrZ" & chrom != "chrLGE22" ) dim(Spanish_fst) # 1307 SNPs # loop through Spa.fst_recomb <- sapply(unique(Spanish_fst$chrom), function(y){ x <- filter(Spanish_fst, chrom == y) z <- filter(recomb, chr == y) # get var target_pos <- x %>% .$pos window_mid <- z %>% .$mid rr <- sapply(1:length(target_pos), function(w) { index <- which.min(abs(window_mid - target_pos[w])) slice(z, index) %>% .$male_int_rate }) x$recomb <- rr x }, simplify = F) # head(Spa.fst_recomb) # collapse Spa.fst_recomb <- do.call(rbind, Spa.fst_recomb) head(Spa.fst_recomb) # write out write_delim(Spa.fst_recomb, "fst_recomb_Spanish.from.Spanish_MF.tsv", delim = "\t") #### HOUSE Global Fst #### House_fst<-read_delim("FST.House_House_MF.0.01_mod.weir.fst", delim = " ") head(House_fst) dim(House_fst) # 6520 SNPs # rename colnames(House_fst) <- tolower(names(House_fst)) head(House_fst) House_fst <- filter(House_fst, chrom != "chrZ" & chrom != "chrLGE22" ) dim(House_fst) # 6447 SNPs # loop through Hou.fst_recomb <- sapply(unique(House_fst$chrom), function(y){ x <- filter(House_fst, chrom == y) z <- filter(recomb, chr == y) # get var target_pos <- x %>% .$pos window_mid <- z %>% .$mid rr <- sapply(1:length(target_pos), function(w) { index <- which.min(abs(window_mid - target_pos[w])) slice(z, index) %>% .$male_int_rate }) x$recomb <- rr x }, simplify = F) head(Hou.fst_recomb) # collapse Hou.fst_recomb <- do.call(rbind, Hou.fst_recomb) head(Hou.fst_recomb) # write out write_delim(Hou.fst_recomb, "fst_recomb_House.from.House_MF.tsv", delim = "\t") a<-lm(Hou.fst_recomb$fst_global.house~Hou.fst_recomb$recomb) # a<-lm(Hou.fst_recomb$fst_global.house~log10(Hou.fst_recomb$recomb)) summary(a) #### ITALIAN Global Fst #### Ita_fst<-read_delim("FST.Ita.global_Ita.only_MF.0.02_NORimini_mod.weir.fst", delim = " ") head(Ita_fst) dim(Ita_fst) # 4387 SNPs # rename colnames(Ita_fst) <- tolower(names(Ita_fst)) head(Ita_fst) Ita_fst <- filter(Ita_fst, chrom != "chrZ" & chrom != "chrLGE22" ) dim(Ita_fst) # 4361 SNPs # loop through Ita.fst_recomb <- sapply(unique(Ita_fst$chrom), function(y){ x <- filter(Ita_fst, chrom == y) z <- filter(recomb, chr == y) # get var target_pos <- x %>% .$pos window_mid <- z %>% .$mid rr <- sapply(1:length(target_pos), function(w) { index <- which.min(abs(window_mid - target_pos[w])) slice(z, index) %>% .$male_int_rate }) x$recomb <- rr x }, simplify = F) head(Ita.fst_recomb) # collapse Ita.fst_recomb <- do.call(rbind, Ita.fst_recomb) head(Ita.fst_recomb) # write out write_delim(Ita.fst_recomb, "fst_recomb_Italian.from.Ita.only_MF.tsv", delim = "\t") b<-lm(Ita.fst_recomb$fst_global.italian~Ita.fst_recomb$recomb) # b<-lm(Ita.fst_recomb$weir_and_cockerham_fst~log10(Ita.fst_recomb$recomb)) summary(b) ###### # # # ######---------------------------------------------------------------------------------------------------------------------------------- # Cite as : Cuevas et al., 2020. Intraspecific genomic variation and local adaptation in a young hybrid species. Molecular Ecology ######---------------------------------------------------------------------------------------------------------------------------------- # # # #======================================================================================================================================================================================###### ############################################################################################################################################################################################# #======================================================================================================================================================================================######