/** * Checks that the average quality over the entire read is >= min, and that the first N bases do * not contain any no-calls. */ boolean passesQualityCheck(final byte[] bases, final byte[] quals, final int seedLength, final int minQuality) { if (bases.length < seedLength) return false; for (int i = 0; i < seedLength; ++i) { if (SequenceUtil.isNoCall(bases[i])) return false; } final int maxReadLength = (MAX_READ_LENGTH <= 0) ? Integer.MAX_VALUE : MAX_READ_LENGTH; final int readLength = Math.min(bases.length, maxReadLength); int total = 0; for (int i = 0; i < readLength; i++) total += quals[i]; return total / readLength >= minQuality; } }
/** * Checks that the average quality over the entire read is >= min, and that the first N bases do * not contain any no-calls. */ boolean passesQualityCheck(final byte[] bases, final byte[] quals, final int seedLength, final int minQuality) { if (bases.length < seedLength) return false; for (int i = 0; i < seedLength; ++i) { if (SequenceUtil.isNoCall(bases[i])) return false; } final int maxReadLength = (MAX_READ_LENGTH <= 0) ? Integer.MAX_VALUE : MAX_READ_LENGTH; final int readLength = Math.min(bases.length, maxReadLength); int total = 0; for (int i = 0; i < readLength; i++) total += quals[i]; return total / readLength >= minQuality; } }
/** * Checks if reference base at given position is unknown. * * @param position to check the base * @param ref reference sequence * @return true if reference base at position represents a no call, otherwise false */ boolean isReferenceBaseN(final int position, final ReferenceSequence ref) { final byte base = ref.getBases()[position - 1]; return SequenceUtil.isNoCall(base); } }
/** * the function by which new loci are "shown" to the calculator **/ @Override public void addBase(final SamLocusIterator.RecordAndOffset recordAndOffset, final SamLocusAndReferenceIterator.SAMLocusAndReference locusAndRef) { if (!SequenceUtil.isNoCall(recordAndOffset.getReadBase())) { nBases++; } } }
/** * Truncate to the given length, and in addition truncate any trailing Ns. */ private String substringAndRemoveTrailingNs(final String s, int length) { length = Math.min(length, s.length()); final byte[] bytes = StringUtil.stringToBytes(s); while (length > 0 && SequenceUtil.isNoCall(bytes[length - 1])) { length--; } return s.substring(0, length); }
/** * Checks if reference base at given position is unknown. * * @param position to check the base * @param ref reference sequence * @return true if reference base at position represents a no call, otherwise false */ boolean isReferenceBaseN(final int position, final ReferenceSequence ref) { final byte base = ref.getBases()[position - 1]; return SequenceUtil.isNoCall(base); } }
/** * Truncate to the given length, and in addition truncate any trailing Ns. */ private String substringAndRemoveTrailingNs(final String s, int length) { length = Math.min(length, s.length()); final byte[] bytes = StringUtil.stringToBytes(s); while (length > 0 && SequenceUtil.isNoCall(bytes[length - 1])) { length--; } return s.substring(0, length); }
/** * the function by which new loci are "shown" to the calculator **/ @Override public void addBase(final SamLocusIterator.RecordAndOffset recordAndOffset, final SamLocusAndReferenceIterator.SAMLocusAndReference locusAndRef) { if (!SequenceUtil.isNoCall(recordAndOffset.getReadBase())) { nBases++; } } }
/** * Determines whether a SAMRecord matches this filter * * @param record the SAMRecord to evaluate * @return true if the SAMRecord matches the filter, otherwise false */ @Override public boolean filterOut(final SAMRecord record) { final byte[] sequence = record.getReadBases(); for (final byte base : sequence) { if (base != 'A' && base != 'a' && !SequenceUtil.isNoCall(base)) { return false; } } return true; }
/** * Determines whether a SAMRecord matches this filter * * @param record the SAMRecord to evaluate * @return true if the SAMRecord matches the filter, otherwise false */ public boolean filterOut(final SAMRecord record) { final byte[] sequence = record.getReadBases(); for (final byte base : sequence) { if (base != 'A' && base != 'a' && !SequenceUtil.isNoCall(base)) { return false; } } return true; }
/** * The function by which new loci are "shown" to the calculator **/ @Override public void addBase(final SamLocusIterator.RecordAndOffset recordAndOffset, final SamLocusAndReferenceIterator.SAMLocusAndReference locusAndRef) { super.addBase(recordAndOffset, locusAndRef); final byte readBase = recordAndOffset.getReadBase(); if (!SequenceUtil.isNoCall(readBase) && (readBase != locusAndRef.getReferenceBase())) { nMismatchingBases++; } }
/** * The function by which new loci are "shown" to the calculator **/ @Override public void addBase(final SamLocusIterator.RecordAndOffset recordAndOffset, final SamLocusAndReferenceIterator.SAMLocusAndReference locusAndRef) { super.addBase(recordAndOffset, locusAndRef); final byte readBase = recordAndOffset.getReadBase(); if (!SequenceUtil.isNoCall(readBase) && (readBase != locusAndRef.getReferenceBase())) { nMismatchingBases++; } }
/** * Calculates the sum of error probabilities for all read bases in the SAM record. Takes * the SAM record as opposed to the qualities directly so that it can make sure to count * no-calls as 1 instead of what the quality score says. * */ public static double sumOfErrorProbabilities(final SAMRecord rec) { final byte[] bases = rec.getReadBases(); final byte[] quals = rec.getBaseQualities(); double sum = 0; for (int i=0; i<bases.length; ++i) { if (SequenceUtil.isNoCall(bases[i])) ++sum; else sum += QualityUtil.getErrorProbabilityFromPhredScore(quals[i]); } return sum; } }
/** * Calculates the sum of error probabilities for all read bases in the SAM record. Takes * the SAM record as opposed to the qualities directly so that it can make sure to count * no-calls as 1 instead of what the quality score says. * */ public static double sumOfErrorProbabilities(final SAMRecord rec) { final byte[] bases = rec.getReadBases(); final byte[] quals = rec.getBaseQualities(); double sum = 0; for (int i=0; i<bases.length; ++i) { if (SequenceUtil.isNoCall(bases[i])) ++sum; else sum += QualityUtil.getErrorProbabilityFromPhredScore(quals[i]); } return sum; } }
/** * Calculates the sum of error probabilities for all read bases in the SAM record. Takes * the SAM record as opposed to the qualities directly so that it can make sure to count * no-calls as 1 instead of what the quality score says. * */ public static double sumOfErrorProbabilities(final SAMRecord rec) { final byte[] bases = rec.getReadBases(); final byte[] quals = rec.getBaseQualities(); double sum = 0; for (int i=0; i<bases.length; ++i) { if (SequenceUtil.isNoCall(bases[i])) ++sum; else sum += QualityUtil.getErrorProbabilityFromPhredScore(quals[i]); } return sum; } }
@Override public Integer stratify(final SAMRecord sam) { int numberOfNsInRead = 0; // Check to see if we've already seen this record before. If not, count the number // of Ns in the read, and store it in a transient attribute. If we have seen it // before, simply retrieve the value and avoid doing the computation again. if (sam.getTransientAttribute(numberOfNsTag) != null) { numberOfNsInRead = (Integer) sam.getTransientAttribute(numberOfNsTag); } else { final byte[] bases = sam.getReadBases(); for (final byte base : bases) { if (SequenceUtil.isNoCall(base)) { numberOfNsInRead++; } } sam.setTransientAttribute(numberOfNsTag, numberOfNsInRead); } return numberOfNsInRead; }
private static Character stratifyReferenceBase(final RecordAndOffset recordAndOffset, final SAMLocusAndReference locusInfo) { final ReadDirection direction = ReadDirection.of(recordAndOffset.getRecord()); if (SequenceUtil.isNoCall(locusInfo.getReferenceBase())) { return null; } return stratifySequenceBase(locusInfo.getReferenceBase(), direction == ReadDirection.NEGATIVE); }
private static Character stratifyReferenceBase(final RecordAndOffset recordAndOffset, final SAMLocusAndReference locusInfo) { final ReadDirection direction = ReadDirection.of(recordAndOffset.getRecord()); if (SequenceUtil.isNoCall(locusInfo.getReferenceBase())) { return null; } return stratifySequenceBase(locusInfo.getReferenceBase(), direction == ReadDirection.NEGATIVE); }
@Override protected void acceptRead(final SAMRecord rec, final ReferenceSequence ref) { // Skip unwanted records if (PF_READS_ONLY && rec.getReadFailsVendorQualityCheckFlag()) return; if (ALIGNED_READS_ONLY && rec.getReadUnmappedFlag()) return; if (rec.isSecondaryOrSupplementary()) return; final byte[] bases = rec.getReadBases(); final byte[] quals = rec.getBaseQualities(); final byte[] oq = rec.getOriginalBaseQualities(); final int length = quals.length; for (int i=0; i<length; ++i) { if (INCLUDE_NO_CALLS || !SequenceUtil.isNoCall(bases[i])) { qCounts[quals[i]]++; if (oq != null) oqCounts[oq[i]]++; } } }
@Override protected void acceptRead(final SAMRecord rec, final ReferenceSequence ref) { // Skip unwanted records if (PF_READS_ONLY && rec.getReadFailsVendorQualityCheckFlag()) return; if (ALIGNED_READS_ONLY && rec.getReadUnmappedFlag()) return; if (rec.isSecondaryOrSupplementary()) return; final byte[] bases = rec.getReadBases(); final byte[] quals = rec.getBaseQualities(); final byte[] oq = rec.getOriginalBaseQualities(); final int length = quals.length; for (int i=0; i<length; ++i) { if (INCLUDE_NO_CALLS || !SequenceUtil.isNoCall(bases[i])) { qCounts[quals[i]]++; if (oq != null) oqCounts[oq[i]]++; } } }