Skip to content

Sat 206 indenpendent chr estimations - #17

Open
Cristianetaniguti wants to merge 10 commits into
developmentfrom
SAT-206-Indenpendent_chr_estimations
Open

Sat 206 indenpendent chr estimations#17
Cristianetaniguti wants to merge 10 commits into
developmentfrom
SAT-206-Indenpendent_chr_estimations

Conversation

@Cristianetaniguti

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_nrow and gray_CN use ##' 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.

Comment thread R/hmm_main.R
z_range = NULL,
transition_jump = 0.995, # decrease this value if you think there changes in CN is likely
initial_prob = 0.95, # Initial probability for the best CN state in the initial state distribution (pi0). Default 0.95. Sets the prior probability for the expected ploidy (or best CN from BAF model) at the first window; remaining probability is distributed uniformly across other states. If the best CN is not found, pi0 is uniform across all states.
initial_prob = 0.5, # Initial probability for the best CN state in the initial state distribution (pi0). Default 0.95. Sets the prior probability for the expected ploidy (or best CN from BAF model) at the first window; remaining probability is distributed uniformly across other states. If the best CN is not found, pi0 is uniform across all states.
Comment thread R/hmm_main.R
Comment on lines 914 to 918
min_het_frac = min_het_frac,
het_range = het_range,
dosage_threshold = dosage_threshold,
z_no_baf_scale = z_no_baf_scale,
rerun_overall_ploidy = FALSE,
Comment on lines +15 to +17
#' Segments are colored by copy number (CN_call) using a high-contrast palette:
#' baseline CN (most frequent, weighted by window length) is black; losses are blue;
#' gains are red. Transparency reflects posterior confidence (post_max).
Comment on lines +234 to +238
"<br>post_max: ", round(plot_df$post_max, 3),
"<br>CN_reliability: ", round(plot_df$CN_reliability, 3),
"<br>w_baf: ", if ("w_baf" %in% names(plot_df)) round(plot_df$w_baf, 3) else "NA",
"<br>w_het: ", round(plot_df$n_het/plot_df$n_snps, 3)
)
Comment thread NEWS.md

# 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.
Comment on lines +200 to +205
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 |>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants