From 2f004665fb1f51728cdb586479ae7202d1c2e7cc Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Mon, 6 Aug 2012 11:42:12 -0400 Subject: [PATCH] Fixing public -> private dep --- .../utils/recalibration/AdaptiveContext.java | 175 ------------------ 1 file changed, 175 deletions(-) delete mode 100644 public/java/src/org/broadinstitute/sting/utils/recalibration/AdaptiveContext.java diff --git a/public/java/src/org/broadinstitute/sting/utils/recalibration/AdaptiveContext.java b/public/java/src/org/broadinstitute/sting/utils/recalibration/AdaptiveContext.java deleted file mode 100644 index b8a2eaf05..000000000 --- a/public/java/src/org/broadinstitute/sting/utils/recalibration/AdaptiveContext.java +++ /dev/null @@ -1,175 +0,0 @@ -package org.broadinstitute.sting.utils.recalibration; - -import java.util.*; - -/** - * Functions for working with AdaptiveContexts - * - * User: depristo - * Date: 8/3/12 - * Time: 12:21 PM - * To change this template use File | Settings | File Templates. - */ -public class AdaptiveContext { - private AdaptiveContext() {} - - /** - * Return a freshly allocated tree filled in completely to fillDepth with - * all combinations of {A,C,G,T}^filldepth contexts. For nodes - * in the tree, they are simply copied. When the algorithm needs to - * generate new nodes (because they are missing) the subnodes inherit the - * observation and error counts of their parent. - * - * This algorithm produces data consistent with the standard output in a BQSR recal - * file for the Context covariate. - * - * Suppose you have input tree - * - * - x - * - A - * - C - * - T - * - C - * - T - * - * This will produce the following contexts with fill depth of 2 - * - * AA <- gets A info - * CA <- gets CA info - * GA <- gets A info - * TA <- get TA info - * .. for all 16 contexts - * - * @param root - * @param fillDepth - * @return - */ - public static RecalDatumNode fillToDepth(final RecalDatumNode root, - final int fillDepth, - final boolean debugWriteN) { - if ( root == null ) throw new IllegalArgumentException("root is null"); - if ( fillDepth < 0 ) throw new IllegalArgumentException("fillDepth is < 0"); - - return fillToDepthRec(root, fillDepth, 0, debugWriteN); - } - - private static RecalDatumNode fillToDepthRec(final RecalDatumNode parent, - final int fillDepth, - final int currentDepth, - final boolean debugWriteN) { - // three cases: - // We are in the tree and so just recursively build - // We have reached our depth goal, so just return the parent since we are done - // We are outside of the tree, in which case we need to pointer to our parent node so we can - // we info (N, M) and we need a running context - if ( currentDepth < fillDepth ) { - // we need to create subnodes for each base, and propogate N and M down - final RecalDatumNode newParent = new RecalDatumNode(parent.getRecalDatum()); - - for ( final String base : Arrays.asList("A", "C", "G", "T")) { - final String subContextBases = base + parent.getRecalDatum().context; - ContextDatum subContext; - Set> subContexts; - - final RecalDatumNode subNode = findSubcontext(subContextBases, parent); - if ( subNode != null ) { - // we have a subnode corresponding to the expected one, just copy and recurse - subContext = subNode.getRecalDatum(); - subContexts = subNode.getSubnodes(); - } else { - // have to create a new one - subContext = new ContextDatum(debugWriteN ? ("N" + parent.getRecalDatum().context ) : subContextBases, - parent.getRecalDatum().getNumObservations(), parent.getRecalDatum().getNumMismatches()); - subContexts = Collections.emptySet(); - } - - newParent.addSubnode( - fillToDepthRec(new RecalDatumNode(subContext, subContexts), - fillDepth, currentDepth + 1, debugWriteN)); - } - return newParent; - } else { - return parent; - } - } - - /** - * Go from a flat list of contexts to the tree implied by the contexts - * - * Implicit nodes are created as needed, and their observation and error counts are the sum of the - * all of their subnodes. - * - * Note this does not guarentee the tree is complete, as some contexts (e.g., AAT) may be missing - * from the tree because they are absent from the input list of contexts. - * - * For input AAG, AAT, AC, G would produce the following tree: - * - * - x [root] - * - A - * - A - * - T - * - G - * - C - * - G - * - * sets the fixed penalties in the resulting tree as well - * - * @param flatContexts list of flat contexts - * @return - */ - public static RecalDatumNode createTreeFromFlatContexts(final List flatContexts) { - if ( flatContexts == null || flatContexts.isEmpty() ) - throw new IllegalArgumentException("flatContexts cannot be empty or null"); - - final Queue> remaining = new LinkedList>(); - final Map> contextToNodes = new HashMap>(); - RecalDatumNode root = null; - - // initialize -- start with all of the contexts - for ( final ContextDatum cd : flatContexts ) - remaining.add(new RecalDatumNode(cd)); - - while ( remaining.peek() != null ) { - final RecalDatumNode add = remaining.poll(); - final ContextDatum cd = add.getRecalDatum(); - - final String parentContext = cd.getParentContext(); - RecalDatumNode parent = contextToNodes.get(parentContext); - if ( parent == null ) { - // haven't yet found parent, so make one, and enqueue it for processing - parent = new RecalDatumNode(new ContextDatum(parentContext, 0, 0)); - contextToNodes.put(parentContext, parent); - - if ( ! parent.getRecalDatum().isRootContext() ) - remaining.add(parent); - else - root = parent; - } - - parent.getRecalDatum().incrementNumObservations(cd.getNumObservations()); - parent.getRecalDatum().incrementNumMismatches(cd.getNumMismatches()); - parent.addSubnode(add); - } - - if ( root == null ) - throw new RuntimeException("root is unexpectedly null"); - - // set the fixed penalty everywhere in the tree, so that future modifications don't change the penalties - root.calcAndSetFixedPenalty(true); - - return root; - } - - /** - * Finds immediate subnode with contextToFind, or null if none exists - * - * @param tree whose subnodes should be searched - * @return - */ - public static RecalDatumNode findSubcontext(final String contextToFind, final RecalDatumNode tree) { - for ( final RecalDatumNode sub : tree.getSubnodes() ) - if ( sub.getRecalDatum().context.equals(contextToFind) ) - return sub; - return null; - } -}