protected void justify ( Variant variant , int startOffset , int endOffset , String allele , String genomicSequence , String strand ) { StringBuilder stringBuilder = new StringBuilder ( allele ) ; // Justify to the left if ( "-" . equals ( strand ) ) { while ( startOffset > 0 && genomicSequence . charAt ( startOffset - 1 ) == stringBuilder . charAt ( stringBuilder . length ( ) - 1 ) ) { stringBuilder . deleteCharAt ( stringBuilder . length ( ) - 1 ) ; stringBuilder . insert ( 0 , genomicSequence . charAt ( startOffset - 1 ) ) ; startOffset -- ; endOffset -- ; variant . setStart ( variant . getStart ( ) - 1 ) ; variant . setEnd ( variant . getEnd ( ) - 1 ) ; } // Justify to the right } else { while ( ( endOffset + 1 ) < genomicSequence . length ( ) && genomicSequence . charAt ( endOffset + 1 ) == stringBuilder . charAt ( 0 ) ) { stringBuilder . deleteCharAt ( 0 ) ; stringBuilder . append ( genomicSequence . charAt ( endOffset + 1 ) ) ; startOffset ++ ; endOffset ++ ; variant . setStart ( variant . getStart ( ) + 1 ) ; variant . setEnd ( variant . getEnd ( ) + 1 ) ; } } // Insertion if ( variant . getReference ( ) . isEmpty ( ) ) { variant . setAlternate ( stringBuilder . toString ( ) ) ; // Deletion } else { variant . setReference ( stringBuilder . toString ( ) ) ; } }
Justify an indel to the left or right along a sequence seq .