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

Removed plain asserts and replaced them with ValidationUtil function #1465

Merged
merged 5 commits into from Feb 20, 2020

Conversation

yfarjoun
Copy link
Contributor

@yfarjoun yfarjoun commented Feb 9, 2020

  • some asserts remain, but they have been fixed in a different PR.

Description

Give your PR a concise yet descriptive title
Please explain the changes you made here.
Explain the motivation for making this change. What existing problem does the pull request solve?
Mention any issues fixed, addressed or otherwise related to this pull request, including issue numbers or hard links for issues in other repos.
You can delete these instructions once you have written your PR description.


Checklist (never delete this)

Never delete this, it is our record that procedure was followed. If you find that for whatever reason one of the checklist points doesn't apply to your PR, you can leave it unchecked but please add an explanation below.

Content

  • Added or modified tests to cover changes and any new functionality
  • Edited the README / documentation (if applicable)
  • All tests passing on Travis

Review

  • Final thumbs-up from reviewer
  • Rebase, squash and reword as applicable

For more detailed guidelines, see https://github.com/broadinstitute/picard/wiki/Guidelines-for-pull-requests

…ions.

- some asserts remain, but they have been fixed in a different PR.
@lbergelson
Copy link
Member

Yes... asserts are evil.

@yfarjoun
Copy link
Contributor Author

feel free to review this @lbergelson ....

@@ -45,7 +47,7 @@
public static TruthState getHom(final int alleleIdx) {
if (alleleIdx == 0) return HOM_REF;
if (alleleIdx == 1) return HOM_VAR1;
assert false;
ValidationUtils.validateArg(false,"Shouldn't be here.");
Copy link
Member

Choose a reason for hiding this comment

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

In this case, why not throw new PicardException("Invalid allele index: " + alleleIdx);? This doesn't seem like a proper use of validateArg().

Copy link
Member

Choose a reason for hiding this comment

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

@yfarjoun Wait, I lied, you didn't respond to Phil here.

@@ -186,7 +187,7 @@ protected WgsMetrics generateWgsMetrics(final IntervalList intervals,

@Override
protected WgsMetricsCollector getCollector(final int coverageCap, final IntervalList intervals) {
assert(coverageCap == this.collector.coverageCap);
ValidationUtils.validateArg(coverageCap == this.collector.coverageCap,()->"coverageCap has to be the same as the internal coverageCap, found " + coverageCap + " and " + this.collector.coverageCap);
Copy link
Member

Choose a reason for hiding this comment

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

Please reformat the changed lines in the IDE. In this case I would expect to see spaces around the -> operator, and the line length seems long to me.

* one or two of them, depending on whether it's a paired-end read. This relies on the unmapped
* BAM file having all paired reads together in order.
*/
public class BamToBfqWriter {
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to delete this class? This seems unrelated to your other changes, and maybe deserves its own PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this seemed to have been due to the rebase...I didn't do it...

Copy link
Member

@lbergelson lbergelson left a comment

Choose a reason for hiding this comment

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

@yfarjoun I agree with @pshapiro4broad 👍 after resolving the minor issues.

@@ -948,7 +949,7 @@ private void doTest(final String[] args, final File metrics, final int expectedR

} catch (NoSuchFieldException e) {
e.printStackTrace();
assert false;
ValidationUtils.validateArg(false,"Shouldn't be here.");
Copy link
Member

Choose a reason for hiding this comment

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

just throw here

@@ -56,7 +58,7 @@ public static TruthState getVar(final int allele0idx, final int allele1idx) {
if (allele0idx == 1 && allele1idx == 2) return HET_VAR1_VAR2;
if (allele0idx == 2 && allele1idx == 1) return HET_VAR1_VAR2;

assert false;
ValidationUtils.validateArg(false,"Shouldn't be here.");
Copy link
Member

Choose a reason for hiding this comment

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

Just throw if we shouldn't be here.

Copy link
Member

Choose a reason for hiding this comment

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

Same

// adjust to a shorter length iff clipping tag exists
Integer trimPoint = rec.getIntegerAttribute(ReservedTagConstants.XT);
if (trimPoint != null) {
ValidationUtils.validateArg(rec.getReadLength() == seqs.length, () -> "length of read and seqs differ. Found " + rec.getReadLength() + " and '" + seqs.length + ".");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the actual change in the file...everything else is due to newline differences.....

@yfarjoun
Copy link
Contributor Author

since I added a commit...I cannot merge without another review....

Copy link
Member

@lbergelson lbergelson left a comment

Choose a reason for hiding this comment

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

@yfarjoun Looks good, although something funky is going on with the BamToBfqWriter. I it supposed to be deleted in master?

@@ -109,8 +111,7 @@ public static CallState getHom(final int alleleIdx) {
if (alleleIdx == 2) return HOM_VAR2;
if (alleleIdx == 3) return HOM_VAR3;

assert false;
return null;
throw new IllegalStateException("Shouldn't be here.");
Copy link
Member

Choose a reason for hiding this comment

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

here

@@ -124,22 +125,22 @@ public static CallState getHet(int allele0idx, int allele1idx) {
if (allele1idx == 1) return HET_REF_VAR1;
if (allele1idx == 2) return HET_REF_VAR2;
if (allele1idx == 3) return HET_REF_VAR3;
assert false;
ValidationUtils.validateArg(false,"Shouldn't be here.");
Copy link
Member

Choose a reason for hiding this comment

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

to

return null;
}

//HET CASES
if(allele0idx == 1) {
if (allele1idx == 2) return HET_VAR1_VAR2;
if (allele1idx == 3) return HET_VAR1_VAR3;
assert false;
ValidationUtils.validateArg(false,"Shouldn't be here.");
Copy link
Member

Choose a reason for hiding this comment

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

and

return null;
}

if(allele0idx == 2 && allele1idx == 3) return HET_VAR3_VAR4; //special case not a mistake.
if(allele0idx == 3 && allele1idx == 4) return HET_VAR3_VAR4;

assert false;
ValidationUtils.validateArg(false,"Shouldn't be here.");
Copy link
Member

Choose a reason for hiding this comment

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

here

Copy link
Member

@lbergelson lbergelson left a comment

Choose a reason for hiding this comment

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

@yfarjoun Missed a set of comments

@yfarjoun
Copy link
Contributor Author

thanks @lbergelson fixed.

Copy link
Member

@pshapiro4broad pshapiro4broad left a comment

Choose a reason for hiding this comment

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

Looks good. Some (maybe) unused imports to clean up.

@@ -1,5 +1,7 @@
package picard.vcf;

import htsjdk.utils.ValidationUtils;
Copy link
Member

Choose a reason for hiding this comment

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

import is now unused?

@@ -3,6 +3,7 @@
import htsjdk.samtools.SamReader;
import htsjdk.samtools.metrics.MetricsFile;
import htsjdk.samtools.util.IOUtil;
import htsjdk.utils.ValidationUtils;
Copy link
Member

Choose a reason for hiding this comment

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

Also unused import

@yfarjoun yfarjoun merged commit d6cb393 into master Feb 20, 2020
@yfarjoun yfarjoun deleted the yf_remove_asserts branch February 20, 2020 20:55
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.

None yet

3 participants