Java Code Examples for htsjdk.samtools.util.Locatable#getStart()
The following examples show how to use
htsjdk.samtools.util.Locatable#getStart() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureDataSource.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Refill our cache from disk after a cache miss. Will prefetch Features overlapping an additional * queryLookaheadBases bases after the end of the provided interval, in addition to those overlapping * the interval itself. * <p> * Calling this has the side effect of invalidating (closing) any currently-open iteration over * this data source. * * @param interval the query interval that produced a cache miss */ private void refillQueryCache(final Locatable interval) { // Tribble documentation states that having multiple iterators open simultaneously over the same FeatureReader // results in undefined behavior closeOpenIterationIfNecessary(); // Expand the end of our query by the configured number of bases, in anticipation of probable future // queries with slightly larger start/stop positions. // // Note that it doesn't matter if we go off the end of the contig in the process, since // our reader's query operation is not aware of (and does not care about) contig boundaries. // Note: we use addExact to blow up on overflow rather than propagate negative results downstream final SimpleInterval queryInterval = new SimpleInterval(interval.getContig(), interval.getStart(), Math.addExact(interval.getEnd(), queryLookaheadBases)); // Query iterator over our reader will be immediately closed after re-populating our cache try (final CloseableTribbleIterator<T> queryIter = featureReader.query(queryInterval.getContig(), queryInterval.getStart(), queryInterval.getEnd())) { queryCache.fill(queryIter, queryInterval); } catch (final IOException e) { throw new GATKException("Error querying file " + featureInput + " over interval " + interval, e); } }
Example 2
Source File: SegmentUtils.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Given an interval and collections of targets and SNPs, returns a trimmed interval produced by removing the empty * portions at the start and the end of the original interval that do not overlap the targets and SNPs that overlap * with the original interval. If this procedure would remove the entire interval, the original interval is * returned instead. Note that this method will not expand an interval to the start of the first overlapping target * and the end of the last overlapping target; it will only shrink the interval or leave it alone. This is to * avoid overlapping segments (which would occur if a SNP breakpoint fell within a target and the interval * were expanded, for example). */ public static SimpleInterval trimInterval(final Locatable interval, final TargetCollection<? extends Locatable> targets, final TargetCollection<? extends Locatable> snps) { Utils.nonNull(interval, "The interval cannot be null."); Utils.nonNull(targets, "The collection of targets cannot be null."); Utils.nonNull(snps, "The collection of SNPs cannot be null."); final IndexRange targetRange = targets.indexRange(interval); final IndexRange snpRange = snps.indexRange(interval); final int numTargetsInInterval = targetRange.size(); final int numSNPsInInterval = snpRange.size(); int start = interval.getStart(); int end = interval.getEnd(); if (numTargetsInInterval == 0 && numSNPsInInterval > 0) { //if there are no targets overlapping interval, use SNPs to determine trimmed interval start = snps.target(snpRange.from).getStart(); end = snps.target(snpRange.to - 1).getEnd(); } else if (numTargetsInInterval > 0) { //if interval start does not fall within first target, use start of first target as start of trimmed interval start = Math.max(start, targets.target(targetRange.from).getStart()); //if interval end does not fall within last target, use end of last target as end of trimmed interval end = Math.min(end, targets.target(targetRange.to - 1).getEnd()); if (numSNPsInInterval > 0) { //if there are also SNPs within interval, check to see if they give a larger trimmed interval start = Math.min(start, snps.target(snpRange.from).getStart()); end = Math.max(end, snps.target(snpRange.to - 1).getEnd()); } } if (start < interval.getStart() || end > interval.getEnd() || end < start) { throw new GATKException.ShouldNeverReachHereException("Something went wrong in trimming interval."); } return new SimpleInterval(interval.getContig(), start, end); }
Example 3
Source File: AnnotatedIntervalUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Gets the distance, in base pairs between two locatables. Looks for the closest endpoints, so the order of loc1 * and loc2 do not matter. * * Overlapping (or abutting) locatables will always return 0. * * Locatables on different contigs will have a distance of {@link Long#MAX_VALUE} * @param loc1 Never {@code null} * @param loc2 Never {@code null} * @return 0 or a positive number. */ private static long getDistance(final Locatable loc1, final Locatable loc2) { Utils.nonNull(loc1); Utils.nonNull(loc2); if (!loc1.getContig().equals(loc2.getContig())) { return Long.MAX_VALUE; } if (IntervalUtils.overlaps(loc1, loc2)) { return 0; } return (loc1.getEnd() < loc2.getStart()) ? (loc2.getStart() - loc1.getEnd()) : (loc1.getStart() - loc2.getEnd()); }
Example 4
Source File: SimpleInterval.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Determines whether this interval contains the entire region represented by other * (in other words, whether it covers it). * * @param other interval to check * @return true if this interval contains all of the bases spanned by other, otherwise false */ public boolean contains( final Locatable other ) { if ( other == null || other.getContig() == null ) { return false; } return this.contig.equals(other.getContig()) && this.start <= other.getStart() && this.end >= other.getEnd(); }
Example 5
Source File: SimpleInterval.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Determines whether this interval comes within "margin" of overlapping the provided locatable. * This is the same as plain overlaps if margin=0. * * @param other interval to check * @param margin how many bases may be between the two interval for us to still consider them overlapping; must be non-negative * @return true if this interval overlaps other, otherwise false * @throws IllegalArgumentException if margin is negative */ public boolean overlapsWithMargin(final Locatable other, final int margin) { if ( margin < 0 ) { throw new IllegalArgumentException("given margin is negative: " + margin + "\tfor this: " + toString() + "\tand that: " + (other == null ? "other is null" : other.toString())); } if ( other == null || other.getContig() == null ) { return false; } return this.contig.equals(other.getContig()) && this.start <= other.getEnd() + margin && other.getStart() - margin <= this.end; }
Example 6
Source File: BaseRecalibrationEngine.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected static boolean[] calculateKnownSites( final GATKRead read, final Iterable<? extends Locatable> knownSites ) { final int readLength = read.getLength(); final boolean[] knownSitesArray = new boolean[readLength];//initializes to all false final Cigar cigar = read.getCigar(); final int softStart = read.getSoftStart(); final int softEnd = read.getSoftEnd(); for ( final Locatable knownSite : knownSites ) { if (knownSite.getEnd() < softStart || knownSite.getStart() > softEnd) { // knownSite is outside clipping window for the read, ignore continue; } final Pair<Integer, CigarOperator> featureStartAndOperatorOnRead = ReadUtils.getReadIndexForReferenceCoordinate(read, knownSite.getStart()); int featureStartOnRead = featureStartAndOperatorOnRead.getLeft() == ReadUtils.READ_INDEX_NOT_FOUND ? 0 : featureStartAndOperatorOnRead.getLeft(); if (featureStartAndOperatorOnRead.getRight() == CigarOperator.DELETION) { featureStartOnRead--; } final Pair<Integer, CigarOperator> featureEndAndOperatorOnRead = ReadUtils.getReadIndexForReferenceCoordinate(read, knownSite.getEnd()); int featureEndOnRead = featureEndAndOperatorOnRead.getLeft() == ReadUtils.READ_INDEX_NOT_FOUND ? readLength : featureEndAndOperatorOnRead.getLeft(); if( featureStartOnRead > readLength ) { featureStartOnRead = featureEndOnRead = readLength; } Arrays.fill(knownSitesArray, Math.max(0, featureStartOnRead), Math.min(readLength, featureEndOnRead + 1), true); } return knownSitesArray; }
Example 7
Source File: FuncotatorUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a cDNA string for an intronic variant. * The cDNA string contains information about the coding position of a variant and the alleles involved. * If the transcript in which the variant occurs contains at least 1 exon, the string will be non-empty and of * the form: * c.e[EXON NUMBER][+|-][BASES FROM EXON][REF ALLELE]>[ALT ALLELE] * Concretely: * c.e2-1A>G * Where: * 2 = the number of the exon to which the given variant start is closest * -1 = number of bases away from the exon (1 before) * A = Reference allele * G = Alternate allele * @param variantStart The start position (1-based, inclusive) in genomic coordinates of the variant. * @param exonList The {@link List<Locatable>} representing the exons in the transcript in which this variant occurs. Must not be {@code null}. * @param strandCorrectedRefAllele A {@link String} containing the bases of the reference allele, which are correct for strandedness (i.e. if on a transcript on the {@link Strand#NEGATIVE} strand, the string has already been reverse-complemented). Must not be {@code null}. * @param strandCorrectedAltAllele A {@link String} containing the bases of the alternate allele, which are correct for strandedness (i.e. if on a transcript on the {@link Strand#NEGATIVE} strand, the string has already been reverse-complemented). Must not be {@code null}. * @return A {@link String} representing the cDNA change for the given data. Will be empty if the given {@code exonList} is empty. */ public static String createIntronicCDnaString(final int variantStart, final List<? extends Locatable> exonList, final String strandCorrectedRefAllele, final String strandCorrectedAltAllele) { Utils.nonNull(exonList); Utils.nonNull(strandCorrectedRefAllele); Utils.nonNull(strandCorrectedAltAllele); // Get the exon that is closest to our variant: final int exonIndex = getClosestExonIndex(variantStart, exonList); if ( exonIndex != -1 ) { final Locatable closestExon = exonList.get(exonIndex); final int startDiff = variantStart - closestExon.getStart(); final int endDiff = variantStart - closestExon.getEnd(); // Get the offset from our start: final int exonOffset; if ( Math.abs(startDiff) <= Math.abs(endDiff) ) { exonOffset = startDiff; } else { exonOffset = endDiff; } // Get the cDNA string itself: return "c.e" + (exonIndex+1) + (exonOffset < 0 ? "-" : "+") + Math.abs(exonOffset) + strandCorrectedRefAllele + ">" + strandCorrectedAltAllele; } else { return "NA"; } }
Example 8
Source File: IntervalUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Tests whether the first Locatable ends before the start of the second Locatable * * @param first first Locatable * @param second second Locatable * @param dictionary sequence dictionary used to determine contig ordering * @return true if first ends before the start of second, otherwise false */ public static boolean isBefore(final Locatable first, final Locatable second, final SAMSequenceDictionary dictionary) { Utils.nonNull(first); Utils.nonNull(second); Utils.nonNull(dictionary); final int contigComparison = compareContigs(first, second, dictionary); return contigComparison == -1 || (contigComparison == 0 && first.getEnd() < second.getStart()); }
Example 9
Source File: ReferenceConfidenceModel.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Note that we don't have to match alleles because the PosteriorProbabilitesUtils will take care of that * @param curPos position of interest for genotyping * @param call (may be null) * @param priorList priors within the current ActiveRegion * @return prior VCs representing the same variant position as call */ private List<VariantContext> getMatchingPriors(final Locatable curPos, final VariantContext call, final List<VariantContext> priorList) { final int position = call != null ? call.getStart() : curPos.getStart(); final List<VariantContext> matchedPriors = new ArrayList<>(priorList.size()); // NOTE: a for loop is used here because this method ends up being called per-pileup, per-read and using a loop instead of streaming saves runtime final int priorsListSize = priorList.size(); for (int i = 0; i < priorsListSize; i++) { if (position == priorList.get(i).getStart()) { matchedPriors.add(priorList.get(i)); } } return matchedPriors; }
Example 10
Source File: Haplotype.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new Haplotype derived from this one that exactly spans the provided location * * Note that this haplotype must have a contain a genome loc for this operation to be successful. If no * GenomeLoc is contained than @throws an IllegalStateException * * Also loc must be fully contained within this Haplotype's genomeLoc. If not an IllegalArgumentException is * thrown. * * @param loc a location completely contained within this Haplotype's location * @return a new Haplotype within only the bases spanning the provided location, or null for some reason the haplotype would be malformed if */ public Haplotype trim(final Locatable loc) { Utils.nonNull( loc, "Loc cannot be null"); Utils.nonNull(genomeLocation, "Cannot trim a Haplotype without containing GenomeLoc"); Utils.validateArg(new SimpleInterval(genomeLocation).contains(loc), () -> "Can only trim a Haplotype to a containing span. My loc is " + genomeLocation + " but wanted trim to " + loc); Utils.nonNull( getCigar(), "Cannot trim haplotype without a cigar " + this); final int newStart = loc.getStart() - this.genomeLocation.getStart(); final int newStop = newStart + loc.getEnd() - loc.getStart(); // note: the following returns null if the bases covering the ref interval start or end in a deletion. final byte[] newBases = AlignmentUtils.getBasesCoveringRefInterval(newStart, newStop, getBases(), 0, getCigar()); if ( newBases == null || newBases.length == 0 ) { // we cannot meaningfully chop down the haplotype, so return null return null; } // note: trimCigarByReference does not remove leading or trailing indels, while getBasesCoveringRefInterval does remove bases // of leading and trailing insertions. We must remove leading and trailing insertions from the Cigar manually. // we keep leading and trailing deletions because these are necessary for haplotypes to maintain consistent reference coordinates final Cigar newCigar = AlignmentUtils.trimCigarByReference(getCigar(), newStart, newStop).getCigar(); final boolean leadingInsertion = !newCigar.getFirstCigarElement().getOperator().consumesReferenceBases(); final boolean trailingInsertion = !newCigar.getLastCigarElement().getOperator().consumesReferenceBases(); final int firstIndexToKeepInclusive = leadingInsertion ? 1 : 0; final int lastIndexToKeepExclusive = newCigar.numCigarElements() - (trailingInsertion ? 1 : 0); if (lastIndexToKeepExclusive <= firstIndexToKeepInclusive) { // edge case of entire cigar is insertion return null; } final Cigar leadingIndelTrimmedNewCigar = !(leadingInsertion || trailingInsertion) ? newCigar : new CigarBuilder(false).addAll(newCigar.getCigarElements().subList(firstIndexToKeepInclusive, lastIndexToKeepExclusive)).make(); final Haplotype ret = new Haplotype(newBases, isReference()); ret.setCigar(leadingIndelTrimmedNewCigar); ret.setGenomeLocation(loc); ret.setScore(score); ret.setAlignmentStartHapwrtRef(newStart + getAlignmentStartHapwrtRef()); return ret; }
Example 11
Source File: VariantShard.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * getVariantShardsFromInterval calculates *all* shards overlapping location. * @param location the range of sites determines which shards are overlapping * @return All overlapping VariantShards */ public static List<VariantShard> getVariantShardsFromInterval(final Locatable location) { if (location.getContig()==null) { // don't feed me unmapped reads! throw new GATKException("getVariantShardsFromInterval requires locations to be mapped"); } List<VariantShard> shardList = new ArrayList<>(); // Get all of the shard numbers that span the start and end of the interval. int startShard = location.getStart()/ VARIANT_SHARDSIZE; int endShard = location.getEnd()/ VARIANT_SHARDSIZE; for (int i = startShard; i <= endShard; ++i) { shardList.add(new VariantShard(i, location.getContig())); } return shardList; }
Example 12
Source File: SegmentExonUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param transcript Never {@code null} * @param segment Genomic region to determine which exons are covered in the transcript. Never {@code null} * @return Instance of {@link SegmentExonOverlaps}. A typical value will be a number appended to a "-" or a "+". * The exon numbers are 0-based. "-" if it covers upstream exons (considering coding direction -- i.e. previous exons * are higher genomic coordinates on negative strand transcripts) and "+" for downstream exons. * For example: * - "6+" would be sixth exon and above. This would indicate downstream exons (higher genomic * coordinates on positive coding directions and lower genomic coordinates when negative coding) are covered by * the segment. * - "" indicates that the endpoints of the segment do not cover any transcript exons. So either the entire * transcript is covered or none of the transcript is covered. * * Note that this will return the first exon covered, as long as the breakpoint is in the transcript. Even if the * breakpoint itself does not cover an exon. * For example, this will yield a non-blank value when a segment breakpoint is in an intron. */ public static SegmentExonOverlaps determineSegmentExonPosition(final GencodeGtfTranscriptFeature transcript, final Locatable segment) { Utils.nonNull(transcript); Utils.nonNull(segment); final String NOT_IN_TRANSCRIPT = ""; // Internally, this method assumes that the exons are sorted in genomic order. Which is NOT how these are // stored in the GencodeGtfTranscriptFeature final List<GencodeGtfExonFeature> exons = transcript.getGenomicStrand() == Strand.NEGATIVE ? Lists.reverse(transcript.getExons()) : transcript.getExons(); if (exons.size() == 0) { return new SegmentExonOverlaps(NOT_IN_TRANSCRIPT, NOT_IN_TRANSCRIPT); } final SimpleInterval segmentStart = new SimpleInterval(segment.getContig(), segment.getStart(), segment.getStart()); final SimpleInterval segmentEnd = new SimpleInterval(segment.getContig(), segment.getEnd(), segment.getEnd()); // Find the proper index for the start. // If the start of the segment does not overlap the first exon, but the segment does, then the start index is -1 (no overlap) final int inclusiveIndexPositiveDirectionStart = findInclusiveExonIndex(transcript.getGenomicStrand(), exons, segmentStart, true); // If the end of the segment does not overlap the last exon, but the segment does, then the end index is -1 (no overlap) final int inclusiveIndexPositiveDirectionEnd = findInclusiveExonIndex(transcript.getGenomicStrand(), exons, segmentEnd, false); // Construct the final strings final String startResult = inclusiveIndexPositiveDirectionStart != NO_EXON_OVERLAP ? inclusiveIndexPositiveDirectionStart + determineSegmentOverlapDirection(transcript.getGenomicStrand(), true) : NOT_IN_TRANSCRIPT; final String endResult = inclusiveIndexPositiveDirectionEnd != NO_EXON_OVERLAP ? inclusiveIndexPositiveDirectionEnd + determineSegmentOverlapDirection(transcript.getGenomicStrand(), false) : NOT_IN_TRANSCRIPT; return new SegmentExonOverlaps(startResult, endResult); }
Example 13
Source File: FuncotatorUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Get the position (1-based, inclusive) of the given {@link VariantContext} start relative to the transcript it appears in. * The transcript is specified by {@code sortedTranscriptExonList}. * @param variant The {@link VariantContext} of which to find the start position in the given transcript (must not be {@code null}). * @param exons {@link List} of {@link Locatable}s representing the exons in the transcript in which the given {@code variant} occurs. * @param strand The {@link Strand} on which the {@code variant} occurs. * @return The start position (1-based, inclusive) of the given {@code variant} in the transcript in which it appears. */ public static int getTranscriptAlleleStartPosition(final VariantContext variant, final List<? extends Locatable> exons, final Strand strand) { Utils.nonNull(variant); Utils.nonNull(exons); assertValidStrand(strand); // Set up our position variable: int position; // NOTE: We don't need to worry about UTRs in here - all UTRs occur somewhere in an exon in GENCODE. // Filter the elements by whether they come before the variant in the transcript and // then sort them by their order in the transcript: final List<Locatable> sortedFilteredExons; if ( strand == Strand.POSITIVE) { sortedFilteredExons = exons.stream() .filter(e -> e.getStart() <= variant.getStart()) .sorted(Comparator.comparingInt(Locatable::getStart)) .collect(Collectors.toList()); // We are guaranteed that the variant occurs in the last element of sortedTranscriptElements because of the sorting. // Add 1 to position to account for inclusive values: position = variant.getStart() - sortedFilteredExons.get(sortedFilteredExons.size()-1).getStart() + 1; } else { sortedFilteredExons = exons.stream() .filter(e -> e.getEnd() >= variant.getStart()) .sorted(Comparator.comparingInt(Locatable::getStart).reversed()) .collect(Collectors.toList()); // We are guaranteed that the variant occurs in the last element of sortedTranscriptElements because of the sorting. // Add 1 to position to account for inclusive values: position = sortedFilteredExons.get(sortedFilteredExons.size()-1).getEnd() - variant.getStart() + 1; } // Add up the lengths of all exons before the last one: final int numExonsBeforeLast = sortedFilteredExons.size() - 1; for ( int i = 0; i < numExonsBeforeLast; ++i ) { final Locatable exon = sortedFilteredExons.get(i); // Add 1 to position to account for inclusive values: position += exon.getEnd() - exon.getStart() + 1; } return position; }
Example 14
Source File: SimpleInterval.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
private boolean contiguous(final Locatable that) { Utils.nonNull(that); return this.getContig().equals(that.getContig()) && this.getStart() <= that.getEnd() + 1 && that.getStart() <= this.getEnd() + 1; }
Example 15
Source File: ReferenceConfidenceModel.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Calculate the reference confidence for a single sample given the its read data * * Returns a list of variant contexts, one for each position in the {@code activeRegion.getLoc()}, each containing * detailed information about the certainty that the sample is hom-ref for each base in the region. * * * * @param refHaplotype the reference haplotype, used to get the reference bases across activeRegion.getLoc() * @param calledHaplotypes a list of haplotypes that segregate in this region, for realignment of the reads in the * readLikelihoods, corresponding to each reads best haplotype. Must contain the refHaplotype. * @param paddedReferenceLoc the location of refHaplotype (which might be larger than activeRegion.getLoc()) * @param activeRegion the active region we want to get the reference confidence over * @param readLikelihoods a map from a single sample to its PerReadAlleleLikelihoodMap for each haplotype in calledHaplotypes * @param ploidyModel indicate the ploidy of each sample in {@code stratifiedReadMap}. * @param variantCalls calls made in this region. The return result will contain any variant call in this list in the * correct order by genomic position, and any variant in this list will stop us emitting a ref confidence * under any position it covers (for snps and insertions that is 1 bp, but for deletions its the entire ref span) * @return an ordered list of variant contexts that spans activeRegion.getLoc() and includes both reference confidence * contexts as well as calls from variantCalls if any were provided */ public List<VariantContext> calculateRefConfidence(final Haplotype refHaplotype, final Collection<Haplotype> calledHaplotypes, final SimpleInterval paddedReferenceLoc, final AssemblyRegion activeRegion, final AlleleLikelihoods<GATKRead, Haplotype> readLikelihoods, final PloidyModel ploidyModel, final List<VariantContext> variantCalls, final boolean applyPriors, final List<VariantContext> VCpriors) { Utils.nonNull(refHaplotype, "refHaplotype cannot be null"); Utils.nonNull(calledHaplotypes, "calledHaplotypes cannot be null"); Utils.validateArg(calledHaplotypes.contains(refHaplotype), "calledHaplotypes must contain the refHaplotype"); Utils.nonNull(paddedReferenceLoc, "paddedReferenceLoc cannot be null"); Utils.nonNull(activeRegion, "activeRegion cannot be null"); Utils.nonNull(readLikelihoods, "readLikelihoods cannot be null"); Utils.validateArg(readLikelihoods.numberOfSamples() == 1, () -> "readLikelihoods must contain exactly one sample but it contained " + readLikelihoods.numberOfSamples()); Utils.validateArg( refHaplotype.length() == activeRegion.getPaddedSpan().size(), () -> "refHaplotype " + refHaplotype.length() + " and activeRegion location size " + activeRegion.getSpan().size() + " are different"); Utils.nonNull(ploidyModel, "the ploidy model cannot be null"); final int ploidy = ploidyModel.samplePloidy(0); // the first sample = the only sample in reference-confidence mode. final SimpleInterval refSpan = activeRegion.getSpan(); final List<ReadPileup> refPileups = AssemblyBasedCallerUtils.getPileupsOverReference(activeRegion.getHeader(), refSpan, readLikelihoods, samples); final byte[] ref = refHaplotype.getBases(); final List<VariantContext> results = new ArrayList<>(refSpan.size()); final String sampleName = readLikelihoods.getSample(0); final int globalRefOffset = refSpan.getStart() - activeRegion.getPaddedSpan().getStart(); // Note, we use an indexed for-loop here because this method has a large impact on the profile of HaplotypeCaller runtime in GVCF mode final int refPileupsSize = refPileups.size(); for (int i = 0; i < refPileupsSize; i++) { final ReadPileup pileup = refPileups.get(i); final Locatable curPos = pileup.getLocation(); final int offset = curPos.getStart() - refSpan.getStart(); final VariantContext overlappingSite = GATKVariantContextUtils.getOverlappingVariantContext(curPos, variantCalls); final List<VariantContext> currentPriors = VCpriors.isEmpty() ? Collections.emptyList() : getMatchingPriors(curPos, overlappingSite, VCpriors); if (overlappingSite != null && overlappingSite.getStart() == curPos.getStart()) { if (applyPriors) { results.add(PosteriorProbabilitiesUtils.calculatePosteriorProbs(overlappingSite, currentPriors, numRefSamplesForPrior, options)); } else { results.add(overlappingSite); } } else { // otherwise emit a reference confidence variant context results.add(makeReferenceConfidenceVariantContext(ploidy, ref, sampleName, globalRefOffset, pileup, curPos, offset, applyPriors, currentPriors)); } } // Ensuring that we remove any indel informativeness data we may have attached to the underlying reads for caching purposes // This is important as if multiple reference blocks are computed for a low complexity active region some reads may incorrectly // be using caching values computed for a different reference block. if (USE_CACHED_READ_INDEL_INFORMATIVENESS_VALUES) { readLikelihoods.sampleEvidence(0).forEach(r -> r.clearTransientAttribute(INDEL_INFORMATIVE_BASES_CACHE_ATTRIBUTE_NAME)); } return results; }
Example 16
Source File: IntervalUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Check whether two locatables overlap. * <p> * Two locatables overlap if the share the same contig and they have at least one * base in common based on their start and end positions. * </p> * <p> * This method returns {@code false} if either input {@link Locatable} has a {@code null} * contig. * </p> * * @param left first locatable. * @param right second locatable. * @throws IllegalArgumentException if either {@code left} or {@code right} locatable * is {@code null}. * @return {@code true} iff there is an overlap between both locatables. */ public static boolean overlaps(final Locatable left, final Locatable right) { Utils.nonNull(left,"the left locatable is null"); Utils.nonNull(right,"the right locatable is null"); if (left.getContig() == null || right.getContig() == null) { return false; } else if (!left.getContig().equals(right.getContig())) { return false; } else { return left.getStart() <= right.getEnd() && right.getStart() <= left.getEnd(); } }
Example 17
Source File: ActivityProfileState.java From gatk with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * The offset of state w.r.t. our current region's start location * @param regionStartLoc the start of the region, as a Locatable * @return the position of this profile relative to the start of this region */ public int getOffset(final Locatable regionStartLoc) { Utils.nonNull(regionStartLoc); return getLoc().getStart() - regionStartLoc.getStart(); }
Example 18
Source File: ReferenceShard.java From gatk with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * getShardNumberFromInterval returns the ReferenceShard that overlap the read's start position. * @param location, the start of which is used to determine the shard * @return the shard (contig + id) */ public static ReferenceShard getShardNumberFromInterval(final Locatable location) { return new ReferenceShard(location.getStart()/REFERENCE_SHARD_SIZE, location.getContig()); }
Example 19
Source File: SimpleInterval.java From gatk with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Create a new SimpleInterval from a {@link Locatable} * @param locatable any Locatable * @throws IllegalArgumentException if locatable violates any of the SimpleInterval constraints or is null */ public SimpleInterval(final Locatable locatable){ this(Utils.nonNull(locatable).getContig(), locatable.getStart(), locatable.getEnd()); }