当前位置: 首页>>代码示例>>Java>>正文


Java IOUtil类代码示例

本文整理汇总了Java中htsjdk.samtools.util.IOUtil的典型用法代码示例。如果您正苦于以下问题:Java IOUtil类的具体用法?Java IOUtil怎么用?Java IOUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IOUtil类属于htsjdk.samtools.util包,在下文中一共展示了IOUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unrollFileCollection

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
/** return 'inputs' as set, if a filename ends with '*.list'
    * is is considered as a file:one file per line
    * @param inputs files
    * @return set of files
    */
public static LinkedHashSet<File> unrollFileCollection(java.util.Collection<File> inputs)
	{
	LinkedHashSet<File> vcfFiles= new LinkedHashSet<>(inputs.size()+1);
	for(File file : inputs)
		{
		if(file.getName().endsWith(".list"))
			{
			IOUtil.assertFileIsReadable(file);
			 for (final String s : IOUtil.readLines(file))
			 	{
				if (s.endsWith("#")) continue;
				if (s.trim().isEmpty()) continue;
				vcfFiles.add(new File(s));
				}
			}
		else
			{
			vcfFiles.add(file);
			}
		
		}
	return vcfFiles;
	}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:29,代码来源:IOUtils.java

示例2: getMaybeBufferedOutputStream

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
/**
 * Creates a maybe buffered output stream from a Path.
 *
 * In addition, if the Path is from the Hadoop Filesystem, it sets other characteristics for
 * the output stream:
 *
 * - HDFS Block-size: {@link #hdfsBlockSize}.
 * - Buffer-size: {@link #bufferSize}, instead of wrapping in a buffered stream.
 */
