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

Improving exception messages in AssemblyRegion #6781

Merged
merged 2 commits into from
Sep 3, 2020

Conversation

lbergelson
Copy link
Member

  • Replacing some cases of NPE with IllegalArgumentException with a clear message.

This should help clarify the issue we talked about at the meeting today if it comes up again. I can't remember what the ticket was to link to though.

Copy link
Contributor

@droazen droazen left a comment

Choose a reason for hiding this comment

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

@lbergelson Back to you with my comments

Math.min(sequence.getSequenceLength(), genomeLoc.getEnd() + padding)).getBases();
}

private static String listContigsAsString(final SAMSequenceDictionary sequenceDictionary) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to SequenceDictionaryUtils (or, better, use one of the existing methods there like SequenceDictionaryUtils.getContigNamesList())

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course that exists already.

Copy link
Member Author

Choose a reason for hiding this comment

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

It actually exists in at least 2 places. ReadUtils.prettyPrintSequenceRecords seems to be the version I want.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Contig chrNotInReference not found in reference.*")
//Testing a case where an NPE was thrown when somehow the reference sequence dictionary didn't contain a contig in the
//assembly region.
public void testMimatchedReferenceAndRegion(){
Copy link
Contributor

Choose a reason for hiding this comment

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

Mimatched -> Mismatched

Copy link
Member Author

Choose a reason for hiding this comment

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

My keyboard is going to kill me with typos. It's started to just drop random letters and double others.

"\nPlease check that you are using a compatible reference for your data." +
"\nReference Sequences: " + listContigsAsString(referenceReader.getSequenceDictionary()));

return referenceReader.getSubsequenceAt(contig,
Copy link
Contributor

Choose a reason for hiding this comment

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

getSubsequenceAt() will already throw a UserException.MissingContigInSequenceDictionary exception internally if the contig is missing -- is there some way we could rely on that existing check? Ideally we should avoid adding lots of additional sequence dictionary lookups to frequently-called methods if we can possibly help it...

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not clear to me how to avoid it because we need the sequence length from the sequence to make the call to getSubsequenceAt. This pr isn't adding a new lookup, it's just moving it. We could add a new sequenceDictionary method that automatically clips to the ends to avoid this extra lookup, but that seems like a lot of effort.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you're right, it can't be avoided. This is fine then.

@@ -122,6 +124,19 @@ private void assertGoodReferenceGetter(final byte[] actualBytes, final SimpleInt
return tests.subList(2,3).toArray(new Object[][]{}); //HACK!
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Contig chrNotInReference not found in reference.*")
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not know about expectedExceptionsMessageRegExp ! And now that I do, I have mixed feelings about it...throwing a more specific exception type is better than checking the exception message text itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right... changing to UserException.MissingContigInSequenceDictionary.

public void testMimatchedReferenceAndRegion(){
final SAMSequenceDictionary sequenceDictionary = header.getSequenceDictionary();
final String contigNotInReference = "chrNotInReference";
sequenceDictionary.addSequence(new SAMSequenceRecord(contigNotInReference, 1000));
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this change the sequence dictionary in the shared header instance used by all the tests in this class? Can you write this test in a way that doesn't modify shared data?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh. Yes it does. Changing. Good catch.

@droazen droazen assigned lbergelson and unassigned droazen Sep 1, 2020
* Replacing some cases of NPE with IllegalArgumentException with a clear message.
@lbergelson lbergelson force-pushed the lb_fix_npe_in_assemblyregion branch from 4b0c1ac to 20328e7 Compare September 1, 2020 19:48
@lbergelson
Copy link
Member Author

@droazen I think I addressed everything. Thanks for the review. Good catch on the header.

Copy link
Contributor

@droazen droazen left a comment

Choose a reason for hiding this comment

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

👍 New version looks good

@droazen droazen merged commit 3031738 into master Sep 3, 2020
@droazen droazen deleted the lb_fix_npe_in_assemblyregion branch September 3, 2020 16:49
mwalker174 pushed a commit that referenced this pull request Nov 3, 2020
…erence dictionary (#6781)

* Improving exception messages in AssemblyRegion for contigs not in the reference dictionary 

* Replacing some cases of NPE with UserException.MissingContigInSequenceDictionary with a clear message.
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