Java Code Examples for htsjdk.samtools.TextCigarCodec#encode()

The following examples show how to use htsjdk.samtools.TextCigarCodec#encode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SAMRecordUtils.java    From abra2 with MIT License 6 votes vote down vote up
public static String getLeadingClips(SAMRecord read) {
	List<CigarElement> elems = read.getCigar().getCigarElements();
	
	List<CigarElement> leading = new ArrayList<CigarElement>();
	
	for (CigarElement elem : elems) {
		if (isClip(elem)) {
			leading.add(elem);
		} else {
			break;
		}
	}
	
	String ret = "";
	if (leading.size() > 0) {
		Cigar cigar = new Cigar(leading);
		ret = TextCigarCodec.encode(cigar);
	}
	
	return ret;
}
 
Example 2
Source File: SAMRecordUtils.java    From abra2 with MIT License 6 votes vote down vote up
public static String getTrailingClips(SAMRecord read) {
	List<CigarElement> elems = read.getCigar().getCigarElements();
	
	List<CigarElement> trailing = new ArrayList<CigarElement>();
	boolean isNonClippedReached = false;
	
	for (CigarElement elem : elems) {
		if (isClip(elem)) {
			if (isNonClippedReached) {
				trailing.add(elem);
			}
		} else {
			isNonClippedReached = true;
		}
	}

	String ret = "";
	if (trailing.size() > 0) {
		Cigar cigar = new Cigar(trailing);
		ret =  TextCigarCodec.encode(cigar);
	}
	
	return ret;
}
 
Example 3
Source File: SWNativeAlignerWrapperUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected SmithWatermanAligner getAligner() {
    final SWAlignerNativeBinding javaBackedNativeBinding = new SWAlignerNativeBinding() {

        @Override
        public boolean load(File tmpDir) {
            return true;
        }

        @Override
        public SWNativeAlignerResult align(byte[] ref, byte[] alt, SWParameters parameters, SWOverhangStrategy overhangStrategy) {
            final SmithWatermanAlignment alignment = SmithWatermanJavaAligner.getInstance().align(ref, alt,
                                                                                                      parameters,
                                                                                                      overhangStrategy);
            return new SWNativeAlignerResult(TextCigarCodec.encode(alignment.getCigar()), alignment.getAlignmentOffset());
        }
    };
    return new SWNativeAlignerWrapper(javaBackedNativeBinding);
}
 
Example 4
Source File: CigarUtilsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(dataProvider = "testData_invertCigar")
public void testInvertCigar(final String cigarStrIn, final String expectedCigarStrOut){
    final Cigar cigarIn = TextCigarCodec.decode(cigarStrIn);
    final Cigar cigarOut = CigarUtils.invertCigar(cigarIn);
    final String actualCigarStrOut = TextCigarCodec.encode(cigarOut);
    Assert.assertEquals(actualCigarStrOut, expectedCigarStrOut);
}
 
Example 5
Source File: CigarUtilsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(dataProvider = "testData_unclipCigar")
public void testUnclipCigar(final String cigarStrIn, final String expectedCigarStrOut){
    final Cigar cigarIn = TextCigarCodec.decode(cigarStrIn);
    final Cigar cigarOut = CigarUtils.removeClipsAndPadding(cigarIn);
    final String actualCigarStrOut = TextCigarCodec.encode(cigarOut);
    Assert.assertEquals(actualCigarStrOut, expectedCigarStrOut);
}