Conversation
Add a sam-stats command that prints summary statistics for SAM/BAM/CRAM files: read counts, mapping rates, Q30, depth, SAM flag breakdown, per-reference counts, optional --tags value distributions and --calc-insert median. Ports the per-read logic from ngsutils bam-stats (unique = NH/IH/MAPQ; profiles the first read of each pair). Phase 1 omits the --gtf gene-model and --bed on-target stats. Also fix usage-on-error handling at the root: move SilenceUsage into PersistentPreRun so argument/flag errors still print usage while execution errors do not, and stop double-printing the error in Execute. 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.
Summary
Adds a
sam-statscommand that prints summary statistics for SAM/BAM/CRAM files, porting the per-read logic fromngsutils bam-stats. Phase 1 — the--gtfgene-model and--bedon-target stats are intentionally deferred (they need an interval/region model that doesn't exist in cgkit yet).Statistics reported
Nalignments are present, matching the RNA-seq guard)[Flags]breakdown (non-zero bits only) and[References]per-chrom counts--tags NH:i,RG:Z,MAPQvalue distributions with amissingbucket--calc-insertmedian,--rgidfilter,--unique,--show-unmapped-ref,--cram-refFaithful to the Java semantics: unique detection is NH→IH→MAPQ, and only the first read of each pair is profiled (so
totalis intentionally lower thansamtools flagstat's raw record count).Also: usage-on-error fix (root)
SilenceUsagewas set globally, so a missing argument printed only the bare error with no usage. Moved it intoPersistentPreRun(which runs after Cobra validates args/flags but beforeRunE), so:Also stopped double-printing the error in
Execute()(Cobra already prints it). This applies uniformly to all commands.Test plan
go test ./...passes;go vetandgofmtcleansam_stats_test.gocovers counts, second-of-pair/unmapped handling, Q30, a--tagstally,--rgidfiltering, and tag-spec parsingsamtools flagstat🤖 Generated with Claude Code