use of htsjdk.tribble.index.Index in project gatk by broadinstitute.
the class IndexFeatureFileIntegrationTest method testSAMPileupGZIndex.
@Test
public void testSAMPileupGZIndex() {
// made with bgzip
final File ORIG_FILE = getTestFile("test_sampileup_for_index.pileup.gz");
final File outName = createTempFile(ORIG_FILE.getName(), TabixUtils.STANDARD_INDEX_EXTENSION);
final String[] args = { "--feature_file", ORIG_FILE.getAbsolutePath(), "-O", outName.getAbsolutePath() };
final Object res = this.runCommandLine(args);
Assert.assertEquals(res, outName.getAbsolutePath());
final Index index = IndexFactory.loadIndex(res.toString());
Assert.assertTrue(index instanceof TabixIndex);
for (int chr : new int[] { 1, 2, 3, 4 }) {
//note: unusual loop
Assert.assertTrue(index.containsChromosome(String.valueOf(chr)), String.valueOf(chr));
}
for (int chr : new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 }) {
//note: unusual loop
Assert.assertFalse(index.containsChromosome(String.valueOf(chr)), String.valueOf(chr));
}
for (final String chr : Arrays.asList("X", "Y", "MT")) {
Assert.assertFalse(index.containsChromosome(chr), String.valueOf(chr));
}
Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "3", "4"));
}
use of htsjdk.tribble.index.Index in project gatk by broadinstitute.
the class IndexFeatureFileIntegrationTest method testVCFGZIndex_tabix.
@Test
public void testVCFGZIndex_tabix() {
//made by bgzip
final File ORIG_FILE = getTestFile("test_variants_for_index.vcf.blockgz.gz");
final File outName = createTempFile("test_variants_for_index.blockgz.gz.", TabixUtils.STANDARD_INDEX_EXTENSION);
final String[] args = { "--feature_file", ORIG_FILE.getAbsolutePath(), "-O", outName.getAbsolutePath() };
final Object res = this.runCommandLine(args);
Assert.assertEquals(res, outName.getAbsolutePath());
final Index index = IndexFactory.loadIndex(res.toString());
Assert.assertTrue(index instanceof TabixIndex);
Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "3", "4"));
checkIndex(index, Arrays.asList("1", "2", "3", "4"));
}
use of htsjdk.tribble.index.Index in project gatk by broadinstitute.
the class IndexFeatureFileIntegrationTest method testVCFIndex_inferredName.
@Test
public void testVCFIndex_inferredName() {
final File ORIG_FILE = getTestFile("test_variants_for_index.vcf");
final String[] args = { "--feature_file", ORIG_FILE.getAbsolutePath() };
final Object res = this.runCommandLine(args);
final File tribbleIndex = Tribble.indexFile(ORIG_FILE);
Assert.assertEquals(res, tribbleIndex.getAbsolutePath());
tribbleIndex.deleteOnExit();
final Index index = IndexFactory.loadIndex(res.toString());
Assert.assertTrue(index instanceof LinearIndex);
Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1", "2", "3", "4"));
checkIndex(index, Arrays.asList("1", "2", "3", "4"));
}
use of htsjdk.tribble.index.Index 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