Java Code Examples for htsjdk.samtools.util.IOUtil#deleteDirectoryTree()

The following examples show how to use htsjdk.samtools.util.IOUtil#deleteDirectoryTree() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IlluminaFileUtilTest.java    From picard with MIT License 6 votes vote down vote up
public static void deleteRelativeFiles(final File baseFile, final List<String> relativeFilesToDelete) {
    for (final String relativeFile : relativeFilesToDelete) {
        final File actualFile = new File(baseFile, relativeFile);


        if (!actualFile.exists()) {
            throw new RuntimeException("Trying to delete a non-existent file" + actualFile.getAbsolutePath());
        }

        if (actualFile.isDirectory()) {
            IOUtil.deleteDirectoryTree(actualFile);
        } else {
            IOUtil.deleteFiles(actualFile);
        }
        if (actualFile.exists()) {
            throw new RuntimeException("File still exists after calling delete: " + actualFile);
        }
    }
}
 
Example 2
Source File: BclParserTest.java    From picard with MIT License 6 votes vote down vote up
public void fullBclParserTestWDeletedSkipsImpl(final int[] tiles, final int size, final int seekAfter, final int newTileIndex, final int orderedTileIndex, final String readStructure) {
    final File basecallDir = IOUtil.createTempDir("bclParserTest", "BaseCalls");

    Exception exc = null;
    try {
        final File l001 = new File(basecallDir, "L001");
        if (!l001.mkdir()) {
            throw new RuntimeException("Couldn't make lane dir " + l001.getAbsolutePath());
        }

        copyBcls(TEST_DATA_DIR, l001);
        deleteBclFiles(l001, readStructure);
        fullBclParserTestImpl(l001, READ_STRUCTURE_WSKIPS, tiles, size, seekAfter, newTileIndex, orderedTileIndex, false);
    } catch (final Exception thrExc) {
        exc = thrExc;
    } finally {
        IOUtil.deleteDirectoryTree(basecallDir);
    }
    if (exc != null) {
        if (exc.getClass() == PicardException.class) {
            throw new PicardException(exc.getMessage());
        }
        throw new RuntimeException(exc);
    }
}
 
Example 3
Source File: IlluminaLaneMetricsCollectorTest.java    From picard with MIT License 6 votes vote down vote up
@Test(dataProvider = "testLaneMetrics")
public void testWriteLaneMetrics(final String testRun) throws Exception {
    for (final boolean useReadStructure : Arrays.asList(true, false)) {
        final CollectIlluminaLaneMetrics clp = new CollectIlluminaLaneMetrics();
        clp.OUTPUT_DIRECTORY = IOUtil.createTempDir("illuminaLaneMetricsCollectorTest", null);
        clp.RUN_DIRECTORY = new File(TEST_DIRECTORY, testRun);
        clp.OUTPUT_PREFIX = "test";
        if (useReadStructure) clp.READ_STRUCTURE = new ReadStructure("101T8B101T");
        clp.doWork();

        final File laneMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaLaneMetrics.getExtension());
        final File canonicalOutputFile = buildOutputFile(TEST_DIRECTORY, testRun, IlluminaLaneMetrics.getExtension());

        IOUtil.assertFilesEqual(canonicalOutputFile, laneMetricsFile);

        IOUtil.deleteDirectoryTree(clp.OUTPUT_DIRECTORY);
    }
}
 
