Skip to content
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

Validate SVCallRecord coordinates #7714

Merged
merged 2 commits into from
Mar 24, 2022
Merged

Validate SVCallRecord coordinates #7714

merged 2 commits into from
Mar 24, 2022

Conversation

mwalker174
Copy link
Contributor

-Adds start/end coordinate validation to SVCallRecord, checking contigs and positions against the sequence dictionary and their ordering.
-Adds some checks for invalid coordinates in places where SimpleInterval.expandWithinContig() can potentially return null.
-Addresses an issue where inter-chromosomal records' end positions were incorrectly disallowed from preceding the start position during record collapsing (despite being on a different contig).
-Deletes unused SVCallRecordWithEvidence

Includes regression tests.

@mwalker174 mwalker174 requested a review from cwhelan March 9, 2022 21:40
Copy link
Member

@cwhelan cwhelan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine -- just a couple of small questions and suggestions.

Utils.nonNull(dictionary);
validatePosition(contigA, positionA, dictionary);
validatePosition(contigB, positionB, dictionary);
Utils.validateArg(IntervalUtils.compareLocatables(getPositionAInterval(), getPositionBInterval(), dictionary) <= 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget -- do we do start == end for insertions in SVCallRecords? Just checking whether this needs to be <= or not. If we do, you might want to add a quick unit test condition to your new test in SVCallRecordUnitTest where start == end with a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes start==end should be correct. I've added a test with some valid coordinates to make sure they pass.

if (!getPaddedRecordInterval(a.getContigA(), a.getPositionA(), a.getPositionB())
.overlaps(getPaddedRecordInterval(b.getContigA(), b.getPositionA(), b.getPositionB()))) return false;
final SimpleInterval intervalA = getPaddedRecordInterval(a.getContigA(), a.getPositionA(), a.getPositionB());
Utils.nonNull(intervalA, "Invalid interval " + new SimpleInterval(a.getContigA(), a.getPositionA(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the getPaddedRecordInterval method returns null in the odd cases where the padded start is greater than the contig end or the padded stop is less than 1. Am I missing other cases? If not, aren't we already validating the coordinates when we construct the SVCallRecord object? I guess this assertion is there to be thorough -- maybe a short comment here explaining what the possible error condition is would be helpful to code readers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right I added checks for valid coordinates so this wouldn't happen, and this is here simply for safety. I've added a comment about it.

return new Object[][]{
{"chr1", 0, "chr1", 248956422},
{"chr1", 1, "chr1", 248956423},
{"chr1", 1, "chr1", 248956423},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned above maybe add a case where start == end? (I guess you'd have to change this test to handle positive examples as well..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Lists.newArrayList(Allele.REF_N, Allele.SV_SIMPLE_DEL),
Collections.emptyList(), Collections.emptyMap(), dictionary);
defragmenter.areClusterable(call1, call2);
Assert.fail("Expected exception not thrown");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but it might be a little more explicit to catch the exception and assert it's of the right type, etc. This test pattern can mask something going wrong in the error handling code (ie it would be pass if an NPE came back).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I realized that the exception thrown in these tests was actually happening when creating the invalid SVCallRecord, not during areClusterable(). There's no way around this (by design), so I've deleted these tests.

@mwalker174 mwalker174 merged commit 7c06a6a into master Mar 24, 2022
@mwalker174 mwalker174 deleted the mw_svcallrecord_coords branch March 24, 2022 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants