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

snp_readBed(bedfile, backingfile = sub_bed(bedfile))

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

Arguments

bedfile

Path to file with extension ".bed" to read. You need the corresponding ".bim" and ".fam" in the same directory.

backingfile

The path (without extension) for the backing files for the cache of the bigSNP object. Default takes the bedfile without the ".bed" extension.

ind.row

An optional vector of the row indices (individuals) that are used. If not specified, all rows are used.
Don't use negative indices.

ind.col

An optional vector of the column indices (SNPs) that are used. If not specified, all columns are used.
Don't use negative indices.

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] "/tmp/Rtmp6g6JP9/temp_libpath23c736204813/bigsnpr/extdata/example.bed"
# Reading the bedfile and storing the data in temporary directory rds <- snp_readBed(bedfile, backingfile = tempfile()) # Loading the data from backing files test <- snp_attach(rds) str(test)
#> List of 3 #> $ genotypes:Reference class 'FBM.code256' [package "bigstatsr"] with 10 fields #> ..$ extptr :<externalptr> #> ..$ nrow : int 517 #> ..$ ncol : int 4542 #> ..$ type : Named int 1 #> .. ..- attr(*, "names")= chr "unsigned char" #> ..$ backingfile: chr "/tmp/RtmpHMIGXH/file272e33782b45.bk" #> ..$ address :<externalptr> #> ..$ bk : chr "/tmp/RtmpHMIGXH/file272e33782b45.bk" #> ..$ rds : chr "/tmp/RtmpHMIGXH/file272e33782b45.rds" #> ..$ is_saved : logi TRUE #> ..$ code256 : num [1:256] 0 1 2 NA NA NA NA NA NA NA ... #> ..and 24 methods, of which 10 are possibly relevant: #> .. add_columns, as.FBM, bm, bm.desc, 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 4542
G[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