From fb2d475c2285c10fd6a66aff1dc0d6c1dd6c1b90 Mon Sep 17 00:00:00 2001 From: Guillermo del Angel Date: Tue, 19 Jul 2011 20:13:56 -0400 Subject: [PATCH 1/4] Bug fix to prevent null pointer --- .../sting/gatk/walkers/PrintReadsWalker.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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..78b6e7c04 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java @@ -59,7 +59,7 @@ 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; @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; @@ -73,10 +73,13 @@ 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()) { From e8409c80fa9c771dd79c515cdb8273e2d7645b07 Mon Sep 17 00:00:00 2001 From: Guillermo del Angel Date: Tue, 19 Jul 2011 21:59:24 -0400 Subject: [PATCH 2/4] Further protection vs null pointers in PrintReadsWalker --- .../broadinstitute/sting/gatk/walkers/PrintReadsWalker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 78b6e7c04..b10486e50 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java @@ -59,9 +59,9 @@ 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 sampleFile; + 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; From a2d90a35903d28ea4e7ab7017e712a008bc12712 Mon Sep 17 00:00:00 2001 From: Guillermo del Angel Date: Wed, 20 Jul 2011 10:23:10 -0400 Subject: [PATCH 3/4] Bug fix: reverted logic so that default behavior skips over sample lookup --- .../sting/gatk/walkers/PrintReadsWalker.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 b10486e50..2b7db8d34 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java @@ -64,7 +64,7 @@ public class PrintReadsWalker extends ReadWalker { public Set sampleNames = new TreeSet(); private TreeSet samplesToChoose = new TreeSet(); - private boolean NO_SAMPLES_SPECIFIED = false; + private boolean SAMPLES_SPECIFIED = false; /** * The initialize function. @@ -82,8 +82,8 @@ public class PrintReadsWalker extends ReadWalker { if (!sampleNames.isEmpty()) samplesToChoose.addAll(sampleNames); - if(samplesToChoose.isEmpty()) { - NO_SAMPLES_SPECIFIED = true; + if(!samplesToChoose.isEmpty()) { + SAMPLES_SPECIFIED = true; } } @@ -112,7 +112,7 @@ 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; From 7140280bf640fe2e46de52c51888134210dddf6e Mon Sep 17 00:00:00 2001 From: Guillermo del Angel Date: Wed, 20 Jul 2011 10:44:37 -0400 Subject: [PATCH 4/4] Further bug fixes/cleanups for PrintReadsWalker --- .../sting/gatk/walkers/PrintReadsWalker.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) 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 2b7db8d34..7e1dcd707 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java @@ -114,17 +114,9 @@ public class PrintReadsWalker extends ReadWalker { } 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; }