Search in sources :

Example 1 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class Target method calculateDistance.

/**
     * Calculate the distance between two targets.
     * <p>
     * If both targets map to different chromosomes then we return {@link Double#POSITIVE_INFINITY}.
     * </p>
     * <p>
     * Otherwise, the distance returned is the distance between their centers. This method
     * works regardless of the targets' relative positions.
     * </p>
     * @param fromTarget the previous target.
     * @param toTarget the next target.
     * @return any values between 0 and {@link Double#POSITIVE_INFINITY}.
     * @throws NullPointerException if any of the targets is {@code null}.
     * @throws IllegalArgumentException if the {@link SimpleInterval} in any of the targets is {@code null}
     */
public static double calculateDistance(final Target fromTarget, final Target toTarget) {
    final SimpleInterval fromInterval = fromTarget.getInterval();
    final SimpleInterval toInterval = toTarget.getInterval();
    Utils.validateArg(fromInterval != null && toInterval != null, () -> String.format("Either the departure target" + " (%s) or the destination target (%s) has missing interval annotation and the distance" + " between can not be calculated", fromTarget.toString(), toTarget.toString()));
    if (!fromInterval.getContig().equals(toInterval.getContig())) {
        return Double.POSITIVE_INFINITY;
    } else {
        final double toMidpoint = (toInterval.getStart() + toInterval.getEnd()) / 2;
        final double fromMidpoint = (fromInterval.getStart() + fromInterval.getEnd()) / 2;
        return Math.abs(toMidpoint - fromMidpoint);
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 2 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class AlleleFractionLikelihoods method hetLogLikelihood.

/**
     * Computes {@link AlleleFractionLikelihoods#hetLogLikelihood} using allelic-bias priors derived from an
     * {@link AllelicPanelOfNormals}.  See docs/CNVs/CNV-methods.pdf for details.
     */
public static double hetLogLikelihood(final AlleleFractionGlobalParameters parameters, final double minorFraction, final AllelicCount count, final AlleleFractionIndicator indicator, final AllelicPanelOfNormals allelicPoN) {
    final SimpleInterval site = count.getInterval();
    final double alpha = allelicPoN.equals(AllelicPanelOfNormals.EMPTY_PON) ? parameters.getAlpha() : allelicPoN.getAlpha(site);
    final double beta = allelicPoN.equals(AllelicPanelOfNormals.EMPTY_PON) ? parameters.getBeta() : allelicPoN.getBeta(site);
    final double pi = parameters.getOutlierProbability();
    final int a = count.getAltReadCount();
    final int r = count.getRefReadCount();
    return hetLogLikelihood(alpha, beta, minorFraction, pi, indicator, a, r);
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 3 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class BaseRecalibratorSparkSharded method runPipeline.

@Override
protected void runPipeline(JavaSparkContext ctx) {
    if (readArguments.getReadFilesNames().size() != 1) {
        throw new UserException("Sorry, we only support a single reads input for now.");
    }
    final String bam = readArguments.getReadFilesNames().get(0);
    final String referenceURL = referenceArguments.getReferenceFileName();
    auth = getAuthHolder();
    final ReferenceMultiSource rds = new ReferenceMultiSource(auth, referenceURL, BaseRecalibrationEngine.BQSR_REFERENCE_WINDOW_FUNCTION);
    SAMFileHeader readsHeader = new ReadsSparkSource(ctx, readArguments.getReadValidationStringency()).getHeader(bam, referenceURL);
    final SAMSequenceDictionary readsDictionary = readsHeader.getSequenceDictionary();
    final SAMSequenceDictionary refDictionary = rds.getReferenceSequenceDictionary(readsDictionary);
    final ReadFilter readFilterToApply = ReadFilter.fromList(BaseRecalibrator.getStandardBQSRReadFilterList(), readsHeader);
    SequenceDictionaryUtils.validateDictionaries("reference", refDictionary, "reads", readsDictionary);
    Broadcast<SAMFileHeader> readsHeaderBcast = ctx.broadcast(readsHeader);
    Broadcast<SAMSequenceDictionary> refDictionaryBcast = ctx.broadcast(refDictionary);
    List<SimpleInterval> intervals = intervalArgumentCollection.intervalsSpecified() ? intervalArgumentCollection.getIntervals(readsHeader.getSequenceDictionary()) : IntervalUtils.getAllIntervalsForReference(readsHeader.getSequenceDictionary());
    List<String> localVariants = knownVariants;
    localVariants = hackilyCopyFromGCSIfNecessary(localVariants);
    List<GATKVariant> variants = VariantsSource.getVariantsList(localVariants);
    // get reads, reference, variants
    JavaRDD<ContextShard> readsWithContext = AddContextDataToReadSparkOptimized.add(ctx, intervals, bam, variants, readFilterToApply, rds);
    // run BaseRecalibratorEngine.
    BaseRecalibratorEngineSparkWrapper recal = new BaseRecalibratorEngineSparkWrapper(readsHeaderBcast, refDictionaryBcast, bqsrArgs);
    JavaRDD<RecalibrationTables> tables = readsWithContext.mapPartitions(s -> recal.apply(s));
    final RecalibrationTables emptyRecalibrationTable = new RecalibrationTables(new StandardCovariateList(bqsrArgs, readsHeader));
    final RecalibrationTables table = tables.treeAggregate(emptyRecalibrationTable, RecalibrationTables::inPlaceCombine, RecalibrationTables::inPlaceCombine, Math.max(1, (int) (Math.log(tables.partitions().size()) / Math.log(2))));
    BaseRecalibrationEngine.finalizeRecalibrationTables(table);
    try {
        BaseRecalibratorEngineSparkWrapper.saveTextualReport(outputTablesPath, readsHeader, table, bqsrArgs, auth);
    } catch (IOException e) {
        throw new UserException.CouldNotCreateOutputFile(new File(outputTablesPath), e);
    }
}
Also used : ContextShard(org.broadinstitute.hellbender.engine.ContextShard) ReadsSparkSource(org.broadinstitute.hellbender.engine.spark.datasources.ReadsSparkSource) GATKVariant(org.broadinstitute.hellbender.utils.variant.GATKVariant) ReferenceMultiSource(org.broadinstitute.hellbender.engine.datasources.ReferenceMultiSource) IOException(java.io.IOException) RecalibrationTables(org.broadinstitute.hellbender.utils.recalibration.RecalibrationTables) StandardCovariateList(org.broadinstitute.hellbender.utils.recalibration.covariates.StandardCovariateList) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) BaseRecalibratorEngineSparkWrapper(org.broadinstitute.hellbender.tools.spark.transforms.bqsr.BaseRecalibratorEngineSparkWrapper) ReadFilter(org.broadinstitute.hellbender.engine.filters.ReadFilter) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) UserException(org.broadinstitute.hellbender.exceptions.UserException) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File)

