-
Notifications
You must be signed in to change notification settings - Fork 589
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
FlowFeatureMapper speed improvements #8982
Draft
dror27
wants to merge
14
commits into
broadinstitute:master
Choose a base branch
from
Ultimagen:optimize-ffm-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9643092
--no-edit-distance added to FlowFeatureMap
dror27 d961443
--use-mapper-thread added
dror27 57b52d7
--threaded-walker refactoring
dror27 6642c68
--threaded-writer added
dror27 8e2e686
--nm-edit-distance added
dror27 62089a7
--no-edit-distance is back
dror27 a014717
calc score on shorter flow reads
dror27 b4a8884
make CachingIndexedFastaSequenceFile.java thread safe + allow to incr…
dror27 2f77208
handle thread exceptions - make program exit
dror27 2cae74b
FlowFeatureMapperIntegrationTest passed
dror27 2adab1f
NM edit distance now default
dror27 12e8e06
--no-edit-distance removed
dror27 75deee8
featrure snapping haplotype/read creation cleanup
dror27 511565d
further refactoring
dror27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
209 changes: 183 additions & 26 deletions
209
...in/java/org/broadinstitute/hellbender/tools/walkers/featuremapping/FlowFeatureMapper.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...n/java/org/broadinstitute/hellbender/tools/walkers/featuremapping/ThreadedReadWalker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.broadinstitute.hellbender.tools.walkers.featuremapping; | ||
|
||
import org.broadinstitute.barclay.argparser.Argument; | ||
import org.broadinstitute.hellbender.engine.FeatureContext; | ||
import org.broadinstitute.hellbender.engine.ReadWalker; | ||
import org.broadinstitute.hellbender.engine.ReferenceContext; | ||
import org.broadinstitute.hellbender.exceptions.GATKException; | ||
import org.broadinstitute.hellbender.utils.read.GATKRead; | ||
|
||
import java.util.concurrent.LinkedBlockingQueue; | ||
|
||
public abstract class ThreadedReadWalker extends ReadWalker implements Runnable { | ||
|
||
public static final int CAPACITY = 5000; | ||
|
||
// apply() message and queue - carrying read/referenceContext tuples | ||
static class ApplyMessage { | ||
GATKRead read; | ||
ReferenceContext referenceContext; | ||
FeatureContext featureContext; | ||
} | ||
|
||
private LinkedBlockingQueue<ApplyMessage> applyQueue; | ||
private Thread worker; | ||
|
||
/** | ||
* turn threaded walker on | ||
**/ | ||
@Argument(fullName = "threaded-walker", doc = "turn threaded walker on?", optional = true) | ||
public boolean threadedWalker = false; | ||
|
||
|
||
@Override | ||
public void onTraversalStart() { | ||
|
||
// if running in threaded mode, start worker thread | ||
if ( threadedWalker ) { | ||
applyQueue = new LinkedBlockingQueue<>(CAPACITY); | ||
worker = new Thread(this); | ||
worker.setUncaughtExceptionHandler(getUncaughtExceptionHandler()); | ||
worker.start(); | ||
} | ||
} | ||
|
||
@Override | ||
public void closeTool() { | ||
|
||
// if running in threaded mode, signal end of input and wait for thread to complete | ||
if ( threadedWalker ) { | ||
try { | ||
applyQueue.put(new ApplyMessage()); | ||
worker.join(); | ||
} catch (InterruptedException e) { | ||
throw new GATKException("", e ); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
final public void apply(final GATKRead read, final ReferenceContext referenceContext, final FeatureContext featureContext) { | ||
|
||
if ( !acceptRead(read, referenceContext, featureContext) ) { | ||
return; | ||
} | ||
|
||
if ( threadedWalker ) { | ||
// redirect message into queue | ||
ApplyMessage message = new ApplyMessage(); | ||
message.read = read; | ||
message.referenceContext = referenceContext; | ||
message.featureContext = featureContext; | ||
try { | ||
applyQueue.put(message); | ||
} catch (InterruptedException e) { | ||
throw new GATKException("", e); | ||
} | ||
} else { | ||
applyPossiblyThreaded(read, referenceContext, featureContext); | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
|
||
// loop on messages | ||
ApplyMessage message; | ||
while ( true ) { | ||
// take next message off the queue | ||
try { | ||
message = applyQueue.take(); | ||
} catch (InterruptedException e) { | ||
throw new GATKException("", e); | ||
} | ||
|
||
// end of stream? | ||
if ( message.read == null ) { | ||
break; | ||
} | ||
|
||
// process message | ||
applyPossiblyThreaded(message.read, message.referenceContext, message.featureContext); | ||
} | ||
} | ||
|
||
public abstract boolean acceptRead(GATKRead read, ReferenceContext referenceContext, FeatureContext featureContext); | ||
public abstract void applyPossiblyThreaded(final GATKRead read, final ReferenceContext referenceContext, final FeatureContext featureContext); | ||
|
||
public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() { | ||
Thread.UncaughtExceptionHandler handler = (th, ex) -> { | ||
System.out.println("Uncaught exception: " + ex); | ||
ex.printStackTrace(System.out); | ||
System.exit(-1); | ||
}; | ||
return handler; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine that these changes are going to raise some questions. Can you please add description in the PR? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/test/resources/large/featureMapping/snv_feature_mapper_input.cram
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
src/test/resources/large/featureMapping/snv_feature_mapper_input.cram.crai
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
src/test/resources/large/featureMapping/snv_feature_mapper_nm_edit_disance_output.vcf
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
src/test/resources/large/featureMapping/snv_feature_mapper_nm_edit_disance_output.vcf.idx
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
src/test/resources/large/featureMapping/snv_feature_mapper_no_edit_disance_output.vcf
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
src/test/resources/large/featureMapping/snv_feature_mapper_no_edit_disance_output.vcf.idx
Git LFS file not shown
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed