protected int getNumAlignedBases(SAMRecord rec) { int numAlignedBases = 0; for (final AlignmentBlock alignmentBlock : rec.getAlignmentBlocks()) { numAlignedBases += alignmentBlock.getLength(); } return numAlignedBases; }
protected int getNumAlignedBases(SAMRecord rec) { int numAlignedBases = 0; for (final AlignmentBlock alignmentBlock : rec.getAlignmentBlocks()) { numAlignedBases += alignmentBlock.getLength(); } return numAlignedBases; }
@Override public final boolean filterOut(final SAMRecord record) { final boolean filteredOut = reallyFilterOut(record); if (filteredOut) { ++filteredRecords; for (final AlignmentBlock block : record.getAlignmentBlocks()) { this.filteredBases += block.getLength(); } } return filteredOut; }
@Override public final boolean filterOut(final SAMRecord record) { final boolean filteredOut = reallyFilterOut(record); if (filteredOut) { ++filteredRecords; for (final AlignmentBlock block : record.getAlignmentBlocks()) { this.filteredBases += block.getLength(); } } return filteredOut; }
/** * Returns 1-based index of first base in read that corresponds to M in CIGAR string. * Note that first is relative to 5' end, so that for reverse-strand alignment, the index of * the last base aligned is computed relative to the end of the read. */ int getIndexOfFirstAlignedBase(final SAMRecord rec) { final List<AlignmentBlock> alignmentBlocks = rec.getAlignmentBlocks(); if (rec.getReadNegativeStrandFlag()) { final AlignmentBlock alignmentBlock = alignmentBlocks.get(alignmentBlocks.size() - 1); return rec.getReadLength() - CoordMath.getEnd(alignmentBlock.getReadStart(), alignmentBlock.getLength()) + 1; } else { return alignmentBlocks.get(0).getReadStart(); } } }
/** * Returns 1-based index of first base in read that corresponds to M in CIGAR string. * Note that first is relative to 5' end, so that for reverse-strand alignment, the index of * the last base aligned is computed relative to the end of the read. */ int getIndexOfFirstAlignedBase(final SAMRecord rec) { final List<AlignmentBlock> alignmentBlocks = rec.getAlignmentBlocks(); if (rec.getReadNegativeStrandFlag()) { final AlignmentBlock alignmentBlock = alignmentBlocks.get(alignmentBlocks.size() - 1); return rec.getReadLength() - CoordMath.getEnd(alignmentBlock.getReadStart(), alignmentBlock.getLength()) + 1; } else { return alignmentBlocks.get(0).getReadStart(); } } }
/** Get the the number of bases in the given alignment block and record that have base quality greater or equal to the minimum */ public static int getNumBasesPassingMinimumBaseQuality(final SAMRecord record, final AlignmentBlock block, final int minimumBaseQuality) { int basesInBlockAtMinimumQuality = 0; final byte[] baseQualities = record.getBaseQualities(); for (int idx = block.getReadStart(); idx <= CoordMath.getEnd(block.getLength(), block.getReadStart()); idx++) { // idx is one-based if (minimumBaseQuality <= baseQualities[idx-1]) basesInBlockAtMinimumQuality++; } return basesInBlockAtMinimumQuality; }
/** Get the the number of bases in the given alignment block and record that have base quality greater or equal to the minimum */ public static int getNumBasesPassingMinimumBaseQuality(final SAMRecord record, final AlignmentBlock block, final int minimumBaseQuality) { int basesInBlockAtMinimumQuality = 0; final byte[] baseQualities = record.getBaseQualities(); for (int idx = block.getReadStart(); idx <= CoordMath.getEnd(block.getLength(), block.getReadStart()); idx++) { // idx is one-based if (minimumBaseQuality <= baseQualities[idx-1]) basesInBlockAtMinimumQuality++; } return basesInBlockAtMinimumQuality; }
final int referenceSequenceLength = sequence.getSequenceLength(); for (final AlignmentBlock alignmentBlock : alignmentBlocks) { if (alignmentBlock.getReferenceStart() + alignmentBlock.getLength() - 1 > referenceSequenceLength) { if (ret == null) ret = new ArrayList<SAMValidationError>(); ret.add(new SAMValidationError(SAMValidationError.Type.CIGAR_MAPS_OFF_REFERENCE,
/** * Capture the loci covered by the given SAMRecord in the LocusInfos in the accumulator, * creating new LocusInfos as needed. */ private void accumulateSamRecord(final SAMRecord rec) { // interpret the CIGAR string and add the base info for(final AlignmentBlock alignmentBlock : rec.getAlignmentBlocks()) { for (int i = 0; i < alignmentBlock.getLength(); ++i) { // 0-based offset into the read of the current base final int readOffset = alignmentBlock.getReadStart() + i - 1; // 1-based reference position that the current base aligns to final int refPos = alignmentBlock.getReferenceStart() + i; // 0-based offset from the aligned position of the first base in the read to the aligned position // of the current base. final int refOffset = refPos - rec.getAlignmentStart(); // Ensure there are LocusInfos up to and including this position for (int j = accumulator.size(); j <= refOffset; ++j) { accumulator.add(new LocusInfo(getReferenceSequence(rec.getReferenceIndex()), rec.getAlignmentStart() + j)); } // if the quality score cutoff is met, accumulate the base info if (rec.getBaseQualities()[readOffset] >= getQualityScoreCutoff()) { accumulator.get(refOffset).add(rec, readOffset); } } } }
/** * Sadly, this is a duplicate of the method above, except that it takes char[] for referenceBases rather * than byte[]. This is because GATK needs it this way. * * TODO: Remove this method when GATK map method is changed to take refseq as byte[]. */ private static int countMismatches(final SAMRecord read, final char[] referenceBases, final int referenceOffset) { int mismatches = 0; final byte[] readBases = read.getReadBases(); for (final AlignmentBlock block : read.getAlignmentBlocks()) { final int readBlockStart = block.getReadStart() - 1; final int referenceBlockStart = block.getReferenceStart() - 1 - referenceOffset; final int length = block.getLength(); for (int i=0; i<length; ++i) { if (!basesEqual(readBases[readBlockStart+i], StringUtil.charToByte(referenceBases[referenceBlockStart+i]))) { ++mismatches; } } } return mismatches; }
final int readStart = alignmentBlock.getReadStart(); final int refStart = alignmentBlock.getReferenceStart(); final int blockLength = alignmentBlock.getLength();
/** * @return 1-based inclusive reference position of the unclipped sequence at a given offset, * or 0 if there is no position. * For example, given the sequence NNNAAACCCGGG, cigar 3S9M, and an alignment start of 1, * and a (1-based)offset 10 (start of GGG) it returns 7 (1-based offset starting after the soft clip. * For example: given the sequence AAACCCGGGTTT, cigar 4M1D6M, an alignment start of 1, * an offset of 4 returns reference position 4, an offset of 5 returns reference position 6. * Another example: given the sequence AAACCCGGGTTT, cigar 4M1I6M, an alignment start of 1, * an offset of 4 returns reference position 4, an offset of 5 returns 0. * @offset 1-based location within the unclipped sequence */ public int getReferencePositionAtReadPosition(final int offset) { if (offset == 0) return 0; for (final AlignmentBlock alignmentBlock : getAlignmentBlocks()) { if (CoordMath.getEnd(alignmentBlock.getReadStart(), alignmentBlock.getLength()) < offset) { continue; } else if (offset < alignmentBlock.getReadStart()) { return 0; } else { return alignmentBlock.getReferenceStart() + offset - alignmentBlock.getReadStart(); } } return 0; // offset not located in an alignment block }
final int readStart = alignmentBlock.getReadStart(); final int refStart = alignmentBlock.getReferenceStart(); final int blockLength = alignmentBlock.getLength();
if (CoordMath.getEnd(alignmentBlock.getReadStart(), alignmentBlock.getLength()) < position) { continue; } else if (position < alignmentBlock.getReadStart()) {
public static int countMismatches(final SAMRecord read, final byte[] referenceBases, final int referenceOffset, final boolean bisulfiteSequence, final boolean matchAmbiguousRef) { try { int mismatches = 0; final byte[] readBases = read.getReadBases(); for (final AlignmentBlock block : read.getAlignmentBlocks()) { final int readBlockStart = block.getReadStart() - 1; final int referenceBlockStart = block.getReferenceStart() - 1 - referenceOffset; final int length = block.getLength(); for (int i = 0; i < length; ++i) { if (!basesMatch(readBases[readBlockStart + i], referenceBases[referenceBlockStart + i], read.getReadNegativeStrandFlag(), bisulfiteSequence, matchAmbiguousRef)) { ++mismatches; } } } return mismatches; } catch (final Exception e) { throw new SAMException("Exception counting mismatches for read " + read, e); } }
public static int countMismatches(final SAMRecord read, final byte[] referenceBases, final int referenceOffset, final boolean bisulfiteSequence, final boolean matchAmbiguousRef) { try { int mismatches = 0; final byte[] readBases = read.getReadBases(); for (final AlignmentBlock block : read.getAlignmentBlocks()) { final int readBlockStart = block.getReadStart() - 1; final int referenceBlockStart = block.getReferenceStart() - 1 - referenceOffset; final int length = block.getLength(); for (int i = 0; i < length; ++i) { if (!basesMatch(readBases[readBlockStart + i], referenceBases[referenceBlockStart + i], read.getReadNegativeStrandFlag(), bisulfiteSequence, matchAmbiguousRef)) { ++mismatches; } } } return mismatches; } catch (final Exception e) { throw new SAMException("Exception counting mismatches for read " + read, e); } }
if (CoordMath.getEnd(alignmentBlock.getReadStart(), alignmentBlock.getLength()) < position) { continue; } else if (position < alignmentBlock.getReadStart()) {
/** * Sadly, this is a duplicate of the method above, except that it takes char[] for referenceBases rather * than byte[]. This is because GATK needs it this way. * * TODO: Remove this method when GATK map method is changed to take refseq as byte[]. */ public static int sumQualitiesOfMismatches(final SAMRecord read, final char[] referenceBases, final int referenceOffset) { int qualities = 0; final byte[] readBases = read.getReadBases(); final byte[] readQualities = read.getBaseQualities(); if (read.getAlignmentStart() <= referenceOffset) { throw new IllegalArgumentException("read.getAlignmentStart(" + read.getAlignmentStart() + ") <= referenceOffset(" + referenceOffset + ")"); } for (final AlignmentBlock block : read.getAlignmentBlocks()) { final int readBlockStart = block.getReadStart() - 1; final int referenceBlockStart = block.getReferenceStart() - 1 - referenceOffset; final int length = block.getLength(); for (int i=0; i<length; ++i) { if (!basesEqual(readBases[readBlockStart+i], StringUtil.charToByte(referenceBases[referenceBlockStart+i]))) { qualities += readQualities[readBlockStart+i]; } } } return qualities; }
final int readBlockStart = block.getReadStart() - 1; final int referenceBlockStart = block.getReferenceStart() - 1 - referenceOffset; final int length = block.getLength();