/** * @return The number of read bases that the read covers. */ public static int getReadLength(final List<CigarElement> cigarElements) { int length = 0; for (final CigarElement element : cigarElements) { if (element.getOperator().consumesReadBases()){ length += element.getLength(); } } return length; }
/** * @return The number of read bases that the read covers. */ public static int getReadLength(final List<CigarElement> cigarElements) { int length = 0; for (final CigarElement element : cigarElements) { if (element.getOperator().consumesReadBases()){ length += element.getLength(); } } return length; }
/** * @return The number of read bases that the read covers. */ public static int getReadLength(final List<CigarElement> cigarElements) { int length = 0; for (final CigarElement element : cigarElements) { if (element.getOperator().consumesReadBases()){ length += element.getLength(); } } return length; }
/** * Returns the number of read bases 'consumed' by the given cigar * @param list * @return base count */ public static int readLength(List<CigarElement> list) { int length = 0; for (CigarElement e : list) { if (e.getOperator().consumesReadBases()) { length += e.getLength(); } } return length; } /**
/** * Determines if a cigar has any element that both consumes read bases and consumes reference bases * (e.g. is not all soft-clipped) */ public static boolean cigarMapsNoBasesToRef(final Cigar cigar) { for (final CigarElement el : cigar.getCigarElements()) { if (el.getOperator().consumesReadBases() && el.getOperator().consumesReferenceBases()) { return false; } } return true; }
/** * Determines if a cigar has any element that both consumes read bases and consumes reference bases * (e.g. is not all soft-clipped) */ public static boolean cigarMapsNoBasesToRef(final Cigar cigar) { for (final CigarElement el : cigar.getCigarElements()) { if (el.getOperator().consumesReadBases() && el.getOperator().consumesReferenceBases()) { return false; } } return true; }
/** * Determines if a cigar has any element that both consumes read bases and consumes reference bases * (e.g. is not all soft-clipped) */ public static boolean cigarMapsNoBasesToRef(final Cigar cigar) { for (final CigarElement el : cigar.getCigarElements()) { if (el.getOperator().consumesReadBases() && el.getOperator().consumesReferenceBases()) { return false; } } return true; }
/** * Determines if a cigar has any element that both consumes read bases and consumes reference bases * (e.g. is not all soft-clipped) */ public static boolean cigarMapsNoBasesToRef(final Cigar cigar) { for (final CigarElement el : cigar.getCigarElements()) { if (el.getOperator().consumesReadBases() && el.getOperator().consumesReferenceBases()) { return false; } } return true; }
public static int countMappedBases(List<CigarElement> cigar) { int mapped = 0; for (CigarElement e : cigar) { if (e.getOperator().consumesReferenceBases() && e.getOperator().consumesReadBases()) { mapped += e.getLength(); } } return mapped; } /**
static private void elementStraddlesClippedRead(List<CigarElement> newCigar, CigarElement c, int relativeClippedPosition, int clippedBases){ final CigarOperator op = c.getOperator(); int clipAmount = clippedBases; if (op.consumesReadBases()){ if (op.consumesReferenceBases() & relativeClippedPosition > 0){ newCigar.add(new CigarElement(relativeClippedPosition, op)); } if (!op.consumesReferenceBases()){ clipAmount = clippedBases + relativeClippedPosition; } } else if (relativeClippedPosition != 0){ throw new SAMException("Unexpected non-0 relativeClippedPosition " + relativeClippedPosition); } newCigar.add(new CigarElement(clipAmount, CigarOperator.S)); // S is always last element }
static private void elementStraddlesClippedRead(List<CigarElement> newCigar, CigarElement c, int relativeClippedPosition, int clippedBases){ final CigarOperator op = c.getOperator(); int clipAmount = clippedBases; if (op.consumesReadBases()){ if (op.consumesReferenceBases() & relativeClippedPosition > 0){ newCigar.add(new CigarElement(relativeClippedPosition, op)); } if (!op.consumesReferenceBases()){ clipAmount = clippedBases + relativeClippedPosition; } } else if (relativeClippedPosition != 0){ throw new SAMException("Unexpected non-0 relativeClippedPosition " + relativeClippedPosition); } newCigar.add(new CigarElement(clipAmount, CigarOperator.S)); // S is always last element }
static private void elementStraddlesClippedRead(List<CigarElement> newCigar, CigarElement c, int relativeClippedPosition, int clippedBases){ final CigarOperator op = c.getOperator(); int clipAmount = clippedBases; if (op.consumesReadBases()){ if (op.consumesReferenceBases() & relativeClippedPosition > 0){ newCigar.add(new CigarElement(relativeClippedPosition, op)); } if (!op.consumesReferenceBases()){ clipAmount = clippedBases + relativeClippedPosition; } } else if (relativeClippedPosition != 0){ throw new SAMException("Unexpected non-0 relativeClippedPosition " + relativeClippedPosition); } newCigar.add(new CigarElement(clipAmount, CigarOperator.S)); // S is always last element }
/** * Returns the alignment offset of the given base relative to the starting alignment * @param cigar alignment CIGAR * @param readBaseOffset base offset * @return offset relative to first alignment */ public static int offsetOf(Cigar cigar, int readBaseOffset) { List<CigarElement> cl = cigar.getCigarElements(); int basesLeft = readBaseOffset; int currentAlignmentOffset = 0; for (int i = 0; i < cl.size(); i++) { CigarElement ce = cl.get(i); if (ce.getOperator().consumesReadBases() && ce.getOperator().consumesReferenceBases()) { if (basesLeft < ce.getLength()) { return currentAlignmentOffset + basesLeft; } } if (ce.getOperator().consumesReferenceBases()) { currentAlignmentOffset += ce.getLength(); } if (ce.getOperator().consumesReadBases()) { basesLeft = Math.max(0, basesLeft - ce.getLength()); } } throw new IllegalArgumentException(String.format("Offset of %d base not defined for %s", readBaseOffset, cigar)); } /**
private void parseAlignments() { Utils.parseCigarInto(evidenceRecord.ReferenceAlignment, firstHalf.cgCigElList); int len = 0; for (CigEl e : firstHalf.cgCigElList) { switch (e.op) { case 'B': break; default: len += CigarOperator.characterToEnum(e.op).consumesReadBases() ? e.len : 0; break; } } if ((evidenceRecord.side == 1 && !evidenceRecord.negativeStrand) || (evidenceRecord.side == 0 && evidenceRecord.negativeStrand)) { secondHalf.baseBuf = Utils.slice(baseBuf, 0, len); secondHalf.scoreBuf = Utils.slice(scoreBuf, 0, len); firstHalf.baseBuf = Utils.slice(baseBuf, len, baseBuf.limit()); firstHalf.scoreBuf = Utils.slice(scoreBuf, len, scoreBuf.limit()); } else { firstHalf.baseBuf = Utils.slice(baseBuf, 0, len); firstHalf.scoreBuf = Utils.slice(scoreBuf, 0, len); secondHalf.baseBuf = Utils.slice(baseBuf, len, baseBuf.limit()); secondHalf.scoreBuf = Utils.slice(scoreBuf, len, scoreBuf.limit()); } Utils.parseCigarInto(evidenceRecord.MateReferenceAlignment, secondHalf.cgCigElList); }
public boolean filterOut(final SAMRecord read) { int alignedLength = 0; int softClipBlocks = 0; int minSoftClipBlocks = doNotRequireSoftclipsOnBothEnds ? 1 : 2; CigarOperator lastOperator = null; for ( final CigarElement element : read.getCigar().getCigarElements() ) { if ( element.getOperator() == CigarOperator.S ) { //Treat consecutive S blocks as a single one if(lastOperator != CigarOperator.S){ softClipBlocks += 1; } } else if ( element.getOperator().consumesReadBases() ) { // M, I, X, and EQ (S was already accounted for above) alignedLength += element.getLength(); } lastOperator = element.getOperator(); } return(alignedLength < tooShort && softClipBlocks >= minSoftClipBlocks); }
@Override public boolean filterOut(final SAMRecord record) { int alignedLength = 0; int softClipBlocks = 0; int minSoftClipBlocks = filterSingleEndClips ? 1 : 2; CigarOperator lastOperator = null; for ( final CigarElement element : record.getCigar().getCigarElements() ) { if ( element.getOperator() == CigarOperator.S ) { //Treat consecutive S blocks as a single one if(lastOperator != CigarOperator.S){ softClipBlocks += 1; } } else if ( element.getOperator().consumesReadBases() ) { // M, I, X, and EQ (S was already accounted for above) alignedLength += element.getLength(); } lastOperator = element.getOperator(); } return(alignedLength < unclippedBasesThreshold && softClipBlocks >= minSoftClipBlocks); }
@Override public boolean filterOut(final SAMRecord record) { int alignedLength = 0; int softClipBlocks = 0; int minSoftClipBlocks = filterSingleEndClips ? 1 : 2; CigarOperator lastOperator = null; for ( final CigarElement element : record.getCigar().getCigarElements() ) { if ( element.getOperator() == CigarOperator.S ) { //Treat consecutive S blocks as a single one if(lastOperator != CigarOperator.S){ softClipBlocks += 1; } } else if ( element.getOperator().consumesReadBases() ) { // M, I, X, and EQ (S was already accounted for above) alignedLength += element.getLength(); } lastOperator = element.getOperator(); } return(alignedLength < unclippedBasesThreshold && softClipBlocks >= minSoftClipBlocks); }
private static ImmutableRangeSet<Integer> getMappedBases(int start, Cigar cigar) { Builder<Integer> builder = ImmutableRangeSet.builder(); int position = start; for (CigarElement op : cigar.getCigarElements()) { if (op.getOperator().consumesReferenceBases()) { if (op.getOperator().consumesReadBases()) { builder.add(Range.closedOpen(position, position + op.getLength())); } position += op.getLength(); } } return builder.build(); } /**
private static void updateTracks(final List<SAMRecord> samRecords, final ReferenceTracks tracks) { for (final SAMRecord samRecord : samRecords) { if (samRecord.getAlignmentStart() != SAMRecord.NO_ALIGNMENT_START) { int refPos = samRecord.getAlignmentStart(); int readPos = 0; for (final CigarElement cigarElement : samRecord.getCigar().getCigarElements()) { if (cigarElement.getOperator().consumesReferenceBases()) { for (int elementIndex = 0; elementIndex < cigarElement.getLength(); elementIndex++) tracks.addCoverage(refPos + elementIndex, 1); } switch (cigarElement.getOperator()) { case M: case X: case EQ: for (int pos = readPos; pos < cigarElement.getLength(); pos++) { final byte readBase = samRecord.getReadBases()[readPos + pos]; final byte refBase = tracks.baseAt(refPos + pos); if (readBase != refBase) tracks.addMismatches(refPos + pos, 1); } break; default: break; } readPos += cigarElement.getOperator().consumesReadBases() ? cigarElement.getLength() : 0; refPos += cigarElement.getOperator().consumesReferenceBases() ? cigarElement.getLength() : 0; } } } }
private static void updateTracks(final List<SAMRecord> samRecords, final ReferenceTracks tracks) { for (final SAMRecord samRecord : samRecords) { if (samRecord.getAlignmentStart() != SAMRecord.NO_ALIGNMENT_START) { int refPos = samRecord.getAlignmentStart(); int readPos = 0; for (final CigarElement cigarElement : samRecord.getCigar().getCigarElements()) { if (cigarElement.getOperator().consumesReferenceBases()) { for (int elementIndex = 0; elementIndex < cigarElement.getLength(); elementIndex++) tracks.addCoverage(refPos + elementIndex, 1); } switch (cigarElement.getOperator()) { case M: case X: case EQ: for (int pos = readPos; pos < cigarElement.getLength(); pos++) { final byte readBase = samRecord.getReadBases()[readPos + pos]; final byte refBase = tracks.baseAt(refPos + pos); if (readBase != refBase) tracks.addMismatches(refPos + pos, 1); } break; default: break; } readPos += cigarElement.getOperator().consumesReadBases() ? cigarElement.getLength() : 0; refPos += cigarElement.getOperator().consumesReferenceBases() ? cigarElement.getLength() : 0; } } } }