Skip to content

Get HaplotypeCallerSpark strict mode running on an exome - #5475

Merged
tomwhite merged 3 commits into
masterfrom
tw_strict_assembly_region_walker_spark_hc_exome
Jan 16, 2019
Merged

tomwhite merged 3 commits into
masterfrom
tw_strict_assembly_region_walker_spark_hc_exome

Conversation

@tomwhite

@tomwhite tomwhite commented Dec 3, 2018

Copy link
Copy Markdown
Contributor

This is based on #5416

@tomwhite
tomwhite requested a review from jamesemery December 3, 2018 14:46
@codecov-io

codecov-io commented Dec 3, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5475 into master will increase coverage by 0.07%.
The diff coverage is 84.9%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #5475      +/-   ##
============================================
+ Coverage     87.01%   87.08%   +0.07%     
- Complexity    31251    31533     +282     
============================================
  Files          1919     1930      +11     
  Lines        144355   145262     +907     
  Branches      15961    16095     +134     
============================================
+ Hits         125607   126505     +898     
+ Misses        12969    12903      -66     
- Partials       5779     5854      +75
Impacted Files Coverage Δ Complexity Δ
.../hellbender/engine/spark/SparkSharderUnitTest.java 93.89% <100%> (+0.04%) 8 <0> (ø) ⬇️
...lbender/engine/spark/FindAssemblyRegionsSpark.java 85.24% <100%> (-0.47%) 21 <0> (ø)
...nstitute/hellbender/engine/spark/SparkSharder.java 88.04% <84.31%> (-2.75%) 36 <10> (+8)
...der/tools/walkers/annotator/OriginalAlignment.java 84.21% <0%> (-15.79%) 7% <0%> (-3%)
...hellbender/utils/runtime/RuntimeUtilsUnitTest.java 87.5% <0%> (-12.5%) 4% <0%> (+1%)
...s/haplotypecaller/graphs/LowWeightChainPruner.java 83.33% <0%> (-12.23%) 5% <0%> (-15%)
...r/arguments/CopyNumberArgumentValidationUtils.java 66.66% <0%> (-11.12%) 19% <0%> (-1%)
...tools/funcotator/DataSourceFuncotationFactory.java 75.92% <0%> (-11.04%) 17% <0%> (ø)
...ools/walkers/haplotypecaller/graphs/SeqVertex.java 92.85% <0%> (-7.15%) 10% <0%> (-1%)
...te/hellbender/tools/funcotator/OutputRenderer.java 92.85% <0%> (-7.15%) 4% <0%> (ø)
... and 170 more

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 1f6a172...623830b. Read the comment docs.

FindAssemblyRegionsSpark can repartition them, rather than collect
them to the driver.

Also ensure repartition results in sorted intervals.

Successfully ran on an exome (24 mins, vs 12 for fast mode)
@tomwhite
tomwhite force-pushed the tw_strict_assembly_region_walker_spark_hc_exome branch from 80c4629 to f011abc Compare December 5, 2018 10:06
@tomwhite

tomwhite commented Dec 5, 2018

Copy link
Copy Markdown
Contributor Author

@jamesemery I've rebased this and added some more javadoc so it's ready for review now.

@jamesemery jamesemery left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mostly some questions but no real issue from me. Generally speaking it sounds like this works because you flipped the partitioning from collecting the very large number of intervals for the assembly regions to instead collecting the intervals for the reads rdd which is a much more controlled number. I think this raises the question again of whether we should reduce the num-partitions for reads to make that number smaller yet.

* @param maxLocatableLength the maximum length of a {@link Locatable}, if any is larger than this size then an exception will be thrown
* @param <L> the {@link Locatable} type
* @param <SB> the {@link ShardBoundary} type
* @return an RDD of {@link Shard} of overlapping {@link Locatable} objects (including overlapping only padding)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In the interest of excessive nit-picking, the maxLocatableLenght and useShuffle doesn't seem to be in the java docs for any of these overrides...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I couldn't see what was missing here. Both maxLocatableLength and useShuffle have @param descriptions in all the public methods.


