2009-04-10 04:28:17 +08:00
|
|
|
package org.broadinstitute.sting.gatk.traversals;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
|
|
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
2009-05-16 05:02:12 +08:00
|
|
|
import org.broadinstitute.sting.gatk.walkers.DataSource;
|
2009-04-10 04:28:17 +08:00
|
|
|
import org.broadinstitute.sting.gatk.LocusContext;
|
2009-05-16 05:02:12 +08:00
|
|
|
import org.broadinstitute.sting.gatk.WalkerManager;
|
2009-04-10 04:28:17 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.shards.Shard;
|
2009-05-09 05:27:54 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.ShardDataProvider;
|
2009-05-23 03:12:00 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.AllLocusView;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.CoveredLocusView;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.LocusView;
|
2009-05-22 04:09:32 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.ReferenceOrderedView;
|
2009-05-23 03:12:00 +08:00
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.ReferenceView;
|
|
|
|
|
import org.broadinstitute.sting.gatk.dataSources.providers.LocusReferenceView;
|
2009-04-10 04:28:17 +08:00
|
|
|
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedData;
|
|
|
|
|
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
|
|
|
|
|
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
|
|
|
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
|
|
|
|
import org.broadinstitute.sting.utils.Utils;
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
/**
|
2009-05-23 03:12:00 +08:00
|
|
|
* A simple solution to iterating over all reference positions over a series of genomic locations.
|
2009-04-10 04:28:17 +08:00
|
|
|
*/
|
2009-05-18 09:31:57 +08:00
|
|
|
public class TraverseLoci extends TraversalEngine {
|
2009-04-10 04:28:17 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* our log, which we want to capture anything from this class
|
|
|
|
|
*/
|
|
|
|
|
protected static Logger logger = Logger.getLogger(TraversalEngine.class);
|
|
|
|
|
|
2009-05-18 09:31:57 +08:00
|
|
|
public TraverseLoci(List<File> reads, File ref, List<ReferenceOrderedData<? extends ReferenceOrderedDatum>> rods) {
|
2009-04-10 04:28:17 +08:00
|
|
|
super( reads, ref, rods );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <M,T> T traverse(Walker<M,T> walker, ArrayList<GenomeLoc> locations) {
|
|
|
|
|
if ( locations.isEmpty() )
|
|
|
|
|
Utils.scareUser("Requested all locations be processed without providing locations to be processed!");
|
|
|
|
|
|
2009-05-18 09:31:57 +08:00
|
|
|
throw new UnsupportedOperationException("This traversal type not supported by TraverseLoci");
|
2009-04-10 04:28:17 +08:00
|
|
|
}
|
|
|
|
|
|
2009-05-09 05:27:54 +08:00
|
|
|
@Override
|
2009-04-10 04:28:17 +08:00
|
|
|
public <M,T> T traverse( Walker<M,T> walker,
|
|
|
|
|
Shard shard,
|
2009-05-09 05:27:54 +08:00
|
|
|
ShardDataProvider dataProvider,
|
2009-04-10 04:28:17 +08:00
|
|
|
T sum ) {
|
2009-05-18 09:31:57 +08:00
|
|
|
logger.debug(String.format("TraverseLoci.traverse Genomic interval is %s", shard.getGenomeLoc()));
|
2009-04-10 04:28:17 +08:00
|
|
|
|
|
|
|
|
if ( !(walker instanceof LocusWalker) )
|
|
|
|
|
throw new IllegalArgumentException("Walker isn't a loci walker!");
|
|
|
|
|
|
|
|
|
|
LocusWalker<M, T> locusWalker = (LocusWalker<M, T>)walker;
|
2009-05-14 02:51:16 +08:00
|
|
|
|
2009-05-23 03:12:00 +08:00
|
|
|
LocusView locusView = getLocusView( walker, dataProvider );
|
|
|
|
|
LocusReferenceView referenceView = new LocusReferenceView( dataProvider );
|
2009-05-22 04:09:32 +08:00
|
|
|
ReferenceOrderedView referenceOrderedDataView = new ReferenceOrderedView( dataProvider );
|
2009-05-16 05:02:12 +08:00
|
|
|
|
2009-04-10 04:28:17 +08:00
|
|
|
// We keep processing while the next reference location is within the interval
|
2009-05-23 03:12:00 +08:00
|
|
|
while( locusView.hasNext() ) {
|
|
|
|
|
LocusContext locus = locusView.next();
|
2009-04-10 04:28:17 +08:00
|
|
|
|
|
|
|
|
TraversalStatistics.nRecords++;
|
|
|
|
|
|
|
|
|
|
// Iterate forward to get all reference ordered data covering this locus
|
2009-05-23 03:12:00 +08:00
|
|
|
final RefMetaDataTracker tracker = referenceOrderedDataView.getReferenceOrderedDataAtLocus(locus.getLocation());
|
2009-04-10 04:28:17 +08:00
|
|
|
|
2009-05-23 03:12:00 +08:00
|
|
|
char refBase = referenceView.getReferenceBase(locus.getLocation());
|
2009-04-10 04:28:17 +08:00
|
|
|
|
|
|
|
|
final boolean keepMeP = locusWalker.filter(tracker, refBase, locus);
|
|
|
|
|
if (keepMeP) {
|
|
|
|
|
M x = locusWalker.map(tracker, refBase, locus);
|
|
|
|
|
sum = locusWalker.reduce(x, sum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.maxReads > 0 && TraversalStatistics.nRecords > this.maxReads) {
|
|
|
|
|
logger.warn(String.format("Maximum number of reads encountered, terminating traversal " + TraversalStatistics.nRecords));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printProgress("loci", locus.getLocation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
2009-05-08 22:12:45 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Temporary override of printOnTraversalDone.
|
|
|
|
|
* TODO: Add some sort of TE.getName() function once all TraversalEngines are ported.
|
|
|
|
|
* @param sum Result of the computation.
|
|
|
|
|
* @param <T> Type of the result.
|
|
|
|
|
*/
|
|
|
|
|
public <T> void printOnTraversalDone( T sum ) {
|
|
|
|
|
printOnTraversalDone( "loci", sum );
|
|
|
|
|
}
|
2009-05-23 03:12:00 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the best view of loci for this walker given the available data.
|
|
|
|
|
* @param walker walker to interrogate.
|
|
|
|
|
* @param dataProvider Data which which to drive the locus view.
|
|
|
|
|
*/
|
|
|
|
|
private LocusView getLocusView( Walker walker, ShardDataProvider dataProvider ) {
|
|
|
|
|
DataSource dataSource = WalkerManager.getWalkerDataSource(walker);
|
|
|
|
|
if( dataSource == DataSource.READS )
|
|
|
|
|
return new CoveredLocusView(dataProvider);
|
|
|
|
|
else if( dataSource == DataSource.REFERENCE )
|
|
|
|
|
return new AllLocusView(dataProvider);
|
|
|
|
|
else
|
|
|
|
|
throw new UnsupportedOperationException("Unsupported traversal type: " + dataSource);
|
|
|
|
|
}
|
2009-04-25 03:40:21 +08:00
|
|
|
}
|