use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class ApplyVQSR method trancheIntervalIsValid.
private boolean trancheIntervalIsValid(final String sensitivityLimits) {
final String[] vals = sensitivityLimits.split("to");
if (vals.length != 2)
return false;
try {
double lowerLimit = Double.parseDouble(vals[0]);
//why does our last tranche end with 100+? Is there anything greater than 100 percent? Really???
double upperLimit = Double.parseDouble(vals[1].replace("+", ""));
} catch (NumberFormatException e) {
throw new UserException("Poorly formatted tranche filter name does not contain two sensitivity interval end points.");
}
return true;
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class ApplyVQSR method doSiteSpecificFiltering.
/**
* Calculate the filter status for a given VariantContext using the combined data from all alleles at a site
* @param vc
* @param recals
* @param builder is modified by adding attributes
* @return a String with the filter status for this site
*/
private String doSiteSpecificFiltering(final VariantContext vc, final List<VariantContext> recals, final VariantContextBuilder builder) {
VariantContext recalDatum = getMatchingRecalVC(vc, recals, null);
if (recalDatum == null) {
throw new UserException("Encountered input variant which isn't found in the input recal file. Please make sure VariantRecalibrator and ApplyRecalibration were run on the same set of input variants. First seen at: " + vc);
}
final String lodString = recalDatum.getAttributeAsString(GATKVCFConstants.VQS_LOD_KEY, null);
if (lodString == null) {
throw new UserException("Encountered a malformed record in the input recal file. There is no lod for the record at: " + vc);
}
final double lod;
try {
lod = Double.valueOf(lodString);
} catch (NumberFormatException e) {
throw new UserException("Encountered a malformed record in the input recal file. The lod is unreadable for the record at: " + vc);
}
builder.attribute(GATKVCFConstants.VQS_LOD_KEY, lod);
builder.attribute(GATKVCFConstants.CULPRIT_KEY, recalDatum.getAttribute(GATKVCFConstants.CULPRIT_KEY));
if (recalDatum != null) {
if (recalDatum.hasAttribute(GATKVCFConstants.POSITIVE_LABEL_KEY))
builder.attribute(GATKVCFConstants.POSITIVE_LABEL_KEY, true);
if (recalDatum.hasAttribute(GATKVCFConstants.NEGATIVE_LABEL_KEY))
builder.attribute(GATKVCFConstants.NEGATIVE_LABEL_KEY, true);
}
return generateFilterString(lod);
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class Concordance method onTraversalSuccess.
@Override
public Object onTraversalSuccess() {
try (ConcordanceSummaryRecord.Writer concordanceSummaryWriter = ConcordanceSummaryRecord.getWriter(summary)) {
concordanceSummaryWriter.writeRecord(new ConcordanceSummaryRecord(VariantContext.Type.SNP, snpCounts.get(ConcordanceState.TRUE_POSITIVE).longValue(), snpCounts.get(ConcordanceState.FALSE_POSITIVE).longValue(), snpCounts.get(ConcordanceState.FALSE_NEGATIVE).longValue() + snpCounts.get(ConcordanceState.FILTERED_FALSE_NEGATIVE).longValue()));
concordanceSummaryWriter.writeRecord(new ConcordanceSummaryRecord(VariantContext.Type.INDEL, indelCounts.get(ConcordanceState.TRUE_POSITIVE).longValue(), indelCounts.get(ConcordanceState.FALSE_POSITIVE).longValue(), indelCounts.get(ConcordanceState.FALSE_NEGATIVE).longValue() + indelCounts.get(ConcordanceState.FILTERED_FALSE_NEGATIVE).longValue()));
} catch (IOException e) {
throw new UserException("Encountered an IO exception writing the concordance summary table", e);
}
if (truePositivesAndFalsePositivesVcfWriter != null) {
truePositivesAndFalsePositivesVcfWriter.close();
}
if (truePositivesAndFalseNegativesVcfWriter != null) {
truePositivesAndFalseNegativesVcfWriter.close();
}
if (filteredTrueNegativesAndFalseNegativesVcfWriter != null) {
filteredTrueNegativesAndFalseNegativesVcfWriter.close();
}
return "SUCCESS";
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class CalculateGenotypePosteriors method onTraversalStart.
@Override
public void onTraversalStart() {
final VariantContextWriterBuilder builder = new VariantContextWriterBuilder().setOutputFile(out).setOutputFileType(VariantContextWriterBuilder.OutputType.VCF);
if (hasReference()) {
vcfWriter = builder.setReferenceDictionary(getBestAvailableSequenceDictionary()).setOption(Options.INDEX_ON_THE_FLY).build();
} else {
vcfWriter = builder.unsetOption(Options.INDEX_ON_THE_FLY).build();
logger.info("Can't make an index for output file " + out + " because a reference dictionary is required for creating Tribble indices on the fly");
}
sampleDB = initializeSampleDB();
// Get list of samples to include in the output
final Map<String, VCFHeader> vcfHeaders = Collections.singletonMap(getDrivingVariantsFeatureInput().getName(), getHeaderForVariants());
final Set<String> vcfSamples = VcfUtils.getSortedSampleSet(vcfHeaders, GATKVariantContextUtils.GenotypeMergeType.REQUIRE_UNIQUE);
//Get the trios from the families passed as ped
if (!skipFamilyPriors) {
final Set<Trio> trios = sampleDB.getTrios();
if (trios.isEmpty()) {
logger.info("No PED file passed or no *non-skipped* trios found in PED file. Skipping family priors.");
skipFamilyPriors = true;
}
}
final VCFHeader header = vcfHeaders.values().iterator().next();
if (!header.hasGenotypingData()) {
throw new UserException("VCF has no genotypes");
}
if (header.hasInfoLine(GATKVCFConstants.MLE_ALLELE_COUNT_KEY)) {
final VCFInfoHeaderLine mleLine = header.getInfoHeaderLine(GATKVCFConstants.MLE_ALLELE_COUNT_KEY);
if (mleLine.getCountType() != VCFHeaderLineCount.A) {
throw new UserException("VCF does not have a properly formatted MLEAC field: the count type should be \"A\"");
}
if (mleLine.getType() != VCFHeaderLineType.Integer) {
throw new UserException("VCF does not have a properly formatted MLEAC field: the field type should be \"Integer\"");
}
}
// Initialize VCF header
final Set<VCFHeaderLine> headerLines = VCFUtils.smartMergeHeaders(vcfHeaders.values(), true);
headerLines.add(GATKVCFHeaderLines.getFormatLine(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY));
headerLines.add(GATKVCFHeaderLines.getInfoLine(GATKVCFConstants.GENOTYPE_PRIOR_KEY));
if (!skipFamilyPriors) {
headerLines.add(GATKVCFHeaderLines.getFormatLine(GATKVCFConstants.JOINT_LIKELIHOOD_TAG_NAME));
headerLines.add(GATKVCFHeaderLines.getFormatLine(GATKVCFConstants.JOINT_POSTERIOR_TAG_NAME));
}
headerLines.addAll(getDefaultToolVCFHeaderLines());
vcfWriter.writeHeader(new VCFHeader(headerLines, vcfSamples));
final Map<String, Set<Sample>> families = sampleDB.getFamilies(vcfSamples);
famUtils = new FamilyLikelihoods(sampleDB, deNovoPrior, vcfSamples, families);
}
use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.
the class GenomeLocParser method parseGenomeLoc.
// --------------------------------------------------------------------------------------------------------------
//
// Parsing genome locs
//
// --------------------------------------------------------------------------------------------------------------
/**
* parse a genome interval, from a location string
*
* Performs interval-style validation:
*
* contig is valid; start and stop less than the end; start <= stop, and start/stop are on the contig
* @param str the string to parse
*
* @return a GenomeLoc representing the String
*
*/
public GenomeLoc parseGenomeLoc(final String str) {
try {
if (isUnmappedGenomeLocString(str)) {
return GenomeLoc.UNMAPPED;
}
final Locatable locatable = new SimpleInterval(str);
final String contig = locatable.getContig();
final int start = locatable.getStart();
int stop = locatable.getEnd();
if (!contigIsInDictionary(contig)) {
throw new UserException.MalformedGenomeLoc("Contig '" + contig + "' does not match any contig in the GATK sequence dictionary derived from the reference; are you sure you are using the correct reference fasta file?");
}
if (stop == Integer.MAX_VALUE) {
// lookup the actual stop position!
stop = getContigInfo(contig).getSequenceLength();
}
return createGenomeLoc(contig, getContigIndex(contig), start, stop, true);
} catch (UserException.MalformedGenomeLoc e) {
throw e;
} catch (IllegalArgumentException | UserException e) {
throw new UserException.MalformedGenomeLoc("Failed to parse Genome Location string: " + str + ": " + e.getMessage(), e);
}
}
Aggregations