Search in sources :

Example 21 with IndexRange

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);
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) IndexRange(org.broadinstitute.hellbender.utils.IndexRange)

Example 22 with IndexRange

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);
}
Also used : IndexRange(org.broadinstitute.hellbender.utils.IndexRange) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 23 with IndexRange

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);
}
Also used : IndexRange(org.broadinstitute.hellbender.utils.IndexRange) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 24 with IndexRange

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));
    }
}
Also used : IndexRange(org.broadinstitute.hellbender.utils.IndexRange) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 25 with IndexRange

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()][]);
}
Also used : IndexRange(org.broadinstitute.hellbender.utils.IndexRange) DataProvider(org.testng.annotations.DataProvider)

Aggregations

IndexRange (org.broadinstitute.hellbender.utils.IndexRange)32 Test (org.testng.annotations.Test)11 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)9 IntStream (java.util.stream.IntStream)7 Target (org.broadinstitute.hellbender.tools.exome.Target)7 CopyNumberTriState (org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState)7 MathUtils (org.broadinstitute.hellbender.utils.MathUtils)7 Allele (htsjdk.variant.variantcontext.Allele)5 VariantContext (htsjdk.variant.variantcontext.VariantContext)5 Collectors (java.util.stream.Collectors)5 MathArrays (org.apache.commons.math3.util.MathArrays)5 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)5 Utils (org.broadinstitute.hellbender.utils.Utils)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 File (java.io.File)4 java.util (java.util)4 Genotype (htsjdk.variant.variantcontext.Genotype)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Map (java.util.Map)3