Skip to content

Optimize alignment and introduce new configuration options#162

Merged
smasongarrison merged 49 commits into
mainfrom
dev
Jun 12, 2026
Merged

Optimize alignment and introduce new configuration options#162
smasongarrison merged 49 commits into
mainfrom
dev

Conversation

@smasongarrison

Copy link
Copy Markdown
Member

This pull request introduces several new features, optimizations, and bug fixes to the ggpedigree package, with a focus on improving pedigree plotting flexibility, alignment, and lineage visualization. It also updates dependencies and documentation to reflect these enhancements.

Major new features and improvements:

  • Added the renumberPedigreeIDs function to consistently renumber pedigree IDs and update parent-child relationships, aiding in plotting and analysis. [1] [2]
  • Introduced configuration options for pinning individuals to fixed layout positions (fixed_positions), coloring connecting segments by lineage (segment_lineage_*), and optimizing founder ordering and layout scoring (founder_order_seed, founder_order_tries, layout_score_method).
  • Optimized and added unit tests for pedigree alignment functions, improving performance and reliability.

Bug fixes:

  • Fixed issues with lineage-colored segments when reduce_variables = FALSE by carrying all extra pedigree columns forward and avoiding duplicate joins, preventing silent failures in segment coloring. [1] [2] [3]
  • Addressed problems with unplaced individuals, long diagonal spouse segments, and clarified the naming of NA color configuration options for consistency with ggplot2.

Dependency and documentation updates:

  • Added ggnewscale and mockery to DESCRIPTION to support new plotting features and unit testing. [1] [2]
  • Updated the package version to 1.2.0.90 and documented all changes in NEWS.md. [1] [2]
  • Added benchmark_alignment_results.csv to .Rbuildignore for build hygiene.

These changes collectively enhance the package's flexibility for complex pedigree visualization, ensure more robust and reproducible layouts, and improve overall code maintainability.

smasongarrison and others added 30 commits May 30, 2026 20:22
Introduce a 'classic' logical parameter across kinship2 alignment functions to toggle between the original algorithm and a new optimized alignment. Implement a new optimized routine (kinship2_alignped4_optimized) that builds quadratic penalty matrices more efficiently and uses quadprog to solve positioning; kinship2_alignped4 now dispatches to the optimized implementation when classic = FALSE. Update internal API, man pages, and tests to exercise both modes, add benchmarking scripts and results (data-raw/benchmarks_align.R, benchmark_alignment_results.csv), and bump package version and Suggests (mockery). This change improves alignment performance while preserving the classic behavior for compatibility.
Introduce a fast_threshold option and refactor coordinate calculation to support piecewise layout for large pedigrees. calculateCoordinates was modularized (extractCoordinatesFromAlignedPedigree, alignAndExtractComponent) and now splits big pedigrees into connected components (splitPedigreeComponents), computes layouts per component, and offsets/combines them (stitchComponents). Default config/getDefaultPlotConfig and documentation updated to include fast_threshold, new man pages added for the helper functions, and the test expectation adjusted for the added default parameter.
Make rowMeans ignore NA parents (na.rm = TRUE) to avoid spurious NA x positions. Propagate the config argument into alignAndExtractComponent and update its calls so relation-based alignment uses the provided config. In splitPedigreeComponents, switch the ped2fam family id key from ".comp" to "famID" and use that column when splitting components. Update documentation: add config = NULL to alignPedigreeWithRelations Rd and raise the getDefaultPlotConfig fast_threshold default from 300 to 1000.
Add fast_threshold option and refactor pedigree layout calculations
Introduce configurable lineage-based coloring for connecting segments. Adds new config options (segment_lineage_*) to getDefaultPlotConfig and docs/vignette entries, implements addSegmentLineageColumn to compute per-person lineage values, and integrates lineage-aware rendering in ggPedigree.core. New helpers .addSegmentLayer and .add_segment_lineage_scales handle conditional aesthetic mapping and color scales (with optional ggnewscale support for independent node/segment scales). Updates include man pages, unit tests for segment lineage behavior, NEWS entry, and DESCRIPTION (suggesting ggnewscale); interactive (plotly) plots fall back to fixed segment colors with a warning when two color scales cannot be preserved.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Introduce a new config option `fixed_positions` and internal helper `.applyFixedPositions()` to pin specific individuals to absolute layout-slot coordinates (x/y) that compose with generation scaling and radial layouts. Pinning updates connection anchors automatically; an option `fixed_positions_update_family` controls whether pinning a parent recomputes children family anchors. Adds documentation (man page and vignette section), NEWS entry, default config entries, and unit tests; updates test expectations and example vignette/html accordingly.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-Authored-By: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Enable backwards-compatible segment lineage coloring for interactive plots and add debug-friendly behavior and messages.

