Last data update: 2014.03.03

R: Create a SNP genotype dataset from a matrix
snpgdsCreateGenoR Documentation

Create a SNP genotype dataset from a matrix

Description

To create a GDS file of genotypes from a matrix.

Usage

snpgdsCreateGeno(gds.fn, genmat, sample.id=NULL, snp.id=NULL, snp.rs.id=NULL,
    snp.chromosome=NULL, snp.position=NULL, snp.allele=NULL, snpfirstdim=TRUE,
    compress.annotation="ZIP_RA.max", compress.geno="", other.vars=NULL)

Arguments

gds.fn

the file name of gds

genmat

a matrix of genotypes

sample.id

the sample ids, which should be unique

snp.id

the SNP ids, which should be unique

snp.rs.id

the rs ids for SNPs, which can be not unique

snp.chromosome

the chromosome indices

snp.position

the SNP positions in basepair

snp.allele

the reference/non-reference alleles

snpfirstdim

if TRUE, genotypes are stored in the individual-major mode, (i.e, list all SNPs for the first individual, and then list all SNPs for the second individual, etc)

compress.annotation

the compression method for the variables except genotype

compress.geno

the compression method for the variable genotype

other.vars

a list object storing other variables

Details

There are possible values stored in the variable genmat: 0, 1, 2 and other values. “0” indicates two B alleles, “1” indicates one A allele and one B allele, “2” indicates two A alleles, and other values indicate a missing genotype.

If snpfirstdim is TRUE, then genmat should be “# of SNPs X # of samples”; if snpfirstdim is FALSE, then genmat should be “# of samples X # of SNPs”.

The typical variables specified in other.vars are “sample.annot” and “snp.annot”, which are data.frame objects.

Value

None.

Author(s)

Xiuwen Zheng

See Also

snpgdsCreateGenoSet, snpgdsCombineGeno

Examples

# load data
data(hapmap_geno)

# create a gds file
with(hapmap_geno, snpgdsCreateGeno("test.gds", genmat=genotype,
    sample.id=sample.id, snp.id=snp.id, snp.chromosome=snp.chromosome,
    snp.position=snp.position, snp.allele=snp.allele, snpfirstdim=TRUE))

# open the gds file
genofile <- snpgdsOpen("test.gds")

RV <- snpgdsPCA(genofile)
plot(RV$eigenvect[,2], RV$eigenvect[,1], xlab="PC 2", ylab="PC 1")

# close the file
snpgdsClose(genofile)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SNPRelate)
Loading required package: gdsfmt
SNPRelate -- supported by Streaming SIMD Extensions 2 (SSE2)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/SNPRelate/snpgdsCreateGeno.Rd_%03d_medium.png", width=480, height=480)
> ### Name: snpgdsCreateGeno
> ### Title: Create a SNP genotype dataset from a matrix
> ### Aliases: snpgdsCreateGeno
> ### Keywords: GDS GWAS
> 
> ### ** Examples
> 
> # load data
> data(hapmap_geno)
> 
> # create a gds file
> with(hapmap_geno, snpgdsCreateGeno("test.gds", genmat=genotype,
+     sample.id=sample.id, snp.id=snp.id, snp.chromosome=snp.chromosome,
+     snp.position=snp.position, snp.allele=snp.allele, snpfirstdim=TRUE))
> 
> # open the gds file
> genofile <- snpgdsOpen("test.gds")
> 
> RV <- snpgdsPCA(genofile)
Principal Component Analysis (PCA) on SNP genotypes:
Excluding 42 SNPs on non-autosomes
Excluding 0 SNP (monomorphic: TRUE, < MAF: NaN, or > missing rate: NaN)
Working space: 279 samples, 958 SNPs
	using 1 (CPU) core
PCA:	the sum of all selected genotypes (0, 1 and 2) = 264760
Wed Jul  6 05:34:32 2016    (internal increment: 1744)
 [>.................................................]  0%, ETC: NA     [==================================================] 100%, completed  
Wed Jul  6 05:34:32 2016    Begin (eigenvalues and eigenvectors)
Wed Jul  6 05:34:32 2016    Done.
> plot(RV$eigenvect[,2], RV$eigenvect[,1], xlab="PC 2", ylab="PC 1")
> 
> # close the file
> snpgdsClose(genofile)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>