Search in sources :

Example 1 with TVModel

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

the class DendroView method flipSelectedATRNode.

/**
 * Finds the currently selected arrays, mirror image flips them, and then
 * rebuilds all necessary trees and saved data to the .jtv file.
 */
private void flipSelectedATRNode() {
    int leftIndex, rightIndex;
    String selectedID;
    TreeDrawerNode arrayNode = invertedTreeDrawer.getNodeById(getArraySelection().getSelectedNode());
    if (arrayNode == null || arrayNode.isLeaf()) {
        return;
    }
    selectedID = arrayNode.getId();
    // find the starting index of the left array tree, the ending index of the right array tree
    leftIndex = getDataModel().getArrayHeaderInfo().getHeaderIndex(arrayNode.getLeft().getLeftLeaf().getId());
    rightIndex = getDataModel().getArrayHeaderInfo().getHeaderIndex(arrayNode.getRight().getRightLeaf().getId());
    int num = getDataModel().getDataMatrix().getNumUnappendedCol();
    int[] newOrder = new int[num];
    for (int i = 0; i < num; i++) {
        newOrder[i] = i;
    }
    for (int i = 0; i <= (rightIndex - leftIndex); i++) {
        newOrder[leftIndex + i] = rightIndex - i;
    }
    /*System.out.print("Fliping to: ");
			for(int i = 0; i < newOrder.length; i++)
			{
				System.out.print(newOrder[i] + " ");
			}
			System.out.println("");*/
    ((TVModel) getDataModel()).reorderArrays(newOrder);
    ((TVModel) getDataModel()).saveOrder(newOrder);
    ((Observable) getDataModel()).notifyObservers();
    updateATRDrawer(selectedID);
}
Also used : TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode) TVModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TVModel) AtrTVModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.AtrTVModel) Observable(java.util.Observable)

Example 2 with TVModel

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

the class DendroView method bindTrees.

/**
 * this is meant to be called from setupViews.
 * It make sure that the trees are generated from the current model,
 * and enables/disables them as required.
 *
 * I factored it out because it is common betwen DendroView and KnnDendroView.
 */
protected void bindTrees() {
    DataModel tvmodel = getDataModel();
    if ((tvmodel != null) && tvmodel.aidFound()) {
        try {
            atrview.setEnabled(true);
            atrzview.setEnabled(true);
            invertedTreeDrawer.setData(tvmodel.getAtrHeaderInfo(), tvmodel.getArrayHeaderInfo());
            HeaderInfo trHeaderInfo = tvmodel.getAtrHeaderInfo();
            if (trHeaderInfo.getIndex("NODECOLOR") >= 0) {
                TreeColorer.colorUsingHeader(invertedTreeDrawer.getRootNode(), trHeaderInfo, trHeaderInfo.getIndex("NODECOLOR"));
            }
        } catch (DendroException e) {
            throw new RuntimeException("Had problem setting up the array tree: " + e.getMessage());
        /*
				//				LogPanel.println("Had problem setting up the array tree : " + e.getMessage());
				//				e.printStackTrace();
				Box mismatch = new Box(BoxLayout.Y_AXIS); mismatch.add(new JLabel(e.getMessage()));
				mismatch.add(new JLabel("Perhaps there is a mismatch between your ATR and CDT files?"));
				mismatch.add(new JLabel("Ditching Array Tree, since it's lame."));
				JOptionPane.showMessageDialog(viewFrame, mismatch, "Tree Construction Error", JOptionPane.ERROR_MESSAGE);
				atrview.setEnabled(false);
				atrzview.setEnabled(false);
				try{invertedTreeDrawer.setData(null, null);} catch (DendroException ex) {}
				*/
        }
    } else {
        atrview.setEnabled(false);
        atrzview.setEnabled(false);
        try {
            invertedTreeDrawer.setData(null, null);
        } catch (DendroException ex) {
        }
    }
    invertedTreeDrawer.notifyObservers();
    if ((tvmodel != null) && tvmodel.gidFound()) {
        try {
            leftTreeDrawer.setData(tvmodel.getGtrHeaderInfo(), tvmodel.getGeneHeaderInfo());
            HeaderInfo gtrHeaderInfo = tvmodel.getGtrHeaderInfo();
            if (gtrHeaderInfo.getIndex("NODECOLOR") >= 0) {
                TreeColorer.colorUsingHeader(leftTreeDrawer.getRootNode(), tvmodel.getGtrHeaderInfo(), gtrHeaderInfo.getIndex("NODECOLOR"));
            } else {
                TreeColorer.colorUsingLeaf(leftTreeDrawer.getRootNode(), tvmodel.getGeneHeaderInfo(), tvmodel.getGeneHeaderInfo().getIndex("FGCOLOR"));
            }
            gtrview.setEnabled(true);
        } catch (DendroException e) {
            throw new RuntimeException("Had problem setting up the gene tree: " + e.getMessage());
        // LogPanel.println("Had problem setting up the gene tree : " + e.getMessage());
        // e.printStackTrace();
        /*
				Box mismatch = new Box(BoxLayout.Y_AXIS); mismatch.add(new JLabel(e.getMessage()));
				mismatch.add(new JLabel("Perhaps there is a mismatch between your GTR and CDT files?"));
				mismatch.add(new JLabel("Ditching Gene Tree, since it's lame."));
				JOptionPane.showMessageDialog(viewFrame, mismatch, "Tree Construction Error", JOptionPane.ERROR_MESSAGE);
				gtrview.setEnabled(false);
				try{leftTreeDrawer.setData(null, null);} catch (DendroException ex) {}
				*/
        }
    } else {
        gtrview.setEnabled(false);
        try {
            leftTreeDrawer.setData(null, null);
        } catch (DendroException ex) {
        }
    }
    leftTreeDrawer.notifyObservers();
}
Also used : HeaderInfo(edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo) DataModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.DataModel) ReorderedDataModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.ReorderedDataModel)

