@Test(dataProvider = "TrimCigarByBasesData", enabled = !DEBUG) public void testTrimCigarByBase(final String cigarString, final int start, final int length, final String expectedCigarString) { final Cigar cigar = TextCigarCodec.decode(cigarString); final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString); final Cigar actualCigar = AlignmentUtils.trimCigarByBases(cigar, start, length); Assert.assertEquals(actualCigar, expectedCigar); }
/** * Calculate the cigar elements for this path against the reference sequence * * @param refSeq the reference sequence that all of the bases in this path should align to * @return a Cigar mapping this path to refSeq, or null if no reasonable alignment could be found */ public static Cigar calculateCigar(final byte[] refSeq, final byte[] altSeq) { if ( altSeq.length == 0 ) { // horrible edge case from the unit tests, where this path has no bases return new Cigar(Arrays.asList(new CigarElement(refSeq.length, CigarOperator.D))); } final Cigar nonStandard; final String paddedRef = SW_PAD + new String(refSeq) + SW_PAD; final String paddedPath = SW_PAD + new String(altSeq) + SW_PAD; final SmithWaterman alignment = new SWPairwiseAlignment( paddedRef.getBytes(), paddedPath.getBytes(), NEW_SW_PARAMETERS); if ( isSWFailure(alignment) ) { return null; } // cut off the padding bases final int baseStart = SW_PAD.length(); final int baseEnd = paddedPath.length() - SW_PAD.length() - 1; // -1 because it's inclusive nonStandard = AlignmentUtils.trimCigarByBases(alignment.getCigar(), baseStart, baseEnd); if ( nonStandard.getReferenceLength() != refSeq.length ) { nonStandard.add(new CigarElement(refSeq.length - nonStandard.getReferenceLength(), CigarOperator.D)); } // finally, return the cigar with all indels left aligned return leftAlignCigarSequentially(nonStandard, refSeq, altSeq, 0, 0); }
final Cigar haplotypeToRef = trimCigarByBases(extendedHaplotypeCigar, swPairwiseAlignment.getAlignmentStart2wrt1(), extendedHaplotypeCigar.getReadLength() - 1); final Cigar readToRefCigarRaw = applyCigarToCigar(swCigar, haplotypeToRef); final Cigar readToRefCigarClean = cleanUpCigar(readToRefCigarRaw);