Package {FILEST}


Type: Package
Title: Fine-Level Structure Simulator
Version: 1.2.6
Description: A population genetic simulator that generates synthetic genotype datasets of single-nucleotide variants (SNPs) for multiple populations. The genetic distances among populations can be set according to the Fixation Index (Fst) as explained in Balding and Nichols (1995) <doi:10.1007/BF01441146>. It can also simulate outlying individuals and missing genotypes. For genome-wide association studies (GWAS), disease status can be set at the desired level according to a risk ratio.
Depends: R (≥ 3.2.4)
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Imports: KRIS (≥ 1.1.1), grDevices, stats, tools, utils
Suggests: testthat
BugReports: https://github.com/kridsadakorn/filest/issues
URL: https://github.com/kridsadakorn/filest
NeedsCompilation: no
Packaged: 2026-12-02 15:53:19 UTC; kris
Author: Kridsadakorn Chaichoompu [aut, cre], Kristel Van Steen [aut], Fentaw Abegaz [aut]
Maintainer: Kridsadakorn Chaichoompu <kridsadakorn@biostatgen.org>
Repository: CRAN
Date/Publication: 2026-12-02 16:50:02 UTC

Fine-Level Structure Simulator

Description

FILEST simulates single-nucleotide polymorphism (SNP) data for several populations at once. You control how far apart the populations are by setting the fixation index (Fst) between them. You can also add outlying individuals, missing genotypes, and cases with disease-associated SNPs for genome-wide association studies (GWAS).

Details

To get started, run demo.filest. The main functions are:

filest

Run a simulation from a setting file.

create.template.setting

Create a setting file to edit.

demo.filest

Run a demo simulation.

The helpers rbind_bigmatrix and cbind_bigmatrix combine large matrices.

Author(s)

Maintainer: Kridsadakorn Chaichoompu kridsadakorn@biostatgen.org

Authors:

See Also

Useful links:


Combine two matrices by column

Description

Joins two matrices by column by filling a preallocated matrix. Used internally by filest.

Usage

cbind_bigmatrix(a, b)

Arguments

a

The first matrix.

b

The second matrix.

Value

The combined matrix. If one matrix is NULL, the other is returned. Returns NULL if both are NULL or if the numbers of rows differ.

See Also

rbind_bigmatrix

Examples

X <- matrix(c(1,2,0,1,2,2,1,2,0,0,1,2,1,2,2,2),ncol=4)
Y <- matrix(c(2,1,1,0,1,0,0,1,1,2,2,0,0,1,1,0),ncol=4)
Z <- cbind_bigmatrix(X,Y)
print(Z)


Create a template setting file

Description

Writes a setting file for filest with default values for three populations. Edit the file to set up your own simulation. The format is described in filest.

Usage

create.template.setting(out.file, no.setting = 1)

Arguments

out.file

Path to the new setting file. If the file already exists, it is not overwritten; a number is added to the file name instead.

no.setting

Number of settings to write (default 1).

Value

The path of the file that was written.

See Also

filest

Examples

# Create a setting file with two settings
output <- file.path(tempdir(), "example_setting.txt")
res <- create.template.setting(out.file = output, no.setting = 2)
cat(readLines(res), sep = "\n")


Run a demo simulation

Description

Writes the setting file example1.txt to a temporary directory and runs filest on it. The setting simulates two populations of 100 individuals each with 1000 SNPs. Use the setting file as a starting point for your own simulations.

Usage

demo.filest()

Value

The temporary directory that holds example1.txt and the output folder example1.

See Also

filest, create.template.setting

Examples

output_dir <- demo.filest()
dir(file.path(output_dir, "example1"))


Simulate SNP data for multiple populations

Description

Reads a setting file, simulates SNP data for each setting in it and writes the results to a folder named after the setting inside out.

Usage

filest(setting, out, thread = 1)

Arguments

setting

Path to the setting file. See create.template.setting to create one.

out

Path to the output directory. It is created if it does not exist.

thread