Example 3 with TVModel

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

the class DendroView method updateATRDrawer.

/**
 * Updates the ATRDrawer to reflect changes in the DataMode
 * array order; rebuilds the TreeDrawerNode tree.
 * @param selectedID ID of the node selected before a change in
 *                   tree structure was made. This node is then
 *                   found and reselected after the ATR tree is rebuilt.
 */
private void updateATRDrawer(String selectedID) {
    try {
        TVModel tvmodel = (TVModel) getDataModel();
        invertedTreeDrawer.setData(tvmodel.getAtrHeaderInfo(), tvmodel.getArrayHeaderInfo());
        HeaderInfo trHeaderInfo = tvmodel.getAtrHeaderInfo();
        if (trHeaderInfo.getIndex("NODECOLOR") >= 0) {
            TreeColorer.colorUsingHeader(invertedTreeDrawer.getRootNode(), trHeaderInfo, trHeaderInfo.getIndex("NODECOLOR"));
        }
    } catch (DendroException e) {
        // LogPanel.println("Had problem setting up the array tree : " + e.getMessage());
        // e.printStackTrace();
        Box mismatch = new Box(BoxLayout.Y_AXIS);
        mismatch.add(new JLabel(e.getMessage()));
        mismatch.add(new JLabel("Perhaps there is a mismatch between your ATR and CDT files?"));
        mismatch.add(new JLabel("Ditching Array Tree, since it's lame."));
        JOptionPane.showMessageDialog(viewFrame, mismatch, "Tree Construction Error", JOptionPane.ERROR_MESSAGE);
        atrview.setEnabled(false);
        atrzview.setEnabled(false);
        try {
            invertedTreeDrawer.setData(null, null);
        } catch (DendroException ex) {
        }
    }
    TreeDrawerNode arrayNode = invertedTreeDrawer.getRootNode().findNode(selectedID);
    arraySelection.setSelectedNode(arrayNode.getId());
    atrzview.setSelectedNode(arrayNode);
    atrview.setSelectedNode(arrayNode);
    arraySelection.notifyObservers();
    invertedTreeDrawer.notifyObservers();
}
Also used : HeaderInfo(edu.ucsf.rbvi.clusterMaker2.internal.treeview.HeaderInfo) TreeDrawerNode(edu.ucsf.rbvi.clusterMaker2.internal.treeview.TreeDrawerNode) TVModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.TVModel) AtrTVModel(edu.ucsf.rbvi.clusterMaker2.internal.treeview.model.AtrTVModel)

Aggregations

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