GenomicsBootCamp

Compute Fst with PLINK

Apr 9th, 2021
2,785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.58 KB | None | 0 0
  1. ######################################
  2. # Fst                                #
  3. ######################################
  4. ## Fixation index for population differentiation (Fst)
  5. ## Fst will be computed with PLINK for each loci - Weir and Cockerham 1984
  6.  
  7. # Clear workspace
  8. rm(list = ls())
  9. # Set working directory - you need to adapt this...
  10. setwd("d:/analysis/2020_GenomicsBootCamp_Demo/")
  11.  
  12. #
  13. if (!require("tidyverse")) {
  14.   install.packages("tidyverse", dependencies = TRUE)
  15.   library(tidyverse)
  16. }
  17. if (!require("qqman")) {
  18.   install.packages("qqman", dependencies = TRUE)
  19.   library(qqman)
  20. }
  21.  
  22. ## POSSIBLE IMPROVEMENT CHALLANGE (feedback on completion welcomed in comments, but NOT the solution!)
  23. ## Run specifics
  24. #breed1 <- "ANG"
  25. #breed2 <- "GUM"
  26. #
  27. ## Create "breed1.txt" and "breed2.txt" files based on R input
  28. # write............... > "breed1.txt"
  29. # write............... > "breed2.txt"
  30.  
  31. #####################
  32. # Create subsets
  33. #####################
  34. # Breed 1
  35. system("plink --bfile ADAPTmap_genotypeTOP_20160222_full --cow --keep-fam breed1.txt --make-bed --out breed1")
  36. # Breed 2
  37. system("plink --bfile ADAPTmap_genotypeTOP_20160222_full --cow --keep-fam breed2.txt --make-bed --out breed2")
  38.  
  39. #####################
  40. # Breed specific QC
  41. #####################
  42. # breed 1 - no MAF! careful with HWE!
  43. system("plink --bfile breed1 --cow --autosome --geno 0.1 --mind 0.1 --hwe 0.000001 --nonfounders --allow-no-sex --make-bed --out breed1_QC")
  44.  
  45. # breed 2 - no MAF! careful with HWE!
  46. system("plink --bfile breed2 --cow --autosome --geno 0.1 --mind 0.1 --hwe 0.000001 --nonfounders --allow-no-sex --make-bed --out breed2_QC")
  47.  
  48. #####################
  49. # Merge both breeds
  50. #####################
  51. system("plink --bfile breed1_QC --cow --autosome --bmerge breed2_QC --nonfounders --allow-no-sex --make-bed --out inputForFst")
  52.  
  53.  
  54. system(paste0("plink --bfile breed1_QC --cow --autosome --bmerge breed2_QC ",
  55.               "--list-duplicate-vars ids-only suppress-first --nonfounders ",
  56.               "--allow-no-sex --make-bed --out inputForFst"))
  57.  
  58. system(paste0("plink --bfile inputForFst --cow --autosome ",
  59.               "--exclude inputForFst.dupvar --nonfounders ",
  60.               "--allow-no-sex --make-bed --out inputForFst_dupRemoved"))
  61.  
  62. #####################
  63. # compute Fst
  64. #####################
  65. system("plink --cow --bfile inputForFst_dupRemoved --fst --family --out FstResults")
  66.  
  67. #####################
  68. # load and visualize Fst results
  69. #####################
  70.  
  71. data <- read.delim("FstResults.fst") %>%
  72.   drop_na()
  73.  
  74. manhattan(data, chr = "CHR", bp = "POS", p = "FST", logp = F)
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment