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

The following examples show how to use htsjdk.samtools.util.IOUtil#createTempDir() . 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: BamToBfqTest.java    From picard with MIT License 6 votes vote down vote up
@Test(dataProvider = "inputs")
public void testBamToBfq(final File input, final boolean isPairedRun,
                 final String outputFilePrefix) throws IOException {
    final File analysisDir = IOUtil.createTempDir("BamToBfqTest", ".dir");
    try {
        final String[] args = new String[] {
                "INPUT=" + input.getAbsolutePath(),
                "ANALYSIS_DIR=" + analysisDir.getAbsolutePath(),
                "OUTPUT_FILE_PREFIX=" + outputFilePrefix,
                "PAIRED_RUN=" + isPairedRun,
                "READS_TO_ALIGN=8"
        };
        BamToBfq bamToBfq = new BamToBfq();
        Assert.assertEquals(bamToBfq.instanceMain(args), 0, "Can't process " + input.getAbsolutePath() + " correctly");

        final File output = new File(analysisDir, outputFilePrefix + ".0.1.bfq");
        final File expectedBFQ = new File(TEST_DATA_DIR, outputFilePrefix + ".0.1.bfq");

        Assert.assertEquals(Files.readAllBytes(output.toPath()), Files.readAllBytes(expectedBFQ.toPath()));
    } finally {
        IOUtil.recursiveDelete(analysisDir.toPath());
    }
}
 
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: CheckIlluminaDirectoryTest.java    From picard with MIT License 6 votes vote down vote up
@BeforeMethod
private void setUp() throws Exception {
    illuminaDir = IOUtil.createTempDir("ift_test", "IlluminaDir");

    interopDir = new File(illuminaDir, "InterOp");
    if (!interopDir.exists() && !interopDir.mkdir()) {
        throw new RuntimeException("Couldn't make interop dir " + interopDir.getAbsolutePath());
    }

    dataDir = new File(illuminaDir, "Data");
    if (!dataDir.exists() && !dataDir.mkdir()) {
        throw new RuntimeException("Couldn't make data dir " + dataDir.getAbsolutePath());
    }

    intensityDir = new File(dataDir, "Intensities");
    if (!intensityDir.exists() && !intensityDir.mkdir()) {
        throw new RuntimeException("Couldn't make intensity dir " + intensityDir.getAbsolutePath());
    }

    basecallDir = new File(intensityDir, "BaseCalls");
    if (!basecallDir.exists() && !basecallDir.mkdir()) {
        throw new RuntimeException("Couldn't make basecalls dir " + basecallDir.getAbsolutePath());
    }
}
 
Example 4
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 5
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 6
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 7
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 8
Source File: MarkDuplicatesTest.java    From picard with MIT License 6 votes vote down vote up
@Test(dataProvider = "testOpticalDuplicateDetectionDataProvider")
public void testOpticalDuplicateDetection(final File sam, final long expectedNumOpticalDuplicates) {
    final File outputDir = IOUtil.createTempDir(TEST_BASE_NAME + ".", ".tmp");
    outputDir.deleteOnExit();
    final File outputSam = new File(outputDir, TEST_BASE_NAME + ".sam");
    outputSam.deleteOnExit();
    final File metricsFile = new File(outputDir, TEST_BASE_NAME + ".duplicate_metrics");
    metricsFile.deleteOnExit();
    // Run MarkDuplicates, merging the 3 input files, and either enabling or suppressing PG header
    // record creation according to suppressPg.
    final MarkDuplicates markDuplicates = new MarkDuplicates();
    markDuplicates.setupOpticalDuplicateFinder();
    markDuplicates.INPUT = CollectionUtil.makeList(sam.getAbsolutePath());
    markDuplicates.OUTPUT = outputSam;
    markDuplicates.METRICS_FILE = metricsFile;
    markDuplicates.TMP_DIR = CollectionUtil.makeList(outputDir);
    // Needed to suppress calling CommandLineProgram.getVersion(), which doesn't work for code not in a jar
    markDuplicates.PROGRAM_RECORD_ID = null;
    Assert.assertEquals(markDuplicates.doWork(), 0);
    Assert.assertEquals(markDuplicates.numOpticalDuplicates(), expectedNumOpticalDuplicates);
    IOUtil.recursiveDelete(outputDir.toPath());

}
 
