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-04-10 04:28:17 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.simpleDataSources.SimpleDataSourceLoadException;
|
2009-04-16 02:29:38 +08:00
|
|
|
import org.broadinstitute.sting.gatk.iterators.MergingSamRecordIterator2;
|
2009-04-10 04:28:17 +08:00
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraversalEngine;
|
2009-04-16 02:29:38 +08:00
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraverseLociByReference;
|
|
|
|
|
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
|
|
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
|
|
|
|
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-04-27 07:08:12 +08:00
|
|
|
* A micro-scheduling manager for single-threaded execution of a traversal.
|
2009-03-27 23:40:45 +08:00
|
|
|
*/
|
2009-04-27 01:46:52 +08:00
|
|
|
public class LinearMicroScheduler extends MicroScheduler {
|
2009-04-10 04:28:17 +08:00
|
|
|
|
|
|
|
|
private TraverseLociByReference traversalEngine = null;
|
2009-03-27 23:40:45 +08:00
|
|
|
|
2009-04-10 04:28:17 +08:00
|
|
|
public TraversalEngine getTraversalEngine() {
|
|
|
|
|
return traversalEngine;
|
2009-03-27 23:40:45 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-27 07:08:12 +08:00
|
|
|
/**
|
|
|
|
|
* Create a new linear microscheduler to process the given reads and reference.
|
|
|
|
|
* @param reads Reads file(s) to process.
|
|
|
|
|
* @param refFile Reference for driving the traversal.
|
|
|
|
|
*/
|
|
|
|
|
protected LinearMicroScheduler( List<File> reads, File refFile ) {
|
2009-04-27 01:42:00 +08:00
|
|
|
super( reads, refFile );
|
2009-04-10 04:28:17 +08:00
|
|
|
traversalEngine = new TraverseLociByReference( reads, refFile, new java.util.ArrayList() );
|
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.
|
|
|
|
|
* @param walker Computation to perform over dataset.
|
|
|
|
|
* @param locations Subset of the dataset over which to walk.
|
|
|
|
|
*/
|
|
|
|
|
public void execute( Walker walker, List<GenomeLoc> locations ) {
|
2009-04-27 01:42:00 +08:00
|
|
|
ShardStrategy shardStrategy = getShardStrategy( reference, locations );
|
|
|
|
|
SAMDataSource dataSource = getReadsDataSource();
|
2009-04-11 04:50:28 +08:00
|
|
|
|
2009-04-24 05:07:11 +08:00
|
|
|
boolean walkerInitialized = false;
|
|
|
|
|
Object accumulator = null;
|
2009-04-10 04:28:17 +08:00
|
|
|
|
|
|
|
|
for(Shard shard: shardStrategy) {
|
2009-04-25 03:40:21 +08:00
|
|
|
|
2009-04-16 02:29:38 +08:00
|
|
|
MergingSamRecordIterator2 readShard = null;
|
2009-04-10 04:28:17 +08:00
|
|
|
try {
|
2009-05-01 04:35:56 +08:00
|
|
|
readShard = (MergingSamRecordIterator2)dataSource.seek( shard );
|
2009-04-10 04:28:17 +08:00
|
|
|
}
|
|
|
|
|
catch( SimpleDataSourceLoadException ex ) {
|
|
|
|
|
throw new RuntimeException( ex );
|
|
|
|
|
}
|
2009-04-11 06:09:01 +08:00
|
|
|
|
2009-05-01 04:35:56 +08:00
|
|
|
ReferenceProvider referenceProvider = new ReferenceProvider( reference, shard.getGenomeLoc() );
|
2009-04-10 04:28:17 +08:00
|
|
|
LocusContextProvider locusProvider = new LocusContextProvider( readShard );
|
|
|
|
|
|
2009-04-24 04:34:52 +08:00
|
|
|
// set the sam header of the traversal engine
|
|
|
|
|
traversalEngine.setSAMHeader(readShard.getMergedHeader());
|
2009-04-24 05:07:11 +08:00
|
|
|
|
|
|
|
|
if (!walkerInitialized) {
|
|
|
|
|
walker.initialize();
|
|
|
|
|
accumulator = ((LocusWalker<?,?>)walker).reduceInit();
|
|
|
|
|
walkerInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-10 04:28:17 +08:00
|
|
|
accumulator = traversalEngine.traverse( walker, shard, referenceProvider, locusProvider, accumulator );
|
2009-04-16 02:29:38 +08:00
|
|
|
readShard.close();
|
2009-04-10 04:28:17 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-16 02:29:38 +08:00
|
|
|
traversalEngine.printOnTraversalDone("loci", accumulator);
|
|
|
|
|
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
|
|
|
}
|