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);
}
}
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);
}
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);
}
}
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;
}
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);
}
}
Aggregations