Search in sources :

Example 86 with UserException

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

the class GenomicsDBImport method overwriteOrCreateWorkspace.

/**
     * Input argument "overwriteExistingWorkspace" defaults to false.
     * The tool creates a new workspace if it doesn't exist. Deletes
     * an existing workspace if argument is true
     *
     * @return  The workspace directory
     */
private File overwriteOrCreateWorkspace() {
    final File workspaceDir = new File(workspace);
    if (overwriteExistingWorkspace) {
        IOUtils.tryDelete(workspaceDir);
    }
    if (!workspaceDir.exists()) {
        final int ret = GenomicsDBImporter.createTileDBWorkspace(workspaceDir.getAbsolutePath());
        if (ret > 0) {
            checkIfValidWorkspace(workspaceDir);
            logger.info("Importing data to GenomicsDB workspace: " + workspaceDir);
        } else if (ret < 0) {
            throw new UserException("Error creating GenomicsDB workspace: " + workspaceDir);
        }
    } else {
        // Check whether its a valid workspace
        checkIfValidWorkspace(workspaceDir);
    }
    return workspaceDir;
}
Also used : UserException(org.broadinstitute.hellbender.exceptions.UserException) File(java.io.File)

Example 87 with UserException

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

the class GenomicsDBImport method traverse.

/**
     * A complete traversal from start to finish. This method will import all samples
     * specified in the input GVCF files.
     */
@Override
public void traverse() {
    // Force the progress meter to update after every batch
    progressMeter.setRecordsBetweenTimeChecks(1L);
    final int sampleCount = sampleNameToVcfUri.size();
    final int updatedBatchSize = (batchSize == DEFAULT_ZERO_BATCH_SIZE) ? sampleCount : batchSize;
    final int totalBatchCount = (sampleCount / updatedBatchSize) + (sampleCount % updatedBatchSize == 0 ? 0 : 1);
    GenomicsDBImporter importer;
    for (int i = 0, batchCount = 1; i < sampleCount; i += updatedBatchSize, ++batchCount) {
        final Map<String, FeatureReader<VariantContext>> sampleToReaderMap = getFeatureReaders(new ArrayList<>(sampleNameToVcfUri.keySet()), sampleNameToVcfUri, updatedBatchSize, sampleCount, i);
        logger.info("Importing batch " + batchCount + " with " + sampleToReaderMap.size() + " samples");
        final long variantContextBufferSize = vcfBufferSizePerSample * sampleToReaderMap.size();
        final GenomicsDBImportConfiguration.ImportConfiguration importConfiguration = createImportConfiguration(workspace, GenomicsDBConstants.DEFAULT_ARRAY_NAME, variantContextBufferSize, segmentSize, i, (i + updatedBatchSize - 1));
        try {
            importer = new GenomicsDBImporter(sampleToReaderMap, mergedHeaderLines, intervals.get(0), importConfiguration);
        } catch (final IOException e) {
            throw new UserException("Error initializing GenomicsDBImporter in batch " + batchCount, e);
        }
        try {
            importer.importBatch();
        } catch (final IOException e) {
            throw new UserException("GenomicsDB import failed in batch " + batchCount, e);
        }
        closeReaders(sampleToReaderMap);
        progressMeter.update(intervals.get(0));
        logger.info("Done importing batch " + batchCount + "/" + totalBatchCount);
    }
}
Also used : GenomicsDBImporter(com.intel.genomicsdb.GenomicsDBImporter) GenomicsDBImportConfiguration(com.intel.genomicsdb.GenomicsDBImportConfiguration) IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException) FeatureReader(htsjdk.tribble.FeatureReader) AbstractFeatureReader(htsjdk.tribble.AbstractFeatureReader)

Example 88 with UserException

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

the class GenomicsDBImport method initializeHeaderAndSampleMappings.

/**
     * sets the values of mergedHeaderLines, mergedHeaderSequenceDictionary, and sampleNameToVcfUri
     */
