adding code to detect out-of-date index files, which we now remove and regenerate if the target file is newer than the index file.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3303 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
a68f3b2e9c
commit
c998c48a23
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
package org.broadinstitute.sting.gatk.refdata.tracks.builders;
|
package org.broadinstitute.sting.gatk.refdata.tracks.builders;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.broad.tribble.Feature;
|
import org.broad.tribble.Feature;
|
||||||
import org.broad.tribble.FeatureCodec;
|
import org.broad.tribble.FeatureCodec;
|
||||||
import org.broad.tribble.FeatureReader;
|
import org.broad.tribble.FeatureReader;
|
||||||
|
|
@ -53,6 +54,11 @@ import java.util.Map;
|
||||||
* that gets iterators from the FeatureReader using Tribble.
|
* that gets iterators from the FeatureReader using Tribble.
|
||||||
*/
|
*/
|
||||||
public class TribbleRMDTrackBuilder extends PluginManager<FeatureCodec> implements RMDTrackBuilder {
|
public class TribbleRMDTrackBuilder extends PluginManager<FeatureCodec> implements RMDTrackBuilder {
|
||||||
|
/**
|
||||||
|
* our log, which we want to capture anything from this class
|
||||||
|
*/
|
||||||
|
private static Logger logger = Logger.getLogger(TribbleRMDTrackBuilder.class);
|
||||||
|
|
||||||
|
|
||||||
// the linear index extension
|
// the linear index extension
|
||||||
private static final String linearIndexExtension = ".idx";
|
private static final String linearIndexExtension = ".idx";
|
||||||
|
|
@ -88,7 +94,8 @@ public class TribbleRMDTrackBuilder extends PluginManager<FeatureCodec> implemen
|
||||||
FeatureReader reader;
|
FeatureReader reader;
|
||||||
try {
|
try {
|
||||||
// check to see if the input file has an index
|
// check to see if the input file has an index
|
||||||
if (!(new File(inputFile.getAbsolutePath() + linearIndexExtension).canRead())) {
|
if (requireIndex(inputFile)) {
|
||||||
|
logger.warn("Creating Tribble Index for file " + inputFile);
|
||||||
LinearIndex index = createIndex(inputFile, this.createByType(targetClass));
|
LinearIndex index = createIndex(inputFile, this.createByType(targetClass));
|
||||||
reader = new FeatureReader(inputFile,index, this.createByType(targetClass));
|
reader = new FeatureReader(inputFile,index, this.createByType(targetClass));
|
||||||
}
|
}
|
||||||
|
|
@ -115,6 +122,26 @@ public class TribbleRMDTrackBuilder extends PluginManager<FeatureCodec> implemen
|
||||||
LinearIndexCreator create = new LinearIndexCreator(inputFile, codec);
|
LinearIndexCreator create = new LinearIndexCreator(inputFile, codec);
|
||||||
return create.createIndex();
|
return create.createIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this function checks if we need to make an index file. There are three cases:
|
||||||
|
* 1. The index file doesn't exist; return true
|
||||||
|
* 2. The index does exist, but is older than the file. We delete the index and return true
|
||||||
|
* 3. else return false;
|
||||||
|
* @param inputFile the target file to make an index for
|
||||||
|
* @return true if we need to create an index, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean requireIndex(File inputFile) {
|
||||||
|
// can we read the index? if not, create an index
|
||||||
|
File indexFile = new File(inputFile.getAbsolutePath() + linearIndexExtension);
|
||||||
|
if (!(indexFile.canRead())) return true;
|
||||||
|
if (inputFile.lastModified() > indexFile.lastModified()) {
|
||||||
|
logger.warn("Removing out of date (index file date older than target file ) index file " + indexFile);
|
||||||
|
indexFile.delete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue