diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGatherer.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGatherer.java index 82d08da41..ad97dc008 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGatherer.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGatherer.java @@ -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 diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationEngine.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationEngine.java index 5e6e2a8d9..9f33234cf 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationEngine.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/RecalibrationEngine.java @@ -178,7 +178,7 @@ public class RecalibrationEngine { final NestedIntegerArray byQualTable = finalRecalibrationTables.getQualityScoreTable(); // iterate over all values in the qual table - for ( NestedIntegerArray.Leaf leaf : byQualTable.getAllLeaves() ) { + for ( final NestedIntegerArray.Leaf 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 ) { diff --git a/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationReport.java b/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationReport.java index a3fec6a22..ea45c2abf 100644 --- a/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationReport.java +++ b/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationReport.java @@ -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(); + } } diff --git a/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java b/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java index 15b6c8571..7d1a9f956 100644 --- a/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java +++ b/protected/java/src/org/broadinstitute/sting/utils/recalibration/RecalibrationTables.java @@ -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 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 diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGathererUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGathererUnitTest.java index f82f24439..658b8527d 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGathererUnitTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/bqsr/BQSRGathererUnitTest.java @@ -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 recalFiles = new LinkedList (); + 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