/** * @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 }
/** 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,
protected int getNumAlignedBases(SAMRecord rec) { int numAlignedBases = 0; for (final AlignmentBlock alignmentBlock : rec.getAlignmentBlocks()) { numAlignedBases += alignmentBlock.getLength(); } return numAlignedBases; }
case X : final int length = e.getLength(); alignmentBlocks.add(new AlignmentBlock(readBase, refBase, length)); readBase += length; refBase += length;
final int referenceSequenceLength = sequence.getSequenceLength(); for (final AlignmentBlock alignmentBlock : alignmentBlocks) { if (alignmentBlock.getReferenceStart() + alignmentBlock.getLength() - 1 > referenceSequenceLength) { if (ret == null) ret = new ArrayList<>(); ret.add(new SAMValidationError(SAMValidationError.Type.CIGAR_MAPS_OFF_REFERENCE,
/** 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; }
protected int getNumAlignedBases(SAMRecord rec) { int numAlignedBases = 0; for (final AlignmentBlock alignmentBlock : rec.getAlignmentBlocks()) { numAlignedBases += alignmentBlock.getLength(); } return numAlignedBases; }
case X: final int length = e.getLength(); alignmentBlocks.add(new AlignmentBlock(readBase, refBase, length)); readBase += length; refBase += length;
if (CoordMath.getEnd(alignmentBlock.getReadStart(), alignmentBlock.getLength()) < position) { continue; } else if (position < alignmentBlock.getReadStart()) { return 0; } else { return alignmentBlock.getReferenceStart() + position - alignmentBlock.getReadStart();
final int referenceSequenceLength = sequence.getSequenceLength(); for (final AlignmentBlock alignmentBlock : alignmentBlocks) { if (alignmentBlock.getReferenceStart() + alignmentBlock.getLength() - 1 > referenceSequenceLength) { if (ret == null) ret = new ArrayList<>(); ret.add(new SAMValidationError(SAMValidationError.Type.CIGAR_MAPS_OFF_REFERENCE,
/** * 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(); } } }
@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; }
case X: final int length = e.getLength(); alignmentBlocks.add(new AlignmentBlock(readBase, refBase, length)); readBase += length; refBase += length;
if (CoordMath.getEnd(alignmentBlock.getReferenceStart(), alignmentBlock.getLength()) >= pos) { if (pos < alignmentBlock.getReferenceStart()) { return pos - alignmentBlock.getReferenceStart() + alignmentBlock.getReadStart() ; lastAlignmentOffset = alignmentBlock.getReadStart() + alignmentBlock.getLength() - 1 ;
final int referenceSequenceLength = sequence.getSequenceLength(); for (final AlignmentBlock alignmentBlock : alignmentBlocks) { if (alignmentBlock.getReferenceStart() + alignmentBlock.getLength() - 1 > referenceSequenceLength) { if (ret == null) ret = new ArrayList<>(); ret.add(new SAMValidationError(SAMValidationError.Type.CIGAR_MAPS_OFF_REFERENCE,
/** * 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(); } } }
@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; }
case X: final int length = e.getLength(); alignmentBlocks.add(new AlignmentBlock(readBase, refBase, length)); readBase += length; refBase += length;
if (CoordMath.getEnd(alignmentBlock.getReadStart(), alignmentBlock.getLength()) < position) { continue; } else if (position < alignmentBlock.getReadStart()) { return 0; } else { return alignmentBlock.getReferenceStart() + position - alignmentBlock.getReadStart();