Example 4
Source File: IlluminaLaneMetricsCollectorTest.java    From picard with MIT License 6 votes vote down vote up
@Test(dataProvider = "testCollectIlluminaLaneMetrics")
public void testCollectIlluminaLaneMetrics(final String testRun, final ReadStructure readStructure, final boolean isNovaSeq) throws Exception {
    for (final boolean useReadStructure : Arrays.asList(true, false)) {
        final File runDirectory = new File(TILE_RUN_DIRECTORY, testRun);
        final CollectIlluminaLaneMetrics clp = new CollectIlluminaLaneMetrics();
        clp.OUTPUT_DIRECTORY = IOUtil.createTempDir("illuminaLaneMetricsCollectorTest", null);
        clp.RUN_DIRECTORY = runDirectory;
        clp.OUTPUT_PREFIX = "test";
        clp.IS_NOVASEQ = isNovaSeq;
        if (useReadStructure) clp.READ_STRUCTURE = readStructure;
        clp.doWork();

        final File phasingMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaPhasingMetrics.getExtension());
        final File canonicalPhasingFile = buildOutputFile(runDirectory, testRun, IlluminaPhasingMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalPhasingFile, phasingMetricsFile);

        final File laneMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaLaneMetrics.getExtension());
        final File canonicalLaneFile = buildOutputFile(runDirectory, testRun, IlluminaLaneMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalLaneFile, laneMetricsFile);
        IOUtil.deleteDirectoryTree(clp.OUTPUT_DIRECTORY);
    }
}
 
Example 5
Source File: IlluminaLaneMetricsCollectorTest.java    From picard with MIT License 6 votes vote down vote up
/** Ensures that an exception is thrown when we encounter a tile without phasing/pre-phasing metrics. */
@Test(expectedExceptions = PicardException.class)
public void testMissingPhasingValuesStrict() {
    final ReadStructure readStructure = new ReadStructure("151T8B8B151T");
    for (final boolean useReadStructure : Arrays.asList(true, false)) {
        final File runDirectory = TEST_MISSING_PHASING_DIRECTORY;
        final CollectIlluminaLaneMetrics clp = new CollectIlluminaLaneMetrics();
        clp.OUTPUT_DIRECTORY = IOUtil.createTempDir("illuminaLaneMetricsCollectorTest", null);
        clp.RUN_DIRECTORY = runDirectory;
        clp.OUTPUT_PREFIX = "test";
        clp.VALIDATION_STRINGENCY = ValidationStringency.STRICT;
        if (useReadStructure) clp.READ_STRUCTURE = readStructure;
        clp.doWork();

        final File phasingMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaPhasingMetrics.getExtension());
        final File canonicalPhasingFile = buildOutputFile(runDirectory, runDirectory.getName(), IlluminaPhasingMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalPhasingFile, phasingMetricsFile);

        final File laneMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaLaneMetrics.getExtension());
        final File canonicalLaneFile = buildOutputFile(runDirectory, runDirectory.getName(), IlluminaLaneMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalLaneFile, laneMetricsFile);
        IOUtil.deleteDirectoryTree(clp.OUTPUT_DIRECTORY);
    }
}
 
Example 6
Source File: IlluminaLaneMetricsCollectorTest.java    From picard with MIT License 6 votes vote down vote up
/** Silently continue if we encounter a tile without phasing/pre-phasing metrics. */
@Test
public void testMissingPhasingValuesSilent() throws IOException {
    final ReadStructure readStructure = new ReadStructure("151T8B8B151T");
    for (final boolean useReadStructure : Arrays.asList(true, false)) {
        final File runDirectory = TEST_MISSING_PHASING_DIRECTORY;
        final CollectIlluminaLaneMetrics clp = new CollectIlluminaLaneMetrics();
        clp.OUTPUT_DIRECTORY = IOUtil.createTempDir("illuminaLaneMetricsCollectorTest", null);
        clp.RUN_DIRECTORY = runDirectory;
        clp.OUTPUT_PREFIX = "test";
        clp.VALIDATION_STRINGENCY = ValidationStringency.SILENT;
        if (useReadStructure) clp.READ_STRUCTURE = readStructure;
        clp.doWork();

        final File phasingMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaPhasingMetrics.getExtension());
        final File canonicalPhasingFile = buildOutputFile(runDirectory, runDirectory.getName(), IlluminaPhasingMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalPhasingFile, phasingMetricsFile);

        final File laneMetricsFile = buildOutputFile(clp.OUTPUT_DIRECTORY, clp.OUTPUT_PREFIX, IlluminaLaneMetrics.getExtension());
        final File canonicalLaneFile = buildOutputFile(runDirectory, runDirectory.getName(), IlluminaLaneMetrics.getExtension());
        IOUtil.assertFilesEqual(canonicalLaneFile, laneMetricsFile);
        IOUtil.deleteDirectoryTree(clp.OUTPUT_DIRECTORY);
    }
}
 
