private boolean isLowQualityBase( final GATKSAMRecord read, final int offset ) { return read.getBaseQualities()[offset] < minimumQToUse; }
/** * Get the element for the given read at the given reference position * * @param read the read * @param refLoc the reference position * @return a Double representing the element to be used in the rank sum test, or null if it should not be used */ @Override protected Double getElementForRead(final GATKSAMRecord read, final int refLoc) { return (double) read.getBaseQualities()[ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, refLoc, ReadUtils.ClippingTail.RIGHT_TAIL)]; }
/** * Given a read, outputs the base qualities in a string format * * @param read the read * @return a string representation of the base qualities */ public static String convertReadQualToString(GATKSAMRecord read) { return convertReadQualToString(read.getBaseQualities()); }
/** * Get the base quality score of the base at this aligned position on the genome * @return a phred-scaled quality score as a byte */ public byte getQual() { return isDeletion() ? DELETION_QUAL : read.getBaseQualities()[offset]; }
protected static void checkForMisencodedQuals(final GATKSAMRecord read) { // sample reads randomly for checking if ( ++currentReadCounter >= samplingFrequency ) { currentReadCounter = 0; final byte[] quals = read.getBaseQualities(); for ( final byte qual : quals ) { if ( qual > QualityUtils.MAX_REASONABLE_Q_SCORE ) throw new UserException.MisencodedBAM(read, "we encountered an extremely high quality score of " + (int)qual); } } } }
@Override protected Double getElementForRead(final GATKSAMRecord read, final int refLoc) { return (double)read.getBaseQualities()[ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, refLoc, ReadUtils.ClippingTail.RIGHT_TAIL)]; }
/** * Default utility to query the base insertion quality of a read. If the read doesn't have one, it creates an array of default qualities (currently Q45) * and assigns it to the read. * * @return the base insertion quality array */ public byte[] getBaseInsertionQualities() { byte [] quals = getExistingBaseInsertionQualities(); if( quals == null ) { quals = new byte[getBaseQualities().length]; Arrays.fill(quals, DEFAULT_INSERTION_DELETION_QUAL); // Some day in the future when base insertion and base deletion quals exist the samtools API will // be updated and the original quals will be pulled here, but for now we assume the original quality is a flat Q45 } return quals; }
protected Double getBaseQualityForRead(final GATKSAMRecord read, final int refLoc) { return (double)read.getBaseQualities()[ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, refLoc, ReadUtils.ClippingTail.RIGHT_TAIL)]; }
/** * Default utility to query the base deletion quality of a read. If the read doesn't have one, it creates an array of default qualities (currently Q45) * and assigns it to the read. * * @return the base deletion quality array */ public byte[] getBaseDeletionQualities() { byte[] quals = getExistingBaseDeletionQualities(); if( quals == null ) { quals = new byte[getBaseQualities().length]; Arrays.fill(quals, DEFAULT_INSERTION_DELETION_QUAL); // Some day in the future when base insertion and base deletion quals exist the samtools API will // be updated and the original quals will be pulled here, but for now we assume the original quality is a flat Q45 } return quals; }
protected static GATKSAMRecord fixMisencodedQuals(final GATKSAMRecord read) { final byte[] quals = read.getBaseQualities(); for ( int i = 0; i < quals.length; i++ ) { quals[i] -= encodingFixValue; if ( quals[i] < 0 ) throw new UserException.BadInput("while fixing mis-encoded base qualities we encountered a read that was correctly encoded; we cannot handle such a mixture of reads so unfortunately the BAM must be fixed with some other tool"); } read.setBaseQualities(quals); return read; }
public void addAlignment(GATKSAMRecord read) { output.println("@" + read.getReadName()); if (read.getReadNegativeStrandFlag()) { output.println(ReadUtils.getBasesReverseComplement(read)); output.println("+"); output.println(ReadUtils.convertReadQualToString(invertQuals(read.getBaseQualities()))); } else { output.println(ReadUtils.convertReadBasesToString(read)); output.println("+"); output.println(ReadUtils.convertReadQualToString(read)); } }
private GATKSAMRecord modifyBaseQualities(final GATKSAMRecord read, final int startOffset, final int length) throws Exception { final GATKSAMRecord readWithLowQuals = (GATKSAMRecord)read.clone(); final byte[] withLowQuals = Arrays.copyOf(read.getBaseQualities(), read.getBaseQualities().length); for ( int i = startOffset; i < startOffset + length; i++ ) withLowQuals[i] = (byte)(read.getBaseQualities()[i] + (i % 2 == 0 ? -1 : 0)); readWithLowQuals.setBaseQualities(withLowQuals); return readWithLowQuals; }
@Override public void recordValues(final GATKSAMRecord read, final ReadCovariates values) { final byte[] baseQualities = read.getBaseQualities(); final byte[] baseInsertionQualities = read.getBaseInsertionQualities(); final byte[] baseDeletionQualities = read.getBaseDeletionQualities(); for (int i = 0; i < baseQualities.length; i++) { values.addCovariate((int)baseQualities[i], (int)baseInsertionQualities[i], (int)baseDeletionQualities[i], i); } }
public byte[] getBaseQualities( final EventType errorModel ) { switch( errorModel ) { case BASE_SUBSTITUTION: return getBaseQualities(); case BASE_INSERTION: return getBaseInsertionQualities(); case BASE_DELETION: return getBaseDeletionQualities(); default: throw new ReviewedGATKException("Unrecognized Base Recalibration type: " + errorModel ); } }
private void performBatchAdditions(final List<GATKSAMRecord> reads, final List<Haplotype> haplotypes, Map<GATKSAMRecord,byte[]> gcp) { for(final GATKSAMRecord read : reads){ final byte[] readBases = read.getReadBases(); final byte[] readQuals = read.getBaseQualities(); final byte[] readInsQuals = read.getBaseInsertionQualities(); final byte[] readDelQuals = read.getBaseDeletionQualities(); final byte[] overallGCP = gcp.get(read); batchAdd(haplotypes, readBases, readQuals, readInsQuals, readDelQuals, overallGCP); } }
@Test(enabled = !DEBUG, dataProvider = "AdjustFragmentsTest") public void testAdjustingTwoReads(final GATKSAMRecord read1, final GATKSAMRecord read2, final int overlapSize) { FragmentUtils.adjustQualsOfOverlappingPairedFragments(read1, read2); for ( int i = 0; i < read1.getReadLength() - overlapSize; i++ ) Assert.assertEquals(read1.getBaseQualities()[i], highQuality); for ( int i = read1.getReadLength() - overlapSize; i < read1.getReadLength(); i++ ) Assert.assertEquals(read1.getBaseQualities()[i], overlappingQuality); for ( int i = 0; i < overlapSize; i++ ) Assert.assertEquals(read2.getBaseQualities()[i], overlappingQuality); for ( int i = overlapSize; i < read2.getReadLength(); i++ ) Assert.assertEquals(read2.getBaseQualities()[i], highQuality); } }
@Test(enabled = true) public void testFixBadQuals() { final GATKSAMRecord read = createRead(false); final GATKSAMRecord fixedRead = MisencodedBaseQualityReadTransformer.fixMisencodedQuals(read); for ( int i = 0; i < fixedQuals.length; i++ ) Assert.assertEquals(fixedQuals[i], fixedRead.getBaseQualities()[i]); }
private void assertNoLowQualBases(GATKSAMRecord read, byte low_qual) { if (!read.isEmpty()) { byte[] quals = read.getBaseQualities(); for (int i = 0; i < quals.length; i++) Assert.assertFalse(quals[i] <= low_qual, String.format("Found low qual (%d) base after hard clipping. Position: %d -- %s", low_qual, i, read.getCigarString())); } }
private void writeDebugLikelihoods(final GATKSAMRecord processedRead, final Haplotype haplotype, final double log10l){ likelihoodsStream.printf("%s %s %s %s %s %s %f%n", haplotype.getBaseString(), new String(processedRead.getReadBases() ), SAMUtils.phredToFastq(processedRead.getBaseQualities()), SAMUtils.phredToFastq(processedRead.getBaseInsertionQualities() ), SAMUtils.phredToFastq(processedRead.getBaseDeletionQualities() ), SAMUtils.phredToFastq(constantGCP), log10l); }
/** * Loads the read that is going to be evaluated in following calls to {@link #calculateLocalLikelihoods}. * * @param read the target read. * @throws NullPointerException if {@code read} is null. */ @Override public void loadRead(final GATKSAMRecord read) { loadRead(read.getReadBases(),read.getBaseQualities(),read.getBaseInsertionQualities(),read.getBaseDeletionQualities(),read.getMappingQuality()); }