From f3e2aae570b9d0df16d34051ac8cd3d8c9867090 Mon Sep 17 00:00:00 2001 From: aaron Date: Tue, 25 May 2010 04:44:46 +0000 Subject: [PATCH] add experimental support for tabix files (for any of our Tribble rod types), as long as they end in .gz and can be read by the tabix reader. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3429 348d0f76-0448-11de-a6fe-93d51630548a --- .../builders/TribbleRMDTrackBuilder.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java index ceb4aed07..8dd4bfab7 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java @@ -105,6 +105,40 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen */ public FeatureReader createFeatureReader(Class targetClass, File inputFile) { FeatureReader reader = null; + if (inputFile.getAbsolutePath().endsWith(".gz")) + reader = createBasicFeatureReaderNoAssumedIndex(targetClass, inputFile); + else + reader = getLinearFeatureReader(targetClass, inputFile); + return reader; + } + + /** + * create a feature reader, without assuming there exists an index. This code assumes the feature + * reader of the appropriate type will figure out what the right index type is, and determine if it + * exists. + * + * @param targetClass the codec class type + * @param inputFile the file to load + * @return a feature reader implementation + */ + private BasicFeatureReader createBasicFeatureReaderNoAssumedIndex(Class targetClass, File inputFile) { + // we might not know the index type, try loading with the default reader constructor + logger.debug("Attempting to blindly load " + inputFile); + try { + return new BasicFeatureReader(inputFile.getAbsolutePath(),this.createByType(targetClass)); + } catch (IOException e) { + throw new StingException("Unable to create feature reader from file " + inputFile); + } + } + + /** + * create a linear feature reader, where we create the index ahead of time + * @param targetClass the target class + * @param inputFile the tribble file to parse + * @return the input file as a FeatureReader + */ + private FeatureReader getLinearFeatureReader(Class targetClass, File inputFile) { + FeatureReader reader; try { Index index = loadIndex(inputFile, this.createByType(targetClass), true); reader = new BasicFeatureReader(inputFile.getAbsolutePath(), index, this.createByType(targetClass));