Updating BQSR RecalibrationEngine to work correctly with empty BQSR tables.

-- Previously would crash when a scatter/gather interval contained no usable data.
-- Added unit test to cover this case.
This commit is contained in:
Ryan Poplin 2013-04-11 15:05:19 -04:00
parent 44230b97eb
commit a507381a33
5 changed files with 45 additions and 3 deletions

View File

@ -65,7 +65,7 @@ import java.util.List;
public class BQSRGatherer extends Gatherer {
private static final String EMPTY_INPUT_LIST = "list of inputs files is empty";
private static final String EMPTY_INPUT_LIST = "list of inputs files is empty or there is no usable data in any input file";
private static final String MISSING_OUTPUT_FILE = "missing output file name";
@Override
@ -80,6 +80,8 @@ public class BQSRGatherer extends Gatherer {
RecalibrationReport generalReport = null;
for (File input : inputs) {
final RecalibrationReport inputReport = new RecalibrationReport(input);
if( inputReport.isEmpty() ) { continue; }
if (generalReport == null)
generalReport = inputReport;
else

View File

@ -178,7 +178,7 @@ public class RecalibrationEngine {
final NestedIntegerArray<RecalDatum> byQualTable = finalRecalibrationTables.getQualityScoreTable();
// iterate over all values in the qual table
for ( NestedIntegerArray.Leaf<RecalDatum> leaf : byQualTable.getAllLeaves() ) {
for ( final NestedIntegerArray.Leaf<RecalDatum> leaf : byQualTable.getAllLeaves() ) {
final int rgKey = leaf.keys[0];
final int eventIndex = leaf.keys[2];
final RecalDatum rgDatum = byReadGroupTable.get(rgKey, eventIndex);
@ -206,7 +206,9 @@ public class RecalibrationEngine {
*/
@Requires("! finalized")
private RecalibrationTables mergeThreadLocalRecalibrationTables() {
if ( recalibrationTablesList.isEmpty() ) throw new IllegalStateException("recalibration tables list is empty");
if ( recalibrationTablesList.isEmpty() ) {
recalibrationTablesList.add( new RecalibrationTables(covariates, numReadGroups, maybeLogStream) );
}
RecalibrationTables merged = null;
for ( final RecalibrationTables table : recalibrationTablesList ) {

View File

@ -372,4 +372,11 @@ public class RecalibrationReport {
public Covariate[] getCovariates() {
return requestedCovariates;
}
/**
* @return true if the report has no data
*/
public boolean isEmpty() {
return recalibrationTables.isEmpty();
}
}

View File

@ -124,6 +124,16 @@ public final class RecalibrationTables {
return tables.size();
}
/**
* @return true if all the tables contain no RecalDatums
*/
public boolean isEmpty() {
for( final NestedIntegerArray<RecalDatum> table : tables ) {
if( !table.getAllValues().isEmpty() ) { return false; }
}
return true;
}
/**
* Allocate a new quality score table, based on requested parameters
* in this set of tables, without any data in it. The return result

View File

@ -69,6 +69,7 @@ public class BQSRGathererUnitTest extends BaseTest {
private static File recal3 = new File(privateTestDir + "HiSeq.1mb.1RG.sg3.table");
private static File recal4 = new File(privateTestDir + "HiSeq.1mb.1RG.sg4.table");
private static File recal5 = new File(privateTestDir + "HiSeq.1mb.1RG.sg5.table");
private static File recalEmpty = new File(privateTestDir + "HiSeq.1mb.1RG.empty.table");
private static File recal_original = new File(privateTestDir + "HiSeq.1mb.1RG.noSG.table");
@ -110,6 +111,26 @@ public class BQSRGathererUnitTest extends BaseTest {
testReports(originalReport, calculatedReport);
}
@Test(enabled = true)
public void testGatherBQSRWithEmptyFile() {
BQSRGatherer gatherer = new BQSRGatherer();
List<File> recalFiles = new LinkedList<File> ();
final File output = BaseTest.createTempFile("BQSRgathererTest", ".table");
recalFiles.add(recal1);
recalFiles.add(recal2);
recalFiles.add(recal3);
recalFiles.add(recal4);
recalFiles.add(recal5);
recalFiles.add(recalEmpty);
gatherer.gather(recalFiles, output);
GATKReport originalReport = new GATKReport(recal_original);
GATKReport calculatedReport = new GATKReport(output);
testReports(originalReport, calculatedReport);
}
private void testReports(final GATKReport originalReport, final GATKReport calculatedReport) {
// test the Arguments table