Unified byLoci and byLociByInterval traversals. It now figures out what to do for you based on the presence of an index and set of required locations to process.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@191 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
c18f8fbf5f
commit
d457778283
|
|
@ -185,10 +185,7 @@ public class GenomeAnalysisTK extends CommandLineProgram {
|
||||||
// Try to get the walker specified
|
// Try to get the walker specified
|
||||||
try {
|
try {
|
||||||
LocusWalker<?, ?> walker = (LocusWalker<?, ?>) my_walker;
|
LocusWalker<?, ?> walker = (LocusWalker<?, ?>) my_walker;
|
||||||
if ( INTERVALS_FILE == null )
|
|
||||||
engine.traverseByLoci(walker);
|
engine.traverseByLoci(walker);
|
||||||
else
|
|
||||||
engine.traverseByLociByInterval(walker);
|
|
||||||
}
|
}
|
||||||
catch (java.lang.ClassCastException e) {
|
catch (java.lang.ClassCastException e) {
|
||||||
// I guess we're a read walker LOL
|
// I guess we're a read walker LOL
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,10 @@ public class TraversalEngine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasLocations() {
|
||||||
|
return this.locs != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true iff we have a specified series of locations to process AND we are past the last
|
* Returns true iff we have a specified series of locations to process AND we are past the last
|
||||||
* location in the list. It means that, in a serial processing of the genome, that we are done.
|
* location in the list. It means that, in a serial processing of the genome, that we are done.
|
||||||
|
|
@ -551,15 +555,33 @@ public class TraversalEngine {
|
||||||
* @return 0 on success
|
* @return 0 on success
|
||||||
*/
|
*/
|
||||||
protected <M, T> int traverseByLoci(LocusWalker<M, T> walker) {
|
protected <M, T> int traverseByLoci(LocusWalker<M, T> walker) {
|
||||||
samReadIter = initializeReads();
|
samReader = initializeSAMFile(readsFile);
|
||||||
|
|
||||||
verifySortOrder(true);
|
verifySortOrder(true);
|
||||||
|
|
||||||
// initialize the walker object
|
// initialize the walker object
|
||||||
walker.initialize();
|
walker.initialize();
|
||||||
|
|
||||||
|
T sum = walker.reduceInit();
|
||||||
|
if ( samReader.hasIndex() && hasLocations() ) {
|
||||||
|
// we are doing interval-based traversals
|
||||||
|
for ( GenomeLoc interval : locs ) {
|
||||||
|
logger.debug(String.format("Processing locus %s", interval.toString()));
|
||||||
|
|
||||||
|
CloseableIterator<SAMRecord> readIter = samReader.queryOverlapping( interval.getContig(),
|
||||||
|
(int)interval.getStart(),
|
||||||
|
(int)interval.getStop() );
|
||||||
|
|
||||||
|
Iterator<SAMRecord> wrappedIter = WrapReadsIterator( readIter, false );
|
||||||
|
sum = carryWalkerOverInterval(walker, wrappedIter, sum, interval);
|
||||||
|
readIter.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
// We aren't locus oriented
|
// We aren't locus oriented
|
||||||
T sum = carryWalkerOverInterval(walker, samReadIter, walker.reduceInit(), null);
|
samReadIter = WrapReadsIterator(getReadsIterator(samReader), true);
|
||||||
|
sum = carryWalkerOverInterval(walker, samReadIter, sum, null);
|
||||||
|
}
|
||||||
|
|
||||||
printOnTraversalDone("loci", sum);
|
printOnTraversalDone("loci", sum);
|
||||||
walker.onTraversalDone();
|
walker.onTraversalDone();
|
||||||
|
|
@ -617,40 +639,6 @@ public class TraversalEngine {
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as the normal locus traverser, but oriented by locus, rather than implicitly
|
|
||||||
*
|
|
||||||
* @param walker A locus walker object
|
|
||||||
* @param <M> MapType -- the result of calling map() on walker
|
|
||||||
* @param <T> ReduceType -- the result of calling reduce() on the walker
|
|
||||||
* @return 0 on success
|
|
||||||
*/
|
|
||||||
protected <M, T> int traverseByLociByInterval(LocusWalker<M, T> walker) {
|
|
||||||
//verifySortOrder(true);
|
|
||||||
|
|
||||||
// initialize the walker object
|
|
||||||
walker.initialize();
|
|
||||||
// Initialize the T sum using the walker
|
|
||||||
T sum = walker.reduceInit();
|
|
||||||
|
|
||||||
samReader = initializeSAMFile(readsFile);
|
|
||||||
for ( GenomeLoc interval : locs ) {
|
|
||||||
logger.debug(String.format("Processing locus %s", interval.toString()));
|
|
||||||
|
|
||||||
CloseableIterator<SAMRecord> readIter = samReader.queryOverlapping( interval.getContig(),
|
|
||||||
(int)interval.getStart(),
|
|
||||||
(int)interval.getStop() );
|
|
||||||
|
|
||||||
Iterator<SAMRecord> wrappedIter = WrapReadsIterator( readIter, false );
|
|
||||||
sum = carryWalkerOverInterval(walker, wrappedIter, sum, interval);
|
|
||||||
readIter.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
printOnTraversalDone("loci", sum);
|
|
||||||
walker.onTraversalDone();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Traverse by read -- the key driver of linearly ordered traversal of reads. Provides a single read to
|
* Traverse by read -- the key driver of linearly ordered traversal of reads. Provides a single read to
|
||||||
* the walker object, in coordinate order. Supports all of the
|
* the walker object, in coordinate order. Supports all of the
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue