big refactor - #1
Open
matthewpeterkort wants to merge 15 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog: Battenberg Refactor v3.0.2
This document outlines the significant mathematical, technical, and feature changes introduced in the refactored Battenberg pipeline compared to the original implementation.
1. Architectural Changes: "Pure R" Pipeline
alleleCounter,impute2, orjava -jar beagle.jar.convert_beagle_to_impute) that digests the output of modern phasing tools.2. Mathematical & Algorithmic Changes
Geometric Centroid Selection
Recalculated Ploidy (Psi_t)
run_clonal_ASCAT, the ploidy (psi) is partially recalculated using only high-confidence clonal segments after the initial grid search.Optimized Integer Copy Number Fitting
ascat_distance.cpp) explicitly optimizes the integer combination of Major/Minor alleles (checking Floor/Ceiling combinations) for every grid point to minimize the BAF squared error.LOH/Deletion Constraint Logic
calculate_solution_fastthat valid solutions typically require at least some Loss-Of-Heterozygosity (LOH) or deletions (CN=0).Winsorization in Segmentation
copynumber::winsorizestep prior to PCF segmentation (segmentation.R).3. Technical & Performance Optimizations
C++ Acceleration (
Rcpp)calculate_ascat_dist_matrix_cpp) and segmentation (pcf_core.cpp)—ported to C++.High-Performance IO & Vectorization
vroom: Used for instant reading/merging of large BAF files (haplotype.R).collapse: Replaced base R stats withcollapse::fsum/fmean.Workflow Checkpoints & Resume
preprocessed_data_dirandphasing_results_dirarguments tobattenberg().Dynamic Thread Budgeting
chromosomes_in_parallel×threads_per_chromosome) and dynamic setting ofOMP_NUM_THREADSandMKL_NUM_THREADS.Memory Management
4. Stability & Robustness
Critical Probe Misalignment Fix
run_ascat_enhancedto subset vectors using names (lrr[names(baf)]) rather than position.Failsafe Grid Search
5. New Features
Configurable Grid Search
n_neighbors_search: Limit search to top N closest points.psi_step/rho_step: Custom grid resolution.local_min_window_size: Adjustable local minima window.Structured Logging
loggerpackage for timestamped, leveled logs (INFO, DEBUG, ERROR).Early Termination
early_termination = TRUEflag to stop grid search once a high-quality solution is found.6. Code Structure & Dependencies
Modularization
clonal_ascat.R) into focused modules (run_clonal_ascat.R,clonal_ascat_calc.R, etc.).New Dependencies
Rcpp,RcppRoll(Acceleration)collapse,vroom,tictoc,fs(IO/Perf)logger,cli,optparse(Interface)S4Vectors,IRanges(Genomics)License
AGPL-3since that is what was listed in the LICENSE file.7. Container & CLI Support
Dockerfile,Makefile, andcli/optparsesupport.