Merge pull request #509 from broadinstitute/ldg_empty_bam_list_error
Check for empty BAM lists in command line input
This commit is contained in:
commit
602fc0ca4d
|
|
@ -497,19 +497,27 @@ public class GenomeAnalysisEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* Verifies that the supplied set of reads files mesh with what the walker says it requires,
|
||||
* and also makes sure that there were no duplicate SAM files specified on the command line.
|
||||
* Verifies that the supplied set of reads files mesh with what the walker says it requires;
|
||||
* also makes sure that list of SAM files specified on the command line is not empty and contains
|
||||
* no duplicates.
|
||||
*/
|
||||
protected void validateSuppliedReads() {
|
||||
GATKArgumentCollection arguments = this.getArguments();
|
||||
final Boolean samFilesArePresent = (arguments.samFiles != null && !arguments.samFiles.isEmpty());
|
||||
|
||||
// Check what the walker says is required against what was provided on the command line.
|
||||
if (WalkerManager.isRequired(walker, DataSource.READS) && (arguments.samFiles == null || arguments.samFiles.size() == 0))
|
||||
if (WalkerManager.isRequired(walker, DataSource.READS) && !samFilesArePresent)
|
||||
throw new ArgumentException("Walker requires reads but none were provided.");
|
||||
|
||||
// Check what the walker says is allowed against what was provided on the command line.
|
||||
if ((arguments.samFiles != null && arguments.samFiles.size() > 0) && !WalkerManager.isAllowed(walker, DataSource.READS))
|
||||
if (samFilesArePresent && !WalkerManager.isAllowed(walker, DataSource.READS))
|
||||
throw new ArgumentException("Walker does not allow reads but reads were provided.");
|
||||
|
||||
//Make sure SAM list specified by the user (if necessary) is not empty
|
||||
if(WalkerManager.isRequired(walker, DataSource.READS) && samFilesArePresent && samReaderIDs.isEmpty() ) {
|
||||
throw new UserException("The list of input files does not contain any BAM files.");
|
||||
}
|
||||
|
||||
// Make sure no SAM files were specified multiple times by the user.
|
||||
checkForDuplicateSamFiles();
|
||||
}
|
||||
|
|
@ -535,6 +543,7 @@ public class GenomeAnalysisEngine {
|
|||
throw new UserException("The following BAM files appear multiple times in the list of input files: " +
|
||||
duplicateSamFiles + " BAM files may be specified at most once.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,9 +28,11 @@ package org.broadinstitute.sting.gatk;
|
|||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.commandline.ArgumentException;
|
||||
import org.broadinstitute.sting.commandline.Tags;
|
||||
import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection;
|
||||
import org.broadinstitute.sting.gatk.datasources.reads.SAMReaderID;
|
||||
import org.broadinstitute.sting.gatk.iterators.ReadTransformer;
|
||||
import org.broadinstitute.sting.gatk.walkers.Walker;
|
||||
import org.broadinstitute.sting.gatk.walkers.qc.CountReads;
|
||||
import org.broadinstitute.sting.gatk.walkers.readutils.PrintReads;
|
||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||
import org.broadinstitute.sting.utils.GenomeLocSortedSet;
|
||||
|
|
@ -51,6 +53,23 @@ import java.util.*;
|
|||
*/
|
||||
public class GenomeAnalysisEngineUnitTest extends BaseTest {
|
||||
|
||||
@Test(expectedExceptions=UserException.class)
|
||||
public void testEmptySamFileListHandling() throws Exception {
|
||||
GenomeAnalysisEngine testEngine = new GenomeAnalysisEngine();
|
||||
testEngine.setWalker(new CountReads()); //generalizable to any walker requiring reads
|
||||
|
||||
//supply command line args so validateSuppliedReads() knows whether reads were passed in
|
||||
GATKArgumentCollection testArgs = new GATKArgumentCollection();
|
||||
testArgs.samFiles.add("empty.list");
|
||||
testEngine.setArguments(testArgs);
|
||||
|
||||
//represents the empty list of samFiles read in from empty.list by CommandLineExecutable
|
||||
Collection<SAMReaderID> samFiles = new ArrayList<SAMReaderID>();
|
||||
|
||||
testEngine.setSAMFileIDs(samFiles);
|
||||
testEngine.validateSuppliedReads();
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=UserException.class)
|
||||
public void testDuplicateSamFileHandlingSingleDuplicate() throws Exception {
|
||||
GenomeAnalysisEngine testEngine = new GenomeAnalysisEngine();
|
||||
|
|
|
|||
Loading…
Reference in New Issue