private void initializeHeaderAndSampleMappings() {
    // Only one of -V and --sampleNameMapFile may be specified
    if (sampleNameMapFile == null) {
        // -V was specified
        final List<VCFHeader> headers = new ArrayList<>(variantPaths.size());
        for (final String variantPath : variantPaths) {
            final VCFHeader header = loadHeaderFromVCFUri(variantPath);
            Utils.validate(header != null, "Null header was found in " + variantPath + ".");
            assertGVCFHasOnlyOneSample(variantPath, header);
            headers.add(header);
            final String sampleName = header.getGenotypeSamples().get(0);
            final String previousPath = sampleNameToVcfUri.put(sampleName, variantPath);
            if (previousPath != null) {
                throw new UserException("Duplicate sample: " + sampleName + ". Sample was found in both " + variantPath + " and " + previousPath + ".");
            }
        }
        mergedHeaderLines = VCFUtils.smartMergeHeaders(headers, true);
        mergedHeaderSequenceDictionary = new VCFHeader(mergedHeaderLines).getSequenceDictionary();
    } else {
        // --sampleNameMap was specified
        sampleNameToVcfUri = loadSampleNameMapFile(IOUtils.getPath(sampleNameMapFile));
        final String firstHeaderPath = sampleNameToVcfUri.entrySet().iterator().next().getValue();
        final VCFHeader header = loadHeaderFromVCFUri(firstHeaderPath);
        mergedHeaderLines = header.getMetaDataInInputOrder();
        mergedHeaderSequenceDictionary = header.getSequenceDictionary();
    }
    if (mergedHeaderSequenceDictionary == null) {
        throw new UserException("The merged vcf header has no sequence dictionary. Please provide a header that contains a sequence dictionary.");
    }
}
Also used : UserException(org.broadinstitute.hellbender.exceptions.UserException) VCFHeader(htsjdk.variant.vcf.VCFHeader)

Example 89 with UserException

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

the class AbstractMarkDuplicatesCommandLineProgram method openInputs.

/**
     * Since this may read it's inputs more than once this method does all the opening
     * and checking of the inputs.
     */
protected SamHeaderAndIterator openInputs() {
    final List<SAMFileHeader> headers = new ArrayList<>(INPUT.size());
    final List<SamReader> readers = new ArrayList<>(INPUT.size());
    for (final File f : INPUT) {
        final SamReader reader = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.EAGERLY_DECODE).referenceSequence(REFERENCE_SEQUENCE).open(// eager decode
        f);
        final SAMFileHeader header = reader.getFileHeader();
        if (!ASSUME_SORTED && header.getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
            throw new UserException("Input file " + f.getAbsolutePath() + " is not coordinate sorted.");
        }
        headers.add(header);
        readers.add(reader);
    }
    if (headers.size() == 1) {
        return new SamHeaderAndIterator(headers.get(0), readers.get(0).iterator(), readers);
    } else {
        final SamFileHeaderMerger headerMerger = new SamFileHeaderMerger(SAMFileHeader.SortOrder.coordinate, headers, false);
        final MergingSamRecordIterator iterator = new MergingSamRecordIterator(headerMerger, readers, ASSUME_SORTED);
        return new SamHeaderAndIterator(headerMerger.getMergedHeader(), iterator, readers);
    }
}
Also used : UserException(org.broadinstitute.hellbender.exceptions.UserException) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File)

Example 90 with UserException

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

the class Main method mainEntry.

/**
     * The entry point to the toolkit from commandline: it uses {@link #instanceMain(String[])} to run the command line
     * program and handle the returned object with {@link #handleResult(Object)}, and exit with 0.
     * If any error occurs, it handles the exception (if non-user exception, through {@link #handleNonUserException(Exception)})
     * and exit with the concrete error exit value.
     *
     * Note: this is the only method that is allowed to call System.exit (because gatk tools may be run from test harness etc)
     */
protected final void mainEntry(final String[] args) {
    final CommandLineProgram program = extractCommandLineProgram(args, getPackageList(), getClassList(), getCommandLineName());
    try {
        final Object result = runCommandLineProgram(program, args);
        handleResult(result);
        System.exit(0);
    } catch (final CommandLineException e) {
        System.err.println(program.getUsage());
        handleUserException(e);
        System.exit(COMMANDLINE_EXCEPTION_EXIT_VALUE);
    } catch (final UserException e) {
        handleUserException(e);
        System.exit(USER_EXCEPTION_EXIT_VALUE);
    } catch (final StorageException e) {
        handleStorageException(e);
        System.exit(ANY_OTHER_EXCEPTION_EXIT_VALUE);
    } catch (final Exception e) {
        handleNonUserException(e);
        System.exit(ANY_OTHER_EXCEPTION_EXIT_VALUE);
    }
}
Also used : CommandLineProgram(org.broadinstitute.hellbender.cmdline.CommandLineProgram) UserException(org.broadinstitute.hellbender.exceptions.UserException) StorageException(com.google.cloud.storage.StorageException) CommandLineException(org.broadinstitute.barclay.argparser.CommandLineException) UserException(org.broadinstitute.hellbender.exceptions.UserException) StorageException(com.google.cloud.storage.StorageException) CommandLineException(org.broadinstitute.barclay.argparser.CommandLineException)

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