@@ -0,0 +1,2200 @@
+package org.broadinstitute.sting.playground.gatk.walkers;%0A%0Aimport org.broadinstitute.sting.gatk.LocusContext;%0Aimport org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;%0Aimport org.broadinstitute.sting.gatk.walkers.RefWalker;%0Aimport org.broadinstitute.sting.gatk.walkers.WalkerName;%0Aimport org.broadinstitute.sting.utils.GenomeLoc;%0Aimport org.broadinstitute.sting.utils.Pair;%0A%0A// create a fasta sequence file from a reference and intervals%0A%0A@WalkerName(%22FastaReferenceMaker%22)%0Apublic class FastaReferenceWalker extends RefWalker%3CPair%3CGenomeLoc, Character%3E, Pair%3CGenomeLoc, String%3E%3E %7B%0A%0A%09public Pair%3CGenomeLoc, Character%3E map(RefMetaDataTracker rodData, char ref, LocusContext context) %7B%0A        return new Pair%3CGenomeLoc, Character%3E(context.getLocation(), ref);%0A%09%7D%0A%0A    public Pair%3CGenomeLoc, String%3E reduceInit() %7B%0A        return new Pair%3CGenomeLoc, String%3E(null, %22%22);%0A    %7D%0A%0A%09public Pair%3CGenomeLoc, String%3E reduce(Pair%3CGenomeLoc, Character%3E value, Pair%3CGenomeLoc, String%3E sum) %7B%0A        // if there is no interval to the left, then this is the first one%0A        if ( sum.first == null ) %7B%0A            sum.first = value.first;%0A            sum.second = value.second.toString();%0A        %7D%0A        // if the intervals don't overlap, print out the leftmost one and start a new one%0A        else if ( value.first.getStart() != sum.first.getStop() + 1 ) %7B%0A            printFasta(sum.first, sum.second);%0A            sum.first = value.first;%0A            sum.second = value.second.toString();%0A        %7D%0A        // otherwise, merge them%0A        else %7B%0A            sum.first.setStop(value.first.getStop());%0A            sum.second = new String(sum.second + value.second);%0A        %7D%0A%09%09return sum;%0A%09%7D%0A%0A    public void onTraversalDone(Pair%3CGenomeLoc, String%3E sum) %7B%0A        if (sum.second != null)%0A            printFasta(sum.first, sum.second);%0A    %7D%0A%0A    private void printFasta(GenomeLoc loc, String s) %7B%0A        out.println(%22%3E%22 + loc);%0A        int lines = s.length() / 60;%0A        int currentStart = 0;%0A        for (int i=0; i %3C lines; i++) %7B%0A            out.println(s.substring(currentStart, currentStart+60));%0A            currentStart += 60;%0A        %7D%0A        out.println(s.substring(currentStart));%0A    %7D%0A%7D

Walker to pull out the reference for given intervals and emit them in fasta format