2009-03-27 23:40:45 +08:00
|
|
|
package org.broadinstitute.sting.gatk.executive;
|
|
|
|
|
|
2009-04-16 02:29:38 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.LocusContextProvider;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.ReferenceProvider;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.shards.Shard;
|
2009-04-10 04:28:17 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.shards.ShardStrategy;
|
2009-04-15 21:52:56 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.simpleDataSources.SAMDataSource;
|
2009-05-07 05:40:41 +08:00
|
|
|
import org.broadinstitute.sting.gatk.iterators.StingSAMIterator;
|
2009-05-07 06:36:25 +08:00
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraverseByReads;
|
2009-04-16 02:29:38 +08:00
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraverseLociByReference;
|
2009-05-07 06:36:25 +08:00
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraverseReads;
|
2009-05-07 05:40:41 +08:00
|
|
|
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
|
2009-04-16 02:29:38 +08:00
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
2009-05-07 07:26:21 +08:00
|
|
|
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
|
|
|
|
|
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedData;
|
2009-04-16 02:29:38 +08:00
|
|
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
2009-04-10 04:28:17 +08:00
|
|
|
|
|
|
|
|
import java.io.File;
|
2009-04-16 02:29:38 +08:00
|
|
|
import java.util.List;
|
2009-03-27 23:40:45 +08:00
|
|
|
|
2009-05-07 06:36:25 +08:00
|
|
|
/** A micro-scheduling manager for single-threaded execution of a traversal. */
|
2009-04-27 01:46:52 +08:00
|
|
|
public class LinearMicroScheduler extends MicroScheduler {
|
2009-04-10 04:28:17 +08:00
|
|
|
|
2009-05-07 06:36:25 +08:00
|
|
|
private boolean isAReadWalker = false;
|
|
|
|
|
|
2009-04-27 07:08:12 +08:00
|
|
|
/**
|
|
|
|
|
* Create a new linear microscheduler to process the given reads and reference.
|
2009-05-07 06:36:25 +08:00
|
|
|
*
|
|
|
|
|
* @param reads Reads file(s) to process.
|
2009-04-27 07:08:12 +08:00
|
|
|
* @param refFile Reference for driving the traversal.
|
|
|
|
|
*/
|
2009-05-07 07:26:21 +08:00
|
|
|
protected LinearMicroScheduler(List<File> reads, File refFile, List<ReferenceOrderedData<? extends ReferenceOrderedDatum>> rods, Walker walker) {
|
2009-05-07 06:36:25 +08:00
|
|
|
super(reads, refFile);
|
|
|
|
|
|
|
|
|
|
// determine if we're a read walker: they get a slightly different, but not in any way worse execute methodology. I pinky swear...
|
|
|
|
|
isAReadWalker = (walker instanceof ReadWalker) ? true : false;
|
|
|
|
|
|
|
|
|
|
if (isAReadWalker) {
|
2009-05-07 07:26:21 +08:00
|
|
|
traversalEngine = new TraverseByReads(reads, refFile, rods);
|
2009-05-07 06:36:25 +08:00
|
|
|
} else {
|
2009-05-07 07:26:21 +08:00
|
|
|
traversalEngine = new TraverseLociByReference(reads, refFile, rods);
|
2009-05-07 06:36:25 +08:00
|
|
|
}
|
2009-03-27 23:40:45 +08:00
|
|
|
}
|
2009-04-10 04:28:17 +08:00
|
|
|
|
2009-04-27 07:08:12 +08:00
|
|
|
/**
|
|
|
|
|
* Run this traversal over the specified subsection of the dataset.
|
2009-05-07 06:36:25 +08:00
|
|
|
*
|
|
|
|
|
* @param walker Computation to perform over dataset.
|
2009-04-27 07:08:12 +08:00
|
|
|
* @param locations Subset of the dataset over which to walk.
|
|
|
|
|
*/
|
2009-05-07 06:36:25 +08:00
|
|
|
public void execute(Walker walker, List<GenomeLoc> locations) {
|
|
|
|
|
ShardStrategy shardStrategy = getShardStrategy(reference, locations);
|
2009-04-27 01:42:00 +08:00
|
|
|
SAMDataSource dataSource = getReadsDataSource();
|
2009-04-11 04:50:28 +08:00
|
|
|
|
2009-05-08 08:58:37 +08:00
|
|
|
walker.initialize();
|
2009-05-08 21:46:28 +08:00
|
|
|
Object accumulator = walker.reduceInit();
|
2009-04-10 04:28:17 +08:00
|
|
|
|
2009-05-07 06:36:25 +08:00
|
|
|
for (Shard shard : shardStrategy) {
|
2009-04-25 03:40:21 +08:00
|
|
|
|
2009-05-08 08:58:37 +08:00
|
|
|
StingSAMIterator readShard = dataSource.seek(shard);
|
2009-04-11 06:09:01 +08:00
|
|
|
|
2009-05-08 22:12:45 +08:00
|
|
|
ReferenceProvider referenceProvider = new ReferenceProvider(reference, shard);
|
2009-05-07 06:36:25 +08:00
|
|
|
LocusContextProvider locusProvider = new LocusContextProvider(readShard);
|
2009-04-10 04:28:17 +08:00
|
|
|
|
2009-05-07 06:36:25 +08:00
|
|
|
if (!isAReadWalker) {
|
|
|
|
|
accumulator = ((TraverseLociByReference) traversalEngine).traverse(walker, shard, referenceProvider, locusProvider, accumulator);
|
|
|
|
|
} else {
|
|
|
|
|
accumulator = ((TraverseReads) traversalEngine).traverse(walker, shard, readShard, accumulator);
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-16 02:29:38 +08:00
|
|
|
readShard.close();
|
2009-04-10 04:28:17 +08:00
|
|
|
}
|
|
|
|
|
|
2009-05-08 22:12:45 +08:00
|
|
|
traversalEngine.printOnTraversalDone(accumulator);
|
2009-05-07 06:36:25 +08:00
|
|
|
|
2009-04-16 02:29:38 +08:00
|
|
|
walker.onTraversalDone(accumulator);
|
2009-04-10 04:28:17 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-16 02:29:38 +08:00
|
|
|
|
2009-03-27 23:40:45 +08:00
|
|
|
}
|