Fix spectrum, tree, IO, and plotting bugs; add calculate_mutrate - #17
Draft
kpotoh wants to merge 1 commit into
Draft
Fix spectrum, tree, IO, and plotting bugs; add calculate_mutrate#17kpotoh wants to merge 1 commit into
kpotoh wants to merge 1 commit into
Conversation
Keep RawMutSpec separate from scaled MutSpec, accept 12-component Mut values, and add calculate_mutrate. Fix CodonAnnotation (CDS length, ValueError, logger crash), GenomeStates/GenesStates IO, MutSpecExtractor serial extraction, plot_mutspec closing caller axes, and several pandas 3 compat issues. Add regression tests and bump to 0.0.16. Co-authored-by: kpotoh <kpotoh@users.noreply.github.com>
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.
Fixes several correctness bugs found while exploring the library (issue #13) and adds
calculate_mutrate. Version bump: 0.0.15 → 0.0.16. All 97 tests pass.Spectrum calculation (
calculate_mutspec/ MutRate)RawMutSpec(obs/exp) separate from scaledMutSpecso scaling no longer overwrites the unscaled rates.C>T) as well as 192 (A[C>T]G).calculate_mutrate()for unscaled observed/expected rates (exported from the package).collapse_mutspecacceptsObsNum/ExpNumas aliases ofObsFr/ExpFrand copies input to avoidSettingWithCopy.complete_sbs192_columnsfills missing columns in oneconcat(no fragmentation warning).jackknife_spectra_sampling/calc_edgewise_spectracopy inputs instead of mutating caller frames.nobs_cutoffadded; misspellednobs_cuttofkept as an alias.filter_outlier_branchesfalls back toProbaFullifProbaMutis missing.Codon annotation
warnings.warn(CodonAnnotation had nologger— that was a crash)._prepare_codontablenow actually raisesValueErrorfor invalid genetic-code arguments.get_syn_codonsdefault isset()notdict().MutSpecExtractor._derive_mutspecnow callsbranch.process_branch()(serial extraction was broken after the parallel refactor).dump_tableskips empty frames.Tree
TreeNode.parent/.upanditer_edges().Treeloads from a Newick string or a file path.node_parentcatchesStopIterationrather thanBaseException.get_tree_heighthandles zero distances for geometric mean.calc_phylocoefshandlestree_height <= 0.get_ingroup_rootno longer raisesUnboundLocalErrorwhen both root children are leaves.IO
GenomeStatesreads the states file (was using a leftover gappy-sitespath);path_to_gappy_sites=Noneworks.GenesStatespassesstates_fmtintoread_alignment; parameterized SQL;groupby.size(); validRuntimeError(illegalfile=keyword removed).read_genbank_refusesgene_qualifierandftr.location.strand(BioPython 1.88 has noSeqFeature.strand).Plotting and scripts
plot_mutspec(show=False)with callerax=no longerplt.close()s that figure (README multi-panel example was broken).scripts/calculate_mutspec.py:filter_short_exp_seqsactually drops IQR outliers;pivot(index=..., columns=..., values=...)for pandas 3.scripts/collect_mutations.py: empty dump handling; separate header flags for ms12 vs ms192 files.scripts/collect_mutations_parallel.py: sameBranch.process_branchfix as the library.basic_logger()uses a named logger and does not attach duplicate handlers.Tests
tests/test_mutspec_calc.pynow asserts realRawMutSpecvalues (old lookups never matched).tests/test_bugfixes.pyregression coverage.tests/test_codon_ann.py: realextract_mutations_simpletest.Suggested follow-ups (not in this PR)
These remain from issue #13 / README TODOs:
tree.pyintophylo_tree.py— existing TODO;node_parent/get_tree_heightstill live in a leftover module.vertdeprecation — 204MatplotlibDeprecationWarnings from seaborn internals vs matplotlib 3.11 (orientationinstead ofvert). Needs a seaborn upgrade or a local workaround inplot_mutspec.nobs_cutoffis the start; remaining names likenobs_cuttofalias,tree_heigthtypos in git history, and script--rewrite_dbTODOs could be cleaned up in a dedicated pass.basic_loggerstill optionally reads a config file; inline the small config as noted inutils/logging.py.