Search in sources :

Example 6 with TreeDrawerNode

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode in project clusterMaker2 by RBVI.

the class ATRView method update.

/**
 *  expect updates to come from map, arraySelection and drawer
 *
 * @param  o    The observable which sent the update
 * @param  arg  Argument for this update, typically null.
 */
public void update(Observable o, Object arg) {
    if (isEnabled() == false) {
        return;
    }
    if (o == map) {
        offscreenValid = false;
        repaint();
    } else if (o == drawer) {
        offscreenValid = false;
        repaint();
    } else if (o == arraySelection) {
        TreeDrawerNode cand = null;
        if (arraySelection.getNSelectedIndexes() > 0) {
            // This clause selects the array node if only a single array is selected.
            if (arraySelection.getMinIndex() == arraySelection.getMaxIndex()) {
                cand = drawer.getLeaf(arraySelection.getMinIndex());
            }
            // this clause selects the root node if all arrays are selected.
            if (arraySelection.getMinIndex() == map.getMinIndex()) {
                if (arraySelection.getMaxIndex() == map.getMaxIndex()) {
                    cand = drawer.getRootNode();
                }
            }
        }
        // Only notify observers if we're changing the selected node.
        if ((cand != null) && (cand.getId() != arraySelection.getSelectedNode())) {
            arraySelection.setSelectedNode(cand.getId());
            arraySelection.notifyObservers();
        } else {
            setSelectedNode(drawer.getNodeById(arraySelection.getSelectedNode()));
        }
    } else {
        System.out.println(viewName() + "Got an update from unknown " + o);
    }
}
Also used : TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)

Example 7 with TreeDrawerNode

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode in project clusterMaker2 by RBVI.

the class ATRView method selectLeft.

private void selectLeft() {
    if (selectedNode.isLeaf()) {
        return;
    }
    TreeDrawerNode current = selectedNode;
    selectedNode = current.getLeft();
    drawer.paintSingle(offscreenGraphics, xScaleEq, yScaleEq, destRect, current, false);
    drawer.paintSubtree(offscreenGraphics, xScaleEq, yScaleEq, destRect, current.getRight(), false);
    synchMap();
    repaint();
}
Also used : TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)

Example 8 with TreeDrawerNode

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode in project clusterMaker2 by RBVI.

the class ATRZoomView method keyPressed.

// method from KeyListener
/**
 *  Use keypress to navigate nodes
 *
 * up selects parent of current.
 * left selects left child.
 * right selects right child
 * down selects child with most descendants.
 */
public void keyPressed(KeyEvent e) {
    if (selectedNode == null) {
        return;
    }
    int c = e.getKeyCode();
    TreeDrawerNode cand = null;
    switch(c) {
        case KeyEvent.VK_UP:
            cand = selectedNode.getParent();
            break;
        // hey, the tree is upside down!
        case KeyEvent.VK_LEFT:
            if (selectedNode.isLeaf() == false) {
                cand = selectedNode.getRight();
            }
            break;
        case KeyEvent.VK_RIGHT:
            if (selectedNode.isLeaf() == false) {
                cand = selectedNode.getLeft();
            }
            break;
        case KeyEvent.VK_DOWN:
            if (selectedNode.isLeaf() == false) {
                TreeDrawerNode right = selectedNode.getRight();
                TreeDrawerNode left = selectedNode.getLeft();
                if (right.getRange() > left.getRange()) {
                    cand = right;
                } else {
                    cand = left;
                }
            }
            break;
    }
    if (cand != null) {
        setSelectedNode(cand);
    }
}
Also used : TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)

Example 9 with TreeDrawerNode

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode in project clusterMaker2 by RBVI.

the class TreeDrawer method setBranchHeightsIter.