private OutputStream getMaybeBufferedOutputStream(final Path path) throws IOException {
    // iif there is a block-size to change and the path is from Hadoop
    if (hdfsBlockSize != null && path instanceof HadoopPath) {
        final HadoopPath hadoopPath = (HadoopPath) path;
        // gets the HDFS to create the output stream with custom block-size
        final FileSystem hdfs = hadoopPath.getFileSystem().getHDFS();
        // gets the the path (extracted here to get the default replication)
        final org.apache.hadoop.fs.Path hdfsPath = hadoopPath.getRawResolvedPath();

        // construct the output stream already buffered here
        return hdfs.create(hdfsPath, forceOverwrite,
                // buffer size
                bufferSize,
                // replication is using the default
                hdfs.getDefaultReplication(hdfsPath),
                // block-size is the one set here
                hdfsBlockSize);
    }
    logger.debug("Block-size is ignored: {}", () -> hdfsBlockSize);
    return IOUtil.maybeBufferOutputStream(Files.newOutputStream(path), bufferSize);
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:31,代码来源:ReadWriterFactory.java

示例3: divideIntoBatches

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
/**
 * Divide the part files into the batches to download and pre-sort at the same time.
 *
 * @param partFiles all part files to download.
 *
 * @return a map of path to download the parts and the parts that should be used (as reads
 * source).
 *
 * @see #downloadBatchesAndPreSort(List)
 */
private Map<Path, ReadsDataSource> divideIntoBatches(final List<Path> partFiles) {
    // partition the files into batches
    final List<List<Path>> batches = Lists.partition(partFiles, numberOfParts);
    final Map<Path, ReadsDataSource> toReturn = new LinkedHashMap<>(batches.size());

    // creates a temp file for each in a common temp folder
    final File tempDir = IOUtil.createTempDir(this.toString(), ".batches");
    int i = 0;
    for (final List<Path> parts : batches) {
        // create a temp file and store it in the temp parts
        final Path tempFile =
                IOUtils.getPath(new File(tempDir, "batch-" + i++ + ".bam").getAbsolutePath());
        logger.debug("Batch file {} will contain {} parts: {}",
                () -> tempFile.toUri().toString(),
                () -> parts.size(),
                () -> parts.stream().map(p -> p.toUri().toString())
                        .collect(Collectors.toList()));
        toReturn.put(tempFile, new ReadsDataSource(parts, getSamReaderFactory()));
    }

    return toReturn;
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:33,代码来源:DistmapPartDownloader.java

示例4: BamToBfqWriter

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param bamFile        the BAM file to read from
 * @param outputPrefix   the directory and file prefix for the binary fastq files
 * @param total          the total number of records that should be written, drawn evenly
 *                       from throughout the file (null for all).
 * @param chunk          the maximum number of records that should be written to any one file
 * @param pairedReads    whether these reads are from  a paired-end run
 * @param namePrefix     The string to be stripped off the read name
 *                       before writing to the bfq file. May be null, in which case
 *                       the name will not be trimmed.
 * @param includeNonPfReads whether to include non pf-reads
 * @param clipAdapters    whether to replace adapters as marked with XT:i clipping position attribute
 */
public BamToBfqWriter(final File bamFile, final String outputPrefix, final Integer total,
                      final Integer chunk, final boolean pairedReads, String namePrefix,
                      boolean includeNonPfReads, boolean clipAdapters, Integer basesToWrite) {

    IOUtil.assertFileIsReadable(bamFile);
    this.bamFile = bamFile;
    this.outputPrefix = outputPrefix;
    this.pairedReads = pairedReads;
    if (total != null) {
        final double writeable = (double)countWritableRecords();
        this.increment = (int)Math.floor(writeable/total.doubleValue());
        if (this.increment == 0) {
            this.increment = 1;
        }
    }
    if (chunk != null) {
        this.chunk = chunk;
    }
    this.namePrefix = namePrefix;
    this.nameTrim = namePrefix != null ? namePrefix.length() : 0;
    this.includeNonPfReads = includeNonPfReads;
    this.clipAdapters = clipAdapters;
    this.basesToWrite = basesToWrite;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:40,代码来源:BamToBfqWriter.java

示例5: customCommandLineValidation

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
@Override
protected String[] customCommandLineValidation() {
    IOUtil.assertDirectoryIsReadable(BASECALLS_DIR);
    final List<String> errors = new ArrayList<>();

    for (final Integer lane : LANES) {
        if (lane < 1) {
            errors.add(
                    "LANES must be greater than or equal to 1.  LANES passed in " + StringUtil.join(", ", LANES));
            break;
        }
    }

    if (errors.isEmpty()) {
        return null;
    } else {
        return errors.toArray(new String[errors.size()]);
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:20,代码来源:CheckIlluminaDirectory.java

示例6: testDebugOption

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
/**
 * makes sure debug files are created properly
 */
@Test(dataProvider = "dataTestDebugOption")
public void testDebugOption(Boolean writeDebugReads, boolean isDebugFileExpected) throws Exception {
    // input as SAM file
    final File inputSam = new File("testdata/picard/sam/aligned.sam");
    final File javascriptFile = new File("testdata/picard/sam/FilterSamReads/filterOddStarts.js");

    FilterSamReads filterTest = setupProgram(javascriptFile, inputSam, FilterSamReads.Filter.includeJavascript, writeDebugReads);
    Assert.assertEquals(filterTest.doWork(), 0);

    final File inputReadsFile = new File(filterTest.OUTPUT.getParentFile(), IOUtil.basename(filterTest.INPUT) + ".reads");
    Assert.assertEquals(inputReadsFile.exists(), isDebugFileExpected);

    final File outputReadsFile = new File(filterTest.OUTPUT.getParentFile(), IOUtil.basename(filterTest.OUTPUT) + ".reads");
    outputReadsFile.deleteOnExit();
    Assert.assertEquals(outputReadsFile.exists(), isDebugFileExpected);

    // We have to clean up the debug files after each test is run to make sure a clean state is preserved in between tests
    // This mostly affects the input *.reads file because it will always be called "aligned.reads" and will cause future
    // tests to fail if it sticks around and we dont expect it to be written
    Files.deleteIfExists(inputReadsFile.toPath());
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:FilterSamReadsTest.java

示例7: TileIndex

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
TileIndex(final File tileIndexFile) {
    try {
        this.tileIndexFile = tileIndexFile;
        final InputStream is = IOUtil.maybeBufferInputStream(new FileInputStream(tileIndexFile));
        final ByteBuffer buf = ByteBuffer.allocate(8);
        buf.order(ByteOrder.LITTLE_ENDIAN);
        int absoluteRecordIndex = 0;
        int numTiles = 0;
        while (readTileIndexRecord(buf.array(), buf.capacity(), is)) {
            buf.rewind();
            buf.limit(buf.capacity());
            final int tile = buf.getInt();
            // Note: not handling unsigned ints > 2^31, but could if one of these exceptions is thrown.
            if (tile < 0) throw new PicardException("Tile number too large in " + tileIndexFile.getAbsolutePath());
            final int numClusters = buf.getInt();
            if (numClusters < 0) throw new PicardException("Cluster size too large in " + tileIndexFile.getAbsolutePath());
            tiles.add(new TileIndexRecord(tile, numClusters, absoluteRecordIndex, numTiles++));
            absoluteRecordIndex += numClusters;
        }
        CloserUtil.close(is);
    } catch (final IOException e) {
        throw new PicardException("Problem reading " + tileIndexFile.getAbsolutePath(), e);
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:TileIndex.java

示例8: testWriteLaneMetrics

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:19,代码来源:IlluminaLaneMetricsCollectorTest.java

示例9: withIntervals

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
@Test
public void withIntervals() throws IOException {
    final File input = new File(REFERENCE);
    final File outfile = File.createTempFile("nonNcount", ".txt");
    final File intervals = new File("testdata/picard/reference/test.intervals");
    outfile.deleteOnExit();
    final String[] args = new String[] {
            "INPUT="  + input.getAbsolutePath(),
            "OUTPUT=" + outfile.getAbsolutePath(),
            "INTERVALS=" + intervals.getAbsolutePath()
    };
    Assert.assertEquals(new NonNFastaSize().instanceMain(args), 0);

    final BufferedReader reader = IOUtil.openFileForBufferedReading(outfile);
    final String count = reader.readLine();

    try {
        Assert.assertEquals(Long.parseLong(count), 53);
    } catch (Exception e) {
        System.err.println("Failed to read in count because of error: " + e.getMessage());
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:NonNFastaSizeTest.java

示例10: testCollectIlluminaLaneMetrics

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:IlluminaLaneMetricsCollectorTest.java

示例11: fakeFiles

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
@Override
public List<String> fakeFiles(final List<Integer> expectedTiles, final int[] expectedCycles,
                              final IlluminaFileUtil.SupportedIlluminaFormat format) {
    //we need to fake a bci file for the tile index
    final BciFileFaker bciFileFaker = new BciFileFaker();
    try {
        bciFileFaker.fakeBciFile(bci, expectedTiles);
        tileIndex = new TileIndex(bci);
        faker.fakeFile(base, expectedTiles, lane, extension);
        final File[] filesMatchingRegexp = IOUtil.getFilesMatchingRegexp(base, matchPattern);
        if (filesMatchingRegexp == null || filesMatchingRegexp.length == 0) {
            dataFile = null;
        } else if (filesMatchingRegexp.length == 1) {
            dataFile = filesMatchingRegexp[0];
        } else {
            throw new PicardException("More than one filter file found in " + base.getAbsolutePath());
        }
    } catch (final IOException e) {
        return Collections.singletonList("Could not create tile index file: " + bci.getAbsolutePath());
    }
    return tileIndex.verify(expectedTiles);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:MultiTileFileUtil.java

示例12: renderPhasingMetricsFilesFromBasecallingDirectory

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
public static Map<Integer, File> renderPhasingMetricsFilesFromBasecallingDirectory(File illuminaRunDirectory) {
    File[] cycleDirs = IOUtil.getFilesMatchingRegexp(new File(illuminaRunDirectory, INTEROP_SUBDIRECTORY_NAME),
            IlluminaFileUtil.CYCLE_SUBDIRECTORY_PATTERN);

    Map<Integer, File> phasingMetrics = new HashMap<>();
    Arrays.asList(cycleDirs)
            .forEach(cycleDir -> {
                File[] filesMatchingRegexp = IOUtil.getFilesMatchingRegexp(
                        cycleDir, "EmpiricalPhasingMetricsOut.bin");
                if (filesMatchingRegexp.length > 0) {
                    phasingMetrics.put(PerTilePerCycleFileUtil.getCycleFromDir(cycleDir),
                            filesMatchingRegexp[0]);
                }
            });
    return phasingMetrics;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:17,代码来源:TileMetricsUtil.java

示例13: hasCbcls

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
public static boolean hasCbcls(final File basecallDir, final int lane) {
    final File laneDir = new File(basecallDir, IlluminaFileUtil.longLaneStr(lane));
    final File[] cycleDirs = IOUtil.getFilesMatchingRegexp(laneDir, IlluminaFileUtil.CYCLE_SUBDIRECTORY_PATTERN);

    // Either the lane or the cycle directory do not exist!
    if (cycleDirs == null) {
        return false;
    }

    //CBCLs
    final List<File> cbcls = new ArrayList<>();
    Arrays.asList(cycleDirs)
            .forEach(cycleDir -> cbcls.addAll(
                    Arrays.asList(IOUtil.getFilesMatchingRegexp(
                            cycleDir, "^" + IlluminaFileUtil.longLaneStr(lane) + "_(\\d{1,5}).cbcl$"))));

    return cbcls.size() > 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:19,代码来源:IlluminaFileUtil.java

示例14: getPerTilePerCycleFiles

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
/**
 * For the given tiles, populate a CycleIlluminaFileMap that contains all these tiles and will iterate through
 * all the files for these tiles in expectedBase
 * Side Effect: Assigns numCycles
 *
 * @return A CycleIlluminaFileMap with the listed (or all) tiles for at least expectedCycles number of cycles(or total available
 * cycles if expectedCycles is null)
 */
protected CycleIlluminaFileMap getPerTilePerCycleFiles() {
    final CycleIlluminaFileMap cycledMap = new CycleIlluminaFileMap();

    final File laneDir = base;
    final File[] tempCycleDirs;
    tempCycleDirs = IOUtil.getFilesMatchingRegexp(laneDir, IlluminaFileUtil.CYCLE_SUBDIRECTORY_PATTERN);
    if (tempCycleDirs == null || tempCycleDirs.length == 0) {
        return cycledMap;
    }

    for (final File tempCycleDir : tempCycleDirs) {
        detectedCycles.add(getCycleFromDir(tempCycleDir));
    }

    final Set<Integer> uniqueTiles = new HashSet<Integer>();

    for (final File cycleDir : tempCycleDirs) {
        final IlluminaFileMap fileMap = getTiledFiles(cycleDir, matchPattern);
        uniqueTiles.addAll(fileMap.keySet());
        cycledMap.put(getCycleFromDir(cycleDir), fileMap);
    }

    this.tiles = new ArrayList<>(uniqueTiles);
    return cycledMap;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:34,代码来源:PerTilePerCycleFileUtil.java

示例15: buildSamFileWriter

import htsjdk.samtools.util.IOUtil; //导入依赖的package包/类
/**
 * Build a SamFileWriter that will write its contents to the output file.
 *
 * @param output           The file to which to write
 * @param sampleAlias      The sample alias set in the read group header
 * @param libraryName      The name of the library to which this read group belongs
 * @param headerParameters Header parameters that will be added to the RG header for this SamFile
 * @return A SAMFileWriter
 */
private SAMFileWriterWrapper buildSamFileWriter(final File output, final String sampleAlias,
                                                final String libraryName, final Map<String, String> headerParameters,
                                                final boolean presorted) {
    IOUtil.assertFileIsWritable(output);
    final SAMReadGroupRecord rg = new SAMReadGroupRecord(READ_GROUP_ID);
    rg.setSample(sampleAlias);

    if (libraryName != null) rg.setLibrary(libraryName);
    for (final Map.Entry<String, String> tagNameToValue : headerParameters.entrySet()) {
        if (tagNameToValue.getValue() != null) {
            rg.setAttribute(tagNameToValue.getKey(), tagNameToValue.getValue());
        }
    }

    final SAMFileHeader header = new SAMFileHeader();

    header.setSortOrder(SAMFileHeader.SortOrder.queryname);
    header.addReadGroup(rg);
    return new SAMFileWriterWrapper(new SAMFileWriterFactory().makeSAMOrBAMWriter(header, presorted, output));
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:30,代码来源:IlluminaBasecallsToSam.java


注:本文中的htsjdk.samtools.util.IOUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。