From 62807139fccdbf5e1f61388c06bbed0f5e1ad661 Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 2 Jul 2009 14:54:01 +0000 Subject: [PATCH] Cleanup pileup and depth of coverage in preparation for release. Add pileup, depth of coverage, and print reads to package for distribution. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1159 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/walkers/DepthOfCoverageWalker.java | 36 ++++-- .../sting/gatk/walkers/PileupWalker.java | 121 +++++++++++------- packages/GenomeAnalysisTK.xml | 3 + 3 files changed, 107 insertions(+), 53 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/DepthOfCoverageWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/DepthOfCoverageWalker.java index cf5ba61c5..7c04829ca 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/DepthOfCoverageWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/DepthOfCoverageWalker.java @@ -1,18 +1,36 @@ +/* + * Copyright (c) 2009 The Broad Institute + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + package org.broadinstitute.sting.gatk.walkers; import org.broadinstitute.sting.gatk.LocusContext; -import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.cmdLine.Argument; import org.broadinstitute.sting.utils.Pair; -import java.util.List; /** - * Created by IntelliJ IDEA. - * User: mdepristo - * Date: Feb 22, 2009 - * Time: 3:22:14 PM - * To change this template use File | Settings | File Templates. + * Display the depth of coverage at a given locus. */ public class DepthOfCoverageWalker extends LocusWalker> { @Argument(fullName="suppressLocusPrinting",doc="Suppress printing",required=false) @@ -28,12 +46,12 @@ public class DepthOfCoverageWalker extends LocusWalker return true; } - public Pair reduceInit() { return new Pair(0l,0l); } + public Pair reduceInit() { return new Pair(0l,0l); } public Pair reduce(Integer value, Pair sum) { long left = value.longValue() + sum.getFirst(); long right = sum.getSecond() + 1l; - return new Pair(left, right); + return new Pair(left, right); } public void onTraversalDone(Pair result) { diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java index 8b025bd93..d218c8ff6 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java @@ -1,3 +1,27 @@ +/* + * Copyright (c) 2009 The Broad Institute + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + package org.broadinstitute.sting.gatk.walkers; import org.broadinstitute.sting.gatk.LocusContext; @@ -7,9 +31,6 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.cmdLine.Argument; import org.broadinstitute.sting.utils.ReadBackedPileup; import org.broadinstitute.sting.utils.Utils; -import net.sf.samtools.SAMRecord; - -import java.util.List; /** * samtools pileup [-f in.ref.fasta] [-t in.ref_list] [-l in.site_list] [-iscg] [-T theta] [-N nHap] [-r pairDiffRate] @@ -32,16 +53,14 @@ public class PileupWalker extends LocusWalker implements TreeR @Argument(fullName="alwaysShowSecondBase",doc="If true, prints dummy bases for the second bases in the BAM file where they are missing",required=false) public boolean alwaysShowSecondBase = false; - //@Argument(fullName="showSecondBaseQuals",doc="If true, prints out second base qualities in the pileup",required=false) - //public boolean showSecondBaseQuals = false; - @Argument(fullName="qualsAsInts",doc="If true, prints out qualities in the pileup as comma-separated integers",required=false) public boolean qualsAsInts = false; @Argument(fullName="extended",shortName="ext",doc="extended",required=false) public boolean EXTENDED = false; - public boolean FLAG_UNCOVERED_BASES = true; // todo: how do I make this a command line argument? + @Argument(fullName="ignore_uncovered_bases",shortName="skip_uncov",doc="Output nothing when a base is uncovered") + public boolean IGNORE_UNCOVERED_BASES = false; public void initialize() { } @@ -50,47 +69,16 @@ public class PileupWalker extends LocusWalker implements TreeR ReadBackedPileup pileup = new ReadBackedPileup(ref, context); String bases = pileup.getBases(); - if ( bases.equals("") && FLAG_UNCOVERED_BASES ) { + if ( bases.equals("") && !IGNORE_UNCOVERED_BASES ) { bases = "***UNCOVERED_SITE***"; } - StringBuilder extras = new StringBuilder(); + String secondBasePileup = ""; + if(shouldShowSecondaryBasePileup(pileup)) + secondBasePileup = getSecondBasePileup(pileup); + String rods = getReferenceOrderedData( tracker ); - String secondBasePileup = pileup.getSecondaryBasePileup(); - if ( secondBasePileup == null && alwaysShowSecondBase ) { - secondBasePileup = Utils.dupString('N', bases.length()); - } - if ( secondBasePileup != null ) extras.append(" ").append(secondBasePileup); - - /* - if ( showSecondBaseQuals ) { - String secondQualPileup = pileup.getSecondaryQualPileup(); - if ( secondQualPileup == null ) - secondQualPileup = Utils.dupString((char)(33), bases.length()); - extras.append(" ").append(secondQualPileup); - } - */ - - String rodString = ""; - for ( ReferenceOrderedDatum datum : tracker.getAllRods() ) { - if ( datum != null && ! (datum instanceof rodDbSNP)) { - //System.out.printf("rod = %s%n", datum.toSimpleString()); - rodString += datum.toSimpleString(); - //System.out.printf("Rod string %s%n", rodString); - } - } - - rodDbSNP dbsnp = (rodDbSNP)tracker.lookup("dbSNP", null); - if ( dbsnp != null ) - rodString += dbsnp.toMediumString(); - - if ( rodString != "" ) - rodString = "[ROD: " + rodString + "]"; - - //if ( context.getLocation().getStart() % 1 == 0 ) { - //System.out.printf("quals as ints %b%n", qualsAsInts); - out.printf("%s%s %s%n", pileup.getPileupString(qualsAsInts), extras, rodString); - //} + out.printf("%s%s %s%n", pileup.getPileupString(qualsAsInts), secondBasePileup, rods); if ( EXTENDED ) { String probDists = pileup.getProbDistPileup(); @@ -108,4 +96,49 @@ public class PileupWalker extends LocusWalker implements TreeR public Integer treeReduce(Integer lhs, Integer rhs) { return lhs + rhs; } + + /** + * Should the secondary base be shown under all circumstances? + * @param pileup The ReadBackedPileup at the current locus. + * @return True, if a secondary base pileup should always be shown. + */ + private boolean shouldShowSecondaryBasePileup( ReadBackedPileup pileup ) { + return ( pileup.getSecondaryBasePileup() != null || alwaysShowSecondBase ); + } + + /** + * Gets second base information for the pileup, if requested. + * @param pileup Pileup from which to extract secondary base info. + * @return String representation of the secondary base. + */ + private String getSecondBasePileup( ReadBackedPileup pileup ) { + String secondBasePileup = pileup.getSecondaryBasePileup(); + if( secondBasePileup != null ) + return " " + secondBasePileup; + else + return " " + Utils.dupString('N', pileup.getBases().length()); + } + + /** + * Get a string representation the reference-ordered data. + * @param tracker Container for the reference-ordered data. + * @return String representation of the reference-ordered data. + */ + private String getReferenceOrderedData( RefMetaDataTracker tracker ) { + String rodString = ""; + for ( ReferenceOrderedDatum datum : tracker.getAllRods() ) { + if ( datum != null && ! (datum instanceof rodDbSNP)) { + rodString += datum.toSimpleString(); + } + } + + rodDbSNP dbsnp = (rodDbSNP)tracker.lookup("dbSNP", null); + if ( dbsnp != null ) + rodString += dbsnp.toMediumString(); + + if ( !rodString.equals("") ) + rodString = "[ROD: " + rodString + "]"; + + return rodString; + } } diff --git a/packages/GenomeAnalysisTK.xml b/packages/GenomeAnalysisTK.xml index 19d195d52..c8ddd6e94 100644 --- a/packages/GenomeAnalysisTK.xml +++ b/packages/GenomeAnalysisTK.xml @@ -8,6 +8,9 @@ org.broadinstitute.sting.gatk.walkers.PrintReadsWalker + java/src/org/broadinstitute/sting/gatk/walkers/DepthOfCoverageWalker.java + java/src/org/broadinstitute/sting/gatk/walkers/PileupWalker.java + java/src/org/broadinstitute/sting/gatk/walkers/PrintReadsWalker.java java/src/org/broadinstitute/sting/gatk/examples/HelloWalker.java java/src/org/broadinstitute/sting/gatk/examples/build.xml testdata/exampleBAM.bam