Example 7
Source File: CheckIlluminaDirectoryTest.java    From picard with MIT License 5 votes vote down vote up
@AfterMethod
private void tearDown() {
    IOUtil.deleteDirectoryTree(dataDir);
    IOUtil.deleteDirectoryTree(basecallDir);
    IOUtil.deleteDirectoryTree(intensityDir);
    IOUtil.deleteDirectoryTree(illuminaDir);
}
 
Example 8
Source File: ExtractIlluminaBarcodesTest.java    From picard with MIT License 5 votes vote down vote up
@AfterTest
private void tearDown() {
    IOUtil.deleteDirectoryTree(basecallsDir);
    IOUtil.deleteDirectoryTree(dual);
    IOUtil.deleteDirectoryTree(qual);
    IOUtil.deleteDirectoryTree(noSymlink);
}
 
Example 9
Source File: CollectIlluminaBasecallingMetricsTest.java    From picard with MIT License 4 votes vote down vote up
@AfterTest
private void tearDown() {
    IOUtil.deleteDirectoryTree(rootTestDir);
}
 
Example 10
Source File: CollectSequencingArtifactMetricsTest.java    From picard with MIT License 4 votes vote down vote up
@AfterTest
public void tearDown() throws IOException {
    IOUtil.deleteDirectoryTree(globalTempOutputDir);
}
 
Example 11
Source File: CollectRrbsMetricsTest.java    From picard with MIT License 4 votes vote down vote up
@AfterTest
private void tearDown() {
    IOUtil.deleteDirectoryTree(rootTestDir);
}
 
Example 12
Source File: CheckFingerprintTest.java    From picard with MIT License 4 votes vote down vote up
@AfterClass
private void rmTemp() {
    IOUtil.deleteDirectoryTree(tempFolder);
}
 
Example 13
Source File: GenotypeConcordanceTest.java    From picard with MIT License 4 votes vote down vote up
@AfterClass
public void tearDown() {
    IOUtil.deleteDirectoryTree(OUTPUT_DATA_PATH);
}
 
Example 14
Source File: UpdateVcfSequenceDictionaryTest.java    From picard with MIT License 4 votes vote down vote up
@AfterClass
public void teardown() {
    IOUtil.deleteDirectoryTree(OUTPUT_DATA_PATH);
}
 
Example 15
Source File: SplitVcfsTest.java    From picard with MIT License 4 votes vote down vote up
@AfterClass
public void teardown() {
    IOUtil.deleteDirectoryTree(OUTPUT_DATA_PATH);
}
 
Example 16
Source File: LiftoverVcfTest.java    From picard with MIT License 4 votes vote down vote up
@AfterClass
public void teardown() {
    IOUtil.deleteDirectoryTree(OUTPUT_DATA_PATH);
}
 
