Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
00c157a
alternative methods for adjecenci matrix
smasongarrison Feb 27, 2025
09b2e12
added indexed version
smasongarrison Feb 27, 2025
94b6f27
Delete benchmark_results.csv
smasongarrison Feb 27, 2025
f25acb5
less aggressive lintr
smasongarrison Feb 27, 2025
eb0ae69
add data
smasongarrison Feb 27, 2025
a067075
documentaion
smasongarrison Mar 1, 2025
7357bf8
change default to indexed
smasongarrison Mar 1, 2025
718b77c
Merge pull request #55 from R-Computing-Lab/optimize
smasongarrison Mar 1, 2025
7005458
Update convertPedigree.R
smasongarrison Mar 1, 2025
ece675e
Fix adjacency whitespace
mhunter1 Mar 3, 2025
2754176
Remove adjacency dead code
mhunter1 Mar 3, 2025
a9f936a
Refactor adjacency into helper functions
mhunter1 Mar 3, 2025
c52462c
Return indices rather than parList for adjacency
mhunter1 Mar 3, 2025
fa3d6da
Allow for 0, 1, or 2 parents
mhunter1 Mar 3, 2025
7aef1d7
Add direct method for computing adjacency
mhunter1 Mar 3, 2025
7ea8cae
Correct typo in direct adjacency method and add tiny test
mhunter1 Mar 3, 2025
3bffa1d
Actually pass adjacency_method to later functions
mhunter1 Mar 4, 2025
a6e6dbb
tweak a few tests
smasongarrison Mar 5, 2025
32c3d57
Update ped2com.Rd
smasongarrison Mar 5, 2025
cc87ab1
Merge pull request #56 from R-Computing-Lab/povich
smasongarrison Mar 5, 2025
5066814
hotfix
smasongarrison Mar 10, 2025
52be0b7
more hotfixs
smasongarrison Mar 10, 2025
08f0165
Update convertPedigree.R
smasongarrison Mar 10, 2025
9d7f3e4
Create makeLinks.R
smasongarrison Mar 10, 2025
93c3656
Update makeLinks.R
smasongarrison Mar 10, 2025
e669c5c
Update makeLinks.R
smasongarrison Mar 11, 2025
85f2d76
style
smasongarrison Mar 11, 2025
1313e47
Update makeLinks.R
smasongarrison Mar 11, 2025
1d7fb5f
Update makeLinks.R
smasongarrison Mar 11, 2025
29874f9
add buffer
smasongarrison Mar 11, 2025
3dd1796
tests
smasongarrison Mar 11, 2025
21da97a
links
smasongarrison Mar 12, 2025
0f7d43d
fixed methods call error
smasongarrison Mar 12, 2025
6dc9fe7
read wikitree
smasongarrison Mar 12, 2025
8f8b8f6
REFACTOR
smasongarrison Mar 13, 2025
8ebf258
add different data types
smasongarrison Mar 13, 2025
1120a3d
adding documenation
smasongarrison Mar 13, 2025
b71256c
forgfot to export
smasongarrison Mar 13, 2025
72859a5
Update makeLinks.R
smasongarrison Mar 13, 2025
92b0ca8
adds IDs
smasongarrison Mar 13, 2025
3c7df6c
convert warnings to messages
smasongarrison Mar 13, 2025
b717ce7
smarter
smasongarrison Mar 13, 2025
6e7261b
Update makeLinks.R
smasongarrison Mar 14, 2025
92deafe
Update convertPedigree.R
smasongarrison Mar 14, 2025
6e0a956
add option to remove alternative isChild
smasongarrison Mar 14, 2025
de27cb3
push docs
smasongarrison Mar 14, 2025
6d9d765
Merge branch 'dev_main' into makelinks
smasongarrison Mar 14, 2025
0d4e518
merge legacy
smasongarrison Mar 15, 2025
c176a68
added missing method
smasongarrison Mar 17, 2025
f625081
Merge branch 'dev_main' into makelinks
smasongarrison Mar 17, 2025
2e06731
Update test-convertPedigree.R
smasongarrison Mar 17, 2025
cb29d27
testing out
smasongarrison Mar 17, 2025
d1d473d
temp
smasongarrison Mar 19, 2025
5ce5a2a
Update partial.Rmd
smasongarrison Mar 20, 2025
04a084d
Update partial.Rmd
smasongarrison Mar 20, 2025
c8e8129
Update partial.Rmd
smasongarrison Mar 20, 2025
7d4f150
bias
smasongarrison Mar 21, 2025
394a48c
Update partial.Rmd
smasongarrison Mar 24, 2025
578d3cd
documentation
smasongarrison Mar 24, 2025
5411f25
forgot suggestions
smasongarrison Mar 24, 2025
35e39c9
fix tests?
smasongarrison Mar 24, 2025
fd376c7
now returns silently
smasongarrison Mar 24, 2025
9281590
Merge pull request #57 from R-Computing-Lab/makelinks
smasongarrison Mar 24, 2025
bb59099
added asoif dataset
smasongarrison Mar 25, 2025
325aafe
update
smasongarrison Mar 26, 2025
9bb5f15
checkPedigreeNetwork implemented
smasongarrison Mar 27, 2025
dda221b
tidy up vignette
smasongarrison Mar 27, 2025
c4a7321
detection of duplicate edges
smasongarrison Mar 27, 2025
cc707be
more narrative
smasongarrison Mar 28, 2025
bf70997
a couple more tests and utils::write
smasongarrison Mar 31, 2025
97d4961
tidy up
smasongarrison Mar 31, 2025
8f72000
caurion! write links isn't behaving nicely
smasongarrison Apr 1, 2025
2387587
whitespace
smasongarrison Apr 1, 2025
3a8d739
fixed!
smasongarrison Apr 1, 2025
e30f288
Update test-makeLinks.R
smasongarrison Apr 1, 2025
27d22e3
docs
smasongarrison Apr 1, 2025
b9be8af
Merge branch 'main' into dev_main
smasongarrison Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ CITATION.cff$
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.vscode$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ tests/testthat/Rplots.pdf
ASOIAF.ged
*.Rproj