Example 9
Source File: CreateSequenceDictionary.java    From varsim with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private SortingCollection<String> makeSortingCollection() {
  final String name = getClass().getSimpleName();
  final File tmpDir = IOUtil.createTempDir(name, null);
  tmpDir.deleteOnExit();
  // 256 byte for one name, and 1/10 part of all memory for this, rough estimate
  long maxNamesInRam = Runtime.getRuntime().maxMemory() / 256 / 10;
  return SortingCollection.newInstance(
          String.class,
          new StringCodec(),
          String::compareTo,
          (int) Math.min(maxNamesInRam, Integer.MAX_VALUE),
          tmpDir
  );
}
 
Example 10
Source File: SequenceDictionaryUtils.java    From picard with MIT License 5 votes vote down vote up
public static SortingCollection<String> makeSortingCollection() {
    final File tmpDir = IOUtil.createTempDir("SamDictionaryNames", null);
    tmpDir.deleteOnExit();
    // 256 byte for one name, and 1/10 part of all memory for this, rough estimate
    long maxNamesInRam = Runtime.getRuntime().maxMemory() / 256 / 10;
    return SortingCollection.newInstance(
            String.class,
            new StringCodec(),
            String::compareTo,
            (int) Math.min(maxNamesInRam, Integer.MAX_VALUE),
            tmpDir.toPath()
    );
}
 
Example 11
Source File: IntervalListToolsTest.java    From picard with MIT License 5 votes vote down vote up
@Test(dataProvider = "testScatterTestcases")
public void testScatterByContent(final IntervalListScattererTest.Testcase tc) throws IOException {

    final List<String> args = new ArrayList<>();

    args.add("ACTION=CONCAT");
    args.add("INPUT=" + tc.file.getAbsolutePath());

    args.add("SUBDIVISION_MODE=" + tc.mode);

    final File ilOutDir = IOUtil.createTempDir("IntervalListTools", "lists");
    dirsToDelete.add(ilOutDir);

    if (tc.scatterWidth == 1) {
        final File subDir = new File(ilOutDir, "temp_1_of_1");
        Assert.assertTrue(subDir.mkdir(), "was unable to create directory");
        args.add("OUTPUT=" + new File(subDir, "scattered.interval_list"));
    } else {
        args.add("OUTPUT=" + ilOutDir);
    }

    args.add("SCATTER_CONTENT=" + tc.mode.make().listWeight(tc.source) / tc.expectedScatter.size());

    Assert.assertEquals(runPicardCommandLine(args), 0);

    final String[] files = ilOutDir.list();
    Assert.assertNotNull(files);
    Arrays.sort(files);

    Assert.assertEquals(files.length, tc.expectedScatter.size());

    final Iterator<IntervalList> intervals = tc.expectedScatter.iterator();

    for (final String fileName : files) {
        final IntervalList intervalList = IntervalList.fromFile(new File(new File(ilOutDir, fileName), "scattered.interval_list"));
        final IntervalList expected = intervals.next();

        Assert.assertEquals(intervalList.getIntervals(), expected);
    }
}
 
Example 12
Source File: CollectSamErrorMetricsTest.java    From picard with MIT License 5 votes vote down vote up
@BeforeTest()
public void samMetricsProvider() {
    final File[] files = new File[]{
            simpleSamWithBaseErrors1,
            simpleSamWithBaseErrors2,
            simpleSingleStrandConsensusSamWithBaseErrors,
            simpleDuplexConsensusSamWithBaseErrors,
            chrMReadsWithClips};

    if (OUTPUT_DATA_PATH != null) {
        throw new PicardException("This should only be called once!");
    }

    OUTPUT_DATA_PATH = IOUtil.createTempDir("CollectSamErrorMetricsTest", null);

    for (final File file : files) {
        final File vcf = new File(TEST_DIR, "NIST.selected.vcf");

        final File outputBaseFileName = new File(OUTPUT_DATA_PATH, file.getName());
        outputBaseFileName.deleteOnExit();

        final String[] args = {
                "INPUT=" + file,
                "OUTPUT=" + outputBaseFileName,
                "REFERENCE_SEQUENCE=" + CHR_M_REFERENCE.getAbsolutePath(),
                "ERROR_METRICS=" + "ERROR:TWO_BASE_PADDED_CONTEXT", // Not all covariates are included by default, but we still want to test them.
                "ERROR_METRICS=" + "ERROR:CONSENSUS",
                "ERROR_METRICS=" + "ERROR:NS_IN_READ",
                "ERROR_METRICS=" + "ERROR:BINNED_CYCLE",
                "VCF=" + vcf.getAbsolutePath()
        };

        Assert.assertEquals(new CollectSamErrorMetrics().instanceMain(args), 0);

        errorMetrics.put(file, outputBaseFileName);
    }
}
 
