use of htsjdk.tribble.index.Index in project gatk by broadinstitute.
the class IndexUtilsUnitTest method testLoadIndex_noIndex.
@Test
public void testLoadIndex_noIndex() throws Exception {
final File featureFile = new File(getToolTestDataDir(), "test_variants_for_index.noIndex.vcf");
final Index index = IndexUtils.loadTribbleIndex(featureFile);
Assert.assertNull(index);
}
use of htsjdk.tribble.index.Index in project gatk by broadinstitute.
the class IndexUtilsUnitTest method testLoadIndexAcceptOldIndex.
@Test
public void testLoadIndexAcceptOldIndex() throws Exception {
final File featureFile = new File(getToolTestDataDir(), "test_variants_for_index.newerThanIndex.vcf");
final File featureFileIdx = new File(getToolTestDataDir(), "test_variants_for_index.newerThanIndex.vcf.idx");
final File tmpDir = BaseTest.createTempDir("testLoadIndexAcceptOldIndex");
final Path tmpFeatureFilePath = tmpDir.toPath().resolve(featureFile.toPath().getFileName());
final Path tmpFeatureFileIdxPath = tmpDir.toPath().resolve(featureFileIdx.toPath().getFileName());
Files.copy(featureFile.toPath(), tmpFeatureFilePath);
Files.copy(featureFileIdx.toPath(), tmpFeatureFileIdxPath);
final File tmpVcf = tmpFeatureFilePath.toFile();
//wait a second
Thread.sleep(1000L);
//touch the file but not the index
tmpFeatureFilePath.toFile().setLastModified(System.currentTimeMillis());
final Index index = IndexUtils.loadTribbleIndex(tmpVcf);
Assert.assertNotNull(index);
//this should NOT blow up (files newer than indices are tolerated)
}
use of htsjdk.tribble.index.Index in project gatk-protected by broadinstitute.
the class AnnotateTargetsIntegrationTest method createTargetFile.
@BeforeClass
public void createTargetFile() throws IOException {
final SAMSequenceDictionary referenceDictionary = resolveReferenceDictionary();
final List<SimpleInterval> targetIntervals = createRandomIntervals(referenceDictionary, NUMBER_OF_TARGETS, MIN_TARGET_SIZE, MAX_TARGET_SIZE, MEAN_TARGET_SIZE, TARGET_SIZE_STDEV);
final List<Target> targets = targetIntervals.stream().map(Target::new).collect(Collectors.toList());
TargetWriter.writeTargetsToFile(TARGET_FILE, targets);
final Index index = IndexFactory.createIndex(TARGET_FILE, new TargetCodec(), IndexFactory.IndexType.LINEAR);
final LittleEndianOutputStream stream = new LittleEndianOutputStream(new FileOutputStream(TARGET_FILE_IDX));
index.write(stream);
stream.close();
}
use of htsjdk.tribble.index.Index in project gatk by broadinstitute.
the class IndexFeatureFileIntegrationTest method testGVCFTreatedAsVCFIndex.
@Test
public void testGVCFTreatedAsVCFIndex() {
// Here we're testing what happens when we have a GVCF that is treated by the tool as a
// regular VCF due to the lack of a .g.vcf extension
final File ORIG_FILE = getTestFile("test_variants_for_index.gvcf_treated_as_vcf.vcf");
final File outName = createTempFile("test_variants_for_index.gvcf_treated_as_vcf.vcf.", ".idx");
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 LinearIndex);
Assert.assertEquals(index.getSequenceNames(), Arrays.asList("1"));
checkIndex(index, Arrays.asList("1"));
}
use of htsjdk.tribble.index.Index in project gatk by broadinstitute.
the class IndexFeatureFileIntegrationTest method testBedIndex.
private void testBedIndex(final File ORIG_FILE, final Class<? extends Index> indexClass) {
final File outName = createTempFile(ORIG_FILE.getName(), (indexClass == TabixIndex.class) ? TabixUtils.STANDARD_INDEX_EXTENSION : ".idx");
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(indexClass.isInstance(index));
for (int chr : new int[] { 1, 2, 4 }) {
//note: unusual loop
Assert.assertTrue(index.containsChromosome(String.valueOf(chr)), String.valueOf(chr));
}
for (int chr : new int[] { 3, 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", "4"));
}
Aggregations