# SeqMiner Quick Guide

SeqMiner(former name, vcf2geno) is a R package that helps you efficiently processing sequencing data in the VCF format.

SeqMiner requires VCF files indexed by Tabix. To use its gene based extraction, VCF need to be annotated by SeqAnno We have provided an examplar VCF file in this package. You can use the following command to find its location on your computer:

    library(seqminer)
    fileName = system.file("vcf/all.anno.filtered.extract.vcf.gz", package = "seqminer")
    fileName

    ## [1] "/Library/Frameworks/R.framework/Versions/2.15/Resources/library/seqminer/vcf/all.anno.filtered.extract.vcf.gz"

This manual demonstrates a quick guide on how to use SeqMiner.

## Extract gentoype matrix from VCF file

Extract genotype matrix from 1:196621007-196716634, and only focused on Nonsynonymous variants:

    cfh <- readVCFToMatrixByRange(fileName, "1:196621007-196716634", "Nonsynonymous")

    ## Regcomp OK

    cfh

    ##             NA12286 NA12341 NA12342
    ## 1:196642233       1       2       0
    ## 1:196659237       0       2       1

In this example, we use the fileName for the VCF file path, 1:196621007-196716634 for the genomic range, and Nonsynonymous for the variants type. Extraction results are stored in the variable cfh. Its row names are variant positions, while column names are sample IDs.

Similarly, we can extract genotype matrix per gene:

    geneFile = system.file("vcf/refFlat_hg19_6col.txt.gz", package = "seqminer")
    geneFile

    ## [1] "/Library/Frameworks/R.framework/Versions/2.15/Resources/library/seqminer/vcf/refFlat_hg19_6col.txt.gz"

    cfh <- readVCFToMatrixByGene(fileName, geneFile, "CFH", "Synonymous")

    ## Regcomp OK

    cfh

    ##             NA12286 NA12341 NA12342
    ## 1:196654324       1       2       1
    ## 1:196682947       2       2       1
    ## 1:196654324       1       2       1

Note here we require a gene file in refFlat format. We have prepared several gene definition files in refFlat format using NCBI human build 37. From this website, you can obtain these resources files.

The supported annotation variant type are:

    # large strucutre variant
    StructuralVariation

    # indels
    Stop_Gain
    Stop_Loss
    Start_Gain
    Start_Loss
    Frameshift        /* Indel length is not divisible by 3 */
    CodonGain         /* Insertion length is divisible by 3 */
    CodonLoss         /* Deletion length is divisible by 3 */
    CodonRegion       /* Just say the variant is in the Coding Region used in Structrual Varition*/
    Insertion
    Deletion

    # single variants
    Nonsynonymous
    Synonymous
    Essential_Splice_Site
    Normal_Splice_Site
    Utr5
    Utr3
    Exon
    Intron
    Upstream
    Downstream
    SNV
    Noncoding
    Monomorphic

## Extract arbitrary fields from VCF file

For advanced data extraction from VCF file, there are two functions: readVCFToListByRange and readVCFToListByGene. Their usage are similar to the previous two functions: readVCFToMatrixByRange and readVCFToMatrixByGene but the results are organized in list.

    result <- readVCFToListByGene(fileName, geneFile, "CFH", "Synonymous", c("CHROM",
        "ID"), c("AC", "AN"), "GT")

    ## extractStringArray: [1] AC
    ## extractStringArray: [2] AN
    ## extractStringArray: [1] GT
    ## Regcomp OK
    ## Dump 9 elements:
    ## s[0] = "0/1"
    ## s[1] = "1/1"
    ## s[2] = "0/1"
    ## s[3] = "1/1"
    ## s[4] = "1/1"
    ## s[5] = "0/1"
    ## s[6] = "0/1"
    ## s[7] = "1/1"
    ## s[8] = "0/1"

    result

    ## $CHROM
    ## [1] "1" "1" "1"
    ##
    ## $ID
    ## [1] "." "." "."
    ##
    ## $AC
    ## [1] "4" "5" "4"
    ##
    ## $AN
    ## [1] "6" "6" "6"
    ##
    ## $GT
    ##      [,1]  [,2]  [,3]
    ## [1,] "0/1" "1/1" "0/1"
    ## [2,] "1/1" "1/1" "1/1"
    ## [3,] "0/1" "0/1" "0/1"
    ##
    ## $sampleId
    ## [1] "NA12286" "NA12341" "NA12342"

There are 7 parameters in readVCFToListByGene: 1. VCF file path 2. Gene definition file (refFlat foramt) 3. Character array of gene names (can be one gene or more than one gene names) 4. Annotation type 5. VCF field to extract (explain later) 6. VCF tags in the INFO field to extract (explain later) 7. VCF tags in the individual field to extract (explain later)

The last three parameter are closely related to VCF format. In the VCF data lines, there are 8 fixed fields per record: CHROM, POS, ID, REF, ALT, QUAL, FILTER, INFO. These field, as well as the FORMAT field can be specifed in the 5th parameter. For example, specify c(“CHROM”, “POS”) will extract the genomic position.

In the VCF INFO field, there may be information including variant depth (DP), variant allele counts (AC), total allele counts (AN). To extract those information, use the 6th paramter.

In the VCF genotype fileds, which are from the 10th column to the last column per record, it contains the individual level information. Mostly commonly used information are genotype (GT), genotype depth (GD) and genotype quality (GQ). To extract these, specify c(“GT”, “GD”, “GQ”) in the 7th parameter.

The extraction results are stored in result in our example. All values are characters for simplicity. The extraction results is a list, and it contains CHROM, ID, AC, AN, GT and sampleId. CHROM and ID are speicified in the 5th parameter; AC and AN are speicified by the 6th parameter; GT are specified in the last parameter. We also list sample IDs in the sampleId part.

## Applying rare-variant analysis

SeqMiner can greatly reduce your effort to process huge sequencing files in VCF format. That indicates your valuable time can be spared on investigating causal variants. Here we demonstrate how to apply SKAT method to study CFH gene. The genotype file we used is extracted from 1000 Genomes Project. It contains 85 individuals in CEU population and the variants are all located in the CFH gene region. We will use simulated phenotype in this demonstration.

    # Extract genotype matrix
    vcf.1000g <- system.file("vcf/1000g.phase1.20110521.CFH.anno.vcf.gz", package = "seqminer")
    geneFile = system.file("vcf/refFlat_hg19_6col.txt.gz", package = "seqminer")
    geneName <- "CFH"
    cfh <- readVCFToMatrixByGene(vcf.1000g, geneFile, geneName, "Nonsynonymous")

    ## Regcomp OK

    dim(cfh)

    ## [1] 47 85

    # Simulation phenotype under the null model
    pheno <- rnorm(ncol(cfh))

    # Apply SKAT method
    library(SKAT)
    obj <- SKAT_Null_Model(pheno ~ 1, out_type = "C")
    SKAT(t(cfh), obj)$p.value

    ## Warning: 37 SNPs with either high missing rates or no-variation are
    ## excluded!

    ## Warning: Genotypes of some variants are not the number of minor alleles!

    ## [1] 0.2591

## Contact

SeqMiner is developed with joint effort from Xiaowei Zhan and Dajiang Liu. We welcome your questions and feedbacks.