Search in sources :

Example 1 with Locatable

use of htsjdk.samtools.util.Locatable in project gatk by broadinstitute.

the class FragmentCollectionUnitTest method createFromMultiSamplePileup.

@Test
public void createFromMultiSamplePileup() throws Exception {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "10M");
    final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "10M");
    read1.setPosition(new SimpleInterval("22", 200, 210));
    read2.setPosition(new SimpleInterval("22", 208, 218));
    read1.setMatePosition(read2);
    read2.setMatePosition(read1);
    final Locatable loc = new SimpleInterval("22", 208, 208);
    final Map<String, ReadPileup> stratified = new LinkedHashMap<>();
    stratified.put("sample1", new ReadPileup(loc, Arrays.asList(read2), 0));
    stratified.put("sample2", new ReadPileup(loc, Arrays.asList(read1), 9));
    final ReadPileup combined = new ReadPileup(loc, stratified);
    final FragmentCollection<PileupElement> elements = FragmentCollection.create(combined);
    Assert.assertTrue(elements.getSingletonReads().isEmpty());
    Assert.assertEquals(elements.getOverlappingPairs().size(), 1);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Locatable(htsjdk.samtools.util.Locatable) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 2 with Locatable

use of htsjdk.samtools.util.Locatable in project gatk by broadinstitute.

the class IntervalsSkipListOneContigUnitTest method testEmptyInput.

@Test
public void testEmptyInput() throws Exception {
    List<Locatable> empty = new ArrayList<>();
    final IntervalsSkipListOneContig<Locatable> l = new IntervalsSkipListOneContig<>(empty);
    //try to fool it by using empty contig
    Assert.assertTrue(l.getOverlapping(new SimpleInterval("", 10, 100)).isEmpty());
    Assert.assertTrue(l.getOverlapping(new SimpleInterval("1", 10, 100)).isEmpty());
}
Also used : ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Locatable(htsjdk.samtools.util.Locatable) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with Locatable

use of htsjdk.samtools.util.Locatable in project gatk by broadinstitute.

the class IntervalsSkipListOneContigUnitTest method intervals.

@DataProvider(name = "intervals")
public Object[][] intervals() {
    ArrayList<Locatable> input = Lists.newArrayList(new SimpleInterval("1", 10, 100));
    ArrayList<Locatable> empty = new ArrayList<>();
    ArrayList<Locatable> manyOverlapping = Lists.newArrayList(new SimpleInterval("1", 10, 100), // special case: multiple intervals starting at the same place
    new SimpleInterval("1", 20, 50), new SimpleInterval("1", 20, 50), new SimpleInterval("1", 20, 50));
    ArrayList<Locatable> mixInput = Lists.newArrayList(// ends before query interval
    new SimpleInterval("1", 10, 20), // ends in query interval
    new SimpleInterval("1", 10, 60), // equal to query interval
    new SimpleInterval("1", 30, 50), // covered by query interval
    new SimpleInterval("1", 40, 42), // ends after query interval
    new SimpleInterval("1", 45, 60), // starts after query interval
    new SimpleInterval("1", 60, 100));
    ArrayList<Locatable> mixExpected = Lists.newArrayList(// ends in query interval
    new SimpleInterval("1", 10, 60), // equal to query interval
    new SimpleInterval("1", 30, 50), // covered by query interval
    new SimpleInterval("1", 40, 42), // ends after query interval
    new SimpleInterval("1", 45, 60));
    // returns input single SimpleInterval, query range, expected SimpleInterval
    return new Object[][] { // single-point boundary cases
    new Object[] { input, new SimpleInterval("1", 10, 10), input }, new Object[] { input, new SimpleInterval("1", 100, 100), input }, new Object[] { input, new SimpleInterval("1", 9, 9), empty }, new Object[] { input, new SimpleInterval("1", 11, 11), input }, new Object[] { input, new SimpleInterval("1", 99, 99), input }, new Object[] { input, new SimpleInterval("1", 101, 101), empty }, // empty list boundary case
    new Object[] { empty, new SimpleInterval("1", 101, 101), empty }, // different contig
    new Object[] { empty, new SimpleInterval("2", 101, 101), empty }, // input exactly matches the query interval
    new Object[] { input, new SimpleInterval("1", 10, 100), input }, // multiple intervals in the same place (potential edge case for indexing)
    new Object[] { manyOverlapping, new SimpleInterval("1", 20, 20), manyOverlapping }, // input with multiple intervals
    new Object[] { mixInput, new SimpleInterval("1", 30, 50), mixExpected } };
}
Also used : ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Locatable(htsjdk.samtools.util.Locatable) DataProvider(org.testng.annotations.DataProvider)

Example 4 with Locatable

use of htsjdk.samtools.util.Locatable in project gatk-protected by broadinstitute.

the class HaplotypeCallerGenotypingEngineUnitTest method testAddMiscellaneousAllele.

@Test(dataProvider = "AddMiscellaneousDataProvider", enabled = false)
public void testAddMiscellaneousAllele(final String readBases, final int readOffset, final String ref, final int refOffset, final String referenceAllele, final String[] alternatives, final double[] likelihoods, final double[] expected) {
    final byte baseQual = (byte) 30;
    final byte[] baseQuals = Utils.dupBytes(baseQual, readBases.length());
    final GATKRead read = ArtificialReadUtils.createArtificialRead(readBases.getBytes(), baseQuals, readBases.length() + "M");
    final Locatable loc = new SimpleInterval("20", refOffset, refOffset);
    final ReadPileup pileup = new ReadPileup(loc, Collections.singletonList(read), readOffset);
    final VariantContextBuilder vcb = new VariantContextBuilder();
    final GenotypeBuilder gb = new GenotypeBuilder();
    final List<String> alleleStrings = new ArrayList<>(1 + alternatives.length);
    alleleStrings.add(referenceAllele);
    alleleStrings.addAll(Arrays.asList(alternatives));
    gb.AD(new int[] { 1 });
    gb.DP(1);
    gb.PL(likelihoods);
    vcb.alleles(alleleStrings);
    vcb.loc("20", refOffset, refOffset + referenceAllele.length() - 1);
    vcb.genotypes(gb.make());
    final VariantContext vc = vcb.make();
    // GenotypingEngine.addMiscellaneousAllele(vc,pileup,ref.getBytes(),0);
    final VariantContext updatedVc = null;
    final GenotypeLikelihoods updatedLikelihoods = updatedVc.getGenotype(0).getLikelihoods();
    Assert.assertEquals(updatedLikelihoods.getAsVector().length, expected.length);
    final double[] updatedLikelihoodsArray = updatedVc.getGenotype(0).getLikelihoods().getAsVector();
    for (int i = 0; i < updatedLikelihoodsArray.length; i++) {
        Assert.assertEquals(updatedLikelihoodsArray[i], expected[i], 0.0001);
    }
    Allele altAllele = null;
    for (final Allele allele : updatedVc.getAlleles()) if (allele.isSymbolic() && allele.getBaseString().equals(GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE_NAME))
        altAllele = allele;
    Assert.assertNotNull(altAllele);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Locatable(htsjdk.samtools.util.Locatable) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 5 with Locatable

use of htsjdk.samtools.util.Locatable in project gatk by broadinstitute.

the class BaseRecalibrationEngine method calculateKnownSites.

protected boolean[] calculateKnownSites(final GATKRead read, final Iterable<? extends Locatable> knownSites) {
    final int readLength = read.getLength();
    //initializes to all false
    final boolean[] knownSitesArray = new boolean[readLength];
    final Cigar cigar = read.getCigar();
    final int softStart = ReadUtils.getSoftStart(read);
    final int softEnd = ReadUtils.getSoftEnd(read);
    for (final Locatable knownSite : knownSites) {
        if (knownSite.getEnd() < softStart || knownSite.getStart() > softEnd) {
            // knownSite is outside clipping window for the read, ignore
            continue;
        }
        int featureStartOnRead = ReadUtils.getReadCoordinateForReferenceCoordinate(softStart, cigar, knownSite.getStart(), ReadUtils.ClippingTail.LEFT_TAIL, true);
        if (featureStartOnRead == ReadUtils.CLIPPING_GOAL_NOT_REACHED) {
            featureStartOnRead = 0;
        }
        int featureEndOnRead = ReadUtils.getReadCoordinateForReferenceCoordinate(softStart, cigar, knownSite.getEnd(), ReadUtils.ClippingTail.LEFT_TAIL, true);
        if (featureEndOnRead == ReadUtils.CLIPPING_GOAL_NOT_REACHED) {
            featureEndOnRead = readLength;
        }
        if (featureStartOnRead > readLength) {
            featureStartOnRead = featureEndOnRead = readLength;
        }
        Arrays.fill(knownSitesArray, Math.max(0, featureStartOnRead), Math.min(readLength, featureEndOnRead + 1), true);
    }
    return knownSitesArray;
}
Also used : Cigar(htsjdk.samtools.Cigar) Locatable(htsjdk.samtools.util.Locatable)

Aggregations

Locatable (htsjdk.samtools.util.Locatable)38 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)24 Test (org.testng.annotations.Test)22 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)20 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)11 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)10 SAMFileHeader (htsjdk.samtools.SAMFileHeader)6 ArrayList (java.util.ArrayList)5 UserException (org.broadinstitute.hellbender.exceptions.UserException)5 DataProvider (org.testng.annotations.DataProvider)4 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)3 com.google.common.collect (com.google.common.collect)2 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)2 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)2 OverlapDetector (htsjdk.samtools.util.OverlapDetector)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 java.util (java.util)2 LinkedHashMap (java.util.LinkedHashMap)2 Collectors (java.util.stream.Collectors)2