2009-03-27 23:40:45 +08:00
|
|
|
package org.broadinstitute.sting.gatk.executive;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
2009-04-10 04:28:17 +08:00
|
|
|
import org.broadinstitute.sting.utils.FastaSequenceFile2;
|
|
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
|
|
|
|
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.shards.ShardStrategy;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.shards.ShardStrategyFactory;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.shards.Shard;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.simpleDataSources.SAMBAMDataSource;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.simpleDataSources.SimpleDataSourceLoadException;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.LocusContextProvider;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.ReferenceProvider;
|
|
|
|
|
import org.broadinstitute.sting.gatk.iterators.ReferenceIterator;
|
|
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraverseLociByReference;
|
|
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraversalEngine;
|
|
|
|
|
|
|
|
|
|
import net.sf.samtools.SAMRecord;
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
2009-03-27 23:40:45 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A micro-scheduling manager for N-way threaded execution of a traversal
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class MicroManager {
|
2009-04-10 04:28:17 +08:00
|
|
|
private static long SHARD_SIZE = 5L;
|
|
|
|
|
|
|
|
|
|
private File reads;
|
|
|
|
|
private FastaSequenceFile2 ref;
|
|
|
|
|
|
|
|
|
|
private TraverseLociByReference traversalEngine = null;
|
2009-03-27 23:40:45 +08:00
|
|
|
|
2009-04-10 04:28:17 +08:00
|
|
|
protected static Logger logger = Logger.getLogger(MicroManager.class);
|
|
|
|
|
|
|
|
|
|
public TraversalEngine getTraversalEngine() {
|
|
|
|
|
return traversalEngine;
|
2009-03-27 23:40:45 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-10 04:28:17 +08:00
|
|
|
public MicroManager( File reads, // the reads file
|
|
|
|
|
File refFile, // the reference file driving the traversal
|
|
|
|
|
int nThreadsToUse ) { // maximum number of threads to use to do the work
|
|
|
|
|
|
|
|
|
|
this.reads = reads;
|
|
|
|
|
ref = new FastaSequenceFile2(refFile);
|
|
|
|
|
GenomeLoc.setupRefContigOrdering(ref);
|
2009-03-27 23:40:45 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
public void execute( Walker walker, // the analysis technique to use.
|
|
|
|
|
List<GenomeLoc> locations ) { // list of work to do
|
2009-04-11 06:09:01 +08:00
|
|
|
ShardStrategy shardStrategy = null;
|
|
|
|
|
if( locations != null )
|
|
|
|
|
shardStrategy = ShardStrategyFactory.shatter( ShardStrategyFactory.SHATTER_STRATEGY.LINEAR,
|
|
|
|
|
ref.getSequenceDictionary(),
|
|
|
|
|
SHARD_SIZE,
|
|
|
|
|
locations );
|
|
|
|
|
else
|
|
|
|
|
shardStrategy = ShardStrategyFactory.shatter( ShardStrategyFactory.SHATTER_STRATEGY.LINEAR,
|
|
|
|
|
ref.getSequenceDictionary(),
|
|
|
|
|
SHARD_SIZE );
|
|
|
|
|
|
2009-04-11 04:50:28 +08:00
|
|
|
ReferenceIterator refIter = new ReferenceIterator(ref);
|
2009-04-11 06:09:01 +08:00
|
|
|
SAMBAMDataSource dataSource = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
dataSource = new SAMBAMDataSource( Arrays.asList( new String[] { reads.getCanonicalPath() } ) );
|
|
|
|
|
}
|
|
|
|
|
catch( SimpleDataSourceLoadException ex ) {
|
|
|
|
|
throw new RuntimeException( ex );
|
|
|
|
|
}
|
|
|
|
|
catch( IOException ex ) {
|
|
|
|
|
throw new RuntimeException( ex );
|
|
|
|
|
}
|
2009-04-11 04:50:28 +08:00
|
|
|
|
2009-04-10 04:28:17 +08:00
|
|
|
Object accumulator = ((LocusWalker<?,?>)walker).reduceInit();
|
|
|
|
|
|
|
|
|
|
for(Shard shard: shardStrategy) {
|
|
|
|
|
Iterator<SAMRecord> readShard = null;
|
|
|
|
|
try {
|
|
|
|
|
readShard = dataSource.seek( shard.getGenomeLoc() );
|
|
|
|
|
}
|
|
|
|
|
catch( SimpleDataSourceLoadException ex ) {
|
|
|
|
|
throw new RuntimeException( ex );
|
|
|
|
|
}
|
2009-04-11 06:09:01 +08:00
|
|
|
|
2009-04-11 04:50:28 +08:00
|
|
|
ReferenceProvider referenceProvider = new ReferenceProvider( refIter );
|
2009-04-10 04:28:17 +08:00
|
|
|
LocusContextProvider locusProvider = new LocusContextProvider( readShard );
|
|
|
|
|
|
|
|
|
|
accumulator = traversalEngine.traverse( walker, shard, referenceProvider, locusProvider, accumulator );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
traversalEngine.printOnTraversalDone("loci", accumulator);
|
|
|
|
|
walker.onTraversalDone(accumulator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-27 23:40:45 +08:00
|
|
|
}
|