本文整理汇总了Java中htsjdk.samtools.util.IOUtil.openFileForBufferedWriting方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtil.openFileForBufferedWriting方法的具体用法?Java IOUtil.openFileForBufferedWriting怎么用?Java IOUtil.openFileForBufferedWriting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.util.IOUtil
的用法示例。
在下文中一共展示了IOUtil.openFileForBufferedWriting方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitPerBaseCoverageIfRequested
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
/** Emits a file with per base coverage if an output file has been set. */
private void emitPerBaseCoverageIfRequested() {
if (this.perBaseOutput == null) return;
final PrintWriter out = new PrintWriter(IOUtil.openFileForBufferedWriting(this.perBaseOutput));
out.println("chrom\tpos\ttarget\tcoverage");
for (final Map.Entry<Interval,Coverage> entry : this.highQualityCoverageByTarget.entrySet()) {
final Interval interval = entry.getKey();
final String chrom = interval.getContig();
final int firstBase = interval.getStart();
final int[] cov = entry.getValue().getDepths();
for (int i = 0; i < cov.length; ++i) {
out.print(chrom);
out.print('\t');
out.print(firstBase + i);
out.print('\t');
out.print(interval.getName());
out.print('\t');
out.print(cov[i]);
out.println();
}
}
out.close();
}
示例2: doWork
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
IntervalList intervals = IntervalList.fromFile(INPUT);
if (SORT) intervals = intervals.sorted();
try {
final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);
for (final Interval i : intervals) {
final String strand = i.isNegativeStrand() ? "-" : "+";
final List<?> fields = CollectionUtil.makeList(i.getContig(), i.getStart()-1, i.getEnd(), i.getName(), SCORE, strand);
out.append(fields.stream().map(String::valueOf).collect(Collectors.joining("\t")));
out.newLine();
}
out.close();
}
catch (IOException ioe) {
throw new RuntimeIOException(ioe);
}
return 0;
}
示例3: writeParametersFile
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
/** Method that writes out all the parameter values that were used in the design using reflection. */
void writeParametersFile(final File file) {
try {
final BufferedWriter out = IOUtil.openFileForBufferedWriting(file);
for (final Field field : getClass().getDeclaredFields()) {
if (Modifier.isPrivate(field.getModifiers())) continue;
final String name = field.getName();
if (name.toUpperCase().equals(name) && !name.equals("USAGE")) {
final Object value = field.get(this);
if (value != null) {
out.append(name);
out.append("=");
out.append(value.toString());
out.newLine();
}
}
}
out.close();
} catch (Exception e) {
throw new PicardException("Error writing out parameters file.", e);
}
}
示例4: write
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
/**
* Writes a set of pedigrees out to disk.
*/
public void write(final File file) {
IOUtil.assertFileIsWritable(file);
final BufferedWriter out = IOUtil.openFileForBufferedWriting(file);
try {
for (final PedTrio trio : values()) {
out.write(trio.getFamilyId());
out.write("\t");
out.write(trio.getIndividualId());
out.write("\t");
out.write(trio.getPaternalId());
out.write("\t");
out.write(trio.getMaternalId());
out.write("\t");
out.write(String.valueOf(trio.getSex().toCode()));
out.write("\t");
out.write(trio.getPhenotype().toString());
out.newLine();
}
out.close();
}
catch (final IOException ioe) {
throw new RuntimeIOException("IOException while writing to file " + file.getAbsolutePath(), ioe);
}
}
示例5: writeDesignFastaFile
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
void writeDesignFastaFile(final File file, final IntervalList baits) {
final BufferedWriter out = IOUtil.openFileForBufferedWriting(file);
for (final Interval i : baits) {
writeBaitFasta(out, i, false);
}
CloserUtil.close(out);
}
示例6: doWork
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INTERVAL_LIST);
IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
IOUtil.assertFileIsWritable(OUTPUT);
final IntervalList intervals = IntervalList.fromFile(INTERVAL_LIST);
final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
SequenceUtil.assertSequenceDictionariesEqual(intervals.getHeader().getSequenceDictionary(), ref.getSequenceDictionary());
final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);
for (final Interval interval : intervals) {
final ReferenceSequence seq = ref.getSubsequenceAt(interval.getContig(), interval.getStart(), interval.getEnd());
final byte[] bases = seq.getBases();
if (interval.isNegativeStrand()) SequenceUtil.reverseComplement(bases);
try {
out.write(">");
out.write(interval.getName());
out.write("\n");
for (int i=0; i<bases.length; ++i) {
if (i > 0 && i % LINE_LENGTH == 0) out.write("\n");
out.write(bases[i]);
}
out.write("\n");
}
catch (IOException ioe) {
throw new PicardException("Error writing to file " + OUTPUT.getAbsolutePath(), ioe);
}
}
CloserUtil.close(out);
return 0;
}
示例7: run
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
/**
* run method which extracts barcodes and accumulates metrics for an entire tile
*/
synchronized public void run() {
try {
//delayed instantiation for new provider
if (this.provider == null) {
this.provider = factory.makeDataProvider(cbcls, locs, filterFiles, tile, null);
}
LOG.info("Extracting barcodes for tile " + tile);
//Sometimes makeDataProvider takes a while waiting for slow file IO, for each tile the needed set of files
//is non-overlapping sets of files so make the data providers in the individual threads for PerTileBarcodeExtractors
//so they are not all waiting for each others file operations
//Most likely we have SKIPS in our read structure since we replace all template reads with skips in the input data structure
//(see customCommnandLineValidation), therefore we must use the outputReadStructure to index into the output cluster data
final int[] barcodeIndices = outputReadStructure.sampleBarcodes.getIndices();
final BufferedWriter writer = IOUtil.openFileForBufferedWriting(barcodeFile);
final byte[][] barcodeSubsequences = new byte[barcodeIndices.length][];
final byte[][] qualityScores = usingQualityScores ? new byte[barcodeIndices.length][] : null;
while (provider.hasNext()) {
// Extract the barcode from the cluster and write it to the file for the tile
final ClusterData cluster = provider.next();
for (int i = 0; i < barcodeIndices.length; i++) {
barcodeSubsequences[i] = cluster.getRead(barcodeIndices[i]).getBases();
if (usingQualityScores) qualityScores[i] = cluster.getRead(barcodeIndices[i]).getQualities();
}
final boolean passingFilter = cluster.isPf();
final BarcodeMatch match = findBestBarcodeAndUpdateMetrics(barcodeSubsequences, qualityScores,
passingFilter, metrics, noMatch, maxNoCalls, maxMismatches,
minMismatchDelta, minimumBaseQuality);
final String yOrN = (match.matched ? "Y" : "N");
for (final byte[] bc : barcodeSubsequences) {
writer.write(StringUtil.bytesToString(bc));
}
writer.write("\t" + yOrN + "\t" + match.barcode + "\t" + String.valueOf(match.mismatches) +
"\t" + String.valueOf(match.mismatchesToSecondBest));
writer.newLine();
}
writer.close();
} catch (final Exception e) {
LOG.error(e, "Error processing tile ", this.tile);
this.exception = e;
} finally {
CloserUtil.close(provider);
provider = null;
}
}
示例8: writePoolFiles
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
/**
* Writes out fasta files for each pool and also agilent format files if requested.
*
* @param dir the directory to output files into
* @param basename the basename of each file
* @param baits the set of baits to write out
*/
void writePoolFiles(final File dir, final String basename, final IntervalList baits) {
final int copies;
if (FILL_POOLS && baits.size() < POOL_SIZE) copies = (int) Math.floor(POOL_SIZE / (double) baits.size());
else copies = 1;
int written = 0;
int nextPool = 0;
BufferedWriter out = null;
BufferedWriter agilentOut = null;
final String prefix = DESIGN_NAME.substring(0, Math.min(DESIGN_NAME.length(), 8)) + "_"; // prefix for 15 digit bait id
final NumberFormat fmt = new DecimalFormat("000000");
try {
for (int i = 0; i < copies; ++i) {
final boolean rc = i % 2 == 1;
int baitId = 1;
for (final Interval interval : baits) {
final Bait bait = (Bait) interval;
if (written++ % POOL_SIZE == 0) {
if (out != null) out.close();
if (agilentOut != null) agilentOut.close();
final String filename = basename + ".pool" + nextPool++ + ".design.";
out = IOUtil.openFileForBufferedWriting(new File(dir, filename + "fasta"));
if (OUTPUT_AGILENT_FILES) {
agilentOut = IOUtil.openFileForBufferedWriting(new File(dir, filename + "txt"));
}
}
writeBaitFasta(out, interval, rc);
if (OUTPUT_AGILENT_FILES) {
agilentOut.append(prefix).append(fmt.format(baitId++));
agilentOut.append("\t");
agilentOut.append(getBaitSequence(bait, rc).toUpperCase());
agilentOut.newLine();
}
}
}
CloserUtil.close(out);
CloserUtil.close(agilentOut);
} catch (Exception e) {
throw new PicardException("Error while writing pool files.", e);
}
}
示例9: doWork
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
if (INPUT.getAbsoluteFile().equals(OUTPUT.getAbsoluteFile())) {
throw new IllegalArgumentException("Input and output cannot be the same file.");
}
final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(INPUT, TRUNCATE_SEQUENCE_NAMES_AT_WHITESPACE);
final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);
ReferenceSequence seq = null;
while ((seq = ref.nextSequence()) != null) {
final String name = seq.getName();
final byte[] bases = seq.getBases();
try {
out.write(">");
out.write(name);
out.newLine();
if (bases.length == 0) {
log.warn("Sequence " + name + " contains 0 bases.");
}
else {
for (int i=0; i<bases.length; ++i) {
if (i > 0 && i % LINE_LENGTH == 0) out.write("\n");
out.write(bases[i]);
}
out.write("\n");
}
}
catch (IOException ioe) {
throw new PicardException("Error writing to file " + OUTPUT.getAbsolutePath(), ioe);
}
}
try {
out.close();
} catch (IOException e) {
throw new RuntimeIOException(e);
}
return 0;
}
示例10: doWork
import htsjdk.samtools.util.IOUtil; //导入方法依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
// set up the reference and a mask so that we only count the positions requested by the user
final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(INPUT);
final ReferenceSequenceMask referenceSequenceMask;
if (INTERVALS != null) {
IOUtil.assertFileIsReadable(INTERVALS);
final IntervalList intervalList = IntervalList.fromFile(INTERVALS);
referenceSequenceMask = new IntervalListReferenceSequenceMask(intervalList);
} else {
final SAMFileHeader header = new SAMFileHeader();
header.setSequenceDictionary(ref.getSequenceDictionary());
referenceSequenceMask = new WholeGenomeReferenceSequenceMask(header);
}
long nonNbases = 0L;
for (final SAMSequenceRecord rec : ref.getSequenceDictionary().getSequences()) {
// pull out the contig and set up the bases
final ReferenceSequence sequence = ref.getSequence(rec.getSequenceName());
final byte[] bases = sequence.getBases();
StringUtil.toUpperCase(bases);
for (int i = 0; i < bases.length; i++) {
// only investigate this position if it's within our mask
if (referenceSequenceMask.get(sequence.getContigIndex(), i+1)) {
nonNbases += bases[i] == SequenceUtil.N ? 0 : 1;
}
}
}
try {
final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);
out.write(nonNbases + "\n");
out.close();
}
catch (IOException ioe) {
throw new PicardException("Error writing to file " + OUTPUT.getAbsolutePath(), ioe);
}
return 0;
}