public void setBranchHeightsIter(HeaderInfo nodeInfo, int nameIndex, int type, TreeDrawerNode start) {
    Stack remaining = new Stack();
    remaining.push(start);
    while (remaining.empty() == false) {
        TreeDrawerNode current = (TreeDrawerNode) remaining.pop();
        if (current.isLeaf()) {
        // will get handled in a linear-time routine...
        } else {
            int j = nodeInfo.getHeaderIndex(current.getId());
            Double d = new Double(nodeInfo.getHeader(j)[nameIndex]);
            double corr = d.doubleValue();
            if (type == CORRELATION) {
                // Account for a litle arithmetic fudge
                if (corr > 1.0)
                    corr = 1.0;
                else if (corr < -1.0)
                    corr = -1.0;
                // if ((corr  < -1.0) || (corr > 1.0)) {
                // System.out.println("Got illegal correlation " + corr + " at line "+j);
                // }
                current.setCorr(corr);
            } else {
                current.setCorr(corr);
            }
            remaining.push(current.getLeft());
            remaining.push(current.getRight());
        }
    }
}
Also used : TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)

Example 10 with TreeDrawerNode

use of edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode in project clusterMaker2 by RBVI.

the class TreeDrawer method setData.

/**
 * Set the data from which to draw the tree
 *
 * @param nodeInfo The headers from the node file.
 * There should be one header row per node.
 * There should be a column named "NODEID", "RIGHT", "LEFT" and one of either
 * "CORRELATION" or "TIME".
 *
 * @param rowInfo This is the header info for the rows which the ends of the tree are supposed to line up with.
 */
public void setData(HeaderInfo nodeInfo, HeaderInfo rowInfo) throws DendroException {
    if (nodeInfo == null) {
        setDefaults();
        return;
    }
    if (this.nodeInfo != null)
        this.nodeInfo.deleteObserver(this);
    this.nodeInfo = nodeInfo;
    nodeInfo.addObserver(this);
    leafList = new TreeDrawerNode[rowInfo.getNumHeaders()];
    id2node = new Hashtable(((nodeInfo.getNumHeaders() * 4) / 3) / 2, .75f);
    int nodeIndex = nodeInfo.getIndex("NODEID");
    if (nodeIndex == -1)
        throw new DendroException("Could not find header NODEID in tree header info");
    for (int j = 0; j < nodeInfo.getNumHeaders(); j++) {
        // extract the things we need from the enumeration
        String newId = nodeInfo.getHeader(j, nodeIndex);
        String leftId = nodeInfo.getHeader(j, "LEFT");
        String rightId = nodeInfo.getHeader(j, "RIGHT");
        // setup the kids
        TreeDrawerNode newn = (TreeDrawerNode) id2node.get(newId);
        TreeDrawerNode leftn = (TreeDrawerNode) id2node.get(leftId);
        TreeDrawerNode rightn = (TreeDrawerNode) id2node.get(rightId);
        if (newn != null) {
            System.out.println("Symbol '" + newn + "' appeared twice, building weird tree");
        }
        if (leftn == null) {
            // this means that the identifier for leftn is a new leaf
            // stores index (y location)
            int val;
            val = rowInfo.getHeaderIndex(leftId);
            if (val == -1) {
                Thread.dumpStack();
                throw new DendroException("Identifier " + leftId + " from tree file not found in CDT.");
            }
            leftn = new TreeDrawerNode(leftId, 1.0, val);
            leafList[val] = leftn;
            id2node.put(leftId, leftn);
        }
        if (rightn == null) {
            // this means that the identifier for rightn is a new leaf
            // System.out.println("Looking up " + rightId);
            // stores index (y location)
            int val;
            val = rowInfo.getHeaderIndex(rightId);
            if (val == -1) {
                Thread.dumpStack();
                throw new DendroException("Identifier " + rightId + " from tree file not found in CDT!");
            }
            rightn = new TreeDrawerNode(rightId, 1.0, val);
            leafList[val] = rightn;
            id2node.put(rightId, rightn);
        }
        if (leftn.getIndex() > rightn.getIndex()) {
            TreeDrawerNode swap = leftn;
            leftn = rightn;
            rightn = swap;
        }
        rootNode = new TreeDrawerNode(newId, 0.0, leftn, rightn);
        leftn.setParent(rootNode);
        rightn.setParent(rootNode);
        // finally, insert in tree
        id2node.put(newId, rootNode);
    }
    setBranchHeights(nodeInfo, rowInfo);
    setChanged();
}
Also used : TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)

Aggregations

TreeDrawerNode (edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode)17 AtrTVModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.AtrTVModel)2 TVModel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TVModel)2 HeaderInfo (edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo)1 TreeSelectionI (edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeSelectionI)1 Observable (java.util.Observable)1