use of org.broadinstitute.hellbender.utils.IndexRange in project gatk by broadinstitute.
the class ReadLikelihoods method filterToOnlyOverlappingUnclippedReads.
/**
* Remove those reads that do not overlap certain genomic location.
*
* <p>
* This method modifies the current read-likelihoods collection.
* </p>
*
* @param location the target location.
*
* @throws IllegalArgumentException the location cannot be {@code null} nor unmapped.
*/
public void filterToOnlyOverlappingUnclippedReads(final SimpleInterval location) {
Utils.nonNull(location, "the location cannot be null");
final int sampleCount = samples.numberOfSamples();
final String locContig = location.getContig();
final int locStart = location.getStart();
final int locEnd = location.getEnd();
final int alleleCount = alleles.numberOfAlleles();
for (int s = 0; s < sampleCount; s++) {
final GATKRead[] sampleReads = readsBySampleIndex[s];
final List<Integer> removeIndices = new IndexRange(0, sampleReads.length).filter(r -> !unclippedReadOverlapsRegion(sampleReads[r], locContig, locStart, locEnd));
removeSampleReads(s, removeIndices, alleleCount);
}
}
use of org.broadinstitute.hellbender.utils.IndexRange in project gatk-protected by broadinstitute.
the class SegmentUtils method trimInterval.
/**
* 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);
}
use of org.broadinstitute.hellbender.utils.IndexRange in project gatk by broadinstitute.
the class HashedListTargetCollectionUnitTest method testInvalidRangeUsingObject.
@Test(dependsOnMethods = { "testCorrectInitialization", "testCorrectRangeObjectInitialization" }, expectedExceptions = { IndexOutOfBoundsException.class, IllegalArgumentException.class }, dataProvider = "invalidRangeData")
public void testInvalidRangeUsingObject(final int from, final int to) {
final IndexRange range = new IndexRange(from, to);
targetDB.targets(range);
}
use of org.broadinstitute.hellbender.utils.IndexRange in project gatk by broadinstitute.
the class HashedListTargetCollectionUnitTest method testArbitraryTargetRangeObject.
@Test(dependsOnMethods = { "testCorrectInitialization", "testCorrectRangeObjectInitialization" }, dataProvider = "arbitraryTargetRageData")
public void testArbitraryTargetRangeObject(final int from, final int to) {
final IndexRange range = new IndexRange(from, to);
final List<SimpleInterval> targets = targetDB.targets(range);
Assert.assertNotNull(targets);
final int expectedSize = to - from;
Assert.assertEquals(targets.size(), expectedSize);
for (int i = from; i < to; i++) {
Assert.assertEquals(targets.get(i - from), nonOverlappingTargetIntervals.get(i));
}
}
use of org.broadinstitute.hellbender.utils.IndexRange in project gatk by broadinstitute.
the class HashedListTargetCollectionUnitTest method indexRangeData.
@DataProvider(name = "indexRangeData")
public Object[][] indexRangeData() {
final List<Object[]> result = new ArrayList<>();
final Random rdn = new Random(131313);
for (int i = 0; i < nonOverlappingTargetIntervals.size(); i++) {
result.add(new Object[] { nonOverlappingTargetIntervals.get(i), new IndexRange(i, i + 1) });
result.add(new Object[] { TargetsToolsTestUtils.createInterval(nonOverlappingTargetIntervals.get(i).getContig(), nonOverlappingTargetIntervals.get(i).getStart() - 1), new IndexRange(i, i) });
int j;
for (j = i + 1; j < nonOverlappingTargetIntervals.size() && rdn.nextBoolean(); j++) {
if (!nonOverlappingTargetIntervals.get(j).getContig().equals(nonOverlappingTargetIntervals.get(i).getContig())) {
break;
}
}
result.add(new Object[] { TargetsToolsTestUtils.createInterval(nonOverlappingTargetIntervals.get(i).getContig(), nonOverlappingTargetIntervals.get(i).getStart(), nonOverlappingTargetIntervals.get(j - 1).getEnd()), new IndexRange(i, j) });
}
return result.toArray(new Object[result.size()][]);
}
Aggregations