Search in sources :

Example 1 with CigarUnit

use of com.google.api.services.genomics.model.CigarUnit in project gatk by broadinstitute.

the class CigarConversionUtilsUnitTest method createCigarUnit.

private CigarUnit createCigarUnit(final Long operationLength, final String operation) {
    final CigarUnit unit = new CigarUnit();
    unit.setOperationLength(operationLength);
    unit.setOperation(operation);
    return unit;
}
Also used : CigarUnit(com.google.api.services.genomics.model.CigarUnit)

Example 2 with CigarUnit

use of com.google.api.services.genomics.model.CigarUnit in project gatk by broadinstitute.

the class CigarConversionUtilsUnitTest method testConvertSAMCigarToCigarUnitList.

@Test(dataProvider = "MatchingSAMCigarAndCigarUnitListData")
public void testConvertSAMCigarToCigarUnitList(final List<CigarUnit> cigarUnitList, final Cigar samCigar) {
    final List<CigarUnit> convertedCigar = CigarConversionUtils.convertSAMCigarToCigarUnitList(samCigar);
    Assert.assertEquals(convertedCigar.size(), cigarUnitList.size(), "Wrong number of elements in CigarUnit list after conversion from SAM cigar");
    for (int i = 0; i < convertedCigar.size(); ++i) {
        final CigarUnit actualCigarUnit = convertedCigar.get(i);
        final CigarUnit expectedCigarUnit = cigarUnitList.get(i);
        Assert.assertEquals(actualCigarUnit.getOperationLength(), expectedCigarUnit.getOperationLength(), "Wrong operation length in CigarUnit after conversion from SAM Cigar");
        Assert.assertEquals(actualCigarUnit.getOperation(), expectedCigarUnit.getOperation(), "Wrong operation in CigarUnit after conversion from SAM Cigar");
    }
}
Also used : CigarUnit(com.google.api.services.genomics.model.CigarUnit) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with CigarUnit

use of com.google.api.services.genomics.model.CigarUnit in project gatk by broadinstitute.

the class CigarConversionUtilsUnitTest method testHandleInvalidCigarElement.

@Test(dataProvider = "InvalidCigarElementData")
public void testHandleInvalidCigarElement(final CigarElement invalidCigarElement, final Class<? extends Exception> exceptionClass) {
    boolean sawException = false;
    try {
        final CigarUnit convertedUnit = CigarConversionUtils.convertSAMCigarElementToCigarUnit(invalidCigarElement);
    } catch (Exception e) {
        sawException = true;
        Assert.assertEquals(e.getClass(), exceptionClass, "Wrong class of exception thrown for invalid CigarElement");
    }
    Assert.assertTrue(sawException, "Expected exception of class " + exceptionClass + ", but no exception was thrown");
}
Also used : CigarUnit(com.google.api.services.genomics.model.CigarUnit) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 4 with CigarUnit

use of com.google.api.services.genomics.model.CigarUnit in project gatk by broadinstitute.

the class CigarConversionUtilsUnitTest method testConvertSAMCigarElementToCigarUnit.

@Test(dataProvider = "MatchingCigarUnitsAndElementsData")
public void testConvertSAMCigarElementToCigarUnit(final CigarUnit cigarUnit, final CigarElement cigarElement) {
    final CigarUnit convertedUnit = CigarConversionUtils.convertSAMCigarElementToCigarUnit(cigarElement);
    Assert.assertEquals(convertedUnit.getOperationLength(), cigarUnit.getOperationLength(), "CigarElement -> CigarUnit conversion failed: wrong operation length");
    Assert.assertEquals(convertedUnit.getOperation(), cigarUnit.getOperation(), "CigarElement -> CigarUnit conversion failed: wrong operation");
}
Also used : CigarUnit(com.google.api.services.genomics.model.CigarUnit) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 5 with CigarUnit

use of com.google.api.services.genomics.model.CigarUnit in project gatk by broadinstitute.

the class CigarConversionUtils method convertSAMCigarElementToCigarUnit.

/**
     * Converts an individual SAM CigarElement to an equivalent GA4GH-style CigarUnit
     *
     * @param cigarElement SAM CigarElement to convert to CigarUnit
     * @return equivalent CigarUnit
     */
public static CigarUnit convertSAMCigarElementToCigarUnit(final CigarElement cigarElement) {
    if (cigarElement == null) {
        throw new IllegalArgumentException("Cannot convert a null CigarElement");
    }
    final String convertedOperation = samToGA4GHOperatorTable.get(cigarElement.getOperator());
    if (convertedOperation == null) {
        throw new GATKException("Unable to convert CigarElement to CigarUnit: unknown operator in CigarElement: " + cigarElement.getOperator());
    }
    if (cigarElement.getLength() < 0) {
        throw new GATKException("Unable to convert CigarElement to CigarUnit: negative operation length in CigarElement: " + cigarElement.getLength());
    }
    final CigarUnit cigarUnit = new CigarUnit();
    cigarUnit.setOperationLength((long) cigarElement.getLength());
    cigarUnit.setOperation(convertedOperation);
    return cigarUnit;
}
Also used : GATKException(org.broadinstitute.hellbender.exceptions.GATKException) CigarUnit(com.google.api.services.genomics.model.CigarUnit)

Aggregations

CigarUnit (com.google.api.services.genomics.model.CigarUnit)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)3 Test (org.testng.annotations.Test)3 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)2