Refactor active Snakefiles to Snakemake best practices#43
Merged
Conversation
Convert the run:/os.system() anti-pattern in the three active-command
Snakefiles (bap2.chr, bap_frags, bap_bulk_frags) to idiomatic Snakemake:
- Replace string-concatenated os.system() calls with proper shell: directives
using {input}/{output}/{params}/{threads} and global variables
- Move manual 2>/&> redirects into log: directives
- Move computed values (name-sorted bam path, temp/anno paths, cut columns,
QC flag toggles) into params:; keep awk programs as readable named constants
substituted verbatim via {params.*}
- For determine_HQ_beads (genuine Python: Counter/knee logic) keep run: but
swap os.system() for Snakemake's shell() helper
- Replace pysam.sort/pysam.index with the configured samtools binary so the
rule is a clean shell:, and fix a latent NameError (undefined `pp` when
--all-pairs is set) via a proper_pair_filter param
Command semantics are preserved exactly (verified by rendering every rule's
shell command with `snakemake -n -p` against a scaffolded config/DAG). The
deprecated v1 Snakefile.bap.chr is intentionally left unchanged, consistent
with leaving the v1 CLI untouched.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Follow-up to #42. Refactors the three Snakefiles driving the active commands (
Snakefile.bap2.chr,Snakefile.bap_frags,Snakefile.bap_bulk_frags) from therun:+os.system(<string>)anti-pattern to idiomatic Snakemake.Changes
shell:directives replace string-concatenatedos.system()calls, using{input}/{output}/{params}/{threads}and global variables.log:directives replace manual2>/&>redirects.params:hold computed values (name-sorted bam path, temp/annotated paths,cutcolumns, QC flag toggles). awk programs are kept as readable named constants and substituted verbatim via{params.*}(avoids brace-escaping noise).determine_HQ_beadskeepsrun:(it has genuine Python:Counter/knee-calling logic) but swapsos.system()for Snakemake'sshell()helper.pysam.sort/pysam.indexwith the configuredsamtoolsbinary so those rules become cleanshell:blocks, and fixed a latentNameError(undefinedppwhen--all-pairsis set) via aproper_pair_filterparam.Behavior preservation
Command semantics are preserved exactly. Every rule's rendered shell command was verified with
snakemake -n -pagainst a scaffolded config + DAG (all three build valid DAGs: 17 / 5 / 4 jobs). Subtle differences were kept intact — e.g.bap_fragsgzips its bedpe whilebap_bulk_fragsdoes not, thenc_thresholdargument position,samtools collatevssort -n, and thetabix <file> -p bedargument order. One real bug was caught and fixed during validation: a bare{name}collided with Snakemake's reserved shell-namespace key and rendered the rule name; it now passes the sample name via asample_nameparam.Out of scope
The deprecated v1
Snakefile.bap.chris left unchanged, consistent with leaving the v1 CLI untouched in #42.🤖 Generated with Claude Code