Kept for backward compatibility. It is not used; the simulation runs on a single thread.

Value

NULL, invisibly, on success. NA if the setting file does not exist or the output directory cannot be created.

Setting file

A setting file is a plain text file with one parameter per line, written as --name=value. Lines starting with # are comments and empty lines are ignored. One file can hold several settings; each one starts with --setting.

Lists have one value per population, separated by commas, so --population, --fst, --case and --outlier must all have the same length.

--setting

Name of the setting. The results are saved in a folder with this name.

--population

Number of individuals in each population, for example 100,100. Values below 2 are set to 2.

--fst

Fst between each population and the first population, for example 0.01,0.01. The first two values should be equal; otherwise their mean is used.

--case

Proportion of cases in each population, for example 0.5,0. Use 0 for no cases.

--outlier

1 if the population is an outlier group, 0 if not.

--marker

Number of SNPs.

--replicate

Number of data sets to simulate with this setting.

--riskratio

Risk ratio used to generate the case SNPs. Optional, default 1.

--no.case.snp

Number of disease-associated SNPs added after the other SNPs. Optional, default 0.

--missing

Amount of missing data. The number of missing genotypes is this value times the total number of individuals. Optional, default 0 (no missing data).

--pc

TRUE to calculate principal components (PCs). Optional, default FALSE.

--fulloutput

TRUE to write the extra output files. Optional, default FALSE.

TRUE and FALSE are not case-sensitive. A setting that leaves out --population, --fst, --case, --outlier, --marker or --replicate stops with an error.

Output files

Each replicate n gets these files in the setting's folder:

simSNP_repn.bed, .bim, .fam

Genotypes in PLINK binary format.

simSNP_repn_data_numMark_rowVar_colInd.txt

Genotypes coded 0, 1, 2 (missing is -1), one SNP per row.

simSNP_repn_individuals.txt

Individual ID, population label and disease status (1 = control, 2 = case).

simSNP_repn_estimated_Fst.txt

Fst estimated between each pair of populations.

simSNP_repn.RData

The simulated data as R objects.

simSNP_repn_PC10.txt, _eigenvector10.txt, _PC.pdf

The first 10 PCs and a plot, when --pc=TRUE.

simSNP_repn_cases.*, _controls.*

Cases and controls in separate PLINK files, when --no.case.snp is above 0.

simSNP_repn_PC.projected.txt, .pdf

Projected PCs and a plot, when there are cases and --pc=TRUE.

simSNP_repn_data_numMark_rowInd_colVar.txt, _individuals_with_header.txt

Extra files, when --fulloutput=TRUE.

See Also

demo.filest, create.template.setting

Examples

# Write a setting file for two populations of 100 individuals each
setting_file <- file.path(tempdir(), "example1.txt")
writeLines(c(
  "--setting=example1",
  "--population=100,100",
  "--fst=0.01,0.01",
  "--case=0,0",
  "--outlier=0,0",
  "--marker=1000",
  "--replicate=1",
  "--riskratio=1",
  "--no.case.snp=0",
  "--pc=TRUE",
  "--missing=0",
  "--fulloutput=TRUE"
), setting_file)

# Run the simulation and list the output files
filest(setting = setting_file, out = tempdir())
dir(file.path(tempdir(), "example1"))


Combine two matrices by row

Description

Joins two matrices by row by filling a preallocated matrix. Used internally by filest.

Usage

rbind_bigmatrix(a, b)

Arguments

a

The first matrix.

b

The second matrix.

Value

The combined matrix. If one matrix is NULL, the other is returned. Returns NULL if both are NULL or if the numbers of columns differ.

See Also

cbind_bigmatrix

Examples

X <- matrix(c(1,2,0,1,2,2,1,2,0,0,1,2,1,2,2,2),ncol=4)
Y <- matrix(c(2,1,1,0,1,0,0,1,1,2,2,0,0,1,1,0),ncol=4)
Z <- rbind_bigmatrix(X,Y)
print(Z)