Saves genotype and map data from an SNPDataLong object in PLINK format (.ped/.map and optionally binary files).

savePlink(
  object,
  path,
  name = "plink_data",
  run_plink = TRUE,
  chunk_size = 1000,
  extra_args = NULL
)

Arguments

object

An object of class SNPDataLong.

path

Character. Directory where files will be saved. Must be supplied by the caller (e.g. a folder inside tempdir() for examples).

name

Character. Base name for PLINK output files.

Logical. If TRUE (default), runs PLINK1 to convert to binary files. If FALSE, only .ped and .map files are saved.

chunk_size

Integer. Number of individuals per chunk for writing .ped file (default: 1000).

extra_args

Character vector. Extra arguments appended verbatim to the PLINK command line when run_plink = TRUE. Useful for non-human data; e.g. "--chr-set 29" makes PLINK treat autosomes 1-29 correctly for cattle instead of reading 23-26 as human X/Y/XY/MT. Default is NULL.

Value

No return value, called for side effects. Files (.ped/.map, and .bed/.bim/.fam when run_plink = TRUE) are written under path.

Examples

# \donttest{
set.seed(1)
raw_mat <- matrix(as.raw(sample(1:3, 100, TRUE)), nrow = 10, ncol = 10)
rownames(raw_mat) <- paste0("S", 1:10)
colnames(raw_mat) <- paste0("SNP", 1:10)
geno <- methods::new("SnpMatrix", raw_mat)
obj <- methods::new("SNPDataLong",
                    geno = geno,
                    map  = data.frame(Name = colnames(geno),
                                      Chromosome = 1,
                                      Position = 1:10),
                    path = tempfile(),
                    xref_path = "chip1")
savePlink(obj, path = tempdir(), name = "demo",
          run_plink = FALSE, chunk_size = 5)
#> 
#> +====================================+
#> |    Saving Files in Plink Format    |
#> +====================================+
#> Writing .ped file in chunks...
#>  Wrote individuals 1 to 5
#>  Wrote individuals 6 to 10
#> .ped file written: /tmp/Rtmp4EiFZk/demo.ped
#> Writing .map file...
#> .map file written: /tmp/Rtmp4EiFZk/demo.map
#> Skipping PLINK binary conversion as requested.
#> All done.
# }