GenomicsBootCamp

Change PLINK to 23andMe format

May 26th, 2021
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.10 KB | None | 0 0
  1. # Transform PLINK to 23andMe-format
  2.  
  3. # Clear workspace
  4. rm(list = ls())
  5. # Set working directory
  6. setwd("d:/analysis/2020_GenomicsBootCamp_Demo/")
  7. #load packages
  8. library(tidyverse)
  9.  
  10. # prepare data
  11. system("plink --file hereford --cow --chr 1 --make-bed --out humanDataForSure")
  12.  
  13. ###
  14. # single individual from PLINK to 23andMe-format
  15. ###
  16. # select individual + change format
  17. system("plink --bfile humanDataForSure --keep selectedIndividual.txt --recode 23 --out recoded_23andMe")
  18.  
  19.  
  20. ###
  21. # all individuals from PLINK to 23andMe-format
  22. ###
  23.  
  24. individuals <- read_delim("humanDataForSure.fam", delim = " ", col_names = F)
  25.  
  26. # cycle through each individual in the data file
  27. for (i in 1:nrow(individuals)) {
  28.  
  29.   #write one individual at the time to a file
  30.   currentInd <- individuals %>%
  31.     slice(i) %>%
  32.     write_delim("selectedIndividual.txt", col_names = F) %>%
  33.     select(X2)
  34.  
  35.   # select this individual only and write out into a specific file
  36.   system(str_c("plink --bfile humanDataForSure --keep selectedIndividual.txt --recode 23 ",
  37.                "--out recoded_23andMe_",currentInd))
  38.  
  39. }
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment