Repository navigation
bedfile plots with gtars - #127
Merged
Merged
Conversation
khoroshevskyi
requested review from
sanghoonio
and
a balanced review from Copilot
August 31, 2026 19:27
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
There are confirmed correctness/documentation issues in the new aggregation output (partition scaling and per-chrom n handling) that should be addressed before merge.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 7
- Review effort level: Lite
| distributions: bool = False, | ||
| ) -> BedBatchResult: | ||
| """ | ||
| Get multiple bed file records by identifiers in a single DB round-trip. |
Member
There was a problem hiding this comment.
Taken as suggested in 5304f56.
On the count, for the record: SelectInLoader chunks parent keys at 500 (sqlalchemy/orm/strategies.py:2967), so get_batch costs three statements up to 500 identifiers and five at the MAX_BATCH_SIZE ceiling of 1000. The new wording avoids committing to a number, which is the right call.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
5edc86f removed the `agg_columns.extend([` wrapper along with the `* 100` multipliers, leaving an orphaned list literal. aggregation.py has not parsed since, and both bedsets.py and bedfiles.py import it, so `import bbconf` fails outright — conftest.py cannot load and no tests are collected. Restore the wrapper. The multipliers stay off, but for a different reason than the autofix assumed: the bed_stats.*_percentage columns hold a fraction, not a percentage. Both producers divide by the region count — regionstat.R:212 stores Freq/length(query), gtars_backend.py:227 stores count/total — and bedbase-ui renders the per-file values as value * 100. Since the aggregation no longer rescales, `mean_pct`/`sd_pct` would have been misnamed, so they become `mean`/`sd`. That also matches the shape already used by `scalar_summaries`, leaving every value in BedSetDistributions on the same scale as the column it aggregates. bedbase-ui scales to percent at the plot layer, where the local comparison path already does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRGhWjGiUXFoygd35QsKQ7
The scalar was mapped to bed_stats.tssdist, a leftover TSS column that nothing writes: BedStatsModel has never declared the field, so the value bedboss computed was discarded by extra="ignore" before insert. count() returned 0, `if not n: continue` fired, and the key was silently absent from every scalar_summaries payload since the aggregation was written. Rather than adding a column, a model field and a migration to wire it up, drop it. Remove the aggregation entry, the matching key in the _old_stats_to_scalar_summaries fallback, and the BedSetDistributions docstring line that pointed readers at it as the replacement for the neighbor_distances KDE. That line now states the real reason the KDE is not aggregated: each file's curve is fit over its own log10 range, so bin i means a different bp value per file. bed_stats.tssdist is left in place; removing it needs its own migration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRGhWjGiUXFoygd35QsKQ7
Four fixes, none behavioural beyond the values reported: region_distribution set each chromosome's "n" from whichever (chrom, bin) row arrived first and never updated it, so a chromosome whose member files have ragged arrays reported the count for an arbitrary bin. Take the max across bins, which is the number of files contributing anything to that chromosome. get_distributions' pre-aggregation fallback reported n_files=0 and n=0 for bedsets that do have members. The bedset row carries bedfile_count, so use it. The fallback also omitted "histogram" entirely while the aggregation path always emits it — two shapes for one field, which a consumer can only distinguish by probing for absence. Emit histogram: None instead; there are no per-file values to bin, and the key now matches. The BedSetDistributions docstring described tss_histogram as summed per-bin counts; _aggregate_tss_histogram computes AVG and STDDEV. get_batch's docstring claimed a single DB round-trip; the two selectinload options make it three. It is batched, not single. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRGhWjGiUXFoygd35QsKQ7
Same defect Copilot flagged in region_distribution, one function over and unreported: "n" was read from rows[0], so it described whichever bin sorted first rather than the collection. Member files emitting different-length counts arrays give bins different contributing-file counts, and the reported value was then arbitrary. Take the max, matching what _aggregate_region_distribution now does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRGhWjGiUXFoygd35QsKQ7
Both queries order by bin_idx, and every file with a non-empty array for a chromosome contributes bin 0, so the first row already carried the number of contributing files — max() computed the same value. The change was robustness against a future reordering, not a fix, and nothing reads either field: bedset-plots.ts passes the top-level n_files into regionDistributionSlot. Reverts 3e608c9 and the aggregation.py hunk of 92fe156. The fallback n_files, histogram shape, and the two docstring corrections from 92fe156 stand. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRGhWjGiUXFoygd35QsKQ7
"with batched DB queries" is tighter than "without a per-record query" and matches the review comment's own phrasing. Neither commits to a query count, which is the right call: selectinload chunks parent keys at 500, so get_batch costs three statements up to 500 identifiers and five at the MAX_BATCH_SIZE ceiling of 1000. The `or 0` on bedfile_count was dead: the column is nullable=False in the initial migration, so the guard implied a NULL that cannot occur. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRGhWjGiUXFoygd35QsKQ7
sanghoonio
approved these changes
Sep 3, 2026
1 of 3 tasks
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.
Changes:
_aggregate_region_distribution() (aggregation.py:245) takes all member files of a bedset and, per (chromosome, bin index), computes the mean, sd, and n across files:
Concerns:
The scalar stats are one number per file (a plain AVG over N rows).
region_distributionis a nested array per file, so aggregating means materializing files × chromosomes × bins rows in SQL before the GROUP BY — that product is what can blow up for 10K files, depending on how many bins gtars emits per file.TODO:
__version__.pyfile