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

Clarified behavior of MarkDuplicatesSpark when given multiple input bams #5901

Merged
merged 2 commits into from
Apr 24, 2019

Conversation

jamesemery
Copy link
Collaborator

Also improved the sorting behavior if given a mix of queryname sorted and query-grouped bams.

@bhanugandham

@jamesemery
Copy link
Collaborator Author

This also raises another question. There is no particularly strong reason to restrict multi-bam mode to inputs of a particular sort order. We could happily treat multiple arbitrarily unsorted inputs as just that and sort them as the first step. Perhaps thats better than restricting them all to only work at all in the best case? Let me know your thoughts @droazen.

@codecov-io
Copy link

codecov-io commented Apr 23, 2019

Codecov Report

Merging #5901 into master will increase coverage by 0.003%.
The diff coverage is 100%.

@@              Coverage Diff               @@
##              master    #5901       +/-   ##
==============================================
+ Coverage     86.838%   86.84%   +0.003%     
- Complexity     32325    32327        +2     
==============================================
  Files           1991     1991               
  Lines         149341   149347        +6     
  Branches       16483    16482        -1     
==============================================
+ Hits          129684   129693        +9     
+ Misses         13647    13646        -1     
+ Partials        6010     6008        -2
Impacted Files Coverage Δ Complexity Δ
...stitute/hellbender/engine/spark/GATKSparkTool.java 82.778% <100%> (+0.91%) 78 <2> (+1) ⬆️
.../pipelines/MarkDuplicatesSparkIntegrationTest.java 91.367% <100%> (+0.223%) 42 <0> (ø) ⬇️
...transforms/markduplicates/MarkDuplicatesSpark.java 94.595% <100%> (+0.074%) 36 <6> (ø) ⬇️
...roadinstitute/hellbender/utils/read/ReadUtils.java 80.328% <0%> (+0.234%) 208% <0%> (+1%) ⬆️

@droazen droazen self-assigned this Apr 23, 2019
Copy link
Collaborator

@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.

Minor comments only -- merge after addressing them @jamesemery

@@ -47,6 +47,7 @@
* <li>Due to MarkDuplicatesSpark queryname-sorting coordinate-sorted inputs internally at the start, the tool produces identical results regardless of the input sort-order. That is, it will flag duplicates sets that include secondary, and supplementary and unmapped mate records no matter the sort-order of the input. This differs from how Picard MarkDuplicates behaves given the differently sorted inputs. </li>
* <li>Collecting duplicate metrics slows down performance and thus the metrics collection is optional and must be specified for the Spark version of the tool with '-M'. It is possible to collect the metrics with the standalone Picard tool <a href='https://software.broadinstitute.org/gatk/documentation/tooldocs/current/picard_sam_markduplicates_EstimateLibraryComplexity.php'>EstimateLibraryComplexity</a>.</li>
* <li>MarkDuplicatesSpark is optimized to run locally on a single machine by leveraging core parallelism that MarkDuplicates and SortSam cannot. It will typically run faster than MarkDuplicates and SortSam by a factor of 15% over the same data at 2 cores and will scale linearly to upwards of 16 cores. This means MarkDuplicatesSpark, even without access to a Spark cluster, is faster than MarkDuplicates.</li>
* <li>MarkDuplicatesSpark can be run with multiple input bams. If this is the case all of the inputs must be querygroup ordered or queryname sorted.</li>
Copy link
Collaborator

Choose a reason for hiding this comment

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

So a mix of querygroup-sorted and queryname-sorted inputs is ok? Or do they all have to be querygroup-sorted?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also: briefly explain the difference between the two orderings here (since it's not necessarily widely known).

// Check if we are using multiple inputs that the headers are all in the correct querygrouped ordering
final SAMFileHeader header = getHeaderForReads();

// Check if we are using multiple inputs that the headers are all in the correct querygrouped ordering, if so set the aggregate header to reflect this
Map<String, SAMFileHeader> headerMap = getReadSouceHeaderMap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Souce?

@@ -288,12 +289,15 @@ public int getPartition(Object key) {

@Override
protected void runTool(final JavaSparkContext ctx) {
// Check if we are using multiple inputs that the headers are all in the correct querygrouped ordering
final SAMFileHeader header = getHeaderForReads();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This gets a merged header -- what will the underlying SamFileHeaderMerger do in the case where the sort order does not agree across headers? Will it throw in that case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, rename header to mergedHeader

Map<String, SAMFileHeader> headerMap = getReadSouceHeaderMap();
if (headerMap.size() > 1) {
headerMap.entrySet().stream().forEach(h -> {if(!ReadUtils.isReadNameGroupedBam(h.getValue())) {
throw new UserException("Multiple inputs to MarkDuplicatesSpark detected but input "+h.getKey()+" was sorted in "+h.getValue().getSortOrder()+" order");
throw new UserException("Multiple inputs to MarkDuplicatesSpark detected. MarkDuplicatesSpark requires all inputs be queryname sorted or querygrouped for multi-input processing but input "+h.getKey()+" was sorted in "+h.getValue().getSortOrder()+" order");
Copy link
Collaborator

Choose a reason for hiding this comment

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

be -> to be
querygrouped -> querygroup-sorted

}});
header.setGroupOrder(SAMFileHeader.GroupOrder.query);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't SAMFileHeader.GroupOrder.query correspond to querygrouped ordering? Is it ok to set this here if not all inputs are necessarily querygrouped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Query grouped bams are a superset of queryname sorted bams. So long as all the inputs are querygrouped (and I suppose also that they don't have overlapping readnames...) the inputs are valid.

@droazen droazen assigned jamesemery and unassigned droazen Apr 23, 2019
@jamesemery jamesemery merged commit bd8ad14 into master Apr 24, 2019
@jamesemery jamesemery deleted the je_clarifyMultipleInputBamErrorMessage branch April 24, 2019 14:04
Copy link
Contributor

@bhanugandham bhanugandham left a comment

Choose a reason for hiding this comment

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

This is great! Thank you James.

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.

4 participants