├── data ├── datalist └── simdata.rda ├── inst └── extdata │ ├── 02plinkb │ ├── demo │ ├── demo.bed │ ├── demo.fam │ └── demo.bim │ ├── 03plinkp │ ├── demo │ ├── demo.map │ └── demo.ped │ ├── 01bigmemory │ ├── demo │ ├── demo.geno.ind │ ├── demo.geno.desc │ ├── demo.geno.bin │ └── demo.geno.map │ ├── 00simer_logo │ └── simer_logo.png │ ├── 05others │ ├── pedigree.txt │ └── phenotype.txt │ └── 04breeding_plan │ ├── plan1.json │ ├── plan2.json │ └── plan3.json ├── .Rbuildignore ├── .gitignore ├── man ├── pop.map.Rd ├── pop.geno.Rd ├── format_time.Rd ├── load_if_installed.Rd ├── logging.initialize.Rd ├── mkl_env.Rd ├── simer.Version.Rd ├── print_accomplished.Rd ├── paste_label.Rd ├── rule_wrap.Rd ├── write.file.Rd ├── make_line.Rd ├── logging.print.Rd ├── checkEnv.Rd ├── generate.pop.Rd ├── GxG.network.Rd ├── bigt.Rd ├── generate.map.Rd ├── getfam.Rd ├── geno.cvt1.Rd ├── geno.cvt2.Rd ├── build.cov.Rd ├── param.simer.Rd ├── simer.Rd ├── remove_bigmatrix.Rd ├── param.reprod.Rd ├── simer.Data.Map.Rd ├── mate.Rd ├── logging.log.Rd ├── param.geno.Rd ├── simer.Data.MVP2Bfile.Rd ├── print_bar.Rd ├── IndPerGen.Rd ├── simer.Data.MVP2MVP.Rd ├── genotype.Rd ├── cal.eff.Rd ├── simer.Data.Bfile2MVP.Rd ├── simer.Data.Impute.Rd ├── simer.Data.Rd ├── param.sel.Rd ├── param.global.Rd ├── simer.Data.Pheno.Rd ├── simer.Data.cHIBLUP.Rd ├── simer.Data.SELIND.Rd ├── simer.Data.Env.Rd ├── simer.Data.Json.Rd ├── param.pheno.Rd ├── mate.clone.Rd ├── mate.dh.Rd ├── mate.userped.Rd ├── mate.assort.Rd ├── mate.randmate.Rd ├── mate.selfpol.Rd ├── mate.disassort.Rd ├── reproduces.Rd ├── print_info.Rd ├── mate.backcro.Rd ├── mate.randexself.Rd ├── mate.3waycro.Rd ├── selects.Rd ├── mate.2waycro.Rd ├── mate.4waycro.Rd ├── simer.Data.Ped.Rd ├── simer.Data.Geno.Rd ├── param.annot.Rd ├── annotation.Rd └── phenotype.Rd ├── SIMER.Rproj ├── R ├── exports.R ├── simdata.R ├── zzz.R ├── RcppExports.R ├── simer.R ├── simer.Logging.R └── simer.Selects.R ├── src ├── Makevars ├── Makevars.win ├── simer_omp.h ├── data_converter.cpp ├── pedigree.cpp ├── simer.h ├── impute.cpp └── RcppExports.cpp ├── DESCRIPTION ├── NAMESPACE └── LICENSE /data/datalist: -------------------------------------------------------------------------------- 1 | simdata: pop.geno pop.map -------------------------------------------------------------------------------- /inst/extdata/02plinkb/demo: -------------------------------------------------------------------------------- 1 | name 2 | -------------------------------------------------------------------------------- /inst/extdata/03plinkp/demo: -------------------------------------------------------------------------------- 1 | name 2 | -------------------------------------------------------------------------------- /inst/extdata/01bigmemory/demo: -------------------------------------------------------------------------------- 1 | name 2 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | LICENSE 4 | -------------------------------------------------------------------------------- /data/simdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolei-lab/SIMER/HEAD/data/simdata.rda -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | src/*.o 6 | src/*.so 7 | src/*.dll 8 | -------------------------------------------------------------------------------- /inst/extdata/02plinkb/demo.bed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolei-lab/SIMER/HEAD/inst/extdata/02plinkb/demo.bed -------------------------------------------------------------------------------- /inst/extdata/00simer_logo/simer_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolei-lab/SIMER/HEAD/inst/extdata/00simer_logo/simer_logo.png -------------------------------------------------------------------------------- /inst/extdata/01bigmemory/demo.geno.ind: -------------------------------------------------------------------------------- 1 | ind000120000101 2 | ind000220000102 3 | ind000320000103 4 | ind000420000104 5 | ind000520000105 6 | ind000620000106 7 | ind000720000107 8 | ind000820000108 9 | ind000920000109 10 | ind001020000110 11 | -------------------------------------------------------------------------------- /inst/extdata/01bigmemory/demo.geno.desc: -------------------------------------------------------------------------------- 1 | new("big.matrix.descriptor", description = list(sharedType = "FileBacked", 2 | filename = "demo.geno.bin", dirname = "./", totalRows = 10L, 3 | totalCols = 100L, rowOffset = c(0, 10), colOffset = c(0, 4 | 100), nrow = 10, ncol = 100, rowNames = NULL, colNames = NULL, 5 | type = "char", separated = FALSE)) 6 | -------------------------------------------------------------------------------- /inst/extdata/05others/pedigree.txt: -------------------------------------------------------------------------------- 1 | index sir dam 2 | ind000120000101 0 0 3 | ind000220000102 0 0 4 | ind000320000103 0 0 5 | ind000420000104 0 0 6 | ind000520000105 0 0 7 | ind000620000106 ind000120000101 ind000320000103 8 | ind000720000107 ind000120000101 ind000320000103 9 | ind000820000108 ind000220000102 ind000420000104 10 | ind000920000109 ind000220000102 ind000420000104 11 | ind001020000110 ind000220000102 ind000520000105 12 | -------------------------------------------------------------------------------- /man/pop.map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simdata.R 3 | \docType{data} 4 | \name{pop.map} 5 | \alias{pop.map} 6 | \title{Map file from outside in simdata} 7 | \format{ 8 | list 9 | } 10 | \usage{ 11 | data(simdata) 12 | } 13 | \description{ 14 | Map file from outside in simdata 15 | } 16 | \examples{ 17 | data(simdata) 18 | dim(pop.map) 19 | head(pop.map) 20 | } 21 | \keyword{datasets} 22 | -------------------------------------------------------------------------------- /man/pop.geno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simdata.R 3 | \docType{data} 4 | \name{pop.geno} 5 | \alias{pop.geno} 6 | \title{Raw genotype matrix from outside in simdata} 7 | \format{ 8 | matrix 9 | } 10 | \usage{ 11 | data(simdata) 12 | } 13 | \description{ 14 | Raw genotype matrix from outside in simdata 15 | } 16 | \examples{ 17 | data(simdata) 18 | dim(pop.geno) 19 | head(pop.geno) 20 | } 21 | \keyword{datasets} 22 | -------------------------------------------------------------------------------- /SIMER.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: XeLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageBuildArgs: --resave-data 19 | PackageBuildBinaryArgs: --resave-data 20 | PackageCheckArgs: --as-cran 21 | -------------------------------------------------------------------------------- /inst/extdata/02plinkb/demo.fam: -------------------------------------------------------------------------------- 1 | ind000120000101 ind000120000101 0 0 0 0.086667 2 | ind000220000102 ind000220000102 0 0 0 -0.101667 3 | ind000320000103 ind000320000103 0 0 0 -0.120173 4 | ind000420000104 ind000420000104 0 0 0 0.106211 5 | ind000520000105 ind000520000105 0 0 0 -0.111879 6 | ind000620000106 ind000620000106 0 0 0 -0.0201065 7 | ind000720000107 ind000720000107 0 0 0 -0.244335 8 | ind000820000108 ind000820000108 0 0 0 -0.302136 9 | ind000920000109 ind000920000109 0 0 0 -0.196387 10 | ind001020000110 ind001020000110 0 0 0 -0.146253 11 | -------------------------------------------------------------------------------- /R/exports.R: -------------------------------------------------------------------------------- 1 | #' @import bigmemory 2 | NULL 3 | 4 | #' @import Rcpp 5 | NULL 6 | 7 | #' @import jsonlite 8 | NULL 9 | 10 | #' @importFrom utils write.table read.delim read.table str packageVersion 11 | NULL 12 | 13 | #' @importFrom stats aov cor dnorm qnorm rgamma rnorm rbeta rgeom runif sd var shapiro.test na.omit lm step formula model.matrix 14 | NULL 15 | 16 | #' @importFrom Matrix bdiag 17 | NULL 18 | 19 | #' @importFrom methods getPackageName 20 | NULL 21 | 22 | #' @importFrom MASS mvrnorm ginv 23 | NULL 24 | 25 | #' @useDynLib simer 26 | NULL 27 | -------------------------------------------------------------------------------- /man/format_time.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{format_time} 4 | \alias{format_time} 5 | \title{Time formating} 6 | \usage{ 7 | format_time(x) 8 | } 9 | \arguments{ 10 | \item{x}{the total seconds.} 11 | } 12 | \value{ 13 | running time. 14 | } 15 | \description{ 16 | Format the time. 17 | } 18 | \details{ 19 | Build date: Oct 22, 2018 20 | Last update: Dec 28, 2024 21 | } 22 | \examples{ 23 | format_time(x = 7200) 24 | } 25 | \author{ 26 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/load_if_installed.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{load_if_installed} 4 | \alias{load_if_installed} 5 | \title{Installation checking} 6 | \usage{ 7 | load_if_installed(package) 8 | } 9 | \arguments{ 10 | \item{package}{the package name.} 11 | } 12 | \value{ 13 | none. 14 | } 15 | \description{ 16 | Check if the software is installed. 17 | } 18 | \details{ 19 | Build date: Oct 22, 2018 20 | Last update: Apr 30, 2022 21 | } 22 | \author{ 23 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/logging.initialize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Logging.R 3 | \name{logging.initialize} 4 | \alias{logging.initialize} 5 | \title{Logging initialization} 6 | \usage{ 7 | logging.initialize(module, outpath) 8 | } 9 | \arguments{ 10 | \item{module}{the module name.} 11 | 12 | \item{outpath}{the path of output files, Simer writes files only if outpath is not 'NULL'.} 13 | } 14 | \value{ 15 | none. 16 | } 17 | \description{ 18 | Initialize the logging process. 19 | } 20 | \details{ 21 | Build date: Jul 11, 2020 22 | Last update: Apr 28, 2022 23 | } 24 | \author{ 25 | Dong Yin 26 | } 27 | -------------------------------------------------------------------------------- /man/mkl_env.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{mkl_env} 4 | \alias{mkl_env} 5 | \title{MKL environment} 6 | \usage{ 7 | mkl_env(exprs, threads = 1) 8 | } 9 | \arguments{ 10 | \item{exprs}{the expression.} 11 | 12 | \item{threads}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | } 14 | \value{ 15 | none. 16 | } 17 | \description{ 18 | Run code in the MKL environment. 19 | } 20 | \details{ 21 | Build date: Oct 22, 2018 22 | Last update: Apr 30, 2022 23 | } 24 | \author{ 25 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/simer.Version.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{simer.Version} 4 | \alias{simer.Version} 5 | \title{Simer version} 6 | \usage{ 7 | simer.Version(width = 60, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{width}{the width of the message.} 11 | 12 | \item{verbose}{whether to print detail.} 13 | } 14 | \value{ 15 | version number. 16 | } 17 | \description{ 18 | Print simer version. 19 | } 20 | \details{ 21 | Build date: Aug 30, 2017 22 | Last update: Apr 30, 2022 23 | } 24 | \examples{ 25 | simer.Version() 26 | } 27 | \author{ 28 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 29 | } 30 | -------------------------------------------------------------------------------- /man/print_accomplished.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{print_accomplished} 4 | \alias{print_accomplished} 5 | \title{Accomplishment} 6 | \usage{ 7 | print_accomplished(width = 60, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{width}{the width of the message.} 11 | 12 | \item{verbose}{whether to print detail.} 13 | } 14 | \value{ 15 | none. 16 | } 17 | \description{ 18 | Print accomplishment information. 19 | } 20 | \details{ 21 | Build date: Aug 30, 2017 22 | Last update: Apr 30, 2022 23 | } 24 | \author{ 25 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/paste_label.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{paste_label} 4 | \alias{paste_label} 5 | \title{Pasting label} 6 | \usage{ 7 | paste_label(line, label, side = "right", margin = 2) 8 | } 9 | \arguments{ 10 | \item{line}{long text.} 11 | 12 | \item{label}{short label.} 13 | 14 | \item{side}{"right" or "left".} 15 | 16 | \item{margin}{the margin information, default 2.} 17 | } 18 | \value{ 19 | none. 20 | } 21 | \description{ 22 | Paste label to a line. 23 | } 24 | \details{ 25 | Build date: Oct 22, 2018 26 | Last update: Apr 30, 2022 27 | } 28 | \author{ 29 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /inst/extdata/05others/phenotype.txt: -------------------------------------------------------------------------------- 1 | ID gen F1 F2 R1 T1 T2 2 | ind000120000101 1 Female d2 l3 62.1739300162497 48.5716864096252 3 | ind000220000102 1 Female d2 l3 46.3431689292979 74.2507229686063 4 | ind000320000103 1 Female d2 l3 38.0787234837552 60.2292881824951 5 | ind000420000104 1 Female d1 l2 12.2746006933259 16.4803172419506 6 | ind000520000105 1 Male d1 l1 75.2647521567841 51.4561759127272 7 | ind000620000106 1 Male d3 l1 74.4261123361246 73.7507185836479 8 | ind000720000107 1 Male d1 l1 49.6931958521522 61.7258121124838 9 | ind000820000108 1 Male d3 l3 97.1615026563166 80.039416396856 10 | ind000920000109 1 Male d1 l3 73.8102133741169 71.2171726425528 11 | ind001020000110 1 Female d2 l3 50.7738005018768 42.278689549055 12 | -------------------------------------------------------------------------------- /man/rule_wrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{rule_wrap} 4 | \alias{rule_wrap} 5 | \title{Accomplishment} 6 | \usage{ 7 | rule_wrap(string, width, align = "center", linechar = " ") 8 | } 9 | \arguments{ 10 | \item{string}{a string.} 11 | 12 | \item{width}{the width of the message.} 13 | 14 | \item{align}{the position of string.} 15 | 16 | \item{linechar}{char in every line.} 17 | } 18 | \value{ 19 | none. 20 | } 21 | \description{ 22 | Print accomplishment information. 23 | } 24 | \details{ 25 | Build date: Oct 22, 2018 26 | Last update: Apr 30, 2022 27 | } 28 | \author{ 29 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/write.file.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{write.file} 4 | \alias{write.file} 5 | \title{File writing} 6 | \usage{ 7 | write.file(SP) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | } 12 | \value{ 13 | none. 14 | } 15 | \description{ 16 | Write files of Simer. 17 | } 18 | \details{ 19 | Build date: Jan 7, 2019 20 | Last update: Jan 28, 2025 21 | } 22 | \examples{ 23 | \donttest{ 24 | outpath <- tempdir() 25 | SP <- param.simer(out = "simer") 26 | SP <- simer(SP) 27 | SP$global$outpath <- outpath 28 | write.file(SP) 29 | unlink(file.path(outpath, "180_Simer_Data_numeric"), recursive = TRUE) 30 | } 31 | } 32 | \author{ 33 | Dong Yin 34 | } 35 | -------------------------------------------------------------------------------- /man/make_line.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{make_line} 4 | \alias{make_line} 5 | \title{Line making} 6 | \usage{ 7 | make_line(string, width, linechar = " ", align = "center", margin = 1) 8 | } 9 | \arguments{ 10 | \item{string}{a string.} 11 | 12 | \item{width}{the width of the message.} 13 | 14 | \item{linechar}{char in every line.} 15 | 16 | \item{align}{the position of string.} 17 | 18 | \item{margin}{the margin information, default 2.} 19 | } 20 | \value{ 21 | none. 22 | } 23 | \description{ 24 | Add a line to the screen. 25 | } 26 | \details{ 27 | Build date: Dec 12, 2018 28 | Last update: Apr 30, 2022 29 | } 30 | \author{ 31 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 32 | } 33 | \keyword{internal} 34 | -------------------------------------------------------------------------------- /man/logging.print.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Logging.R 3 | \name{logging.print} 4 | \alias{logging.print} 5 | \title{Logging printer} 6 | \usage{ 7 | logging.print(x, file = NULL, append = TRUE, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{a matrix or a list.} 11 | 12 | \item{file}{the filename of output file.} 13 | 14 | \item{append}{logical. If TRUE, output will be appended to file; otherwise, it will overwrite the contents of file.} 15 | 16 | \item{verbose}{whether to print details.} 17 | } 18 | \value{ 19 | none. 20 | } 21 | \description{ 22 | Print R object information into file. 23 | } 24 | \details{ 25 | Build date: Feb 7, 2020 26 | Last update: Apr 28, 2022 27 | } 28 | \examples{ 29 | x <- list(a = "a", b = "b") 30 | logging.print(x) 31 | } 32 | \author{ 33 | Dong Yin 34 | } 35 | -------------------------------------------------------------------------------- /man/checkEnv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{checkEnv} 4 | \alias{checkEnv} 5 | \title{Environmental factor checking} 6 | \usage{ 7 | checkEnv(data, envName, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{data}{data needing check.} 11 | 12 | \item{envName}{the environmental factor name within the data.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | data without environmental factors of wrong level. 18 | } 19 | \description{ 20 | Check the levels of environmental factors. 21 | } 22 | \details{ 23 | Build date: Sep 10, 2021 24 | Last update: Apr 28, 2022 25 | } 26 | \examples{ 27 | data <- data.frame(a = c(1, 1, 2), b = c(2, 2, 3), c = c(3, 3, 4)) 28 | envName <- c("a", "b", "c") 29 | data <- checkEnv(data = data, envName = envName) 30 | } 31 | \author{ 32 | Dong Yin 33 | } 34 | -------------------------------------------------------------------------------- /man/generate.pop.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Phenotype.R 3 | \name{generate.pop} 4 | \alias{generate.pop} 5 | \title{Population generator} 6 | \usage{ 7 | generate.pop(pop.ind = 100, from = 1, ratio = 0.5, gen = 1) 8 | } 9 | \arguments{ 10 | \item{pop.ind}{the number of the individuals in a population.} 11 | 12 | \item{from}{initial index of the population.} 13 | 14 | \item{ratio}{sex ratio of males in a population.} 15 | 16 | \item{gen}{generation ID of the population.} 17 | } 18 | \value{ 19 | a data frame of population information. 20 | } 21 | \description{ 22 | Generate population according to the number of individuals. 23 | } 24 | \details{ 25 | Build date: Nov 14, 2018 26 | Last update: Apr 28, 2022 27 | } 28 | \examples{ 29 | pop <- generate.pop(pop.ind = 100) 30 | head(pop) 31 | } 32 | \author{ 33 | Dong Yin 34 | } 35 | -------------------------------------------------------------------------------- /man/GxG.network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{GxG.network} 4 | \alias{GxG.network} 5 | \title{Genetic interaction network} 6 | \usage{ 7 | GxG.network(pop.map = NULL, qtn.pos = 1:10, qtn.model = "A:D") 8 | } 9 | \arguments{ 10 | \item{pop.map}{the map data with annotation information.} 11 | 12 | \item{qtn.pos}{the index of QTNs in the map data.} 13 | 14 | \item{qtn.model}{the genetic model of QTN such as 'A:D'.} 15 | } 16 | \value{ 17 | a data frame of genetic interaction effect. 18 | } 19 | \description{ 20 | Generate genetic interaction effect combination network. 21 | } 22 | \details{ 23 | Build date: Mar 19, 2022 24 | Last update: Apr 28, 2022 25 | } 26 | \examples{ 27 | pop.map <- generate.map(pop.marker = 1e4) 28 | GxG.net <- GxG.network(pop.map) 29 | head(GxG.net) 30 | } 31 | \author{ 32 | Dong Yin 33 | } 34 | -------------------------------------------------------------------------------- /man/bigt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{bigt} 4 | \alias{bigt} 5 | \title{Genotype transportor} 6 | \usage{ 7 | bigt(pop.geno, ncpus = 0) 8 | } 9 | \arguments{ 10 | \item{pop.geno}{genotype matrix of (0, 1).} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | } 14 | \value{ 15 | genotype matrix of (0, 1, 2). 16 | } 17 | \description{ 18 | Transport genotype matrix. 19 | } 20 | \details{ 21 | Build date: Jan 28, 2025 22 | Last update: Jan 29, 2025 23 | } 24 | \examples{ 25 | \donttest{ 26 | library(bigmemory) 27 | options(bigmemory.typecast.warning=FALSE) 28 | pop.geno <- matrix(sample(c(0, 1), 16, replace = TRUE), 4, 4) 29 | pop.geno[] 30 | bigmat <- bigt(pop.geno) 31 | bigmat[] 32 | pop.geno <- as.big.matrix(pop.geno, type = 'char') 33 | bigmat <- bigt(pop.geno) 34 | bigmat[] 35 | } 36 | } 37 | \author{ 38 | Dong Yin 39 | } 40 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | 2 | ## With R 3.1.0 or later, you can uncomment the following line to tell R to 3 | ## enable compilation with C++11 (where available) 4 | ## 5 | ## Also, OpenMP support in Armadillo prefers C++11 support. However, for wider 6 | ## availability of the package we do not yet enforce this here. It is however 7 | ## recommended for client packages to set it. 8 | ## 9 | ## And with R 3.4.0, and RcppArmadillo 0.7.960.*, we turn C++11 on as OpenMP 10 | ## support within Armadillo prefers / requires it 11 | ## 12 | ## R 4.0.0 made C++11 the default, R 4.1.0 switched to C++14, R 4.3.0 to C++17 13 | ## _In general_ we should no longer need to set a standard as any recent R 14 | ## installation will do the right thing. Should you need it, uncomment it and 15 | ## set the appropriate value, possibly CXX17. 16 | 17 | ## CXX_STD = CXX11 18 | 19 | PKG_CXXFLAGS = -DARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) 20 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | 2 | ## With R 3.1.0 or later, you can uncomment the following line to tell R to 3 | ## enable compilation with C++11 (where available) 4 | ## 5 | ## Also, OpenMP support in Armadillo prefers C++11 support. However, for wider 6 | ## availability of the package we do not yet enforce this here. It is however 7 | ## recommended for client packages to set it. 8 | ## 9 | ## And with R 3.4.0, and RcppArmadillo 0.7.960.*, we turn C++11 on as OpenMP 10 | ## support within Armadillo prefers / requires it 11 | ## 12 | ## R 4.0.0 made C++11 the default, R 4.1.0 switched to C++14, R 4.3.0 to C++17 13 | ## _In general_ we should no longer need to set a standard as any recent R 14 | ## installation will do the right thing. Should you need it, uncomment it and 15 | ## set the appropriate value, possibly CXX17. 16 | 17 | ## CXX_STD = CXX11 18 | 19 | PKG_CXXFLAGS = -DARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) 20 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -------------------------------------------------------------------------------- /man/generate.map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{generate.map} 4 | \alias{generate.map} 5 | \title{Marker information} 6 | \usage{ 7 | generate.map( 8 | species = NULL, 9 | pop.marker = NULL, 10 | num.chr = 18, 11 | len.chr = 1.5e+08 12 | ) 13 | } 14 | \arguments{ 15 | \item{species}{the species of genetic map, which can be "arabidopsis", "cattle", "chicken", "dog", "horse", "human", "maize", "mice", "pig", and "rice".} 16 | 17 | \item{pop.marker}{the number of markers.} 18 | 19 | \item{num.chr}{the number of chromosomes.} 20 | 21 | \item{len.chr}{the length of chromosomes.} 22 | } 23 | \value{ 24 | a data frame with marker information. 25 | } 26 | \description{ 27 | Generate map data with marker information. 28 | } 29 | \details{ 30 | Build date: Mar 19, 2022 31 | Last update: Apr 28, 2022 32 | } 33 | \examples{ 34 | pop.map <- generate.map(pop.marker = 1e4) 35 | str(pop.map) 36 | } 37 | \author{ 38 | Dong Yin 39 | } 40 | -------------------------------------------------------------------------------- /inst/extdata/01bigmemory/demo.geno.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /man/getfam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{getfam} 4 | \alias{getfam} 5 | \title{Family index and within-family index} 6 | \usage{ 7 | getfam(sir, dam, fam.op, mode = c("pat", "mat", "pm")) 8 | } 9 | \arguments{ 10 | \item{sir}{the indice of sires.} 11 | 12 | \item{dam}{the indice of dams.} 13 | 14 | \item{fam.op}{the initial index of family indice.} 15 | 16 | \item{mode}{"pat": paternal mode; "mat": maternal mode; "pm": paternal and maternal mode.} 17 | } 18 | \value{ 19 | a matrix with family indice and within-family indice. 20 | } 21 | \description{ 22 | Get indice of family and within-family 23 | } 24 | \details{ 25 | Build date: Nov 14, 2018 26 | Last update: Apr 30, 2022 27 | } 28 | \examples{ 29 | s <- c(0, 0, 0, 0, 1, 3, 3, 1, 5, 7, 5, 7, 1, 3, 5, 7) 30 | d <- c(0, 0, 0, 0, 2, 4, 4, 2, 6, 8, 8, 6, 6, 8, 4, 8) 31 | fam <- getfam(sir = s, dam = d, fam.op = 1, mode = "pm") 32 | fam 33 | } 34 | \author{ 35 | Dong Yin 36 | } 37 | -------------------------------------------------------------------------------- /man/geno.cvt1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{geno.cvt1} 4 | \alias{geno.cvt1} 5 | \title{Genotype code convertor 1} 6 | \usage{ 7 | geno.cvt1(pop.geno, ncpus = 0) 8 | } 9 | \arguments{ 10 | \item{pop.geno}{genotype matrix of (0, 1).} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | } 14 | \value{ 15 | genotype matrix of (0, 1, 2). 16 | } 17 | \description{ 18 | Convert genotype matrix from (0, 1) to (0, 1, 2). 19 | } 20 | \details{ 21 | Build date: Nov 14, 2018 22 | Last update: Jan 30, 2025 23 | } 24 | \examples{ 25 | \donttest{ 26 | library(bigmemory) 27 | options(bigmemory.typecast.warning=FALSE) 28 | pop.geno <- matrix(sample(c(0, 1), 16, replace = TRUE), 4, 4) 29 | pop.geno[] 30 | bigmat <- geno.cvt1(pop.geno) 31 | bigmat[] 32 | pop.geno <- as.big.matrix(pop.geno, type = 'char') 33 | bigmat <- geno.cvt1(pop.geno) 34 | bigmat[] 35 | } 36 | } 37 | \author{ 38 | Dong Yin 39 | } 40 | -------------------------------------------------------------------------------- /man/geno.cvt2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{geno.cvt2} 4 | \alias{geno.cvt2} 5 | \title{Genotype code convertor 2} 6 | \usage{ 7 | geno.cvt2(pop.geno, ncpus = 0) 8 | } 9 | \arguments{ 10 | \item{pop.geno}{genotype matrix of (0, 1, 2).} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | } 14 | \value{ 15 | genotype matrix of (0, 1). 16 | } 17 | \description{ 18 | Convert genotype matrix from (0, 1, 2) to (0, 1). 19 | } 20 | \details{ 21 | Build date: Jul 11, 2020 22 | Last update: Jan 29, 2025 23 | } 24 | \examples{ 25 | \donttest{ 26 | library(bigmemory) 27 | options(bigmemory.typecast.warning=FALSE) 28 | pop.geno <- matrix(sample(c(0, 1, 2), 8, replace = TRUE), 2, 4) 29 | pop.geno[] 30 | bigmat <- geno.cvt2(pop.geno) 31 | bigmat[] 32 | pop.geno <- as.big.matrix(pop.geno, type = 'char') 33 | bigmat <- geno.cvt2(pop.geno) 34 | bigmat[] 35 | } 36 | } 37 | \author{ 38 | Dong Yin 39 | } 40 | -------------------------------------------------------------------------------- /man/build.cov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Phenotype.R 3 | \name{build.cov} 4 | \alias{build.cov} 5 | \title{Correlation building} 6 | \usage{ 7 | build.cov(df = NULL, mu = rep(0, nrow(Sigma)), Sigma = diag(2), tol = 1e-06) 8 | } 9 | \arguments{ 10 | \item{df}{a data frame needing building correlation.} 11 | 12 | \item{mu}{means of the variables.} 13 | 14 | \item{Sigma}{covariance matrix of variables.} 15 | 16 | \item{tol}{tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma.} 17 | } 18 | \value{ 19 | a data frame with expected correlation 20 | } 21 | \description{ 22 | To bulid correlation of variables. 23 | } 24 | \details{ 25 | Build date: Oct 10, 2019 26 | Last update: Apr 28, 2022 27 | } 28 | \examples{ 29 | df <- data.frame(tr1 = rnorm(100), tr2 = rnorm(100)) 30 | df.cov <- build.cov(df) 31 | var(df.cov) 32 | } 33 | \references{ 34 | B. D. Ripley (1987) Stochastic Simulation. Wiley. Page 98 35 | } 36 | \author{ 37 | Dong Yin and R 38 | } 39 | -------------------------------------------------------------------------------- /man/param.simer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Parameter.R 3 | \name{param.simer} 4 | \alias{param.simer} 5 | \title{Parameter generator} 6 | \usage{ 7 | param.simer(SP = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{...}{one or more parameter(s) for simer.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$global}{a list of global parameters.} 18 | \item{$map}{a list of marker information parameters.} 19 | \item{$geno}{a list of genotype simulation parameters.} 20 | \item{$pheno}{a list of phenotype simulation parameters.} 21 | \item{$sel}{a list of selection parameters.} 22 | \item{$reprod}{a list of reproduction parameters.} 23 | } 24 | } 25 | \description{ 26 | Generate parameters for Simer. 27 | } 28 | \details{ 29 | Build date: Apr 17, 2022 30 | Last update: Jul 4, 2022 31 | } 32 | \examples{ 33 | SP <- param.simer(out = "simer") 34 | str(SP) 35 | } 36 | \author{ 37 | Dong Yin 38 | } 39 | -------------------------------------------------------------------------------- /man/simer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.R 3 | \name{simer} 4 | \alias{simer} 5 | \title{Simer} 6 | \usage{ 7 | simer(SP) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | } 12 | \value{ 13 | the function returns a list containing 14 | \describe{ 15 | \item{$global}{a list of global parameters.} 16 | \item{$map}{a list of marker information parameters.} 17 | \item{$geno}{a list of genotype simulation parameters.} 18 | \item{$pheno}{a list of phenotype simulation parameters.} 19 | \item{$sel}{a list of selection parameters.} 20 | \item{$reprod}{a list of reproduction parameters.} 21 | } 22 | } 23 | \description{ 24 | Main function of Simer. 25 | } 26 | \details{ 27 | Build date: Jan 7, 2019 28 | Last update: Feb 18, 2025 29 | } 30 | \examples{ 31 | \donttest{ 32 | # Generate all simulation parameters 33 | SP <- param.simer(out = "simer") 34 | 35 | # Run Simer 36 | SP <- simer(SP) 37 | } 38 | } 39 | \author{ 40 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 41 | } 42 | -------------------------------------------------------------------------------- /man/remove_bigmatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{remove_bigmatrix} 4 | \alias{remove_bigmatrix} 5 | \title{Big.matrix removing} 6 | \usage{ 7 | remove_bigmatrix(x, desc_suffix = ".geno.desc", bin_suffix = ".geno.bin") 8 | } 9 | \arguments{ 10 | \item{x}{the filename of big.matrix.} 11 | 12 | \item{desc_suffix}{the suffix of description file of big.matrix.} 13 | 14 | \item{bin_suffix}{the suffix of binary file of big.matrix.} 15 | } 16 | \value{ 17 | TRUE or FALSE 18 | } 19 | \description{ 20 | Remove big.matrix safely. 21 | } 22 | \details{ 23 | Build date: Aug 8, 2019 24 | Last update: Apr 30, 2022 25 | } 26 | \examples{ 27 | \donttest{ 28 | library(bigmemory) 29 | mat <- filebacked.big.matrix( 30 | nrow = 10, 31 | ncol = 10, 32 | init = 0, 33 | type = 'char', 34 | backingpath = ".", 35 | backingfile = 'simer.geno.bin', 36 | descriptorfile = 'simer.geno.desc') 37 | 38 | remove_bigmatrix(x = "simer") 39 | } 40 | } 41 | \author{ 42 | Haohao Zhang and Dong Yin 43 | } 44 | -------------------------------------------------------------------------------- /man/param.reprod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Parameter.R 3 | \name{param.reprod} 4 | \alias{param.reprod} 5 | \title{Reproduction parameters generator} 6 | \usage{ 7 | param.reprod(SP = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{...}{one or more parameter(s) for reproduction.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$reprod$pop.gen}{the generations of simulated population.} 18 | \item{$reprod$reprod.way}{reproduction method, it consists of "clone", "dh", "selfpol", "randmate", "randexself", "assort", "disassort", "2waycro", "3waycro", "4waycro", "backcro", and "userped".} 19 | \item{$reprod$sex.rate}{the male rate in the population.} 20 | \item{$reprod$prog}{the progeny number of an individual.} 21 | } 22 | } 23 | \description{ 24 | Generate parameters for reproduction. 25 | } 26 | \details{ 27 | Build date: Apr 6, 2022 28 | Last update: Jul 4, 2022 29 | } 30 | \examples{ 31 | SP <- param.reprod(reprod.way = "randmate") 32 | str(SP) 33 | } 34 | \author{ 35 | Dong Yin 36 | } 37 | -------------------------------------------------------------------------------- /man/simer.Data.Map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Map} 4 | \alias{simer.Data.Map} 5 | \title{simer.Data.Map: To check map file} 6 | \usage{ 7 | simer.Data.Map( 8 | map, 9 | out = "simer", 10 | cols = 1:5, 11 | header = TRUE, 12 | sep = "\\t", 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{map}{the name of map file or map object(data.frame or matrix).} 18 | 19 | \item{out}{the name of output file.} 20 | 21 | \item{cols}{selected columns.} 22 | 23 | \item{header}{whether the file contains header.} 24 | 25 | \item{sep}{seperator of the file.} 26 | 27 | \item{verbose}{whether to print detail.} 28 | } 29 | \value{ 30 | Output file: 31 | .map 32 | } 33 | \description{ 34 | checking map file. 35 | } 36 | \details{ 37 | Build date: Sep 12, 2018 38 | Last update: July 25, 2022 39 | } 40 | \examples{ 41 | # Get map path 42 | mapPath <- system.file("extdata", "01bigmemory", "demo.geno.map", package = "simer") 43 | 44 | # Check map data 45 | simer.Data.Map(mapPath, tempfile("outfile")) 46 | } 47 | \author{ 48 | Haohao Zhang and Dong Yin 49 | } 50 | -------------------------------------------------------------------------------- /man/mate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate} 4 | \alias{mate} 5 | \title{Mate} 6 | \usage{ 7 | mate(pop.geno, index.sir, index.dam, ncpus = 0) 8 | } 9 | \arguments{ 10 | \item{pop.geno}{the genotype data.} 11 | 12 | \item{index.sir}{the indice of sires.} 13 | 14 | \item{index.dam}{the indice of dams.} 15 | 16 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 17 | } 18 | \value{ 19 | a genotype matrix after mating 20 | } 21 | \description{ 22 | Mating according to the indice of sires and dams. 23 | } 24 | \details{ 25 | Build date: Nov 14, 2018 26 | Last update: Jan 28, 2025 27 | } 28 | \examples{ 29 | \donttest{ 30 | # Generate the genotype data 31 | SP <- param.geno(pop.marker = 1e4, pop.ind = 1e2) 32 | SP <- genotype(SP) 33 | pop.geno <- SP$geno$pop.geno$gen1 34 | 35 | # The mating design 36 | index.sir <- rep(1:50, each = 2) 37 | index.dam <- rep(51:100, each = 2) 38 | 39 | # Mate according to mating design 40 | geno.curr <- mate(pop.geno = pop.geno, index.sir = index.sir, 41 | index.dam = index.dam) 42 | geno.curr[1:5, 1:5] 43 | } 44 | } 45 | \author{ 46 | Dong Yin 47 | } 48 | -------------------------------------------------------------------------------- /man/logging.log.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Logging.R 3 | \name{logging.log} 4 | \alias{logging.log} 5 | \title{Logging} 6 | \usage{ 7 | logging.log( 8 | ..., 9 | file = NULL, 10 | sep = " ", 11 | fill = FALSE, 12 | labels = NULL, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{...}{R objects.} 18 | 19 | \item{file}{a connection or a character string naming the file to print to. If "" (the default), cat prints to the standard output connection, the console unless redirected by sink. If it is "|cmd", the output is piped to the command given by ‘cmd’, by opening a pipe connection.} 20 | 21 | \item{sep}{a character vector of strings to append after each element.} 22 | 23 | \item{fill}{a logical or (positive) numeric controlling how the output is broken into successive lines.} 24 | 25 | \item{labels}{a character vector of labels for the lines printed. Ignored if fill is FALSE.} 26 | 27 | \item{verbose}{whether to print detail.} 28 | } 29 | \value{ 30 | none. 31 | } 32 | \description{ 33 | Print or write log. 34 | } 35 | \details{ 36 | Build date: Jul 11, 2020 37 | Last update: Apr 28, 2022 38 | } 39 | \examples{ 40 | logging.log('simer') 41 | } 42 | \author{ 43 | Dong Yin 44 | } 45 | -------------------------------------------------------------------------------- /R/simdata.R: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | #' Raw genotype matrix from outside in simdata 15 | #' 16 | #' @name pop.geno 17 | #' 18 | #' @docType data 19 | #' 20 | #' @usage data(simdata) 21 | #' 22 | #' @format matrix 23 | #' 24 | #' @keywords datasets 25 | #' 26 | #' @examples 27 | #' data(simdata) 28 | #' dim(pop.geno) 29 | #' head(pop.geno) 30 | "pop.geno" 31 | 32 | #' Map file from outside in simdata 33 | #' 34 | #' @name pop.map 35 | #' 36 | #' @docType data 37 | #' 38 | #' @usage data(simdata) 39 | #' 40 | #' @format list 41 | #' 42 | #' @keywords datasets 43 | #' 44 | #' @examples 45 | #' data(simdata) 46 | #' dim(pop.map) 47 | #' head(pop.map) 48 | "pop.map" 49 | -------------------------------------------------------------------------------- /man/param.geno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Parameter.R 3 | \name{param.geno} 4 | \alias{param.geno} 5 | \title{Genotype parameters generator} 6 | \usage{ 7 | param.geno(SP = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{...}{one or more parameter(s) for genotype simulation.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$geno$pop.geno}{the genotype data.} 18 | \item{$geno$inrows}{"1":one-row genotype represents an individual; "2": two-row genotype represents an individual.} 19 | \item{$geno$pop.marker}{the number of markers.} 20 | \item{$geno$pop.ind}{the number of individuals in the base population.} 21 | \item{$geno$prob}{the genotype code probability.} 22 | \item{$geno$rate.mut}{the mutation rate of the genotype data.} 23 | \item{$geno$cld}{whether to generate a complete LD genotype data when "inrows == 2".} 24 | } 25 | } 26 | \description{ 27 | Generate parameters for genotype data simulation. 28 | } 29 | \details{ 30 | Build date: Feb 21, 2022 31 | Last update: Jan 27, 2025 32 | } 33 | \examples{ 34 | SP <- param.geno(pop.marker = 1e4, pop.ind = 1e2) 35 | str(SP) 36 | } 37 | \author{ 38 | Dong Yin 39 | } 40 | -------------------------------------------------------------------------------- /src/simer_omp.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 by Xiaolei Team 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef SIMER_OMP_H_ 16 | #define SIMER_OMP_H_ 17 | 18 | #if defined(_OPENMP) 19 | #include 20 | // [[Rcpp::plugins(openmp)]] 21 | #endif 22 | 23 | #include 24 | 25 | static int omp_setup(int threads); 26 | static inline int omp_setup(int threads=0) { 27 | int t = 1; 28 | #ifdef _OPENMP 29 | if (threads == 0) { 30 | t = omp_get_num_procs() - 1; 31 | t = t > 0 ? t : 1; 32 | } else { 33 | t = threads > 0 ? threads : 1; 34 | } 35 | omp_set_num_threads(t); 36 | #else 37 | #endif 38 | return t; 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /man/simer.Data.MVP2Bfile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.MVP2Bfile} 4 | \alias{simer.Data.MVP2Bfile} 5 | \title{simer.Data.MVP2Bfile: To transform MVP data to binary format} 6 | \usage{ 7 | simer.Data.MVP2Bfile( 8 | bigmat, 9 | map, 10 | pheno = NULL, 11 | out = "simer", 12 | threads = 1, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{bigmat}{Genotype in bigmatrix format (0,1,2).} 18 | 19 | \item{map}{the map file.} 20 | 21 | \item{pheno}{the phenotype file.} 22 | 23 | \item{out}{the name of output file.} 24 | 25 | \item{threads}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 26 | 27 | \item{verbose}{whether to print the reminder.} 28 | } 29 | \value{ 30 | NULL 31 | Output files: 32 | .bed, .bim, .fam 33 | } 34 | \description{ 35 | transforming MVP data to binary format. 36 | } 37 | \details{ 38 | Build date: Sep 12, 2018 39 | Last update: Jan 29, 2025 40 | } 41 | \examples{ 42 | \donttest{ 43 | library(bigmemory) 44 | 45 | # Generate bigmat and map 46 | bigmat <- as.big.matrix(matrix(1:6, 3, 2)) 47 | map <- generate.map(pop.marker = 3) 48 | 49 | # Data converting 50 | simer.Data.MVP2Bfile(bigmat, map, out=tempfile("outfile")) 51 | } 52 | } 53 | \author{ 54 | Haohao Zhang and Dong Yin 55 | } 56 | -------------------------------------------------------------------------------- /man/print_bar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{print_bar} 4 | \alias{print_bar} 5 | \title{Progress bar} 6 | \usage{ 7 | print_bar( 8 | i, 9 | n, 10 | type = c("type1", "type3"), 11 | symbol = "-", 12 | tmp.file = NULL, 13 | symbol.head = ">>>", 14 | symbol.tail = ">", 15 | fixed.points = TRUE, 16 | points = seq(0, 100, 1), 17 | symbol.len = 48, 18 | verbose = TRUE 19 | ) 20 | } 21 | \arguments{ 22 | \item{i}{the current loop number.} 23 | 24 | \item{n}{the max loop number.} 25 | 26 | \item{type}{type1 for "for" function.} 27 | 28 | \item{symbol}{the symbol for the rate of progress.} 29 | 30 | \item{tmp.file}{the opened file of "fifo" function.} 31 | 32 | \item{symbol.head}{the head for the bar.} 33 | 34 | \item{symbol.tail}{the tail for the bar.} 35 | 36 | \item{fixed.points}{whether use the setted points which will be printed.} 37 | 38 | \item{points}{the setted points which will be printed.} 39 | 40 | \item{symbol.len}{the total length of progress bar.} 41 | 42 | \item{verbose}{whether to print detail.} 43 | } 44 | \value{ 45 | none. 46 | } 47 | \description{ 48 | Print progress bar. 49 | } 50 | \details{ 51 | Build date: Aug 30, 2017 52 | Last update: Apr 30, 2022 53 | } 54 | \author{ 55 | Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 56 | } 57 | \keyword{internal} 58 | -------------------------------------------------------------------------------- /man/IndPerGen.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{IndPerGen} 4 | \alias{IndPerGen} 5 | \title{Individual number per generation} 6 | \usage{ 7 | IndPerGen( 8 | pop, 9 | pop.gen = 2, 10 | ps = c(0.8, 0.8), 11 | reprod.way = "randmate", 12 | sex.rate = 0.5, 13 | prog = 2 14 | ) 15 | } 16 | \arguments{ 17 | \item{pop}{the population information containing environmental factors and other effects.} 18 | 19 | \item{pop.gen}{the generations of simulated population.} 20 | 21 | \item{ps}{if ps <= 1, fraction selected in selection of males and females; if ps > 1, ps is number of selected males and females.} 22 | 23 | \item{reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 24 | 25 | \item{sex.rate}{the sex ratio of simulated population.} 26 | 27 | \item{prog}{the progeny number of an individual.} 28 | } 29 | \value{ 30 | the vector containing the individual number per generation. 31 | } 32 | \description{ 33 | Calculate the individual number per generation. 34 | } 35 | \details{ 36 | Build date: Apr 12, 2022 37 | Last update: Apr 30, 2022 38 | } 39 | \examples{ 40 | pop <- generate.pop(pop.ind = 100) 41 | count.ind <- IndPerGen(pop) 42 | } 43 | \author{ 44 | Dong Yin 45 | } 46 | -------------------------------------------------------------------------------- /man/simer.Data.MVP2MVP.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.MVP2MVP} 4 | \alias{simer.Data.MVP2MVP} 5 | \title{Genotype data conversion} 6 | \usage{ 7 | simer.Data.MVP2MVP(fileMVP, genoType = "char", out = "simer", verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{fileMVP}{the prefix of MVP file.} 11 | 12 | \item{genoType}{type parameter in bigmemory data. The default is 'char', it is highly recommended *NOT* to modify this parameter.} 13 | 14 | \item{out}{the prefix of output files.} 15 | 16 | \item{verbose}{whether to print detail.} 17 | } 18 | \value{ 19 | the function returns files 20 | \describe{ 21 | \item{.geno.desc}{the description file of genotype data.} 22 | \item{.geno.bin}{the binary file of genotype data.} 23 | \item{.geno.ind}{the genotyped individual file.} 24 | \item{.geno.map}{the marker information data file.} 25 | } 26 | } 27 | \description{ 28 | Convert genotype data from MVP format to MVP format. 29 | } 30 | \details{ 31 | Build date: May 26, 2021 32 | Last update: Apr 28, 2022 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Get the prefix of genotype data 37 | fileMVP <- system.file("extdata", "01bigmemory", "demo", package = "simer") 38 | 39 | # Convert genotype data from MVP to MVP 40 | simer.Data.MVP2MVP(fileMVP, out = tempfile("outfile")) 41 | } 42 | } 43 | \author{ 44 | Dong Yin 45 | } 46 | -------------------------------------------------------------------------------- /man/genotype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{genotype} 4 | \alias{genotype} 5 | \title{Genotype simulation} 6 | \usage{ 7 | genotype(SP = NULL, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$geno$pop.geno}{the genotype data.} 20 | \item{$geno$inrows}{"1": one-row genotype represents an individual; "2": two-row genotype represents an individual.} 21 | \item{$geno$pop.marker}{the number of markers.} 22 | \item{$geno$pop.ind}{the number of individuals in the base population.} 23 | \item{$geno$prob}{the genotype code probability.} 24 | \item{$geno$rate.mut}{the mutation rate of the genotype data.} 25 | \item{$geno$cld}{whether to generate a complete LD genotype data when "inrows == 2".} 26 | } 27 | } 28 | \description{ 29 | Generating and editing genotype data. 30 | } 31 | \details{ 32 | Build date: Nov 14, 2018 33 | Last update: Jan 28, 2025 34 | } 35 | \examples{ 36 | \donttest{ 37 | # Generate genotype simulation parameters 38 | SP <- param.geno(pop.marker = 1e4, pop.ind = 1e2) 39 | 40 | # Run genotype simulation 41 | SP <- genotype(SP) 42 | } 43 | } 44 | \author{ 45 | Dong Yin 46 | } 47 | -------------------------------------------------------------------------------- /inst/extdata/04breeding_plan/plan1.json: -------------------------------------------------------------------------------- 1 | { 2 | "genotype": "../02plinkb", 3 | "pedigree": "../05others/pedigree.txt", 4 | "threads": 16, 5 | "quality_control_plan": { 6 | "genotype_quality_control":{ 7 | "filter": "F1 == 'Male'", 8 | "filter_geno": 0.1, 9 | "filter_mind": 0.1, 10 | "filter_maf": 0.05, 11 | "filter_hwe": 0.001 12 | }, 13 | "pedigree_quality_control":{ 14 | "standard_ID": false, 15 | "candidate_sire_file": [], 16 | "candidate_dam_file": [], 17 | "exclude_threshold": 0.1, 18 | "assign_threshold": 0.05 19 | }, 20 | "phenotype_quality_control":[ 21 | { 22 | "job_name": "Data_Quality_Control_Demo", 23 | "sample_info": "../05others/phenotype.txt", 24 | "repeated_records": false, 25 | "multi_trait": true, 26 | "filter": "F1 == 'Male'", 27 | "job_traits": [ 28 | { 29 | "traits": "T1", 30 | "definition": "T1", 31 | "range": [] 32 | }, 33 | { 34 | "traits": "T2", 35 | "definition": "T2", 36 | "range": [] 37 | } 38 | ] 39 | } 40 | ] 41 | } 42 | } -------------------------------------------------------------------------------- /man/cal.eff.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{cal.eff} 4 | \alias{cal.eff} 5 | \title{QTN genetic effects} 6 | \usage{ 7 | cal.eff( 8 | qtn.num = 10, 9 | qtn.dist = "norm", 10 | qtn.var = 1, 11 | qtn.prob = 0.5, 12 | qtn.shape = 1, 13 | qtn.scale = 1, 14 | qtn.shape1 = 1, 15 | qtn.shape2 = 1, 16 | qtn.ncp = 0 17 | ) 18 | } 19 | \arguments{ 20 | \item{qtn.num}{integer: the QTN number of single trait; vector: the multiple group QTN number of single trait; matrix: the QTN number of multiple traits.} 21 | 22 | \item{qtn.dist}{the QTN distribution containing "norm", "geom", "gamma" or "beta".} 23 | 24 | \item{qtn.var}{the standard deviations for normal distribution.} 25 | 26 | \item{qtn.prob}{the probability of success for geometric distribution.} 27 | 28 | \item{qtn.shape}{the shape parameter for gamma distribution.} 29 | 30 | \item{qtn.scale}{the scale parameter for gamma distribution.} 31 | 32 | \item{qtn.shape1}{the shape1 parameter for beta distribution.} 33 | 34 | \item{qtn.shape2}{the shape2 parameter for beta distribution.} 35 | 36 | \item{qtn.ncp}{the ncp parameter for beta distribution.} 37 | } 38 | \value{ 39 | a vector of genetic effect. 40 | } 41 | \description{ 42 | Calculate for genetic effects vector of selected markers. 43 | } 44 | \details{ 45 | Build date: Nov 14, 2018 46 | Last update: Apr 28, 2022 47 | } 48 | \examples{ 49 | eff <- cal.eff(qtn.num = 10) 50 | str(eff) 51 | } 52 | \author{ 53 | Dong Yin 54 | } 55 | -------------------------------------------------------------------------------- /man/simer.Data.Bfile2MVP.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Bfile2MVP} 4 | \alias{simer.Data.Bfile2MVP} 5 | \title{simer.Data.Bfile2MVP: To transform plink binary data to MVP package} 6 | \usage{ 7 | simer.Data.Bfile2MVP( 8 | bfile, 9 | out = "simer", 10 | maxLine = 10000, 11 | type.geno = "char", 12 | threads = 10, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{bfile}{Genotype in binary format (.bed, .bim, .fam).} 18 | 19 | \item{out}{the name of output file.} 20 | 21 | \item{maxLine}{the max number of line to write to big matrix for each loop.} 22 | 23 | \item{type.geno}{the type of genotype elements.} 24 | 25 | \item{threads}{number of thread for transforming.} 26 | 27 | \item{verbose}{whether to print the reminder.} 28 | } 29 | \value{ 30 | number of individuals and markers. 31 | Output files: 32 | genotype.desc, genotype.bin: genotype file in bigmemory format 33 | phenotype.phe: ordered phenotype file, same taxa order with genotype file 34 | map.map: SNP information 35 | } 36 | \description{ 37 | transforming plink binary data to MVP package. 38 | } 39 | \details{ 40 | Build date: Sep 12, 2018 41 | Last update: Dec 28, 2024 42 | } 43 | \examples{ 44 | \donttest{ 45 | # Get bfile path 46 | bfilePath <- file.path(system.file("extdata", "02plinkb", package = "simer"), "demo") 47 | 48 | # Data converting 49 | simer.Data.Bfile2MVP(bfilePath, tempfile("outfile")) 50 | } 51 | } 52 | \author{ 53 | Haohao Zhang and Dong Yin 54 | } 55 | -------------------------------------------------------------------------------- /man/simer.Data.Impute.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Impute} 4 | \alias{simer.Data.Impute} 5 | \title{Genotype data imputation} 6 | \usage{ 7 | simer.Data.Impute( 8 | fileMVP = NULL, 9 | fileBed = NULL, 10 | out = NULL, 11 | maxLine = 10000, 12 | ncpus = 0, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{fileMVP}{genotype in MVP format.} 18 | 19 | \item{fileBed}{genotype in PLINK binary format.} 20 | 21 | \item{out}{the name of output file.} 22 | 23 | \item{maxLine}{number of SNPs, only used for saving memory when calculate kinship matrix.} 24 | 25 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 26 | 27 | \item{verbose}{whether to print detail.} 28 | } 29 | \value{ 30 | the function returns files 31 | \describe{ 32 | \item{.geno.desc}{the description file of genotype data.} 33 | \item{.geno.bin}{the binary file of genotype data.} 34 | \item{.geno.ind}{the genotyped individual file.} 35 | \item{.geno.map}{the marker information data file.} 36 | } 37 | } 38 | \description{ 39 | Impute the missing value within genotype data. 40 | } 41 | \details{ 42 | Build date: May 26, 2021 43 | Last update: Apr 28, 2022 44 | } 45 | \examples{ 46 | # Get the prefix of genotype data 47 | fileMVP <- system.file("extdata", "02plinkb", "demo", package = "simer") 48 | 49 | \dontrun{ 50 | # It needs 'beagle' software 51 | fileMVPimp <- simer.Data.Impute(fileBed = fileBed) 52 | } 53 | } 54 | \author{ 55 | Dong Yin 56 | } 57 | -------------------------------------------------------------------------------- /man/simer.Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data} 4 | \alias{simer.Data} 5 | \title{Data handling} 6 | \usage{ 7 | simer.Data(jsonList = NULL, out = "simer.qc", ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{jsonList}{a list of data quality control parameters.} 11 | 12 | \item{out}{the prefix of output files.} 13 | 14 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 15 | 16 | \item{verbose}{whether to print detail.} 17 | } 18 | \value{ 19 | the function returns a list containing 20 | \describe{ 21 | \item{$genotype}{the path of genotype data.} 22 | \item{$pedigree}{the filename of pedigree data.} 23 | \item{$selection_index}{the selection index for all traits.} 24 | \item{$breeding_value_index}{the breeding value index for all traits.} 25 | \item{$quality_control_plan}{a list of parameters for data quality control.} 26 | \item{$breeding_plan}{a list of parameters for genetic evaluation.} 27 | } 28 | } 29 | \description{ 30 | Make data quality control for genotype, phenotype, and pedigree. 31 | } 32 | \details{ 33 | Build date: May 26, 2021 34 | Last update: Jun 13, 2025 35 | } 36 | \examples{ 37 | # Read JSON file 38 | jsonFile <- system.file("extdata", "04breeding_plan", "plan1.json", package = "simer") 39 | jsonList <- jsonlite::fromJSON(txt = jsonFile, simplifyVector = FALSE) 40 | 41 | \dontrun{ 42 | # It needs "plink" and "hiblup" software 43 | jsonList <- simer.Data(jsonList = jsonList) 44 | } 45 | } 46 | \author{ 47 | Dong Yin 48 | } 49 | -------------------------------------------------------------------------------- /man/param.sel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Parameter.R 3 | \name{param.sel} 4 | \alias{param.sel} 5 | \title{Selection parameters generator} 6 | \usage{ 7 | param.sel(SP = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{...}{one or more parameter(s) for selection.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$sel$pop.sel}{the selected males and females.} 18 | \item{$sel$ps}{if ps <= 1, fraction selected in selection of males and females; if ps > 1, ps is number of selected males and females.} 19 | \item{$sel$decr}{whether the sort order is decreasing.} 20 | \item{$sel$sel.crit}{the selection criteria, it can be "TBV", "TGV", and "pheno".} 21 | \item{$sel$sel.single}{the single-trait selection method, it can be "ind", "fam", "infam", and "comb".} 22 | \item{$sel$sel.multi}{the multiple-trait selection method, it can be "index", "indcul", and "tmd".} 23 | \item{$sel$index.wt}{the weight of each trait for multiple-trait selection.} 24 | \item{$sel$index.tdm}{the index of tandem selection for multiple-trait selection.} 25 | \item{$sel$goal.perc}{the percentage of goal more than the mean of scores of individuals.} 26 | \item{$sel$pass.perc}{the percentage of expected excellent individuals.} 27 | } 28 | } 29 | \description{ 30 | Generate parameters for selection. 31 | } 32 | \details{ 33 | Build date: Apr 6, 2022 34 | Last update: Jul 4, 2022 35 | } 36 | \examples{ 37 | SP <- param.sel(sel.single = "ind") 38 | str(SP) 39 | } 40 | \author{ 41 | Dong Yin 42 | } 43 | -------------------------------------------------------------------------------- /man/param.global.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Parameter.R 3 | \name{param.global} 4 | \alias{param.global} 5 | \title{Global parameters generator} 6 | \usage{ 7 | param.global(SP = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{...}{one or more parameter(s) for global options.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$replication}{the replication times of simulation.} 18 | \item{$seed.sim}{simulation random seed.} 19 | \item{$out}{the prefix of output files.} 20 | \item{$outpath}{the path of output files, Simer writes files only if outpath is not "NULL".} 21 | \item{$out.format}{"numeric" or "plink", the data format of output files.} 22 | \item{$pop.gen}{the generations of simulated population.} 23 | \item{$out.geno.gen}{the output generations of genotype data.} 24 | \item{$out.pheno.gen}{the output generations of phenotype data.} 25 | \item{$useAllGeno}{whether to use all genotype data to simulate phenotype.} 26 | \item{$missing.geno}{the ratio of missing values in genotype data.} 27 | \item{$missing.phe}{the ratio of missing values in phenotype data.} 28 | \item{$ncpus}{the number of threads used, if it is 0, (logical core number - 1) is automatically used.} 29 | \item{$verbose}{whether to print detail.} 30 | } 31 | } 32 | \description{ 33 | Generate parameters for global options. 34 | } 35 | \details{ 36 | Build date: Apr 16, 2022 37 | Last update: Jul 4, 2022 38 | } 39 | \examples{ 40 | SP <- param.global(out = "simer") 41 | str(SP) 42 | } 43 | \author{ 44 | Dong Yin 45 | } 46 | -------------------------------------------------------------------------------- /man/simer.Data.Pheno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Pheno} 4 | \alias{simer.Data.Pheno} 5 | \title{Phenotype data quality control} 6 | \usage{ 7 | simer.Data.Pheno( 8 | filePhe = NULL, 9 | filePed = NULL, 10 | out = NULL, 11 | planPhe = NULL, 12 | pheCols = NULL, 13 | header = TRUE, 14 | sep = "\\t", 15 | missing = c(NA, "NA", "Na", ".", "-", "NAN", "nan", "na", "N/A", "n/a", "", "", 16 | "-9", 9999), 17 | verbose = TRUE 18 | ) 19 | } 20 | \arguments{ 21 | \item{filePhe}{the phenotype files, it can be a vector.} 22 | 23 | \item{filePed}{the pedigree files, it can be a vector.} 24 | 25 | \item{out}{the prefix of output file.} 26 | 27 | \item{planPhe}{the plans for phenotype quality control.} 28 | 29 | \item{pheCols}{the column needing extracting.} 30 | 31 | \item{header}{the header of file.} 32 | 33 | \item{sep}{the separator of file.} 34 | 35 | \item{missing}{the missing value.} 36 | 37 | \item{verbose}{whether to print detail.} 38 | } 39 | \value{ 40 | the function returns files 41 | \describe{ 42 | \item{.phe}{the phenotype file after correction.} 43 | } 44 | } 45 | \description{ 46 | Data quality control for phenotype data. 47 | } 48 | \details{ 49 | Build date: June 13, 2021 50 | Last update: Apr 28, 2022 51 | } 52 | \examples{ 53 | # Get the filename of phenotype data 54 | filePhe <- system.file("extdata", "05others", "phenotype.txt", package = "simer") 55 | 56 | # Run phenotype correction 57 | simer.Data.Pheno(filePhe = filePhe, out = tempfile("outfile")) 58 | } 59 | \author{ 60 | Haohao Zhang and Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: simer 2 | Title: Data Simulation for Life Science and Breeding 3 | Version: 1.0.0 4 | Date: 2025-2-25 5 | Authors@R: c( person("Dong", "Yin", role = "aut"), 6 | person("Xuanning", "Zhang", role = "aut"), 7 | person("Lilin", "Yin", role = "aut"), 8 | person("Haohao", "Zhang", role = "aut"), 9 | person("Zhenshuang", "Tang", role = "aut"), 10 | person("Jingya", "Xu", role = "aut"), 11 | person("Xiaohui", "Yuan", role = "aut"), 12 | person("Xiang", "Zhou", role = "aut"), 13 | person("Xinyun", "Li", role = "aut"), 14 | person("Shuhong", "Zhao", role = "aut"), 15 | person("Xiaolei", "Liu", role = c("cre", "aut", "cph"), email = "xll198708@gmail.com")) 16 | Description: Data simulator including genotype, phenotype, pedigree, 17 | selection and reproduction in R. It simulates most of reproduction process 18 | of animals or plants and provides data for GS (Genomic Selection), 19 | GWAS (Genome-Wide Association Study), and Breeding. 20 | For ADI model, please see Kao C and Zeng Z (2002) . 21 | For build.cov, please see B. D. Ripley (1987) . 22 | License: Apache License 2.0 23 | URL: https://github.com/xiaolei-lab/SIMER 24 | BugReports: https://github.com/xiaolei-lab/SIMER/issues 25 | Imports: utils, stats, Matrix, methods, MASS, bigmemory, jsonlite, Rcpp 26 | LinkingTo: Rcpp, RcppArmadillo, RcppProgress, BH, bigmemory 27 | Depends: R (>= 3.5.0) 28 | Suggests: knitr, igraph 29 | RoxygenNote: 7.3.2 30 | Encoding: UTF-8 31 | NeedsCompilation: yes 32 | Maintainer: Xiaolei Liu 33 | -------------------------------------------------------------------------------- /man/simer.Data.cHIBLUP.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.cHIBLUP} 4 | \alias{simer.Data.cHIBLUP} 5 | \title{Genetic evaluation} 6 | \usage{ 7 | simer.Data.cHIBLUP( 8 | jsonList = NULL, 9 | hiblupPath = "", 10 | mode = "A", 11 | vc.method = "AI", 12 | ncpus = 10, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{jsonList}{the list of genetic evaluation parameters.} 18 | 19 | \item{hiblupPath}{the path of HIBLUP software.} 20 | 21 | \item{mode}{'A' or 'AD', Additive effect model or Additive and Dominance model.} 22 | 23 | \item{vc.method}{default is 'AI', the method of calculating variance components in HIBLUP software.} 24 | 25 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 26 | 27 | \item{verbose}{whether to print detail.} 28 | } 29 | \value{ 30 | the function returns a list containing 31 | \describe{ 32 | \item{$randList}{a list of estimated random effects.} 33 | \item{$varList}{a list of variance components.} 34 | \item{$covA}{the genetic covariance matrix for all traits.} 35 | \item{$corA}{the genetic correlation matrix for all traits.} 36 | } 37 | } 38 | \description{ 39 | The function of calling HIBLUP software of C version. 40 | } 41 | \details{ 42 | Build date: June 28, 2021 43 | Last update: Apr 28, 2022 44 | } 45 | \examples{ 46 | # Read JSON file 47 | jsonFile <- system.file("extdata", "04breeding_plan", "plan1.json", package = "simer") 48 | jsonList <- jsonlite::fromJSON(txt = jsonFile, simplifyVector = FALSE) 49 | 50 | \dontrun{ 51 | # It needs "hiblup" software 52 | gebvs <- simer.Data.cHIBLUP(jsonList = jsonList) 53 | } 54 | } 55 | \author{ 56 | Dong Yin 57 | } 58 | -------------------------------------------------------------------------------- /man/simer.Data.SELIND.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.SELIND} 4 | \alias{simer.Data.SELIND} 5 | \title{Selection index construction} 6 | \usage{ 7 | simer.Data.SELIND(jsonList = NULL, hiblupPath = "", ncpus = 10, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{jsonList}{the list of selection index construction parameters.} 11 | 12 | \item{hiblupPath}{the path of HIBLUP software.} 13 | 14 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 15 | 16 | \item{verbose}{whether to print detail.} 17 | } 18 | \value{ 19 | the function returns a list containing 20 | \describe{ 21 | \item{$genotype}{the path of genotype data.} 22 | \item{$pedigree}{the filename of pedigree data.} 23 | \item{$selection_index}{the selection index for all traits.} 24 | \item{$breeding_value_index}{the breeding value index for all traits.} 25 | \item{$quality_control_plan}{a list of parameters for data quality control.} 26 | \item{$breeding_plan}{a list of parameters for genetic evaluation.} 27 | } 28 | } 29 | \description{ 30 | The function of General Selection Index. 31 | } 32 | \details{ 33 | Build date: Aug 26, 2021 34 | Last update: Apr 28, 2022 35 | } 36 | \examples{ 37 | # Read JSON file 38 | jsonFile <- system.file("extdata", "04breeding_plan", "plan1.json", package = "simer") 39 | jsonList <- jsonlite::fromJSON(txt = jsonFile, simplifyVector = FALSE) 40 | 41 | \dontrun{ 42 | # It needs "hiblup" software 43 | jsonList <- simer.Data.SELIND(jsonList = jsonList) 44 | } 45 | } 46 | \references{ 47 | Y. S. Chen, Z. L. Sheng (1988) The Theory of General Selection Index. Genetic Report, 15(3): P185-P190 48 | } 49 | \author{ 50 | Dong Yin 51 | } 52 | -------------------------------------------------------------------------------- /man/simer.Data.Env.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Env} 4 | \alias{simer.Data.Env} 5 | \title{Environmental factor selection} 6 | \usage{ 7 | simer.Data.Env( 8 | jsonList = NULL, 9 | hiblupPath = "", 10 | header = TRUE, 11 | sep = "\\t", 12 | ncpus = 10, 13 | verbose = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{jsonList}{the list of environmental factor selection parameters.} 18 | 19 | \item{hiblupPath}{the path of HIBLUP software.} 20 | 21 | \item{header}{the header of file.} 22 | 23 | \item{sep}{the separator of file.} 24 | 25 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 26 | 27 | \item{verbose}{whether to print detail.} 28 | } 29 | \value{ 30 | the function returns a list containing 31 | \describe{ 32 | \item{$genotype}{the path of genotype data.} 33 | \item{$pedigree}{the filename of pedigree data.} 34 | \item{$selection_index}{the selection index for all traits.} 35 | \item{$breeding_value_index}{the breeding value index for all traits.} 36 | \item{$quality_control_plan}{a list of parameters for data quality control.} 37 | \item{$breeding_plan}{a list of parameters for genetic evaluation.} 38 | } 39 | } 40 | \description{ 41 | To find appropriate fixed effects, covariates, and random effects. 42 | } 43 | \details{ 44 | Build date: July 17, 2021 45 | Last update: Apr 28, 2022 46 | } 47 | \examples{ 48 | # Read JSON file 49 | jsonFile <- system.file("extdata", "04breeding_plan", "plan1.json", package = "simer") 50 | jsonList <- jsonlite::fromJSON(txt = jsonFile, simplifyVector = FALSE) 51 | 52 | \dontrun{ 53 | # It needs "hiblup" solfware 54 | jsonList <- simer.Data.Env(jsonList = jsonList) 55 | } 56 | } 57 | \author{ 58 | Dong Yin 59 | } 60 | -------------------------------------------------------------------------------- /man/simer.Data.Json.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Json} 4 | \alias{simer.Data.Json} 5 | \title{Data quality control} 6 | \usage{ 7 | simer.Data.Json( 8 | jsonFile, 9 | hiblupPath = "", 10 | out = "simer.qc", 11 | dataQC = TRUE, 12 | buildModel = TRUE, 13 | buildIndex = TRUE, 14 | ncpus = 10, 15 | verbose = TRUE 16 | ) 17 | } 18 | \arguments{ 19 | \item{jsonFile}{the path of JSON file.} 20 | 21 | \item{hiblupPath}{the path of HIBLUP software.} 22 | 23 | \item{out}{the prefix of output files.} 24 | 25 | \item{dataQC}{whether to make data quality control.} 26 | 27 | \item{buildModel}{whether to build EBV model.} 28 | 29 | \item{buildIndex}{whether to build Selection Index.} 30 | 31 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 32 | 33 | \item{verbose}{whether to print detail.} 34 | } 35 | \value{ 36 | the function returns a list containing 37 | \describe{ 38 | \item{$genotype}{the path of genotype data.} 39 | \item{$pedigree}{the filename of pedigree data.} 40 | \item{$selection_index}{the selection index for all traits.} 41 | \item{$breeding_value_index}{the breeding value index for all traits.} 42 | \item{$quality_control_plan}{a list of parameters for data quality control.} 43 | \item{$breeding_plan}{a list of parameters for genetic evaluation.} 44 | } 45 | } 46 | \description{ 47 | Make data quality control by JSON file. 48 | } 49 | \details{ 50 | Build date: Oct 19, 2020 51 | Last update: Apr 28, 2022 52 | } 53 | \examples{ 54 | # Get JSON file 55 | jsonFile <- system.file("extdata", "04breeding_plan", "plan1.json", package = "simer") 56 | 57 | \dontrun{ 58 | # It needs "plink" and "hiblup" software 59 | jsonList <- simer.Data.Json(jsonFile = jsonFile) 60 | } 61 | } 62 | \author{ 63 | Dong Yin 64 | } 65 | -------------------------------------------------------------------------------- /man/param.pheno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Parameter.R 3 | \name{param.pheno} 4 | \alias{param.pheno} 5 | \title{Phenotype parameters generator} 6 | \usage{ 7 | param.pheno(SP = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{...}{one or more parameter(s) for phenotype simulation.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$pheno$pop}{the population information containing environmental factors and other effects.} 18 | \item{$pheno$pop.ind}{the number of individuals in the base population.} 19 | \item{$pheno$pop.rep}{the repeated times of repeated records.} 20 | \item{$pheno$pop.rep.bal}{whether repeated records are balanced.} 21 | \item{$pheno$pop.env}{a list of environmental factors setting.} 22 | \item{$pheno$phe.type}{a list of phenotype types.} 23 | \item{$pheno$phe.model}{a list of genetic model of phenotype such as "T1 = A + E".} 24 | \item{$pheno$phe.h2A}{a list of additive heritability.} 25 | \item{$pheno$phe.h2D}{a list of dominant heritability.} 26 | \item{$pheno$phe.h2GxG}{a list of GxG interaction heritability.} 27 | \item{$pheno$phe.h2GxE}{a list of GxE interaction heritability.} 28 | \item{$pheno$phe.h2PE}{a list of permanent environmental heritability.} 29 | \item{$pheno$phe.var}{a list of phenotype variance.} 30 | \item{$pheno$phe.corA}{the additive genetic correlation matrix.} 31 | \item{$pheno$phe.corD}{the dominant genetic correlation matrix.} 32 | \item{$pheno$phe.corGxG}{the GxG genetic correlation matrix.} 33 | \item{$pheno$phe.corPE}{the permanent environmental correlation matrix.} 34 | \item{$pheno$phe.corE}{the residual correlation matrix.} 35 | } 36 | } 37 | \description{ 38 | Generate parameters for phenotype data simulation. 39 | } 40 | \details{ 41 | Build date: Feb 21, 2022 42 | Last update: Jul 4, 2022 43 | } 44 | \examples{ 45 | SP <- param.pheno(phe.model = list(tr1 = "T1 = A + E")) 46 | str(SP) 47 | } 48 | \author{ 49 | Dong Yin 50 | } 51 | -------------------------------------------------------------------------------- /man/mate.clone.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.clone} 4 | \alias{mate.clone} 5 | \title{Clone} 6 | \usage{ 7 | mate.clone(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by clone. 29 | } 30 | \details{ 31 | Build date: Nov 14, 2018 32 | Last update: Jan 28, 2025 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "clone") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | # Run clone 56 | SP <- mate.clone(SP) 57 | } 58 | } 59 | \author{ 60 | Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /man/mate.dh.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.dh} 4 | \alias{mate.dh} 5 | \title{Doubled haploid} 6 | \usage{ 7 | mate.dh(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by doubled haploid. 29 | } 30 | \details{ 31 | Build date: Nov 14, 2018 32 | Last update: Jan 28, 2025 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "dh") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | # Run doubled haploid 56 | SP <- mate.dh(SP) 57 | } 58 | } 59 | \author{ 60 | Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /man/mate.userped.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.userped} 4 | \alias{mate.userped} 5 | \title{User-specified pedigree mating} 6 | \usage{ 7 | mate.userped(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.sel}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$reprod$userped}{the pedigree designed by user.} 24 | \item{$geno}{a list of genotype simulation parameters.} 25 | \item{$pheno}{a list of phenotype simulation parameters.} 26 | } 27 | } 28 | \description{ 29 | Produce individuals by user-specified pedigree mating. 30 | } 31 | \details{ 32 | Build date: Apr 12, 2022 33 | Last update: Feb 18, 2025 34 | } 35 | \examples{ 36 | \donttest{ 37 | # Generate annotation simulation parameters 38 | SP <- param.annot(qtn.num = list(tr1 = 10)) 39 | # Generate genotype simulation parameters 40 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 41 | # Generate phenotype simulation parameters 42 | SP <- param.pheno(SP = SP, pop.ind = 100) 43 | # Generate reproduction parameters 44 | SP <- param.reprod(SP = SP, reprod.way = "userped") 45 | 46 | # Run annotation simulation 47 | SP <- annotation(SP) 48 | # Run genotype simulation 49 | SP <- genotype(SP) 50 | # Run phenotype simulation 51 | SP <- phenotype(SP) 52 | # Run user-specified pedigree mating 53 | SP <- mate.userped(SP) 54 | } 55 | } 56 | \author{ 57 | Dong Yin 58 | } 59 | -------------------------------------------------------------------------------- /man/mate.assort.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.assort} 4 | \alias{mate.assort} 5 | \title{Assortative mating} 6 | \usage{ 7 | mate.assort(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by assortative mating. 29 | } 30 | \details{ 31 | Build date: Sep 30, 2022 32 | Last update: Sep 30, 2022 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "assort") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | # Run random mating 56 | SP <- mate.assort(SP) 57 | } 58 | } 59 | \author{ 60 | Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /man/mate.randmate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.randmate} 4 | \alias{mate.randmate} 5 | \title{Random mating} 6 | \usage{ 7 | mate.randmate(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by random-mating. 29 | } 30 | \details{ 31 | Build date: Nov 14, 2018 32 | Last update: Apr 30, 2022 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "randmate") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | # Run random mating 56 | SP <- mate.randmate(SP) 57 | } 58 | } 59 | \author{ 60 | Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /man/mate.selfpol.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.selfpol} 4 | \alias{mate.selfpol} 5 | \title{Self-pollination} 6 | \usage{ 7 | mate.selfpol(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by self-pollination. 29 | } 30 | \details{ 31 | Build date: Nov 14, 2018 32 | Last update: Apr 30, 2022 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "selfpol") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | # Run self-pollination 56 | SP <- mate.selfpol(SP) 57 | } 58 | } 59 | \author{ 60 | Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /man/mate.disassort.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.disassort} 4 | \alias{mate.disassort} 5 | \title{Disassortative mating} 6 | \usage{ 7 | mate.disassort(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by disassortative mating. 29 | } 30 | \details{ 31 | Build date: Sep 30, 2022 32 | Last update: Sep 30, 2022 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "disassort") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | # Run random mating 56 | SP <- mate.disassort(SP) 57 | } 58 | } 59 | \author{ 60 | Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /man/reproduces.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{reproduces} 4 | \alias{reproduces} 5 | \title{Reproduction} 6 | \usage{ 7 | reproduces(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of "clone", "dh", "selfpol", "randmate", "randexself", "assort", "disassort", "2waycro", "3waycro", "4waycro", "backcro", and "userped".} 21 | \item{$reprod$sex.rate}{the male rate in the population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$reprod$userped}{the pedigree designed by user.} 24 | \item{$geno}{a list of genotype simulation parameters.} 25 | \item{$pheno}{a list of phenotype simulation parameters.} 26 | } 27 | } 28 | \description{ 29 | Population reproduction by different mate design. 30 | } 31 | \details{ 32 | Build date: Nov 14, 2018 33 | Last update: May 28, 2025 34 | } 35 | \examples{ 36 | \donttest{ 37 | # Generate annotation simulation parameters 38 | SP <- param.annot(qtn.num = list(tr1 = 10)) 39 | # Generate genotype simulation parameters 40 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 41 | # Generate phenotype simulation parameters 42 | SP <- param.pheno(SP = SP, pop.ind = 100) 43 | # Generate selection parameters 44 | SP <- param.sel(SP = SP, sel.single = "ind") 45 | # Generate reproduction parameters 46 | SP <- param.reprod(SP = SP, reprod.way = "randmate") 47 | 48 | # Run annotation simulation 49 | SP <- annotation(SP) 50 | # Run genotype simulation 51 | SP <- genotype(SP) 52 | # Run phenotype simulation 53 | SP <- phenotype(SP) 54 | # Run selection 55 | SP <- selects(SP) 56 | # Run reproduction 57 | SP <- reproduces(SP) 58 | } 59 | } 60 | \author{ 61 | Dong Yin 62 | } 63 | -------------------------------------------------------------------------------- /man/print_info.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Utility.R 3 | \name{print_info} 4 | \alias{print_info} 5 | \title{Simer information} 6 | \usage{ 7 | print_info( 8 | welcome = NULL, 9 | title = NULL, 10 | short_title = NULL, 11 | logo = NULL, 12 | version = NULL, 13 | authors = NULL, 14 | contact = NULL, 15 | linechar = "=", 16 | width = NULL, 17 | verbose = TRUE 18 | ) 19 | } 20 | \arguments{ 21 | \item{welcome}{welcome text, for example: "Welcom to ".} 22 | 23 | \item{title}{long text to introduct package.} 24 | 25 | \item{short_title}{short label, top-left of logo.} 26 | 27 | \item{logo}{logo.} 28 | 29 | \item{version}{short label, bottom-right of logo.} 30 | 31 | \item{authors}{authors of software.} 32 | 33 | \item{contact}{email or website.} 34 | 35 | \item{linechar}{1, 2, or char.} 36 | 37 | \item{width}{banner width.} 38 | 39 | \item{verbose}{whether to print detail.} 40 | } 41 | \value{ 42 | welcome information. 43 | } 44 | \description{ 45 | Print R Package information, include title, short_title, logo, version, authors, contact. 46 | } 47 | \details{ 48 | Build date: Oct 22, 2018 49 | Last update: Apr 30, 2022 50 | } 51 | \examples{ 52 | welcome <- "Welcome to SIMER" 53 | title <- "Data Simulation for Life Science and Breeding" 54 | authors <- c("Designed and Maintained by Dong Yin, Xuanning Zhang, 55 | Lilin Yin, Haohao Zhang, and Xiaolei Liu", 56 | "Contributors: Zhenshuang Tang, Jingya Xu, Xinyun Li, 57 | Mengjin Zhu, Xiaohui Yuan, Shuhong Zhao") 58 | contact <- "Contact: xiaoleiliu@mail.hzau.edu.cn" 59 | logo_s <- c(" ____ ___ __ __ _____ ____ ", 60 | "/ ___|_ _| \\\\/ | ____| _ \\\\ ", 61 | "\\\\___ \\\\| || |\\\\/| | _| | |_) |", 62 | " ___) | || | | | |___| _ < ", 63 | "|____/___|_| |_|_____|_| \\\\_\\\\") 64 | print_info(welcome = welcome, title = title, logo = logo_s, authors = authors, 65 | contact = contact, linechar = '=', width = 70) 66 | } 67 | \author{ 68 | Dong Yin and Haohao Zhang 69 | } 70 | \keyword{internal} 71 | -------------------------------------------------------------------------------- /man/mate.backcro.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.backcro} 4 | \alias{mate.backcro} 5 | \title{Back cross} 6 | \usage{ 7 | mate.backcro(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by back cross. 29 | } 30 | \details{ 31 | Build date: Apr 12, 2022 32 | Last update: Jan 28, 2025 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "backcro") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Two different breeds are cut by sex 54 | SP$pheno$pop$gen1$sex <- rep(c(1, 2), c(50, 50)) 55 | # Run selection 56 | SP <- selects(SP) 57 | # Run back cross 58 | SP <- mate.backcro(SP) 59 | } 60 | } 61 | \author{ 62 | Dong Yin 63 | } 64 | -------------------------------------------------------------------------------- /man/mate.randexself.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.randexself} 4 | \alias{mate.randexself} 5 | \title{Random mating excluding self-pollination} 6 | \usage{ 7 | mate.randexself(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by random mating excluding self-pollination. 29 | } 30 | \details{ 31 | Build date: Nov 14, 2018 32 | Last update: Apr 30, 2022 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "randexself") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | # Run random mating excluding self-pollination 56 | SP <- mate.randexself(SP) 57 | } 58 | } 59 | \author{ 60 | Dong Yin 61 | } 62 | -------------------------------------------------------------------------------- /inst/extdata/03plinkp/demo.map: -------------------------------------------------------------------------------- 1 | 0 SNP00001 0 0 2 | 0 SNP00002 0 0 3 | 0 SNP00003 0 0 4 | 0 SNP00004 0 0 5 | 0 SNP00005 0 0 6 | 0 SNP00006 0 0 7 | 0 SNP00007 0 0 8 | 0 SNP00008 0 0 9 | 0 SNP00009 0 0 10 | 0 SNP00010 0 0 11 | 0 SNP00011 0 0 12 | 0 SNP00012 0 0 13 | 0 SNP00013 0 0 14 | 0 SNP00014 0 0 15 | 0 SNP00015 0 0 16 | 0 SNP00016 0 0 17 | 0 SNP00017 0 0 18 | 0 SNP00018 0 0 19 | 0 SNP00019 0 0 20 | 0 SNP00020 0 0 21 | 0 SNP00021 0 0 22 | 0 SNP00022 0 0 23 | 0 SNP00023 0 0 24 | 0 SNP00024 0 0 25 | 0 SNP00025 0 0 26 | 0 SNP00026 0 0 27 | 0 SNP00027 0 0 28 | 0 SNP00028 0 0 29 | 0 SNP00029 0 0 30 | 0 SNP00030 0 0 31 | 0 SNP00031 0 0 32 | 0 SNP00032 0 0 33 | 0 SNP00033 0 0 34 | 0 SNP00034 0 0 35 | 0 SNP00035 0 0 36 | 0 SNP00036 0 0 37 | 0 SNP00037 0 0 38 | 0 SNP00038 0 0 39 | 0 SNP00039 0 0 40 | 0 SNP00040 0 0 41 | 0 SNP00041 0 0 42 | 0 SNP00042 0 0 43 | 0 SNP00043 0 0 44 | 0 SNP00044 0 0 45 | 0 SNP00045 0 0 46 | 0 SNP00046 0 0 47 | 0 SNP00047 0 0 48 | 0 SNP00048 0 0 49 | 0 SNP00049 0 0 50 | 0 SNP00050 0 0 51 | 0 SNP00051 0 0 52 | 0 SNP00052 0 0 53 | 0 SNP00053 0 0 54 | 0 SNP00054 0 0 55 | 0 SNP00055 0 0 56 | 0 SNP00056 0 0 57 | 0 SNP00057 0 0 58 | 0 SNP00058 0 0 59 | 0 SNP00059 0 0 60 | 0 SNP00060 0 0 61 | 0 SNP00061 0 0 62 | 0 SNP00062 0 0 63 | 0 SNP00063 0 0 64 | 0 SNP00064 0 0 65 | 0 SNP00065 0 0 66 | 0 SNP00066 0 0 67 | 0 SNP00067 0 0 68 | 0 SNP00068 0 0 69 | 0 SNP00069 0 0 70 | 0 SNP00070 0 0 71 | 0 SNP00071 0 0 72 | 0 SNP00072 0 0 73 | 0 SNP00073 0 0 74 | 0 SNP00074 0 0 75 | 0 SNP00075 0 0 76 | 0 SNP00076 0 0 77 | 0 SNP00077 0 0 78 | 0 SNP00078 0 0 79 | 0 SNP00079 0 0 80 | 0 SNP00080 0 0 81 | 0 SNP00081 0 0 82 | 0 SNP00082 0 0 83 | 0 SNP00083 0 0 84 | 0 SNP00084 0 0 85 | 0 SNP00085 0 0 86 | 0 SNP00086 0 0 87 | 0 SNP00087 0 0 88 | 0 SNP00088 0 0 89 | 0 SNP00089 0 0 90 | 0 SNP00090 0 0 91 | 0 SNP00091 0 0 92 | 0 SNP00092 0 0 93 | 0 SNP00093 0 0 94 | 0 SNP00094 0 0 95 | 0 SNP00095 0 0 96 | 0 SNP00096 0 0 97 | 0 SNP00097 0 0 98 | 0 SNP00098 0 0 99 | 0 SNP00099 0 0 100 | 0 SNP00100 0 0 101 | -------------------------------------------------------------------------------- /man/mate.3waycro.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.3waycro} 4 | \alias{mate.3waycro} 5 | \title{Three-way cross} 6 | \usage{ 7 | mate.3waycro(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by three-way cross. 29 | } 30 | \details{ 31 | Build date: Apr 11, 2022 32 | Last update: Jan 28, 2025 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "3waycro") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Three different breeds are cut by sex 54 | SP$pheno$pop$gen1$sex <- rep(c(1, 2, 1), c(30, 30, 40)) 55 | # Run selection 56 | SP <- selects(SP) 57 | # Run three-way cross 58 | SP <- mate.3waycro(SP) 59 | } 60 | } 61 | \author{ 62 | Dong Yin 63 | } 64 | -------------------------------------------------------------------------------- /man/selects.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Selects.R 3 | \name{selects} 4 | \alias{selects} 5 | \title{Selection} 6 | \usage{ 7 | selects(SP = NULL, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{verbose}{whether to print detail.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$sel$pop.sel}{the selected males and females.} 18 | \item{$sel$ps}{if ps <= 1, fraction selected in selection of males and females; if ps > 1, ps is number of selected males and females.} 19 | \item{$sel$decr}{whether the sort order is decreasing.} 20 | \item{$sel$sel.crit}{the selection criteria, it can be "TBV", "TGV", and "pheno".} 21 | \item{$sel$sel.single}{the single-trait selection method, it can be "ind", "fam", "infam", and "comb".} 22 | \item{$sel$sel.multi}{the multiple-trait selection method, it can be "index", "indcul", and "tmd".} 23 | \item{$sel$index.wt}{the weight of each trait for multiple-trait selection.} 24 | \item{$sel$index.tdm}{the index of tandem selection for multiple-trait selection.} 25 | \item{$sel$goal.perc}{the percentage of goal more than the mean of scores of individuals.} 26 | \item{$sel$pass.perc}{the percentage of expected excellent individuals.} 27 | } 28 | } 29 | \description{ 30 | Select individuals by combination of selection method and criterion. 31 | } 32 | \details{ 33 | Build date: Sep 8, 2018 34 | Last update: Apr 19, 2025 35 | } 36 | \examples{ 37 | \donttest{ 38 | # Generate annotation simulation parameters 39 | SP <- param.annot(qtn.num = list(tr1 = 10)) 40 | # Generate genotype simulation parameters 41 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 42 | # Generate phenotype simulation parameters 43 | SP <- param.pheno(SP = SP, pop.ind = 100) 44 | # Generate selection parameters 45 | SP <- param.sel(SP = SP, sel.single = "ind") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Run selection 54 | SP <- selects(SP) 55 | } 56 | } 57 | \author{ 58 | Dong Yin 59 | } 60 | -------------------------------------------------------------------------------- /man/mate.2waycro.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.2waycro} 4 | \alias{mate.2waycro} 5 | \title{Two-way cross} 6 | \usage{ 7 | mate.2waycro(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by two-way cross. 29 | } 30 | \details{ 31 | Build date: Nov 14, 2018 32 | Last update: Apr 30, 2022 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "2waycro") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Two different breeds are cut by sex 54 | SP$pheno$pop$gen1$sex <- rep(c(1, 2), c(50, 50)) 55 | # Run selection 56 | SP <- selects(SP) 57 | # Run two-way cross 58 | SP <- mate.2waycro(SP) 59 | } 60 | } 61 | \author{ 62 | Dong Yin 63 | } 64 | -------------------------------------------------------------------------------- /man/mate.4waycro.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Reproduces.R 3 | \name{mate.4waycro} 4 | \alias{mate.4waycro} 5 | \title{Four-way cross process} 6 | \usage{ 7 | mate.4waycro(SP, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$reprod$pop.gen}{the generations of simulated population.} 20 | \item{$reprod$reprod.way}{reproduction method, it consists of 'clone', 'dh', 'selfpol', 'randmate', 'randexself', 'assort', 'disassort', '2waycro', '3waycro', '4waycro', 'backcro', and 'userped'.} 21 | \item{$reprod$sex.rate}{the sex ratio of simulated population.} 22 | \item{$reprod$prog}{the progeny number of an individual.} 23 | \item{$geno}{a list of genotype simulation parameters.} 24 | \item{$pheno}{a list of phenotype simulation parameters.} 25 | } 26 | } 27 | \description{ 28 | Produce individuals by four-way cross. 29 | } 30 | \details{ 31 | Build date: Apr 11, 2022 32 | Last update: Jan 28, 2025 33 | } 34 | \examples{ 35 | \donttest{ 36 | # Generate annotation simulation parameters 37 | SP <- param.annot(qtn.num = list(tr1 = 10)) 38 | # Generate genotype simulation parameters 39 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 40 | # Generate phenotype simulation parameters 41 | SP <- param.pheno(SP = SP, pop.ind = 100) 42 | # Generate selection parameters 43 | SP <- param.sel(SP = SP, sel.single = "ind") 44 | # Generate reproduction parameters 45 | SP <- param.reprod(SP = SP, reprod.way = "4waycro") 46 | 47 | # Run annotation simulation 48 | SP <- annotation(SP) 49 | # Run genotype simulation 50 | SP <- genotype(SP) 51 | # Run phenotype simulation 52 | SP <- phenotype(SP) 53 | # Four different breeds are cut by sex 54 | SP$pheno$pop$gen1$sex <- rep(c(1, 2, 1, 2), c(25, 25, 25, 25)) 55 | # Run selection 56 | SP <- selects(SP) 57 | # Run four-way cross 58 | SP <- mate.4waycro(SP) 59 | } 60 | } 61 | \author{ 62 | Dong Yin 63 | } 64 | -------------------------------------------------------------------------------- /man/simer.Data.Ped.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Ped} 4 | \alias{simer.Data.Ped} 5 | \title{Pedigree data quality control} 6 | \usage{ 7 | simer.Data.Ped( 8 | filePed, 9 | fileMVP = NULL, 10 | out = NULL, 11 | standardID = FALSE, 12 | fileSir = NULL, 13 | fileDam = NULL, 14 | exclThres = 0.1, 15 | assignThres = 0.05, 16 | header = TRUE, 17 | sep = "\\t", 18 | ncpus = 0, 19 | verbose = TRUE 20 | ) 21 | } 22 | \arguments{ 23 | \item{filePed}{the filename of pedigree need correcting.} 24 | 25 | \item{fileMVP}{genotype in MVP format.} 26 | 27 | \item{out}{the prefix of output file.} 28 | 29 | \item{standardID}{whether kid id is 15-character standard.} 30 | 31 | \item{fileSir}{the filename of candidate sires.} 32 | 33 | \item{fileDam}{the filename of candidate dams.} 34 | 35 | \item{exclThres}{if conflict ratio is more than exclThres, exclude this parent.} 36 | 37 | \item{assignThres}{if conflict ratio is less than assignThres, assign this parent to the individual.} 38 | 39 | \item{header}{whether the file contains header.} 40 | 41 | \item{sep}{separator of the file.} 42 | 43 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 44 | 45 | \item{verbose}{whether to print detail.} 46 | } 47 | \value{ 48 | the function returns files 49 | \describe{ 50 | \item{.ped.report}{the report file containing correction condition.} 51 | \item{.ped.error}{the file containing pedigree error.} 52 | \item{.ped}{the pedigree file after correction.} 53 | } 54 | } 55 | \description{ 56 | Data quality control for pedigree data. 57 | } 58 | \details{ 59 | Build date: May 6, 2021 60 | Last update: Apr 3, 2025 61 | } 62 | \examples{ 63 | \donttest{ 64 | # Get the filename of pedigree data 65 | filePed <- system.file("extdata", "05others", "pedigree.txt", package = "simer") 66 | 67 | # Get the prefix of genotype data 68 | fileMVP <- system.file("extdata", "01bigmemory", "demo", package = "simer") 69 | 70 | # Run pedigree correction 71 | simer.Data.Ped(filePed = filePed, fileMVP = fileMVP, out = tempfile("outfile")) 72 | } 73 | } 74 | \author{ 75 | Lilin Yin and Dong Yin 76 | } 77 | -------------------------------------------------------------------------------- /man/simer.Data.Geno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Data.R 3 | \name{simer.Data.Geno} 4 | \alias{simer.Data.Geno} 5 | \title{Genotype data quality control} 6 | \usage{ 7 | simer.Data.Geno( 8 | fileMVP = NULL, 9 | fileBed = NULL, 10 | filePlinkPed = NULL, 11 | filePed = NULL, 12 | filePhe = NULL, 13 | out = "simer.qc", 14 | genoType = "char", 15 | filter = NULL, 16 | filterGeno = NULL, 17 | filterHWE = NULL, 18 | filterMind = NULL, 19 | filterMAF = NULL, 20 | ncpus = 0, 21 | verbose = TRUE 22 | ) 23 | } 24 | \arguments{ 25 | \item{fileMVP}{genotype in MVP format.} 26 | 27 | \item{fileBed}{genotype in PLINK binary format.} 28 | 29 | \item{filePlinkPed}{genotype in PLINK numeric format.} 30 | 31 | \item{filePed}{the filename of pedigree data.} 32 | 33 | \item{filePhe}{the filename of phenotype data, it can be a vector.} 34 | 35 | \item{out}{the prefix of output files.} 36 | 37 | \item{genoType}{type parameter in bigmemory, genotype data. The default is char, it is highly recommended *NOT* to modify this parameter.} 38 | 39 | \item{filter}{filter of genotyped individual.} 40 | 41 | \item{filterGeno}{threshold of sample miss rate.} 42 | 43 | \item{filterHWE}{threshold of Hardy-Weinberg Test.} 44 | 45 | \item{filterMind}{threshold of variant miss rate.} 46 | 47 | \item{filterMAF}{threshold of Minor Allele Frequency.} 48 | 49 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 50 | 51 | \item{verbose}{whether to print detail.} 52 | } 53 | \value{ 54 | the function returns files 55 | \describe{ 56 | \item{.bed}{the .bed file of PLINK binary format.} 57 | \item{.bim}{the .bim file of PLINK binary format.} 58 | \item{.fam}{the .fam file of PLINK binary format.} 59 | } 60 | } 61 | \description{ 62 | Data quality control for genotype data in MVP format and PLINK format. 63 | } 64 | \details{ 65 | Build date: May 26, 2021 66 | Last update: Apr 28, 2022 67 | } 68 | \examples{ 69 | # Get the prefix of genotype data 70 | fileBed <- system.file("extdata", "02plinkb", "demo", package = "simer") 71 | 72 | \dontrun{ 73 | # It needs "plink" software 74 | simer.Data.Geno(fileBed=fileBed) 75 | } 76 | } 77 | \author{ 78 | Dong Yin 79 | } 80 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(GxG.network) 4 | export(IndPerGen) 5 | export(annotation) 6 | export(bigt) 7 | export(build.cov) 8 | export(cal.eff) 9 | export(checkEnv) 10 | export(format_time) 11 | export(generate.map) 12 | export(generate.pop) 13 | export(geno.cvt1) 14 | export(geno.cvt2) 15 | export(genotype) 16 | export(getfam) 17 | export(logging.log) 18 | export(logging.print) 19 | export(mate) 20 | export(mate.2waycro) 21 | export(mate.3waycro) 22 | export(mate.4waycro) 23 | export(mate.assort) 24 | export(mate.backcro) 25 | export(mate.clone) 26 | export(mate.dh) 27 | export(mate.disassort) 28 | export(mate.randexself) 29 | export(mate.randmate) 30 | export(mate.selfpol) 31 | export(mate.userped) 32 | export(param.annot) 33 | export(param.geno) 34 | export(param.global) 35 | export(param.pheno) 36 | export(param.reprod) 37 | export(param.sel) 38 | export(param.simer) 39 | export(phenotype) 40 | export(print_info) 41 | export(remove_bigmatrix) 42 | export(reproduces) 43 | export(selects) 44 | export(simer) 45 | export(simer.Data) 46 | export(simer.Data.Bfile2MVP) 47 | export(simer.Data.Env) 48 | export(simer.Data.Geno) 49 | export(simer.Data.Impute) 50 | export(simer.Data.Json) 51 | export(simer.Data.MVP2Bfile) 52 | export(simer.Data.MVP2MVP) 53 | export(simer.Data.Map) 54 | export(simer.Data.Ped) 55 | export(simer.Data.Pheno) 56 | export(simer.Data.SELIND) 57 | export(simer.Data.cHIBLUP) 58 | export(simer.Version) 59 | export(write.file) 60 | import(Rcpp) 61 | import(bigmemory) 62 | import(jsonlite) 63 | importFrom(MASS,ginv) 64 | importFrom(MASS,mvrnorm) 65 | importFrom(Matrix,bdiag) 66 | importFrom(methods,getPackageName) 67 | importFrom(stats,aov) 68 | importFrom(stats,cor) 69 | importFrom(stats,dnorm) 70 | importFrom(stats,formula) 71 | importFrom(stats,lm) 72 | importFrom(stats,model.matrix) 73 | importFrom(stats,na.omit) 74 | importFrom(stats,qnorm) 75 | importFrom(stats,rbeta) 76 | importFrom(stats,rgamma) 77 | importFrom(stats,rgeom) 78 | importFrom(stats,rnorm) 79 | importFrom(stats,runif) 80 | importFrom(stats,sd) 81 | importFrom(stats,shapiro.test) 82 | importFrom(stats,step) 83 | importFrom(stats,var) 84 | importFrom(utils,packageVersion) 85 | importFrom(utils,read.delim) 86 | importFrom(utils,read.table) 87 | importFrom(utils,str) 88 | importFrom(utils,write.table) 89 | useDynLib(simer) 90 | -------------------------------------------------------------------------------- /man/param.annot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Parameter.R 3 | \name{param.annot} 4 | \alias{param.annot} 5 | \title{Annotation parameters generator} 6 | \usage{ 7 | param.annot(SP = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{...}{one or more parameter(s) for map simulation.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$map$pop.map}{the map data with annotation information.} 18 | \item{$map$species}{the species of genetic map, which can be "arabidopsis", "cattle", "chicken", "dog", "horse", "human", "maize", "mice", "pig", and "rice".} 19 | \item{$map$pop.marker}{the number of markers.} 20 | \item{$map$num.chr}{the number of chromosomes.} 21 | \item{$map$len.chr}{the length of chromosomes.} 22 | \item{$map$qtn.model}{the genetic model of QTN such as "A + D".} 23 | \item{$map$qtn.index}{the QTN index for each trait.} 24 | \item{$map$qtn.num}{the QTN number for (each group in) each trait.} 25 | \item{$map$qtn.dist}{the QTN distribution containing "norm", "geom", "gamma" or "beta".} 26 | \item{$map$qtn.var}{the standard deviations for normal distribution.} 27 | \item{$map$qtn.prob}{the probability of success for geometric distribution.} 28 | \item{$map$qtn.shape}{the shape parameter for gamma distribution.} 29 | \item{$map$qtn.scale}{the scale parameter for gamma distribution.} 30 | \item{$map$qtn.shape1}{the shape1 parameter for beta distribution.} 31 | \item{$map$qtn.shape2}{the shape2 parameter for beta distribution.} 32 | \item{$map$qtn.ncp}{the ncp parameter for beta distribution.} 33 | \item{$map$qtn.spot}{the QTN distribution probability in each block.} 34 | \item{$map$len.block}{the block length.} 35 | \item{$map$maf}{the maf threshold, markers less than this threshold will be exclude.} 36 | \item{$map$recom.spot}{whether to generate recombination events.} 37 | \item{$map$range.hot}{the recombination times range in the hot spot.} 38 | \item{$map$range.cold}{the recombination times range in the cold spot.} 39 | } 40 | } 41 | \description{ 42 | Generate parameters for annotation data simulation. 43 | } 44 | \details{ 45 | Build date: Feb 24, 2022 46 | Last update: Jul 10, 2022 47 | } 48 | \examples{ 49 | SP <- param.annot(qtn.num = list(tr1 = 10)) 50 | str(SP) 51 | } 52 | \author{ 53 | Dong Yin 54 | } 55 | -------------------------------------------------------------------------------- /inst/extdata/04breeding_plan/plan2.json: -------------------------------------------------------------------------------- 1 | { 2 | "genotype": "../02plinkb", 3 | "pedigree": "../05others/pedigree.txt", 4 | "threads": 16, 5 | "auto_optimization": true, 6 | "quality_control_plan": { 7 | "genotype_quality_control":{ 8 | "filter": "F1 == 'Male'", 9 | "filter_geno": 0.1, 10 | "filter_mind": 0.1, 11 | "filter_maf": 0.05, 12 | "filter_hwe": 0.001 13 | }, 14 | "pedigree_quality_control":{ 15 | "standard_ID": false, 16 | "candidate_sire_file": [], 17 | "candidate_dam_file": [], 18 | "exclude_threshold": 0.1, 19 | "assign_threshold": 0.05 20 | }, 21 | "phenotype_quality_control":[ 22 | { 23 | "job_name": "Data_Quality_Control_Demo", 24 | "sample_info": "../05others/phenotype.txt", 25 | "repeated_records": false, 26 | "multi_trait": true, 27 | "filter": "F1 == 'Male'", 28 | "job_traits": [ 29 | { 30 | "traits": "T1", 31 | "definition": "T1", 32 | "range": [] 33 | }, 34 | { 35 | "traits": "T2", 36 | "definition": "T2", 37 | "range": [] 38 | } 39 | ] 40 | } 41 | ] 42 | }, 43 | "breeding_plan":[ 44 | { 45 | "job_name": "EBV_Model_Demo", 46 | "sample_info": "../05others/phenotype.txt", 47 | "repeated_records": false, 48 | "multi_trait": true, 49 | "vc_vars": [], 50 | "vc_covars": [], 51 | "random_ratio": 0.05, 52 | "job_traits": [ 53 | { 54 | "traits": "T1", 55 | "covariates": [], 56 | "fixed_effects": ["F1", "F2"], 57 | "random_effects": ["R1"] 58 | }, 59 | { 60 | "traits": "T2", 61 | "covariates": [], 62 | "fixed_effects": ["F1", "F2"], 63 | "random_effects": ["R1"] 64 | } 65 | ] 66 | } 67 | ] 68 | } -------------------------------------------------------------------------------- /inst/extdata/01bigmemory/demo.geno.map: -------------------------------------------------------------------------------- 1 | SNP CHROM POS REF ALT 2 | SNP00001 0 0 C T 3 | SNP00002 0 0 G A 4 | SNP00003 0 0 A G 5 | SNP00004 0 0 C T 6 | SNP00005 0 0 C T 7 | SNP00006 0 0 C T 8 | SNP00007 0 0 G A 9 | SNP00008 0 0 A G 10 | SNP00009 0 0 T C 11 | SNP00010 0 0 A G 12 | SNP00011 0 0 A G 13 | SNP00012 0 0 C T 14 | SNP00013 0 0 C T 15 | SNP00014 0 0 G . 16 | SNP00015 0 0 C T 17 | SNP00016 0 0 G A 18 | SNP00017 0 0 C T 19 | SNP00018 0 0 G A 20 | SNP00019 0 0 G A 21 | SNP00020 0 0 G . 22 | SNP00021 0 0 G A 23 | SNP00022 0 0 G A 24 | SNP00023 0 0 C A 25 | SNP00024 0 0 G A 26 | SNP00025 0 0 C T 27 | SNP00026 0 0 C T 28 | SNP00027 0 0 G A 29 | SNP00028 0 0 A C 30 | SNP00029 0 0 T C 31 | SNP00030 0 0 T G 32 | SNP00031 0 0 C T 33 | SNP00032 0 0 T C 34 | SNP00033 0 0 C T 35 | SNP00034 0 0 C A 36 | SNP00035 0 0 A G 37 | SNP00036 0 0 G T 38 | SNP00037 0 0 G A 39 | SNP00038 0 0 G A 40 | SNP00039 0 0 G C 41 | SNP00040 0 0 G T 42 | SNP00041 0 0 C T 43 | SNP00042 0 0 G A 44 | SNP00043 0 0 A C 45 | SNP00044 0 0 C T 46 | SNP00045 0 0 A G 47 | SNP00046 0 0 C T 48 | SNP00047 0 0 T C 49 | SNP00048 0 0 G A 50 | SNP00049 0 0 C T 51 | SNP00050 0 0 C A 52 | SNP00051 0 0 G A 53 | SNP00052 0 0 G A 54 | SNP00053 0 0 C T 55 | SNP00054 0 0 A G 56 | SNP00055 0 0 C T 57 | SNP00056 0 0 G A 58 | SNP00057 0 0 G A 59 | SNP00058 0 0 T C 60 | SNP00059 0 0 G A 61 | SNP00060 0 0 G A 62 | SNP00061 0 0 G A 63 | SNP00062 0 0 G A 64 | SNP00063 0 0 C T 65 | SNP00064 0 0 G A 66 | SNP00065 0 0 T C 67 | SNP00066 0 0 C T 68 | SNP00067 0 0 A G 69 | SNP00068 0 0 G A 70 | SNP00069 0 0 C A 71 | SNP00070 0 0 G A 72 | SNP00071 0 0 G T 73 | SNP00072 0 0 G A 74 | SNP00073 0 0 G A 75 | SNP00074 0 0 C T 76 | SNP00075 0 0 A C 77 | SNP00076 0 0 G . 78 | SNP00077 0 0 A G 79 | SNP00078 0 0 C A 80 | SNP00079 0 0 C T 81 | SNP00080 0 0 C T 82 | SNP00081 0 0 C T 83 | SNP00082 0 0 A G 84 | SNP00083 0 0 G A 85 | SNP00084 0 0 A G 86 | SNP00085 0 0 G A 87 | SNP00086 0 0 C T 88 | SNP00087 0 0 C T 89 | SNP00088 0 0 A G 90 | SNP00089 0 0 G . 91 | SNP00090 0 0 G . 92 | SNP00091 0 0 C A 93 | SNP00092 0 0 C A 94 | SNP00093 0 0 G A 95 | SNP00094 0 0 G A 96 | SNP00095 0 0 C T 97 | SNP00096 0 0 G A 98 | SNP00097 0 0 G A 99 | SNP00098 0 0 G A 100 | SNP00099 0 0 C T 101 | SNP00100 0 0 G A 102 | -------------------------------------------------------------------------------- /man/annotation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Genotype.R 3 | \name{annotation} 4 | \alias{annotation} 5 | \title{Annotation simulation} 6 | \usage{ 7 | annotation(SP, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{verbose}{whether to print detail.} 13 | } 14 | \value{ 15 | the function returns a list containing 16 | \describe{ 17 | \item{$map$pop.map}{the map data with annotation information.} 18 | \item{$map$species}{the species of genetic map, which can be "arabidopsis", "cattle", "chicken", "dog", "horse", "human", "maize", "mice", "pig", and "rice".} 19 | \item{$map$pop.marker}{the number of markers.} 20 | \item{$map$num.chr}{the number of chromosomes.} 21 | \item{$map$len.chr}{the length of chromosomes.} 22 | \item{$map$qtn.model}{the genetic model of QTN such as "A + D".} 23 | \item{$map$qtn.index}{the QTN index for each trait.} 24 | \item{$map$qtn.num}{the QTN number for (each group in) each trait.} 25 | \item{$map$qtn.dist}{the QTN distribution containing "norm", "geom", "gamma" or "beta".} 26 | \item{$map$qtn.var}{the variances for normal distribution.} 27 | \item{$map$qtn.prob}{the probability of success for geometric distribution.} 28 | \item{$map$qtn.shape}{the shape parameter for gamma distribution.} 29 | \item{$map$qtn.scale}{the scale parameter for gamma distribution.} 30 | \item{$map$qtn.shape1}{the shape1 parameter for beta distribution.} 31 | \item{$map$qtn.shape2}{the shape2 parameter for beta distribution.} 32 | \item{$map$qtn.ncp}{the ncp parameter for beta distribution.} 33 | \item{$map$qtn.spot}{the QTN distribution probability in each block.} 34 | \item{$map$len.block}{the block length.} 35 | \item{$map$maf}{the maf threshold, markers less than this threshold will be exclude.} 36 | \item{$map$recom.spot}{whether to generate recombination events.} 37 | \item{$map$range.hot}{the recombination times range in the hot spot.} 38 | \item{$map$range.cold}{the recombination times range in the cold spot.} 39 | } 40 | } 41 | \description{ 42 | Generating a map with annotation information 43 | } 44 | \details{ 45 | Build date: Nov 14, 2018 46 | Last update: Jul 10, 2022 47 | } 48 | \examples{ 49 | # Generate annotation simulation parameters 50 | SP <- param.annot(qtn.num = list(tr1 = 10)) 51 | 52 | # Run annotation simulation 53 | SP <- annotation(SP) 54 | } 55 | \author{ 56 | Dong Yin 57 | } 58 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | package.env <- NULL 2 | 3 | allparam <- c( 4 | "replication" , "seed.sim" , "out" , "outpath" , 5 | "out.format" , "pop.gen" , "out.geno.gen" , "out.pheno.gen", 6 | "useAllGeno" , "missing.geno" , "missing.phe" , "ncpus" , 7 | "verbose" , "pop.map" , "species" , "pop.marker" , 8 | "num.chr" , "len.chr" , "qtn.model" , "qtn.index" , 9 | "qtn.num" , "qtn.dist" , "qtn.var" , "qtn.prob" , 10 | "qtn.shape" , "qtn.scale" , "qtn.shape1" , "qtn.shape2" , 11 | "qtn.ncp" , "qtn.spot" , "len.block" , "maf" , 12 | "recom.spot" , "range.hot" , "range.cold" , "pop.geno" , 13 | "inrows" , "pop.marker" , "pop.ind" , "prob" , 14 | "rate.mut" , "cld" , "pop" , "pop.ind" , 15 | "pop.rep" , "pop.rep.bal" , "pop.env" , "phe.type" , 16 | "phe.model" , "phe.h2A" , "phe.h2D" , "phe.h2GxG" , 17 | "phe.h2GxE" , "phe.h2PE" , "phe.var" , "phe.corA" , 18 | "phe.corD" , "phe.corGxG" , "phe.corPE" , "phe.corE" , 19 | "pop.sel" , "ps" , "decr" , "sel.crit" , 20 | "sel.single" , "sel.multi" , "index.wt" , "index.tdm" , 21 | "goal.perc" , "pass.perc" , "pop.gen" , "reprod.way" , 22 | "sex.rate" , "prog" 23 | ) 24 | 25 | .onLoad <- function(libname, pkgname) { 26 | # limit number of threads in veclib (MacOS MRO) 27 | if (Sys.info()["sysname"] == "Darwin") { 28 | Sys.setenv("VECLIB_MAXIMUM_THREADS" = "1") 29 | } 30 | 31 | # set option 32 | op <- options() 33 | op.simer <- list( 34 | simer.OutputLog2File = TRUE, 35 | simer.show.warning = TRUE 36 | ) 37 | toset <- !(names(op.simer) %in% names(op)) 38 | if (any(toset)) { 39 | options(op.simer[toset]) 40 | } 41 | options(bigmemory.typecast.warning = FALSE) 42 | 43 | # package level environment 44 | package.env <<- new.env() 45 | 46 | return(invisible()) 47 | } 48 | 49 | .onUnload <- function(libpath) { 50 | options(simer.OutputLog2File = NULL) 51 | } 52 | 53 | .onAttach <- function(...){ 54 | packageStartupMessage("Full description, Bug report, Suggestion and the latest version:") 55 | packageStartupMessage("https://github.com/xiaolei-lab/SIMER") 56 | } -------------------------------------------------------------------------------- /inst/extdata/04breeding_plan/plan3.json: -------------------------------------------------------------------------------- 1 | { 2 | "genotype": "../02plinkb", 3 | "pedigree": "../05others/pedigree.txt", 4 | "selection_index": "100 - 0.2 * T1 + 0.8 * T2", 5 | "threads": 16, 6 | "genetic_progress": [], 7 | "breeding_value_index": "-0.2 * T1 + 0.8 * T2", 8 | "auto_optimization": true, 9 | "quality_control_plan": { 10 | "genotype_quality_control":{ 11 | "filter": "F1 == 'Male'", 12 | "filter_geno": 0.1, 13 | "filter_mind": 0.1, 14 | "filter_maf": 0.05, 15 | "filter_hwe": 0.001 16 | }, 17 | "pedigree_quality_control":{ 18 | "standard_ID": false, 19 | "candidate_sire_file": [], 20 | "candidate_dam_file": [], 21 | "exclude_threshold": 0.1, 22 | "assign_threshold": 0.05 23 | }, 24 | "phenotype_quality_control":[ 25 | { 26 | "job_name": "Data_Quality_Control_Demo", 27 | "sample_info": "../05others/phenotype.txt", 28 | "repeated_records": false, 29 | "multi_trait": true, 30 | "filter": "F1 == 'Male'", 31 | "job_traits": [ 32 | { 33 | "traits": "T1", 34 | "definition": "T1", 35 | "range": [] 36 | }, 37 | { 38 | "traits": "T2", 39 | "definition": "T2", 40 | "range": [] 41 | } 42 | ] 43 | } 44 | ] 45 | }, 46 | "breeding_plan":[ 47 | { 48 | "job_name": "EBV_Model_Demo", 49 | "sample_info": "../05others/phenotype.txt", 50 | "repeated_records": false, 51 | "multi_trait": true, 52 | "vc_vars": [], 53 | "vc_covars": [], 54 | "random_ratio": 0.05, 55 | "job_traits": [ 56 | { 57 | "traits": "T1", 58 | "covariates": [], 59 | "fixed_effects": ["F1", "F2"], 60 | "random_effects": ["R1"] 61 | }, 62 | { 63 | "traits": "T2", 64 | "covariates": [], 65 | "fixed_effects": ["F1", "F2"], 66 | "random_effects": ["R1"] 67 | } 68 | ] 69 | } 70 | ] 71 | } -------------------------------------------------------------------------------- /inst/extdata/02plinkb/demo.bim: -------------------------------------------------------------------------------- 1 | 0 SNP00001 0 0 T C 2 | 0 SNP00002 0 0 A G 3 | 0 SNP00003 0 0 G A 4 | 0 SNP00004 0 0 T C 5 | 0 SNP00005 0 0 T C 6 | 0 SNP00006 0 0 T C 7 | 0 SNP00007 0 0 A G 8 | 0 SNP00008 0 0 G A 9 | 0 SNP00009 0 0 C T 10 | 0 SNP00010 0 0 G A 11 | 0 SNP00011 0 0 G A 12 | 0 SNP00012 0 0 T C 13 | 0 SNP00013 0 0 T C 14 | 0 SNP00014 0 0 0 G 15 | 0 SNP00015 0 0 T C 16 | 0 SNP00016 0 0 A G 17 | 0 SNP00017 0 0 T C 18 | 0 SNP00018 0 0 A G 19 | 0 SNP00019 0 0 A G 20 | 0 SNP00020 0 0 0 G 21 | 0 SNP00021 0 0 A G 22 | 0 SNP00022 0 0 A G 23 | 0 SNP00023 0 0 A C 24 | 0 SNP00024 0 0 A G 25 | 0 SNP00025 0 0 T C 26 | 0 SNP00026 0 0 T C 27 | 0 SNP00027 0 0 A G 28 | 0 SNP00028 0 0 C A 29 | 0 SNP00029 0 0 C T 30 | 0 SNP00030 0 0 G T 31 | 0 SNP00031 0 0 T C 32 | 0 SNP00032 0 0 C T 33 | 0 SNP00033 0 0 T C 34 | 0 SNP00034 0 0 A C 35 | 0 SNP00035 0 0 G A 36 | 0 SNP00036 0 0 T G 37 | 0 SNP00037 0 0 A G 38 | 0 SNP00038 0 0 A G 39 | 0 SNP00039 0 0 C G 40 | 0 SNP00040 0 0 T G 41 | 0 SNP00041 0 0 T C 42 | 0 SNP00042 0 0 A G 43 | 0 SNP00043 0 0 C A 44 | 0 SNP00044 0 0 T C 45 | 0 SNP00045 0 0 G A 46 | 0 SNP00046 0 0 T C 47 | 0 SNP00047 0 0 C T 48 | 0 SNP00048 0 0 A G 49 | 0 SNP00049 0 0 T C 50 | 0 SNP00050 0 0 A C 51 | 0 SNP00051 0 0 A G 52 | 0 SNP00052 0 0 A G 53 | 0 SNP00053 0 0 T C 54 | 0 SNP00054 0 0 G A 55 | 0 SNP00055 0 0 T C 56 | 0 SNP00056 0 0 A G 57 | 0 SNP00057 0 0 A G 58 | 0 SNP00058 0 0 C T 59 | 0 SNP00059 0 0 A G 60 | 0 SNP00060 0 0 A G 61 | 0 SNP00061 0 0 A G 62 | 0 SNP00062 0 0 A G 63 | 0 SNP00063 0 0 T C 64 | 0 SNP00064 0 0 A G 65 | 0 SNP00065 0 0 C T 66 | 0 SNP00066 0 0 T C 67 | 0 SNP00067 0 0 G A 68 | 0 SNP00068 0 0 A G 69 | 0 SNP00069 0 0 A C 70 | 0 SNP00070 0 0 A G 71 | 0 SNP00071 0 0 T G 72 | 0 SNP00072 0 0 A G 73 | 0 SNP00073 0 0 A G 74 | 0 SNP00074 0 0 T C 75 | 0 SNP00075 0 0 C A 76 | 0 SNP00076 0 0 0 G 77 | 0 SNP00077 0 0 G A 78 | 0 SNP00078 0 0 A C 79 | 0 SNP00079 0 0 T C 80 | 0 SNP00080 0 0 T C 81 | 0 SNP00081 0 0 T C 82 | 0 SNP00082 0 0 G A 83 | 0 SNP00083 0 0 A G 84 | 0 SNP00084 0 0 G A 85 | 0 SNP00085 0 0 A G 86 | 0 SNP00086 0 0 T C 87 | 0 SNP00087 0 0 T C 88 | 0 SNP00088 0 0 G A 89 | 0 SNP00089 0 0 0 G 90 | 0 SNP00090 0 0 0 G 91 | 0 SNP00091 0 0 A C 92 | 0 SNP00092 0 0 A C 93 | 0 SNP00093 0 0 A G 94 | 0 SNP00094 0 0 A G 95 | 0 SNP00095 0 0 T C 96 | 0 SNP00096 0 0 A G 97 | 0 SNP00097 0 0 A G 98 | 0 SNP00098 0 0 A G 99 | 0 SNP00099 0 0 T C 100 | 0 SNP00100 0 0 A G 101 | -------------------------------------------------------------------------------- /R/RcppExports.R: -------------------------------------------------------------------------------- 1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | write_bfile <- function(pBigMat, bed_file, mrkbycol = TRUE, threads = 0L, verbose = TRUE) { 5 | invisible(.Call('_simer_write_bfile', PACKAGE = 'simer', pBigMat, bed_file, mrkbycol, threads, verbose)) 6 | } 7 | 8 | read_bfile <- function(bed_file, pBigMat, maxLine, threads = 0L, verbose = TRUE) { 9 | invisible(.Call('_simer_read_bfile', PACKAGE = 'simer', bed_file, pBigMat, maxLine, threads, verbose)) 10 | } 11 | 12 | GenoFilter <- function(pBigMat, NA_C, keepIndsNull = NULL, filterGeno = NULL, filterHWE = NULL, filterMind = NULL, filterMAF = NULL, threads = 0L, verbose = TRUE) { 13 | .Call('_simer_GenoFilter', PACKAGE = 'simer', pBigMat, NA_C, keepIndsNull, filterGeno, filterHWE, filterMind, filterMAF, threads, verbose) 14 | } 15 | 16 | Mat2BigMat <- function(pBigMat, mat, indIdxNull = NULL, op = 1L, threads = 0L) { 17 | invisible(.Call('_simer_Mat2BigMat', PACKAGE = 'simer', pBigMat, mat, indIdxNull, op, threads)) 18 | } 19 | 20 | BigMat2BigMat <- function(pBigMat, pBigmat, indIdxNull = NULL, op = 1L, threads = 0L) { 21 | invisible(.Call('_simer_BigMat2BigMat', PACKAGE = 'simer', pBigMat, pBigmat, indIdxNull, op, threads)) 22 | } 23 | 24 | geno_cvt1_mat <- function(pBigMat, mat, threads = 0L) { 25 | invisible(.Call('_simer_geno_cvt1_mat', PACKAGE = 'simer', pBigMat, mat, threads)) 26 | } 27 | 28 | geno_cvt1_bigmat <- function(pBigMat, pBigmat, threads = 0L) { 29 | invisible(.Call('_simer_geno_cvt1_bigmat', PACKAGE = 'simer', pBigMat, pBigmat, threads)) 30 | } 31 | 32 | geno_cvt2_mat <- function(pBigMat, mat, threads = 0L) { 33 | invisible(.Call('_simer_geno_cvt2_mat', PACKAGE = 'simer', pBigMat, mat, threads)) 34 | } 35 | 36 | geno_cvt2_bigmat <- function(pBigMat, pBigmat, threads = 0L) { 37 | invisible(.Call('_simer_geno_cvt2_bigmat', PACKAGE = 'simer', pBigMat, pBigmat, threads)) 38 | } 39 | 40 | bigt_mat <- function(pBigMat, mat, threads = 0L) { 41 | invisible(.Call('_simer_bigt_mat', PACKAGE = 'simer', pBigMat, mat, threads)) 42 | } 43 | 44 | bigt_bigmat <- function(pBigMat, pBigmat, threads = 0L) { 45 | invisible(.Call('_simer_bigt_bigmat', PACKAGE = 'simer', pBigMat, pBigmat, threads)) 46 | } 47 | 48 | impute_marker <- function(pBigMat, mrkbycol = TRUE, threads = 0L, verbose = TRUE) { 49 | invisible(.Call('_simer_impute_marker', PACKAGE = 'simer', pBigMat, mrkbycol, threads, verbose)) 50 | } 51 | 52 | hasNA <- function(pBigMat, mrkbycol = TRUE, geno_ind = NULL, marker_ind = NULL, threads = 1L) { 53 | .Call('_simer_hasNA', PACKAGE = 'simer', pBigMat, mrkbycol, geno_ind, marker_ind, threads) 54 | } 55 | 56 | hasNABed <- function(bed_file, ind, maxLine, threads = 0L, verbose = TRUE) { 57 | .Call('_simer_hasNABed', PACKAGE = 'simer', bed_file, ind, maxLine, threads, verbose) 58 | } 59 | 60 | PedigreeCorrector <- function(pBigMat, rawGenoID, rawPed, candSirID = NULL, candDamID = NULL, exclThres = 0.005, assignThres = 0.02, birthDate = NULL, threads = 0L, verbose = TRUE) { 61 | .Call('_simer_PedigreeCorrector', PACKAGE = 'simer', pBigMat, rawGenoID, rawPed, candSirID, candDamID, exclThres, assignThres, birthDate, threads, verbose) 62 | } 63 | 64 | -------------------------------------------------------------------------------- /R/simer.R: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | #' Simer 15 | #' 16 | #' Main function of Simer. 17 | #' 18 | #' Build date: Jan 7, 2019 19 | #' Last update: Feb 18, 2025 20 | #' 21 | #' @author Dong Yin, Lilin Yin, Haohao Zhang, and Xiaolei Liu 22 | #' 23 | #' @param SP a list of all simulation parameters. 24 | #' 25 | #' @return 26 | #' the function returns a list containing 27 | #' \describe{ 28 | #' \item{$global}{a list of global parameters.} 29 | #' \item{$map}{a list of marker information parameters.} 30 | #' \item{$geno}{a list of genotype simulation parameters.} 31 | #' \item{$pheno}{a list of phenotype simulation parameters.} 32 | #' \item{$sel}{a list of selection parameters.} 33 | #' \item{$reprod}{a list of reproduction parameters.} 34 | #' } 35 | #' 36 | #' @export 37 | #' 38 | #' @examples 39 | #' \donttest{ 40 | #' # Generate all simulation parameters 41 | #' SP <- param.simer(out = "simer") 42 | #' 43 | #' # Run Simer 44 | #' SP <- simer(SP) 45 | #' } 46 | simer <- function(SP) { 47 | 48 | ### Start simer 49 | 50 | # TODO: how to generate inbreeding sirs and uninbreeding dams 51 | # TODO: optcontri.sel 52 | # TODO: add superior limit of homo 53 | # TODO: add inbreeding coefficient 54 | # TODO: inbreeding change in every generations 55 | # TODO: breeding literature from ZhenST 56 | # TODO: core population 57 | # TODO: pEBVs, gEBVs, and ssEBVs 58 | 59 | # global parameters 60 | replication <- SP$global$replication 61 | seed.sim <- SP$global$seed.sim 62 | out <- SP$global$out 63 | outpath <- SP$global$outpath 64 | ncpus <- SP$global$ncpus 65 | verbose <- SP$global$verbose 66 | 67 | # initialize logging 68 | if (!is.null(outpath)) { 69 | if (!dir.exists(outpath)) stop(paste0("Please check your output path: ", outpath)) 70 | if (verbose) { 71 | logging.initialize("Simer", outpath = outpath) 72 | } 73 | } 74 | 75 | # welcome to simer 76 | simer.Version(width = 70, verbose = verbose) 77 | 78 | ################### MAIN_FUNCTION_SETTING ################### 79 | logging.log("--------------------------- replication ", replication, "---------------------------\n", verbose = verbose) 80 | op <- Sys.time() 81 | logging.log(" SIMER BEGIN AT", as.character(op), "\n", verbose = verbose) 82 | logging.log(" Random seed is", floor(seed.sim), "\n", verbose = verbose) 83 | set.seed(floor(seed.sim)) 84 | 85 | ################### DATA SIMULATION ################### 86 | SP <- annotation(SP = SP, verbose = verbose) 87 | SP <- genotype(SP = SP, ncpus = ncpus, verbose = verbose) 88 | SP <- phenotype(SP = SP, ncpus = ncpus, verbose = verbose) 89 | SP <- selects(SP = SP, verbose = verbose) 90 | SP <- reproduces(SP = SP, ncpus = ncpus, verbose = verbose) 91 | 92 | ################### DATA WRITING ################### 93 | SP <- write.file(SP) 94 | 95 | print_accomplished(width = 70, verbose = verbose) 96 | ed <- Sys.time() 97 | logging.log(" SIMER DONE WITHIN TOTAL RUN TIME:", format_time(as.numeric(ed)-as.numeric(op)), "\n", verbose = verbose) 98 | 99 | return(SP) 100 | } 101 | -------------------------------------------------------------------------------- /man/phenotype.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simer.Phenotype.R 3 | \name{phenotype} 4 | \alias{phenotype} 5 | \title{Phenotype simulation} 6 | \usage{ 7 | phenotype(SP = NULL, ncpus = 0, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SP}{a list of all simulation parameters.} 11 | 12 | \item{ncpus}{the number of threads used, if NULL, (logical core number - 1) is automatically used.} 13 | 14 | \item{verbose}{whether to print detail.} 15 | } 16 | \value{ 17 | the function returns a list containing 18 | \describe{ 19 | \item{$pheno$pop}{the population information containing environmental factors and other effects.} 20 | \item{$pheno$pop.ind}{the number of individuals in the base population.} 21 | \item{$pheno$pop.rep}{the repeated times of repeated records.} 22 | \item{$pheno$pop.rep.bal}{whether repeated records are balanced.} 23 | \item{$pheno$pop.env}{a list of environmental factors setting.} 24 | \item{$pheno$phe.type}{a list of phenotype types.} 25 | \item{$pheno$phe.model}{a list of genetic model of phenotype such as "T1 = A + E".} 26 | \item{$pheno$phe.h2A}{a list of additive heritability.} 27 | \item{$pheno$phe.h2D}{a list of dominant heritability.} 28 | \item{$pheno$phe.h2GxG}{a list of GxG interaction heritability.} 29 | \item{$pheno$phe.h2GxE}{a list of GxE interaction heritability.} 30 | \item{$pheno$phe.h2PE}{a list of permanent environmental heritability.} 31 | \item{$pheno$phe.var}{a list of phenotype variance.} 32 | \item{$pheno$phe.corA}{the additive genetic correlation matrix.} 33 | \item{$pheno$phe.corD}{the dominant genetic correlation matrix.} 34 | \item{$pheno$phe.corGxG}{the GxG genetic correlation matrix.} 35 | \item{$pheno$phe.corPE}{the permanent environmental correlation matrix.} 36 | \item{$pheno$phe.corE}{the residual correlation matrix.} 37 | } 38 | } 39 | \description{ 40 | Generate single-trait or multiple-trait phenotype by mixed model. 41 | } 42 | \details{ 43 | Build date: Nov 14, 2018 44 | Last update: Jun 10, 2025 45 | } 46 | \examples{ 47 | \donttest{ 48 | # Prepare environmental factor list 49 | pop.env <- list( 50 | F1 = list( # fixed effect 1 51 | level = c("1", "2"), 52 | effect = list(tr1 = c(50, 30), tr2 = c(50, 30)) 53 | ), 54 | F2 = list( # fixed effect 2 55 | level = c("d1", "d2", "d3"), 56 | effect = list(tr1 = c(10, 20, 30), tr2 = c(10, 20, 30)) 57 | ), 58 | C1 = list( # covariate 1 59 | level = c(70, 80, 90), 60 | slope = list(tr1 = 1.5, tr2 = 1.5) 61 | ), 62 | R1 = list( # random effect 1 63 | level = c("l1", "l2", "l3"), 64 | ratio = list(tr1 = 0.1, tr2 = 0.1) 65 | ) 66 | ) 67 | 68 | # Generate genotype simulation parameters 69 | SP <- param.annot(qtn.num = list(tr1 = c(2, 8), tr2 = 10), 70 | qtn.model = "A + D + A:D") 71 | # Generate annotation simulation parameters 72 | SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 73 | # Generate phenotype simulation parameters 74 | SP <- param.pheno( 75 | SP = SP, 76 | pop.ind = 100, 77 | pop.rep = 2, # 2 repeated record 78 | pop.rep.bal = TRUE, # balanced repeated record 79 | pop.env = pop.env, 80 | phe.type = list( 81 | tr1 = "continuous", 82 | tr2 = list(case = 0.01, control = 0.99) 83 | ), 84 | phe.model = list( 85 | tr1 = "T1 = A + D + A:D + F1 + F2 + C1 + R1 + A:F1 + E", 86 | tr2 = "T2 = A + D + A:D + F1 + F2 + C1 + R1 + A:F1 + E" 87 | ), 88 | phe.var = list(tr1 = 100, tr2 = 100) 89 | ) 90 | 91 | # Run annotation simulation 92 | SP <- annotation(SP) 93 | # Run genotype simulation 94 | SP <- genotype(SP) 95 | # Run phenotype simulation 96 | SP <- phenotype(SP) 97 | } 98 | } 99 | \references{ 100 | Kao C and Zeng Z (2002) 101 | } 102 | \author{ 103 | Dong Yin 104 | } 105 | -------------------------------------------------------------------------------- /R/simer.Logging.R: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | #' Logging initialization 15 | #' 16 | #' Initialize the logging process. 17 | #' 18 | #' Build date: Jul 11, 2020 19 | #' Last update: Apr 28, 2022 20 | #' 21 | #' @author Dong Yin 22 | #' 23 | #' @param module the module name. 24 | #' @param outpath the path of output files, Simer writes files only if outpath is not 'NULL'. 25 | #' 26 | #' @return none. 27 | logging.initialize <- function(module, outpath) { 28 | file <- NULL 29 | if (options("simer.OutputLog2File") == TRUE) { 30 | try(file <- get("logging.file", envir = package.env), silent = TRUE) 31 | if (is.null(file)) { 32 | now <- Sys.time() 33 | file <- paste(module, format(now, "%Y%m%d_%H%M%S"), "log", sep = ".") 34 | file <- file.path(outpath, file) 35 | } 36 | } 37 | 38 | assign("logging.file", file, envir = package.env) 39 | } 40 | 41 | #' Logging 42 | #' 43 | #' Print or write log. 44 | #' 45 | #' Build date: Jul 11, 2020 46 | #' Last update: Apr 28, 2022 47 | #' 48 | #' @author Dong Yin 49 | #' 50 | #' @param ... R objects. 51 | #' @param file a connection or a character string naming the file to print to. If "" (the default), cat prints to the standard output connection, the console unless redirected by sink. If it is "|cmd", the output is piped to the command given by ‘cmd’, by opening a pipe connection. 52 | #' @param sep a character vector of strings to append after each element. 53 | #' @param fill a logical or (positive) numeric controlling how the output is broken into successive lines. 54 | #' @param labels a character vector of labels for the lines printed. Ignored if fill is FALSE. 55 | #' @param verbose whether to print detail. 56 | #' 57 | #' @return none. 58 | #' 59 | #' @export 60 | #' 61 | #' @examples 62 | #' logging.log('simer') 63 | logging.log <- function(..., file = NULL, sep = " ", fill = FALSE, labels = NULL, verbose = TRUE) { 64 | if (verbose) { 65 | cat(..., sep = sep, fill = fill, labels = labels) 66 | } 67 | 68 | if (is.null(file)) { 69 | try(file <- get("logging.file", envir = package.env), silent = TRUE) 70 | } 71 | 72 | if (!is.null(file)) { 73 | cat(..., file = file, sep = sep, fill = fill, labels = labels, append = TRUE) 74 | } 75 | } 76 | 77 | #' Logging printer 78 | #' 79 | #' Print R object information into file. 80 | #' 81 | #' Build date: Feb 7, 2020 82 | #' Last update: Apr 28, 2022 83 | #' 84 | #' @author Dong Yin 85 | #' 86 | #' @param x a matrix or a list. 87 | #' @param file the filename of output file. 88 | #' @param append logical. If TRUE, output will be appended to file; otherwise, it will overwrite the contents of file. 89 | #' @param verbose whether to print details. 90 | #' 91 | #' @return none. 92 | #' 93 | #' @export 94 | #' 95 | #' @examples 96 | #' x <- list(a = "a", b = "b") 97 | #' logging.print(x) 98 | logging.print <- function(x, file = NULL, append = TRUE, verbose = TRUE) { 99 | if (verbose) { 100 | if (is.numeric(x) & is.vector(x)) { 101 | if (length(x) <= 10) { 102 | cat("", x, "\n") 103 | } else { 104 | cat("", x[1:10], "...(more IDs in the logging file)\n") 105 | } 106 | } else { 107 | print(x) 108 | } 109 | 110 | if (is.null(file)) { 111 | try(file <- get("logging.file", envir = package.env), silent = TRUE) 112 | } 113 | if (!is.null(file)) { 114 | sink(file = file, append = append) 115 | if (is.numeric(x) & is.vector(x)) { 116 | cat("", x, "\n") 117 | } else { 118 | print(x) 119 | } 120 | sink() 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /inst/extdata/03plinkp/demo.ped: -------------------------------------------------------------------------------- 1 | ind000120000101 ind000120000101 0 0 0 0.086667 C C A G G A C C C C C C G G A A T T A A A A T C T C G G C C G G T C A G A G G G A G A G A C G G C C T C G G C A T T T T C C C T T C A C G A T G A G G G C G T G T C A A A A C C G A T C C C A G C C C C A A G G T C A G C C A G A G C T A G A G A G G G T C A G T C T C A G A G A A A G T G A G G G T C C A G G G A C C T C T C C C A A G G G A A G T C C C A G G G G G A C A C A G A G T C A G G G A G T C A G 2 | ind000220000102 ind000220000102 0 0 0 -0.101667 T C A A A A C C C C C C G G G A C T G A G A C C C C G G C C G G T C A G A G G G A G A G A C G G C C C C A G C A C T G T T C C T T C A C G A G G A G A G C G T G C C A G C A T C A A T C C C A G T C C C G G A G T C A A C C A G G G C T G G A A G G A G T C A G T T T C G G G G A C G G G G G G A A T C C A G G G A C C T C C C T C G A G G A A A G T C C C A A G G G G A C A A A G A G T C A G G G A G T C A G 3 | ind000320000103 ind000320000103 0 0 0 -0.120173 T C A G G G C C C C C C G G G A C T G A G A C C C C G G C C G G T C A G A G G G G G G G C C A G T T C C A G A A T T T T C C T T C C C C A A T G G G A G C G T T C C A A A A T C G A T T C T G G T C C C A G A A T C A G C C A G G G C T A G G G A G A G T C A G T T C C G G A G A C A G T T A G G G T C A A G G A A C C T C C C T C G G G G G A A G T C T C A A G G G G A C A C A G A G T C A G A G A G T C A G 4 | ind000420000104 ind000420000104 0 0 0 0.106211 C C G G G G T C T C T C A G G A C T G A G A T C T C G G C C G G T C A G A G G G A G A G A C G G T C C C A G A A T T T T C C T T C C C C A A T G G G A G G G T G C C A G C A T T G A T C T T G G C C C C A G A G C C G G T C A G G G C T A G G G A G G G T C A G T C T C A G A G C C A A T G G G A G C C A A G G A A C C T C T C T C G A A G G G G G C C T C A G G G G G C C C C G G G G C C G G A G G G T C G G 5 | ind000520000105 ind000520000105 0 0 0 -0.111879 T C G G G A T C T C T C A G G A C T G A G A C C C C G G C C G G C C G G G G G G A G A G A C G G T T T C A G C C C C G G T C C T T C A C G A G G A G A G C G T G C C A G C A T T A A T T C T A G C C C C A G G G C C G G T T G G A G T T G G G G G G A G C C G G C C T C A A A G C C A G G G G G A G C C C A G G G A C C T C T C T C G A G G G A G G C C C C G G G G G G C C C C G G G G C C G G A G G G T C G G 6 | ind000620000106 ind000620000106 0 0 0 -0.0201065 T C G G A A C C C C C C G G G A C T G A G A C C C C G G T C A G C C G G G G G G G G G G C C G G C C T C G G A A T T T T C C T T C C A C G G G G G G A G G G T G C C G G C A T C G A C C T T A G T T A C A G A G T C A G T C G G G G C T A G G G A G G G T C A G T C T C A G A G C C A G G G G G A G C C C A G G G A C C T C T C T C G A A G G G G G C C C C G G G G G G C C C C G G G G C C G G A G G G C C G G 7 | ind000720000107 ind000720000107 0 0 0 -0.244335 T C G G G A C C C C C C G G G A C T G A G A T C T C G G T T A A C C G G G G G G A G A G A C G G T C C C A G A A T T T T C C T T C C C C A A G G G G A G C G T G C C A G C A C C G A C C C T A G T T A C G G A G T C A A C C G G G G C T G G A G G G G G C C G G C C T C A A A G C C A G T G A G G G T C C A G G G A A C T C T T T C A A G G G A A G T C C C A G G G G G A C A C A G A G T C A G G G A G C C A G 8 | ind000820000108 ind000820000108 0 0 0 -0.302136 T C G G A A T C T C T C A G G A C T G A G A T C T C G G C C G G C C G G G G G G A G A G A C G G T C T C A G C A C T G T C C T T C C C C A A G G G G A A C G T G C C A G A A T C G A T C T T A G C C C C A G G G C C A G T C G G A A T T G G A G A G A G C C A G T C T C A G G G A C G G G G G G G G C C C A G G G A A C T C T C C C G A G G A A A G T C C C A G G G G G A C A C A G A G T C A G A G G G T C A G 9 | ind000920000109 ind000920000109 0 0 0 -0.196387 C C G G G A C C C C C C G G G A C T G A G A T C T C G G C C G G C C G G G G G G A G A G A C G G T C C C A G C A C T G T T C T T C C C C G A T G G G A G G G G G C C G G C A T C G A C C C T G G T C C C A G G G T C A G C C A G G G C T A G A A A G G G C C A G T C T C A G A G A A A G G G G G A G C C C A G G G A A C T C T C C C G A G G A A A G T C C C A G G G G G A C A A A G A G T C A G A G G G T C A G 10 | ind001020000110 ind001020000110 0 0 0 -0.146253 T C A G A A T C T C T C A G A A T T A A A A C C C C G G T C A G C C G G G G G G G G G G C C G G C C T C A G C C C C G G C C C T C C A C G A T G G G G G G G G G C C G G C C T C G A C C C T A G C C C C A G G G T C A G C C G G G G C T G G G G A G A G T C A G T C T C A G G G A C G G T G A G G G T C C C G G G G C C C C T C C C G A G G A A A G T C C C A G G G G G A C A C A G A G T C A G A G A G T C A G 11 | -------------------------------------------------------------------------------- /src/data_converter.cpp: -------------------------------------------------------------------------------- 1 | // Data pre-processing module 2 | // 3 | // Copyright (C) 2016-2018 by Xiaolei Lab 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | #include "simer.h" 18 | #include 19 | 20 | using namespace std; 21 | using namespace Rcpp; 22 | 23 | // [[Rcpp::depends(bigmemory, BH)]] 24 | // [[Rcpp::depends(RcppProgress)]] 25 | 26 | // ***** BFILE ***** 27 | 28 | template 29 | void write_bfile(XPtr pMat, std::string bed_file, double NA_C, bool mrkbycol = true, int threads=0, bool verbose=true) { 30 | // check input 31 | string ending = ".bed"; 32 | if (bed_file.length() <= ending.length() || 33 | 0 != bed_file.compare(bed_file.length() - ending.length(), ending.length(), ending)) { 34 | bed_file += ending; 35 | } 36 | 37 | // define 38 | T c; 39 | omp_setup(threads); 40 | int m = (mrkbycol ? pMat->ncol() : pMat->nrow()); 41 | int nind = (mrkbycol ? pMat->nrow() : pMat->ncol()); 42 | int n = nind / 4; // 4 individual = 1 bit 43 | if (nind % 4 != 0) 44 | n++; 45 | 46 | vector geno(n); 47 | MatrixAccessor mat = MatrixAccessor(*pMat); 48 | FILE *fout; 49 | fout = fopen(bed_file.c_str(), "wb"); 50 | 51 | // progress bar 52 | MinimalProgressBar_perc pb; 53 | Progress progress(m, verbose, pb); 54 | 55 | // magic number of bfile 56 | const unsigned char magic_bytes[] = { 0x6c, 0x1b, 0x01 }; 57 | fwrite((char*)magic_bytes, 1, 3, fout); 58 | 59 | // map 60 | std::map code; 61 | code[0] = 3; 62 | code[1] = 2; 63 | code[2] = 0; 64 | code[static_cast(NA_C)] = 1; 65 | 66 | // write bfile 67 | if (mrkbycol) { 68 | for (int i = 0; i < m; i++) { 69 | #pragma omp parallel for private(c) 70 | for (int j = 0; j < n; j++) { 71 | uint8_t p = 0; 72 | for (int x = 0; x < 4 && (4 * j + x) < nind; x++) { 73 | c = mat[i][4 * j + x]; 74 | p |= code[c] << (x*2); 75 | } 76 | geno[j] = p; 77 | } 78 | fwrite((char*)geno.data(), 1, geno.size(), fout); 79 | progress.increment(); 80 | } 81 | }else{ 82 | for (int i = 0; i < m; i++) { 83 | #pragma omp parallel for private(c) 84 | for (int j = 0; j < n; j++) { 85 | uint8_t p = 0; 86 | for (int x = 0; x < 4 && (4 * j + x) < nind; x++) { 87 | c = mat[4 * j + x][i]; 88 | p |= code[c] << (x*2); 89 | } 90 | geno[j] = p; 91 | } 92 | fwrite((char*)geno.data(), 1, geno.size(), fout); 93 | progress.increment(); 94 | } 95 | } 96 | fclose(fout); 97 | return; 98 | } 99 | 100 | // [[Rcpp::export]] 101 | void write_bfile(SEXP pBigMat, std::string bed_file, bool mrkbycol = true, int threads=0, bool verbose=true) { 102 | XPtr xpMat(pBigMat); 103 | 104 | switch(xpMat->matrix_type()) { 105 | case 1: 106 | return write_bfile(xpMat, bed_file, NA_CHAR, mrkbycol, threads, verbose); 107 | case 2: 108 | return write_bfile(xpMat, bed_file, NA_SHORT, mrkbycol, threads, verbose); 109 | case 4: 110 | return write_bfile(xpMat, bed_file, NA_INTEGER, mrkbycol, threads, verbose); 111 | case 8: 112 | return write_bfile(xpMat, bed_file, NA_REAL, mrkbycol, threads, verbose); 113 | default: 114 | throw Rcpp::exception("unknown type detected for big.matrix object!"); 115 | } 116 | } 117 | 118 | template 119 | void read_bfile(std::string bed_file, XPtr pMat, long maxLine, double NA_C, int threads=0, bool verbose=true) { 120 | // check input 121 | if (!boost::ends_with(bed_file, ".bed")) { 122 | bed_file += ".bed"; 123 | } 124 | 125 | // define 126 | omp_setup(threads); 127 | size_t ind = pMat->nrow(); 128 | long n = ind / 4; // 4 individual = 1 bit 129 | if (ind % 4 != 0) 130 | n++; 131 | char *buffer; 132 | long buffer_size; 133 | MatrixAccessor mat = MatrixAccessor(*pMat); 134 | 135 | // map 136 | std::map code; 137 | code[3] = static_cast(0); 138 | code[2] = static_cast(1); 139 | code[1] = static_cast(NA_C); 140 | code[0] = static_cast(2); 141 | 142 | // open file 143 | FILE *fin; 144 | fin = fopen(bed_file.c_str(), "rb"); 145 | fseek(fin, 0, SEEK_END); 146 | long length = ftell(fin); 147 | rewind(fin); 148 | 149 | // get buffer_size 150 | buffer_size = maxLine > 0 ? (maxLine * n) : (length - 3); 151 | 152 | // progress bar 153 | int n_block = (length - 3) / buffer_size; 154 | if ((length - 3) % buffer_size != 0) { n_block++; } 155 | MinimalProgressBar_perc pb; 156 | Progress progress(n_block, verbose, pb); 157 | 158 | // magic number of bfile 159 | buffer = new char [3]; 160 | size_t n_bytes_read = static_cast(fread(buffer, 1, 3, fin)); 161 | if (n_bytes_read != 3) { // new if 162 | Rcpp::stop("It is not a normal binary file!"); 163 | } 164 | 165 | // loop file 166 | size_t cond; 167 | long block_start; 168 | for (int i = 0; i < n_block; i++) { 169 | buffer = new char [buffer_size]; 170 | n_bytes_read = static_cast(fread(buffer, 1, buffer_size, fin)); 171 | 172 | // i: current block, j: current bit. 173 | block_start = i * buffer_size; 174 | cond = min(buffer_size, length - 3 - block_start); 175 | 176 | #pragma omp parallel for 177 | for (size_t j = 0; j < cond; j++) { 178 | // bit -> item in matrix 179 | size_t r = j / n + i * maxLine; 180 | size_t c = j % n * 4; 181 | uint8_t p = buffer[j]; 182 | 183 | for (size_t x = 0; x < 4 && (c + x) < ind; x++) { 184 | mat[r][c + x] = code[(p >> (2*x)) & 0x03]; 185 | } 186 | } 187 | progress.increment(); 188 | } 189 | fclose(fin); 190 | return; 191 | } 192 | 193 | // [[Rcpp::export]] 194 | void read_bfile(std::string bed_file, SEXP pBigMat, long maxLine, int threads=0, bool verbose=true) { 195 | XPtr xpMat(pBigMat); 196 | 197 | switch(xpMat->matrix_type()) { 198 | case 1: 199 | return read_bfile(bed_file, xpMat, maxLine, NA_CHAR, threads, verbose); 200 | case 2: 201 | return read_bfile(bed_file, xpMat, maxLine, NA_SHORT, threads, verbose); 202 | case 4: 203 | return read_bfile(bed_file, xpMat, maxLine, NA_INTEGER, threads, verbose); 204 | case 8: 205 | return read_bfile(bed_file, xpMat, maxLine, NA_REAL, threads, verbose); 206 | default: 207 | throw Rcpp::exception("unknown type detected for big.matrix object!"); 208 | } 209 | } -------------------------------------------------------------------------------- /src/pedigree.cpp: -------------------------------------------------------------------------------- 1 | #include "simer.h" 2 | 3 | using namespace std; 4 | using namespace Rcpp; 5 | using namespace arma; 6 | 7 | // [[Rcpp::depends(RcppArmadillo)]] 8 | // [[Rcpp::depends(bigmemory, BH)]] 9 | 10 | template 11 | arma::mat calConf(XPtr pMat, int threads=0, bool verbose=true) { 12 | omp_setup(threads); 13 | 14 | if (verbose) { Rcout << " Computing Mendel Conflict Matrix..." << endl; } 15 | 16 | MatrixAccessor bigm = MatrixAccessor(*pMat); 17 | size_t i, j, k, n = pMat->nrow(), m = pMat->ncol(); 18 | 19 | arma::mat numConfs(n, n, fill::zeros); 20 | 21 | MinimalProgressBar pb; 22 | Progress p(m, verbose, pb); 23 | 24 | #pragma omp parallel for schedule(dynamic) private(i, j, k) 25 | for (k = 0; k < m; k++) { 26 | for (i = 0; i < n; i++) { 27 | for (j = i+1; j < n; j++) { 28 | if (((bigm[k][i] == 0) && (bigm[k][j] == 2)) || ((bigm[k][i] == 2) && (bigm[k][j] == 0))) { 29 | numConfs(i, j) = numConfs(i, j) + 1; 30 | numConfs(j, i) = numConfs(j, i) + 1; 31 | } 32 | } 33 | } 34 | if ( ! Progress::check_abort() ) { p.increment(); } 35 | } 36 | 37 | return numConfs; 38 | } 39 | 40 | arma::mat calConf(XPtr pMat, int threads=0, bool verbose=true) { 41 | XPtr xpMat(pMat); 42 | 43 | switch(xpMat->matrix_type()) { 44 | case 1: 45 | return calConf(xpMat, threads, verbose); 46 | case 2: 47 | return calConf(xpMat, threads, verbose); 48 | case 4: 49 | return calConf(xpMat, threads, verbose); 50 | case 8: 51 | return calConf(xpMat, threads, verbose); 52 | default: 53 | throw Rcpp::exception("unknown type detected for big.matrix object!"); 54 | } 55 | } 56 | 57 | template 58 | DataFrame PedigreeCorrector(XPtr pMat, StringVector genoID, DataFrame rawPed, Nullable candSirID=R_NilValue, Nullable candDamID=R_NilValue, double exclThres=0.1, double assignThres=0.05, Nullable birthDate=R_NilValue, int threads=0, bool verbose=true) { 59 | omp_setup(threads); 60 | 61 | // ******* 01 prepare data for checking rawPed ******* 62 | StringVector kidID = rawPed[0], sirOriID = rawPed[2], damOriID = rawPed[3], sirID = rawPed[4], damID = rawPed[5], sirState = rawPed[6], damState = rawPed[7]; 63 | NumericVector generation = rawPed[1]; 64 | size_t n = kidID.size(), m = pMat->ncol(); 65 | 66 | StringVector fullSirID, fullDamID; 67 | copy(sirID.begin(), sirID.end(), back_inserter(fullSirID)); 68 | copy(damID.begin(), damID.end(), back_inserter(fullDamID)); 69 | 70 | StringVector candSir, candDam; 71 | if (candSirID.isNotNull()) { 72 | StringVector candSirIDUse = as(candSirID); 73 | size_t ncsu = candSirIDUse.size(); 74 | for (size_t i = 0; i < ncsu; i++) 75 | fullSirID.insert(fullSirID.end(), candSirIDUse[i]); 76 | } 77 | if (candDamID.isNotNull()) { 78 | StringVector candDamIDUse = as(candDamID); 79 | size_t ncdu = candDamIDUse.size(); 80 | for (size_t i = 0; i < ncdu; i++) 81 | fullSirID.insert(fullSirID.end(), candDamIDUse[i]); 82 | } 83 | NumericVector birdate; 84 | if (birthDate.isNotNull()) { 85 | birdate = as(birthDate); 86 | } 87 | fullSirID = sort_unique(fullSirID); fullSirID.erase(0); 88 | fullDamID = sort_unique(fullDamID); fullDamID.erase(0); 89 | 90 | // kids should not be same as parents 91 | NumericVector kidOrder, sirOrder, damOrder; 92 | kidOrder = match(kidID, genoID); kidOrder = kidOrder - 1; 93 | sirOrder = match(sirID, genoID); sirOrder = sirOrder - 1; 94 | damOrder = match(damID, genoID); damOrder = damOrder - 1; 95 | LogicalVector naKid, naSir, naDam; 96 | naKid = is_na(kidOrder); naSir = is_na(sirOrder); naDam = is_na(damOrder); 97 | NumericVector sirNumConfs(n), damNumConfs(n); 98 | 99 | int exclMax = exclThres * m, assignMax = assignThres * m; 100 | 101 | // ******* 02 calculate conflict of pedigree in the rawPed ******* 102 | arma::mat numConfs = calConf(pMat, threads, verbose); 103 | // arma::mat numConfs(pMat->ncol(), pMat->ncol(), fill::zeros); 104 | 105 | for (size_t i = 0; i < n; i++) { 106 | 107 | if (naKid[i]) { continue; } 108 | 109 | if (!naSir[i]) { 110 | sirNumConfs[i] = numConfs(kidOrder[i], sirOrder[i]); 111 | if (sirNumConfs[i] <= exclMax) { 112 | sirState[i] = "Match"; 113 | } else { 114 | sirState[i] = "NotFoundByGeno"; 115 | sirID[i] = "0"; 116 | } 117 | } 118 | 119 | if (!naDam[i]) { 120 | damNumConfs[i] = numConfs(kidOrder[i], damOrder[i]); 121 | if (damNumConfs[i] <= exclMax) { 122 | damState[i] = "Match"; 123 | } else { 124 | damState[i] = "NotFoundByGeno"; 125 | damID[i] = "0"; 126 | } 127 | } 128 | 129 | } 130 | 131 | // ******* 03 seek parents of NotMatch in the rawPed ******* 132 | StringVector candKid(n); 133 | LogicalVector kidFlag; 134 | NumericVector candKidOrder, candParOrder; 135 | arma::uvec candParUse; 136 | size_t numCand; 137 | arma::mat subNumConfs; 138 | 139 | arma::uword maxPos, rowPos, colPos; 140 | StringVector candPar1(1), candPar2(1); 141 | 142 | size_t i, j; 143 | 144 | MinimalProgressBar pb; 145 | Progress p(n, verbose, pb); 146 | 147 | if(verbose) { Rcout << " Seeking Parents..." << endl; } 148 | // #pragma omp parallel for schedule(dynamic) private(i, j) 149 | for (i = 0; i < n; i++) { 150 | 151 | if ((sirState[i] != "NotFoundByGeno") && (damState[i] != "NotFoundByGeno")) { continue; } 152 | 153 | candKid.fill(kidID[i]); 154 | kidFlag = (sirID == candKid | damID == candKid) & !naKid; 155 | if (birthDate.isNotNull()) { kidFlag = kidFlag | birdate > birdate[i]; } 156 | candKidOrder = kidOrder[kidFlag]; 157 | candParOrder = wrap(arma::find(numConfs.row(kidOrder[i]) < assignMax)); 158 | candParUse = as(setdiff(candParOrder, candKidOrder)); 159 | numCand = candParUse.size(); 160 | if (numCand == 0) { continue; } 161 | subNumConfs = numConfs.rows(candParUse); 162 | subNumConfs = subNumConfs.cols(candParUse); 163 | 164 | arma::uvec sortIdx = sort_index(subNumConfs); 165 | size_t nsi = sortIdx.n_elem; 166 | for (j = 0; j < nsi; j++) { 167 | 168 | maxPos = sortIdx[nsi-1-j]; 169 | rowPos = maxPos % numCand; 170 | colPos = maxPos / numCand; 171 | candPar1[0] = genoID[candParUse[rowPos]]; 172 | candPar2[0] = genoID[candParUse[colPos]]; 173 | 174 | if (find(fullSirID.begin(), fullSirID.end(), candPar1[0]) != fullSirID.end()) { 175 | if (find(fullDamID.begin(), fullDamID.end(), candPar2[0]) != fullDamID.end()) { 176 | if (sirState[i] == "NotFoundByGeno") { 177 | sirID[i] = candPar1[0]; 178 | sirState[i] = "FoundByGeno"; 179 | sirNumConfs[i] = numConfs(kidOrder[i], candParUse[rowPos]); 180 | } 181 | if (damState[i] == "NotFoundByGeno") { 182 | damID[i] = candPar2[0]; 183 | damState[i] = "FoundByGeno"; 184 | damNumConfs[i] = numConfs(kidOrder[i], candParUse[colPos]); 185 | } 186 | break; 187 | } 188 | 189 | } else if (find(fullSirID.begin(), fullSirID.end(), candPar2[0]) != fullSirID.end()) { 190 | if (find(fullDamID.begin(), fullDamID.end(), candPar1[0]) != fullDamID.end()) { 191 | if (sirState[i] == "NotFoundByGeno") { 192 | sirID[i] = candPar2[0]; 193 | sirState[i] = "FoundByGeno"; 194 | sirNumConfs[i] = numConfs(kidOrder[i], candParUse[colPos]); 195 | } 196 | if (damState[i] == "NotFoundByGeno") { 197 | damID[i] = candPar1[0]; 198 | damState[i] = "FoundByGeno"; 199 | damNumConfs[i] = numConfs(kidOrder[i], candParUse[rowPos]); 200 | } 201 | break; 202 | } 203 | 204 | } 205 | } 206 | 207 | if ( ! Progress::check_abort() ) { p.increment(); } 208 | } 209 | 210 | DataFrame parConflict = DataFrame::create( 211 | Named("kid") = kidID, 212 | _["generation"] = generation, 213 | _["sirOrigin"] = sirOriID, 214 | _["damOrigin"] = damOriID, 215 | _["sirFound"] = sirID, 216 | _["damFound"] = damID, 217 | _["sirState"] = sirState, 218 | _["damState"] = damState, 219 | _["sirNumConfs"] = sirNumConfs, 220 | _["damNumConfs"] = damNumConfs, 221 | _["sirRatioConfs"] = sirNumConfs * 100 / m, 222 | _["damRatioConfs"] = damNumConfs * 100 / m 223 | ); 224 | return parConflict; 225 | } 226 | 227 | // [[Rcpp::export]] 228 | DataFrame PedigreeCorrector(const SEXP pBigMat, StringVector rawGenoID, DataFrame rawPed, Nullable candSirID=R_NilValue, Nullable candDamID=R_NilValue, double exclThres=0.005, double assignThres=0.02, Nullable birthDate=R_NilValue, int threads=0, bool verbose=true){ 229 | XPtr xpMat(pBigMat); 230 | 231 | switch(xpMat->matrix_type()) { 232 | case 1: 233 | return PedigreeCorrector(xpMat, rawGenoID, rawPed, candSirID, candDamID, exclThres, assignThres, birthDate, threads, verbose); 234 | case 2: 235 | return PedigreeCorrector(xpMat, rawGenoID, rawPed, candSirID, candDamID, exclThres, assignThres, birthDate, threads, verbose); 236 | case 4: 237 | return PedigreeCorrector(xpMat, rawGenoID, rawPed, candSirID, candDamID, exclThres, assignThres, birthDate, threads, verbose); 238 | case 8: 239 | return PedigreeCorrector(xpMat, rawGenoID, rawPed, candSirID, candDamID, exclThres, assignThres, birthDate, threads, verbose); 240 | default: 241 | throw Rcpp::exception("unknown type detected for big.matrix object!"); 242 | } 243 | } 244 | 245 | -------------------------------------------------------------------------------- /src/simer.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMER_ 2 | #define SIMER_ 3 | #endif 4 | 5 | #if !defined(ARMA_64BIT_WORD) 6 | #define ARMA_64BIT_WORD 1 7 | #endif 8 | 9 | #define ARMA_DONT_USE_FORTRAN_HIDDEN_ARGS 1 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "progress_bar.hpp" 19 | #include "simer_omp.h" 20 | 21 | class MinimalProgressBar_plus: public ProgressBar{ 22 | public: 23 | MinimalProgressBar_plus() { 24 | _finalized = false; 25 | } 26 | 27 | ~MinimalProgressBar_plus() {} 28 | 29 | std::string _time_to_string(double seconds, float progress) { 30 | 31 | int time = (int) seconds; 32 | 33 | int hour = 0; 34 | int min = 0; 35 | int sec = 0; 36 | 37 | hour = time / 3600; 38 | time = time % 3600; 39 | min = time / 60; 40 | time = time % 60; 41 | sec = time; 42 | 43 | std::stringstream time_strs; 44 | time_strs << (progress < 1.0 ? "TimeLeft: " : "RunTime: "); 45 | if (hour != 0) time_strs << hour << "h"; 46 | if (hour != 0 || min != 0) time_strs << min << "m"; 47 | time_strs << sec << "s"; 48 | std::string time_str = time_strs.str(); 49 | 50 | return time_str; 51 | } 52 | 53 | int _compute_nb_ticks(float progress) { 54 | return int(progress * _max_ticks); 55 | } 56 | 57 | std::string _construct_ticks_display_string(int nb) { 58 | std::stringstream ticks_strs; 59 | for (int i = 1; i <= _max_ticks; ++i) { 60 | if(i < 4){ 61 | ticks_strs << ">"; 62 | } else if (i < nb) { 63 | ticks_strs << "-"; 64 | } else if(i == nb) { 65 | ticks_strs << ">"; 66 | } else { 67 | ticks_strs << " "; 68 | } 69 | } 70 | std::string tick_space_string = ticks_strs.str(); 71 | return tick_space_string; 72 | } 73 | 74 | void end_display() { 75 | update(1); 76 | } 77 | 78 | void _finalize_display() { 79 | if (_finalized) return; 80 | REprintf("\n"); 81 | _finalized = true; 82 | } 83 | 84 | void display() { 85 | flush_console(); 86 | } 87 | 88 | void update(float progress) { 89 | 90 | // stop if already finalized 91 | if (_finalized) return; 92 | 93 | // start time measurement when update() is called the first time 94 | if (_timer_flag) { 95 | _timer_flag = false; 96 | // measure start time 97 | time(&start); 98 | } else { 99 | 100 | int nb_ticks = _compute_nb_ticks(progress); 101 | int delta = nb_ticks - _ticks_displayed; 102 | if (delta > 0) { 103 | _ticks_displayed = nb_ticks; 104 | std::string cur_display = _construct_ticks_display_string(nb_ticks); 105 | 106 | // measure current time 107 | time(&end); 108 | 109 | // calculate passed time and remaining time (in seconds) 110 | double pas_time = std::difftime(end, start); 111 | double rem_time = (progress < 1.0 ? (pas_time / progress) * (1 - progress) : pas_time); 112 | if(rem_time < 1 && rem_time > 0.5) rem_time = 1; 113 | 114 | // convert seconds to time string 115 | std::string time_string = _time_to_string(rem_time, progress); 116 | 117 | // ensure overwriting of old time info 118 | int empty_length = time_string.length(); 119 | 120 | std::string empty_space; 121 | 122 | // merge progress bar and time string 123 | std::stringstream strs; 124 | if(empty_length_p && abs(empty_length - empty_length_p)){ 125 | empty_space = std::string(abs(empty_length - empty_length_p), ' '); 126 | strs << "[" << cur_display << "] " << time_string << empty_space; 127 | }else{ 128 | strs << "[" << cur_display << "] " << time_string; 129 | } 130 | empty_length_p = empty_length; 131 | // strs << "[" << cur_display << "]"; 132 | 133 | std::string temp_str = strs.str(); 134 | char const* char_type = temp_str.c_str(); 135 | 136 | // print: remove old display and replace with new 137 | REprintf("\r"); 138 | REprintf("%s", char_type); 139 | 140 | } 141 | if (_ticks_displayed >= _max_ticks) 142 | // end_display(); 143 | _finalize_display(); 144 | } 145 | } 146 | 147 | void flush_console() { 148 | #if !defined(WIN32) && !defined(__WIN32) && !defined(__WIN32__) 149 | R_FlushConsole(); 150 | #endif 151 | } 152 | 153 | private: 154 | int empty_length_p = 0; 155 | int _max_ticks = 45; 156 | bool _finalized; 157 | bool _timer_flag = true; 158 | time_t start, end; 159 | int _ticks_displayed = 0; 160 | }; 161 | 162 | class MinimalProgressBar_perc: public ProgressBar{ 163 | public: 164 | MinimalProgressBar_perc() { 165 | _finalized = false; 166 | } 167 | 168 | ~MinimalProgressBar_perc() {} 169 | 170 | std::string _time_to_string(double seconds, float progress) { 171 | 172 | int time = (int) seconds; 173 | 174 | int hour = 0; 175 | int min = 0; 176 | int sec = 0; 177 | 178 | hour = time / 3600; 179 | time = time % 3600; 180 | min = time / 60; 181 | time = time % 60; 182 | sec = time; 183 | 184 | std::stringstream time_strs; 185 | time_strs << (progress < 1.0 ? "TimeLeft: " : "RunTime: "); 186 | if (hour != 0) time_strs << hour << "h"; 187 | if (hour != 0 || min != 0) time_strs << min << "m"; 188 | time_strs << sec << "s"; 189 | std::string time_str = time_strs.str(); 190 | 191 | return time_str; 192 | } 193 | 194 | int _compute_nb_ticks(float progress) { 195 | return int(progress * _max_ticks); 196 | } 197 | 198 | std::string _construct_ticks_display_string(int nb) { 199 | std::stringstream ticks_strs; 200 | for (int i = 1; i <= _max_ticks; ++i) { 201 | if (i <= nb) { 202 | ticks_strs << "*"; 203 | } else { 204 | ticks_strs << " "; 205 | } 206 | } 207 | std::string tick_space_string = ticks_strs.str(); 208 | return tick_space_string; 209 | } 210 | 211 | void end_display() { 212 | update(1); 213 | } 214 | 215 | void _finalize_display() { 216 | if (_finalized) return; 217 | REprintf("\n"); 218 | _finalized = true; 219 | } 220 | 221 | void display() { 222 | REprintf("0%% 10 20 30 40 50 60 70 80 90 100%%\n"); 223 | REprintf("[----|----|----|----|----|----|----|----|----|----|\n"); 224 | flush_console(); 225 | } 226 | 227 | void update(float progress) { 228 | 229 | // stop if already finalized 230 | if (_finalized) return; 231 | 232 | // start time measurement when update() is called the first time 233 | if (_timer_flag) { 234 | _timer_flag = false; 235 | // measure start time 236 | time(&start); 237 | } else { 238 | 239 | int nb_ticks = _compute_nb_ticks(progress); 240 | int delta = nb_ticks - _ticks_displayed; 241 | if (delta > 0) { 242 | _ticks_displayed = nb_ticks; 243 | std::string cur_display = _construct_ticks_display_string(nb_ticks); 244 | 245 | // measure current time 246 | time(&end); 247 | 248 | // calculate passed time and remaining time (in seconds) 249 | double pas_time = std::difftime(end, start); 250 | double rem_time = (progress < 1.0 ? (pas_time / progress) * (1 - progress) : pas_time); 251 | if(rem_time < 1 && rem_time > 0.5) rem_time = 1; 252 | 253 | // convert seconds to time string 254 | std::string time_string = _time_to_string(rem_time, progress); 255 | 256 | // ensure overwriting of old time info 257 | int empty_length = time_string.length(); 258 | 259 | std::string empty_space; 260 | 261 | // merge progress bar and time string 262 | std::stringstream strs; 263 | if(empty_length_p && abs(empty_length - empty_length_p)){ 264 | empty_space = std::string(abs(empty_length - empty_length_p), ' '); 265 | strs << "[" << cur_display << "] " << time_string << empty_space; 266 | }else{ 267 | strs << "[" << cur_display << "] " << time_string; 268 | } 269 | empty_length_p = empty_length; 270 | // strs << "[" << cur_display << "]"; 271 | 272 | std::string temp_str = strs.str(); 273 | char const* char_type = temp_str.c_str(); 274 | 275 | // print: remove old display and replace with new 276 | REprintf("\r"); 277 | REprintf("%s", char_type); 278 | 279 | } 280 | if (_ticks_displayed >= _max_ticks) 281 | // end_display(); 282 | _finalize_display(); 283 | } 284 | } 285 | 286 | void flush_console() { 287 | #if !defined(WIN32) && !defined(__WIN32) && !defined(__WIN32__) 288 | R_FlushConsole(); 289 | #endif 290 | } 291 | 292 | private: 293 | int empty_length_p = 0; 294 | int _max_ticks = 49; 295 | bool _finalized; 296 | bool _timer_flag = true; 297 | time_t start, end; 298 | int _ticks_displayed = 0; 299 | }; 300 | 301 | class MinimalProgressBar: public ProgressBar{ 302 | public: 303 | MinimalProgressBar() { 304 | _finalized = false; 305 | } 306 | ~MinimalProgressBar() {} 307 | void display() {} 308 | void update(float progress) { 309 | if (_finalized) return; 310 | REprintf("\r"); 311 | REprintf("Calculating in process...(finished %.2f%%)", progress * 100); 312 | } 313 | void end_display() { 314 | if (_finalized) return; 315 | REprintf("\r"); 316 | 317 | REprintf("Calculating in process...(finished 100.00%%)"); 318 | REprintf("\n"); 319 | _finalized = true; 320 | } 321 | private: 322 | bool _finalized; 323 | }; -------------------------------------------------------------------------------- /src/impute.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 by Xiaolei Team 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "simer.h" 16 | #include 17 | 18 | using namespace std; 19 | using namespace Rcpp; 20 | using namespace arma; 21 | 22 | // [[Rcpp::depends(bigmemory, BH)]] 23 | // [[Rcpp::depends(RcppArmadillo)]] 24 | // [[Rcpp::depends(RcppProgress)]] 25 | 26 | template 27 | void impute_marker(XPtr pMat, bool mrkbycol = true, int threads=0, bool verbose=true) { 28 | omp_setup(threads); 29 | 30 | MatrixAccessor mat = MatrixAccessor(*pMat); 31 | const size_t n = (mrkbycol ? pMat->nrow() : pMat->ncol()); 32 | const size_t m = (mrkbycol ? pMat->ncol() : pMat->nrow()); 33 | 34 | MinimalProgressBar_perc pb; 35 | Progress progress(m, verbose, pb); 36 | 37 | // loop marker 38 | if(mrkbycol){ 39 | #pragma omp parallel for 40 | for (size_t i = 0; i < m; i++) { 41 | std::vector na_index = {};; 42 | size_t counts[3] = { 0 }; 43 | 44 | // count allele, record missing index 45 | for (size_t j = 0; j < n; j++) { 46 | switch(int(mat[i][j])) { 47 | case 0: counts[0]++; break; 48 | case 1: counts[1]++; break; 49 | case 2: counts[2]++; break; 50 | default: na_index.push_back(j); 51 | } 52 | } 53 | 54 | // find major allele 55 | T major = counts[2] > counts[1] ? (counts[2] > counts[0] ? 2 : 0) : (counts[1] > counts[0] ? 1 : 0); 56 | 57 | // impute 58 | for (auto&& x: na_index) { 59 | mat[i][x] = major; 60 | } 61 | progress.increment(); 62 | } 63 | }else{ 64 | #pragma omp parallel for 65 | for (size_t i = 0; i < m; i++) { 66 | std::vector na_index = {};; 67 | size_t counts[3] = { 0 }; 68 | 69 | // count allele, record missing index 70 | for (size_t j = 0; j < n; j++) { 71 | switch(int(mat[j][i])) { 72 | case 0: counts[0]++; break; 73 | case 1: counts[1]++; break; 74 | case 2: counts[2]++; break; 75 | default: na_index.push_back(j); 76 | } 77 | } 78 | 79 | // find major allele 80 | T major = counts[2] > counts[1] ? (counts[2] > counts[0] ? 2 : 0) : (counts[1] > counts[0] ? 1 : 0); 81 | 82 | // impute 83 | for (auto&& x: na_index) { 84 | mat[x][i] = major; 85 | } 86 | progress.increment(); 87 | } 88 | } 89 | } 90 | 91 | // [[Rcpp::export]] 92 | void impute_marker(SEXP pBigMat, bool mrkbycol = true, int threads=0, bool verbose=true) { 93 | XPtr xpMat(pBigMat); 94 | 95 | switch(xpMat->matrix_type()) { 96 | case 1: 97 | return impute_marker(xpMat, mrkbycol, threads, verbose); 98 | case 2: 99 | return impute_marker(xpMat, mrkbycol, threads, verbose); 100 | case 4: 101 | return impute_marker(xpMat, mrkbycol, threads, verbose); 102 | case 8: 103 | return impute_marker(xpMat, mrkbycol, threads, verbose); 104 | default: 105 | throw Rcpp::exception("unknown type detected for big.matrix object!"); 106 | } 107 | } 108 | 109 | template 110 | bool hasNA(XPtr pMat, bool mrkbycol = true, const Nullable geno_ind = R_NilValue, const Nullable marker_ind = R_NilValue, const int threads = 1) { 111 | 112 | omp_setup(threads); 113 | 114 | bool HasNA = false; 115 | MatrixAccessor mat = MatrixAccessor(*pMat); 116 | 117 | if(geno_ind.isNotNull()){ 118 | uvec _geno_ind = as(geno_ind) - 1; 119 | int n = _geno_ind.n_elem; 120 | if(marker_ind.isNotNull()){ 121 | uvec _marker_ind = as(marker_ind) - 1; 122 | int m = _marker_ind.n_elem; 123 | if(mrkbycol){ 124 | #pragma omp parallel for shared(HasNA) 125 | for (int j = 0; j < m; j++) { 126 | if(HasNA) continue; 127 | for (int i = 0; i < n; i++) { 128 | // if (mat[_marker_ind[j]][_geno_ind[i]] == NA_C) { 129 | if (isna(mat[_marker_ind[j]][_geno_ind[i]])) { 130 | HasNA = true; 131 | } 132 | } 133 | } 134 | }else{ 135 | #pragma omp parallel for shared(HasNA) 136 | for (int j = 0; j < n; j++) { 137 | if(HasNA) continue; 138 | for (int i = 0; i < m; i++) { 139 | // if (mat[_geno_ind[j]][_marker_ind[i]] == NA_C) { 140 | if (isna(mat[_geno_ind[j]][_marker_ind[i]])) { 141 | HasNA = true; 142 | } 143 | } 144 | } 145 | } 146 | }else{ 147 | if(mrkbycol){ 148 | #pragma omp parallel for shared(HasNA) 149 | for (int j = 0; j < pMat->ncol(); j++) { 150 | if(HasNA) continue; 151 | for (int i = 0; i < n; i++) { 152 | // if (mat[j][_geno_ind[i]] == NA_C) { 153 | if (isna(mat[j][_geno_ind[i]])) { 154 | HasNA = true; 155 | } 156 | } 157 | } 158 | }else{ 159 | #pragma omp parallel for shared(HasNA) 160 | for (int j = 0; j < n; j++) { 161 | if(HasNA) continue; 162 | for (int i = 0; i < pMat->nrow(); i++) { 163 | // if (mat[_geno_ind[j]][i] == NA_C) { 164 | if (isna(mat[_geno_ind[j]][i])) { 165 | HasNA = true; 166 | } 167 | } 168 | } 169 | } 170 | } 171 | }else{ 172 | if(marker_ind.isNotNull()){ 173 | uvec _marker_ind = as(marker_ind) - 1; 174 | int m = _marker_ind.n_elem; 175 | if(mrkbycol){ 176 | #pragma omp parallel for shared(HasNA) 177 | for (int j = 0; j < m; j++) { 178 | if(HasNA) continue; 179 | for (int i = 0; i < pMat->nrow(); i++) { 180 | // if (mat[_marker_ind[j]][i] == NA_C) { 181 | if (isna(mat[_marker_ind[j]][i])) { 182 | HasNA = true; 183 | } 184 | } 185 | } 186 | }else{ 187 | #pragma omp parallel for shared(HasNA) 188 | for (int j = 0; j < pMat->ncol(); j++) { 189 | if(HasNA) continue; 190 | for (int i = 0; i < m; i++) { 191 | // if (mat[j][_marker_ind[i]] == NA_C) { 192 | if (isna(mat[j][_marker_ind[i]])) { 193 | HasNA = true; 194 | } 195 | } 196 | } 197 | } 198 | }else{ 199 | #pragma omp parallel for shared(HasNA) 200 | for (int j = 0; j < pMat->ncol(); j++) { 201 | if(HasNA) continue; 202 | for (int i = 0; i < pMat->nrow(); i++) { 203 | // if (mat[j][i] == NA_C) { 204 | if (isna(mat[j][i])) { 205 | HasNA = true; 206 | } 207 | } 208 | } 209 | } 210 | } 211 | return HasNA; 212 | } 213 | 214 | // [[Rcpp::export]] 215 | bool hasNA(SEXP pBigMat, bool mrkbycol = true, const Nullable geno_ind = R_NilValue, const Nullable marker_ind = R_NilValue, const int threads=1) { 216 | XPtr xpMat(pBigMat); 217 | 218 | switch(xpMat->matrix_type()) { 219 | case 1: 220 | return hasNA(xpMat, mrkbycol, geno_ind, marker_ind, threads); 221 | case 2: 222 | return hasNA(xpMat, mrkbycol, geno_ind, marker_ind, threads); 223 | case 4: 224 | return hasNA(xpMat, mrkbycol, geno_ind, marker_ind, threads); 225 | case 8: 226 | return hasNA(xpMat, mrkbycol, geno_ind, marker_ind, threads); 227 | default: 228 | throw Rcpp::exception("unknown type detected for big.matrix object!"); 229 | } 230 | } 231 | 232 | // [[Rcpp::export]] 233 | bool hasNABed(std::string bed_file, int ind, long maxLine, int threads=0, bool verbose=true) { 234 | // check input 235 | if (!boost::ends_with(bed_file, ".bed")) { 236 | bed_file += ".bed"; 237 | } 238 | 239 | // define 240 | omp_setup(threads); 241 | size_t indt = ind; 242 | long n = indt / 4; // 4 individual = 1 bit 243 | if (indt % 4 != 0) 244 | n++; 245 | char *buffer; 246 | long buffer_size; 247 | bool HasNA = false; 248 | 249 | // open file 250 | FILE *fin; 251 | fin = fopen(bed_file.c_str(), "rb"); 252 | fseek(fin, 0, SEEK_END); 253 | long length = ftell(fin); 254 | rewind(fin); 255 | 256 | // get buffer_size 257 | buffer_size = maxLine > 0 ? (maxLine * n) : (length - 3); 258 | 259 | // progress bar 260 | int n_block = (length - 3) / buffer_size; 261 | if ((length - 3) % buffer_size != 0) { n_block++; } 262 | 263 | // magic number of bfile 264 | buffer = new char [3]; 265 | size_t n_bytes_read = static_cast(fread(buffer, 1, 3, fin)); 266 | if (n_bytes_read != 3) { // new if 267 | Rcpp::stop("It is not a normal binary file!"); 268 | } 269 | 270 | // loop file 271 | size_t cond; 272 | long block_start; 273 | for (int i = 0; i < n_block; i++) { 274 | buffer = new char [buffer_size]; 275 | n_bytes_read = static_cast(fread(buffer, 1, buffer_size, fin)); 276 | 277 | // i: current block, j: current bit. 278 | block_start = i * buffer_size; 279 | cond = min(buffer_size, length - 3 - block_start); 280 | 281 | #pragma omp parallel for 282 | for (size_t j = 0; j < cond; j++) { 283 | // bit -> item in matrix 284 | // size_t r = j / n + i * maxLine; 285 | size_t c = j % n * 4; 286 | uint8_t p = buffer[j]; 287 | 288 | if (HasNA) continue; 289 | 290 | for (size_t x = 0; x < 4 && (c + x) < indt; x++) { 291 | if (1 == ((p >> (2*x)) & 0x03)) { 292 | HasNA = true; 293 | break; 294 | } 295 | } 296 | } 297 | } 298 | fclose(fin); 299 | 300 | return HasNA; 301 | } 302 | -------------------------------------------------------------------------------- /R/simer.Selects.R: -------------------------------------------------------------------------------- 1 | # Licensed under the Apache License, Version 2.0 (the "License"); 2 | # you may not use this file except in compliance with the License. 3 | # You may obtain a copy of the License at 4 | # 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | 13 | 14 | #' Selection 15 | #' 16 | #' Select individuals by combination of selection method and criterion. 17 | #' 18 | #' Build date: Sep 8, 2018 19 | #' Last update: Apr 19, 2025 20 | #' 21 | #' @author Dong Yin 22 | #' 23 | #' @param SP a list of all simulation parameters. 24 | #' @param verbose whether to print detail. 25 | #' 26 | #' @return 27 | #' the function returns a list containing 28 | #' \describe{ 29 | #' \item{$sel$pop.sel}{the selected males and females.} 30 | #' \item{$sel$ps}{if ps <= 1, fraction selected in selection of males and females; if ps > 1, ps is number of selected males and females.} 31 | #' \item{$sel$decr}{whether the sort order is decreasing.} 32 | #' \item{$sel$sel.crit}{the selection criteria, it can be "TBV", "TGV", and "pheno".} 33 | #' \item{$sel$sel.single}{the single-trait selection method, it can be "ind", "fam", "infam", and "comb".} 34 | #' \item{$sel$sel.multi}{the multiple-trait selection method, it can be "index", "indcul", and "tmd".} 35 | #' \item{$sel$index.wt}{the weight of each trait for multiple-trait selection.} 36 | #' \item{$sel$index.tdm}{the index of tandem selection for multiple-trait selection.} 37 | #' \item{$sel$goal.perc}{the percentage of goal more than the mean of scores of individuals.} 38 | #' \item{$sel$pass.perc}{the percentage of expected excellent individuals.} 39 | #' } 40 | #' 41 | #' @export 42 | #' 43 | #' @examples 44 | #' \donttest{ 45 | #' # Generate annotation simulation parameters 46 | #' SP <- param.annot(qtn.num = list(tr1 = 10)) 47 | #' # Generate genotype simulation parameters 48 | #' SP <- param.geno(SP = SP, pop.marker = 1e4, pop.ind = 1e2) 49 | #' # Generate phenotype simulation parameters 50 | #' SP <- param.pheno(SP = SP, pop.ind = 100) 51 | #' # Generate selection parameters 52 | #' SP <- param.sel(SP = SP, sel.single = "ind") 53 | #' 54 | #' # Run annotation simulation 55 | #' SP <- annotation(SP) 56 | #' # Run genotype simulation 57 | #' SP <- genotype(SP) 58 | #' # Run phenotype simulation 59 | #' SP <- phenotype(SP) 60 | #' # Run selection 61 | #' SP <- selects(SP) 62 | #' } 63 | selects <- function(SP = NULL, verbose = TRUE) { 64 | 65 | ### Start selection 66 | 67 | # selection parameters 68 | pop.sel <- SP$sel$pop.sel 69 | pop <- SP$pheno$pop[[length(SP$pheno$pop)]] 70 | pop.total <- do.call(rbind, SP$pheno$pop) 71 | ps <- SP$sel$ps 72 | decr <- SP$sel$decr 73 | sel.crit <- SP$sel$sel.crit 74 | sel.single <- SP$sel$sel.single 75 | sel.multi <- SP$sel$sel.multi 76 | index.wt <- SP$sel$index.wt 77 | index.tdm <- SP$sel$index.tdm 78 | goal.perc <- SP$sel$goal.perc 79 | pass.perc <- SP$sel$pass.perc 80 | pop.ind <- length(pop$index) 81 | if (!is.null(SP$global$pop.gen)) { 82 | pop.gen <- SP$global$pop.gen - 1 83 | } else if (!is.null(SP$reprod$pop.gen)) { 84 | pop.gen <- SP$reprod$pop.gen - 1 85 | } else { 86 | stop("Please add 'SP$global$pop.gen'!") 87 | } 88 | 89 | if (length(pop.gen) == 0) { pop.gen <- 0 } 90 | 91 | if (pop.gen == 0 || all(ps == 1)) { 92 | ind.ordered <- pop$index 93 | 94 | } else { 95 | if (!(all(ps <= 1) | all(ps > 1))) { 96 | stop("Please input a correct ps!") 97 | } 98 | if (sel.crit == "pheno") { 99 | phe.name <- grep(pattern = "TBV", x = names(pop), value = TRUE) 100 | phe.name <- substr(phe.name, 1, nchar(phe.name) - 4) 101 | } else if (sel.crit == "TBV") { 102 | phe.name <- grep(pattern = "TBV", x = names(pop), value = TRUE) 103 | } else if (sel.crit == "TGV") { 104 | phe.name <- grep(pattern = "TGV", x = names(pop), value = TRUE) 105 | } else { 106 | stop("'sel.crit' should be 'pheno', 'TBV', 'TGV', 'pEBVs', 'gEBVs' or 'ssEBVs'!") 107 | } 108 | phe.pos <- match(phe.name, names(pop)) 109 | 110 | ### single trait selection ### 111 | if (length(phe.pos) == 1) { 112 | num.infam <- tapply(rep(1, pop.ind), pop$fam, sum) 113 | if (sel.single == "comb") { 114 | # calculate A matrix 115 | A.cal <- function(s, d) { 116 | n <- length(s) 117 | A <- matrix(0, nrow = n, ncol = n) 118 | for (x in 1:n) { 119 | if (s[x] > 0 && d[x] > 0) { 120 | A[x, x] <- 1 + 0.5 * A[s[x], d[x]]; 121 | } else { 122 | A[x, x] <- 1; 123 | } 124 | if (x == n) next 125 | for (y in (x+1):n) { 126 | axy <- 0 127 | if (s[y] > 0) axy <- axy + 0.5 * A[x, s[y]] 128 | if (d[y] > 0) axy <- axy + 0.5 * A[x, d[y]] 129 | A[x, y] <- axy 130 | A[y, x] <- axy 131 | } 132 | } 133 | return(A) 134 | } 135 | # calculate average family correlation coefficient 136 | cal.r <- function(pop, pop.total) { 137 | if (nrow(pop.total) == nrow(pop)) { return(0.01) } 138 | sir <- pop.total$sir 139 | sir <- as.numeric(sir[sir != "NA"]) 140 | dam <- pop.total$dam 141 | dam <- as.numeric(dam[dam != "NA"]) 142 | A.mat <- A.cal(sir, dam) 143 | cor.ani <- pop[!duplicated(pop$fam), ]$index 144 | cor.r <- rep(0, length(cor.ani)) 145 | for (i in 1:length(cor.ani)) { 146 | cor.r[i] <- A.mat[cor.ani[i], cor.ani[i]+1] 147 | } 148 | cor.r <- mean(cor.r) 149 | return(cor.r) 150 | } 151 | cor.r <- cal.r(pop, pop.total) 152 | # calculate combination selection method 153 | cal.comb <- function(pop) { 154 | pop.ind <- length(pop$index) 155 | num.infam <- tapply(rep(1, pop.ind), pop$fam, sum) 156 | pf <- rep(tapply(pop[, phe.pos], pop$fam, mean), num.infam) 157 | cor.n <- num.infam[[1]] 158 | 159 | if (length(num.infam) == 1) { 160 | cor.t <- 2 161 | } else { 162 | pop.tab <- summary(aov(pop[, phe.pos]~as.factor(pop$fam))) 163 | MB <- pop.tab[[1]][1, 3] 164 | MW <- pop.tab[[1]][2, 3] 165 | if (is.na(MW)) MW <- 0 166 | cor.t <- (MB - MW) / (MB + (cor.n - 1) * MW) 167 | } 168 | 169 | I <- pop[, phe.pos] + ((cor.r-cor.t)*cor.n / (1-cor.r) / (1+(cor.n-1)*cor.t)) * pf 170 | ind.score <- cbind(pop$index, I) 171 | ind.score.ordered <- ind.score[order(ind.score[, 2], decreasing=decr), ] 172 | ind.ordered <- as.vector(ind.score.ordered[, 1]) 173 | return(ind.ordered) 174 | } 175 | ind.ordered <- cal.comb(pop) 176 | 177 | } else { 178 | if (sel.single == "ind") { 179 | bf <- rep(1, pop.ind) 180 | bw <- rep(1, pop.ind) 181 | 182 | } else if (sel.single == "fam") { 183 | bf <- rep(1, pop.ind) 184 | bw <- rep(0, pop.ind) 185 | 186 | } else if (sel.single == "infam") { 187 | bf <- rep(0, pop.ind) 188 | bw <- rep(1, pop.ind) 189 | } 190 | bfw <- cbind(bf, bw) 191 | 192 | # calculate pf and pw 193 | cal.pfw <- function(pop) { 194 | pop.ind <- length(pop$index) 195 | num.infam <- tapply(rep(1, pop.ind), pop$fam, sum) 196 | pf <- rep(tapply(pop[, phe.pos], pop$fam, mean), num.infam) 197 | pw <- pop[, phe.pos] - pf 198 | pfw <- cbind(pf, pw) 199 | return(pfw) 200 | } 201 | 202 | pfw <- cal.pfw(pop) 203 | I <- apply(bfw * pfw, 1, sum) 204 | ind.score <- cbind(pop$index, I) 205 | ind.score.ordered <- ind.score[order(ind.score[, 2], decreasing=decr), ] 206 | ind.ordered <- ind.score.ordered[, 1] 207 | } 208 | 209 | ### multiple trait selection ### 210 | } else { 211 | pheno <- pop[, phe.pos] 212 | 213 | goal <- (1 + goal.perc) * apply(pheno, 2, mean) 214 | 215 | if (sel.multi == "index") { 216 | # calculate the weight of index selection 217 | cal.idx <- function(pheno, index.wt) { 218 | if(ncol(pheno) != length(index.wt)) { 219 | stop("Column of phenotype should equal length of weight of index") 220 | } 221 | # phenotype covariance matrix 222 | P <- var(pheno) 223 | iP <- try(solve(P), silent = TRUE) 224 | if (inherits(iP, "try-error")) { 225 | iP <- ginv(P) 226 | } 227 | TBV <- pop[, grep(pattern = "TBV", x = names(pop))] 228 | # BV covariance matrix 229 | A <- var(TBV) 230 | b <- iP %*% A %*% index.wt 231 | b <- as.vector(b) 232 | } 233 | b <- cal.idx(pheno = pheno, index.wt = index.wt) 234 | 235 | ind.score <- cbind(pop$index, apply(pheno * b, 1, sum)) 236 | ind.score.ordered <- ind.score[order(ind.score[, 2], decreasing = decr), ] 237 | ind.ordered <- ind.score.ordered[, 1] 238 | attr(ind.ordered, "names") <- NULL 239 | 240 | } else if (sel.multi == "indcul") { 241 | flag.prior <- apply(pheno, 1, function(v) { 242 | return(all(v > goal)) 243 | }) 244 | ind.ordered <- c(pop$index[flag.prior], pop$index[!flag.prior]) 245 | 246 | } else if (sel.multi == "tdm") { 247 | ind.score <- cbind(pop$index, pheno[, index.tdm]) 248 | ind.score.ordered <- ind.score[order(ind.score[, 2], decreasing = decr), ] 249 | ind.ordered <- ind.score.ordered[, 1] 250 | if (index.tdm == ncol(pheno)) { 251 | logging.log(" All phenotype have selected by tandem method.\n", verbose = verbose) 252 | SP$sel$index.tmd <- 1 253 | } 254 | if (pheno[nrow(pheno) * pass.perc, index.tdm] >= goal[index.tdm]) { 255 | SP$sel$index.tmd <- index.tdm + 1 256 | } 257 | 258 | } else { 259 | stop("sel.multi should be index, indcul or tdm") 260 | } 261 | } 262 | } 263 | 264 | # get selected sires and dams 265 | ind.sir <- pop$index[pop$sex == 1 | pop$sex == 0] 266 | ind.dam <- pop$index[pop$sex == 2 | pop$sex == 0] 267 | nSir <- ifelse(all(ps <= 1), round(length(ind.sir) * ps[1]), ps[1]) 268 | nDam <- ifelse(all(ps <= 1), round(length(ind.dam) * ps[2]), ps[2]) 269 | sir.ordered <- intersect(ind.ordered, ind.sir) 270 | dam.ordered <- intersect(ind.ordered, ind.dam) 271 | if (length(sir.ordered) == 0 | nSir == 0) { 272 | sir.stay <- NULL 273 | } else { 274 | if (nSir <= length(ind.sir)) { 275 | sir.stay <- sir.ordered[1:nSir] 276 | } else { 277 | sir.stay <- c(sir.ordered, sample(sir.ordered, nSir-length(ind.sir), replace = TRUE)) 278 | } 279 | } 280 | if (length(dam.ordered) == 0 | nDam == 0) { 281 | dam.stay <- NULL 282 | } else { 283 | if (nDam <= length(ind.dam)) { 284 | dam.stay <- dam.ordered[1:nDam] 285 | } else { 286 | dam.stay <- c(dam.ordered, sample(dam.ordered, nDam-length(ind.dam), replace = TRUE)) 287 | } 288 | } 289 | pop.sel <- list(sir = sir.stay, dam = dam.stay) 290 | 291 | SP$sel$pop.sel[[ifelse(is.null(SP$sel$pop.sel), 1, length(SP$sel$pop.sel) + 1)]] <- pop.sel 292 | names(SP$sel$pop.sel)[length(SP$sel$pop.sel)] <- paste0("gen", length(SP$sel$pop.sel)) 293 | return(SP) 294 | } 295 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | // Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #include 5 | #include 6 | 7 | using namespace Rcpp; 8 | 9 | #ifdef RCPP_USE_GLOBAL_ROSTREAM 10 | Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); 11 | Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); 12 | #endif 13 | 14 | // write_bfile 15 | void write_bfile(SEXP pBigMat, std::string bed_file, bool mrkbycol, int threads, bool verbose); 16 | RcppExport SEXP _simer_write_bfile(SEXP pBigMatSEXP, SEXP bed_fileSEXP, SEXP mrkbycolSEXP, SEXP threadsSEXP, SEXP verboseSEXP) { 17 | BEGIN_RCPP 18 | Rcpp::RNGScope rcpp_rngScope_gen; 19 | Rcpp::traits::input_parameter< SEXP >::type pBigMat(pBigMatSEXP); 20 | Rcpp::traits::input_parameter< std::string >::type bed_file(bed_fileSEXP); 21 | Rcpp::traits::input_parameter< bool >::type mrkbycol(mrkbycolSEXP); 22 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 23 | Rcpp::traits::input_parameter< bool >::type verbose(verboseSEXP); 24 | write_bfile(pBigMat, bed_file, mrkbycol, threads, verbose); 25 | return R_NilValue; 26 | END_RCPP 27 | } 28 | // read_bfile 29 | void read_bfile(std::string bed_file, SEXP pBigMat, long maxLine, int threads, bool verbose); 30 | RcppExport SEXP _simer_read_bfile(SEXP bed_fileSEXP, SEXP pBigMatSEXP, SEXP maxLineSEXP, SEXP threadsSEXP, SEXP verboseSEXP) { 31 | BEGIN_RCPP 32 | Rcpp::RNGScope rcpp_rngScope_gen; 33 | Rcpp::traits::input_parameter< std::string >::type bed_file(bed_fileSEXP); 34 | Rcpp::traits::input_parameter< SEXP >::type pBigMat(pBigMatSEXP); 35 | Rcpp::traits::input_parameter< long >::type maxLine(maxLineSEXP); 36 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 37 | Rcpp::traits::input_parameter< bool >::type verbose(verboseSEXP); 38 | read_bfile(bed_file, pBigMat, maxLine, threads, verbose); 39 | return R_NilValue; 40 | END_RCPP 41 | } 42 | // GenoFilter 43 | List GenoFilter(const SEXP pBigMat, double NA_C, Nullable keepIndsNull, Nullable filterGeno, Nullable filterHWE, Nullable filterMind, Nullable filterMAF, int threads, bool verbose); 44 | RcppExport SEXP _simer_GenoFilter(SEXP pBigMatSEXP, SEXP NA_CSEXP, SEXP keepIndsNullSEXP, SEXP filterGenoSEXP, SEXP filterHWESEXP, SEXP filterMindSEXP, SEXP filterMAFSEXP, SEXP threadsSEXP, SEXP verboseSEXP) { 45 | BEGIN_RCPP 46 | Rcpp::RObject rcpp_result_gen; 47 | Rcpp::RNGScope rcpp_rngScope_gen; 48 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 49 | Rcpp::traits::input_parameter< double >::type NA_C(NA_CSEXP); 50 | Rcpp::traits::input_parameter< Nullable >::type keepIndsNull(keepIndsNullSEXP); 51 | Rcpp::traits::input_parameter< Nullable >::type filterGeno(filterGenoSEXP); 52 | Rcpp::traits::input_parameter< Nullable >::type filterHWE(filterHWESEXP); 53 | Rcpp::traits::input_parameter< Nullable >::type filterMind(filterMindSEXP); 54 | Rcpp::traits::input_parameter< Nullable >::type filterMAF(filterMAFSEXP); 55 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 56 | Rcpp::traits::input_parameter< bool >::type verbose(verboseSEXP); 57 | rcpp_result_gen = Rcpp::wrap(GenoFilter(pBigMat, NA_C, keepIndsNull, filterGeno, filterHWE, filterMind, filterMAF, threads, verbose)); 58 | return rcpp_result_gen; 59 | END_RCPP 60 | } 61 | // Mat2BigMat 62 | void Mat2BigMat(const SEXP pBigMat, IntegerMatrix& mat, Nullable indIdxNull, int op, int threads); 63 | RcppExport SEXP _simer_Mat2BigMat(SEXP pBigMatSEXP, SEXP matSEXP, SEXP indIdxNullSEXP, SEXP opSEXP, SEXP threadsSEXP) { 64 | BEGIN_RCPP 65 | Rcpp::RNGScope rcpp_rngScope_gen; 66 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 67 | Rcpp::traits::input_parameter< IntegerMatrix& >::type mat(matSEXP); 68 | Rcpp::traits::input_parameter< Nullable >::type indIdxNull(indIdxNullSEXP); 69 | Rcpp::traits::input_parameter< int >::type op(opSEXP); 70 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 71 | Mat2BigMat(pBigMat, mat, indIdxNull, op, threads); 72 | return R_NilValue; 73 | END_RCPP 74 | } 75 | // BigMat2BigMat 76 | void BigMat2BigMat(const SEXP pBigMat, const SEXP pBigmat, Nullable indIdxNull, int op, int threads); 77 | RcppExport SEXP _simer_BigMat2BigMat(SEXP pBigMatSEXP, SEXP pBigmatSEXP, SEXP indIdxNullSEXP, SEXP opSEXP, SEXP threadsSEXP) { 78 | BEGIN_RCPP 79 | Rcpp::RNGScope rcpp_rngScope_gen; 80 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 81 | Rcpp::traits::input_parameter< const SEXP >::type pBigmat(pBigmatSEXP); 82 | Rcpp::traits::input_parameter< Nullable >::type indIdxNull(indIdxNullSEXP); 83 | Rcpp::traits::input_parameter< int >::type op(opSEXP); 84 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 85 | BigMat2BigMat(pBigMat, pBigmat, indIdxNull, op, threads); 86 | return R_NilValue; 87 | END_RCPP 88 | } 89 | // geno_cvt1_mat 90 | void geno_cvt1_mat(const SEXP pBigMat, IntegerMatrix& mat, int threads); 91 | RcppExport SEXP _simer_geno_cvt1_mat(SEXP pBigMatSEXP, SEXP matSEXP, SEXP threadsSEXP) { 92 | BEGIN_RCPP 93 | Rcpp::RNGScope rcpp_rngScope_gen; 94 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 95 | Rcpp::traits::input_parameter< IntegerMatrix& >::type mat(matSEXP); 96 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 97 | geno_cvt1_mat(pBigMat, mat, threads); 98 | return R_NilValue; 99 | END_RCPP 100 | } 101 | // geno_cvt1_bigmat 102 | void geno_cvt1_bigmat(const SEXP pBigMat, const SEXP pBigmat, int threads); 103 | RcppExport SEXP _simer_geno_cvt1_bigmat(SEXP pBigMatSEXP, SEXP pBigmatSEXP, SEXP threadsSEXP) { 104 | BEGIN_RCPP 105 | Rcpp::RNGScope rcpp_rngScope_gen; 106 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 107 | Rcpp::traits::input_parameter< const SEXP >::type pBigmat(pBigmatSEXP); 108 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 109 | geno_cvt1_bigmat(pBigMat, pBigmat, threads); 110 | return R_NilValue; 111 | END_RCPP 112 | } 113 | // geno_cvt2_mat 114 | void geno_cvt2_mat(const SEXP pBigMat, IntegerMatrix& mat, int threads); 115 | RcppExport SEXP _simer_geno_cvt2_mat(SEXP pBigMatSEXP, SEXP matSEXP, SEXP threadsSEXP) { 116 | BEGIN_RCPP 117 | Rcpp::RNGScope rcpp_rngScope_gen; 118 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 119 | Rcpp::traits::input_parameter< IntegerMatrix& >::type mat(matSEXP); 120 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 121 | geno_cvt2_mat(pBigMat, mat, threads); 122 | return R_NilValue; 123 | END_RCPP 124 | } 125 | // geno_cvt2_bigmat 126 | void geno_cvt2_bigmat(const SEXP pBigMat, const SEXP pBigmat, int threads); 127 | RcppExport SEXP _simer_geno_cvt2_bigmat(SEXP pBigMatSEXP, SEXP pBigmatSEXP, SEXP threadsSEXP) { 128 | BEGIN_RCPP 129 | Rcpp::RNGScope rcpp_rngScope_gen; 130 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 131 | Rcpp::traits::input_parameter< const SEXP >::type pBigmat(pBigmatSEXP); 132 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 133 | geno_cvt2_bigmat(pBigMat, pBigmat, threads); 134 | return R_NilValue; 135 | END_RCPP 136 | } 137 | // bigt_mat 138 | void bigt_mat(const SEXP pBigMat, IntegerMatrix& mat, int threads); 139 | RcppExport SEXP _simer_bigt_mat(SEXP pBigMatSEXP, SEXP matSEXP, SEXP threadsSEXP) { 140 | BEGIN_RCPP 141 | Rcpp::RNGScope rcpp_rngScope_gen; 142 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 143 | Rcpp::traits::input_parameter< IntegerMatrix& >::type mat(matSEXP); 144 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 145 | bigt_mat(pBigMat, mat, threads); 146 | return R_NilValue; 147 | END_RCPP 148 | } 149 | // bigt_bigmat 150 | void bigt_bigmat(const SEXP pBigMat, const SEXP pBigmat, int threads); 151 | RcppExport SEXP _simer_bigt_bigmat(SEXP pBigMatSEXP, SEXP pBigmatSEXP, SEXP threadsSEXP) { 152 | BEGIN_RCPP 153 | Rcpp::RNGScope rcpp_rngScope_gen; 154 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 155 | Rcpp::traits::input_parameter< const SEXP >::type pBigmat(pBigmatSEXP); 156 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 157 | bigt_bigmat(pBigMat, pBigmat, threads); 158 | return R_NilValue; 159 | END_RCPP 160 | } 161 | // impute_marker 162 | void impute_marker(SEXP pBigMat, bool mrkbycol, int threads, bool verbose); 163 | RcppExport SEXP _simer_impute_marker(SEXP pBigMatSEXP, SEXP mrkbycolSEXP, SEXP threadsSEXP, SEXP verboseSEXP) { 164 | BEGIN_RCPP 165 | Rcpp::RNGScope rcpp_rngScope_gen; 166 | Rcpp::traits::input_parameter< SEXP >::type pBigMat(pBigMatSEXP); 167 | Rcpp::traits::input_parameter< bool >::type mrkbycol(mrkbycolSEXP); 168 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 169 | Rcpp::traits::input_parameter< bool >::type verbose(verboseSEXP); 170 | impute_marker(pBigMat, mrkbycol, threads, verbose); 171 | return R_NilValue; 172 | END_RCPP 173 | } 174 | // hasNA 175 | bool hasNA(SEXP pBigMat, bool mrkbycol, const Nullable geno_ind, const Nullable marker_ind, const int threads); 176 | RcppExport SEXP _simer_hasNA(SEXP pBigMatSEXP, SEXP mrkbycolSEXP, SEXP geno_indSEXP, SEXP marker_indSEXP, SEXP threadsSEXP) { 177 | BEGIN_RCPP 178 | Rcpp::RObject rcpp_result_gen; 179 | Rcpp::RNGScope rcpp_rngScope_gen; 180 | Rcpp::traits::input_parameter< SEXP >::type pBigMat(pBigMatSEXP); 181 | Rcpp::traits::input_parameter< bool >::type mrkbycol(mrkbycolSEXP); 182 | Rcpp::traits::input_parameter< const Nullable >::type geno_ind(geno_indSEXP); 183 | Rcpp::traits::input_parameter< const Nullable >::type marker_ind(marker_indSEXP); 184 | Rcpp::traits::input_parameter< const int >::type threads(threadsSEXP); 185 | rcpp_result_gen = Rcpp::wrap(hasNA(pBigMat, mrkbycol, geno_ind, marker_ind, threads)); 186 | return rcpp_result_gen; 187 | END_RCPP 188 | } 189 | // hasNABed 190 | bool hasNABed(std::string bed_file, int ind, long maxLine, int threads, bool verbose); 191 | RcppExport SEXP _simer_hasNABed(SEXP bed_fileSEXP, SEXP indSEXP, SEXP maxLineSEXP, SEXP threadsSEXP, SEXP verboseSEXP) { 192 | BEGIN_RCPP 193 | Rcpp::RObject rcpp_result_gen; 194 | Rcpp::RNGScope rcpp_rngScope_gen; 195 | Rcpp::traits::input_parameter< std::string >::type bed_file(bed_fileSEXP); 196 | Rcpp::traits::input_parameter< int >::type ind(indSEXP); 197 | Rcpp::traits::input_parameter< long >::type maxLine(maxLineSEXP); 198 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 199 | Rcpp::traits::input_parameter< bool >::type verbose(verboseSEXP); 200 | rcpp_result_gen = Rcpp::wrap(hasNABed(bed_file, ind, maxLine, threads, verbose)); 201 | return rcpp_result_gen; 202 | END_RCPP 203 | } 204 | // PedigreeCorrector 205 | DataFrame PedigreeCorrector(const SEXP pBigMat, StringVector rawGenoID, DataFrame rawPed, Nullable candSirID, Nullable candDamID, double exclThres, double assignThres, Nullable birthDate, int threads, bool verbose); 206 | RcppExport SEXP _simer_PedigreeCorrector(SEXP pBigMatSEXP, SEXP rawGenoIDSEXP, SEXP rawPedSEXP, SEXP candSirIDSEXP, SEXP candDamIDSEXP, SEXP exclThresSEXP, SEXP assignThresSEXP, SEXP birthDateSEXP, SEXP threadsSEXP, SEXP verboseSEXP) { 207 | BEGIN_RCPP 208 | Rcpp::RObject rcpp_result_gen; 209 | Rcpp::RNGScope rcpp_rngScope_gen; 210 | Rcpp::traits::input_parameter< const SEXP >::type pBigMat(pBigMatSEXP); 211 | Rcpp::traits::input_parameter< StringVector >::type rawGenoID(rawGenoIDSEXP); 212 | Rcpp::traits::input_parameter< DataFrame >::type rawPed(rawPedSEXP); 213 | Rcpp::traits::input_parameter< Nullable >::type candSirID(candSirIDSEXP); 214 | Rcpp::traits::input_parameter< Nullable >::type candDamID(candDamIDSEXP); 215 | Rcpp::traits::input_parameter< double >::type exclThres(exclThresSEXP); 216 | Rcpp::traits::input_parameter< double >::type assignThres(assignThresSEXP); 217 | Rcpp::traits::input_parameter< Nullable >::type birthDate(birthDateSEXP); 218 | Rcpp::traits::input_parameter< int >::type threads(threadsSEXP); 219 | Rcpp::traits::input_parameter< bool >::type verbose(verboseSEXP); 220 | rcpp_result_gen = Rcpp::wrap(PedigreeCorrector(pBigMat, rawGenoID, rawPed, candSirID, candDamID, exclThres, assignThres, birthDate, threads, verbose)); 221 | return rcpp_result_gen; 222 | END_RCPP 223 | } 224 | 225 | static const R_CallMethodDef CallEntries[] = { 226 | {"_simer_write_bfile", (DL_FUNC) &_simer_write_bfile, 5}, 227 | {"_simer_read_bfile", (DL_FUNC) &_simer_read_bfile, 5}, 228 | {"_simer_GenoFilter", (DL_FUNC) &_simer_GenoFilter, 9}, 229 | {"_simer_Mat2BigMat", (DL_FUNC) &_simer_Mat2BigMat, 5}, 230 | {"_simer_BigMat2BigMat", (DL_FUNC) &_simer_BigMat2BigMat, 5}, 231 | {"_simer_geno_cvt1_mat", (DL_FUNC) &_simer_geno_cvt1_mat, 3}, 232 | {"_simer_geno_cvt1_bigmat", (DL_FUNC) &_simer_geno_cvt1_bigmat, 3}, 233 | {"_simer_geno_cvt2_mat", (DL_FUNC) &_simer_geno_cvt2_mat, 3}, 234 | {"_simer_geno_cvt2_bigmat", (DL_FUNC) &_simer_geno_cvt2_bigmat, 3}, 235 | {"_simer_bigt_mat", (DL_FUNC) &_simer_bigt_mat, 3}, 236 | {"_simer_bigt_bigmat", (DL_FUNC) &_simer_bigt_bigmat, 3}, 237 | {"_simer_impute_marker", (DL_FUNC) &_simer_impute_marker, 4}, 238 | {"_simer_hasNA", (DL_FUNC) &_simer_hasNA, 5}, 239 | {"_simer_hasNABed", (DL_FUNC) &_simer_hasNABed, 5}, 240 | {"_simer_PedigreeCorrector", (DL_FUNC) &_simer_PedigreeCorrector, 10}, 241 | {NULL, NULL, 0} 242 | }; 243 | 244 | RcppExport void R_init_simer(DllInfo *dll) { 245 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 246 | R_useDynamicSymbols(dll, FALSE); 247 | } 248 | --------------------------------------------------------------------------------