SOLVED: how to change SnpMatrix in to numeric
1
1
Entering edit mode
8.4 years ago
zwang10 ▴ 30

I use read.plink from package snpStats. I use following to read bed file, and I want to get the 0,1,2 matrix.

GENOTYPE=read.plink("chr22_1",na.strings = "NA")

Then, from the manuals, I know there is a "genotypes" value of GNEOTYPE, which is an object of class "SnpMatrix". And I got this

> genotype$genotypes
A SnpMatrix with  1497 rows and  6 columns
Row names:  ALS5085249 ... ALS5227466 
Col names:  rs62224609 ... rs62224618

Can someone tell me how to change it into 0,1,2 matrix?

My work, I tried to use

    coerce(genotype$genotypes,to="numeric")

And I got something like this, which is not numeric.

           rs62224609 rs80167676 rs3013006 rs9604721 rs117246541 rs62224618
ALS5085249 "B/B"      "B/B"      "B/B"     "B/B"     "B/B"       "B/B"     
ALS5085250 "B/B"      "B/B"      "A/B"     "B/B"     "B/B"       "B/B"     
ALS5085251 "A/B"      "A/B"      "B/B"     "B/B"     "A/B"       "A/B"     
ALS5085252 "B/B"      "B/B"      "A/B"     "B/B"     "B/B"       "B/B"     
ALS5085253 "B/B"      "B/B"      "B/B"     "B/B"     "B/B"       "B/B"     
ALS5085254 "A/B"      "B/B"      "A/B"     "B/B"     "B/B"       "A/B"     
Warning message:
In coerce(genotype$genotypes, to = "numeric") :
  direct use of coerce() is deprecated:  use as(from, class(to)) instead
R snpmatrix • 6.3k views
ADD COMMENT
0
Entering edit mode

If this is solved, could you post your solution please

ADD REPLY
0
Entering edit mode
6.8 years ago

Use the function indicated in the warning message:

as(genotype$genotypes, to="numeric")

the coerce function is deprecated.

ADD COMMENT

Login before adding your answer.

Traffic: 1611 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