Question on 'gdsSubset' function
2
0
Entering edit mode
@yasuhitonannya-14257
Last seen 7.1 years ago

I tried "GWASTools" R package, and I would be happy if you help me out of a problem.

 

When I tried 'gdsSubset' function, an error occurred with the following message;

 "gds nodegenotypemust have 'snp.order' or 'sample.order' as an attribute".

 

My question is how to put  'snp.order' or 'sample.order' attribute to a 'gds' substance. 

The following is the sample code I am using.

 

 

library(gdsfmt)

 

# construct gds file and put data

gfile<-createfn.gds("test.gds")

gen_node<-add.gdsn(gfile, "genotype", storage="bit2", valdim=c(20, 10)) #20 snps, 10 scans=samples

add.gdsn(gfile, "snp.id", val=c(1:20))

add.gdsn(gfile, "sample.id", val=c(1:10))

add.gdsn(gfile, "snp.chromosome", val=c(1:20))

add.gdsn(gfile, "snp.position", val=c(1:20)*100)

write.gdsn(gen_node, matrix(rep(c(0:3),50), nrow=20), start=c(1,1), count=(c(20,10)))

closefn.gds(gfile)

 

 

# read gds file and subset the file

library(GWASTools)

gds <- GdsGenotypeReader("test.gds", "snp,scan")

 

 

sub.file<- tempfile()

close(gds)

 

gdsSubset("test.gds", sub.file, sample.include=c(1:5))

# HERE! error occures! saying...

#Error in gdsSubset("test.gds", sub.file, sample.include = c(1:5)) :

 #gds nodegenotypemust have 'snp.order' or 'sample.order' as an attribute

GWASTools • 1.7k views
ADD COMMENT
0
Entering edit mode
@stephanie-m-gogarten-5121
Last seen 4 months ago
University of Washington

You can use put.attr.gdsn to define the genotype node as "snp.order" (snp x sample) or "sample.order" (sample x snp).

library(gdsfmt)
gfile <- createfn.gds("test.gds")
gen_node <- add.gdsn(gfile, "genotype", storage="bit2", valdim=c(20, 10)) #20 snps, 10 scans=samples
put.attr.gdsn(gen_node, "snp.order")
add.gdsn(gfile, "snp.id", val=c(1:20))
add.gdsn(gfile, "sample.id", val=c(1:10))
add.gdsn(gfile, "snp.chromosome", val=c(1:20))
add.gdsn(gfile, "snp.position", val=c(1:20)*100)
write.gdsn(gen_node, matrix(rep(c(0:3),50), nrow=20), start=c(1,1), count=(c(20,10)))
closefn.gds(gfile)

library(GWASTools)
(gds <- GdsGenotypeReader("test.gds"))
close(gds)

sub.file <- tempfile()
gdsSubset("test.gds", sub.file, sample.include=c(1:5))
(gds <- GdsGenotypeReader(sub.file))
close(gds)
unlink(c(sub.file, "test.gds"))
ADD COMMENT
0
Entering edit mode
@yasuhitonannya-14257
Last seen 7.1 years ago

Thanks!

It worked!

ADD COMMENT

Login before adding your answer.

Traffic: 568 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6