012 コード化された SNP を列とし、人を行とするマトリックス「マット」があります。例えば:
> mat<-matrix(c("0","1","0","1","2","0","1","1","2"),3,byrow=T)
> rownames(mat)<-c("ID1","ID2","ID3")
> colnames(mat)<-c("rs123","rs333","rs9000")
> mat
rs123 rs333 rs9000
ID1 "0" "1" "0"
ID2 "1" "2" "0"
ID3 "1" "1" "2"
別のマトリックス「mat2」では、それぞれの対立遺伝子を 2 つの列 (すなわち、マイナー対立遺伝子とメジャー対立遺伝子) に、SNP を行として示しています。
> mat2<-matrix(c("A","T","C","T","T","G"),3,byrow=T)
> rownames(mat2)<-c("rs123","rs333","rs9000")
> colnames(mat2)<-c("Allele_A","Allele_B")
> mat2
Allele_A Allele_B
rs123 "A" "T"
rs333 "C" "T"
rs9000 "T" "G"
ここで、最初のマトリックスから 012 でコード化された SNP を 2 列に再コード化します。コードが 0 の場合は新しい列の両方でそれぞれの対立遺伝子 A になり、コードが 1 の場合は A/B になり、2 の場合は B/B になります。 . 私の例では、次のものを取得したいと思います。
> mat3<-matrix(c("A","C","T","A","T","T","A","T","T","T","T","T","A","C","G","T","T","G" ),3,byrow=T)
> rownames(mat3)<-c("ID1","ID2","ID3")
> colnames(mat3)<-c("rs123_1","rs333_1","rs9000_1","rs123_2","rs333_2","rs9000_2")
> mat3
rs123_1 rs333_1 rs9000_1 rs123_2 rs333_2 rs9000_2
ID1 "A" "C" "T" "A" "T" "T"
ID2 "A" "T" "T" "T" "T" "T"
ID3 "A" "C" "G" "T" "T" "G"
それを達成するのを手伝ってもらえますか? 前もって感謝します!