Example 17
Source File: CollectHsMetricsTest.java    From picard with MIT License 4 votes vote down vote up
@Test
public void testHsMetricsHandlesIndelsAppropriately() throws IOException {
    final SAMRecordSetBuilder withDeletions = new SAMRecordSetBuilder(true, SortOrder.coordinate);
    final SAMRecordSetBuilder withInsertions = new SAMRecordSetBuilder(true, SortOrder.coordinate);
    final IntervalList targets = new IntervalList(withDeletions.getHeader());
    final IntervalList baits   = new IntervalList(withDeletions.getHeader());
    targets.add(new Interval("chr1", 1000, 1199, false, "t1"));
    baits.add(new Interval("chr1", 950,  1049, false, "b1"));
    baits.add(new Interval("chr1", 1050, 1149, false, "b2"));
    baits.add(new Interval("chr1", 1150, 1249, false, "b3"));

    // Generate 100 reads that fully cover the the target in each BAM
    for (int i=0; i<100; ++i) {
        withDeletions.addFrag( "d" + i, 0, 1000, false, false, "100M20D80M", null, 30);
        withInsertions.addFrag("i" + i, 0, 1000, false, false, "100M50I100M", null, 30);
    }

    // Write things out to file
    final File dir = IOUtil.createTempDir("hsmetrics.", ".test");
    final File bs = new File(dir, "baits.interval_list").getAbsoluteFile();
    final File ts = new File(dir, "targets.interval_list").getAbsoluteFile();
    baits.write(bs);
    targets.write(ts);
    final File withDelBam = writeBam(withDeletions,  new File(dir, "with_del.bam"));
    final File withInsBam = writeBam(withInsertions, new File(dir, "with_ins.bam"));

    // Now run CollectHsMetrics four times
    final File out = Files.createTempFile("hsmetrics.", ".txt").toFile();
    runPicardCommandLine(Arrays.asList("INCLUDE_INDELS=false", "SAMPLE_SIZE=0", "TI="+ts.getPath(), "BI="+bs.getPath(), "O="+out.getPath(), "I="+withDelBam.getAbsolutePath()));
    final HsMetrics delsWithoutIndelHandling = readMetrics(out);
    runPicardCommandLine(Arrays.asList("INCLUDE_INDELS=true", "SAMPLE_SIZE=0", "TI="+ts.getPath(), "BI="+bs.getPath(), "O="+out.getPath(), "I="+withDelBam.getAbsolutePath()));
    final HsMetrics delsWithIndelHandling = readMetrics(out);
    runPicardCommandLine(Arrays.asList("INCLUDE_INDELS=false", "SAMPLE_SIZE=0", "TI="+ts.getPath(), "BI="+bs.getPath(), "O="+out.getPath(), "I="+withInsBam.getAbsolutePath()));
    final HsMetrics insWithoutIndelHandling = readMetrics(out);
    runPicardCommandLine(Arrays.asList("INCLUDE_INDELS=true", "SAMPLE_SIZE=0", "TI="+ts.getPath(), "BI="+bs.getPath(), "O="+out.getPath(), "I="+withInsBam.getAbsolutePath()));
    final HsMetrics insWithIndelHandling = readMetrics(out);

    IOUtil.deleteDirectoryTree(dir);

    Assert.assertEquals(delsWithoutIndelHandling.MEAN_TARGET_COVERAGE, 90.0);  // 100X over 180/200 bases due to deletion
    Assert.assertEquals(delsWithIndelHandling.MEAN_TARGET_COVERAGE, 100.0);    // 100X with counting the deletion

    Assert.assertEquals(insWithoutIndelHandling.PCT_USABLE_BASES_ON_TARGET, 200/250d); // 50/250 inserted bases are not counted as on target
    Assert.assertEquals(insWithIndelHandling.PCT_USABLE_BASES_ON_TARGET,   1.0d);      // inserted bases are counted as on target
}
 
Example 18
Source File: DownsampleSamTest.java    From picard with MIT License 4 votes vote down vote up
@AfterTest
private void tearDown() {
    IOUtil.deleteDirectoryTree(tempDir);
}
 
Example 19
Source File: TileMetricsUtilTest.java    From picard with MIT License 4 votes vote down vote up
@AfterClass
public void cleanupTestDir() {
    IOUtil.deleteDirectoryTree(testDir.toFile());
}
 
Example 20
Source File: IlluminaFileUtilTest.java    From picard with MIT License 4 votes vote down vote up
@AfterMethod
private void tearDown() {
    IOUtil.deleteDirectoryTree(intensityDir);
}