How to do it...

Finding phenotype and genotype associations with GWAS can be done using the following steps:

  1. Load in the libraries and get the VCF file:
library(VariantAnnotation)
library(rrBLUP)
set.seed(1234) vcf_file <- file.path(getwd(), "datasets", "ch2", "small_sample.vcf") vcf <- readVcf(vcf_file, "hg19")
  1. Extract the genotype, sample, and marker position information:
gts <- geno(vcf)$GT

samples <- samples(header(vcf))
markers <- rownames(gts)
chrom <- as.character(seqnames(rowRanges(vcf)))
pos <- as.numeric(start(rowRanges(vcf)))
  1. Create a custom function to convert VCF genotypes into the convention used by the GWAS function:
convert <- function(v){
  v <- gsub("0/0", 1, v)
  v <- gsub("0/1", 0, v)
  v <- gsub("1/0", 0, v)
  v <- gsub("1/1",-1, v)
  return(v)
}
  1. Call the function and convert the result into a numeric matrix:
gt_char<- apply(gts, convert, MARGIN = 2)

genotype_matrix <- matrix(as.numeric(gt_char), nrow(gt_char) )
colnames(genotype_matrix)<- samples
  1. Build a dataframe describing the variant:
variant_info <- data.frame(marker = markers,
                           chrom = chrom,
                           pos = pos)

  1. Build a combined variant/genotype dataframe:
genotypes <-  cbind(variant_info, as.data.frame(genotype_matrix))
genotypes
  1. Build a phenotype dataframe:
phenotypes <- data.frame(
  line = samples,
  score = rnorm(length(samples))
                         )

phenotypes
  1. Run GWAS:
GWAS(phenotypes, genotypes,plot=FALSE)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.56.251