use of htsjdk.variant.vcf.VCFCodec in project jvarkit by lindenb.
the class KnimeVariantHelper method indexVcfFile.
/**
* index a vcf file is needed
*/
public void indexVcfFile(final File file) throws IOException {
IOUtil.assertFileIsReadable(file);
if (file.getName().endsWith(".vcf.gz")) {
LOG.info("writing tabix index for " + file);
final File output = new File(file.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION);
try {
if (output.exists()) {
getLogger().info("Tabix index " + output + " already exists.");
return;
}
final TabixIndex index = IndexFactory.createTabixIndex(file, new VCFCodec(), (SAMSequenceDictionary) null);
index.write(output);
} catch (final Exception err) {
LOG.error(err);
throw new IOException(err);
}
} else if (file.getName().endsWith(".vcf")) {
LOG.info("writing tribble index for " + file);
final File output = new File(file.getAbsolutePath() + Tribble.STANDARD_INDEX_EXTENSION);
try {
if (output.exists()) {
getLogger().info("Tribble index " + output + " already exists.");
}
final Index index = IndexFactory.createIndex(file, new VCFCodec(), IndexType.LINEAR);
index.writeBasedOnFeatureFile(file);
} catch (final Exception err) {
LOG.error(err);
throw new IOException(err);
}
} else {
throw new IOException("Cannot index VCF file " + file);
}
}
Aggregations