Learn R Programming

LDheatmap (version 1.0-6)

vcfR2SnpMatrix: Extract genotype information from a vcfR object

Description

Convert a vcfR-class object into a list composed of genetic distances, subject IDs, and a SnpMatrix-class/XSnpMatrix-class object.

Usage

vcfR2SnpMatrix(obj, phased = NULL, subjects = NULL)

Arguments

obj

An instance or path of the vcfR-class object to be processed.

phased

If TRUE the output genotype data are in the form of a XSnpMatrix-class object. Otherwise, they are in the form of a SnpMatrix-class object. If it is unspecified, the phasing status will be determined by checking the first entry in the gt slot of the vcfR object. If the first entry is also missing, the value will be set to FALSE.

subjects

A character or factor containing subject IDs. If supplied, genotype info of only those subjects will be returned. This should be a subset of the sample IDs in the vcfR object.

Value

A list which contains the following components:

genetic.distances

A numeric vector of the reference positions of SNPs.

subjectID

A character vector of IDs of the subjects which the returned genotype data belong to.

data

An object of SnpMatrix-class/XSnpMatrix-class containing genotype data.

Details

In order to let vcfR2SnpMatrix function properly, the input vcfR-class object is expected to be generated from a valid VCF file which contains only biallelic SNPs and includes a GT section.

See Also

io_vcfR, SnpMatrix-class, XSnpMatrix-class

Examples

Run this code
# NOT RUN {
# Load the vcfR object -- requires vcfR
 if (requireNamespace("vcfR", quietly = TRUE)) {
   require(vcfR)
   data(vcfR_example)
   vcf <- vcf[8:12,]
   # Extract needed genotype information
   alist <- vcfR2SnpMatrix(vcf)

   # Draw a pairwise LD plot using the extracted data
   LDheatmap(alist$data, alist$genetic.distance)
 }

# }

Run the code above in your browser using DataLab