use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.
the class ReadClipper method clipByReferenceCoordinates.
/**
* Generic functionality to clip a read, used internally by hardClipByReferenceCoordinatesLeftTail
* and hardClipByReferenceCoordinatesRightTail. Should not be used directly.
*
* Note, it REQUIRES you to give the directionality of your hard clip (i.e. whether you're clipping the
* left of right tail) by specifying either refStart < 0 or refStop < 0.
*
* @param refStart first base to clip (inclusive)
* @param refStop last base to clip (inclusive)
* @param clippingOp clipping operation to be performed
* @return a new read, without the clipped bases
*/
protected GATKRead clipByReferenceCoordinates(final int refStart, final int refStop, ClippingRepresentation clippingOp, boolean runAsserts) {
if (read.isEmpty()) {
return read;
}
if ((clippingOp == ClippingRepresentation.SOFTCLIP_BASES) && read.isUnmapped()) {
throw new GATKException("Cannot softclip read " + read.commonToString() + " by reference coordinates because it is unmapped");
}
final int start;
final int stop;
// Determine the read coordinate to start and stop hard clipping
if (refStart < 0) {
if (refStop < 0) {
throw new GATKException("Only one of refStart or refStop must be < 0, not both (" + refStart + ", " + refStop + ")");
}
start = 0;
stop = ReadUtils.getReadCoordinateForReferenceCoordinate(read, refStop, ReadUtils.ClippingTail.LEFT_TAIL);
} else {
if (refStop >= 0) {
throw new GATKException("Either refStart or refStop must be < 0 (" + refStart + ", " + refStop + ")");
}
start = ReadUtils.getReadCoordinateForReferenceCoordinate(read, refStart, ReadUtils.ClippingTail.RIGHT_TAIL);
stop = read.getLength() - 1;
}
if (start < 0 || stop > read.getLength() - 1) {
throw new GATKException("Trying to clip before the start or after the end of a read");
}
if (start > stop) {
throw new GATKException(String.format("START (%d) > (%d) STOP -- this should never happen, please check read: %s (CIGAR: %s)", start, stop, read, read.getCigar().toString()));
}
if (start > 0 && stop < read.getLength() - 1) {
throw new GATKException(String.format("Trying to clip the middle of the read: start %d, stop %d, cigar: %s", start, stop, read.getCigar().toString()));
}
this.addOp(new ClippingOp(start, stop));
final GATKRead clippedRead = clipRead(clippingOp, runAsserts);
this.ops = null;
return clippedRead;
}
use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk-protected by broadinstitute.
the class ConvertGSVariantsToSegments method calculateLog10CallQuality.
private double calculateLog10CallQuality(final double[] log10Probs, final CopyNumberTriState call) {
final IntRange callCopyNumberRange;
switch(call) {
case NEUTRAL:
callCopyNumberRange = new IntRange(neutralCopyNumber, neutralCopyNumber);
break;
case DELETION:
callCopyNumberRange = new IntRange(0, neutralCopyNumber - 1);
break;
case DUPLICATION:
callCopyNumberRange = new IntRange(neutralCopyNumber + 1, log10Probs.length - 1);
break;
default:
throw new GATKException("unexpected call");
}
// We aggregate the probs of any copy number that that does not correspond
final double log10OneMinusProbCall = MathUtils.approximateLog10SumLog10(MathUtils.log10SumLog10(log10Probs, 0, Math.min(callCopyNumberRange.getMinimumInteger(), log10Probs.length)), MathUtils.log10SumLog10(log10Probs, callCopyNumberRange.getMaximumInteger() + 1, log10Probs.length));
final double log10ProbTotal = MathUtils.log10SumLog10(log10Probs);
return log10OneMinusProbCall - log10ProbTotal;
}
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);
}
}
Aggregations