use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class AbstractMarkDuplicatesCommandLineProgram method trackOpticalDuplicates.
/**
* Looks through the set of reads and identifies how many of the duplicates are
* in fact optical duplicates, and stores the data in the instance level histogram.
*/
public static void trackOpticalDuplicates(List<? extends ReadEnds> ends, final OpticalDuplicateFinder opticalDuplicateFinder, final LibraryIdGenerator libraryIdGenerator) {
boolean hasFR = false, hasRF = false;
// Check to see if we have a mixture of FR/RF
for (final ReadEnds end : ends) {
if (ReadEnds.FR == end.orientationForOpticalDuplicates) {
hasFR = true;
} else if (ReadEnds.RF == end.orientationForOpticalDuplicates) {
hasRF = true;
}
}
// Check if we need to partition since the orientations could have changed
if (hasFR && hasRF) {
// need to track them independently
// Variables used for optical duplicate detection and tracking
final List<ReadEnds> trackOpticalDuplicatesF = new ArrayList<>();
final List<ReadEnds> trackOpticalDuplicatesR = new ArrayList<>();
// Split into two lists: first of pairs and second of pairs, since they must have orientation and same starting end
for (final ReadEnds end : ends) {
if (ReadEnds.FR == end.orientationForOpticalDuplicates) {
trackOpticalDuplicatesF.add(end);
} else if (ReadEnds.RF == end.orientationForOpticalDuplicates) {
trackOpticalDuplicatesR.add(end);
} else {
throw new UserException("Found an unexpected orientation: " + end.orientation);
}
}
// track the duplicates
trackOpticalDuplicates(trackOpticalDuplicatesF, opticalDuplicateFinder, libraryIdGenerator.getOpticalDuplicatesByLibraryIdMap());
trackOpticalDuplicates(trackOpticalDuplicatesR, opticalDuplicateFinder, libraryIdGenerator.getOpticalDuplicatesByLibraryIdMap());
} else {
// No need to partition
AbstractMarkDuplicatesCommandLineProgram.trackOpticalDuplicates(ends, opticalDuplicateFinder, libraryIdGenerator.getOpticalDuplicatesByLibraryIdMap());
}
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class GATKReport method loadReport.
/**
* Load a GATKReport from a {@link Reader}
*
* @param in the reader to load from
*/
private void loadReport(Reader in) {
BufferedReader reader = new BufferedReader(in);
String reportHeader;
try {
reportHeader = reader.readLine();
} catch (IOException e) {
throw new UserException("Could not read " + RECAL_FILE, e);
}
if (reportHeader == null) {
throw new UserException(RECAL_FILE + " is empty.");
}
// Read the first line for the version and number of tables.
version = GATKReportVersion.fromHeader(reportHeader);
if (version.equals(GATKReportVersion.V0_1) || version.equals(GATKReportVersion.V0_2))
throw new UserException("The GATK no longer supports reading legacy GATK Reports. Please use v1.0 or newer.");
int nTables = Integer.parseInt(reportHeader.split(":")[2]);
// Read each table according ot the number of tables
for (int i = 0; i < nTables; i++) {
addTable(new GATKReportTable(reader, version));
}
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk-protected by broadinstitute.
the class ReadCountCollectionUtils method writeReadCountsFromSimpleInterval.
/**
* Write a read counts file of targets with coverage to file with dummy names
* @param outWriter Writer to write targets with coverage. Never {@code null}
* @param outName Name of the output writer. Never {@code null}
* @param sampleName Name of sample being written. Never {@code null}
* @param byKeySorted Map of simple-intervals to their copy-ratio. Never {@code null}
* @param comments Comments to add to header of coverage file.
*/
public static <N extends Number> void writeReadCountsFromSimpleInterval(final Writer outWriter, final String outName, final String sampleName, final SortedMap<SimpleInterval, N> byKeySorted, final String[] comments) {
Utils.nonNull(outWriter, "Output writer cannot be null.");
Utils.nonNull(sampleName, "Sample name cannot be null.");
Utils.nonNull(byKeySorted, "Targets cannot be null.");
Utils.nonNull(comments, "Comments cannot be null.");
final boolean areTargetIntervalsAllPopulated = byKeySorted.keySet().stream().allMatch(t -> t != null);
if (!areTargetIntervalsAllPopulated) {
throw new UserException("Cannot write target coverage file with any null intervals.");
}
try (final TableWriter<ReadCountRecord> writer = writerWithIntervals(outWriter, Collections.singletonList(sampleName))) {
for (String comment : comments) {
writer.writeComment(comment);
}
for (final Locatable locatable : byKeySorted.keySet()) {
final SimpleInterval interval = new SimpleInterval(locatable);
final double coverage = byKeySorted.get(locatable).doubleValue();
writer.writeRecord(new ReadCountRecord.SingleSampleRecord(new Target(interval), coverage));
}
} catch (final IOException e) {
throw new UserException.CouldNotCreateOutputFile(outName, e);
}
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class ConvertHeaderlessHadoopBamShardToBam method doWork.
@Override
protected Object doWork() {
SAMFileHeader header = null;
try (final SamReader headerReader = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT).open(bamWithHeader)) {
header = headerReader.getFileHeader();
} catch (IOException e) {
throw new UserException("Error reading header from " + bamWithHeader.getAbsolutePath(), e);
}
SparkUtils.convertHeaderlessHadoopBamShardToBam(bamShard, header, outputBam);
return null;
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class IntervalArgumentCollection method parseIntervals.
private void parseIntervals(final GenomeLocParser genomeLocParser) {
// return if no interval arguments at all
if (!intervalsSpecified()) {
throw new GATKException("Cannot call parseIntervals() without specifying either intervals to include or exclude.");
}
GenomeLocSortedSet includeSortedSet;
if (getIntervalStrings().isEmpty()) {
// the -L argument isn't specified, which means that -XL was, since we checked intervalsSpecified()
// therefore we set the include set to be the entire reference territory
includeSortedSet = GenomeLocSortedSet.createSetFromSequenceDictionary(genomeLocParser.getSequenceDictionary());
} else {
try {
includeSortedSet = IntervalUtils.loadIntervals(getIntervalStrings(), intervalSetRule, intervalMerging, intervalPadding, genomeLocParser);
} catch (UserException.EmptyIntersection e) {
throw new CommandLineException.BadArgumentValue("-L, --interval_set_rule", getIntervalStrings() + "," + intervalSetRule, "The specified intervals had an empty intersection");
}
}
final GenomeLocSortedSet excludeSortedSet = IntervalUtils.loadIntervals(excludeIntervalStrings, IntervalSetRule.UNION, intervalMerging, intervalExclusionPadding, genomeLocParser);
if (excludeSortedSet.contains(GenomeLoc.UNMAPPED)) {
throw new UserException("-XL unmapped is not currently supported");
}
GenomeLocSortedSet intervals;
// if no exclude arguments, can return the included set directly
if (excludeSortedSet.isEmpty()) {
intervals = includeSortedSet;
} else // otherwise there are exclude arguments => must merge include and exclude GenomeLocSortedSets
{
intervals = includeSortedSet.subtractRegions(excludeSortedSet);
if (intervals.isEmpty()) {
throw new CommandLineException.BadArgumentValue("-L,-XL", getIntervalStrings().toString() + ", " + excludeIntervalStrings.toString(), "The intervals specified for exclusion with -XL removed all territory specified by -L.");
}
// logging messages only printed when exclude (-XL) arguments are given
final long toPruneSize = includeSortedSet.coveredSize();
final long toExcludeSize = excludeSortedSet.coveredSize();
final long intervalSize = intervals.coveredSize();
logger.info(String.format("Initial include intervals span %d loci; exclude intervals span %d loci", toPruneSize, toExcludeSize));
logger.info(String.format("Excluding %d loci from original intervals (%.2f%% reduction)", toPruneSize - intervalSize, (toPruneSize - intervalSize) / (0.01 * toPruneSize)));
}
logger.info(String.format("Processing %d bp from intervals", intervals.coveredSize()));
// Separate out requests for unmapped records from the rest of the intervals.
boolean traverseUnmapped = false;
if (intervals.contains(GenomeLoc.UNMAPPED)) {
traverseUnmapped = true;
intervals.remove(GenomeLoc.UNMAPPED);
}
traversalParameters = new TraversalParameters(IntervalUtils.convertGenomeLocsToSimpleIntervals(intervals.toList()), traverseUnmapped);
}
Aggregations