snpStatsWriter

Chris Wallace // web // email

This is a package to write snpStats objects to disk in formats suitable for reading by snphap, phase, mach, IMPUTE, beagle, and (almost) anything else that expects a rectangular format.

We will load a small dataset included in the snpStats package

library(snpStatsWriter)
## Loading required package: snpStats
## Loading required package: survival
## Loading required package: splines
## Loading required package: Matrix
## Loading required package: colorspace
data(testdata, package = "snpStats")
A.small <- Autosomes[1:6, 1:10]
nsnps <- ncol(A.small)

and write it to disk in lots of formats.

snphap

f <- tempfile()
write.snphap(A.small, file = f)
## [1]  6 10
head(read.table(f, sep = "\t"))
##      X173760 X173761 X173762 X173767 X173769 X173770 X173772 X173774
## 1987     1 1     1 1     1 1     2 2     2 2     2 2     2 2     1 2
## 436      1 1     2 2     2 2     2 2     2 2     2 2     2 2     2 2
## 762      1 1     1 2     1 2     1 2     2 2     2 2     2 2     1 2
## 1199     1 1     1 2     1 2     1 1     2 2     2 2     2 2     2 2
## 1296     1 1     1 1     1 1     1 2     2 2     2 2     2 2     2 2
## 81       1 1     1 2     1 2     1 2     2 2     2 2     2 2     2 2
##      X173775 X173776
## 1987     1 1     1 1
## 436      1 1     1 1
## 762      1 1     1 1
## 1199     1 1     1 1
## 1296     1 1     1 1
## 81       1 2     1 1
unlink(f)

mach

pf <- tempfile()  ## pedigree file
mf <- tempfile()  ## marker file
write.mach(A.small, a1 = rep("1", nsnps), a2 = rep("2", nsnps), pedfile = pf, 
    mfile = mf)
## [1]  6 10
head(read.table(mf))
##   V1     V2
## 1  M 173760
## 2  M 173761
## 3  M 173762
## 4  M 173767
## 5  M 173769
## 6  M 173770
head(read.table(pf))
##     V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20
## 1 1987  1  0  0  M  1  1  1  1   1   1   2   2   2   2   2   2   2   2   1
## 2  436  1  0  0  M  1  1  2  2   2   2   2   2   2   2   2   2   2   2   2
## 3  762  1  0  0  M  1  1  1  2   1   2   1   2   2   2   2   2   2   2   1
## 4 1199  1  0  0  M  1  1  1  2   1   2   1   1   2   2   2   2   2   2   2
## 5 1296  1  0  0  M  1  1  1  1   1   1   1   2   2   2   2   2   2   2   2
## 6   81  1  0  0  M  1  1  1  2   1   2   1   2   2   2   2   2   2   2   2
##   V21 V22 V23 V24 V25
## 1   2   1   1   1   1
## 2   2   1   1   1   1
## 3   2   1   1   1   1
## 4   2   1   1   1   1
## 5   2   1   1   1   1
## 6   2   1   2   1   1
unlink(pf)
unlink(mf)

impute

pf <- tempfile()
write.impute(A.small, a1 = rep("1", nsnps), a2 = rep("2", nsnps), bp = 1:nsnps, 
    pedfile = pf)
## [1]  6 10
head(read.table(pf))
##     V1     V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19
## 1 SNP1 173760  1  1  2  1  0  0  1   0   0   1   0   0   1   0   0   1   0
## 2 SNP2 173761  2  1  2  1  0  0  0   0   1   0   1   0   0   1   0   1   0
## 3 SNP3 173762  3  1  2  1  0  0  0   0   1   0   1   0   0   1   0   1   0
## 4 SNP4 173767  4  1  2  0  0  1  0   0   1   0   1   0   1   0   0   0   1
## 5 SNP5 173769  5  1  2  0  0  1  0   0   1   0   0   1   0   0   1   0   0
## 6 SNP6 173770  6  1  2  0  0  1  0   0   1   0   0   1   0   0   1   0   0
##   V20 V21 V22 V23
## 1   0   1   0   0
## 2   0   0   1   0
## 3   0   0   1   0
## 4   0   0   1   0
## 5   1   0   0   1
## 6   1   0   0   1
unlink(pf)

beagle

gf <- tempfile()  ## genotype file
mf <- tempfile()  ## marker file
write.beagle(A.small, a1 = rep("1", nsnps), a2 = rep("2", nsnps), bp = 1:nsnps, 
    gfile = gf, mfile = mf)
## [1]  6 10
head(read.table(gf, header = TRUE))
##   I     id X1987 X1987.1 X436 X436.1 X762 X762.1 X1199 X1199.1 X1296
## 1 M 173760     1       1    1      1    1      1     1       1     1
## 2 M 173761     1       1    2      2    1      2     1       2     1
## 3 M 173762     1       1    2      2    1      2     1       2     1
## 4 M 173767     2       2    2      2    1      2     1       1     1
## 5 M 173769     2       2    2      2    2      2     2       2     2
## 6 M 173770     2       2    2      2    2      2     2       2     2
##   X1296.1 X81 X81.1
## 1       1   1     1
## 2       1   1     2
## 3       1   1     2
## 4       2   1     2
## 5       2   2     2
## 6       2   2     2
head(read.table(mf))
##       V1 V2 V3 V4
## 1 173760  1  1  2
## 2 173761  2  1  2
## 3 173762  3  1  2
## 4 173767  4  1  2
## 5 173769  5  1  2
## 6 173770  6  1  2
unlink(gf)
unlink(mf)

phase/fastPhase

NB phase input is a little different to most other formats!

f <- tempfile()
write.phase(A.small, file = f)
## [1]  6 10
head(scan(f, what = ""))
## [1] "6"          "10"         "SSSSSSSSSS" "#"          "1987"      
## [6] "1112222111"
unlink(f)