-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple problems with mishandling of missing entries in compute_… #242
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
239390b
Fix multiple problems with mishandling of missing entries in compute_…
lfrancioli b7f1b43
Black formatting
lfrancioli 5928464
Added entry in CHANGELOG.md
lfrancioli 65ca815
Fixed problem when mt was keyed by locus/alleles in sparse_mt.compute…
lfrancioli 2246567
Added new version of coverage to resources and a more efficient compu…
lfrancioli 4f18ba6
Update CHANGELOG.md
lfrancioli 93719e3
Merge branch 'master' into compute_cov_sparse
ch-kr 568e261
Reformatted with black
ch-kr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -651,10 +651,10 @@ def compute_coverage_stats( | |
print(f"Computing coverage stats on {n_samples} samples.") | ||
|
||
# Create an outer join with the reference Table | ||
mt = mt.select_entries("END", "DP") | ||
mt = mt.select_entries("END", "DP").select_cols().select_rows() | ||
col_key_fields = list(mt.col_key) | ||
t = mt._localize_entries("__entries", "__cols") | ||
t = t.join(reference_ht.annotate(_in_ref=True), how="outer") | ||
t = t.join(reference_ht.key_by(*mt.row_key).select(_in_ref=True), how="outer") | ||
t = t.annotate( | ||
__entries=hl.or_else( | ||
t.__entries, | ||
|
@@ -669,14 +669,17 @@ def compute_coverage_stats( | |
# Filter rows where the reference is missing | ||
mt = mt.filter_rows(mt._in_ref) | ||
|
||
# Unfilter entries so that entries with no ref block overlap aren't null | ||
mt = mt.unfilter_entries() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohh, great catch!! I didn't realize you needed this and tested it out in a notebook to confirm. |
||
|
||
# Compute coverage stats | ||
coverage_over_x_bins = sorted(coverage_over_x_bins) | ||
max_coverage_bin = coverage_over_x_bins[-1] | ||
hl_coverage_over_x_bins = hl.array(coverage_over_x_bins) | ||
|
||
# This expression creates a counter DP -> number of samples for DP between 0 and max_coverage_bin | ||
coverage_counter_expr = hl.agg.counter( | ||
hl.or_else(hl.min(max_coverage_bin, mt.DP), 0) | ||
hl.min(max_coverage_bin, hl.or_else(mt.DP, 0)) | ||
) | ||
|
||
# This expression aggregates the DP counter in reverse order of the coverage_over_x_bins | ||
|
@@ -697,12 +700,12 @@ def compute_coverage_stats( | |
) | ||
) | ||
) | ||
mean_expr = hl.agg.mean(mt.DP) | ||
mean_expr = hl.agg.mean(hl.or_else(mt.DP, 0)) | ||
|
||
# Annotate rows now | ||
return mt.select_rows( | ||
mean=hl.cond(hl.is_nan(mean_expr), 0, mean_expr), | ||
median=hl.or_else(hl.agg.approx_median(mt.DP), 0), | ||
median_approx=hl.or_else(hl.agg.approx_median(hl.or_else(mt.DP, 0)), 0), | ||
total_DP=hl.agg.sum(mt.DP), | ||
**{ | ||
f"over_{x}": count_array_expr[i] / n_samples | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be helpful to include a note about the resource changes here too