Skip to content

Commit 7c58581

Browse files
Merge pull request #39 from R-Computing-Lab/dev_main
1.3.1 BGA
2 parents 65d9ed3 + 942080d commit 7c58581

30 files changed

Lines changed: 31808 additions & 140 deletions

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.Rproj.user
22
.DS_Store
3-
R/plane.txt
3+
data-raw/ASOIAF.ged
44
R/.Rhistory
55
.Rhistory
66
paper/paper.html
@@ -9,4 +9,5 @@ paper/paper.html
99
vignettes/articles/paper.html
1010
BGmisc.code-workspace
1111
tests/testthat/Rplots.pdf
12-
12+
*.ASOIAF.ged
13+
ASOIAF.ged

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: BGmisc
22
Title: An R Package for Extended Behavior Genetics Analysis
3-
Version: 1.3.0.1
3+
Version: 1.3.1
44
Authors@R: c(
55
person("S. Mason", "Garrison", , email= "garrissm@wfu.edu", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-4804-6003")),
@@ -30,7 +30,8 @@ Imports:
3030
kinship2,
3131
Matrix,
3232
stats,
33-
data.table
33+
data.table,
34+
stringr
3435
Suggests:
3536
dplyr,
3637
EasyMx,

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export(checkIDs)
77
export(checkSex)
88
export(comp2vech)
99
export(createGenDataFrame)
10-
export(determineSex)
1110
export(dropLink)
1211
export(evenInsert)
1312
export(famSizeCal)
@@ -26,6 +25,7 @@ export(ped2maternal)
2625
export(ped2mit)
2726
export(ped2paternal)
2827
export(plotPedigree)
28+
export(readGedcom)
2929
export(recodeSex)
3030
export(related_coef)
3131
export(relatedness)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
# BGmisc 1.3.1
2+
* Confirmed that all orcids are correct
3+
* Added gedcom importer
4+
15
# BGmisc 1.3.0.1
26
* Created subfunctions to reduce function complexity
37

48
# BGmisc 1.3.0
9+
* Harmonized function names
510
* Fixed incorrectly spelled last name in potter pedigree
611
* Added function to summarize variables by family, matrilinael, and patrilineal lines
712
* Added within row duplicate ID checks
813
* Added data validation vignettes
914
* Harmonized function names and arguments
1015

1116
# BGmisc 1.2.1
17+
1218
* Added alternative transpose options for the matrix
1319
* Added generalization of Falconer's formula
1420

R/checkSex.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ repairSex <- function(ped, verbose = FALSE, code_male = NULL) {
134134

135135
#' Recodes Sex Variable in a Pedigree Dataframe
136136
#'
137-
#' This function serves as a wrapper around `checkSex` to specifically handle
138-
#' the repair of the sex coding in a pedigree dataframe.
137+
#' This function serves as is primarily used internally, by plotting functions etc.
139138
#' It sets the `repair` flag to TRUE automatically and forwards any additional parameters to `checkSex`.
140139
#'
141140
#' @inheritParams checkSex
@@ -148,6 +147,7 @@ repairSex <- function(ped, verbose = FALSE, code_male = NULL) {
148147
#' @return A modified version of the input data.frame \code{ped}, containing an additional or modified 'sex_recode' column where the 'sex' values are recoded according to \code{code_male}. NA values in the 'sex' column are preserved.
149148
#' @export
150149
#' @seealso \code{\link{plotPedigree}}
150+
#' @export
151151
recodeSex <- function(
152152
ped, verbose = FALSE, code_male = NULL, code_na = NULL, code_female = NULL,
153153
recode_male = "M", recode_female = "F", recode_na = NA_character_) {

R/cleanPedigree.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
standardizeColnames <- function(df, verbose = FALSE) {
1414
# Internal mapping of standardized names to possible variants
1515
mapping <- list(
16-
"fam" = "^(?:fam(?:ily)?(?:id)?)",
17-
"ID" = "^(?:i(?:d$|ndiv(?:idual)?)|p(?:erson)?id)",
16+
"fam" = "^(?:fam(?:ily)?[\\.\\-_]?(?:id)?)",
17+
"ID" = "^(?:i(?:d$|ndiv(?:idual)?)|p(?:erson)?[\\.\\-_]?id)",
1818
"gen" = "^(?:gen(?:s|eration)?)",
19-
"dadID" = "^(?:d(?:ad)?id|paid|fatherid|pid_fath[er]*)",
20-
"patID" = "^(?:datid|patid|paternal(?:id)?)",
21-
"momID" = "^(?:m(?:om|a|other)?id|pid_moth[er]*)",
22-
"matID" = "^(?:matid|maternal(?:id)?)",
23-
"spt" = "^(?:s(?:pt)?id|spouse(?:id)?|partner(?:id)?|husb(?:and)?id|wife(?:id)?)|pid_spouse1?)",
24-
"twinID" = "^(?:twin(?:id)?)",
19+
"dadID" = "^(?:d(?:ad)?id|paid|fatherid|pid[\\.\\-_]?fath[er]*)",
20+
"patID" = "^(?:dat[\\.\\-_]?id|pat[\\.\\-_]?id|paternal[\\.\\-_]?(?:id)?)",
21+
"momID" = "^(?:m(?:om|a|other)?[\\.\\-_]?id|pid[\\.\\-_]?moth[er]*)",
22+
"matID" = "^(?:mat[\\.\\-_]?id|maternal[\\.\\-_]?(?:id)?)",
23+
"spID" = "^(?:s(?:pt)?id|spouse[\\.\\-_]?(?:id)?|partner[\\.\\-_]?(?:id)?|husb(?:and)?[\\.\\-_]?id|wife[\\.\\-_]?(?:id)?|pid[\\.\\-_]?spouse1?)",
24+
"twinID" = "^(?:twin[\\.\\-_]?(?:id)?)",
2525
"sex" = "^(?:sex|gender|female|m(?:a(?:le|n)|en)|wom[ae]n)"
2626
)
2727
if (verbose) {

R/helpPedigree.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @return A data frame representing the initial structure for the individuals in the specified generation
1212
#' before any relationships (parental, spousal) are defined. The columns include family ID (`fam`),
1313
#' individual ID (`id`), generation number (`gen`), father's ID (`pat`), mother's ID (`mat`),
14-
#' spouse's ID (`spt`), and sex (`sex`), with NA values for paternal, maternal, and spouse IDs, and sex.
14+
#' spouse's ID (`spID`), and sex (`sex`), with NA values for paternal, maternal, and spouse IDs, and sex.
1515
#' @examples
1616
#' sizeGens <- c(3, 5, 4) # Example sizes for 3 generations
1717
#' genIndex <- 2 # Creating data frame for the 2nd generation
@@ -26,7 +26,7 @@ createGenDataFrame <- function(sizeGens, genIndex, idGen) {
2626
gen = rep(genIndex, sizeGens[genIndex]),
2727
pat = rep(NA, sizeGens[genIndex]), # father id
2828
mat = rep(NA, sizeGens[genIndex]), # mother id
29-
spt = rep(NA, sizeGens[genIndex]), # spouse id
29+
spID = rep(NA, sizeGens[genIndex]), # spouse id
3030
sex = rep(NA, sizeGens[genIndex])
3131
)
3232
return(df_Ngen)
@@ -35,13 +35,12 @@ createGenDataFrame <- function(sizeGens, genIndex, idGen) {
3535

3636
#' Determine Sex of Offspring
3737
#'
38-
#' This function assigns sexes to the offspring in a generation based on the specified sex ratio.
38+
#' This internal function assigns sexes to the offspring in a generation based on the specified sex ratio.
3939
#'
4040
#' @param idGen Vector of IDs for the generation.
4141
#' @param sexR Numeric value indicating the sex ratio (proportion of males).
4242
#' @return Vector of sexes ("M" for male, "F" for female) for the offspring.
4343
#' @importFrom stats runif
44-
#' @export
4544
determineSex <- function(idGen, sexR) {
4645
if (runif(1) > .5) {
4746
sexVec1 <- rep("M", floor(length(idGen) * sexR))
@@ -66,16 +65,16 @@ assignCoupleIds <- function(df_Ngen) {
6665
usedCoupleIds <- character() # Initialize an empty character vector to track used IDs
6766

6867
for (j in seq_len(nrow(df_Ngen))) {
69-
if (!is.na(df_Ngen$spt[j]) && is.na(df_Ngen$coupleId[j])) {
68+
if (!is.na(df_Ngen$spID[j]) && is.na(df_Ngen$coupleId[j])) {
7069
# Construct a potential couple ID from sorted individual and spouse IDs
71-
sortedIds <- sort(c(df_Ngen$id[j], df_Ngen$spt[j]))
70+
sortedIds <- sort(c(df_Ngen$id[j], df_Ngen$spID[j]))
7271
potentialCoupleId <- paste(sortedIds[1], sortedIds[2], sep = "_")
7372

7473
# Check if the potentialCoupleId has not already been used
7574
if (!potentialCoupleId %in% usedCoupleIds) {
7675
# Assign the new couple ID to both partners
7776
df_Ngen$coupleId[j] <- potentialCoupleId
78-
spouseIndex <- which(df_Ngen$id == df_Ngen$spt[j])
77+
spouseIndex <- which(df_Ngen$id == df_Ngen$spID[j])
7978
df_Ngen$coupleId[spouseIndex] <- potentialCoupleId
8079

8180
# Add the new couple ID to the list of used IDs
@@ -137,7 +136,7 @@ adjustKidsPerCouple <- function(nMates, kpc, rd_kpc) {
137136
#' the assignment of roles and relationships within and between generations in a pedigree simulation.
138137
#'
139138
#' @param df_Ngen A data frame for the current generation being processed.
140-
#' It must include columns for individual IDs (`id`), spouse IDs (`spt`), sex (`sex`),
139+
#' It must include columns for individual IDs (`id`), spouse IDs (`spID`), sex (`sex`),
141140
#' and any previously assigned roles (`ifparent`, `ifson`, `ifdau`).
142141
#' @param i Integer, the index of the current generation being processed.
143142
#' @param Ngen Integer, the total number of generations in the simulation.
@@ -163,7 +162,7 @@ markPotentialChildren <- function(df_Ngen, i, Ngen, sizeGens, CoupleF) {
163162
# single person should all be sons or daus
164163
# change the ifson and ifdau based on coupleGirl and coupleBoy
165164
for (j in 1:sizeGens[i]) {
166-
if (is.na(df_Ngen$spt[j])) {
165+
if (is.na(df_Ngen$spID[j])) {
167166
if (df_Ngen$sex[j] == "F") {
168167
df_Ngen$ifdau[j] <- TRUE
169168
# usedIds <- c(usedIds, df_Ngen$id[j])

0 commit comments

Comments
 (0)