-
Notifications
You must be signed in to change notification settings - Fork 7
fix: intersect() with mismtached chrom #191
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
38b424d
fix: binary interval ops with mismtached chrom/strand/genome
ovesh b114917
reduce scope to intersect() only
ovesh fe159f5
remove check from binary boolean ops
ovesh 03d7492
add tests
ovesh dd475ec
try to force cache create (github actions error)
ovesh 90cc8df
add negative overlaps() test cases
ovesh 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ on: | |
| - "src/**" | ||
| - "tests/**" | ||
|
|
||
|
|
||
| jobs: | ||
| build: | ||
| strategy: | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,9 @@ Copyright (C) 2016-2023 Deep Genomics Inc. All Rights Reserved. | |
| #define GK_CHECK_REFG(a, b) \ | ||
| GK_CHECK((a).refg == (b).refg, value, "Coordinate system mismatch, {} and {}.", (a), (b)); | ||
|
|
||
| #define GKPY_INTERVAL_BOOL_METHOD_ONEARG(pyname, method) \ | ||
| GKPY_METHOD_BEGIN_ONEARG(pyname, method) \ | ||
| const Py##pyname::value_t& c = Py##pyname::value(selfo); \ | ||
| #define GKPY_INTERVAL_BOOL_METHOD_ONEARG(method) \ | ||
|
Contributor
Author
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. drive by. This macro is only ever used for PyInterval |
||
| GKPY_METHOD_BEGIN_ONEARG(Interval, method) \ | ||
| const PyInterval::value_t& c = PyInterval::value(selfo); \ | ||
| if (PyInterval::check(arg)) { const interval_t& a = PyInterval::value(arg); GK_CHECK_REFG(c, a); GKPY_RETURN_BOOL(c.method(a)); } \ | ||
| GK_THROW(type, "argument must be an Interval, not '{}'", Py_TYPE(arg)->tp_name); \ | ||
| GKPY_METHOD_END | ||
|
|
@@ -270,6 +270,9 @@ GKPY_METHOD_BEGIN_ONEARG(Interval, intersect) | |
| auto x = PyInterval::value(selfo); | ||
| if (PyInterval::check(arg)) { | ||
| auto y = PyInterval::value(arg); | ||
| if (!y.same_strand(x)) { | ||
| GKPY_RETURN_NONE; | ||
| } | ||
| if (((PyInterval*)selfo)->get_anchor() != invalid_pos || ((PyInterval*)arg)->get_anchor() != invalid_pos) { | ||
| GK_THROW(value, "anchored intersection ({}, {}) is not supported.", x, y); | ||
| } | ||
|
|
@@ -285,11 +288,11 @@ GKPY_METHOD_BEGIN_ONEARG(Interval, intersect) | |
| } | ||
| GK_THROW(type, "argument must be Interval, not '{}'", Py_TYPE(arg)->tp_name); | ||
| GKPY_METHOD_END | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(Interval, upstream_of) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(Interval, dnstream_of) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(Interval, contains) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(Interval, within) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(Interval, overlaps) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(upstream_of) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(dnstream_of) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(contains) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(within) | ||
| GKPY_INTERVAL_BOOL_METHOD_ONEARG(overlaps) | ||
| GKPY_INTERVAL_BOOL_METHOD_NOARG(Interval, is_pos_strand) | ||
| GKPY_METHOD_BEGIN_ONEARG(Interval, as_positive_strand) | ||
| return PyInterval::create(PyInterval::value(selfo).as_pos_strand(), self->get_anchor(), self->get_anchor_offset()); | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -443,13 +443,18 @@ def test_comparisons_forward(self): | |
|
|
||
| self.assertTrue(c.upstream_of(a)) | ||
| self.assertFalse(b.upstream_of(a)) | ||
| self.assertTrue(a.overlaps(b)) | ||
|
Collaborator
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. can we add a new test interval just so we can have a overlap == false test |
||
| self.assertFalse(a.overlaps(c)) | ||
|
|
||
| self.assertTrue(a.dnstream_of(c)) | ||
| self.assertFalse(a.dnstream_of(b)) | ||
|
|
||
| self.assertTrue(a.contains(d)) | ||
| self.assertFalse(a.contains(b)) | ||
|
|
||
| self.assertTrue(d.within(a)) | ||
| self.assertFalse(b.within(a)) | ||
|
|
||
| self.assertTrue(a.upstream_of(Interval.from_rna1('chr1', 21, 21, 'hg19'))) | ||
| self.assertFalse(a.upstream_of(Interval.from_rna1('chr1', 20, 20, 'hg19'))) | ||
| self.assertFalse(a.upstream_of(Interval.from_rna1('chr1', 19, 19, 'hg19'))) | ||
|
|
@@ -476,6 +481,18 @@ def test_comparisons_forward(self): | |
| with self.assertRaises(ValueError): | ||
| d != e | ||
|
|
||
| # test incompatible strand/chromosome | ||
| self.assertFalse(c.upstream_of(a.as_opposite_strand())) | ||
| self.assertFalse(c.upstream_of(Interval('chr2', a.strand, a.start, a.end, a.refg))) | ||
| self.assertFalse(a.dnstream_of(c.as_opposite_strand())) | ||
| self.assertFalse(a.dnstream_of(Interval('chr2', c.strand, c.start, c.end, c.refg))) | ||
| self.assertFalse(a.contains(d.as_opposite_strand())) | ||
| self.assertFalse(a.contains(Interval('chr2', d.strand, d.start, d.end, d.refg))) | ||
| self.assertFalse(d.within(a.as_opposite_strand())) | ||
| self.assertFalse(d.within(Interval('chr2', a.strand, a.start, a.end, a.refg))) | ||
| self.assertFalse(a.overlaps(b.as_opposite_strand())) | ||
| self.assertFalse(a.overlaps(Interval('chr2', b.strand, b.start, b.end, b.refg))) | ||
|
|
||
| def test_comparisons_reverse(self): | ||
| a = Interval.from_rna1('chr1', -20, -10, 'hg19') | ||
| b = Interval.from_rna1('chr1', -15, -5, 'hg19') | ||
|
|
@@ -485,6 +502,7 @@ def test_comparisons_reverse(self): | |
| self.assertTrue(a.upstream_of(c)) | ||
| self.assertFalse(a.upstream_of(b)) | ||
| self.assertTrue(a.overlaps(b)) | ||
| self.assertFalse(a.overlaps(c)) | ||
|
|
||
| self.assertTrue(c.dnstream_of(a)) | ||
| self.assertFalse(b.dnstream_of(a)) | ||
|
|
@@ -502,6 +520,17 @@ def test_comparisons_reverse(self): | |
| self.assertTrue(a.dnstream_of(Interval.from_rna1('chr1', -21, -21, 'hg19'))) | ||
| self.assertFalse(a.dnstream_of(Interval.from_rna1('chr1', -20, -20, 'hg19'))) | ||
|
|
||
| # test incompatible strand/chromosome | ||
| self.assertFalse(a.upstream_of(c.as_opposite_strand())) | ||
| self.assertFalse(a.upstream_of(Interval('chr2', c.strand, c.start, c.end, c.refg))) | ||
| self.assertFalse(c.dnstream_of(a.as_opposite_strand())) | ||
| self.assertFalse(c.dnstream_of(Interval('chr2', a.strand, a.start, a.end, a.refg))) | ||
| self.assertFalse(a.contains(d.as_opposite_strand())) | ||
| self.assertFalse(a.contains(Interval('chr2', d.strand, d.start, d.end, d.refg))) | ||
| self.assertFalse(d.within(Interval('chr2', a.strand, a.start, a.end, a.refg))) | ||
| self.assertFalse(a.overlaps(b.as_opposite_strand())) | ||
| self.assertFalse(a.overlaps(Interval('chr2', b.strand, b.start, b.end, b.refg))) | ||
|
|
||
| def test_input_validation(self): | ||
|
|
||
| with self.assertRaises(ValueError): | ||
|
|
@@ -693,6 +722,7 @@ def test_intersect(self): | |
| self.assertEqual(neg_mid.intersect(neg_inside), neg_inside) | ||
|
|
||
| self.assertIsNone(left.intersect(Interval(left.chrom, left.strand, left.start, left.end, 'hg38.p12'))) | ||
| self.assertIsNone(left.intersect(Interval('chr2', left.strand, left.start, left.end, left.reference_genome))) | ||
| self.assertIsNone(neg_left.intersect(left)) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
|
|
||
Oops, something went wrong.
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.
See #192