$ show KamilSJaron/smudgeplot
Smudgeplot is a bioinformatics CLI tool for reference-free ploidy inference from whole genome sequencing data. It operates on FastK k-mer databases, identifying heterozygous k-mer pairs (hetmers) using a high-performance C backend, then aggregates them into 'smudges' via a local clustering algorithm in Python. The tool infers haploid coverage through a grid search and produces 2D histogram plots (smudgeplots) that reveal haplotype structure. The codebase is a hybrid of a Python package (command-line interface, data analysis, matplotlib-based visualization) and a custom C library (parallelized k-mer pair detection). It follows a clean architecture with well-separated concerns, a comprehensive CLI, and CI/CD pipelines for distribution. The project is actively maintained, with recent support for Python 3.14 and cross-platform wheel builds.
The LLM identified 5 files worth highlighting for reuse:
The core C backend for finding heterozygous k-mer pairs (hetmers) from a FastK database. It implements a highly optimized, multithreaded recursive divide-and-conquer algorithm that scans the k-mer space partitioned by nucleotide prefix. The algorithm efficiently identifies k-mer pairs differing by exactly one nucleotide and records their coverage sums. This component is non-trivial, demonstrating masterful C programming with manual memory management, thread synchronization, and bit-level encoding. It could be extracted as a standalone library for any bioinformatics task requiring efficient enumeration of 1-mismatch k-mer pairs.
The Python module containing the core analysis logic: Coverages class for local aggregation of k-mer pairs into smudges, Smudges class for coverage inference via a grid search that maximizes smudge centrality, SmudgeplotData for preparing data and generating matplotlib figures. The local aggregation algorithm (Manhattan distance-based peak finding) is a clean, parameterizable implementation that could be reused for any 2D density peak detection task. The centrality calculation and coverage optimization are well-encapsulated and demonstrate thoughtful statistical engineering for a genomics domain problem.
Custom setuptools build script that compiles the C binary dependencies during installation and bundles them within the Python package. It overrides the build_py and develop commands to ensure binaries are compiled before packaging, supports cross-platform flags, and handles missing compilers gracefully for editable installs. This pattern is a well-crafted example of distributing a Python package with native compiled components and is directly reusable for any project that needs to bundle C tools with a Python wrapper.
The command-line interface entry point using argparse with subcommands (cutoff, hetmers, peak_aggregation, extract, plot, all). It demonstrates a clean pattern for dispatching to different execution paths, including running external C binaries via subprocess with proper error handling. The Parser class dynamically maps subcommand names to methods, making it extensible. It also includes helper functions for locating bundled binaries and for generating JSON reports. This module serves as an example of a well-organized CLI for a scientific tool.
GitHub Actions workflow that tests the package on multiple OS (Ubuntu, macOS) and Python versions (3.9–3.14), builds wheels via cibuildwheel for Linux x86_64 and macOS (both x86 and ARM), and builds a source distribution. It verifies that binaries are bundled and that the CLI commands work. This configuration is a robust, reusable template for any Python package with compiled dependencies, covering testing, wheel building, and sdist validation.