.vscode/launch.json
dataRelatedPairs_new2.csv
5 changes: 4 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
linters: linters_with_defaults(line_length_linter(120),commented_code_linter = NULL,object_name_linter = object_name_linter(styles = c("snake_case", "symbols"))) # see vignette("lintr")
linters: linters_with_defaults(
line_length_linter = NULL,
commented_code_linter = NULL,
object_name_linter=NULL) # see vignette("lintr")
encoding: "UTF-8"
1 change: 1 addition & 0 deletions BGmisc.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 660dde05-601d-4692-8962-9a2223744832

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: BGmisc
Title: An R Package for Extended Behavior Genetics Analysis
Version: 1.3.3
Version: 1.3.5
Authors@R: c(
person("S. Mason", "Garrison", , "garrissm@wfu.edu", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-4804-6003")),
Expand Down Expand Up @@ -33,8 +33,10 @@ Imports:
kinship2,
Matrix,
stats,
stringr
stringr,
methods
Suggests:
corrplot,
dplyr,
EasyMx,
knitr,
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ export(SimPed)
export(allGens)
export(calculateRelatedness)
export(checkIDs)
export(checkPedigreeNetwork)
export(checkSex)
export(com2links)
export(comp2vech)
export(createGenDataFrame)
export(dropLink)
export(evenInsert)
export(extractSummaryText)
export(famSizeCal)
export(fitComponentModel)
export(identifyComponentModel)
export(inferRelatedness)
export(makeInbreeding)
export(makeTwins)
export(parseTree)
export(ped2add)
export(ped2ce)
export(ped2cn)
Expand All @@ -26,6 +30,7 @@ export(ped2mit)
export(ped2paternal)
export(plotPedigree)
export(readGedcom)
export(readWikifamilytree)
export(recodeSex)
export(related_coef)
export(relatedness)
Expand Down
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# BGmisc 1.3.5
* Added ASOIAF pedigree
* Added com2links() function to convert components to kinship links, with accompanying tests
* Added extractWikiFamilyTree() function to parse family trees from wiki templates, with accompanying tests
* Created vignette demonstrating adjacency matrix methods and applications
* Improved plotPedigree() function by silencing unnecessary invisible list outputs
* Added checkPedigreeNetwork() function for validating pedigree network structure, with accompanying tests

# BGmisc 1.3.4.1
* Hot fix to resolve issue with list of adjacency matrix not loading saved version
* Reoptimized generation calculation

# BGmisc 1.3.4
* Added alternative (and faster) methods to create the adjacency matrix
* Add tests for comparison of adjacency matrix build methods
* Added Royal Family pedigree

# BGmisc 1.3.3
* Added ability to save and reload pedigree objects that are used by ped2Com
* Optimized generation calculation
Expand Down
1 change: 0 additions & 1 deletion R/buildPedigree.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ ped2fam <- function(ped, personID = "ID",
ped2 <- merge(fam, ped,
by = personID, all.x = FALSE, all.y = TRUE
)

return(ped2)
}

Expand Down
79 changes: 79 additions & 0 deletions R/checkPedigree.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#' Validate Pedigree Network Structure
#'
#' Checks for structural issues in pedigree networks, including:
#' - Individuals with more than two parents.
#' - Presence of cyclic parent-child relationships.
#'
#' @param ped Dataframe representing the pedigree.
#' @param personID Character. Column name for individual IDs.
#' @param momID Character. Column name for maternal IDs.
#' @param dadID Character. Column name for paternal IDs.
#' @param verbose Logical. If TRUE, print informative messages.
#'
#' @return List containing detailed validation results.
#' @examples
#' \dontrun{
#' results <- checkPedigreeNetwork(ped, personID = "ID",
#' momID = "momID", dadID = "dadID", verbose = TRUE)
#' }
#' @export
checkPedigreeNetwork <- function(ped, personID = "ID", momID = "momID", dadID = "dadID", verbose = FALSE) {
# Create directed edges from parent to child relationships
ped_edges <- rbind(
data.frame(from = ped[[momID]], to = ped[[personID]]),
data.frame(from = ped[[dadID]], to = ped[[personID]])
)
ped_edges <- ped_edges[!is.na(ped_edges$from) & !is.na(ped_edges$to), ]

ped_graph <- igraph::graph_from_data_frame(ped_edges, directed = TRUE)

results <- list()

## Check for individuals with more than two parents
indegrees <- igraph::degree(ped_graph, mode = "in")
ids_excess_parents <- names(indegrees[indegrees > 2])

results$individuals_with_excess_parents <- ids_excess_parents

if (verbose) {
if (length(ids_excess_parents) > 0) {
message("Individuals with more than two parents detected: ", paste(ids_excess_parents, collapse = ", "))
} else {
message("No individuals with more than two parents detected.")
}
}

## Check for duplicate edges

duplicate_edges_idx <- igraph::which_multiple(ped_graph)
duplicate_edges <- igraph::as_edgelist(ped_graph)[duplicate_edges_idx, , drop = FALSE]

results$duplicate_edges <- duplicate_edges

if (verbose) {
if (nrow(duplicate_edges) > 0) {
message("Duplicate edges detected:")
print(duplicate_edges)
} else {
message("No duplicate edges detected.")
}
}
## Check for cyclic relationships
is_acyclic <- igraph::is_dag(ped_graph)
results$is_acyclic <- is_acyclic

if (!is_acyclic) {
cyclic_edges <- igraph::feedback_arc_set(ped_graph)
cyclic_relationships <- igraph::as_edgelist(ped_graph)[cyclic_edges, ]
results$cyclic_relationships <- cyclic_relationships
if (verbose) {
message("Cyclic relationships detected:")
print(cyclic_relationships)
}
} else {
results$cyclic_relationships <- NULL
if (verbose) message("No cyclic relationships detected.")
}

return(results)
}
20 changes: 8 additions & 12 deletions R/checkSex.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ checkSex <- function(ped, code_male = NULL, code_female = NULL, verbose = FALSE,
validation_results$sex_unique <- unique(ped$sex)
validation_results$sex_length <- length(unique(ped$sex))
if (verbose) {
cat(paste0(
validation_results$sex_length, " unique values found.\n ",
paste0(validation_results$sex_unique)
))
cat(paste0(validation_results$sex_length, " unique values found.\n"))
cat(paste0("Unique values: ", paste0(validation_results$sex_unique, collapse = ", "), "\n"))
}
# Are there multiple sexes/genders in the list of dads and moms?

Expand All @@ -83,7 +81,6 @@ checkSex <- function(ped, code_male = NULL, code_female = NULL, verbose = FALSE,
remove(df_moms)
}


if (repair) {
if (verbose) {
cat("Step 2: Attempting to repair sex coding...\n")
Expand All @@ -99,7 +96,7 @@ checkSex <- function(ped, code_male = NULL, code_female = NULL, verbose = FALSE,
num_changes <- sum(original_ped$sex != ped$sex)
# Record the change and the count
changes[[length(changes) + 1]] <- sprintf(
"Recode sex based on most frequent sex in dads: %s. Total gender changes made: %d",
"Recode sex based on most frequent sex in dads: %s. Total sex changes made: %d",
validation_results$most_frequent_sex_dad, num_changes
)
}
Expand Down Expand Up @@ -138,8 +135,8 @@ checkSex <- function(ped, code_male = NULL, code_female = NULL, verbose = FALSE,
#' @export
#'
#' @seealso \code{\link{checkSex}}
repairSex <- function(ped, verbose = FALSE, code_male = NULL) {
checkSex(ped = ped, verbose = verbose, repair = TRUE, code_male = code_male)
repairSex <- function(ped, verbose = FALSE, code_male = NULL, code_female = NULL) {
checkSex(ped = ped, verbose = verbose, repair = TRUE, code_male = code_male, code_female = code_female)
}

#' Recodes Sex Variable in a Pedigree Dataframe
Expand All @@ -164,25 +161,24 @@ recodeSex <- function(
if (!is.null(code_na)) {
ped$sex[ped$sex == code_na] <- NA
}

# Recode as "F" or "M" based on code_male, preserving NAs
if (!is.null(code_male) & !is.null(code_female)) {
if (!is.null(code_male) && !is.null(code_female)) {
# Initialize sex_recode as NA, preserving the length of the 'sex' column
ped$sex_recode <- recode_na
ped$sex_recode[ped$sex == code_female] <- recode_female
ped$sex_recode[ped$sex == code_male] <- recode_male
# Overwriting temp recode variable
ped$sex <- ped$sex_recode
ped$sex_recode <- NULL
} else if (!is.null(code_male) & is.null(code_female)) {
} else if (!is.null(code_male) && is.null(code_female)) {
# Initialize sex_recode as NA, preserving the length of the 'sex' column
ped$sex_recode <- recode_na
ped$sex_recode[ped$sex != code_male & !is.na(ped$sex)] <- recode_female
ped$sex_recode[ped$sex == code_male] <- recode_male
# Overwriting temp recode variable
ped$sex <- ped$sex_recode
ped$sex_recode <- NULL
} else if (is.null(code_male) & !is.null(code_female)) {
} else if (is.null(code_male) && !is.null(code_female)) {
# Initialize sex_recode as NA, preserving the length of the 'sex' column
ped$sex_recode <- recode_na
ped$sex_recode[ped$sex != code_female & !is.na(ped$sex)] <- recode_male
Expand Down
Loading