- * For now, file type is inferred from its suffix: .gz or .bgz for compressed
- * data, .tbi for an index file, anything else is assumed to be plain text
- * VCF.
+ * If the file path ends in ".tbi" or ".csi", or appending one of these
+ * extensions gives a valid file path, open as indexed, else as unindexed.
*
* @param f
* @throws IOException
*/
public VCFReader(String filePath) throws IOException
{
- if (filePath.endsWith(GZ))
+ indexed = false;
+ if (filePath.endsWith(TBI_EXTENSION)
+ || filePath.endsWith(CSI_EXTENSION))
{
- if (new File(filePath + TBI_EXTENSION).exists())
- {
- indexed = true;
- }
+ indexed = true;
+ filePath = filePath.substring(0, filePath.length() - 4);
}
- else if (filePath.endsWith(TBI_EXTENSION))
+ else if (new File(filePath + TBI_EXTENSION).exists())
+ {
+ indexed = true;
+ }
+ else if (new File(filePath + CSI_EXTENSION).exists())
{
indexed = true;
- filePath = filePath.substring(0, filePath.length() - 4);
}
- reader = new VCFFileReader(new File(filePath), indexed);
+ /*
+ * we pass the name of the unindexed file to htsjdk,
+ * with a flag to assert whether it is indexed
+ */
+ File file = new File(filePath);
+ if (file.exists())
+ {
+ reader = new VCFFileReader(file, indexed);
+ }
+ else
+ {
+ Console.error("File not found: " + filePath);
+ }
}
@Override
@@ -88,9 +125,10 @@ public class VCFReader implements Closeable, Iterable