Function to write bed/bim/fam files from a bigSNP.
This will use the slot code
rounded to write 0s, 1s, 2s or NAs.
snp_writeBed(x, bedfile, ind.row = rows_along(G), ind.col = cols_along(G))
A bigSNP.
Path to file with extension ".bed" to create.
An optional vector of the row indices (individuals) that
are used. If not specified, all rows are used.
Don't use negative indices.
An optional vector of the column indices (SNPs) that are used.
If not specified, all columns are used.
Don't use negative indices.
The input bedfile
path.
N <- 17
M <- 911
fake <- snp_fake(N, M)
G <- fake$genotypes
G[] <- sample(as.raw(0:3), size = length(G), replace = TRUE)
# Write the object as a bed/bim/fam object
tmp <- tempfile(fileext = ".bed")
bed <- snp_writeBed(fake, tmp)
# Read this new file for the first time
rds <- snp_readBed(bed, backingfile = tempfile())
# Attach object in R session
fake2 <- snp_attach(rds)
# Same content
all.equal(fake$genotypes[], fake2$genotypes[])
#> [1] TRUE
all.equal(fake$fam, fake2$fam)
#> [1] TRUE
all.equal(fake$map, fake2$map)
#> [1] TRUE
# Two different backingfiles
fake$genotypes$backingfile
#> [1] "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpITJXCm\\file5f8c40e25bfa.bk"
fake2$genotypes$backingfile
#> [1] "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpITJXCm\\file5f8c60e47fe2.bk"