Skip to contents

Package SNPRelate relies on a bit-level representation of a SNP dataset that competes with {adegenet} genlight objects and associated files. This function converts a genlight object to a gds format file.


  outfile = "gl_gds.gds",
  outpath = tempdir(),
  snp_pos = "0",
  snp_chr = "0",
  chr_format = "character",
  verbose = NULL



Name of the genlight object containing the SNP data [required].


File name of the output file (including extension) [default 'gl_gds.gds'].


Path where to save the output file [default tempdir(), mandated by CRAN]. Use outpath=getwd() or outpath='.' when calling this function to direct output files to your working directory.


Field name from the slot loc.metrics where the SNP position is stored [default '0'].


Field name from the slot loc.metrics where the chromosome of each is stored [default '0'].


Whether chromosome information is stored as 'numeric' or as 'character', see details [default 'character'].


Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default 2 or as specified using gl.set.verbosity].


This function orders the SNPS by chromosome and by position before converting to SNPRelate format, as required by this package.

The chromosome of each SNP can be a character or numeric, as described in the vignette of SNPRelate: 'snp.chromosome, an integer or character mapping for each chromosome. Integer: numeric values 1-26, mapped in order from 1-22, 23=X, 24=XY (the pseudoautosomal region), 25=Y, 26=M (the mitochondrial probes), and 0 for probes with unknown positions; it does not allow NA. Character: “X”, “XY”, “Y” and “M” can be used here, and a blank string indicating unknown position.'

When using some functions from package SNPRelate with datasets other than humans it might be necessary to use the option autosome.only=FALSE to avoid detecting chromosome coding. So, it is important to read the documentation of the function before using it.

The chromosome information for unmapped SNPS is coded as 0, as required by SNPRelate.

Remember to close the GDS file before working in a different GDS object with the function snpgdsClose (package SNPRelate).


Custodian: Luis Mijangos (Post to


# \donttest{
snp_chr = 'Chrom_Platypus_Chrom_NCBIv1')
#> Starting gl2gds 
#>   Processing genlight object with SNP data
#>   Warning: data include loci that are scored NA across all individuals.
#>   Consider filtering using gl <- gl.filter.allna(gl)
#>   Converting SNP data to gds format
#>   Writing data to file /tmp/RtmpMqupE6/gl_gds.gds 
#> Structure of gds file
#> Some values of 'snp.position' are invalid (should be > 0)!
#> The file name: /tmp/RtmpMqupE6/gl_gds.gds 
#> The total number of samples: 81 
#> The total number of SNPs: 1000 
#> SNP genotypes are stored in individual-major mode (SNP X Sample).
#> The number of valid samples: 81 
#> The number of biallelic unique SNPs: 921 
#> File: /tmp/RtmpMqupE6/gl_gds.gds (31.2K)
#> +    [  ] *
#> |--+   { Str8 81 ZIP_ra(49.9%), 200B }
#> |--+   { Str8 1000 ZIP_ra(34.0%), 5.3K }
#> |--+ snp.position   { Int32 1000 ZIP_ra(86.6%), 3.4K }
#> |--+ snp.chromosome   { Str8 1000 ZIP_ra(1.90%), 463B }
#> |--+ snp.allele   { Str8 1000 ZIP_ra(18.9%), 765B }
#> \--+ genotype   { Bit2 1000x81, 19.8K } *
#>   Closing file /tmp/RtmpMqupE6/gl_gds.gds 
#> Completed: gl2gds 
# }