Search in sources :

Example 1 with UserException

use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.

the class ConvertACNVResults method runPipeline.

@Override
protected void runPipeline(final JavaSparkContext ctx) {
    final String originalLogLevel = (ctx.getLocalProperty("logLevel") != null) ? ctx.getLocalProperty("logLevel") : "INFO";
    ctx.setLogLevel("WARN");
    final CNLOHCaller cnlohCaller = new CNLOHCaller();
    cnlohCaller.setRhoThreshold(rhoThreshold);
    final List<ACNVModeledSegment> segments = SegmentUtils.readACNVModeledSegmentFile(new File(segmentsFile));
    String sampleName = determineSampleName(new File(segmentsFile));
    // Create the outputdir
    try {
        FileUtils.forceMkdir(outputDir);
    } catch (final IOException ioe) {
        throw new UserException("Cannot create " + outputDir + ".  Does a file (not directory) exist with the same name?  Do you have access to create?", ioe);
    }
    final Genome genome = new Genome(targetCoveragesFile, snpCountsFile);
    // Make the calls
    logger.info("Making the balanced-segment (and CNLoH) calls...");
    final List<AllelicCalls> calls = cnlohCaller.makeCalls(segments, numIterations, ctx);
    // Write updated ACNV file with calls
    logger.info("Writing updated ACNV file with calls ...");
    final File finalACNVModeledSegmentsFile = new File(outputDir, getSegmentsBaseFilename() + "." + BALANCED_SEG_FILE_TAG + ".seg");
    SegmentUtils.writeCnLoHACNVModeledSegmentFile(finalACNVModeledSegmentsFile, calls, genome);
    // write file for GATK CNV formatted seg file
    logger.info("Writing file with same output format as GATK CNV...");
    final File finalModeledSegmentsFileAsGatkCNV = new File(outputDir, getSegmentsBaseFilename() + "." + GATK_SEG_FILE_TAG + ".seg");
    SegmentUtils.writeModeledSegmentFile(finalModeledSegmentsFileAsGatkCNV, ACNVModeledSegmentConversionUtils.convertACNVModeledSegmentsToModeledSegments(segments, genome), sampleName);
    //write file for ACS-compatible output to help Broad CGA
    logger.info("Writing file with same output format as Broad CGA Allelic CapSeg ...");
    final File finalACSModeledSegmentsFile = new File(outputDir, getSegmentsBaseFilename() + "." + CGA_ACS_SEG_FILE_TAG + ".seg");
    ACSModeledSegmentUtils.writeACNVModeledSegmentFileAsAllelicCapSegFile(finalACSModeledSegmentsFile, calls, genome);
    //write files for TITAN-compatible output to help Broad CGA
    logger.info("Writing het file with input format for TITAN ...");
    final File finalTitanHetFile = new File(outputDir, getSegmentsBaseFilename() + "." + TITAN_HET_FILE_TAG + ".tsv");
    TitanFileConverter.convertHetPulldownToTitanHetFile(snpCountsFile, finalTitanHetFile);
    logger.info("Writing tangent-normalized target CR estimates with input format for TITAN ...");
    final File finalTitanTNFile = new File(outputDir, getSegmentsBaseFilename() + "." + TITAN_TN_FILE_TAG + ".tsv");
    TitanFileConverter.convertCRToTitanCovFile(targetCoveragesFile, finalTitanTNFile);
    ctx.setLogLevel(originalLogLevel);
    logger.info("SUCCESS: CNLoH and splits called for sample " + sampleName + ".");
}
Also used : IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException) CNLOHCaller(org.broadinstitute.hellbender.tools.exome.conversion.allelicbalancecaller.CNLOHCaller) File(java.io.File) AllelicCalls(org.broadinstitute.hellbender.tools.exome.conversion.allelicbalancecaller.AllelicCalls)

Example 2 with UserException

use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.

the class FilterByOrientationBias method onTraversalStart.

@Override
public void onTraversalStart() {
    // Gets around issue 2274 in gatk public
    if (transitions.size() == 0) {
        transitions.add(DEFAULT_ARTIFACT_MODE);
    }
    // Sort the input artifacts argument
    transitions.sort(null);
    final MetricsFile<SequencingArtifactMetrics.PreAdapterDetailMetrics, Comparable<?>> mf = new MetricsFile<>();
    try {
        mf.read(new FileReader(preAdapterMetricsFile));
    } catch (final FileNotFoundException fnfe) {
        throw new UserException("Could not find file: " + preAdapterMetricsFile.getAbsolutePath());
    }
    // Collect all of the transitions that were specified in the parameters.
    relevantTransitions.addAll(transitions.stream().map(s -> convertParameterToTransition(s)).collect(Collectors.toSet()));
    // Get the PreAdapterQ score from the picard metrics tool, which gives an indication of how badly infested the bam file is.
    transitionToPreAdapterScoreMap = PreAdapterOrientationScorer.scoreOrientationBiasMetricsOverContext(mf.getMetrics());
    logger.info("preAdapter scores:");
    transitionToPreAdapterScoreMap.keySet().stream().forEach(k -> logger.info(k + ": " + transitionToPreAdapterScoreMap.get(k)));
    setupVCFWriter();
}
Also used : MetricsFile(htsjdk.samtools.metrics.MetricsFile) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) UserException(org.broadinstitute.hellbender.exceptions.UserException)

