| Title: | Format Conversion between PLINK2 PGEN and GDS |
|---|---|
| Description: | Provides functions to convert files from the PLINK2 pgen format to SeqArray GDS, and from SeqArray GDS to the PLINK2 pgen format. |
| Authors: | Xiuwen Zheng [aut, cre] (ORCID: <https://orcid.org/0000-0002-1390-0708>) |
| Maintainer: | Xiuwen Zheng <[email protected]> |
| License: | GPL-3 + file LICENSE |
| Version: | 0.99.4 |
| Built: | 2026-10-06 08:45:24 UTC |
| Source: | https://github.com/bioc/pgen2gds |
Converts a SeqArray GDS file to PLINK2 pgen, pvar and psam files.
seqGDS2PGEN(gdsfile, out.fn, write.rsid=c("auto", "annot_id", "chr_pos_ref_alt"), half.call=c("missing", "haploid"), use.phase=TRUE, chr_prefix="", verbose=TRUE)seqGDS2PGEN(gdsfile, out.fn, write.rsid=c("auto", "annot_id", "chr_pos_ref_alt"), half.call=c("missing", "haploid"), use.phase=TRUE, chr_prefix="", verbose=TRUE)
gdsfile |
a |
out.fn |
the file name prefix of the output PLINK2 files;
|
write.rsid |
|
half.call |
how to handle a genotype with one missing allele (a half
call or a haploid call): |
use.phase |
if |
chr_prefix |
the prefix of chromosome codes, e.g., "chr"; it can be
used to restore the prefix removed by |
verbose |
if |
The sample and variant selections set by
seqSetFilter are respected, so seqGDS2PGEN()
can export a subset of the GDS file. The ploidy has to be 2. Dosages are not
exported.
The pgen file uses the PLINK2 storage mode 0x10. Each variant record is
stored in the smallest of the dense 2-bit, 1-bit and difference-list
encodings, following the thresholds used by PLINK2, and multiallelic genotypes
and hardcall phase are stored in the corresponding auxiliary data tracks. The
LD-based encodings of PLINK2 (differences from the previous variant) are not
used, so the pgen file can be slightly larger than the file generated by PLINK2
itself, especially for datasets with many common variants in strong linkage
disequilibrium. If the smallest file size is required, the files can be
re-encoded by PLINK2, e.g., plink2 --pfile out.fn --make-pgen --out
new.fn.
The pgen format keeps phase information for heterozygous genotypes only, so the phase flags of homozygous and haploid genotypes in the GDS file are ignored without loss of information.
The pvar file has the columns #CHROM, POS, ID,
REF and ALT, where REF and ALT are taken from the
GDS variable allele. If the chromosome codes are not recognized by
PLINK2 (e.g., non-standard contig names), --allow-extra-chr may be
needed when the files are loaded in PLINK2.
The psam file has the column IID from sample.id, and the
columns FID, PAT, MAT, SEX and PHENO1 when
the GDS variables sample.annotation/family,
sample.annotation/father, sample.annotation/mother,
sample.annotation/sex and sample.annotation/phenotype exist
(the same variables as created by seqBED2GDS and
seqPGEN2GDS).
Return the file names of the pgen, pvar and psam files with absolute paths.
Xiuwen Zheng
https://www.cog-genomics.org/plink/2.0/
seqPGEN2GDS, seqGDS2BED,
seqGDS2VCF
pgen_fn <- system.file("extdata", "plink2_gen.pgen", package="pgen2gds") # PGEN to GDS seqPGEN2GDS(pgen_fn, out.gdsfn="test.gds") # GDS to PGEN seqGDS2PGEN("test.gds", "test_out") head(seqReadPVAR("test_out.pvar")) # delete the temporary files unlink(c("test.gds", "test_out.pgen", "test_out.pvar", "test_out.psam"), force=TRUE)pgen_fn <- system.file("extdata", "plink2_gen.pgen", package="pgen2gds") # PGEN to GDS seqPGEN2GDS(pgen_fn, out.gdsfn="test.gds") # GDS to PGEN seqGDS2PGEN("test.gds", "test_out") head(seqReadPVAR("test_out.pvar")) # delete the temporary files unlink(c("test.gds", "test_out.pgen", "test_out.pvar", "test_out.psam"), force=TRUE)
Reformats PLINK2 pgen files to GDS format.
seqPGEN2GDS(pgen.fn, pvar.fn=NULL, psam.fn=NULL, out.gdsfn, compress.geno="LZMA_RA", compress.annot="LZMA_RA", variant.sel=NULL, sample.sel=NULL, start=1L, count=NA_integer_, ignore.chr.prefix=c("chr", "0"), reference=NULL, optimize=TRUE, digest=TRUE, parallel=FALSE, balancing=TRUE, verbose=TRUE)seqPGEN2GDS(pgen.fn, pvar.fn=NULL, psam.fn=NULL, out.gdsfn, compress.geno="LZMA_RA", compress.annot="LZMA_RA", variant.sel=NULL, sample.sel=NULL, start=1L, count=NA_integer_, ignore.chr.prefix=c("chr", "0"), reference=NULL, optimize=TRUE, digest=TRUE, parallel=FALSE, balancing=TRUE, verbose=TRUE)
pgen.fn |
a file name for the pgen file |
pvar.fn |
a file name for the pvar file, or |
psam.fn |
a file name for the psam file, or |
out.gdsfn |
the file name of output GDS file |
compress.geno |
the compression method for "genotype"; optional
values are defined in the function |
compress.annot |
the compression method for the GDS variables,
except "genotype"; optional values are defined in the function
|
variant.sel |
|
sample.sel |
|
start |
the starting variant if importing part of the pgen file |
count |
the maximum count of variant if importing part of the pgen
file, |
ignore.chr.prefix |
a vector of character, indicating the prefix of
chromosome which should be ignored, e.g., |
reference |
genome reference, like "GRCh37", "GRCh38"; it is not
specified if |
optimize |
if |
digest |
a logical value (TRUE/FALSE) or a character (e.g., "md5"); add hash codes to the GDS file if TRUE or a digest algorithm is specified |
parallel |
|
balancing |
whether to perform workload balancing or not, only
applicable when multiple cores are used; if |
verbose |
if |
The sample IDs are taken from the column IID of the psam file. The
psam columns FID, PAT, MAT and SEX are stored in
the GDS variables sample.annotation/family,
sample.annotation/father, sample.annotation/mother and
sample.annotation/sex (coded as "M", "F" or "") if they exist, and the
first phenotype column is stored in sample.annotation/phenotype (the
same variables as created by seqBED2GDS). Dosages and
phase information in the pgen file are not imported.
Return the file name of SeqArray GDS file with an absolute path.
Xiuwen Zheng
https://www.cog-genomics.org/plink/2.0/
pgen_fn <- system.file("extdata", "plink2_gen.pgen", package="pgen2gds") seqPGEN2GDS(pgen_fn, out.gdsfn="test.gds") # delete the temporary file unlink("test.gds", force=TRUE)pgen_fn <- system.file("extdata", "plink2_gen.pgen", package="pgen2gds") seqPGEN2GDS(pgen_fn, out.gdsfn="test.gds") # delete the temporary file unlink("test.gds", force=TRUE)
Read PLINK2 pvar file for variants
seqReadPVAR(pvar, sel=NULL)seqReadPVAR(pvar, sel=NULL)
pvar |
a file name of a pvar file (from NewPvar), or a pvar object, which can be queried for variant IDs and allele codes |
sel |
|
Return a data frame with the columns chrom, pos,
allele and rsid.
Xiuwen Zheng
https://www.cog-genomics.org/plink/2.0/
pvar_fn <- system.file("extdata", "plink2_gen.pvar", package="pgen2gds") head(seqReadPVAR(pvar_fn))pvar_fn <- system.file("extdata", "plink2_gen.pvar", package="pgen2gds") head(seqReadPVAR(pvar_fn))