Added the ability to query the length of the line terminator to Ascii… #843

Merged
merged 1 commit into from Apr 18, 2017

Conversation

Projects
None yet
5 participants
Owner

tfenne commented Apr 5, 2017

…LineReader.

Description

I wanted @magicDGS to have access to the line terminator length so that .fai creation could be more robust 😉

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)

tfenne referenced this pull request Apr 5, 2017

Merged

Add .fai index creation support #842

4 of 5 tasks complete
@@ -93,6 +105,10 @@ public final String readLine(final PositionalBufferedStream stream) throws IOExc
if (c == LINEFEED || c == CARRIAGE_RETURN) {
if (c == CARRIAGE_RETURN && stream.peek() == LINEFEED) {
stream.read(); // <= skip the trailing \n in case of \r\n termination
+ this.lineTerminatorLength = 2;
+ }
+ else {
@yfarjoun

yfarjoun Apr 5, 2017

Contributor

I detect an extra \n here :-)

@tfenne

tfenne Apr 5, 2017

Owner

How meta ;) In all seriousness though I thought putting the else onto the next line was user-choice in htsjdk & picard. Certainly the rule used to be the opposite (always put it on a new line).

@yfarjoun

yfarjoun Apr 5, 2017

Contributor

I don't know about "used to be" I was trained by @nh13 to always have } else { I'm not super picky, but I thought it appropriate due to the subject matter.

@tfenne

tfenne Apr 5, 2017

Owner

Since I've been around since the inception of htsjdk, I'm pretty sure I know about "used to be" 😛

codecov-io commented Apr 5, 2017 edited

Codecov Report

Merging #843 into master will increase coverage by 0.015%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##              master      #843       +/-   ##
===============================================
+ Coverage     64.916%   64.931%   +0.015%     
- Complexity      7200      7204        +4     
===============================================
  Files            527       527               
  Lines          31784     31789        +5     
  Branches        5425      5425               
===============================================
+ Hits           20633     20641        +8     
+ Misses          9016      9015        -1     
+ Partials        2135      2133        -2
Impacted Files Coverage Δ Complexity Δ
...n/java/htsjdk/tribble/readers/AsciiLineReader.java 42.105% <100%> (+8.302%) 14 <2> (+4) ⬆️
...samtools/util/AsyncBlockCompressedInputStream.java 72% <0%> (-4%) 12% <0%> (-1%)
...a/htsjdk/samtools/cram/encoding/rans/Decoding.java 82.143% <0%> (-3.571%) 11% <0%> (-1%)
...dk/samtools/seekablestream/SeekableHTTPStream.java 54.545% <0%> (-1.515%) 9% <0%> (-1%)
...main/java/htsjdk/samtools/SAMRecordSetBuilder.java 89.113% <0%> (+0.806%) 64% <0%> (+2%) ⬆️
...sjdk/samtools/util/Md5CalculatingOutputStream.java 79.487% <0%> (+7.692%) 9% <0%> (+1%) ⬆️
+
+ @Test public void voidTestLineEndingLength() throws Exception {
+ final String input = "Hello\nThis\rIs A Silly Test\r\nSo There";
+ final InputStream is = new ByteArrayInputStream(input.getBytes());
@yfarjoun

yfarjoun Apr 5, 2017

Contributor

What should happen if there's a stray carriage return with no linefeed? Could you add that to the test?

@yfarjoun

yfarjoun Apr 5, 2017

Contributor

also, I don't know what happens with the wrong order \n\r but it should be tested...

@tfenne

tfenne Apr 5, 2017

Owner

Seriously? Valid line endings in use today are CR, LF, CR+LF. AsciiLineReader specifically looks for those three endings for lines. The test already covers all three valid line ending (a solo CR, a solo LF and a CR+LF).

If they are in the wrong order, they will be treated as multiple lines (existing behaviour). I.e. foo\n\r would be tokenized as <foo><eol><empty><eol>.

@yfarjoun

yfarjoun Apr 5, 2017

Contributor

I'm not asking to modify the valid line-endings...I just want the tests to be explicit about it.

So the test will show an empty line and the correct size of line ending.

@nh13

nh13 Apr 5, 2017

Contributor

I don't think this test is necessary.

@@ -49,4 +41,20 @@ public void testReadLines() throws Exception {
assertEquals(expectedNumber, actualLines);
}
+
+ @Test public void voidTestLineEndingLength() throws Exception {
+ final String input = "Hello\nThis\rIs A Silly Test\r\nSo There";
@magicDGS

magicDGS Apr 5, 2017

Contributor

I think that will be nice to have also the ' \r\n' at the end for testing.

@tfenne

tfenne Apr 5, 2017

Owner

Good point, added.

Contributor

magicDGS commented Apr 5, 2017

Great @tfenne! This is perfect for the .fai index. Thank you!

Contributor

magicDGS commented Apr 7, 2017

Could this be merged for using it for the fai creator? Thanks in advance! :)

Contributor

yfarjoun commented Apr 7, 2017

👍 ...I'll add the test I want myself :-p

Contributor

yfarjoun commented Apr 16, 2017

needs a rebase..sorry.

yfarjoun was assigned by droazen Apr 18, 2017

@tfenne tfenne Added the ability to query the length of the line terminator to Ascii…
…LineReader.
14dd748
Owner

tfenne commented Apr 18, 2017

@yfarjoun Rebased and squashed. Ok to merge once the tests pass?

Contributor

yfarjoun commented Apr 18, 2017

💯

@tfenne tfenne merged commit da2b76b into master Apr 18, 2017

4 of 5 checks passed

codecov/changes 3 files have unexpected coverage changes not visible in diff.
Details
codecov/patch 100% of diff hit (target 64.916%)
Details
codecov/project 64.931% (+0.015%) compared to 78da175
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

tfenne deleted the tf_expose_line_terminator_length branch Apr 18, 2017

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