Example 13
Source File: IlluminaFileUtilTest.java    From picard with MIT License 5 votes vote down vote up
@Test(dataProvider = "testHasCbclsDataProvider")
public void testHasCbcls(final int lane,
                         final boolean createCbclDir,
                         final boolean createCbcl,
                         final boolean expectedResult) throws IOException {

    final File basecallsDir = IOUtil.createTempDir("basecalls", "");
    basecallsDir.deleteOnExit();

    if (0 < lane) {
        final File laneDir = new File(basecallsDir, IlluminaFileUtil.longLaneStr(lane));
        Assert.assertTrue(laneDir.mkdir());

        if (createCbclDir) {
            final File cbclDir = new File(laneDir, "C1.1");
            cbclDir.mkdirs();
            cbclDir.deleteOnExit();

            if (createCbcl) {
                final File cbcl = new File(cbclDir, IlluminaFileUtil.longLaneStr(lane) + "_42.cbcl");
                new FileOutputStream(cbcl).close();
                cbcl.deleteOnExit();
            }
        }
    }

    Assert.assertEquals(IlluminaFileUtil.hasCbcls(basecallsDir, lane), expectedResult);
}
 
Example 14
Source File: IlluminaFileUtilTest.java    From picard with MIT License 5 votes vote down vote up
@BeforeMethod
private void setUp() throws Exception {
    intensityDir = IOUtil.createTempDir("ift_test", "Intensities");
    basecallDir = new File(intensityDir, "BaseCalls");
    if (!basecallDir.mkdir()) {
        throw new RuntimeException("Couldn't make basecalls dir " + basecallDir.getAbsolutePath());
    }
}
 
Example 15
Source File: MarkDuplicatesTest.java    From picard with MIT License 4 votes vote down vote up
/**
 * Test that PG header records are created & chained appropriately (or not created), and that the PG record chains
 * are as expected.  MarkDuplicates is used both to merge and to mark dupes in this case.
 * @param suppressPg If true, do not create PG header record.
 * @param expectedPnVnByReadName For each read, info about the expect chain of PG records.
 */
@Test(dataProvider = "pgRecordChainingTest")
public void pgRecordChainingTest(final boolean suppressPg,
                                 final Map<String, List<ExpectedPnAndVn>> expectedPnVnByReadName) {
    final File outputDir = IOUtil.createTempDir(TEST_BASE_NAME + ".", ".tmp");
    outputDir.deleteOnExit();
    try {
        // Run MarkDuplicates, merging the 3 input files, and either enabling or suppressing PG header
        // record creation according to suppressPg.
        final MarkDuplicates markDuplicates = new MarkDuplicates();
        final ArrayList<String> args = new ArrayList<>();
        for (int i = 1; i <= 3; ++i) {
            args.add("INPUT=" + new File(TEST_DATA_DIR, "merge" + i + ".sam").getAbsolutePath());
        }
        final File outputSam = new File(outputDir, TEST_BASE_NAME + ".sam");
        args.add("OUTPUT=" + outputSam.getAbsolutePath());
        args.add("METRICS_FILE=" + new File(outputDir, TEST_BASE_NAME + ".duplicate_metrics").getAbsolutePath());
        args.add("ADD_PG_TAG_TO_READS=true");
        if (suppressPg) args.add("PROGRAM_RECORD_ID=null");

        // I generally prefer to call doWork rather than invoking the argument parser, but it is necessary
        // in this case to initialize the command line.
        // Note that for the unit test, version won't come through because it is obtained through jar
        // manifest, and unit test doesn't run code from a jar.
        Assert.assertEquals(markDuplicates.instanceMain(args.toArray(new String[args.size()])), 0);

        // Read the MarkDuplicates output file, and get the PG ID for each read.  In this particular test,
        // the PG ID should be the same for both ends of a pair.
        final SamReader reader = SamReaderFactory.makeDefault().open(outputSam);

        final Map<String, String> pgIdForReadName = new HashMap<>();
        for (final SAMRecord rec : reader) {
            final String existingPgId = pgIdForReadName.get(rec.getReadName());
            final String thisPgId = rec.getStringAttribute(SAMTag.PG.name());
            if (existingPgId != null) {
                Assert.assertEquals(thisPgId, existingPgId);
            } else {
                pgIdForReadName.put(rec.getReadName(), thisPgId);
            }
        }
        final SAMFileHeader header = reader.getFileHeader();
        CloserUtil.close(reader);

        // Confirm that for each read name, the chain of PG records contains exactly the number that is expected,
        // and that values in the PG chain are as expected.
        for (final Map.Entry<String, List<ExpectedPnAndVn>> entry : expectedPnVnByReadName.entrySet()) {
            final String readName = entry.getKey();
            final List<ExpectedPnAndVn> expectedList = entry.getValue();
            String pgId = pgIdForReadName.get(readName);
            for (final ExpectedPnAndVn expected : expectedList) {
                final SAMProgramRecord programRecord = header.getProgramRecord(pgId);
                if (expected.expectedPn != null) Assert.assertEquals(programRecord.getProgramName(), expected.expectedPn);
                if (expected.expectedVn != null) Assert.assertEquals(programRecord.getProgramVersion(), expected.expectedVn);
                pgId = programRecord.getPreviousProgramGroupId();
            }
            Assert.assertNull(pgId);
        }

    } finally {
        IOUtil.recursiveDelete(outputDir.toPath());
    }
}
 
