use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class BwaAndMarkDuplicatesPipelineSpark method runTool.
@Override
protected void runTool(final JavaSparkContext ctx) {
try (final BwaSparkEngine engine = new BwaSparkEngine(ctx, indexImageFile, getHeaderForReads(), getReferenceSequenceDictionary())) {
final JavaRDD<GATKRead> alignedReads = engine.align(getReads());
final JavaRDD<GATKRead> markedReadsWithOD = MarkDuplicatesSpark.mark(alignedReads, engine.getHeader(), duplicatesScoringStrategy, new OpticalDuplicateFinder(), getRecommendedNumReducers());
final JavaRDD<GATKRead> markedReads = MarkDuplicatesSpark.cleanupTemporaryAttributes(markedReadsWithOD);
try {
ReadsSparkSink.writeReads(ctx, output, referenceArguments.getReferenceFile().getAbsolutePath(), markedReads, engine.getHeader(), shardedOutput ? ReadsWriteFormat.SHARDED : ReadsWriteFormat.SINGLE, getRecommendedNumReducers());
} catch (IOException e) {
throw new GATKException("unable to write bam: " + e);
}
}
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class AlignedAssemblyOrExcuse method writeSAMFile.
/**
* write a SAM file containing records for each aligned contig
*/
static void writeSAMFile(final String samFile, final SAMFileHeader header, final List<AlignedAssemblyOrExcuse> alignedAssemblyOrExcuseList) {
try (final OutputStream os = BucketUtils.createFile(samFile)) {
final SAMTextWriter writer = new SAMTextWriter(os);
writer.setSortOrder(SAMFileHeader.SortOrder.queryname, true);
writer.setHeader(header);
final List<String> refNames = getRefNames(header);
alignedAssemblyOrExcuseList.stream().filter(AlignedAssemblyOrExcuse::isNotFailure).flatMap(aa -> aa.toSAMStreamForAlignmentsOfThisAssembly(header, refNames)).forEach(writer::addAlignment);
writer.finish();
} catch (final IOException ioe) {
throw new GATKException("Can't write SAM file of aligned contigs.", ioe);
}
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class AlignedAssemblyOrExcuse method writeIntervalFile.
/**
* write a file describing each interval
*/
public static void writeIntervalFile(final String intervalFile, final SAMFileHeader header, final List<SVInterval> intervals, final List<AlignedAssemblyOrExcuse> intervalDispositions) {
final Map<Integer, AlignedAssemblyOrExcuse> resultsMap = new HashMap<>();
intervalDispositions.forEach(alignedAssemblyOrExcuse -> resultsMap.put(alignedAssemblyOrExcuse.getAssemblyId(), alignedAssemblyOrExcuse));
try (final OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(BucketUtils.createFile(intervalFile)))) {
final List<SAMSequenceRecord> contigs = header.getSequenceDictionary().getSequences();
final int nIntervals = intervals.size();
for (int intervalId = 0; intervalId != nIntervals; ++intervalId) {
final SVInterval interval = intervals.get(intervalId);
final String seqName = contigs.get(interval.getContig()).getSequenceName();
final AlignedAssemblyOrExcuse alignedAssemblyOrExcuse = resultsMap.get(intervalId);
final String disposition;
if (alignedAssemblyOrExcuse == null) {
disposition = "unknown";
} else if (alignedAssemblyOrExcuse.getErrorMessage() != null) {
disposition = alignedAssemblyOrExcuse.getErrorMessage();
} else {
disposition = "produced " + alignedAssemblyOrExcuse.getAssembly().getNContigs() + " contigs";
}
writer.write(intervalId + "\t" + seqName + ":" + interval.getStart() + "-" + interval.getEnd() + "\t" + disposition + "\n");
}
} catch (final IOException ioe) {
throw new GATKException("Can't write intervals file " + intervalFile, ioe);
}
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class ParallelCopyGCSDirectoryIntoHDFSSpark method readChunkToHdfs.
private static final Tuple2<Integer, String> readChunkToHdfs(final String inputGCSPathFinal, final long chunkSize, final Integer chunkNum, final String outputDirectory) {
final Path gcsPath = IOUtils.getPath(inputGCSPathFinal);
final String basename = gcsPath.getName(gcsPath.getNameCount() - 1).toString();
org.apache.hadoop.fs.Path outputPath = new org.apache.hadoop.fs.Path(outputDirectory);
final String chunkPath = outputPath + "/" + basename + ".chunk." + chunkNum;
try (SeekableByteChannel channel = Files.newByteChannel(gcsPath);
final OutputStream outputStream = new BufferedOutputStream(BucketUtils.createFile(chunkPath))) {
final long start = chunkSize * (long) chunkNum;
channel.position(start);
ByteBuffer byteBuffer = ByteBuffer.allocateDirect((int) Math.min(SIXTY_FOUR_MIB, chunkSize));
long bytesRead = 0;
while (channel.read(byteBuffer) > 0) {
byteBuffer.flip();
while (byteBuffer.hasRemaining() && bytesRead < chunkSize) {
byte b = byteBuffer.get();
outputStream.write(b);
bytesRead++;
}
if (bytesRead == chunkSize) {
break;
}
if (bytesRead > chunkSize) {
throw new GATKException("Encountered an unknown error condition and read too many bytes; output file may be corrupt");
}
byteBuffer.clear();
}
} catch (IOException e) {
throw new GATKException(e.getMessage() + "; inputGCSPathFinal = " + inputGCSPathFinal, e);
}
return new Tuple2<>(chunkNum, chunkPath);
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk-protected by broadinstitute.
the class CombineReadCounts method createMergeTemporalFile.
private File createMergeTemporalFile() {
final File result;
try {
result = File.createTempFile("read-count-merge", ".tab");
} catch (final IOException e) {
throw new GATKException("Could not create temporal merge file", e);
}
result.deleteOnExit();
return result;
}
Aggregations