GenomicsBootCamp

finalReportToPed

Apr 13th, 2021
2,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.05 KB | None | 0 0
  1. #########################
  2. # Transform final report to PLINK files
  3. #########################
  4. # Note: This is *one* of the possible solutions
  5. #       Any other way could be used that creates the same file structure
  6. #########################
  7.  
  8. # Clear workspace
  9. rm(list = ls())
  10. # Set working directory
  11. setwd("d:/analysis/2020_GenomicsBootCamp_Demo/")
  12. #load packages
  13. library(tidyverse)
  14.  
  15. # read in final report file
  16. #
  17. # base R - puts . in column names, instead of spaces
  18. #finalReport <- read.csv("finalReportExample.csv", skip = 9, header = T)
  19. #
  20. # tidyverse - keeps spaces in column names and these are between single quotation marks 'column Name'  
  21. finalReport <-  read_delim("finalReportExample.csv", delim = ",", skip = 9, col_names = T)  
  22.  
  23. ###############################
  24. # Your goal is to create lgen, fam and map files
  25. # Some information might be missing in the final report, so you need to replace them
  26. ###############################
  27. # Scenario 1 - You have all the info in the Final Report - Jackpot!
  28. ###############################
  29.  
  30.  
  31. # Fam file
  32. finalReport %>%
  33.   distinct(`Sample Name`) %>%
  34.   mutate(FID = "BTAU", sire = 0, dam = 0, sex = 0, phenotype = -9) %>%
  35.   relocate(`Sample Name`, .after = FID) %>%
  36.   write_delim("GenomicsBootCamp.fam", col_names = F)
  37.  
  38. # Lgen file
  39. finalReport %>%
  40.   mutate(FID = "BTAU") %>%
  41.   select(FID, `Sample Name`, `SNP Name`, `Allele1 - AB`, `Allele2 - AB`) %>%
  42.   write_delim("GenomicsBootCamp.lgen", col_names = F)
  43.  
  44. # Map file
  45. finalReport %>%
  46.   distinct(`SNP Name`, .keep_all = TRUE) %>%
  47.   mutate(morgan = 0) %>%
  48.   dplyr::select(Chr, `SNP Name`, morgan, Position) %>%
  49.   write_delim("GenomicsBootCamp.map", col_names = F)
  50.  
  51. # change to ped file with PLINK
  52. system("plink --cow --nonfounders --allow-no-sex --lfile GenomicsBootCamp --missing-genotype - --output-missing-genotype 0 --recode --out BosTaurus")
  53.  
  54. ###############################
  55. # Scenario 2 - SNP coordinates (chromosome and position) are missing from the final report - common occurrentce
  56. ###############################
  57. # Fam file
  58. finalReport %>%
  59.   distinct(`Sample Name`) %>%
  60.   mutate(FID = "BTAU", sire = 0, dam = 0, sex = 0, phenotype = -9) %>%
  61.   relocate(`Sample Name`, .after = FID) %>%
  62.   write_delim("GenomicsBootCamp_annon.fam", col_names = F)
  63.  
  64. # Lgen file
  65. finalReport %>%
  66.   mutate(FID = "BTAU") %>%
  67.   select(FID, `Sample Name`, `SNP Name`, `Allele1 - AB`, `Allele2 - AB`) %>%
  68.   write_delim("GenomicsBootCamp_annon.lgen", col_names = F)
  69.  
  70. # Map file - chr and bpPosition not available - tmp values for now
  71. finalReport %>%
  72.   distinct(`SNP Name`) %>%
  73.   mutate(chr = 0, morgan = 0, bpPosition = 0) %>%
  74.   relocate(`SNP Name`, .after = chr) %>%
  75.   write_delim("GenomicsBootCamp_annon.map", col_names = F)
  76.  
  77. # Change to ped file with PLINK
  78. system("plink --cow --nonfounders --allow-no-sex --lfile GenomicsBootCamp_annon --missing-genotype - --output-missing-genotype 0 --recode --out BosTaurus_annon")
  79.  
  80. # Proceed with updating map files, as described in the "Update genomic map positions with PLINK"
  81. #   on the Genomics Boot Camp YouTube channel
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment