Sat 206 indenpendent chr estimations - #17
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Qploidy2’s HMM copy-number pipeline to be more robust to chromosome-order effects and z-only (all-homozygous) windows, adds new quality/summary utilities for multi-sample results, and aligns plotting + documentation around the new CN_reliability metric and updated heterozygosity defaults.
Changes:
- Refactors HMM decoding to use per-chromosome forward–backward smoothing and introduces
CN_reliability(plus related plotting updates). - Adds multi-sample utilities (
compare_cn_track_summary,filter_hmm_CN,count_types+ print method) and expands documentation/tutorials accordingly. - Adjusts default heterozygosity gating (
min_het_frac,het_range) across BAF/HMM/standardization workflows and updates tests.
Reviewed changes
Copilot reviewed 23 out of 34 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/testthat/test-hmm_cn.R | Updates expected numeric outputs from HMM-related tests. |
| R/standardization.R | Tweaks re-standardization defaults and warns/overrides mismatched ploidy.standardization. |
| R/plots_standardization.R | Updates ratio labeling to θ and improves facet labeling. |
| R/plots_hmm_results_all_samples.R | Adds/relocates multi-sample CN plotting + summary plotting utilities. |
| R/plot_raw.R | Updates ratio plot y-axis label and raw-model defaults for het gating. |
| R/plot_karyotype.R | Adds CN_reliability coloring and better handling of filtered/NA CN segments. |
| R/plot_cn_track.R | Colors CN track by CN_reliability (fallback to legacy prob). |
| R/karyotype_notation.R | Suppresses NSE NOTE for CN_call_filled. |
| R/hmm_utils.R | Adds fb_smooth() and viterbi_bidi() utilities (internal). |
| R/hmm_main.R | Major HMM stability updates, new parameters (z_no_baf_scale, hom_z_sigma_inflate), adds CN_reliability, changes defaults. |
| R/filter_hmm_CN.R | New filtering + sample-type classification utilities (filter_hmm_CN, count_types, print method). |
| R/export_results.R | Adds CN_mode to globalVariables to address R CMD check NOTES. |
| R/em_hmm_cn.R | Adds update_pi0 flag and reintroduces a mu-update stability guard. |
| R/call_dosages.R | Updates het gating defaults in dosage calling interface/docs. |
| R/BAF_distributions.R | Updates het gating defaults in BAF likelihood/model selection. |
| NEWS.md | Adds release notes for 1.18.x including new features and default changes. |
| NAMESPACE | Exports new functions and adds new imports/S3 registration. |
| man/select_best_raw_model.Rd | Updates documented defaults for het gating. |
| man/select_best_baf_model.Rd | Updates documented defaults for het gating. |
| man/re_standardize.Rd | Updates documented defaults for het gating. |
| man/print.count_types.Rd | New Rd for print.count_types. |
| man/plot_karyotype.Rd | Documents new CN_reliability option. |
| man/hmm_estimate_CN.Rd | Documents new parameters and default changes. |
| man/filter_hmm_CN.Rd | New Rd for filter_hmm_CN. |
| man/em_hmm_cn.Rd | Documents update_pi0. |
| man/count_types.Rd | New Rd for count_types. |
| man/compute_baf_likelihoods.Rd | Updates documented defaults for het gating. |
| man/compare_cn_track.Rd | Points documentation source to new plotting file. |
| man/compare_cn_track_summary.Rd | New Rd for compare_cn_track_summary. |
| man/call_hmm_dosages.Rd | Updates documented defaults for het gating. |
| docs/QuickStart_template.Rmd | New/expanded QuickStart covering new metrics and utilities. |
| docs/Qploidy_alfalfa_tutorial.Rmd | Tutorial updates to reflect new workflow/tools and defaults. |
| DESCRIPTION | Bumps package version to 1.18.3. |
Files not reviewed (10)
- man/call_hmm_dosages.Rd: Generated file
- man/compare_cn_track.Rd: Generated file
- man/compare_cn_track_summary.Rd: Generated file
- man/compute_baf_likelihoods.Rd: Generated file
- man/count_types.Rd: Generated file
- man/em_hmm_cn.Rd: Generated file
- man/filter_hmm_CN.Rd: Generated file
- man/hmm_estimate_CN.Rd: Generated file
- man/plot_karyotype.Rd: Generated file
- man/print.count_types.Rd: Generated file
Suppressed comments (1)
R/plots_hmm_results_all_samples.R:25
- The roxygen lines for
facet_nrowandgray_CNuse##'instead of#', so these parameters likely won’t be included in the generated documentation.
#' @param facet_ncol Number of columns for facet_wrap. If NULL, will be determined automatically unless facet_nrow is set.
##' @param facet_nrow Number of rows for facet_wrap. If set, facet_ncol will be determined automatically unless both are set.
##' @param gray_CN Integer or NULL. If provided, this copy-number value is colored gray (used as the baseline color). All CNs below it are colored blue and above red. If NULL (default), the baseline is auto-detected as the most frequent CN weighted by window length.
#' @param add_het Logical. If TRUE, a heterozygosity column is added to the right side of the plot, with one square per sample colored from blue (low) to red (high). Requires \code{hmm_dosage_calls}. Default is TRUE.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| # Qploidy2 1.18.2 | ||
|
|
||
| * Revert mu stability guard introduced in 1.18.0: `em_hmm_cn` now always updates mu unconditionally (standard EM update with `pmax` denominator guard). The while-loop in `hmm_estimate_CN` already handles non-monotonic mu. |
| het_raw <- hmm_dosage_calls |> | ||
| filter(.data$SampleName %in% samples_present) | ||
| if (!is.null(chromosomes)) { | ||
| het_raw <- het_raw |> filter(.data$Chr %in% chromosomes) | ||
| } | ||
| het_df <- het_raw |> |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 34 changed files in this pull request and generated 1 comment.
Files not reviewed (10)
- man/call_hmm_dosages.Rd: Generated file
- man/compare_cn_track.Rd: Generated file
- man/compare_cn_track_summary.Rd: Generated file
- man/compute_baf_likelihoods.Rd: Generated file
- man/count_types.Rd: Generated file
- man/em_hmm_cn.Rd: Generated file
- man/filter_hmm_CN.Rd: Generated file
- man/hmm_estimate_CN.Rd: Generated file
- man/plot_karyotype.Rd: Generated file
- man/print.count_types.Rd: Generated file
Suppressed comments (3)
Previously missed (3) — in code that hasn't changed since the last review.
R/hmm_main.R:817
w_baf_use / baf_weightwill produceNaN(0/0) whenbaf_weightis set to 0 (which is allowed by the documented 0–1 range), causingCN_reliabilityto becomeNAfor all windows. Add an explicit guard for non-finite/zerobaf_weightbefore dividing.
w_baf_use <- if (z_only) rep(0, W) else w_baf
w_baf_norm <- pmax(z_no_baf_scale, pmin(1, w_baf_use / baf_weight))
CN_reliability <- post_max * w_baf_norm
R/standardization.R:809
mode(hmm_CN_multi$by_marker$CN_call)can returnNAwhenCN_callcontains many missing values (e.g., afterfilter_hmm_CNmasking). In that case,ploidy.standardization != mode(...)becomesNAand theelse ifwill error with “missing value where TRUE/FALSE needed”, breakingre_standardize()for filtered inputs. Consider using an NA-safe mode (ignoreNAs) and explicitly error if all CN calls areNAbefore doing the comparison/override.
if (is.null(ploidy.standardization)) {
ploidy.standardization <- mode(hmm_CN_multi$by_marker$CN_call)
if (verbose) cat("ploidy.standardization not provided, using:", ploidy.standardization, "\n")
} else if (ploidy.standardization != mode(hmm_CN_multi$by_marker$CN_call)) {
warning(sprintf(
R/filter_hmm_CN.R:72
- When a user supplies a threshold but the corresponding column is missing in
hmm_CN$by_window(e.g., older objects withoutCN_reliability), the filter is silently skipped and the function can still print “No windows failed…”, which is misleading. Emit a warning when a requested filter can’t be applied due to missing columns.
if (!is.null(min_CN_reliability) && "CN_reliability" %in% names(bw))
fail <- fail | is.na(bw$CN_reliability) | bw$CN_reliability < min_CN_reliability
if (!is.null(min_post_max) && "post_max" %in% names(bw))
fail <- fail | is.na(bw$post_max) | bw$post_max < min_post_max
| # Build per-segment tooltip lookup for het | ||
| het_lookup <- if (!is.null(het_df)) { | ||
| setNames(round(het_df$het, 3), as.character(het_df$SampleName)) | ||
| } else NULL | ||
|
|
No description provided.