Example 3 with UserException

use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.

the class FindBreakpointEvidenceSpark method readCrossContigsToIgnoreFile.

/** Read a file of contig names that will be ignored when checking for inter-contig pairs. */
private static Set<Integer> readCrossContigsToIgnoreFile(final String crossContigsToIgnoreFile, final SAMSequenceDictionary dictionary) {
    final Set<Integer> ignoreSet = new HashSet<>();
    try (final BufferedReader rdr = new BufferedReader(new InputStreamReader(BucketUtils.openFile(crossContigsToIgnoreFile)))) {
        String line;
        while ((line = rdr.readLine()) != null) {
            final int tigId = dictionary.getSequenceIndex(line);
            if (tigId == -1) {
                throw new UserException("crossContigToIgnoreFile contains an unrecognized contig name: " + line);
            }
            ignoreSet.add(tigId);
        }
    } catch (final IOException ioe) {
        throw new UserException("Can't read crossContigToIgnore file " + crossContigsToIgnoreFile, ioe);
    }
    return ignoreSet;
}
Also used : UserException(org.broadinstitute.hellbender.exceptions.UserException)

Example 4 with UserException

use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.

the class CompareBaseQualities method doWork.

@Override
protected Object doWork() {
    if (roundDown && (staticQuantizationQuals == null || staticQuantizationQuals.isEmpty())) {
        throw new CommandLineException.BadArgumentValue("round_down_quantized", "true", "This option can only be used if static_quantized_quals is also used");
    }
    staticQuantizedMapping = constructStaticQuantizedMapping(staticQuantizationQuals, roundDown);
    IOUtil.assertFileIsReadable(samFiles.get(0));
    IOUtil.assertFileIsReadable(samFiles.get(1));
    final SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(VALIDATION_STRINGENCY);
    final SamReader reader1 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(0));
    final SamReader reader2 = factory.referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(1));
    final SecondaryOrSupplementarySkippingIterator it1 = new SecondaryOrSupplementarySkippingIterator(reader1.iterator());
    final SecondaryOrSupplementarySkippingIterator it2 = new SecondaryOrSupplementarySkippingIterator(reader2.iterator());
    final CompareMatrix finalMatrix = new CompareMatrix(staticQuantizedMapping);
    final ProgressMeter progressMeter = new ProgressMeter(1.0);
    progressMeter.start();
    while (it1.hasCurrent() && it2.hasCurrent()) {
        final SAMRecord read1 = it1.getCurrent();
        final SAMRecord read2 = it2.getCurrent();
        progressMeter.update(read1);
        if (!read1.getReadName().equals(read2.getReadName())) {
            throw new UserException.BadInput("files do not have the same exact order of reads:" + read1.getReadName() + " vs " + read2.getReadName());
        }
        finalMatrix.add(read1.getBaseQualities(), read2.getBaseQualities());
        it1.advance();
        it2.advance();
    }
    progressMeter.stop();
    if (it1.hasCurrent() || it2.hasCurrent()) {
        throw new UserException.BadInput("files do not have the same exact number of reads");
    }
    CloserUtil.close(reader1);
    CloserUtil.close(reader2);
    finalMatrix.printOutResults(outputFilename);
    if (throwOnDiff && finalMatrix.hasNonDiagonalElements()) {
        throw new UserException("Quality scores from the two BAMs do not match");
    }
    return finalMatrix.hasNonDiagonalElements() ? 1 : 0;
}
Also used : SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) ProgressMeter(org.broadinstitute.hellbender.engine.ProgressMeter) SAMRecord(htsjdk.samtools.SAMRecord) SecondaryOrSupplementarySkippingIterator(htsjdk.samtools.SecondaryOrSupplementarySkippingIterator) UserException(org.broadinstitute.hellbender.exceptions.UserException)

Example 5 with UserException

use of org.broadinstitute.hellbender.exceptions.UserException in project gatk by broadinstitute.

the class RecalibrationReport method initializeArgumentCollectionTable.

/**
     * Parses the arguments table from the GATK Report and creates a RAC object with the proper initialization values
     *
     * @param table the GATKReportTable containing the arguments and its corresponding values
     * @return a RAC object properly initialized with all the objects in the table
     */
