Make exception message informative in SAMUtils.charToCompressedBase #836

Merged
merged 2 commits into from Mar 30, 2017

Conversation

Projects
None yet
3 participants
Contributor

ronlevine commented Mar 30, 2017

Description

Fixes broadinstitute/picard#781.
Added the base and read names to the exception message in SAMUtils.charToCompressedBase.

Checklist

  • Code compiles correctly
  • New tests covering changes and new functionality
  • All tests passing
  • Extended the README / documentation, if necessary
  • Is not backward compatible (breaks binary or source compatibility)
@ronlevine ronlevine Make exception message informative
1cb5eff

ronlevine self-assigned this Mar 30, 2017

ronlevine requested a review from lbergelson Mar 30, 2017

Contributor

ronlevine commented Mar 30, 2017

@lbergelson Please review.

ronlevine changed the title from Make exception message informative to Make exception message informative in SAMUtils.charToCompressedBase Mar 30, 2017

codecov-io commented Mar 30, 2017 edited

Codecov Report

Merging #836 into master will increase coverage by 0.001%.
The diff coverage is 46.154%.

@@               Coverage Diff               @@
##              master      #836       +/-   ##
===============================================
+ Coverage     64.864%   64.866%   +0.001%     
- Complexity      7195      7197        +2     
===============================================
  Files            527       527               
  Lines          31774     31781        +7     
  Branches        5424      5424               
===============================================
+ Hits           20610     20615        +5     
- Misses          9016      9020        +4     
+ Partials        2148      2146        -2
Impacted Files Coverage Δ Complexity Δ
src/main/java/htsjdk/samtools/BAMRecord.java 73.723% <25%> (-1.651%) 37 <0> (ø)
src/main/java/htsjdk/samtools/BAMRecordCodec.java 84.536% <40%> (-2.561%) 15 <0> (ø)
src/main/java/htsjdk/samtools/SAMUtils.java 59.383% <75%> (+1.028%) 122 <0> (+2) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bbab32d...37a499b. Read the comment docs.

@lbergelson

@ronlevine I think that this should be reworked a little. Threading the read name through all of these methods seems like an unnecessary complication. I think it would be better to catch the exceptions in the place that has access to the read name and then rethrow them with added information. I would keep the change to initial throw site to have it output the character as well as the byte value since that's always more useful than just the byte value.

- * Convert from a byte array containing =AaCcGgTtNn represented as ASCII, to a byte array half as long,
- * with =, A, C, G, T converted to 0, 1, 2, 4, 8, 15.
+ * Convert from a byte array containing =AaCcGgTtNnMmRrSsVvWwYyHhKkDdBb represented as ASCII, to a byte array half as long,
+ * with fore example, =, A, C, G, T converted to 0, 1, 2, 4, 8, 15.
@lbergelson

lbergelson Mar 30, 2017

Contributor

isn't it for example?

@ronlevine

ronlevine Mar 30, 2017

Contributor

Yes. Done.

}
return compressedBases;
}
/**
- * Convert from a byte array with basese stored in nybbles, with =, A, C, G, T represented as 0, 1, 2, 4, 8, 15,
+ * Convert from a byte array with bases stored in nybbles, with fore example,=, A, C, G, T, N represented as 0, 1, 2, 4, 8, 15,
@lbergelson

lbergelson Mar 30, 2017

Contributor

fore -> for again I believe

@ronlevine

ronlevine Mar 30, 2017

Contributor

Yes. Done.

* @param compressedOffset Byte offset in compressedBases to start.
* @return New byte array with bases as ASCII bytes.
*/
- public static byte[] compressedBasesToBytes(final int length, final byte[] compressedBases, final int compressedOffset) {
+ public static byte[] compressedBasesToBytes(final int length, final byte[] compressedBases, final int compressedOffset, final String readName) {
@lbergelson

lbergelson Mar 30, 2017

Contributor

I don't think it 's a great idea to change the signature of this public method to require the read name to produce a better error message in a specific use case. I think it would be better to catch the exception in the calling method and re-throw an exception with the added information.

@ronlevine

ronlevine Mar 30, 2017

Contributor

Yes. Done.

@@ -214,17 +218,19 @@ private static byte charToCompressedBaseLow(final int base) {
case 'b':
return COMPRESSED_B_LOW;
default:
- throw new IllegalArgumentException("Bad byte passed to charToCompressedBase: " + base);
+ throw new IllegalArgumentException("Bad base passed to charToCompressedBaseLow: " + Character.toString((char)base) + " in read: " + readName);
@lbergelson

lbergelson Mar 30, 2017

Contributor

good idea to output the character equivalent of the byte number, but you probably also want the byte value itself in case its a non-printing or formatting character

@ronlevine

ronlevine Mar 30, 2017

Contributor

Agreed, done.

@@ -394,6 +404,7 @@ public static char phredToFastq(final int phredScore) {
}
/**
+ *
@lbergelson

lbergelson Mar 30, 2017

Contributor

extra newline got added here accidentally

@ronlevine

ronlevine Mar 30, 2017

Contributor

Yes. Done.

@ronlevine ronlevine Add read name where accessible to the exception message
37a499b
Contributor

ronlevine commented Mar 30, 2017

@lbergelson Reworked the code per your suggestion and responded to the rest of your comments.

@lbergelson lbergelson merged commit 9d343e7 into master Mar 30, 2017

4 of 5 checks passed

codecov/patch 46.154% of diff hit (target 64.864%)
Details
codecov/changes No unexpected coverage changes found.
Details
codecov/project 64.866% (+0.001%) compared to bbab32d
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

lbergelson deleted the rhl_bad_char_log_msg branch Mar 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment