@Test public void testWholeIndelReadInIsolation() { final int firstLocus = 44367789; // create a test version of the Reads object ReadProperties readAttributes = createTestReadProperties(); SAMRecord indelOnlyRead = ArtificialSAMUtils.createArtificialRead(header, "indelOnly", 0, firstLocus, 76); indelOnlyRead.setReadBases(Utils.dupBytes((byte) 'A', 76)); indelOnlyRead.setBaseQualities(Utils.dupBytes((byte) '@', 76)); indelOnlyRead.setCigarString("76I"); List<SAMRecord> reads = Arrays.asList(indelOnlyRead); // create the iterator by state with the fake reads and fake records li = makeLTBS(reads, readAttributes); // Traditionally, reads that end with indels bleed into the pileup at the following locus. // Verify that the next pileup contains this read // and considers it to be an indel-containing read. Assert.assertTrue( li.hasNext(), "Should have found a whole-indel read in the normal base pileup without extended events enabled"); AlignmentContext alignmentContext = li.next(); Assert.assertEquals( alignmentContext.getLocation().getStart(), firstLocus, "Base pileup is at incorrect location."); ReadBackedPileup basePileup = alignmentContext.getBasePileup(); Assert.assertEquals(basePileup.getReads().size(), 1, "Pileup is of incorrect size"); Assert.assertSame(basePileup.getReads().get(0), indelOnlyRead, "Read in pileup is incorrect"); }
@Test(dataProvider = "LIBSTest") public void testLIBS(LIBSTest params) { final int locus = 44367788; SAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "read", 0, locus, params.readLength); read.setReadBases(Utils.dupBytes((byte) 'A', params.readLength)); read.setBaseQualities(Utils.dupBytes((byte) '@', params.readLength)); read.setCigarString(params.cigar); // create the iterator by state with the fake reads and fake records li = makeLTBS(Arrays.asList(read), createTestReadProperties()); final LIBS_position tester = new LIBS_position(read); while (li.hasNext()) { AlignmentContext alignmentContext = li.next(); ReadBackedPileup p = alignmentContext.getBasePileup(); Assert.assertTrue(p.getNumberOfElements() == 1); PileupElement pe = p.iterator().next(); tester.stepForwardOnGenome(); Assert.assertEquals(pe.isBeforeDeletedBase(), tester.isBeforeDeletedBase); Assert.assertEquals(pe.isBeforeDeletionStart(), tester.isBeforeDeletionStart); Assert.assertEquals(pe.isAfterDeletedBase(), tester.isAfterDeletedBase); Assert.assertEquals(pe.isAfterDeletionEnd(), tester.isAfterDeletionEnd); Assert.assertEquals(pe.isBeforeInsertion(), tester.isBeforeInsertion); Assert.assertEquals(pe.isAfterInsertion(), tester.isAfterInsertion); Assert.assertEquals(pe.isNextToSoftClip(), tester.isNextToSoftClip); Assert.assertEquals(pe.getOffset(), tester.getCurrentReadOffset()); } }
@Override public String map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { final String rods = getReferenceOrderedData(tracker); ReadBackedPileup basePileup = context.getBasePileup(); final StringBuilder s = new StringBuilder(); s.append(String.format("%s %s", basePileup.getPileupString((char) ref.getBase()), rods)); if (SHOW_VERBOSE) s.append(" ").append(createVerboseOutput(basePileup)); s.append("\n"); return s.toString(); }
private Map<String, AlignmentContext> getFilteredAndStratifiedContexts( UnifiedArgumentCollection UAC, ReferenceContext refContext, AlignmentContext rawContext, final GenotypeLikelihoodsCalculationModel.Model model) { if (!BaseUtils.isRegularBase(refContext.getBase())) return null; Map<String, AlignmentContext> stratifiedContexts = null; if (model.name().contains("INDEL")) { final ReadBackedPileup pileup = rawContext.getBasePileup().getMappingFilteredPileup(UAC.MIN_BASE_QUALTY_SCORE); // don't call when there is no coverage if (pileup.getNumberOfElements() == 0 && UAC.OutputMode != OUTPUT_MODE.EMIT_ALL_SITES) return null; // stratify the AlignmentContext and cut by sample stratifiedContexts = AlignmentContextUtils.splitContextBySampleName(pileup); } else if (model.name().contains("SNP")) { // stratify the AlignmentContext and cut by sample stratifiedContexts = AlignmentContextUtils.splitContextBySampleName(rawContext.getBasePileup()); if (!(UAC.OutputMode == OUTPUT_MODE.EMIT_ALL_SITES && UAC.GenotypingMode != GenotypeLikelihoodsCalculationModel.GENOTYPING_MODE.GENOTYPE_GIVEN_ALLELES)) { int numDeletions = 0; for (final PileupElement p : rawContext.getBasePileup()) { if (p.isDeletion()) numDeletions++; } if (((double) numDeletions) / ((double) rawContext.getBasePileup().getNumberOfElements()) > UAC.MAX_DELETION_FRACTION) { return null; } } } return stratifiedContexts; }
private Map<String, Object> annotateSNP(AlignmentContext stratifiedContext, VariantContext vc) { if (!stratifiedContext.hasBasePileup()) return null; HashMap<Byte, Integer> alleleCounts = new HashMap<Byte, Integer>(); for (Allele allele : vc.getAlternateAlleles()) alleleCounts.put(allele.getBases()[0], 0); ReadBackedPileup pileup = stratifiedContext.getBasePileup(); int totalDepth = pileup.size(); Map<String, Object> map = new HashMap<String, Object>(); map.put(getKeyNames().get(0), totalDepth); // put total depth in right away if (totalDepth == 0) return map; // done, can not compute FA at 0 coverage!! int mq0 = 0; // number of "ref" reads that are acually mq0 for (PileupElement p : pileup) { if (p.getMappingQual() == 0) { mq0++; continue; } if (alleleCounts.containsKey(p.getBase())) // non-mq0 read and it's an alt alleleCounts.put(p.getBase(), alleleCounts.get(p.getBase()) + 1); } if (mq0 == totalDepth) return map; // if all reads are mq0, there is nothing left to do // we need to add counts in the correct order String[] fracs = new String[alleleCounts.size()]; for (int i = 0; i < vc.getAlternateAlleles().size(); i++) { fracs[i] = String.format( "%.3f", ((float) alleleCounts.get(vc.getAlternateAllele(i).getBases()[0])) / (totalDepth - mq0)); } map.put(getKeyNames().get(1), fracs); return map; }
@Test public void testXandEQOperators() { final byte[] bases1 = new byte[] {'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A'}; final byte[] bases2 = new byte[] {'A', 'A', 'A', 'C', 'A', 'A', 'A', 'A', 'A', 'C'}; // create a test version of the Reads object ReadProperties readAttributes = createTestReadProperties(); SAMRecord r1 = ArtificialSAMUtils.createArtificialRead(header, "r1", 0, 1, 10); r1.setReadBases(bases1); r1.setBaseQualities(new byte[] {20, 20, 20, 20, 20, 20, 20, 20, 20, 20}); r1.setCigarString("10M"); SAMRecord r2 = ArtificialSAMUtils.createArtificialRead(header, "r2", 0, 1, 10); r2.setReadBases(bases2); r2.setBaseQualities(new byte[] {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}); r2.setCigarString("3=1X5=1X"); SAMRecord r3 = ArtificialSAMUtils.createArtificialRead(header, "r3", 0, 1, 10); r3.setReadBases(bases2); r3.setBaseQualities(new byte[] {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}); r3.setCigarString("3=1X5M1X"); SAMRecord r4 = ArtificialSAMUtils.createArtificialRead(header, "r4", 0, 1, 10); r4.setReadBases(bases2); r4.setBaseQualities(new byte[] {20, 20, 20, 20, 20, 20, 20, 20, 20, 20}); r4.setCigarString("10M"); List<SAMRecord> reads = Arrays.asList(r1, r2, r3, r4); // create the iterator by state with the fake reads and fake records li = makeLTBS(reads, readAttributes); while (li.hasNext()) { AlignmentContext context = li.next(); ReadBackedPileup pileup = context.getBasePileup(); Assert.assertEquals(pileup.depthOfCoverage(), 4); } }
private static String createVerboseOutput(final ReadBackedPileup pileup) { final StringBuilder sb = new StringBuilder(); boolean isFirst = true; sb.append(pileup.getNumberOfDeletions()); sb.append(" "); for (PileupElement p : pileup) { if (isFirst) isFirst = false; else sb.append(","); sb.append(p.getRead().getReadName()); sb.append(verboseDelimiter); sb.append(p.getOffset()); sb.append(verboseDelimiter); sb.append(p.getRead().getReadLength()); sb.append(verboseDelimiter); sb.append(p.getRead().getMappingQuality()); } return sb.toString(); }
/** * Test to make sure that reads supporting only an indel (example cigar string: 76I) are * represented properly */ @Test public void testWholeIndelReadRepresentedTest() { final int firstLocus = 44367788, secondLocus = firstLocus + 1; SAMRecord read1 = ArtificialSAMUtils.createArtificialRead(header, "read1", 0, secondLocus, 1); read1.setReadBases(Utils.dupBytes((byte) 'A', 1)); read1.setBaseQualities(Utils.dupBytes((byte) '@', 1)); read1.setCigarString("1I"); List<SAMRecord> reads = Arrays.asList(read1); // create the iterator by state with the fake reads and fake records li = makeLTBS(reads, createTestReadProperties()); while (li.hasNext()) { AlignmentContext alignmentContext = li.next(); ReadBackedPileup p = alignmentContext.getBasePileup(); Assert.assertTrue(p.getNumberOfElements() == 1); PileupElement pe = p.iterator().next(); Assert.assertTrue(pe.isBeforeInsertion()); Assert.assertFalse(pe.isAfterInsertion()); Assert.assertEquals(pe.getEventBases(), "A"); } SAMRecord read2 = ArtificialSAMUtils.createArtificialRead(header, "read2", 0, secondLocus, 10); read2.setReadBases(Utils.dupBytes((byte) 'A', 10)); read2.setBaseQualities(Utils.dupBytes((byte) '@', 10)); read2.setCigarString("10I"); reads = Arrays.asList(read2); // create the iterator by state with the fake reads and fake records li = makeLTBS(reads, createTestReadProperties()); while (li.hasNext()) { AlignmentContext alignmentContext = li.next(); ReadBackedPileup p = alignmentContext.getBasePileup(); Assert.assertTrue(p.getNumberOfElements() == 1); PileupElement pe = p.iterator().next(); Assert.assertTrue(pe.isBeforeInsertion()); Assert.assertFalse(pe.isAfterInsertion()); Assert.assertEquals(pe.getEventBases(), "AAAAAAAAAA"); } }