private static RecalibrationArgumentCollection initializeArgumentCollectionTable(GATKReportTable table) {
    final RecalibrationArgumentCollection RAC = new RecalibrationArgumentCollection();
    final List<String> standardCovariateClassNames = new StandardCovariateList(RAC, Collections.emptyList()).getStandardCovariateClassNames();
    for (int i = 0; i < table.getNumRows(); i++) {
        final String argument = table.get(i, "Argument").toString();
        Object value = table.get(i, RecalUtils.ARGUMENT_VALUE_COLUMN_NAME);
        if (value.equals("null")) {
            // generic translation of null values that were printed out as strings | todo -- add this capability to the GATKReport
            value = null;
        }
        if (argument.equals("covariate") && value != null) {
            final List<String> covs = new ArrayList<>(Arrays.asList(value.toString().split(",")));
            if (!covs.equals(standardCovariateClassNames)) {
                throw new UserException("Non-standard covariates are not supported. Only the following are supported " + standardCovariateClassNames + " but was " + covs);
            }
        } else if (argument.equals("no_standard_covs")) {
            final boolean no_standard_covs = decodeBoolean(value);
            if (no_standard_covs) {
                throw new UserException("Non-standard covariates are not supported. Only the following are supported " + standardCovariateClassNames + " but no_standard_covs was true");
            }
        } else if (argument.equals("solid_recal_mode")) {
            final String solid_recal_mode = (String) value;
            if (!RecalibrationArgumentCollection.SOLID_RECAL_MODE.equals(solid_recal_mode)) {
                throw new UserException("Solid is not supported. Only " + RecalibrationArgumentCollection.SOLID_RECAL_MODE + " is allowed as value for solid_recal_mode");
            }
        } else if (argument.equals("solid_nocall_strategy")) {
            final String solid_nocall_strategy = (String) value;
            if (!RecalibrationArgumentCollection.SOLID_NOCALL_STRATEGY.equals(solid_nocall_strategy)) {
                throw new UserException("Solid is not supported. Only " + RecalibrationArgumentCollection.SOLID_NOCALL_STRATEGY + " is allowed as value for solid_nocall_strategy");
            }
        } else if (argument.equals("mismatches_context_size"))
            RAC.MISMATCHES_CONTEXT_SIZE = decodeInteger(value);
        else if (argument.equals("indels_context_size"))
            RAC.INDELS_CONTEXT_SIZE = decodeInteger(value);
        else if (argument.equals("mismatches_default_quality"))
            RAC.MISMATCHES_DEFAULT_QUALITY = decodeByte(value);
        else if (argument.equals("insertions_default_quality"))
            RAC.INSERTIONS_DEFAULT_QUALITY = decodeByte(value);
        else if (argument.equals("deletions_default_quality"))
            RAC.DELETIONS_DEFAULT_QUALITY = decodeByte(value);
        else if (argument.equals("maximum_cycle_value"))
            RAC.MAXIMUM_CYCLE_VALUE = decodeInteger(value);
        else if (argument.equals("low_quality_tail"))
            RAC.LOW_QUAL_TAIL = decodeByte(value);
        else if (argument.equals("default_platform"))
            RAC.DEFAULT_PLATFORM = (String) value;
        else if (argument.equals("force_platform"))
            RAC.FORCE_PLATFORM = (String) value;
        else if (argument.equals("quantizing_levels"))
            RAC.QUANTIZING_LEVELS = decodeInteger(value);
        else if (argument.equals("recalibration_report"))
            RAC.existingRecalibrationReport = (value == null) ? null : new File((String) value);
        else if (argument.equals("binary_tag_name"))
            RAC.BINARY_TAG_NAME = (value == null) ? null : (String) value;
    }
    return RAC;
}
Also used : ArrayList(java.util.ArrayList) UserException(org.broadinstitute.hellbender.exceptions.UserException) StandardCovariateList(org.broadinstitute.hellbender.utils.recalibration.covariates.StandardCovariateList) File(java.io.File)

Aggregations

UserException (org.broadinstitute.hellbender.exceptions.UserException)100 File (java.io.File)30 IOException (java.io.IOException)30 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)14 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)11 SamReader (htsjdk.samtools.SamReader)10 VariantContext (htsjdk.variant.variantcontext.VariantContext)10 ProgressLogger (org.broadinstitute.hellbender.utils.runtime.ProgressLogger)10 SAMRecord (htsjdk.samtools.SAMRecord)9 IntervalList (htsjdk.samtools.util.IntervalList)9 List (java.util.List)9 SAMFileHeader (htsjdk.samtools.SAMFileHeader)8 ReferenceSequenceFileWalker (htsjdk.samtools.reference.ReferenceSequenceFileWalker)8 SamLocusIterator (htsjdk.samtools.util.SamLocusIterator)8 LogManager (org.apache.logging.log4j.LogManager)8 Logger (org.apache.logging.log4j.Logger)8 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)7 MetricsFile (htsjdk.samtools.metrics.MetricsFile)6 SamRecordFilter (htsjdk.samtools.filter.SamRecordFilter)5 FileNotFoundException (java.io.FileNotFoundException)5