diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java index 57ea5166a..7e1dcd707 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java @@ -59,12 +59,12 @@ public class PrintReadsWalker extends ReadWalker { @Argument(fullName = "number", shortName = "n", doc="Print the first n reads from the file, discarding the rest", required = false) int nReadsToPrint = -1; @Argument(fullName="sample_file", shortName="sf", doc="File containing a list of samples (one per line). Can be specified multiple times", required=false) - public Set sampleFiles; + public Set sampleFile = new TreeSet(); @Argument(fullName="sample_name", shortName="sn", doc="Sample name to be included in the analysis. Can be specified multiple times.", required=false) - public Set sampleNames; + public Set sampleNames = new TreeSet(); private TreeSet samplesToChoose = new TreeSet(); - private boolean NO_SAMPLES_SPECIFIED = false; + private boolean SAMPLES_SPECIFIED = false; /** * The initialize function. @@ -73,14 +73,17 @@ public class PrintReadsWalker extends ReadWalker { if ( platform != null ) platform = platform.toUpperCase(); - Collection samplesFromFile = SampleUtils.getSamplesFromFiles(sampleFiles); - samplesToChoose.addAll(samplesFromFile); + Collection samplesFromFile; + if (!sampleFile.isEmpty()) { + samplesFromFile = SampleUtils.getSamplesFromFiles(sampleFile); + samplesToChoose.addAll(samplesFromFile); + } - if (sampleNames != null) + if (!sampleNames.isEmpty()) samplesToChoose.addAll(sampleNames); - if(samplesToChoose.isEmpty()) { - NO_SAMPLES_SPECIFIED = true; + if(!samplesToChoose.isEmpty()) { + SAMPLES_SPECIFIED = true; } } @@ -109,19 +112,11 @@ public class PrintReadsWalker extends ReadWalker { if ( readPlatformAttr == null || !readPlatformAttr.toString().toUpperCase().contains(platform)) return false; } - if (!NO_SAMPLES_SPECIFIED ) { + if (SAMPLES_SPECIFIED ) { // user specified samples to select - String readSample = read.getReadGroup().getSample(); - boolean found = false; - for (String sampleSelected : samplesToChoose) { - if (readSample.equalsIgnoreCase(sampleSelected)) { - found = true; - break; - } - - } - - if (!found) + // todo - should be case-agnostic but for simplicity and speed this is ignored. + // todo - can check at initialization intersection of requested samples and samples in BAM header to further speedup. + if (!samplesToChoose.contains(read.getReadGroup().getSample())) return false; }