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
)

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).

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/RtmpGZsf3p/demo.ped
#> Writing .map file...
#> .map file written: /tmp/RtmpGZsf3p/demo.map
#> Skipping PLINK binary conversion as requested.
#> All done.
# }