Subset (copy) of a bigSNP, also stored on disk.

snp_subset(
  x,
  ind.row = rows_along(x$fam),
  ind.col = rows_along(x$map),
  backingfile = NULL
)

# S3 method for bigSNP
subset(
  x,
  ind.row = rows_along(x$fam),
  ind.col = rows_along(x$map),
  backingfile = NULL,
  ...
)

Arguments

x

A bigSNP.

ind.row

Indices of the rows (individuals) to keep. Negative indices can be used to exclude row indices. Default: keep them all.

ind.col

Indices of the columns (SNPs) to keep. Negative indices can be used to exclude column indices. Default: keep them all.

backingfile

Prefix of the two new files created (".bk" and ".rds"). By default, it is automatically determined by appending "_sub" and a number to the prefix of the input bigSNP backing files.

...

Not used.

Value

The path to the RDS file that stores the bigSNP object.

See also

Examples

str(test <- snp_attachExtdata())
#> List of 3
#>  $ genotypes:Reference class 'FBM.code256' [package "bigstatsr"] with 16 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\\RtmpoXbdzU\\file352843c79ff.bk"
#>   ..$ is_read_only: logi FALSE
#>   ..$ address     :<externalptr> 
#>   ..$ address_rw  :<externalptr> 
#>   ..$ bk          : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff.bk"
#>   ..$ rds         : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff.rds"
#>   ..$ is_saved    : logi TRUE
#>   ..$ type_chr    : chr "unsigned char"
#>   ..$ type_size   : int 1
#>   ..$ file_size   : num 2348214
#>   ..$ 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#FBM, show#envRefClass
#>  $ 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"

# keep only first 50 samples and SNPs
rdsfile <- snp_subset(test, ind.row = 1:50, ind.col = 1:50)
str(snp_attach(rdsfile))
#> List of 3
#>  $ genotypes:Reference class 'FBM.code256' [package "bigstatsr"] with 16 fields
#>   ..$ extptr      :<externalptr> 
#>   ..$ extptr_rw   :<externalptr> 
#>   ..$ nrow        : int 50
#>   ..$ ncol        : int 50
#>   ..$ type        : Named int 1
#>   .. ..- attr(*, "names")= chr "unsigned char"
#>   ..$ backingfile : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff_sub1.bk"
#>   ..$ is_read_only: logi FALSE
#>   ..$ address     :<externalptr> 
#>   ..$ address_rw  :<externalptr> 
#>   ..$ bk          : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff_sub1.bk"
#>   ..$ rds         : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff_sub1.rds"
#>   ..$ is_saved    : logi TRUE
#>   ..$ type_chr    : chr "unsigned char"
#>   ..$ type_size   : int 1
#>   ..$ file_size   : num 2500
#>   ..$ 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#FBM, show#envRefClass
#>  $ fam      :'data.frame':	50 obs. of  6 variables:
#>   ..$ family.ID  : chr [1:50] "POP1" "POP1" "POP1" "POP1" ...
#>   ..$ sample.ID  : chr [1:50] "IND0" "IND1" "IND2" "IND3" ...
#>   ..$ paternal.ID: int [1:50] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ maternal.ID: int [1:50] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ sex        : int [1:50] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ affection  : int [1:50] 1 1 2 1 1 1 1 1 1 1 ...
#>  $ map      :'data.frame':	50 obs. of  6 variables:
#>   ..$ chromosome  : int [1:50] 1 1 1 1 1 1 1 1 1 1 ...
#>   ..$ marker.ID   : chr [1:50] "SNP0" "SNP1" "SNP2" "SNP3" ...
#>   ..$ genetic.dist: int [1:50] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ physical.pos: int [1:50] 112 1098 2089 3107 4091 5091 6107 7103 8090 9074 ...
#>   ..$ allele1     : chr [1:50] "A" "T" "T" "T" ...
#>   ..$ allele2     : chr [1:50] "T" "A" "A" "A" ...
#>  - attr(*, "class")= chr "bigSNP"

# remove only first 50 samples and SNPs
rdsfile2 <- snp_subset(test, ind.row = -(1:50), ind.col = -(1:50))
str(snp_attach(rdsfile2))
#> List of 3
#>  $ genotypes:Reference class 'FBM.code256' [package "bigstatsr"] with 16 fields
#>   ..$ extptr      :<externalptr> 
#>   ..$ extptr_rw   :<externalptr> 
#>   ..$ nrow        : int 467
#>   ..$ ncol        : int 4492
#>   ..$ type        : Named int 1
#>   .. ..- attr(*, "names")= chr "unsigned char"
#>   ..$ backingfile : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff_sub2.bk"
#>   ..$ is_read_only: logi FALSE
#>   ..$ address     :<externalptr> 
#>   ..$ address_rw  :<externalptr> 
#>   ..$ bk          : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff_sub2.bk"
#>   ..$ rds         : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\RtmpoXbdzU\\file352843c79ff_sub2.rds"
#>   ..$ is_saved    : logi TRUE
#>   ..$ type_chr    : chr "unsigned char"
#>   ..$ type_size   : int 1
#>   ..$ file_size   : num 2097764
#>   ..$ 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#FBM, show#envRefClass
#>  $ fam      :'data.frame':	467 obs. of  6 variables:
#>   ..$ family.ID  : chr [1:467] "POP2" "POP2" "POP2" "POP2" ...
#>   ..$ sample.ID  : chr [1:467] "IND50" "IND51" "IND52" "IND53" ...
#>   ..$ paternal.ID: int [1:467] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ maternal.ID: int [1:467] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ sex        : int [1:467] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ affection  : int [1:467] 1 1 2 1 1 1 1 1 1 2 ...
#>  $ map      :'data.frame':	4492 obs. of  6 variables:
#>   ..$ chromosome  : int [1:4492] 1 1 1 1 1 1 1 1 1 1 ...
#>   ..$ marker.ID   : chr [1:4492] "SNP50" "SNP51" "SNP52" "SNP53" ...
#>   ..$ genetic.dist: int [1:4492] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ physical.pos: int [1:4492] 50100 51109 52101 53106 54101 55097 56103 57110 58101 59088 ...
#>   ..$ allele1     : chr [1:4492] "A" "A" "A" "T" ...
#>   ..$ allele2     : chr [1:4492] "T" "T" "T" "A" ...
#>  - attr(*, "class")= chr "bigSNP"