Changes:
- defaultPlotConfig: set segment_lineage_palette default to focal_fill_color_values.
- ggPedigreeInteractive: wrap optimizePlotlyPedigree in tryCatch to warn and return unoptimized plotly object on error.
- ggpedigreeCore: add debug messages when segment_lineage is requested but not supported (interactive/ggnewscale cases); adjust logic to allow debug-driven behavior and reorder node_mode so sex_color is evaluated last.
- ggpedigreeCoreScales: fix manual scale value handling to ensure named color for single-entry palettes.
- ggpedigreeCoreSegments: add legacy handling when segment_lineage_include = TRUE: build a palette (brewer/paletteer or provided vector), map colors to segment_lineage values, and pass explicit colors to geom_segment; add explanatory prints and input validation.
- Other minor tweaks: overlay shape mapping adjustments, formatting fixes.
- Add tests/tests.R with interactive/static examples and update vignette to demonstrate segment_lineage and focal_fill config options.

Why: these changes restore a legacy pathway for coloring segments when interactive constraints prevent the preferred lineage color scale, provide clearer debug output to guide users, and make scale/color handling more robust.
Co-Authored-By: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Add fixed_positions config and applyFixedPositions
smasongarrison and others added 15 commits June 9, 2026 10:08
Export renumberPedigreeIDs and expose it via @export/NAMESPACE. Change internal ID coercion from integer to numeric for personID, momID, dadID, twinID and spouseID. Update documentation to include twinID and spouseID args. Add/extend tests to cover twin and spouse columns, custom column names, unknown references, ordering behavior, and update expected types from integer/NA_integer_ to numeric/NA_real_. These changes ensure consistent handling of twin/spouse relationships and numeric NA semantics.
Introduce founder_order_seed, founder_order_tries and layout_score_method to calculateCoordinates to allow shuffling pedigree row order (reproducible via seed) and to search multiple shufflings for the best layout. Implement new internal scoring functions (.layoutScore, .layoutScoreCrossings, .layoutScoreTwinPenalty) and integrate a .doOneLayout helper that runs the layout pipeline; when enabled the code evaluates candidate layouts and keeps the lowest-scoring result. Update default config (including return_best_seed and default reposition_founders = TRUE), man pages, NEWS, vignette and add comprehensive tests for the new behaviour and scoring methods. Also include minor code style and test whitespace cleanups.
Add configurable penalty/weight parameters to layout scoring: .layoutScoreTwinPenalty now accepts cross_gen_penalty (default 10) and .layoutScore accepts cross_gen_penalty, twin_penalty_weight (default 20) and duplication_weight (default 100). Replace hard-coded penalty multipliers in composite scoring and twin-penalty usage with these new parameters and update internal calls. Update roxygen documentation for the new parameters. Also remove a block of commented-out default_config lines from defaultPlotConfig.R.
Update plot config naming to match ggplot2 conventions: rename focal_fill_na_value to focal_fill_na_color across getDefaultPlotConfig (roxygen param, internal variables, and core_list key). NEWS.md updated to document the rename. Also make segment_lineage_na_color reference focal_fill_na_color so NA segment color follows the new setting. Note: an accidental stray "s" was introduced in one branch and should be removed to avoid a syntax error.
Add unit tests for ggpedigree core behavior: tests/testthat/test-ggpedigreeCoreLabels.R and tests/testthat/test-ggpedigreeCoreLayout.R. The new tests cover .addLabels (geom_text, geom_label, ggrepel integration and fallback, and invalid methods) and layout functions (.adjustSpacing and .applyRadialLayout) for cartesian and radial configurations, plus integration checks via ggPedigree. Also add 'cowplot' to DESCRIPTION Suggests.
@smasongarrison smasongarrison merged commit 1882327 into main Jun 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] tree lines to be filled by the relationship to the focal individual

1 participant