JavaRDD<ShardBoundary> paddedIntervals = intervals.map(ShardBoundary::paddedShardBoundary);
if (useShuffle) {
throw new UnsupportedOperationException();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This exception should have a description

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

int lastPartitionStartIndex = 0;
for (I interval : intervals) {
int[] partitionIndexes = overlapDetector.getOverlaps(interval).stream()
Broadcast<OverlapDetector<PartitionLocatable<SimpleInterval>>> overlapDetectorBroadcast = ctx.broadcast(overlapDetector);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Considering that we are now broadcasting this value on a per-partition basis perhaps it would be a good idea to reevaluate the default partition size we use for reads in the gatk, as that might cut down on some of the time spent in these sorts of operations.

int maxLocatableLength, FlatMapFunction2<Iterator<L>, Iterator<I>, T> f) {

List<PartitionLocatable<SimpleInterval>> partitionReadExtents = computePartitionReadExtents(locatables, sequenceDictionary, maxLocatableLength);
List<SimpleInterval> firstLocatables = partitionReadExtents.stream().map(PartitionLocatable::getLocatable).collect(Collectors.toList());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is this not broadcasted here? it looks like it is used inside of the RDD operations so it would effectively be passed in for every interval in intervals which doesn't sound desirable. (though I suspect it is smarter than that)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's probably better to broadcast here. I've updated the code to do this.

}
Arrays.sort(partitionIndexes);
int startIndex = partitionIndexes[0];
int endIndex = partitionIndexes[partitionIndexes.length - 1];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we always expect it to hold that a partitioning of the reads will necessarily be in order based on the start? One could imagine pathological cases where a very tall pileup at a given start position (perhaps with some very long reads as part of it) would cause us to split the partition so there may be another partition that starts after the start of this partition but ends before the end of this partition.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unless this is by the start position... in which case we should better document that in computePartitionReadExetents()...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's by start position. Added a comment.

.repartitionAndSortWithinPartitions(new PartitionLocatablePartitioner(locatables.getNumPartitions()), new PartitionLocatableComparator<I>(sequenceDictionary))
.keys();

indexedIntervalsRepartitioned.cache(); // cache since we need to do two calculations on the intervals

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are you sure that ends up being faster? When we were doing mark duplicates work we found that caching ended up costing significantly more than just doing the entire tools work twice (regardless of which cache we used). This is probably a reasonable use of it however...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was faster when I was doing some test runs on exome data.


indexedIntervalsRepartitioned.cache(); // cache since we need to do two calculations on the intervals

Map<Integer, Integer> maxEndPartitionIndexesMap = indexedIntervalsRepartitioned.mapToPair((PairFunction<PartitionLocatable<I>, Integer, Integer>) partitionLocatable ->

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this method generally should have some line comments in it to help readability

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@tomwhite

Copy link
Copy Markdown
Contributor Author

Thanks for the review @jamesemery. Reducing the number of partitions means that each task has to process more data, which has caused out of memory issues in the past. Might be worth revisiting though since the HaplotypeCaller now uses a lot less memory.

@jonn-smith jonn-smith left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I had one question and a very minor comment.

Maybe revisiting the default partition size is a good idea... I wonder if anything will similarly need to be strengthened / improved for running on whole genome data...

if (i >= 0) {
throw new IllegalStateException(); // TODO: no overlaps, yet start of interval matches a partition read extent start
}
int insertionPoint = -i - 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since Collections.binarySearch returns (-<insertion point>)-1 do you really need to subtract one here again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is correct. If the return value is i, then -i - 1 gives the insertion point, since

-i - 1 = -((-<insertion point>)-1) - 1
       = <insertion point>

E.g. if i is -5 then the insertion point is 4. If it's -1 then the insertion point is 0.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah. That makes sense. Just wanted to double-check.


/**
* Compares {@link PartitionLocatable} objects using a {@link htsjdk.samtools.SAMSequenceDictionary} sequence ordering.
* @param <L> he interval type

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing t

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@jonn-smith jonn-smith left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This now looks good to merge to me.

@tomwhite
tomwhite merged commit 68e2401 into master Jan 16, 2019
@tomwhite

Copy link
Copy Markdown
Contributor Author

Thanks @jonn-smith

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