Example 16
Source File: SamFileTester.java    From picard with MIT License 4 votes vote down vote up
private void setOutputDir() {
    this.outputDir = IOUtil.createTempDir(this.getClass().getSimpleName() + ".", ".tmp");
    if (deleteOnExit) {
        outputDir.deleteOnExit();
    }
}
 
Example 17
Source File: CollectSequencingArtifactMetricsTest.java    From picard with MIT License 4 votes vote down vote up
@BeforeTest
public void setUp() throws IOException {
    globalTempOutputDir = IOUtil.createTempDir("artifactMetrics.", ".tmp");
}
 
Example 18
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 19
Source File: IntervalListToolsTest.java    From picard with MIT License 4 votes vote down vote up
@Test(dataProvider = "testScatterTestcases")
public void testScatter(final IntervalListScattererTest.Testcase tc) throws IOException {

    final IntervalListScatterer scatterer = tc.mode.make();
    final List<IntervalList> scatter = scatterer.scatter(tc.source, tc.scatterWidth);
    Assert.assertEquals(scatter.size(), tc.expectedScatter.size());
    for (int i = 0; i < scatter.size(); i++) {
        Assert.assertEquals(scatter.get(i).getIntervals(), tc.expectedScatter.get(i).getIntervals(), "Problem with the " + i + " scatter");
    }

    final List<String> args = new ArrayList<>();

    args.add("ACTION=CONCAT");
    args.add("INPUT=" + tc.file.getAbsolutePath());

    args.add("SUBDIVISION_MODE=" + tc.mode);

    final File ilOutDir = IOUtil.createTempDir("IntervalListTools", "lists");
    dirsToDelete.add(ilOutDir);

    if (tc.scatterWidth == 1) {
        final File subDir = new File(ilOutDir, "temp_1_of_1");
        Assert.assertTrue(subDir.mkdir(), "was unable to create directory");
        args.add("OUTPUT=" + new File(subDir, "scattered.interval_list"));
    } else {
        args.add("OUTPUT=" + ilOutDir);
    }

    args.add("SCATTER_COUNT=" + tc.scatterWidth);

    Assert.assertEquals(runPicardCommandLine(args), 0);

    final String[] files = ilOutDir.list();
    Assert.assertNotNull(files);
    Arrays.sort(files);

    Assert.assertEquals(files.length, tc.expectedScatter.size());

    final Iterator<IntervalList> intervals = tc.expectedScatter.iterator();

    for (final String fileName : files) {
        final IntervalList intervalList = IntervalList.fromFile(new File(new File(ilOutDir, fileName), "scattered.interval_list"));
        final IntervalList expected = intervals.next();

        Assert.assertEquals(intervalList.getIntervals(), expected);
    }
}
 
Example 20
Source File: SamFileTester.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setOutputDir() {
    this.outputDir = IOUtil.createTempDir(this.getClass().getSimpleName() + ".", ".tmp");
    if (deleteOnExit) {
        outputDir.deleteOnExit();
    }
}