Example 4 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class HDF5PCACoveragePoN method renderPoNTargets.

private static List<Target> renderPoNTargets(final String[][] values, final List<String> targetNamesToRender, final HDF5File reader) {
    if (values.length != targetNamesToRender.size()) {
        throw new GATKException(String.format("Wrong number of elements in the targets recovered " + "from file '%s': number of targets found in file (%d) != number of target names (%d)", reader.getFile(), values.length, targetNamesToRender.size()));
    }
    final int numTargetCols = (int) reader.readDouble(NUM_TARGET_COLUMNS_PATH);
    final List<Target> result = new ArrayList<>(values.length);
    for (int i = 0; i < values.length; i++) {
        if (values[i].length != numTargetCols) {
            throw new GATKException(String.format("Wrong number of column elements in the targets recovered " + "from file '%s': number of columns found in file (%d) != number of target columns (%d)", reader.getFile(), values[i].length, numTargetCols));
        }
        result.add(new Target(targetNamesToRender.get(i), new SimpleInterval(values[i][0], Integer.parseInt(values[i][1]), Integer.parseInt(values[i][2]))));
    }
    return result;
}
Also used : Target(org.broadinstitute.hellbender.tools.exome.Target) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Example 5 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class AlignAssembledContigsSpark method decodeStringAsSimpleInterval.

@VisibleForTesting
public static SimpleInterval decodeStringAsSimpleInterval(final String text) {
    try {
        if (!text.startsWith("CTG="))
            throw new IllegalArgumentException(text);
        int stop1 = text.indexOf("START=");
        final String ctg = text.substring(4, stop1);
        int stop2 = text.indexOf("END=", stop1);
        final int start = Integer.valueOf(text.substring(stop1 + 6, stop2));
        final int end = Integer.valueOf(text.substring(stop2 + 4, text.length()));
        return new SimpleInterval(ctg, start, end);
    } catch (final Exception ex) {
        throw new GATKException("unexpected format in supposedly formatted text for a SimpleInterval: " + text, ex);
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)545 Test (org.testng.annotations.Test)287 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)202 File (java.io.File)102 ArrayList (java.util.ArrayList)66 DataProvider (org.testng.annotations.DataProvider)64 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)60 Collectors (java.util.stream.Collectors)53 java.util (java.util)41 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)40 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)40 UserException (org.broadinstitute.hellbender.exceptions.UserException)39 VariantContext (htsjdk.variant.variantcontext.VariantContext)36 IntStream (java.util.stream.IntStream)34 Target (org.broadinstitute.hellbender.tools.exome.Target)34 IOException (java.io.IOException)32 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)28 Assert (org.testng.Assert)27 Locatable (htsjdk.samtools.util.Locatable)26 List (java.util.List)26