public static void completeDifferencesFromReference ( Alignment alignment , String referenceSequence , long referenceSequenceStart ) throws ShortReferenceSequenceException { int offset = ( int ) ( alignment . getUnclippedStart ( ) - referenceSequenceStart ) ; String subRef ; String subRead ; if ( ( alignment . getFlags ( ) & Alignment . SEGMENT_UNMAPPED ) != 0 ) { // umnmapped, return as is return ; } List < Alignment . AlignmentDifference > newDifferences = new LinkedList <> ( ) ; for ( Alignment . AlignmentDifference alignmentDifference : alignment . getDifferences ( ) ) { Alignment . AlignmentDifference currentDifference = null ; switch ( alignmentDifference . getOp ( ) ) { case Alignment . AlignmentDifference . DELETION : //If is a deletion, there is no seq. try { if ( ! alignmentDifference . isAllSequenceStored ( ) ) { subRef = referenceSequence . substring ( alignmentDifference . getPos ( ) + offset , alignmentDifference . getPos ( ) + offset + alignmentDifference . getLength ( ) ) ; alignmentDifference . setSeq ( subRef ) ; } } catch ( StringIndexOutOfBoundsException e ) { throw new ShortReferenceSequenceException ( "ReferenceSequence Out of Bounds in Alignment.completeDifferences()" ) ; } currentDifference = alignmentDifference ; break ; case Alignment . AlignmentDifference . MATCH_MISMATCH : case Alignment . AlignmentDifference . MISMATCH : // try { subRef = referenceSequence . substring ( alignmentDifference . getPos ( ) + offset , alignmentDifference . getPos ( ) + offset + alignmentDifference . getLength ( ) ) ; } catch ( StringIndexOutOfBoundsException e ) { throw new ShortReferenceSequenceException ( "ReferenceSequence Out of Bounds in Alignment.completeDifferences()" ) ; } subRead = alignmentDifference . getSeq ( ) ; newDifferences . addAll ( getMismatchDiff ( subRef , subRead , alignmentDifference . getPos ( ) ) ) ; break ; case Alignment . AlignmentDifference . HARD_CLIPPING : /* subRef = referenceSequence.substring( alignmentDifference.getPos() + offset, alignmentDifference.getPos() + offset + alignmentDifference.getLength() ); alignmentDifference.setSeq(subRef);*/ currentDifference = alignmentDifference ; break ; case Alignment . AlignmentDifference . SOFT_CLIPPING : currentDifference = alignmentDifference ; try { if ( alignmentDifference . isAllSequenceStored ( ) ) { subRef = referenceSequence . substring ( alignmentDifference . getPos ( ) + offset , alignmentDifference . getPos ( ) + offset + alignmentDifference . getLength ( ) ) ; if ( subRef . equals ( alignmentDifference . getSeq ( ) ) ) { currentDifference . setSeq ( null ) ; } } } catch ( StringIndexOutOfBoundsException e ) { //This Soft clipping difference will not be compacted. It's not a bug, just a feature. //TODO: Check for 2.0 version } break ; //offset -= alignmentDifference.getLength(); case Alignment . AlignmentDifference . INSERTION : case Alignment . AlignmentDifference . PADDING : case Alignment . AlignmentDifference . SKIPPED_REGION : // currentDifference = alignmentDifference ; break ; } if ( currentDifference != null ) { newDifferences . add ( currentDifference ) ; } } alignment . setDifferences ( newDifferences ) ; }
Compares all differences with the referenceSequence in order to reduce the stored sequence . Also adds sequence for deletion differences .