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;
}
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");
}
}
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");
}
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");
}
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;
}
Aggregations