| Title: | Fine-Level Structure Simulator |
|---|---|
| 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. |
| Authors: | Kridsadakorn Chaichoompu [aut, cre], Kristel Van Steen [aut], Fentaw Abegaz [aut] |
| Maintainer: | Kridsadakorn Chaichoompu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.2.6 |
| Built: | 2026-12-03 04:02:41 UTC |
| Source: | https://github.com/kridsadakorn/filest |
Joins two matrices by column by filling a preallocated matrix. Used
internally by filest.
cbind_bigmatrix(a, b)cbind_bigmatrix(a, b)
a |
The first matrix. |
b |
The second matrix. |
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.
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)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)
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.
create.template.setting(out.file, no.setting = 1)create.template.setting(out.file, no.setting = 1)
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). |
The path of the file that was written.
# 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")# 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")
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.
demo.filest()demo.filest()
The temporary directory that holds example1.txt and the
output folder example1.
filest, create.template.setting
output_dir <- demo.filest() dir(file.path(output_dir, "example1"))output_dir <- demo.filest() dir(file.path(output_dir, "example1"))
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.
filest(setting, out, thread = 1)filest(setting, out, thread = 1)
setting |
Path to the setting file. See |
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. |
NULL, invisibly, on success. NA if the setting file
does not exist or the output directory cannot be created.
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.
--settingName of the setting. The results are saved in a folder with this name.
--populationNumber of individuals in each population, for
example 100,100. Values below 2 are set to 2.
--fstFst 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.
--caseProportion of cases in each population, for example
0.5,0. Use 0 for no cases.
--outlier1 if the population is an outlier group,
0 if not.
--markerNumber of SNPs.
--replicateNumber of data sets to simulate with this setting.
--riskratioRisk ratio used to generate the case SNPs. Optional, default 1.
--no.case.snpNumber of disease-associated SNPs added after the other SNPs. Optional, default 0.
--missingAmount of missing data. The number of missing genotypes is this value times the total number of individuals. Optional, default 0 (no missing data).
--pcTRUE to calculate principal components (PCs).
Optional, default FALSE.
--fulloutputTRUE 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.
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.txtGenotypes coded 0, 1, 2 (missing is -1), one SNP per row.
simSNP_repn_individuals.txtIndividual ID, population label and disease status (1 = control, 2 = case).
simSNP_repn_estimated_Fst.txtFst estimated between each pair of populations.
simSNP_repn.RDataThe 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.
demo.filest, create.template.setting
# 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"))# 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"))
Joins two matrices by row by filling a preallocated matrix. Used
internally by filest.
rbind_bigmatrix(a, b)rbind_bigmatrix(a, b)
a |
The first matrix. |
b |
The second matrix. |
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.
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)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)