Functions to read bed/bim/fam files into a bigSNP.

snp_readBed(bedfile, backingfile = sub_bed(bedfile))

bedfile,
backingfile = sub_bed(bedfile),
ind.row = rows_along(obj.bed),
ind.col = cols_along(obj.bed),
ncores = 1
)

Arguments

bedfile Path to file with extension ".bed" to read. You need the corresponding ".bim" and ".fam" in the same directory. The path (without extension) for the backing files for the cache of the bigSNP object. Default takes the bedfile without the ".bed" extension. 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. Number of cores used. Default doesn't use parallelism. You may use nb_cores.

Value

The path to the RDS file that stores the bigSNP object. Note that this function creates one other file which stores the values of the Filebacked Big Matrix.
You shouldn't read from PLINK files more than once. Instead, use snp_attach to load the "bigSNP" object in any R session from backing files.

Details

For more information on these formats, please visit PLINK webpage. For other formats, please use PLINK to convert them in bedfiles, which require minimal space to store and are faster to read. For example, to convert from a VCF file, use the --vcf option. See snp_plinkQC.

Examples

(bedfile <- system.file("extdata", "example.bed", package = "bigsnpr"))
#> [1] "C:/Users/au639593/Documents/R/win-library/3.6/bigsnpr/extdata/example.bed"
# Reading the bedfile and storing the data in temporary directory
rds <- snp_readBed(bedfile, backingfile = tempfile())

test <- snp_attach(rds)

str(test)
#> List of 3
#>  $genotypes:Reference class 'FBM.code256' [package "bigstatsr"] with 15 fields #> ..$ extptr      :<externalptr>
#>   ..$extptr_rw :<externalptr> #> ..$ nrow        : int 517
#>   ..$ncol : int 4542 #> ..$ type        : Named int 1
#>   .. ..- attr(*, "names")= chr "unsigned char"
#>   ..$backingfile : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmp4etVds\\file427479d27ff5.bk" #> ..$ is_read_only: logi FALSE
#>   ..$address :<externalptr> #> ..$ address_rw  :<externalptr>
#>   ..$bk : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmp4etVds\\file427479d27ff5.bk" #> ..$ rds         : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmp4etVds\\file427479d27ff5.rds"
#>   ..$is_saved : logi TRUE #> ..$ type_chr    : chr "unsigned char"
#>   ..$type_size : int 1 #> ..$ code256     : num [1:256] 0 1 2 NA NA NA NA NA NA NA ...
#>   ..and 26 methods, of which 12 are  possibly relevant:
#>   ..  add_columns, as.FBM, bm, bm.desc, check_dimensions,
#>   ..  check_write_permissions, copy#envRefClass, initialize, initialize#FBM,
#>   ..  save, show#envRefClass, show#FBM
#>  $fam :'data.frame': 517 obs. of 6 variables: #> ..$ family.ID  : chr [1:517] "POP1" "POP1" "POP1" "POP1" ...
#>   ..$sample.ID : chr [1:517] "IND0" "IND1" "IND2" "IND3" ... #> ..$ paternal.ID: int [1:517] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$maternal.ID: int [1:517] 0 0 0 0 0 0 0 0 0 0 ... #> ..$ sex        : int [1:517] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$affection : int [1:517] 1 1 2 1 1 1 1 1 1 1 ... #>$ map      :'data.frame':	4542 obs. of  6 variables:
#>   ..$chromosome : int [1:4542] 1 1 1 1 1 1 1 1 1 1 ... #> ..$ marker.ID   : chr [1:4542] "SNP0" "SNP1" "SNP2" "SNP3" ...
#>   ..$genetic.dist: int [1:4542] 0 0 0 0 0 0 0 0 0 0 ... #> ..$ physical.pos: int [1:4542] 112 1098 2089 3107 4091 5091 6107 7103 8090 9074 ...
#>   ..$allele1 : chr [1:4542] "A" "T" "T" "T" ... #> ..$ allele2     : chr [1:4542] "T" "A" "A" "A" ...
#>  - attr(*, "class")= chr "bigSNP"dim(G <- test\$genotypes)
#> [1]  517 4542G[1:8, 1:8]
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,]    0    0    2    0    1    1    0    2
#> [2,]    1    0    1    0    0    1    0    2
#> [3,]    0    1    1    0    2    1    0    2
#> [4,]    0    0    2    0    2    1    0    2
#> [5,]    1    0    0    0    2    2    1    0
#> [6,]    0    1    0    0    2    1    0    0
#> [7,]    0    1    1    0    2    2    1    1
#> [8,]    1    0    1    1    1    1    0    1