From e93f751bd72c6afad3cdba28cd90812354abd49d Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 30 Jun 2009 21:59:54 +0000 Subject: [PATCH] First step in replacing the Hello, World! document. Revamped the HelloWalker and checked it into the source tree, created a special build file for it, and added it to the packaging tool. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1135 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/gatk/examples/HelloWalker.java | 76 +++++++++++++++++++ .../sting/gatk/examples/build.xml | 40 ++++++++++ packages/GenomeAnalysisTK.xml | 4 + 3 files changed, 120 insertions(+) create mode 100644 java/src/org/broadinstitute/sting/gatk/examples/HelloWalker.java create mode 100644 java/src/org/broadinstitute/sting/gatk/examples/build.xml diff --git a/java/src/org/broadinstitute/sting/gatk/examples/HelloWalker.java b/java/src/org/broadinstitute/sting/gatk/examples/HelloWalker.java new file mode 100644 index 000000000..637395577 --- /dev/null +++ b/java/src/org/broadinstitute/sting/gatk/examples/HelloWalker.java @@ -0,0 +1,76 @@ +/* + * 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. + */ +import org.broadinstitute.sting.gatk.walkers.LocusWalker; +import org.broadinstitute.sting.gatk.LocusContext; +import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; + +/** + * An example walker for illustrative purposes. + */ +public class HelloWalker extends LocusWalker { + /** + * The map function runs once per single-base locus, and accepts a 'context', a + * data structure consisting of the reads which overlap the locus, the sites over + * which they fall, and the base from the reference that overlaps. + * @param tracker The accessor for reference metadata. + * @param ref The reference base that lines up with this locus. + * @param context Information about reads overlapping this locus. + * @return In this case, returns a count of how many loci were seen at this site (1). + */ + @Override + public Integer map(RefMetaDataTracker tracker, char ref, LocusContext context) { + out.printf("Hello locus %s; your ref base is %c and you have %d reads%n", context.getLocation(), ref, context.getReads().size() ); + return 1; + } + + /** + * Provides an initial value for the reduce function. Hello walker counts loci, + * so the base case for the inductive step is 0, indicating that the walker has seen 0 loci. + * @return 0. + */ + @Override + public Long reduceInit() { return 0L; } + + /** + * Combines the result of the latest map with the accumulator. In inductive terms, + * this represents the step loci[x + 1] = loci[x] + 1 + * @param value result of the map. + * @param sum accumulator for the reduce. + * @return The total count of loci processed so far. + */ + @Override + public Long reduce(Integer value, Long sum) { + return sum + value; + } + + /** + * Retrieves the final result of the traversal. + * @param result The ultimate value of the traversal, produced when map[n] is combined with reduce[n-1] + * by the reduce function. + */ + @Override + public void onTraversalDone(Long result) { + out.println("Number of loci viewed is: " + result); + } +} diff --git a/java/src/org/broadinstitute/sting/gatk/examples/build.xml b/java/src/org/broadinstitute/sting/gatk/examples/build.xml new file mode 100644 index 000000000..8acab9eac --- /dev/null +++ b/java/src/org/broadinstitute/sting/gatk/examples/build.xml @@ -0,0 +1,40 @@ + + + + Build the GATK examples + + + + + + + + + + + + + + diff --git a/packages/GenomeAnalysisTK.xml b/packages/GenomeAnalysisTK.xml index f5fceb542..4eb820b5b 100644 --- a/packages/GenomeAnalysisTK.xml +++ b/packages/GenomeAnalysisTK.xml @@ -7,4 +7,8 @@ org.broadinstitute.sting.gatk.walkers.PileupWalker org.broadinstitute.sting.gatk.walkers.PrintReadsWalker + + java/src/org/broadinstitute/sting/gatk/examples/HelloWalker.java + java/src/org/broadinstitute/sting/gatk/examples/build.xml +