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

Change SAMTextHeaderCodec to no longer accumulate the entire text of … #1361

Merged
merged 2 commits into from
May 17, 2019

Conversation

tfenne
Copy link
Member

@tfenne tfenne commented May 1, 2019

…the header into memory.

Description

Accumulating the entire text of the header into memory is of questionable value and causes a) performance degradation in the best case and b) outright failure in the worst case. In cases where the header text is longer than 2^31 characters the code fails outright.

The changes made simply no longer accumulate the text. Lines that have errors are recorded as validation errors already. And if the full text is really needed, the user can take a look at their input file!

I've also deprecated the methods for getting and setting the entire header text on SAMFileHeader.

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
Copy link
Member Author

tfenne commented May 1, 2019

@lbergelson, @jacarey, @yfarjoun: would one of you like to take a look at this?

@tfenne tfenne self-assigned this May 1, 2019
@codecov-io
Copy link

codecov-io commented May 1, 2019

Codecov Report

Merging #1361 into master will increase coverage by 0.35%.
The diff coverage is 60%.

@@              Coverage Diff               @@
##              master     #1361      +/-   ##
==============================================
+ Coverage     67.849%   68.199%   +0.35%     
- Complexity      8283      8601     +318     
==============================================
  Files            563       564       +1     
  Lines          33707     34326     +619     
  Branches        5657      5820     +163     
==============================================
+ Hits           22870     23410     +540     
- Misses          8659      8721      +62     
- Partials        2178      2195      +17
Impacted Files Coverage Δ Complexity Δ
src/main/java/htsjdk/samtools/SAMFileHeader.java 66.667% <0%> (-0.775%) 44 <0> (-1)
.../main/java/htsjdk/samtools/SAMTextHeaderCodec.java 81.452% <100%> (-0.044%) 46 <0> (-1)
src/main/java/htsjdk/samtools/BAMFileWriter.java 66.667% <100%> (ø) 17 <0> (ø) ⬇️
...s/cram/encoding/external/ExternalLongEncoding.java 61.538% <0%> (-5.128%) 4% <0%> (+1%)
src/main/java/htsjdk/variant/bcf2/BCFVersion.java 93.103% <0%> (-1.633%) 12% <0%> (+5%)
...dk/samtools/cram/structure/SubstitutionMatrix.java 91.026% <0%> (-0.279%) 30% <0%> (+15%)
...s/cram/encoding/external/ExternalByteEncoding.java 100% <0%> (ø) 10% <0%> (+4%) ⬆️
...ram/encoding/external/ExternalIntegerEncoding.java 100% <0%> (ø) 10% <0%> (+4%) ⬆️
...tools/cram/encoding/external/ExternalEncoding.java 100% <0%> (ø) 2% <0%> (?)
...c/main/java/htsjdk/samtools/util/IntervalList.java 73.913% <0%> (+0.016%) 103% <0%> (+34%) ⬆️
... and 8 more

@tfenne
Copy link
Member Author

tfenne commented May 2, 2019

FWIW I've checked the lastest master of Picard and GATK and neither of them have any accesses to either SAMFileHeader.getTextHeader() or SAMFileHeader.setTextHeader().

@pshapiro4broad
Copy link
Contributor

pshapiro4broad commented May 6, 2019

This looks good, can you also remove the comment that refers to SAMFileHeader.getTextHeader() in BAMFileWriter.writeHeader()?

There is also code in picard ViewSam that will need to be updated to avoid a compile time deprecation warning.

mCurrentLine = mReader.readLine();
textHeader.append(mCurrentLine).append('\n');
return mCurrentLine;
this.mCurrentLine = (nextChar == '@') ? mReader.readLine() : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better if there was a named constant for the magic character/string @.

@yfarjoun
Copy link
Contributor

fixes #1045

@yfarjoun
Copy link
Contributor

@tfenne feel free to merge this!

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.

👍

@tfenne tfenne merged commit 4747d08 into master May 17, 2019
@tfenne tfenne deleted the tf_dont_accumulate_header_text branch May 17, 2019 13:34
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.

5 participants